Class: ICB
- Inherits:
-
Object
- Object
- ICB
- Defined in:
- lib/icb.rb
Constant Summary collapse
- VERSION =
"1.0.1"
- DEF_HOST =
Default connection values. (evolve.icb.net, empire.icb.net, cjnetworks.icb.net, swcp.icb.net)
"default.icb.net"
- DEF_PORT =
7326
- DEF_GROUP =
1
- DEF_CMD =
cmds are only “login” and “w”
"login"
- DEF_USER =
ENV["USER"]
- DEL =
Protocol definitions: all nice cleartext.
"\001"
- M_LOGIN =
Packet argument delimiter.
'a'
- M_LOGINOK =
login packet
'a'
- M_OPEN =
login response
'b'
- M_PERSONAL =
open msg to group
'c'
- M_STATUS =
personal message
'd'
- M_ERROR =
group status update message
'e'
- M_ALERT =
error message
'f'
- M_EXIT =
important announcement
'g'
- M_COMMAND =
quit packet from server
'h'
- M_CMDOUT =
send a command from user
'i'
- M_PROTO =
output from a command
'j'
- M_BEEP =
protocol/version information
'k'
- M_PING =
beeps
'l'
- M_PONG =
ping packet from server
'm'
- M_OOPEN =
Archaic packets: some sort of echo scheme?
'n'
- M_OPERSONAL =
for own open messages
'o'
Instance Attribute Summary collapse
-
#debug ⇒ Object
for own personal messages.
Instance Method Summary collapse
- #close ⇒ Object
-
#connect(options) ⇒ Object
Connect to a server and send our login packet.
-
#initialize(options = {}) ⇒ ICB
constructor
Create a new fnet object and optionally connect to a server.
-
#readmsg ⇒ Object
Read a message from the server and break it into its fields.
-
#sendcmd(cmd, *kwargs) ⇒ Object
Server processed command.
-
#sendopen(txt) ⇒ Object
Open or group wide message.
-
#sendpong ⇒ Object
Ping reply.
-
#sendpriv(nick, msg) ⇒ Object
Private or user-directed message.
-
#sendraw(buf) ⇒ Object
Send a raw packet (ie: don’t insert a packet type).
Constructor Details
#initialize(options = {}) ⇒ ICB
Create a new fnet object and optionally connect to a server. keys: host port user nick group cmd passwd
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/icb.rb', line 41 def initialize( = {}) if [:log] @log = [:log] if [:debug] debug = true end end connect() unless .empty? end |
Instance Attribute Details
#debug ⇒ Object
for own personal messages
37 38 39 |
# File 'lib/icb.rb', line 37 def debug @debug end |
Instance Method Details
#close ⇒ Object
108 109 110 111 112 |
# File 'lib/icb.rb', line 108 def close if @socket @socket.close end end |
#connect(options) ⇒ Object
Connect to a server and send our login packet. keys: host port user nick group cmd passwd
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/icb.rb', line 97 def connect() @options = @host = [:host] || DEF_HOST @port = [:port] || DEF_PORT @log.debug "Connecting to #{@host}:#{@port}" @socket = TCPSocket.new(@host, @port) sendlogin end |
#readmsg ⇒ Object
Read a message from the server and break it into its fields. XXX - timeout to prevent sitting on bad socket?
86 87 88 89 90 91 92 93 |
# File 'lib/icb.rb', line 86 def readmsg # Break up the message. type, buf = recvpacket.unpack("aa*") sendpong if type == M_PING return type, buf.split(DEL) end |
#sendcmd(cmd, *kwargs) ⇒ Object
Server processed command. sendcmd(cmd, args)
70 71 72 |
# File 'lib/icb.rb', line 70 def sendcmd(cmd, *kwargs) sendpacket("#{M_COMMAND}#{cmd}#{DEL}#{kwargs.join(' ')}") end |
#sendopen(txt) ⇒ Object
Open or group wide message.
59 60 61 |
# File 'lib/icb.rb', line 59 def sendopen(txt) sendpacket("#{M_OPEN}#{txt}") end |
#sendpong ⇒ Object
Ping reply.
75 76 77 |
# File 'lib/icb.rb', line 75 def sendpong sendpacket(M_PONG) end |
#sendpriv(nick, msg) ⇒ Object
Private or user-directed message.
64 65 66 |
# File 'lib/icb.rb', line 64 def sendpriv(nick, msg) sendcmd("m", nick, msg) end |
#sendraw(buf) ⇒ Object
Send a raw packet (ie: don’t insert a packet type)
80 81 82 |
# File 'lib/icb.rb', line 80 def sendraw(buf) sendpacket(buf) end |