SHOW:
|
|
- or go back to the newest paste.
| 1 | - | pastebin/gist |
| 1 | + | proc receivePacket(self: Bot): JsonNode = |
| 2 | let header: uint16 = rollBytes(self.rootsocket.recv(2)) | |
| 3 | let received: string = self.rootsocket.recv(header.int) | |
| 4 | let packet: JsonNode = packedjson.parseJson(received) | |
| 5 | return packet | |
| 6 | ||
| 7 | proc receive_and_respond*(self: Bot, process_game: proc(game_info: JsonNode): PlayerInputs) = | |
| 8 | echo("looping1")
| |
| 9 | let game_info: JsonNode = self.receivePacket() | |
| 10 | echo("looping2")
| |
| 11 | for packet in game_info: | |
| 12 | echo("even here", game_info.len)
| |
| 13 | echo(packet) | |
| 14 | if packet["type"].getStr() == "Update": | |
| 15 | self.send_inputs(packet, process_game) | |
| 16 | continue | |
| 17 | elif packet["type"].getStr() == "Terminate": | |
| 18 | raise newException(Exception, "Server ended connection") | |
| 19 | else: | |
| 20 | continue |