diff options
author | truelight <truelight@openttd.org> | 2004-12-12 16:04:32 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2004-12-12 16:04:32 +0000 |
commit | b50b664f36a6362d6fe8f1be374617089b21f4ba (patch) | |
tree | fca8d0b096bbb58854b3d8bb840a8213aa9f8395 /network.c | |
parent | 88827672ec6fbeea2d91a956d038ffb4ac4df8cf (diff) | |
download | openttd-b50b664f36a6362d6fe8f1be374617089b21f4ba.tar.xz |
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
unique id (generated via md5)
Diffstat (limited to 'network.c')
-rw-r--r-- | network.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -10,6 +10,7 @@ #include "network_gamelist.h" #include "console.h" /* IConsoleCmdExec */ #include <stdarg.h> /* va_list */ +#include "md5.h" // The listen socket for the server static SOCKET _listensocket; @@ -828,6 +829,7 @@ void NetworkInitGameInfo(void) else ci->client_playas = _local_player + 1; strncpy(ci->client_name, _network_player_name, sizeof(ci->client_name)); + strncpy(ci->unique_id, _network_unique_id, sizeof(ci->unique_id)); } bool NetworkServerStart(void) @@ -1120,6 +1122,28 @@ void NetworkGameLoop(void) NetworkSend(); } +void NetworkGenerateUniqueId() +{ + md5_state_t state; + md5_byte_t digest[16]; + char hex_output[16*2 + 1]; + char coding_string[NETWORK_NAME_LENGTH]; + int di; + + snprintf(coding_string, sizeof(coding_string), "%d%s%d", InteractiveRandom(), "OpenTTD Unique ID", InteractiveRandom()); + + /* Generate the MD5 hash */ + md5_init(&state); + md5_append(&state, coding_string, strlen(coding_string)); + md5_finish(&state, digest); + + for (di = 0; di < 16; ++di) + sprintf(hex_output + di * 2, "%02x", digest[di]); + + /* _network_unique_id is our id */ + snprintf(_network_unique_id, sizeof(_network_unique_id), "%s", hex_output); +} + // This tries to launch the network for a given OS void NetworkStartUp(void) { @@ -1128,6 +1152,10 @@ void NetworkStartUp(void) _network_available = true; _network_dedicated = false; + /* Generate an unique id when there is none yet */ + if (_network_unique_id[0] == '\0') + NetworkGenerateUniqueId(); + memset(&_network_game_info, 0, sizeof(_network_game_info)); /* XXX - Hard number here, because the strings can currently handle no more |