diff --git a/src/cspt-state.c b/src/cspt-state.c index 3311b39..8a9f387 100644 --- a/src/cspt-state.c +++ b/src/cspt-state.c @@ -44,25 +44,21 @@ void doGameTick(struct gameState * state) // Do movement: state->clients[index].xPosition += state->clients[index].xVelocity; state->clients[index].yPosition += state->clients[index].yVelocity; - if(state->clients[index].xPosition > 1000) + if(state->clients[index].xPosition > 512) { - state->clients[index].xPosition = 1000; - state->clients[index].xVelocity = 0; + state->clients[index].xPosition = 0; } if(state->clients[index].xPosition < 0) { - state->clients[index].xPosition = 0; - state->clients[index].xVelocity = 0; + state->clients[index].xPosition = 512; } - if(state->clients[index].yPosition > 1000) + if(state->clients[index].yPosition > 512) { - state->clients[index].yPosition = 1000; - state->clients[index].yVelocity = 0; + state->clients[index].yPosition = 0; } if(state->clients[index].yPosition < 0) { - state->clients[index].yPosition = 0; - state->clients[index].yVelocity = 0; + state->clients[index].yPosition = 512; } } } diff --git a/src/server/cspt-server.c b/src/server/cspt-server.c index adc45dd..0d436f7 100644 --- a/src/server/cspt-server.c +++ b/src/server/cspt-server.c @@ -62,7 +62,10 @@ void * networkThreadHandler(void * arguments) while (true) { returnvalue = recvfrom(*(args.udpSocket), args.message, sizeof(struct clientInput), 0, (struct sockaddr *)&clientAddress, &test); - memcpy(&(args.clientAddresses[args.message->clientNumber]), &clientAddress, sizeof(struct sockaddr_in)); + if (args.message->clientNumber < 16 && args.message->clientNumber > -1) + { + memcpy(&(args.clientAddresses[args.message->clientNumber]), &clientAddress, sizeof(struct sockaddr_in)); + } if(returnvalue > 0) { @@ -114,8 +117,7 @@ int main(int argc, char ** argv) signal(SIGINT, sigintHandler); pthread_create(&networkThread, NULL, networkThreadHandler, globalState); pthread_create(&gameThread, NULL, gameThreadHandler, globalState); - - + // Setup TCP Master Socket: printf("Setting up master socket... "); masterSocket = socket(AF_INET, SOCK_STREAM, 0); @@ -237,8 +239,8 @@ int main(int argc, char ** argv) { currentMessage.type = 0; globalState->state->clients[index].registered = true; - globalState->state->clients[index].xPosition = 300; - globalState->state->clients[index].yPosition = 300; + globalState->state->clients[index].xPosition = 256; + globalState->state->clients[index].yPosition = 256; globalState->state->clients[index].xVelocity = 0; globalState->state->clients[index].yVelocity = 0; currentMessage.content = (uint8_t)index;