7 |
7 |
8 #ifdef ENABLE_NETWORK |
8 #ifdef ENABLE_NETWORK |
9 |
9 |
10 #include "../openttd.h" |
10 #include "../openttd.h" |
11 #include "../debug.h" |
11 #include "../debug.h" |
12 #include "../functions.h" |
12 #include "../strings_func.h" |
13 #include "../string.h" |
13 #include "../map_func.h" |
14 #include "../strings.h" |
14 #include "../command_func.h" |
15 #include "../map.h" |
|
16 #include "../command.h" |
|
17 #include "../variables.h" |
15 #include "../variables.h" |
18 #include "../date.h" |
16 #include "../date_func.h" |
19 #include "../newgrf_config.h" |
17 #include "../newgrf_config.h" |
20 #include "table/strings.h" |
18 #include "table/strings.h" |
21 #include "network_client.h" |
19 #include "network_client.h" |
22 #include "network_server.h" |
20 #include "network_server.h" |
23 #include "network_udp.h" |
21 #include "network_udp.h" |
28 #include "network_gui.h" |
26 #include "network_gui.h" |
29 #include "../console.h" /* IConsoleCmdExec */ |
27 #include "../console.h" /* IConsoleCmdExec */ |
30 #include <stdarg.h> /* va_list */ |
28 #include <stdarg.h> /* va_list */ |
31 #include "../md5.h" |
29 #include "../md5.h" |
32 #include "../fileio.h" |
30 #include "../fileio.h" |
|
31 #include "../texteff.hpp" |
|
32 #include "../core/random_func.hpp" |
|
33 #include "../window_func.h" |
|
34 #include "../string_func.h" |
|
35 #ifdef DEBUG_DUMP_COMMANDS |
|
36 #include "../core/alloc_func.hpp" |
|
37 #endif |
33 |
38 |
34 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ |
39 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ |
35 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); |
40 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); |
36 |
41 |
37 // global variables (declared in network_data.h) |
42 // global variables (declared in network_data.h) |
1348 NetworkSend(); |
1353 NetworkSend(); |
1349 } |
1354 } |
1350 |
1355 |
1351 static void NetworkGenerateUniqueId() |
1356 static void NetworkGenerateUniqueId() |
1352 { |
1357 { |
1353 md5_state_t state; |
1358 Md5 checksum; |
1354 md5_byte_t digest[16]; |
1359 uint8 digest[16]; |
1355 char hex_output[16*2 + 1]; |
1360 char hex_output[16*2 + 1]; |
1356 char coding_string[NETWORK_NAME_LENGTH]; |
1361 char coding_string[NETWORK_NAME_LENGTH]; |
1357 int di; |
1362 int di; |
1358 |
1363 |
1359 snprintf(coding_string, sizeof(coding_string), "%d%s", (uint)Random(), "OpenTTD Unique ID"); |
1364 snprintf(coding_string, sizeof(coding_string), "%d%s", (uint)Random(), "OpenTTD Unique ID"); |
1360 |
1365 |
1361 /* Generate the MD5 hash */ |
1366 /* Generate the MD5 hash */ |
1362 md5_init(&state); |
1367 checksum.Append((const uint8*)coding_string, strlen(coding_string)); |
1363 md5_append(&state, (const md5_byte_t*)coding_string, strlen(coding_string)); |
1368 checksum.Finish(digest); |
1364 md5_finish(&state, digest); |
|
1365 |
1369 |
1366 for (di = 0; di < 16; ++di) |
1370 for (di = 0; di < 16; ++di) |
1367 sprintf(hex_output + di * 2, "%02x", digest[di]); |
1371 sprintf(hex_output + di * 2, "%02x", digest[di]); |
1368 |
1372 |
1369 /* _network_unique_id is our id */ |
1373 /* _network_unique_id is our id */ |
1464 } |
1468 } |
1465 |
1469 |
1466 #ifdef DEBUG_DUMP_COMMANDS |
1470 #ifdef DEBUG_DUMP_COMMANDS |
1467 void CDECL debug_dump_commands(const char *s, ...) |
1471 void CDECL debug_dump_commands(const char *s, ...) |
1468 { |
1472 { |
1469 static FILE *f = FioFOpenFile("commands-out.log", "wb", SAVE_DIR); |
1473 static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR); |
1470 if (f == NULL) return; |
1474 if (f == NULL) return; |
1471 |
1475 |
1472 va_list va; |
1476 va_list va; |
1473 va_start(va, s); |
1477 va_start(va, s); |
1474 vfprintf(f, s, va); |
1478 vfprintf(f, s, va); |