Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarUniverseServer.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-02 13:39:34 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-02 13:39:34 +1100
commit662f12da9624435b1850b424817879f12b7a30b2 (patch)
treed43af674451d2247b91b2e3b9fa3f3e4b4181423 /source/game/StarUniverseServer.cpp
parent40698751e79d119e1ae37ea605b320961d6b597a (diff)
improvements to universe.sendPacket and world.sendPacket
adds necessary clientsMutex lock, and returns false if sending failed
Diffstat (limited to 'source/game/StarUniverseServer.cpp')
-rw-r--r--source/game/StarUniverseServer.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/source/game/StarUniverseServer.cpp b/source/game/StarUniverseServer.cpp
index f2d8b3e..7927aae 100644
--- a/source/game/StarUniverseServer.cpp
+++ b/source/game/StarUniverseServer.cpp
@@ -473,10 +473,15 @@ bool UniverseServer::updatePlanetType(CelestialCoordinate const& coordinate, Str
return false;
}
-void UniverseServer::sendPacket(ConnectionId clientId, PacketPtr packet) {
+bool UniverseServer::sendPacket(ConnectionId clientId, PacketPtr packet) {
RecursiveMutexLocker locker(m_mainLock);
- if (m_clients.contains(clientId))
+ ReadLocker clientsLocker(m_clientsLock);
+ if (m_clients.contains(clientId)) {
+ clientsLocker.unlock();
m_connectionServer->sendPackets(clientId, {packet});
+ return true;
+ }
+ return false;
}
void UniverseServer::run() {