summaryrefslogtreecommitdiff
path: root/console_cmds.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2004-12-13 15:07:33 +0000
committertruelight <truelight@openttd.org>2004-12-13 15:07:33 +0000
commitbff8c0af614f01e19a876201fc4b28d8308a6007 (patch)
tree029adcdd03324420db502f4d1db5a6098ab232fc /console_cmds.c
parent1c4c5ae37037146a4079263ccb0ef20969a33fec (diff)
downloadopenttd-bff8c0af614f01e19a876201fc4b28d8308a6007.tar.xz
(svn r1053) -Change: [Console] Changed 'setservername', 'setpassword', 'protect' and 'name' in:
- set server_pw "password" - set server_name "servername" - set company_pw "password" - set name "playername" (patch by sign_de)
Diffstat (limited to 'console_cmds.c')
-rw-r--r--console_cmds.c167
1 files changed, 99 insertions, 68 deletions
diff --git a/console_cmds.c b/console_cmds.c
index d69cc11ca..8dc46dd1d 100644
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -9,6 +9,7 @@
#include "network_client.h"
#include "network_server.h"
#include "command.h"
+#include "settings.h"
// ** scriptfile handling ** //
@@ -545,87 +546,122 @@ DEF_CONSOLE_CMD(ConSayClient)
return NULL;
}
-DEF_CONSOLE_CMD(ConSetServerName) {
- if (argc == 2) {
- strncpy(_network_server_name, argv[1], 40);
- IConsolePrintF(_iconsole_color_default, "Server-name changed to '%s'", _network_server_name);
- ttd_strlcpy(_network_game_info.server_name, _network_server_name, 40);
- } else if (argc == 1) {
- IConsolePrintF(_iconsole_color_default, "Current server-name is '%s'", _network_server_name);
- IConsolePrint(_iconsole_color_default, " Usage: setservername \"<GameName>\".");
- } else {
- IConsolePrint(_iconsole_color_default, "Unknow usage. Usage: setservername \"<ServerName>\".");
+#endif /* ENABLE_NETWORK */
+
+/* **************************** */
+/* the "set" command */
+/* **************************** */
+
+
+DEF_CONSOLE_CMD(ConSet) {
+ if (argc < 2) {
+ IConsolePrint(_iconsole_color_warning, "Unknonw usage. Usage: set [setting] [value].");
+ return NULL;
}
- return NULL;
-}
-DEF_CONSOLE_CMD(ConClientName) {
- NetworkClientInfo *ci;
- ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
+#ifdef ENABLE_NETWORK
- if (argc == 2 && ci != NULL) {
- if (!_network_server)
- SEND_COMMAND(PACKET_CLIENT_SET_NAME)(argv[1]);
- else {
- if (NetworkFindName(argv[1])) {
- NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, ci->client_name, argv[1]);
- ttd_strlcpy(ci->client_name, argv[1], 40);
- NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
+ // setting the server password
+ if ((strcmp(argv[1],"server_pw") == 0) || (strcmp(argv[1],"server_password") == 0)) {
+ if (!_networking) {
+ IConsolePrintF(_iconsole_color_error,"No network game running");
+ return NULL;
+ }
+ if (argc == 3) {
+ // Change server password
+ if (strncmp(argv[2], "*", 20) == 0) {
+ _network_game_info.server_password[0] = '\0';
+ _network_game_info.use_password = 0;
+ } else {
+ strncpy(_network_game_info.server_password, argv[2], 20);
+ _network_game_info.use_password = 1;
}
+ IConsolePrintF(_iconsole_color_warning, "Game-password changed to '%s'", _network_game_info.server_password);
+ } else {
+ IConsolePrintF(_iconsole_color_default, "Current game-password is set to '%s'", _network_game_info.server_password);
+ IConsolePrint(_iconsole_color_warning, "Usage: set server_pw \"<password>\". Use * as <password> to set no password.");
}
- } else {
- IConsolePrint(_iconsole_color_default, "With 'name' you can change your network-player name.");
- IConsolePrint(_iconsole_color_default, " Usage: name \"<name>\".");
+ return NULL;
}
- return NULL;
-}
-
-DEF_CONSOLE_CMD(ConProtect) {
- // Protect a company with a password
- if (_local_player >= MAX_PLAYERS) {
- IConsolePrintF(_iconsole_color_default, "You have to own a company to make use of this command.");
+ // setting the company password
+ if ((strcmp(argv[1],"company_pw") == 0) || (strcmp(argv[1],"company_password") == 0)) {
+ if (!_networking) {
+ IConsolePrintF(_iconsole_color_error,"No network game running");
+ return NULL;
+ }
+ if (_local_player >= MAX_PLAYERS) {
+ IConsolePrintF(_iconsole_color_default, "You have to own a company to make use of this command.");
+ return NULL;
+ }
+ if (argc == 3) {
+ if (strncmp(argv[2], "*", 20) == 0) {
+ _network_player_info[_local_player].password[0] = '\0';
+ } else {
+ strncpy(_network_player_info[_local_player].password, argv[1], 20);
+ }
+ if (!_network_server)
+ SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
+ IConsolePrintF(_iconsole_color_warning, "Company protected with '%s'", _network_player_info[_local_player].password);
+ } else {
+ IConsolePrint(_iconsole_color_default, "'set company_pw' sets a password on your company, so no-one without the correct password can join.");
+ IConsolePrint(_iconsole_color_warning, "Usage: set company_pw \"<password>\". Use * as <password> to set no password.");
+ }
return NULL;
}
- if (argc == 2) {
- if (strncmp(argv[1], "*", 20) == 0) {
- _network_player_info[_local_player].password[0] = '\0';
+
+ // setting the player name
+ if (strcmp(argv[1],"name") == 0) {
+ NetworkClientInfo *ci;
+
+ if (!_networking) {
+ IConsolePrintF(_iconsole_color_error,"No network game running");
+ return NULL;
+ }
+
+ ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
+
+ if (argc == 3 && ci != NULL) {
+ if (!_network_server)
+ SEND_COMMAND(PACKET_CLIENT_SET_NAME)(argv[2]);
+ else {
+ if (NetworkFindName(argv[2])) {
+ NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, ci->client_name, argv[2]);
+ ttd_strlcpy(ci->client_name, argv[2], 40);
+ NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
+ }
+ }
} else {
- strncpy(_network_player_info[_local_player].password, argv[1], 20);
+ IConsolePrint(_iconsole_color_default, "With 'set name' you can change your network-player name.");
+ IConsolePrint(_iconsole_color_warning, "Usage: set name \"<name>\".");
}
- if (!_network_server)
- SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
- IConsolePrintF(_iconsole_color_default, "Company protected with '%s'", _network_player_info[_local_player].password);
- } else {
- IConsolePrint(_iconsole_color_default, "Protect sets a password on the company, so no-one without the correct password can join.");
- IConsolePrint(_iconsole_color_default, " Usage: protect \"<password>\". Use * as <password> to set no password.");
+ return NULL;
}
- return NULL;
-}
-
-DEF_CONSOLE_CMD(ConSetPassword) {
- if (argc == 2) {
- // Change server password
- if (strncmp(argv[1], "*", 20) == 0) {
- _network_game_info.server_password[0] = '\0';
- _network_game_info.use_password = 0;
+ // setting the server name
+ if (strcmp(argv[1],"server_name") == 0) {
+ if (!_networking) {
+ IConsolePrintF(_iconsole_color_error,"No network game running");
+ return NULL;
+ }
+ if (argc == 3) {
+ strncpy(_network_server_name, argv[2], 40);
+ IConsolePrintF(_iconsole_color_warning, "Server-name changed to '%s'", _network_server_name);
+ ttd_strlcpy(_network_game_info.server_name, _network_server_name, 40);
} else {
- strncpy(_network_game_info.server_password, argv[1], 20);
- _network_game_info.use_password = 1;
+ IConsolePrintF(_iconsole_color_default, "Current server-name is '%s'", _network_server_name);
+ IConsolePrint(_iconsole_color_warning, "Usage: set server_name \"<GameName>\".");
}
- IConsolePrintF(_iconsole_color_default, "Game-password changed to '%s'", _network_game_info.server_password);
- } else if (argc == 1) {
- IConsolePrintF(_iconsole_color_default, "Current game-password is set to '%s'", _network_game_info.server_password);
- IConsolePrint(_iconsole_color_default, " Usage: setpassword \"<password>\". Use * as <password> to set no password.");
- } else {
- IConsolePrint(_iconsole_color_default, "Unknow usage. Usage: setpassword \"<password>\". Use * as <password> to set no password.");
+ return NULL;
}
- return 0;
+#endif
+
+ IConsolePrintF(_iconsole_color_error,"Unknown setting");
+
+ return NULL;
}
-#endif /* ENABLE_NETWORK */
#ifdef _DEBUG
/* ****************************************** */
@@ -682,6 +718,7 @@ void IConsoleStdLibRegister(void)
IConsoleCmdRegister("screenshot", ConScreenShot);
IConsoleCmdRegister("script", ConScript);
IConsoleCmdRegister("scrollto", ConScrollToTile);
+ IConsoleCmdRegister("set", ConSet);
IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE);
@@ -695,15 +732,9 @@ void IConsoleStdLibRegister(void)
IConsoleCmdHook("say_client", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
IConsoleCmdRegister("kick", ConKick);
IConsoleCmdHook("kick", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
- IConsoleCmdRegister("protect", ConProtect);
- IConsoleCmdRegister("name", ConClientName);
IConsoleCmdRegister("connect", ConNetworkConnect);
IConsoleCmdHook("connect", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetServer);
IConsoleCmdRegister("clients", ConNetworkClients);
- IConsoleCmdRegister("setservername", ConSetServerName);
- IConsoleCmdHook("setservername", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
- IConsoleCmdRegister("setpassword", ConSetPassword);
- IConsoleCmdHook("setpassword", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdRegister("status", ConStatus);
IConsoleCmdHook("status", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);