No declaring data inside of switch statement

main
Cameron Murphy Reikes 2 years ago
parent e6e3e68a52
commit 30321fd068

@ -346,9 +346,13 @@ static void frame(void)
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
{
Log("New client from host %x\n", event.peer->address.host);
break;
}
case ENET_EVENT_TYPE_RECEIVE:
{
// @Robust @BeforeShip use some kind of serialization strategy that checks for out of bounds
// and other validation instead of just casting to a struct
// "Alignment of structure members can be different even among different compilers on the same platform, let alone different platforms."
@ -361,11 +365,16 @@ static void frame(void)
myplayer = msg.your_player;
enet_packet_destroy(event.packet);
break;
}
case ENET_EVENT_TYPE_DISCONNECT:
{
fprintf(stderr, "Disconnected from server\n");
exit(-1);
break;
}
}
}
else if (enet_status == 0)
{

@ -78,6 +78,7 @@ void server(void *data)
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
{
Log("A new client connected from %x:%u.\n",
event.peer->address.host,
event.peer->address.port);
@ -104,7 +105,10 @@ void server(void *data)
}
break;
}
case ENET_EVENT_TYPE_RECEIVE:
{
// Log("A packet of length %zu was received on channel %u.\n",
// event.packet->dataLength,
// event.channelID);
@ -156,13 +160,19 @@ void server(void *data)
enet_packet_destroy(event.packet);
break;
}
case ENET_EVENT_TYPE_DISCONNECT:
{
int player_index = (int64_t)event.peer->data;
Log("%" PRId64 " disconnected player index %d.\n", (int64_t)event.peer->data, player_index);
gs.players[player_index].connected = false;
// box_destroy(&gs.players[player_index].box);
event.peer->data = NULL;
break;
}
}
}
}

Loading…
Cancel
Save