Author Topic: OmnomIRC Protocol Information  (Read 10998 times)

0 Members and 2 Guests are viewing this topic.

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
OmnomIRC Protocol Information
« 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):

Code: [Select]
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 += "&lt; " + messageParts[4] + " &gt; " + 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:
Code: [Select]
//******************************
// 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:
Code: [Select]
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  *
//******************************
Omnimaga Admin

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: OmnomIRC Protocol Information
« Reply #1 on: June 20, 2011, 01:24:20 am »
Ah cool, an API. Will help me if I want to write an OmnomIRC client. :P

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: OmnomIRC Protocol Information
« Reply #2 on: June 20, 2011, 01:29:00 am »
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.
Omnimaga Admin

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: OmnomIRC Protocol Information
« Reply #3 on: June 20, 2011, 03:54:56 am »
Pretty nice that you are documenting and releasing everything!

Thanks :)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: OmnomIRC Protocol Information
« Reply #4 on: June 20, 2011, 03:55:46 am »
: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.
Omnimaga Admin

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: OmnomIRC Protocol Information
« Reply #5 on: June 20, 2011, 04:11:55 am »
When I got some time I'll try to setup a local version, without IRC (that should work, shouldn't it?)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: OmnomIRC Protocol Information
« Reply #6 on: June 20, 2011, 04:14:49 am »
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).
Omnimaga Admin

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: OmnomIRC Protocol Information
« Reply #7 on: June 20, 2011, 04:16:18 am »
ok, thanks :)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: OmnomIRC Protocol Information
« Reply #8 on: June 20, 2011, 04:17:29 am »
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?
Omnimaga Admin

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: OmnomIRC Protocol Information
« Reply #9 on: June 20, 2011, 06:10:55 am »
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!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: OmnomIRC Protocol Information
« Reply #10 on: June 23, 2011, 07:27:09 pm »
It would be nice Netham45, especially for spotting bugs and fixing them, plus when you are busy then people could still maintain it.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: OmnomIRC Protocol Information
« Reply #11 on: June 24, 2011, 07:58:12 am »
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.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: OmnomIRC Protocol Information
« Reply #12 on: June 24, 2011, 11:30:28 pm »
Ah ok that's good too :)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: OmnomIRC Protocol Information
« Reply #13 on: June 25, 2011, 12:10:37 am »
I'm working on the login system, and I've hit a bit of a hangup.

Here's what I got so far

Code: [Select]
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:
« Last Edit: June 25, 2011, 12:15:42 am by Netham45 »
Omnimaga Admin

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: OmnomIRC Protocol Information
« Reply #14 on: June 25, 2011, 12:45:28 am »
That seems hard O.O. What about passwords?