UnpackResult transactionProtocolUnpackAttributeAddress(bitstream_t * bitstream, net_addr_t * address) { TransactionAttributeType attributeType; bitstream_read_uint8(bitstream, &attributeType); if(attributeType != TransactionAttributeTypeAddress) return UnpackInvalid; TransactionAttributeLength attributeLength; bitstream_read_uint8(bitstream, &attributeLength); if(attributeLength != kTransactionAttributeLengthAddress) return UnpackInvalid; unsigned int port; bitstream_read_uint16_endian(bitstream, &port); // Address port unsigned int host; bitstream_read_uint32_endian(bitstream, &host); // Address host net_addr_set(address, host, port, false); return UnpackValid; }
int main (int argc, char **argv) { net_addr remote; int serial; int net; graphics_initialise (); graphics_mode (0); serial = serial_open (); net = net_open (); if (argc != 1) { if (argc != 2) { fprintf (stderr, "only 1 or 0 args\n"); return 1; } if (strcmp (argv[1], "--final")) { fprintf (stderr, "unrecognised option\n"); return 1; } } else randomised = true; printf ("randomised: %d\n", randomised); while (serial_ready (serial)) serial_discard (serial); net_addr_set (&remote, "10.0.0.2"); while (true) { bool ended; /* wait for user */ reset_the_physics (true); publish_the_physics (serial, net, &remote); graphics_render (0, 0); while (!serial_ready (serial)) check_sdl (); reset_the_physics (false); ended = false; while (!ended) { serial_read (serial); poll (NULL, 0, 10); ended = physics_update (); publish_the_physics (serial, net, &remote); check_sdl (); graphics_render (0, 0); } while (check_sdl () != ' ') poll (NULL, 0, 10); while (serial_ready (serial)) serial_read (serial); } }