| 1164 | } |
| 1165 | |
| 1166 | void UniverseServer::shutdownInactiveWorlds() { |
| 1167 | RecursiveMutexLocker locker(m_mainLock); |
| 1168 | ReadLocker clientsLocker(m_clientsLock); |
| 1169 | |
| 1170 | // Shutdown idle and errored worlds. |
| 1171 | for (auto const& worldId : m_worlds.keys()) { |
| 1172 | if (auto world = getWorld(worldId)) { |
| 1173 | clientsLocker.unlock(); |
| 1174 | locker.unlock(); |
| 1175 | if (world->serverErrorOccurred()) { |
| 1176 | world->stop(); |
| 1177 | Logger::error("UniverseServer: World {} has stopped due to an error", worldId); |
| 1178 | worldDiedWithError(world->worldId()); |
| 1179 | } else if (world->noClients()) { |
| 1180 | bool anyPendingWarps = false; |
| 1181 | for (auto const& p : m_pendingPlayerWarps) { |
| 1182 | if (resolveWarpAction(p.second.first, p.first, p.second.second).world == world->worldId()) { |
| 1183 | anyPendingWarps = true; |
| 1184 | break; |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | if (!anyPendingWarps && world->shouldExpire()) { |
| 1189 | Logger::info("UniverseServer: Stopping idle world {}", worldId); |
| 1190 | world->stop(); |
| 1191 | } |
| 1192 | } |
| 1193 | locker.lock(); |
| 1194 | clientsLocker.lock(); |
| 1195 | if (world->isJoined()) { |
| 1196 | auto kickClients = world->clients(); |
| 1197 | if (!kickClients.empty()) { |
| 1198 | Logger::info("UniverseServer: World {} shutdown, kicking {} players to their own ships", worldId, world->clients().size()); |
| 1199 | for (auto clientId : world->clients()) |
| 1200 | clientWarpPlayer(clientId, WarpAlias::OwnShip); |
| 1201 | } |
| 1202 | |
| 1203 | if (worldId.is<ClientShipWorldId>()) { |
| 1204 | if (auto clientId = getClientForUuid(worldId.get<ClientShipWorldId>())) |
| 1205 | m_clients.get(*clientId)->updateShipChunks(world->readChunks()); |
| 1206 | } |
| 1207 | |
| 1208 | m_worlds.remove(worldId); |
| 1209 | // Once a world is shutdown, mark its shutdown time in m_tempWorldIndex |
| 1210 | if (auto instanceWorldId = worldId.maybe<InstanceWorldId>()) { |
| 1211 | if (m_tempWorldIndex.contains(*instanceWorldId)) |
| 1212 | m_tempWorldIndex[*instanceWorldId].first = m_universeClock->milliseconds(); |
| 1213 | } |
| 1214 | } |
| 1215 | clientsLocker.unlock(); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | // Clear out all temporary worlds shut down more than tempWorldDeleteTime time ago. |
| 1220 | // Keep around worlds that are currently running or are active in system worlds |
| 1221 | Set<InstanceWorldId> systemLocationWorlds; |
| 1222 | for (auto p : m_systemWorlds) { |
| 1223 | for (auto instanceWorldId : p.second->activeInstanceWorlds()) { |
nothing calls this directly
no test coverage detected