MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / shutdownInactiveWorlds

Method shutdownInactiveWorlds

source/game/StarUniverseServer.cpp:1166–1243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1164}
1165
1166void 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()) {

Callers

nothing calls this directly

Calls 15

errorFunction · 0.85
eraseWhereFunction · 0.85
printWorldIdFunction · 0.85
serverErrorOccurredMethod · 0.80
noClientsMethod · 0.80
updateShipChunksMethod · 0.80
millisecondsMethod · 0.80
keysMethod · 0.45
unlockMethod · 0.45
stopMethod · 0.45
worldIdMethod · 0.45
shouldExpireMethod · 0.45

Tested by

no test coverage detected