35 #include "core/core.h" |
35 #include "core/core.h" |
36 #include "network_gui.h" |
36 #include "network_gui.h" |
37 #include "../console.h" /* IConsoleCmdExec */ |
37 #include "../console.h" /* IConsoleCmdExec */ |
38 #include <stdarg.h> /* va_list */ |
38 #include <stdarg.h> /* va_list */ |
39 #include "../md5.h" |
39 #include "../md5.h" |
|
40 #include "../fileio.h" |
40 |
41 |
41 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ |
42 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ |
42 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); |
43 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); |
43 |
44 |
44 // global variables (declared in network_data.h) |
45 // global variables (declared in network_data.h) |
193 GetString(temp, STR_NETWORK_CHAT_ALL, lastof(temp)); |
194 GetString(temp, STR_NETWORK_CHAT_ALL, lastof(temp)); |
194 ttd_strlcpy(message, temp, sizeof(message)); |
195 ttd_strlcpy(message, temp, sizeof(message)); |
195 break; |
196 break; |
196 } |
197 } |
197 |
198 |
|
199 #ifdef DEBUG_DUMP_COMMANDS |
|
200 debug_dump_commands("ddc:cmsg:%d;%d;%s\n", _date, _date_fract, message); |
|
201 #endif /* DUMP_COMMANDS */ |
198 IConsolePrintF(color, "%s", message); |
202 IConsolePrintF(color, "%s", message); |
199 AddTextMessage(color, duration, "%s", message); |
203 AddTextMessage(color, duration, "%s", message); |
200 } |
204 } |
201 |
205 |
202 // Calculate the frame-lag of a client |
206 // Calculate the frame-lag of a client |
1233 if (_sync_seed_1 != _random_seeds[0][0] || _sync_seed_2 != _random_seeds[0][1]) { |
1237 if (_sync_seed_1 != _random_seeds[0][0] || _sync_seed_2 != _random_seeds[0][1]) { |
1234 #else |
1238 #else |
1235 if (_sync_seed_1 != _random_seeds[0][0]) { |
1239 if (_sync_seed_1 != _random_seeds[0][0]) { |
1236 #endif |
1240 #endif |
1237 NetworkError(STR_NETWORK_ERR_DESYNC); |
1241 NetworkError(STR_NETWORK_ERR_DESYNC); |
|
1242 #ifdef DEBUG_DUMP_COMMANDS |
|
1243 debug_dump_commands("ddc:serr:%d;%d\n", _date, _date_fract); |
|
1244 #endif /* DUMP_COMMANDS */ |
1238 DEBUG(net, 0, "Sync error detected!"); |
1245 DEBUG(net, 0, "Sync error detected!"); |
1239 NetworkClientError(NETWORK_RECV_STATUS_DESYNC, DEREF_CLIENT(0)); |
1246 NetworkClientError(NETWORK_RECV_STATUS_DESYNC, DEREF_CLIENT(0)); |
1240 return false; |
1247 return false; |
1241 } |
1248 } |
1242 |
1249 |
1278 if (!_networking) return; |
1285 if (!_networking) return; |
1279 |
1286 |
1280 if (!NetworkReceive()) return; |
1287 if (!NetworkReceive()) return; |
1281 |
1288 |
1282 if (_network_server) { |
1289 if (_network_server) { |
|
1290 #ifdef DEBUG_DUMP_COMMANDS |
|
1291 static FILE *f = FioFOpenFile("commands.log", "rb", SAVE_DIR); |
|
1292 static Date next_date = 0; |
|
1293 static uint32 next_date_fract; |
|
1294 static CommandPacket *cp = NULL; |
|
1295 if (f == NULL && next_date == 0) { |
|
1296 printf("Cannot open commands.log\n"); |
|
1297 next_date = 1; |
|
1298 } |
|
1299 |
|
1300 while (f != NULL && !feof(f)) { |
|
1301 if (cp != NULL && _date == next_date && _date_fract == next_date_fract) { |
|
1302 _current_player = cp->player; |
|
1303 _cmd_text = cp->text; |
|
1304 DoCommandP(cp->tile, cp->p1, cp->p2, NULL, cp->cmd); |
|
1305 free(cp); |
|
1306 cp = NULL; |
|
1307 } |
|
1308 |
|
1309 if (cp != NULL) break; |
|
1310 |
|
1311 char buff[4096]; |
|
1312 if (fgets(buff, lengthof(buff), f) == NULL) break; |
|
1313 if (strncmp(buff, "ddc:cmd:", 8) != 0) continue; |
|
1314 cp = MallocT<CommandPacket>(1); |
|
1315 int player; |
|
1316 sscanf(&buff[8], "%d;%d;%d;%d;%d;%d;%d;%s", &next_date, &next_date_fract, &player, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, cp->text); |
|
1317 cp->player = (Owner)player; |
|
1318 } |
|
1319 #endif /* DUMP_COMMANDS */ |
|
1320 |
1283 bool send_frame = false; |
1321 bool send_frame = false; |
1284 |
1322 |
1285 // We first increase the _frame_counter |
1323 // We first increase the _frame_counter |
1286 _frame_counter++; |
1324 _frame_counter++; |
1287 // Update max-frame-counter |
1325 // Update max-frame-counter |
1430 * @param other the version string to compare to |
1468 * @param other the version string to compare to |
1431 */ |
1469 */ |
1432 bool IsNetworkCompatibleVersion(const char *other) |
1470 bool IsNetworkCompatibleVersion(const char *other) |
1433 { |
1471 { |
1434 extern const char _openttd_revision[]; |
1472 extern const char _openttd_revision[]; |
1435 return strncmp(NOREV_STRING, other, NETWORK_REVISION_LENGTH - 1) == 0 || |
1473 return strncmp(_openttd_revision, other, NETWORK_REVISION_LENGTH - 1) == 0; |
1436 strncmp(_openttd_revision, other, NETWORK_REVISION_LENGTH - 1) == 0; |
1474 } |
1437 } |
1475 |
1438 |
1476 #ifdef DEBUG_DUMP_COMMANDS |
|
1477 void CDECL debug_dump_commands(const char *s, ...) |
|
1478 { |
|
1479 static FILE *f = FioFOpenFile("commands-out.log", "wb", SAVE_DIR); |
|
1480 if (f == NULL) return; |
|
1481 |
|
1482 va_list va; |
|
1483 va_start(va, s); |
|
1484 vfprintf(f, s, va); |
|
1485 va_end(va); |
|
1486 |
|
1487 fflush(f); |
|
1488 } |
|
1489 #endif /* DEBUG_DUMP_COMMANDS */ |
1439 #endif /* ENABLE_NETWORK */ |
1490 #endif /* ENABLE_NETWORK */ |