* Handle an error coming from the client side. * @param res The "error" that happened. */
| 143 | * @param res The "error" that happened. |
| 144 | */ |
| 145 | void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res) |
| 146 | { |
| 147 | if (this->IsPendingDeletion()) return; |
| 148 | |
| 149 | /* First, send a CLIENT_ERROR to the server, so it knows we are |
| 150 | * disconnected (and why!) */ |
| 151 | NetworkErrorCode errorno; |
| 152 | |
| 153 | /* We just want to close the connection.. */ |
| 154 | if (res == NETWORK_RECV_STATUS_CLOSE_QUERY) { |
| 155 | this->NetworkSocketHandler::MarkClosed(); |
| 156 | this->CloseConnection(res); |
| 157 | _networking = false; |
| 158 | |
| 159 | CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | switch (res) { |
| 164 | case NETWORK_RECV_STATUS_DESYNC: errorno = NETWORK_ERROR_DESYNC; break; |
| 165 | case NETWORK_RECV_STATUS_SAVEGAME: errorno = NETWORK_ERROR_SAVEGAME_FAILED; break; |
| 166 | case NETWORK_RECV_STATUS_NEWGRF_MISMATCH: errorno = NETWORK_ERROR_NEWGRF_MISMATCH; break; |
| 167 | default: errorno = NETWORK_ERROR_GENERAL; break; |
| 168 | } |
| 169 | |
| 170 | if (res == NETWORK_RECV_STATUS_SERVER_ERROR || res == NETWORK_RECV_STATUS_SERVER_FULL || |
| 171 | res == NETWORK_RECV_STATUS_SERVER_BANNED) { |
| 172 | /* This means the server closed the connection. Emergency save is |
| 173 | * already created if this was appropriate during handling of the |
| 174 | * disconnect. */ |
| 175 | this->CloseConnection(res); |
| 176 | } else { |
| 177 | /* This means we as client made a boo-boo. */ |
| 178 | SendError(errorno); |
| 179 | |
| 180 | /* Close connection before we make an emergency save, as the save can |
| 181 | * take a bit of time; better that the server doesn't stall while we |
| 182 | * are doing the save, and already disconnects us. */ |
| 183 | this->CloseConnection(res); |
| 184 | ClientNetworkEmergencySave(); |
| 185 | } |
| 186 | |
| 187 | CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); |
| 188 | |
| 189 | if (_game_mode != GM_MENU) _switch_mode = SM_MENU; |
| 190 | _networking = false; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /** |
no test coverage detected