Files
@ r10454:ba5e39738ffa
Branch filter:
Location: cpp/openttd-patchpack/source/src/console_cmds.cpp
r10454:ba5e39738ffa
39.6 KiB
text/x-c
(svn r14709) -Codechange: make a clearer distinction between 'unique' client identification ids and the indices into the clients/client info arrays.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 | /* $Id$ */
/** @file console_cmds.cpp Implementation of the console hooks. */
#include "stdafx.h"
#include "openttd.h"
#include "console_internal.h"
#include "debug.h"
#include "engine_func.h"
#include "landscape.h"
#include "saveload.h"
#include "variables.h"
#include "network/network.h"
#include "network/network_func.h"
#include "command_func.h"
#include "settings_func.h"
#include "fios.h"
#include "fileio_func.h"
#include "screenshot.h"
#include "genworld.h"
#include "strings_func.h"
#include "viewport_func.h"
#include "window_func.h"
#include "functions.h"
#include "map_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "string_func.h"
#include "company_func.h"
#include "company_base.h"
#include "settings_type.h"
#include "gamelog.h"
#ifdef ENABLE_NETWORK
#include "table/strings.h"
#endif /* ENABLE_NETWORK */
// ** scriptfile handling ** //
static FILE *_script_file;
static bool _script_running;
// ** console command / variable defines ** //
#define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
#define DEF_CONSOLE_HOOK(function) static bool function()
/* **************************** */
/* variable and command hooks */
/* **************************** */
#ifdef ENABLE_NETWORK
static inline bool NetworkAvailable()
{
if (!_network_available) {
IConsoleError("You cannot use this command because there is no network available.");
return false;
}
return true;
}
DEF_CONSOLE_HOOK(ConHookServerOnly)
{
if (!NetworkAvailable()) return false;
if (!_network_server) {
IConsoleError("This command/variable is only available to a network server.");
return false;
}
return true;
}
DEF_CONSOLE_HOOK(ConHookClientOnly)
{
if (!NetworkAvailable()) return false;
if (_network_server) {
IConsoleError("This command/variable is not available to a network server.");
return false;
}
return true;
}
DEF_CONSOLE_HOOK(ConHookNeedNetwork)
{
if (!NetworkAvailable()) return false;
if (!_networking) {
IConsoleError("Not connected. This command/variable is only available in multiplayer.");
return false;
}
return true;
}
DEF_CONSOLE_HOOK(ConHookNoNetwork)
{
if (_networking) {
IConsoleError("This command/variable is forbidden in multiplayer.");
return false;
}
return true;
}
#endif /* ENABLE_NETWORK */
static void IConsoleHelp(const char *str)
{
IConsolePrintF(CC_WARNING, "- %s", str);
}
DEF_CONSOLE_CMD(ConResetEngines)
{
if (argc == 0) {
IConsoleHelp("Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'");
return true;
}
StartupEngines();
return true;
}
#ifdef _DEBUG
DEF_CONSOLE_CMD(ConResetTile)
{
if (argc == 0) {
IConsoleHelp("Reset a tile to bare land. Usage: 'resettile <tile>'");
IConsoleHelp("Tile can be either decimal (34161) or hexadecimal (0x4a5B)");
return true;
}
if (argc == 2) {
uint32 result;
if (GetArgumentInteger(&result, argv[1])) {
DoClearSquare((TileIndex)result);
return true;
}
}
return false;
}
DEF_CONSOLE_CMD(ConStopAllVehicles)
{
if (argc == 0) {
IConsoleHelp("Stops all vehicles in the game. For debugging only! Use at your own risk... Usage: 'stopall'");
return true;
}
StopAllVehicles();
return true;
}
#endif /* _DEBUG */
DEF_CONSOLE_CMD(ConScrollToTile)
{
if (argc == 0) {
IConsoleHelp("Center the screen on a given tile. Usage: 'scrollto <tile>'");
IConsoleHelp("Tile can be either decimal (34161) or hexadecimal (0x4a5B)");
return true;
}
if (argc == 2) {
uint32 result;
if (GetArgumentInteger(&result, argv[1])) {
if (result >= MapSize()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
return true;
}
ScrollMainWindowToTile((TileIndex)result);
return true;
}
}
return false;
}
extern void BuildFileList();
extern void SetFiosType(const byte fiostype);
/* Save the map to a file */
DEF_CONSOLE_CMD(ConSave)
{
if (argc == 0) {
IConsoleHelp("Save the current game. Usage: 'save <filename>'");
return true;
}
if (argc == 2) {
char *filename = str_fmt("%s.sav", argv[1]);
IConsolePrint(CC_DEFAULT, "Saving map...");
if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) {
IConsolePrint(CC_ERROR, "Saving map failed");
} else {
IConsolePrintF(CC_DEFAULT, "Map sucessfully saved to %s", filename);
}
free(filename);
return true;
}
return false;
}
/* Explicitly save the configuration */
DEF_CONSOLE_CMD(ConSaveConfig)
{
if (argc == 0) {
IConsoleHelp("Saves the current config, typically to 'openttd.cfg'.");
return true;
}
SaveToConfig();
IConsolePrint(CC_DEFAULT, "Saved config.");
return true;
}
static const FiosItem* GetFiosItem(const char* file)
{
_saveload_mode = SLD_LOAD_GAME;
BuildFileList();
for (const FiosItem *item = _fios_items.Begin(); item != _fios_items.End(); item++) {
if (strcmp(file, item->name) == 0) return item;
if (strcmp(file, item->title) == 0) return item;
}
/* If no name matches, try to parse it as number */
char *endptr;
int i = strtol(file, &endptr, 10);
if (file == endptr || *endptr != '\0') i = -1;
return IsInsideMM(i, 0, _fios_items.Length()) ? _fios_items.Get(i) : NULL;
}
DEF_CONSOLE_CMD(ConLoad)
{
if (argc == 0) {
IConsoleHelp("Load a game by name or index. Usage: 'load <file | number>'");
return true;
}
if (argc != 2) return false;
const char *file = argv[1];
const FiosItem *item = GetFiosItem(file);
if (item != NULL) {
switch (item->type) {
case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: {
_switch_mode = SM_LOAD;
SetFiosType(item->type);
strecpy(_file_to_saveload.name, FiosBrowseTo(item), lastof(_file_to_saveload.name));
strecpy(_file_to_saveload.title, item->title, lastof(_file_to_saveload.title));
} break;
default: IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
}
} else {
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
}
FiosFreeSavegameList();
return true;
}
DEF_CONSOLE_CMD(ConRemove)
{
if (argc == 0) {
IConsoleHelp("Remove a savegame by name or index. Usage: 'rm <file | number>'");
return true;
}
if (argc != 2) return false;
const char *file = argv[1];
const FiosItem *item = GetFiosItem(file);
if (item != NULL) {
if (!FiosDelete(item->name))
IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
} else {
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
}
FiosFreeSavegameList();
return true;
}
/* List all the files in the current dir via console */
DEF_CONSOLE_CMD(ConListFiles)
{
if (argc == 0) {
IConsoleHelp("List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'");
return true;
}
BuildFileList();
for (uint i = 0; i < _fios_items.Length(); i++) {
IConsolePrintF(CC_DEFAULT, "%d) %s", i, _fios_items[i].title);
}
FiosFreeSavegameList();
return true;
}
/* Change the dir via console */
DEF_CONSOLE_CMD(ConChangeDirectory)
{
if (argc == 0) {
IConsoleHelp("Change the dir via console. Usage: 'cd <directory | number>'");
return true;
}
if (argc != 2) return false;
const char *file = argv[1];
const FiosItem *item = GetFiosItem(file);
if (item != NULL) {
switch (item->type) {
case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
FiosBrowseTo(item);
break;
default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
}
} else {
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
}
FiosFreeSavegameList();
return true;
}
DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
{
const char *path;
if (argc == 0) {
IConsoleHelp("Print out the current working directory. Usage: 'pwd'");
return true;
}
// XXX - Workaround for broken file handling
FiosGetSavegameList(SLD_LOAD_GAME);
FiosFreeSavegameList();
FiosGetDescText(&path, NULL);
IConsolePrint(CC_DEFAULT, path);
return true;
}
DEF_CONSOLE_CMD(ConClearBuffer)
{
if (argc == 0) {
IConsoleHelp("Clear the console buffer. Usage: 'clear'");
return true;
}
IConsoleClearBuffer();
InvalidateWindow(WC_CONSOLE, 0);
return true;
}
// ********************************* //
// * Network Core Console Commands * //
// ********************************* //
#ifdef ENABLE_NETWORK
DEF_CONSOLE_CMD(ConBan)
{
NetworkClientInfo *ci;
const char *banip = NULL;
ClientID client_id;
if (argc == 0) {
IConsoleHelp("Ban a client from a network game. Usage: 'ban <ip | client-id>'");
IConsoleHelp("For client-id's, see the command 'clients'");
IConsoleHelp("If the client is no longer online, you can still ban his/her IP");
return true;
}
if (argc != 2) return false;
if (strchr(argv[1], '.') == NULL) { // banning with ID
client_id = (ClientID)atoi(argv[1]);
ci = NetworkFindClientInfoFromIndex(client_id);
} else { // banning IP
ci = NetworkFindClientInfoFromIP(argv[1]);
if (ci == NULL) {
banip = argv[1];
client_id = (ClientID)-1;
} else {
client_id = ci->client_id;
}
}
if (client_id == CLIENT_ID_SERVER) {
IConsoleError("Silly boy, you can not ban yourself!");
return true;
}
if (client_id == INVALID_CLIENT_ID || (ci == NULL && client_id != (ClientID)-1)) {
IConsoleError("Invalid client");
return true;
}
if (ci != NULL) {
IConsolePrint(CC_DEFAULT, "Client banned");
banip = GetClientIP(ci);
NetworkServerSendError(client_id, NETWORK_ERROR_KICKED);
} else {
IConsolePrint(CC_DEFAULT, "Client not online, banned IP");
}
/* Add user to ban-list */
for (uint index = 0; index < lengthof(_network_ban_list); index++) {
if (_network_ban_list[index] == NULL) {
_network_ban_list[index] = strdup(banip);
break;
}
}
return true;
}
DEF_CONSOLE_CMD(ConUnBan)
{
uint i, index;
if (argc == 0) {
IConsoleHelp("Unban a client from a network game. Usage: 'unban <ip | client-id>'");
IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
return true;
}
if (argc != 2) return false;
index = (strchr(argv[1], '.') == NULL) ? atoi(argv[1]) : 0;
index--;
for (i = 0; i < lengthof(_network_ban_list); i++) {
if (_network_ban_list[i] == NULL) continue;
if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) {
free(_network_ban_list[i]);
_network_ban_list[i] = NULL;
IConsolePrint(CC_DEFAULT, "IP unbanned.");
return true;
}
}
IConsolePrint(CC_DEFAULT, "IP not in ban-list.");
return true;
}
DEF_CONSOLE_CMD(ConBanList)
{
uint i;
if (argc == 0) {
IConsoleHelp("List the IP's of banned clients: Usage 'banlist'");
return true;
}
IConsolePrint(CC_DEFAULT, "Banlist: ");
for (i = 0; i < lengthof(_network_ban_list); i++) {
if (_network_ban_list[i] != NULL)
IConsolePrintF(CC_DEFAULT, " %d) %s", i + 1, _network_ban_list[i]);
}
return true;
}
DEF_CONSOLE_CMD(ConPauseGame)
{
if (argc == 0) {
IConsoleHelp("Pause a network game. Usage: 'pause'");
return true;
}
if (_pause_game == 0) {
DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
IConsolePrint(CC_DEFAULT, "Game paused.");
} else {
IConsolePrint(CC_DEFAULT, "Game is already paused.");
}
return true;
}
DEF_CONSOLE_CMD(ConUnPauseGame)
{
if (argc == 0) {
IConsoleHelp("Unpause a network game. Usage: 'unpause'");
return true;
}
if (_pause_game != 0) {
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
IConsolePrint(CC_DEFAULT, "Game unpaused.");
} else {
IConsolePrint(CC_DEFAULT, "Game is already unpaused.");
}
return true;
}
DEF_CONSOLE_CMD(ConRcon)
{
if (argc == 0) {
IConsoleHelp("Remote control the server from another client. Usage: 'rcon <password> <command>'");
IConsoleHelp("Remember to enclose the command in quotes, otherwise only the first parameter is sent");
return true;
}
if (argc < 3) return false;
if (_network_server) {
IConsoleCmdExec(argv[2]);
} else {
NetworkClientSendRcon(argv[1], argv[2]);
}
return true;
}
DEF_CONSOLE_CMD(ConStatus)
{
if (argc == 0) {
IConsoleHelp("List the status of all clients connected to the server. Usage 'status'");
return true;
}
NetworkServerShowStatusToConsole();
return true;
}
DEF_CONSOLE_CMD(ConServerInfo)
{
if (argc == 0) {
IConsoleHelp("List current and maximum client/company limits. Usage 'server_info'");
IConsoleHelp("You can change these values by setting the variables 'max_clients', 'max_companies' and 'max_spectators'");
return true;
}
IConsolePrintF(CC_DEFAULT, "Current/maximum clients: %2d/%2d", _network_game_info.clients_on, _settings_client.network.max_clients);
IConsolePrintF(CC_DEFAULT, "Current/maximum companies: %2d/%2d", ActiveCompanyCount(), _settings_client.network.max_companies);
IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), _settings_client.network.max_spectators);
return true;
}
DEF_CONSOLE_CMD(ConKick)
{
NetworkClientInfo *ci;
ClientID client_id;
if (argc == 0) {
IConsoleHelp("Kick a client from a network game. Usage: 'kick <ip | client-id>'");
IConsoleHelp("For client-id's, see the command 'clients'");
return true;
}
if (argc != 2) return false;
if (strchr(argv[1], '.') == NULL) {
client_id = (ClientID)atoi(argv[1]);
ci = NetworkFindClientInfoFromIndex(client_id);
} else {
ci = NetworkFindClientInfoFromIP(argv[1]);
client_id = (ci == NULL) ? INVALID_CLIENT_ID : ci->client_id;
}
if (client_id == CLIENT_ID_SERVER) {
IConsoleError("Silly boy, you can not kick yourself!");
return true;
}
if (client_id == INVALID_CLIENT_ID) {
IConsoleError("Invalid client");
return true;
}
if (ci != NULL) {
NetworkServerSendError(client_id, NETWORK_ERROR_KICKED);
} else {
IConsoleError("Client not found");
}
return true;
}
DEF_CONSOLE_CMD(ConResetCompany)
{
CompanyID index;
if (argc == 0) {
IConsoleHelp("Remove an idle company from the game. Usage: 'reset_company <company-id>'");
IConsoleHelp("For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
return true;
}
if (argc != 2) return false;
index = (CompanyID)(atoi(argv[1]) - 1);
/* Check valid range */
if (!IsValidCompanyID(index)) {
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
return true;
}
const Company *c = GetCompany(index);
if (c->is_ai) {
IConsoleError("Company is owned by an AI.");
return true;
}
if (NetworkCompanyHasClients(index)) {
IConsoleError("Cannot remove company: a client is connected to that company.");
return false;
}
const NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(CLIENT_ID_SERVER);
if (ci->client_playas == index) {
IConsoleError("Cannot remove company: the server is connected to that company.");
return true;
}
/* It is safe to remove this company */
DoCommandP(0, 2, index, NULL, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "Company deleted.");
return true;
}
DEF_CONSOLE_CMD(ConNetworkClients)
{
NetworkClientInfo *ci;
if (argc == 0) {
IConsoleHelp("Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
return true;
}
FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s",
ci->client_id, ci->client_name,
ci->client_playas + (IsValidCompanyID(ci->client_playas) ? 1 : 0),
GetClientIP(ci));
}
return true;
}
DEF_CONSOLE_CMD(ConNetworkConnect)
{
char *ip;
const char *port = NULL;
const char *company = NULL;
uint16 rport;
if (argc == 0) {
IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
IConsoleHelp("IP can contain port and company: 'IP[[#Company]:Port]', eg: 'server.ottd.org#2:443'");
IConsoleHelp("Company #255 is spectator all others are a certain company with Company 1 being #1");
return true;
}
if (argc < 2) return false;
if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
ip = argv[1];
/* Default settings: default port and new company */
rport = NETWORK_DEFAULT_PORT;
_network_playas = COMPANY_NEW_COMPANY;
ParseConnectionString(&company, &port, ip);
IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
if (company != NULL) {
_network_playas = (CompanyID)atoi(company);
IConsolePrintF(CC_DEFAULT, " company-no: %d", _network_playas);
/* From a user pov 0 is a new company, internally it's different and all
* companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
if (_network_playas != COMPANY_SPECTATOR) {
_network_playas--;
if (!IsValidCompanyID(_network_playas)) return false;
}
}
if (port != NULL) {
rport = atoi(port);
IConsolePrintF(CC_DEFAULT, " port: %s", port);
}
NetworkClientConnectGame(ip, rport);
return true;
}
#endif /* ENABLE_NETWORK */
/* ******************************** */
/* script file console commands */
/* ******************************** */
DEF_CONSOLE_CMD(ConExec)
{
char cmdline[ICON_CMDLN_SIZE];
char *cmdptr;
if (argc == 0) {
IConsoleHelp("Execute a local script file. Usage: 'exec <script> <?>'");
return true;
}
if (argc < 2) return false;
_script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
if (_script_file == NULL) {
if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
return true;
}
_script_running = true;
while (_script_running && fgets(cmdline, sizeof(cmdline), _script_file) != NULL) {
/* Remove newline characters from the executing script */
for (cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
if (*cmdptr == '\n' || *cmdptr == '\r') {
*cmdptr = '\0';
break;
}
}
IConsoleCmdExec(cmdline);
}
if (ferror(_script_file))
IConsoleError("Encountered errror while trying to read from script file");
_script_running = false;
FioFCloseFile(_script_file);
return true;
}
DEF_CONSOLE_CMD(ConReturn)
{
if (argc == 0) {
IConsoleHelp("Stop executing a running script. Usage: 'return'");
return true;
}
_script_running = false;
return true;
}
/* **************************** */
/* default console commands */
/* **************************** */
extern bool CloseConsoleLogIfActive();
DEF_CONSOLE_CMD(ConScript)
{
extern FILE* _iconsole_output_file;
if (argc == 0) {
IConsoleHelp("Start or stop logging console output to a file. Usage: 'script <filename>'");
IConsoleHelp("If filename is omitted, a running log is stopped if it is active");
return true;
}
if (!CloseConsoleLogIfActive()) {
if (argc < 2) return false;
IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
_iconsole_output_file = fopen(argv[1], "ab");
if (_iconsole_output_file == NULL) IConsoleError("could not open file");
}
return true;
}
DEF_CONSOLE_CMD(ConEcho)
{
if (argc == 0) {
IConsoleHelp("Print back the first argument to the console. Usage: 'echo <arg>'");
return true;
}
if (argc < 2) return false;
IConsolePrint(CC_DEFAULT, argv[1]);
return true;
}
DEF_CONSOLE_CMD(ConEchoC)
{
if (argc == 0) {
IConsoleHelp("Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'");
return true;
}
if (argc < 3) return false;
IConsolePrint((ConsoleColour)atoi(argv[1]), argv[2]);
return true;
}
DEF_CONSOLE_CMD(ConNewGame)
{
if (argc == 0) {
IConsoleHelp("Start a new game. Usage: 'newgame [seed]'");
IConsoleHelp("The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game.");
return true;
}
StartNewGameWithoutGUI((argc == 2) ? (uint)atoi(argv[1]) : GENERATE_NEW_SEED);
return true;
}
extern void SwitchMode(int new_mode);
DEF_CONSOLE_CMD(ConRestart)
{
if (argc == 0) {
IConsoleHelp("Restart game. Usage: 'restart'");
IConsoleHelp("Restarts a game. It tries to reproduce the exact same map as the game started with.");
return true;
}
/* Don't copy the _newgame pointers to the real pointers, so call SwitchMode directly */
_settings_game.game_creation.map_x = MapLogX();
_settings_game.game_creation.map_y = FindFirstBit(MapSizeY());
SwitchMode(SM_NEWGAME);
return true;
}
DEF_CONSOLE_CMD(ConGetSeed)
{
if (argc == 0) {
IConsoleHelp("Returns the seed used to create this game. Usage: 'getseed'");
IConsoleHelp("The seed can be used to reproduce the exact same map as the game started with.");
return true;
}
IConsolePrintF(CC_DEFAULT, "Generation Seed: %u", _settings_game.game_creation.generation_seed);
return true;
}
DEF_CONSOLE_CMD(ConGetDate)
{
if (argc == 0) {
IConsoleHelp("Returns the current date (day-month-year) of the game. Usage: 'getdate'");
return true;
}
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
return true;
}
DEF_CONSOLE_CMD(ConAlias)
{
IConsoleAlias *alias;
if (argc == 0) {
IConsoleHelp("Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'");
return true;
}
if (argc < 3) return false;
alias = IConsoleAliasGet(argv[1]);
if (alias == NULL) {
IConsoleAliasRegister(argv[1], argv[2]);
} else {
free(alias->cmdline);
alias->cmdline = strdup(argv[2]);
}
return true;
}
DEF_CONSOLE_CMD(ConScreenShot)
{
if (argc == 0) {
IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | no_con]'");
IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create the screenshot");
return true;
}
if (argc > 3) return false;
SetScreenshotType(SC_VIEWPORT);
if (argc > 1) {
if (strcmp(argv[1], "big") == 0 || (argc == 3 && strcmp(argv[2], "big") == 0))
SetScreenshotType(SC_WORLD);
if (strcmp(argv[1], "no_con") == 0 || (argc == 3 && strcmp(argv[2], "no_con") == 0))
IConsoleClose();
}
return true;
}
DEF_CONSOLE_CMD(ConInfoVar)
{
static const char *_icon_vartypes[] = {"boolean", "byte", "uint16", "uint32", "int16", "int32", "string"};
const IConsoleVar *var;
if (argc == 0) {
IConsoleHelp("Print out debugging information about a variable. Usage: 'info_var <var>'");
return true;
}
if (argc < 2) return false;
var = IConsoleVarGet(argv[1]);
if (var == NULL) {
IConsoleError("the given variable was not found");
return true;
}
IConsolePrintF(CC_DEFAULT, "variable name: %s", var->name);
IConsolePrintF(CC_DEFAULT, "variable type: %s", _icon_vartypes[var->type]);
IConsolePrintF(CC_DEFAULT, "variable addr: 0x%X", var->addr);
if (var->hook.access) IConsoleWarning("variable is access hooked");
if (var->hook.pre) IConsoleWarning("variable is pre hooked");
if (var->hook.post) IConsoleWarning("variable is post hooked");
return true;
}
DEF_CONSOLE_CMD(ConInfoCmd)
{
const IConsoleCmd *cmd;
if (argc == 0) {
IConsoleHelp("Print out debugging information about a command. Usage: 'info_cmd <cmd>'");
return true;
}
if (argc < 2) return false;
cmd = IConsoleCmdGet(argv[1]);
if (cmd == NULL) {
IConsoleError("the given command was not found");
return true;
}
IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
IConsolePrintF(CC_DEFAULT, "command proc: 0x%X", cmd->proc);
if (cmd->hook.access) IConsoleWarning("command is access hooked");
if (cmd->hook.pre) IConsoleWarning("command is pre hooked");
if (cmd->hook.post) IConsoleWarning("command is post hooked");
return true;
}
DEF_CONSOLE_CMD(ConDebugLevel)
{
if (argc == 0) {
IConsoleHelp("Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'");
IConsoleHelp("Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'s");
return true;
}
if (argc > 2) return false;
if (argc == 1) {
IConsolePrintF(CC_DEFAULT, "Current debug-level: '%s'", GetDebugString());
} else {
SetDebugString(argv[1]);
}
return true;
}
DEF_CONSOLE_CMD(ConExit)
{
if (argc == 0) {
IConsoleHelp("Exit the game. Usage: 'exit'");
return true;
}
if (_game_mode == GM_NORMAL && _settings_client.gui.autosave_on_exit) DoExitSave();
_exit_game = true;
return true;
}
DEF_CONSOLE_CMD(ConPart)
{
if (argc == 0) {
IConsoleHelp("Leave the currently joined/running game (only ingame). Usage: 'part'");
return true;
}
if (_game_mode != GM_NORMAL) return false;
_switch_mode = SM_MENU;
return true;
}
DEF_CONSOLE_CMD(ConHelp)
{
if (argc == 2) {
const IConsoleCmd *cmd;
const IConsoleVar *var;
const IConsoleAlias *alias;
cmd = IConsoleCmdGet(argv[1]);
if (cmd != NULL) {
cmd->proc(0, NULL);
return true;
}
alias = IConsoleAliasGet(argv[1]);
if (alias != NULL) {
cmd = IConsoleCmdGet(alias->cmdline);
if (cmd != NULL) {
cmd->proc(0, NULL);
return true;
}
IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
return true;
}
var = IConsoleVarGet(argv[1]);
if (var != NULL && var->help != NULL) {
IConsoleHelp(var->help);
return true;
}
IConsoleError("command or variable not found");
return true;
}
IConsolePrint(CC_WARNING, " ---- OpenTTD Console Help ---- ");
IConsolePrint(CC_DEFAULT, " - variables: [command to list all variables: list_vars]");
IConsolePrint(CC_DEFAULT, " set value with '<var> = <value>', use '++/--' to in-or decrement");
IConsolePrint(CC_DEFAULT, " or omit '=' and just '<var> <value>'. get value with typing '<var>'");
IConsolePrint(CC_DEFAULT, " - commands: [command to list all commands: list_cmds]");
IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes");
IConsolePrint(CC_DEFAULT, " like this: '<command> \"string argument with spaces\"'");
IConsolePrint(CC_DEFAULT, " - use 'help <command> | <variable>' to get specific information");
IConsolePrint(CC_DEFAULT, " - scroll console output with shift + (up | down) | (pageup | pagedown))");
IConsolePrint(CC_DEFAULT, " - scroll console input history with the up | down arrows");
IConsolePrint(CC_DEFAULT, "");
return true;
}
DEF_CONSOLE_CMD(ConListCommands)
{
const IConsoleCmd *cmd;
size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all registered commands. Usage: 'list_cmds [<pre-filter>]'");
return true;
}
if (argv[1] != NULL) l = strlen(argv[1]);
for (cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
if (argv[1] == NULL || strncmp(cmd->name, argv[1], l) == 0) {
IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
}
}
return true;
}
DEF_CONSOLE_CMD(ConListVariables)
{
const IConsoleVar *var;
size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all registered variables. Usage: 'list_vars [<pre-filter>]'");
return true;
}
if (argv[1] != NULL) l = strlen(argv[1]);
for (var = _iconsole_vars; var != NULL; var = var->next) {
if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
IConsolePrintF(CC_DEFAULT, "%s", var->name);
}
return true;
}
DEF_CONSOLE_CMD(ConListAliases)
{
const IConsoleAlias *alias;
size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all registered aliases. Usage: 'list_aliases [<pre-filter>]'");
return true;
}
if (argv[1] != NULL) l = strlen(argv[1]);
for (alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
if (argv[1] == NULL || strncmp(alias->name, argv[1], l) == 0)
IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
}
return true;
}
#ifdef ENABLE_NETWORK
DEF_CONSOLE_CMD(ConSay)
{
if (argc == 0) {
IConsoleHelp("Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'");
return true;
}
if (argc != 2) return false;
if (!_network_server) {
NetworkClientSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
} else {
NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], CLIENT_ID_SERVER);
}
return true;
}
DEF_CONSOLE_CMD(ConCompanies)
{
Company *c;
if (argc == 0) {
IConsoleHelp("List the in-game details of all clients connected to the server. Usage 'companies'");
return true;
}
NetworkPopulateCompanyInfo();
FOR_ALL_COMPANIES(c) {
char buffer[512];
const NetworkCompanyInfo *npi = &_network_company_info[c->index];
GetString(buffer, STR_00D1_DARK_BLUE + _company_colours[c->index], lastof(buffer));
IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s' Year Founded: %d Money: %" OTTD_PRINTF64 "d Loan: %" OTTD_PRINTF64 "d Value: %" OTTD_PRINTF64 "d (T:%d, R:%d, P:%d, S:%d) %sprotected",
c->index + 1, buffer, npi->company_name, c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
/* trains */ npi->num_vehicle[0],
/* lorry + bus */ npi->num_vehicle[1] + npi->num_vehicle[2],
/* planes */ npi->num_vehicle[3],
/* ships */ npi->num_vehicle[4],
/* protected */ StrEmpty(npi->password) ? "un" : "");
}
return true;
}
DEF_CONSOLE_CMD(ConSayCompany)
{
if (argc == 0) {
IConsoleHelp("Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'");
IConsoleHelp("CompanyNo is the company that plays as company <companyno>, 1 through max_companies");
return true;
}
if (argc != 3) return false;
CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
if (!IsValidCompanyID(company_id)) {
IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
return true;
}
if (!_network_server) {
NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2]);
} else {
NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2], CLIENT_ID_SERVER);
}
return true;
}
DEF_CONSOLE_CMD(ConSayClient)
{
if (argc == 0) {
IConsoleHelp("Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
IConsoleHelp("For client-id's, see the command 'clients'");
return true;
}
if (argc != 3) return false;
if (!_network_server) {
NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
} else {
NetworkServerSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], CLIENT_ID_SERVER);
}
return true;
}
extern void HashCurrentCompanyPassword();
/* Also use from within company_gui to change the password graphically */
bool NetworkChangeCompanyPassword(byte argc, char *argv[])
{
if (argc == 0) {
if (!IsValidCompanyID(_local_company)) return true; // dedicated server
IConsolePrintF(CC_WARNING, "Current value for 'company_pw': %s", _network_company_info[_local_company].password);
return true;
}
if (!IsValidCompanyID(_local_company)) {
IConsoleError("You have to own a company to make use of this command.");
return false;
}
if (argc != 1) return false;
if (strcmp(argv[0], "*") == 0) argv[0][0] = '\0';
strecpy(_network_company_info[_local_company].password, argv[0], lastof(_network_company_info[_local_company].password));
if (!_network_server) {
NetworkClientSetPassword();
} else {
HashCurrentCompanyPassword();
}
IConsolePrintF(CC_WARNING, "'company_pw' changed to: %s", _network_company_info[_local_company].password);
return true;
}
#endif /* ENABLE_NETWORK */
DEF_CONSOLE_CMD(ConPatch)
{
if (argc == 0) {
IConsoleHelp("Change patch variables for all clients. Usage: 'patch <name> [<value>]'");
IConsoleHelp("Omitting <value> will print out the current value of the patch-setting.");
return true;
}
if (argc == 1 || argc > 3) return false;
if (argc == 2) {
IConsoleGetPatchSetting(argv[1]);
} else {
IConsoleSetPatchSetting(argv[1], argv[2]);
}
return true;
}
DEF_CONSOLE_CMD(ConListPatches)
{
if (argc == 0) {
IConsoleHelp("List patch options. Usage: 'list_patches [<pre-filter>]'");
return true;
}
if (argc > 2) return false;
IConsoleListPatches((argc == 2) ? argv[1] : NULL);
return true;
}
DEF_CONSOLE_CMD(ConListDumpVariables)
{
const IConsoleVar *var;
size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all variables with their value. Usage: 'dump_vars [<pre-filter>]'");
return true;
}
if (argv[1] != NULL) l = strlen(argv[1]);
for (var = _iconsole_vars; var != NULL; var = var->next) {
if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
IConsoleVarPrintGetValue(var);
}
return true;
}
DEF_CONSOLE_CMD(ConGamelogPrint)
{
GamelogPrintConsole();
return true;
}
#ifdef _DEBUG
/* ****************************************** */
/* debug commands and variables */
/* ****************************************** */
static void IConsoleDebugLibRegister()
{
/* debugging variables and functions */
extern bool _stdlib_con_developer; // XXX extern in .cpp
IConsoleVarRegister("con_developer", &_stdlib_con_developer, ICONSOLE_VAR_BOOLEAN, "Enable/disable console debugging information (internal)");
IConsoleCmdRegister("resettile", ConResetTile);
IConsoleCmdRegister("stopall", ConStopAllVehicles);
IConsoleAliasRegister("dbg_echo", "echo %A; echo %B");
IConsoleAliasRegister("dbg_echo2", "echo %!");
}
#endif
/* ****************************************** */
/* console command and variable registration */
/* ****************************************** */
void IConsoleStdLibRegister()
{
/* stdlib */
extern byte _stdlib_developer; // XXX extern in .cpp
/* default variables and functions */
IConsoleCmdRegister("debug_level", ConDebugLevel);
IConsoleCmdRegister("dump_vars", ConListDumpVariables);
IConsoleCmdRegister("echo", ConEcho);
IConsoleCmdRegister("echoc", ConEchoC);
IConsoleCmdRegister("exec", ConExec);
IConsoleCmdRegister("exit", ConExit);
IConsoleCmdRegister("part", ConPart);
IConsoleCmdRegister("help", ConHelp);
IConsoleCmdRegister("info_cmd", ConInfoCmd);
IConsoleCmdRegister("info_var", ConInfoVar);
IConsoleCmdRegister("list_cmds", ConListCommands);
IConsoleCmdRegister("list_vars", ConListVariables);
IConsoleCmdRegister("list_aliases", ConListAliases);
IConsoleCmdRegister("newgame", ConNewGame);
IConsoleCmdRegister("restart", ConRestart);
IConsoleCmdRegister("getseed", ConGetSeed);
IConsoleCmdRegister("getdate", ConGetDate);
IConsoleCmdRegister("quit", ConExit);
IConsoleCmdRegister("resetengines", ConResetEngines);
IConsoleCmdRegister("return", ConReturn);
IConsoleCmdRegister("screenshot", ConScreenShot);
IConsoleCmdRegister("script", ConScript);
IConsoleCmdRegister("scrollto", ConScrollToTile);
IConsoleCmdRegister("alias", ConAlias);
IConsoleCmdRegister("load", ConLoad);
IConsoleCmdRegister("rm", ConRemove);
IConsoleCmdRegister("save", ConSave);
IConsoleCmdRegister("saveconfig", ConSaveConfig);
IConsoleCmdRegister("ls", ConListFiles);
IConsoleCmdRegister("cd", ConChangeDirectory);
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
IConsoleCmdRegister("clear", ConClearBuffer);
IConsoleCmdRegister("patch", ConPatch);
IConsoleCmdRegister("list_patches", ConListPatches);
IConsoleCmdRegister("gamelog", ConGamelogPrint);
IConsoleAliasRegister("dir", "ls");
IConsoleAliasRegister("del", "rm %+");
IConsoleAliasRegister("newmap", "newgame");
IConsoleAliasRegister("new_map", "newgame");
IConsoleAliasRegister("new_game", "newgame");
IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE, "Redirect debugging output from the console/command line to the ingame console (value 2). Default value: 1");
/* networking variables and functions */
#ifdef ENABLE_NETWORK
/* Network hooks; only active in network */
IConsoleCmdHookAdd ("resetengines", ICONSOLE_HOOK_ACCESS, ConHookNoNetwork);
/*** Networking commands ***/
IConsoleCmdRegister("say", ConSay);
IConsoleCmdHookAdd("say", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("companies", ConCompanies);
IConsoleCmdHookAdd("companies", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleAliasRegister("players", "companies");
IConsoleCmdRegister("say_company", ConSayCompany);
IConsoleCmdHookAdd("say_company", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleAliasRegister("say_player", "say_company %+");
IConsoleCmdRegister("say_client", ConSayClient);
IConsoleCmdHookAdd("say_client", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("connect", ConNetworkConnect);
IConsoleCmdHookAdd("connect", ICONSOLE_HOOK_ACCESS, ConHookClientOnly);
IConsoleAliasRegister("join", "connect %A");
IConsoleCmdRegister("clients", ConNetworkClients);
IConsoleCmdHookAdd("clients", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("status", ConStatus);
IConsoleCmdHookAdd("status", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("server_info", ConServerInfo);
IConsoleCmdHookAdd("server_info", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleAliasRegister("info", "server_info");
IConsoleCmdRegister("rcon", ConRcon);
IConsoleCmdHookAdd("rcon", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("reset_company", ConResetCompany);
IConsoleCmdHookAdd("reset_company", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleAliasRegister("clean_company", "reset_company %A");
IConsoleCmdRegister("kick", ConKick);
IConsoleCmdHookAdd("kick", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("ban", ConBan);
IConsoleCmdHookAdd("ban", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("unban", ConUnBan);
IConsoleCmdHookAdd("unban", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("banlist", ConBanList);
IConsoleCmdHookAdd("banlist", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("pause", ConPauseGame);
IConsoleCmdHookAdd("pause", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("unpause", ConUnPauseGame);
IConsoleCmdHookAdd("unpause", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
/*** Networking variables ***/
IConsoleVarStringRegister("company_pw", NULL, 0, "Set a password for your company, so no one without the correct password can join. Use '*' to clear the password");
IConsoleVarHookAdd("company_pw", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleVarProcAdd("company_pw", NetworkChangeCompanyPassword);
IConsoleAliasRegister("company_password", "company_pw %+");
IConsoleAliasRegister("net_frame_freq", "patch frame_freq %+");
IConsoleAliasRegister("net_sync_freq", "patch sync_freq %+");
IConsoleAliasRegister("server_pw", "patch server_password %+");
IConsoleAliasRegister("server_password", "patch server_password %+");
IConsoleAliasRegister("rcon_pw", "patch rcon_password %+");
IConsoleAliasRegister("rcon_password", "patch rcon_password %+");
IConsoleAliasRegister("name", "patch client_name %+");
IConsoleAliasRegister("server_name", "patch server_name %+");
IConsoleAliasRegister("server_port", "patch server_port %+");
IConsoleAliasRegister("server_ip", "patch server_bind_ip %+");
IConsoleAliasRegister("server_bind_ip", "patch server_bind_ip %+");
IConsoleAliasRegister("server_ip_bind", "patch server_bind_ip %+");
IConsoleAliasRegister("server_bind", "patch server_bind_ip %+");
IConsoleAliasRegister("server_advertise", "patch server_advertise %+");
IConsoleAliasRegister("max_clients", "patch max_clients %+");
IConsoleAliasRegister("max_companies", "patch max_companies %+");
IConsoleAliasRegister("max_spectators", "patch max_spectators %+");
IConsoleAliasRegister("max_join_time", "patch max_join_time %+");
IConsoleAliasRegister("pause_on_join", "patch pause_on_join %+");
IConsoleAliasRegister("autoclean_companies", "patch autoclean_companies %+");
IConsoleAliasRegister("autoclean_protected", "patch autoclean_protected %+");
IConsoleAliasRegister("autoclean_unprotected", "patch autoclean_unprotected %+");
IConsoleAliasRegister("restart_game_year", "patch restart_game_year %+");
IConsoleAliasRegister("min_players", "patch min_clients %+");
IConsoleAliasRegister("reload_cfg", "patch reload_cfg %+");
#endif /* ENABLE_NETWORK */
// debugging stuff
#ifdef _DEBUG
IConsoleDebugLibRegister();
#endif
}
|