Omnimaga
Omnimaga => Discontinued => Our Projects => OmnomIRC Development => Topic started by: Netham45 on June 20, 2011, 01:22:28 am
-
OmnomIRC Protocol Stuffs (Giant wall of post go!)
All code is javascript
Required functions:
addLine(ircMessage) - This function is called from the load.php to load messages.
addUser(userMessage) - This function is called from the load.php to keep track of users.
The ircMessage message is pretty simple.
There is a common header.
Common Header:
Message Number:Message Type:Online:Time
Message Number -- Corresponds to the auto-incrementing primary key in the SQL DB. You will need to put this on the update.php call to not return already-parsed lines.
Message Type -- pm,message,action,join,part,kick,quit,mode,nick,topic,curline, check the next section.
Online -- Boolean value to tell if the source was from OmnomIRC or IRC. I use this to check if I should apply links to OmnomIRC names.
Time -- UNIX Timestamp
After the common header, all elements are base64 encoded. Check btoa.js for a cross-browser base64 implementation.
Specific Types:
pm, message, action, part, quit, mode, topic - These share paramaters
:Name 1:Message
join
:Name 1
nick
:Name 1:Name 2
curline
No parts, used to set the current line.
Examples:
pm, message, action, part, quit, mode, topic
Decoded:
1:message:0:12345:Netham45:Test
Encoded:
1:message:0:12345:TmV0aGFtNDU=:VGVzdA==
Join
Decoded:
1:join:0:12345:Netham45
Encoded:
1:message:0:12345:TmV0aGFtNDU=
Nick
Decoded:
1:nick:0:12345:Netham45:Netham46
Encoded:
1:nick:0:12345:TmV0aGFtNDU=:TmV0aGFtNDY=
curline: -- This does not return a proper timestamp, as it is not actually matched to an event in the SQL DB.
1:curline:0:0
To parse in javascript, this is a simple method (assuming you're using the btoa.js included):
function addLines(message)
{
var messageParts = message.split(":");
for (var i=4;i<messageParts.length;i++)
messageParts[i] = base64.decode(messageParts[i]);
curLine = messageParts[0]; //This is a global var for a reason
var type = messageParts[1];
var online = messageParts[2];
var time = new Date(messageParts[3]);
textBox.innerHTML += "[" + time.toLocaleString() + "] ";
switch (type)
{
case "message":
textBox.innerHTML += "< " + messageParts[4] + " > " + messageParts[5];
break;
case "action":
...
}
textBox.innerHTML += "<br/>";
}
userMessage information:
These are simpler, only composed of two parts. They are all the same. They are only sent from the load.php for now.
userName:Online
userName is a base64 encoded name
Online is a boolean value for if they're on OmnomIRC or not
Example:
Decoded:
Netham45:1
Encoded:
TmV0aGFtNDU=:1
Here is the code from Omnom_Parser.js that deals with users:
//******************************
// Userlist Start *
//******************************
userListContainer = document.getElementById("UserListArrContainer");
userListDiv = document.getElementById("UserList");
UserListArr = array();
function addUser(user)
{
UserListArr.push(user);
}
function addUserJoin(user)
{
if(!hasLoaded) return;
var userp = base64.encode(user) + ":0";
UserListArr.push(userp);
parseUsers();
}
function removeUser(user)
{
if(!hasLoaded) return;
for (i in UserListArr)
{
parts = UserListArr[i].split(":");
if (base64.decode(parts[0]) == user)
UserListArr.splice(i,1);
}
parseUsers();
}
function parseUsers()
{
if (!userListDiv || userListDiv == null)
userListDiv = document.getElementById("UserList");
userText = "";
i = 0;
UserListArr.sort(function(a,b)
{
var al=base64.decode(a).toLowerCase(),bl=base64.decode(b).toLowerCase();
return al==bl?(a==b?0:a<b?-1:1):al<bl?-1:1;
});
for (i=0;i<UserListArr.length;i++)
{
parts = UserListArr[i].split(":");
if (parts[1] == "0") userText = userText + "#" + base64.decode(parts[0]) + "<br/>";
if (parts[1] == "1")
userText = userText + '<a target="_parent" href="http://www.omnimaga.org/index.php?action=ezportal;sa=page;p=13&userSearch=' +base64.decode(parts[0]) +
'"><img src="http://netham45.org/irc/efnet/ouser.png" alt="Omnimaga User" title="Omnimaga User" border=0 width=8 height=8 />' + base64.decode(parts[0]) + '</a><br/>';
if (parts[1] == "2") userText = userText + "!" + base64.decode(parts[0]) + "<br/>";
}
userText = userText + "<br/><br/>";
userListDiv.innerHTML = userText;
}
//******************************
// Userlist End *
//******************************
To "subscribe" to updates:
Request load.php. This returns a javascript file that calls addLine and addUser
nick and signature are optional, they are only used to return PMs. Channel is required for what channel you're querying. Signature and nick need to be in place to request PMs.
All paramaters except count are base64 encoded.
Here's the URL:
Decoded:
http://omnom.omnimaga.org/OmnomIRC_Dev/load.php?count=50&channel=#Omnimaga&nick=Netham45&signature=No sig for you!
Encoded:
http://omnom.omnimaga.org/OmnomIRC_Dev/load.php?count=50&channel=I09tbmltYWdh&nick=TmV0aGFtNDU=&signature=Tm8gc2lnIGZvciB5b3Uh
Once load.php is parsed, you need to request update.php. This does not return a javascript file, but instead just returns the message.
lineNum is not base64 encoded, but everything else is.
Here's the URL:
Decoded:
http://omnom.omnimaga.org/OmnomIRC_Dev/update.php?lineNum=1&channel=#omnimaga&nick=Netham45&signature=No sig for you!
Encoded:
http://omnom.omnimaga.org/OmnomIRC_Dev/update.php?lineNum=1&channel=I09tbmltYWdh&nick=TmV0aGFtNDU=&signature=Tm8gc2lnIGZvciB5b3Uh
Here is the code from Omnom_Parser that handles 'subscribing' and updating:
function load()
{
var body= document.getElementsByTagName('body')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'Load.php?count=50&channel=' + base64_encode("#Omnimaga") + "&nick=" + base64.encode("Netham45") + "&signature=" + base64.encode("lolnope");
script.onload= function(){parseUsers();startLoop();mBoxCont.scrollTop = mBoxCont.scrollHeight;hasLoaded = true;};
body.appendChild(script);
}
//******************************
// Start Request Loop functions*
//******************************
function startLoop()
{
xmlhttp=getAjaxObject();
if (xmlhttp==null) {
alert ("Your browser does not support AJAX! Please update for OmnomIRC compatibility.");
return;
}
xmlhttp.onreadystatechange=getIncomingLine;
sendRequest();
}
function sendRequest()
{
url = "http://omnom.omnimaga.org/OmnomIRC_Dev/Update.php?lineNum=" + curLine + "&channel=" + getChannelEn() + "&nick=" + base64.encode(parent.userName) + "&signature=" + base64.encode(parent.Signature);
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function getIncomingLine()
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
if (xmlhttp.status == 200) addLine(xmlhttp.responseText); //Filter out 500s from timeouts
sendRequest();
}
}
function getAjaxObject()
{
xmlhttp=new XMLHttpRequest(); //Decent Browsers
if (!xmlhttp || xmlhttp == undefined || xmlhttp == null) xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); //IE7+
if (!xmlhttp || xmlhttp == undefined || xmlhttp == null) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); //IE6-
return xmlhttp;
}
//******************************
// End Request Loop functions *
//******************************
-
Ah cool, an API. Will help me if I want to write an OmnomIRC client. :P
-
I need a method for generating API keys, but once I come up with something I'll be making it so you can make things that send outgoing messages.
-
Pretty nice that you are documenting and releasing everything!
Thanks :)
-
:D
I think right now I've got everything released that someone would need to set up and run their own copy of it, except for the documentation.
-
When I got some time I'll try to setup a local version, without IRC (that should work, shouldn't it?)
-
Yea. You'll need to comment a bit of load.php out to remove the Omnimaga userlist (and prolly remove some other Omni-specific coding, like the username links).
-
ok, thanks :)
-
On that note, I've actually been tossing around the idea of trying to get a couple people to work with me on it to come up with more of a finalized product. Anyone interested in that?
-
I just put omnom up internally, and I must say it works pretty good!
I needed to change some stuff to let it work, but it was pretty straight forward, so good job Netham!
-
It would be nice Netham45, especially for spotting bugs and fixing them, plus when you are busy then people could still maintain it.
-
It would be nice Netham45, especially for spotting bugs and fixing them, plus when you are busy then people could still maintain it.
I also like the idea, and Jim Bauwens already seems to be doing some work.
-
Ah ok that's good too :)
-
I'm working on the login system, and I've hit a bit of a hangup.
Here's what I got so far
Step 1: User hits index.php
Step 2: index.php hits login.php, which will be replacable(SMF,phpBB,etc... versions)
Step 3: login.php will encrypt user data and send it to the forums (OmnomIRC_Login.php, for example). The forums will decrypt it and check it's validity. This will require my own cookies for user info.
ALTERNATIVE
Step 3: login.php will load an iframe to a remote page that will redirect to a local null page. It will then rip the signature from a paramater on the page. This will use the sites' cookies.
Step 4: OmnomIRC_Login.php will return either a signature for the user, or 'INVALID', based off of the result of its check
Step 5: If Invalid, go to the forum to login, or own login. If valid, yay!
I'm stuck on a good way to perform step 3, or a good way to check if the user is logged into the forums by their own site cookies. I'd rather not handle logins separately.
edit: here's an idea.
login.php has a JS callback that marks the signature.
login.php has an iframe that calls the remote one, the remote one them calls a stupid php file on the local page that only calls that callback on index.php
v------------------------------------------------------------------------------^
v-login.php -> OmnomIRC_CheckLogin.php -> signature_callback.php-^
same origin policy :mad:
-
That seems hard O.O. What about passwords?
-
Just came up with a simple solution. Script tags don't fall victim to the same origin policy, so I don't need all that crap.
And, DJ, my goal of making it use the sites cookies is to not need to use usernames/passwords.
-
Oh ok. Well I hope you don't have too much troubles implementing a secure way to do this.
-
Oh ok. Well I hope you don't have too much troubles implementing a secure way to do this.
I think I just got it. >:D
http://netham45.org/OmnomIRC_Test/
^ This should automagically rip out your Omnimaga name.
-
Cool to hear. By the way it is completely safe, right? I mean, could someone edit his cookies or something to steal someone's nick?