Created
December 19, 2012 13:59
-
-
Save NuckChorris/4336847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| property login:username | |
| p=info | |
| usericon=usericon | |
| symbol=symbol | |
| realname=realname | |
| typename=typename | |
| gpc=global privs | |
| conn | |
| online=seconds online | |
| idle=seconds idle | |
| ns channel | |
| ns channel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Packet | |
| attr_reader :cmd, :param, :args, :body, :sub, :depth, :raw | |
| def initialize (pkt) | |
| @args = {} | |
| @sub = [] | |
| if pkt.is_a? Hash | |
| @cmd = pkt[:cmd] | |
| @param = pkt[:param] | |
| @args = pkt[:args] | |
| @body = pkt[:body] | |
| @sub = pkt[:sub] | |
| @raw = pkt[:raw] | |
| elsif pkt.is_a? String | |
| @raw = pkt | |
| parts = pkt.split "\n\n", 2 | |
| head = parts.shift.split "\n" | |
| if head[0]["="] == nil | |
| cmd = head.shift.split " " | |
| @cmd = cmd.shift | |
| @param = cmd.shift | |
| end | |
| head.each do |line| | |
| splat = line.split "=", 2 | |
| @args[splat[0]] = splat[1] | |
| end | |
| @body = parts.shift || "" | |
| @body.split("\n\n").each do |sub| | |
| @sub.push Packet.new(sub) | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #<Packet:0x007fbd020e3f78 | |
| @args = { | |
| "p" => "info" | |
| }, | |
| @sub = [ | |
| #<Packet:0x007fbd020e30a0 | |
| @args = { | |
| "usericon" => "usericon", | |
| "symbol" => "symbol", | |
| "realname" => "realname", | |
| "typename" => "typename", | |
| "gpc" => "global privs" | |
| }, | |
| @sub = [], | |
| @raw = "usericon=usericon\nsymbol=symbol\nrealname=realname\ntypename=typename\ngpc=global privs", | |
| @body = "" | |
| >, | |
| #<Packet:0x007fbd020e2358 | |
| @args = { | |
| "online" => "seconds online", | |
| "idle" => "seconds idle" | |
| }, | |
| @sub = [], | |
| @raw = "conn\nonline=seconds online\nidle=seconds idle", | |
| @cmd = "conn", | |
| @param = nil, | |
| @body = "" | |
| >, | |
| #<Packet:0x007fbd020db120 | |
| @args = {}, | |
| @sub = [], | |
| @raw = "ns channel", | |
| @cmd = "ns", | |
| @param = "channel", | |
| @body = "" | |
| >, | |
| #<Packet:0x007fbd020dabd0 | |
| @args = {}, | |
| @sub = [], | |
| @raw = "ns channel", | |
| @cmd = "ns", | |
| @param = "channel", | |
| @body = "" | |
| > | |
| ], | |
| @raw = "property login:username\np=info\n\nusericon=usericon\nsymbol=symbol\nrealname=realname\ntypename=typename\ngpc=global privs\n\nconn\nonline=seconds online\nidle=seconds idle\n\nns channel\n\nns channel", | |
| @cmd = "property", | |
| @param = "login:username", | |
| @body = "usericon=usericon\nsymbol=symbol\nrealname=realname\ntypename=typename\ngpc=global privs\n\nconn\nonline=seconds online\nidle=seconds idle\n\nns channel\n\nns channel" | |
| > |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require './Packet' | |
| Packet.new "property login:username\np=info\n\nusericon=usericon\nsymbol=symbol\nrealname=realname\ntypename=typename\ngpc=global privs\n\nconn\nonline=seconds online\nidle=seconds idle\n\nns channel\n\nns channel" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment