Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var socket = newSocket(AF_INET, SOCK_STREAM)
- socket.connect("localhost", port)
- stdout.writeLine("Bot: ", bot.name, " connected to server on address: localhost, on port: ", port)
- proc `%`(p: Bot): JsonNode =
- ## Quick wrapper around the generic JObject constructor.
- result = %[("steer", %p.outputs.steer),
- ("throttle", %p.outputs.throttle),
- ("roll", %p.outputs.roll),
- ("pitch", %p.outputs.pitch),
- ("yaw", %p.outputs.yaw),
- ("jump", %p.outputs.jump),
- ("boost", %p.outputs.boost),
- ("use_item", %p.outputs.use_item),
- ("chat", %p.outputs.chat)]
- proc recievePacket(): JsonNode =
- var recieved: string = socket.recv(1024)
- echo(recieved)
- var header: string
- header.add(recieved[2..3].toHex())
- header.add(recieved[0..1].toHex())
- recieved = recieved[3..^2]
- echo(header, ", ", fromHex[uint16](header))
- while len(recieved).uint16 < fromHex[uint16](header):
- echo("receiving more data...")
- let more_data: string = socket.recv(1024) #Here the program does nothing and just stays like that
- echo("more data received: ")
- echo(more_data)
- recieved.add(more_data)
- var packet: JsonNode = json.parseJson(recieved)
- return packet
- while true:
- echo("once")
- let data: JsonNode = recievePacket() #Inside this function
- echo("twice")
- echo(data)
- if data["is_match_ended"].getBool() == true:
- break
- else:
- socket.send(to(%bot, string))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement