Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc receivePacket(self: Bot): JsonNode =
- let header: uint16 = rollBytes(self.rootsocket.recv(2))
- let received: string = self.rootsocket.recv(header.int)
- let packet: JsonNode = packedjson.parseJson(received)
- return packet
- proc receive_and_respond*(self: Bot, process_game: proc(game_info: JsonNode): PlayerInputs) =
- echo("looping1")
- let game_info: JsonNode = self.receivePacket()
- echo("looping2")
- for packet in game_info:
- echo("even here", game_info.len)
- echo(packet)
- if packet["type"].getStr() == "Update":
- self.send_inputs(packet, process_game)
- continue
- elif packet["type"].getStr() == "Terminate":
- raise newException(Exception, "Server ended connection")
- else:
- continue
Advertisement
Add Comment
Please, Sign In to add comment