summaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorMario Kilies <MarioKilies@GMX.net>2011-01-15 00:30:56 +0100
committerMario Kilies <MarioKilies@GMX.net>2011-01-15 00:30:56 +0100
commit22a3b4d27084a93197f82c88a8dc954b49672bd9 (patch)
tree0a73531484a3a9d8bb6f94c31753abc85c9ec3af /src/net.c
parenta68b72e60128834e41a09e2aeb3c2faea59384b2 (diff)
parente486953991884606f60d747b0cfb846f576c6bc4 (diff)
Merge branch 'master' of ssh://git@wg.reiner-h.de:22003/~git/oxen
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/net.c b/src/net.c
index 0eea8a9..1b3811d 100644
--- a/src/net.c
+++ b/src/net.c
@@ -84,7 +84,11 @@ int* server_get_players(int serversock, const uint8_t count)
assert(count < MAX_PLAYERS && count > 0);
clientsocks = malloc(count*sizeof(int));
- assert(clientsocks != NULL);
+ if(clientsocks == NULL)
+ {
+ printf("server_get_players: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
// accept connections
for(i=0; i<count; i++)
@@ -117,8 +121,13 @@ void client_hello(int sock, const char* username)
uint8_t namelen = strlen(username);
buf = malloc(namelen+2); // type + len + username
+ if(buf == NULL)
+ {
+ printf("client_hello: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
- buf[0] = CLIENT_HELLO;
+ buf[0] = msg_type_hello;
buf[1] = namelen;
memcpy(buf+2, username, namelen);
@@ -187,7 +196,12 @@ void server_start_game(int* clients, const uint8_t clientcount, const char* user
buflen += strlen(usernames[i]);
buf = malloc(buflen);
- buf[pos++] = SERVER_START_GAME;
+ if(buf == NULL)
+ {
+ printf("server_start_game: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
+ buf[pos++] = msg_type_start_game;
buf[pos++] = clientcount;
// copy usernames with length to buffer
for(int i=0; i<usercount; i++)
@@ -217,11 +231,17 @@ char* server_recv_hello(int sock)
recv(sock, buf, 13, 0);
- assert(buf[0] == CLIENT_HELLO);
+ assert(buf[0] == msg_type_hello);
namelen = buf[1];
name = malloc(namelen+1);
- strncpy(name, buf+2, namelen);
+ if(name == NULL)
+ {
+ printf("sender_recv_hello: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
+
+ memcpy(name, buf+2, namelen);
name[namelen] = '\0';
return name;
@@ -247,7 +267,7 @@ void* server_recv(int sock, uint8_t wanted)
switch(type)
{
- case CLIENT_HELLO:
+ case msg_type_hello:
result = server_recv_hello(sock);
break;
}