From 5f7ecaecdbd81cb0d40fb5da7f7035b0b8331538 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sat, 15 Jan 2011 00:03:57 +0100 Subject: added functions for receiving/sending hello messages and sending list of usernames --- src/net.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/net.h | 3 ++ 2 files changed, 103 insertions(+) diff --git a/src/net.c b/src/net.c index 627f2b0..0eea8a9 100644 --- a/src/net.c +++ b/src/net.c @@ -106,6 +106,27 @@ int* server_get_players(int serversock, const uint8_t count) return clientsocks; } +/** + * Client side function; Send hello to server + * @param[in] sock Socket to use + * @param[in] username Username of player + */ +void client_hello(int sock, const char* username) +{ + uint8_t* buf; + uint8_t namelen = strlen(username); + + buf = malloc(namelen+2); // type + len + username + + buf[0] = CLIENT_HELLO; + buf[1] = namelen; + memcpy(buf+2, username, namelen); + + send(sock, buf, namelen+2, 0); + + free(buf); +} + /** * Client side function; connects to specified host:port * @param[in] host Hostname of server @@ -155,3 +176,82 @@ int client_connect_server(const char* host, const char* port) } +void server_start_game(int* clients, const uint8_t clientcount, const char* usernames[]) +{ + uint8_t* buf; + uint8_t usercount = clientcount + 1; // 1 more user (server) than clients + uint32_t pos = 0; + uint32_t buflen = 2 + usercount; // type + usercount + (usercount * len) + + for(int i=0; i