SV_Map
(ChangeMapInfo changeMapInfo, int clientIndex)
| 1283 | * SV_Map |
| 1284 | */ |
| 1285 | GameImportsImpl spawnServerInstance(ChangeMapInfo changeMapInfo, int clientIndex) { |
| 1286 | Globals.server_state = ServerStates.SS_DEAD; //fixme: used by the client code |
| 1287 | |
| 1288 | GameExports oldGame = null; |
| 1289 | GameImportsImpl gameImports; |
| 1290 | |
| 1291 | if (clientIndex != 0) |
| 1292 | gameImports = games.get(clients.get(clientIndex - 1).gameName); |
| 1293 | else |
| 1294 | gameImports = games.get("default"); |
| 1295 | |
| 1296 | if (gameImports != null) { //todo |
| 1297 | // store some entity data into gclient_t struct, will be restored in the next game |
| 1298 | oldGame = gameImports.gameExports; |
| 1299 | oldGame.SaveClientData(); |
| 1300 | } |
| 1301 | |
| 1302 | gameImports = createGameInstance(changeMapInfo); |
| 1303 | |
| 1304 | Cvar.getInstance().Set("nextserver", "gamemap \"" + changeMapInfo.nextServer + "\""); |
| 1305 | |
| 1306 | Cmd.ExecuteFunction("loading"); // for local system |
| 1307 | |
| 1308 | if (clientIndex == 0) { |
| 1309 | // leave slots at start for clients only |
| 1310 | for (client_t cl : clients) { //todo |
| 1311 | // needs to reconnect |
| 1312 | if (cl.state == ClientStates.CS_SPAWNED) |
| 1313 | cl.state = ClientStates.CS_CONNECTED; |
| 1314 | cl.lastReceivedFrame = -1; |
| 1315 | } |
| 1316 | gameImports.SV_BroadcastCommand("changing"); |
| 1317 | |
| 1318 | } else { |
| 1319 | final client_t cl = clients.get(clientIndex - 1); |
| 1320 | if (cl.state == ClientStates.CS_SPAWNED) |
| 1321 | cl.state = ClientStates.CS_CONNECTED; |
| 1322 | cl.lastReceivedFrame = -1; |
| 1323 | gameImports.unicastMessage(clientIndex, new StuffTextMessage("changing"), true); |
| 1324 | } |
| 1325 | |
| 1326 | SV_SendClientMessages(); |
| 1327 | |
| 1328 | |
| 1329 | // precache and static commands can be issued during |
| 1330 | // map initialization |
| 1331 | Globals.server_state = gameImports.sv.state; // LOADING |
| 1332 | |
| 1333 | if (oldGame != null) { |
| 1334 | // copy persistent data between instances. |
| 1335 | // after a 'map' command the persistent state will be empty |
| 1336 | gameImports.gameExports.fromPrevious(oldGame, changeMapInfo.spawnPoint); |
| 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | // spawn fresh entities |
| 1341 | gameImports.gameExports.SpawnEntities(gameImports.sv.name, gameImports.cm.CM_EntityString(), changeMapInfo.spawnPoint); |
| 1342 |