Guest User

Untitled

a guest
Feb 4th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
Advertisement
Add Comment
Please, Sign In to add comment