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

summaryrefslogtreecommitdiff
path: root/source/game/StarWorldServerThread.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-23 01:01:23 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-23 01:01:23 +1000
commit5fa97741e509f813d28db90e7bce1aac45e22829 (patch)
tree3095676703537068857c55dfc7b4311e33f03706 /source/game/StarWorldServerThread.cpp
parentcb19eef701b5c9e27d0464795fffcf8a4d795a21 (diff)
experimental universe.sendWorldMessage function
Diffstat (limited to 'source/game/StarWorldServerThread.cpp')
-rw-r--r--source/game/StarWorldServerThread.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/source/game/StarWorldServerThread.cpp b/source/game/StarWorldServerThread.cpp
index e06221e..6928456 100644
--- a/source/game/StarWorldServerThread.cpp
+++ b/source/game/StarWorldServerThread.cpp
@@ -13,7 +13,8 @@ WorldServerThread::WorldServerThread(WorldServerPtr server, WorldId worldId)
m_worldServer(move(server)),
m_worldId(move(worldId)),
m_stop(false),
- m_errorOccurred(false) {
+ m_errorOccurred(false),
+ m_shouldExpire(true) {
if (m_worldServer)
m_worldServer->setWorldId(printWorldId(m_worldId));
}
@@ -50,6 +51,10 @@ bool WorldServerThread::serverErrorOccurred() {
return m_errorOccurred;
}
+bool WorldServerThread::shouldExpire() {
+ return m_shouldExpire;
+}
+
bool WorldServerThread::spawnTargetValid(SpawnTarget const& spawnTarget) {
try {
RecursiveMutexLocker locker(m_mutex);
@@ -115,6 +120,12 @@ bool WorldServerThread::hasClient(ConnectionId clientId) const {
return m_clients.contains(clientId);
}
+bool WorldServerThread::noClients() const {
+ RecursiveMutexLocker locker(m_mutex);
+ return m_clients.empty();
+}
+
+
List<ConnectionId> WorldServerThread::erroredClients() const {
RecursiveMutexLocker locker(m_mutex);
auto unerroredClients = HashSet<ConnectionId>::from(m_worldServer->clientIds());
@@ -165,6 +176,11 @@ void WorldServerThread::setUpdateAction(WorldServerAction updateAction) {
m_updateAction = updateAction;
}
+void WorldServerThread::passMessages(List<Message>&& messages) {
+ RecursiveMutexLocker locker(m_messageMutex);
+ m_messages.appendAll(move(messages));
+}
+
WorldChunks WorldServerThread::readChunks() {
try {
RecursiveMutexLocker locker(m_mutex);
@@ -256,12 +272,26 @@ void WorldServerThread::update(WorldServerFidelity fidelity) {
if (!m_pause || *m_pause == false)
m_worldServer->update(dt);
+ List<Message> messages;
+ {
+ RecursiveMutexLocker locker(m_messageMutex);
+ messages = move(m_messages);
+ }
+ for (auto& message : messages) {
+ if (auto resp = m_worldServer->receiveMessage(ServerConnectionId, message.message, message.args))
+ message.promise.fulfill(*resp);
+ else
+ message.promise.fail("Message not handled by world");
+ }
+
for (auto& clientId : unerroredClientIds) {
auto outgoingPackets = m_worldServer->getOutgoingPackets(clientId);
RecursiveMutexLocker queueLocker(m_queueMutex);
m_outgoingPacketQueue[clientId].appendAll(move(outgoingPackets));
}
+ m_shouldExpire = m_worldServer->shouldExpire();
+
if (m_updateAction)
m_updateAction(this, m_worldServer.get());
}