| 1007 | } |
| 1008 | |
| 1009 | static bool ConMoveClient(std::span<std::string_view> argv) |
| 1010 | { |
| 1011 | if (argv.size() < 3) { |
| 1012 | IConsolePrint(CC_HELP, "Move a client to another company. Usage: 'move <client-id> <company-id>'."); |
| 1013 | IConsolePrint(CC_HELP, "For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators."); |
| 1014 | return true; |
| 1015 | } |
| 1016 | |
| 1017 | auto client_id = ParseType<ClientID>(argv[1]); |
| 1018 | if (!client_id.has_value()) { |
| 1019 | IConsolePrint(CC_ERROR, "The given client-id is not a valid number."); |
| 1020 | return true; |
| 1021 | } |
| 1022 | const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(*client_id); |
| 1023 | |
| 1024 | auto company_id = ParseCompanyID(argv[2]); |
| 1025 | if (!company_id.has_value()) { |
| 1026 | IConsolePrint(CC_ERROR, "The given company-id is not a valid number."); |
| 1027 | return true; |
| 1028 | } |
| 1029 | |
| 1030 | /* check the client exists */ |
| 1031 | if (ci == nullptr) { |
| 1032 | IConsolePrint(CC_ERROR, "Invalid client-id, check the command 'clients' for valid client-id's."); |
| 1033 | return true; |
| 1034 | } |
| 1035 | |
| 1036 | if (!Company::IsValidID(*company_id) && *company_id != COMPANY_SPECTATOR) { |
| 1037 | IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES); |
| 1038 | return true; |
| 1039 | } |
| 1040 | |
| 1041 | if (*company_id != COMPANY_SPECTATOR && !Company::IsHumanID(*company_id)) { |
| 1042 | IConsolePrint(CC_ERROR, "You cannot move clients to AI companies."); |
| 1043 | return true; |
| 1044 | } |
| 1045 | |
| 1046 | if (ci->client_id == CLIENT_ID_SERVER && _network_dedicated) { |
| 1047 | IConsolePrint(CC_ERROR, "You cannot move the server!"); |
| 1048 | return true; |
| 1049 | } |
| 1050 | |
| 1051 | if (ci->client_playas == *company_id) { |
| 1052 | IConsolePrint(CC_ERROR, "You cannot move someone to where they already are!"); |
| 1053 | return true; |
| 1054 | } |
| 1055 | |
| 1056 | /* we are the server, so force the update */ |
| 1057 | NetworkServerDoMove(ci->client_id, *company_id); |
| 1058 | |
| 1059 | return true; |
| 1060 | } |
| 1061 | |
| 1062 | static bool ConResetCompany(std::span<std::string_view> argv) |
| 1063 | { |
nothing calls this directly
no test coverage detected