|
45 | 45 | #include "wrappers.h" |
46 | 46 | #include "multilobbycommands.h" |
47 | 47 | #include "gamehistorylogger.h" |
| 48 | +#include "stdinreader.h" |
48 | 49 |
|
49 | 50 | #include <cwchar> |
50 | 51 |
|
@@ -89,7 +90,6 @@ static bool wz_autoratingEnable = false; |
89 | 90 | static bool wz_cli_headless = false; |
90 | 91 | static bool wz_streamer_spectator_mode = false; |
91 | 92 | static bool wz_lobby_slashcommands = false; |
92 | | -static WZ_Command_Interface wz_cmd_interface = WZ_Command_Interface::None; |
93 | 93 | static int wz_min_autostart_players = -1; |
94 | 94 |
|
95 | 95 | #if defined(WZ_OS_WIN) |
@@ -435,7 +435,7 @@ static const struct poptOption *getOptionsTable() |
435 | 435 | { "enablelobbyslashcmd", POPT_ARG_NONE, CLI_LOBBY_SLASHCOMMANDS, N_("Enable lobby slash commands (for connecting clients)"), nullptr}, |
436 | 436 | { "addlobbyadminhash", POPT_ARG_STRING, CLI_ADD_LOBBY_ADMINHASH, N_("Add a lobby admin identity hash (for slash commands)"), _("hash string")}, |
437 | 437 | { "addlobbyadminpublickey", POPT_ARG_STRING, CLI_ADD_LOBBY_ADMINPUBLICKEY, N_("Add a lobby admin public key (for slash commands)"), N_("b64-pub-key")}, |
438 | | - { "enablecmdinterface", POPT_ARG_STRING, CLI_COMMAND_INTERFACE, N_("Enable command interface"), N_("(stdin)")}, |
| 438 | + { "enablecmdinterface", POPT_ARG_STRING, CLI_COMMAND_INTERFACE, N_("Enable command interface"), N_("(stdin, unixsocket:path)")}, |
439 | 439 | { "startplayers", POPT_ARG_STRING, CLI_STARTPLAYERS, N_("Minimum required players to auto-start game"), N_("startplayers")}, |
440 | 440 | { "gamelog-output", POPT_ARG_STRING, CLI_GAMELOG_OUTPUTMODES, N_("Game history log output mode(s)"), "(log,cmdinterface)"}, |
441 | 441 | { "gamelog-outputkey", POPT_ARG_STRING, CLI_GAMELOG_OUTPUTKEY, N_("Game history log output key"), "[playerindex, playerposition]"}, |
@@ -1101,20 +1101,42 @@ bool ParseCommandLine(int argc, const char * const *argv) |
1101 | 1101 | break; |
1102 | 1102 |
|
1103 | 1103 | case CLI_COMMAND_INTERFACE: |
1104 | | - token = poptGetOptArg(poptCon); |
1105 | | - if (token == nullptr || strlen(token) == 0) |
1106 | | - { |
1107 | | - // use default, which is currently "stdin" |
1108 | | - token = "stdin"; |
1109 | | - } |
1110 | | - if (strcmp(token, "stdin") == 0) |
1111 | | - { |
1112 | | - // enable stdin |
1113 | | - wz_cmd_interface = WZ_Command_Interface::StdIn_Interface; |
1114 | | - } |
1115 | | - else |
1116 | 1104 | { |
1117 | | - qFatal("Unsupported / invalid enablecmdinterface value"); |
| 1105 | + token = poptGetOptArg(poptCon); |
| 1106 | + if (token == nullptr || strlen(token) == 0) |
| 1107 | + { |
| 1108 | + // use default, which is currently "stdin" |
| 1109 | + token = "stdin"; |
| 1110 | + } |
| 1111 | + WZ_Command_Interface mode = WZ_Command_Interface::None; |
| 1112 | + std::string value; |
| 1113 | + if (strcmp(token, "stdin") == 0) |
| 1114 | + { |
| 1115 | + mode = WZ_Command_Interface::StdIn_Interface; |
| 1116 | + } |
| 1117 | + else if (strncmp(token, "unixsocket", strlen("unixsocket")) == 0) |
| 1118 | + { |
| 1119 | + mode = WZ_Command_Interface::Unix_Socket; |
| 1120 | + // expected form is "unixsocket:path" - parse for the path |
| 1121 | + if (strlen(token) > strlen("unixsocket")) |
| 1122 | + { |
| 1123 | + size_t delimeterIdx = strlen("unixsocket"); |
| 1124 | + if (token[delimeterIdx] == ':' && token[delimeterIdx+1] != '\0') |
| 1125 | + { |
| 1126 | + // grab the rest of the string as the path value |
| 1127 | + value = &token[delimeterIdx+1]; |
| 1128 | + } |
| 1129 | + else |
| 1130 | + { |
| 1131 | + qFatal("Invalid enablecmdinterface unixsocket value (expecting unixsocket:path)"); |
| 1132 | + } |
| 1133 | + } |
| 1134 | + } |
| 1135 | + else |
| 1136 | + { |
| 1137 | + qFatal("Unsupported / invalid enablecmdinterface value"); |
| 1138 | + } |
| 1139 | + configSetCmdInterface(mode, value); |
1118 | 1140 | } |
1119 | 1141 | break; |
1120 | 1142 | case CLI_STARTPLAYERS: |
@@ -1287,11 +1309,6 @@ bool lobby_slashcommands_enabled() |
1287 | 1309 | return wz_lobby_slashcommands; |
1288 | 1310 | } |
1289 | 1311 |
|
1290 | | -WZ_Command_Interface wz_command_interface() |
1291 | | -{ |
1292 | | - return wz_cmd_interface; |
1293 | | -} |
1294 | | - |
1295 | 1312 | int min_autostart_player_count() |
1296 | 1313 | { |
1297 | 1314 | return wz_min_autostart_players; |
|
0 commit comments