From: "Ari Brown said:
I just don't want to have to install a bunch of libraries on a bunch
of different computers to craft packets. Just looking for a simple In-
Ruby method of doing custom packets.
No, not really. Just basic usage.
Alright. Well I was asking for specifics because your answer
would dictate which approach I would recommend.
For now I will take you literally when you say you want to do
"custom packets".
For that, you'd generally use the UDP transport layer.
http://en.wikipedia.org/wiki/Transport_layer
http://en.wikipedia.org/wiki/TCP/IP_reference_model
Here is a ruby example using UDP to create a custom packet, and
query the status of a public Quake II server:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/env ruby
require 'socket'
abort "Usage: server_addr, server_port, cmd_str" unless ARGV.length == 3
UDP_RECV_TIMEOUT = 3 # seconds
def q2cmd(server_addr, server_port, cmd_str)
resp, sock = nil, nil
begin
cmd = "\377\377\377\377#{cmd_str}\0"
sock = UDPSocket.open
sock.send(cmd, 0, server_addr, server_port)
resp = if select([sock], nil, nil, UDP_RECV_TIMEOUT)
sock.recvfrom(65536)
end
if resp
resp[0] = resp[0][4..-1] # trim leading 0xffffffff
end
rescue IOError, SystemCallError
ensure
sock.close if sock
end
resp ? resp[0] : nil
end
server, port, cmd = *ARGV
result = q2cmd(server, port, cmd)
puts result
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ ruby q2cmd.rb tastyspleen.net 27912 status
print
\Q2Admin\1.17.44-tsmod-2\mapname\outpost\anticheat\1\maxspectators\5\gamedate\
May 24 2007\gamename\baseq2\INFO2\NO BOTS, HACKS, CHETS PLEASE\INFO1\
All Skill Levels Welcome\cheats\0\timelimit\20\fraglimit\30\dmflags\16404\
deathmatch\1\version\R1Q2 b7260 i386 Feb 6 2007 Linux\
hostname\tastyspleen.net::vanilla\maxclients\32
0 10 "WallFly[BZZZ]"
18 61 "PeterCottontail"
7 131 "Jago"
0 84 "Turbojugend"
0 22 "crusty"
13 129 "Pnshr"
8 45 "Scratch"
19 61 "Thief"
4 223 "Javier"
0 0 "ScrotBag_Nut"
0 44 "_DrinA_AK-47_"
10 60 "Fore[SIR]"
22 56 "ANALGASSES{KEA}"
16 205 "{TNP}Dukie"
5 146 "Hacho"
10 75 "M^leSkinner BS"
0 133 "M][M Prototype"
8 64 "gro~~ovy"
4 129 "St George"
7 76 "Windows Vista"
Note: If you use UDP, you will need to understand that the packets
you send may or may not arrive at the remote end. Specifically,
they may arrive:
- not at all
- multiple times (duplicates)
- out of sequence
Does this sound like what you were looking for? Or did you have
something else in mind?
Regards,
Bill