From 5bcd7260d3b7645042984a588579408db52727a4 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Tue, 12 Apr 2011 18:29:47 +0200 Subject: [PATCH] pong-bot bugfixes --- games/Pong-bots/ggs-network.rb | 13 ++++++------- games/Pong-bots/pong-bot.rb | 2 ++ games/Pong-bots/test.rb | 24 ++++++++++++++++++++++++ src/ggs_protocol.erl | 1 + 4 files changed, 33 insertions(+), 7 deletions(-) mode change 100644 => 100755 games/Pong-bots/pong-bot.rb create mode 100644 games/Pong-bots/test.rb diff --git a/games/Pong-bots/ggs-network.rb b/games/Pong-bots/ggs-network.rb index 1a1e820..7b61322 100644 --- a/games/Pong-bots/ggs-network.rb +++ b/games/Pong-bots/ggs-network.rb @@ -25,16 +25,15 @@ class GGSNetwork protected def connect(host, port) - gs = TCPSocket.open(host, port) - @socket = gs.accept - Thread.start(@socket) { |s| read(s) } + @socket = TCPSocket.new(host, port) + read end def write(message) @socket.write(message) end - def read(s) + def read loop do headers = {} size = 0 @@ -45,7 +44,7 @@ class GGSNetwork headers[key] = value end - if headers.contains?("Content-Size") + if headers.has_key?("Content-Size") headers["Content-Size"].to_i.times do args << @socket.recv end @@ -56,7 +55,7 @@ class GGSNetwork end def receivedCommand(headers, data) - if headers.contains? "Client-Command" + if headers.has_key? "Client-Command" command = headers["Client-Command"] case command when "hello" @@ -71,7 +70,7 @@ class GGSNetwork def makeMessage(serverOrGame, command, args) message =< [LastMessage|_] = Strings, case LastMessage of "" -> % We have a data section.. Last line should thus be the content length. + % FIXME: the Content-Length doesn't have to be the last Header line [LastMessage, SecondLast | Rest] = Strings, case re:split(SecondLast, ": ", [{return, list}]) of ["Content-Length", X] ->