Code Search for Developers
 
 
  

wire-demo.rb from Thousand Parsec at Krugle


Show wire-demo.rb syntax highlighted


require 'packet'
include TPProto

XMLParser.define_packets_from_xml 'protocol.xml'

def wire_to_hex s
  s.unpack('C*').map {|c| ('0' + c.to_s(16))[-2,2] }.join('').gsub(/..../){|m|m+' '}
end
def hex_to_wire s
  s.gsub(/\s+/, '').gsub(/../){|m|m+' '}.split(' ').map{|c|c.to_i(16)}.pack('C*')
end

raw_wire = '5450 3033 0000 0002 0000 0001 0000 000f 0000 0004 0000 0007 7370 6c61 7421 00'

t = Okay.new('all good!')
f = Fail.new(Fail::Code::NoSuchThing, 'splat!')

t2 = Okay.from_wire(t.to_wire)
puts wire_to_hex(t.to_wire)
p t
puts wire_to_hex(f.to_wire)
p f

p Header.load(hex_to_wire(raw_wire))





See more files for this project here

Thousand Parsec

Thousand Parsec is a framework for turn based 4 X\'s game (eXplore, eXpand, eXploit, eXterminate). Designed for long games, supporting massive universes and has an easily expanded tech tree.

Project homepage: http://sourceforge.net/projects/thousandparsec
Programming language(s): C++,Python
License: other

  client.rb
  libtpproto-rb.tailor
  pack.rb
  packet.rb
  socket_support.rb
  test_client_help.rb
  test_server.rb
  wire-demo.rb