SHARE
TWEET

Untitled

Albus70007 Jan 5th, 2020 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var socket = newSocket(AF_INET, SOCK_STREAM)
  3. socket.connect("localhost", port)
  4. stdout.writeLine("Bot: ", bot.name, " connected to server on address: localhost, on port: ", port)
  5.  
  6.  
  7. proc `%`(p: Bot): JsonNode =
  8.     ## Quick wrapper around the generic JObject constructor.
  9.     result = %[("steer", %p.outputs.steer),
  10.     ("throttle", %p.outputs.throttle),
  11.     ("roll", %p.outputs.roll),
  12.     ("pitch", %p.outputs.pitch),
  13.     ("yaw", %p.outputs.yaw),
  14.     ("jump", %p.outputs.jump),
  15.     ("boost", %p.outputs.boost),
  16.     ("use_item", %p.outputs.use_item),
  17.     ("chat", %p.outputs.chat)]
  18.  
  19. proc recievePacket(): JsonNode =
  20.     var recieved: string = socket.recv(1024)
  21.     echo(recieved)
  22.     var header: string
  23.     header.add(recieved[2..3].toHex())
  24.     header.add(recieved[0..1].toHex())
  25.     recieved = recieved[3..^2]
  26.     echo(header, ", ", fromHex[uint16](header))
  27.  
  28.     while len(recieved).uint16 < fromHex[uint16](header):
  29.         echo("receiving more data...")
  30.         let more_data: string = socket.recv(1024) #Here the program does nothing and just stays like that
  31.         echo("more data received: ")
  32.         echo(more_data)
  33.         recieved.add(more_data)
  34.    
  35.     var packet: JsonNode = json.parseJson(recieved)
  36.     return packet
  37.  
  38. while true:
  39.     echo("once")
  40.     let data: JsonNode = recievePacket() #Inside this function
  41.     echo("twice")
  42.     echo(data)
  43.    
  44.     if data["is_match_ended"].getBool() == true:
  45.         break
  46.     else:
  47.         socket.send(to(%bot, string))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top