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 *
//******************************