Handle world creation error when sending world messages, add active world callbacks
This commit is contained in:
parent
a2d901bd66
commit
af31bde032
@ -1,3 +1,5 @@
|
|||||||
|
-- Small helper to organize code for the same context into different Lua scripts without having to "hook" previously defined.
|
||||||
|
|
||||||
modules = setmetatable({}, {__call = function(this, path, names)
|
modules = setmetatable({}, {__call = function(this, path, names)
|
||||||
for i, name in pairs(names) do
|
for i, name in pairs(names) do
|
||||||
require(path .. name .. ".lua")
|
require(path .. name .. ".lua")
|
||||||
|
12
assets/opensb/scripts/opensb/worldserver/messages.lua
Normal file
12
assets/opensb/scripts/opensb/worldserver/messages.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
local module = {}
|
||||||
|
modules.messages = module
|
||||||
|
|
||||||
|
function module.init()
|
||||||
|
message.setHandler("keepAlive", function(_, _, time)
|
||||||
|
return world.setExpiryTime(tonumber(time) or 0)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.update()
|
||||||
|
|
||||||
|
end
|
@ -1,12 +0,0 @@
|
|||||||
local module = {}
|
|
||||||
modules.test = module
|
|
||||||
|
|
||||||
function module.init()
|
|
||||||
message.setHandler("type", function()
|
|
||||||
return world.type()
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function module.update()
|
|
||||||
|
|
||||||
end
|
|
@ -1,2 +1,2 @@
|
|||||||
require "/scripts/opensb/util/modules.lua"
|
require "/scripts/opensb/util/modules.lua"
|
||||||
modules("/scripts/opensb/worldserver/", {"test"})
|
modules("/scripts/opensb/worldserver/", {"messages"})
|
@ -151,6 +151,11 @@ List<WorldId> UniverseServer::activeWorlds() const {
|
|||||||
return m_worlds.keys();
|
return m_worlds.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UniverseServer::isWorldActive(WorldId const& worldId) const {
|
||||||
|
RecursiveMutexLocker locker(m_mainLock);
|
||||||
|
return m_worlds.contains(worldId);
|
||||||
|
}
|
||||||
|
|
||||||
List<ConnectionId> UniverseServer::clientIds() const {
|
List<ConnectionId> UniverseServer::clientIds() const {
|
||||||
ReadLocker clientsLocker(m_clientsLock);
|
ReadLocker clientsLocker(m_clientsLock);
|
||||||
return m_clients.keys();
|
return m_clients.keys();
|
||||||
@ -1045,8 +1050,14 @@ void UniverseServer::handleWorldMessages() {
|
|||||||
auto it = m_pendingWorldMessages.begin();
|
auto it = m_pendingWorldMessages.begin();
|
||||||
while (it != m_pendingWorldMessages.end()) {
|
while (it != m_pendingWorldMessages.end()) {
|
||||||
auto& worldId = it->first;
|
auto& worldId = it->first;
|
||||||
if (auto worldPtr = triggerWorldCreation(worldId).value()) {
|
if (auto worldResult = triggerWorldCreation(worldId)) {
|
||||||
worldPtr->passMessages(move(it->second));
|
auto& world = *worldResult;
|
||||||
|
|
||||||
|
if (world)
|
||||||
|
world->passMessages(move(it->second));
|
||||||
|
else for (auto& message : it->second)
|
||||||
|
message.promise.fail("Error creating world");
|
||||||
|
|
||||||
it = m_pendingWorldMessages.erase(it);
|
it = m_pendingWorldMessages.erase(it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -51,6 +51,7 @@ public:
|
|||||||
void setPause(bool pause);
|
void setPause(bool pause);
|
||||||
|
|
||||||
List<WorldId> activeWorlds() const;
|
List<WorldId> activeWorlds() const;
|
||||||
|
bool isWorldActive(WorldId const& worldId) const;
|
||||||
|
|
||||||
List<ConnectionId> clientIds() const;
|
List<ConnectionId> clientIds() const;
|
||||||
size_t numberOfClients() const;
|
size_t numberOfClients() const;
|
||||||
|
@ -18,7 +18,9 @@ LuaCallbacks LuaBindings::makeUniverseServerCallbacks(UniverseServer* universe)
|
|||||||
callbacks.registerCallbackWithSignature<bool, ConnectionId>("isAdmin", bind(UniverseServerCallbacks::isAdmin, universe, _1));
|
callbacks.registerCallbackWithSignature<bool, ConnectionId>("isAdmin", bind(UniverseServerCallbacks::isAdmin, universe, _1));
|
||||||
callbacks.registerCallbackWithSignature<bool, ConnectionId>("isPvp", bind(UniverseServerCallbacks::isPvp, universe, _1));
|
callbacks.registerCallbackWithSignature<bool, ConnectionId>("isPvp", bind(UniverseServerCallbacks::isPvp, universe, _1));
|
||||||
callbacks.registerCallbackWithSignature<void, ConnectionId, bool>("setPvp", bind(UniverseServerCallbacks::setPvp, universe, _1, _2));
|
callbacks.registerCallbackWithSignature<void, ConnectionId, bool>("setPvp", bind(UniverseServerCallbacks::setPvp, universe, _1, _2));
|
||||||
callbacks.registerCallbackWithSignature<RpcThreadPromise<Json>, LuaEngine&, String, String, LuaVariadic<Json>>("sendWorldMessage", bind(UniverseServerCallbacks::sendWorldMessage, universe, _1, _2, _3, _4));
|
callbacks.registerCallbackWithSignature<bool, String>("isWorldActive", bind(UniverseServerCallbacks::isWorldActive, universe, _1));
|
||||||
|
callbacks.registerCallbackWithSignature<bool, StringList>("activeWorlds", bind(UniverseServerCallbacks::activeWorlds, universe));
|
||||||
|
callbacks.registerCallbackWithSignature<RpcThreadPromise<Json>, String, String, LuaVariadic<Json>>("sendWorldMessage", bind(UniverseServerCallbacks::sendWorldMessage, universe, _1, _2, _3));
|
||||||
|
|
||||||
return callbacks;
|
return callbacks;
|
||||||
}
|
}
|
||||||
@ -108,7 +110,19 @@ void LuaBindings::UniverseServerCallbacks::setPvp(UniverseServer* universe, Conn
|
|||||||
universe->setPvp(client, setPvpTo);
|
universe->setPvp(client, setPvpTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcThreadPromise<Json> LuaBindings::UniverseServerCallbacks::sendWorldMessage(UniverseServer* universe, LuaEngine& engine, String const& worldId, String const& message, LuaVariadic<Json> args) {
|
bool LuaBindings::UniverseServerCallbacks::isWorldActive(UniverseServer* universe, String const& worldId) {
|
||||||
|
return universe->isWorldActive(parseWorldId(worldId));
|
||||||
|
}
|
||||||
|
|
||||||
|
StringList LuaBindings::UniverseServerCallbacks::activeWorlds(UniverseServer* universe) {
|
||||||
|
StringList worlds;
|
||||||
|
for (WorldId& world : universe->activeWorlds())
|
||||||
|
worlds.append(printWorldId(world));
|
||||||
|
|
||||||
|
return worlds;
|
||||||
|
}
|
||||||
|
|
||||||
|
RpcThreadPromise<Json> LuaBindings::UniverseServerCallbacks::sendWorldMessage(UniverseServer* universe, String const& worldId, String const& message, LuaVariadic<Json> args) {
|
||||||
return universe->sendWorldMessage(parseWorldId(worldId), message, JsonArray::from(move(args)));
|
return universe->sendWorldMessage(parseWorldId(worldId), message, JsonArray::from(move(args)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,9 @@ namespace LuaBindings {
|
|||||||
bool isAdmin(UniverseServer* universe, ConnectionId arg1);
|
bool isAdmin(UniverseServer* universe, ConnectionId arg1);
|
||||||
bool isPvp(UniverseServer* universe, ConnectionId arg1);
|
bool isPvp(UniverseServer* universe, ConnectionId arg1);
|
||||||
void setPvp(UniverseServer* universe, ConnectionId arg1, Maybe<bool> arg2);
|
void setPvp(UniverseServer* universe, ConnectionId arg1, Maybe<bool> arg2);
|
||||||
RpcThreadPromise<Json> sendWorldMessage(UniverseServer* universe, LuaEngine& engine, String const& worldId, String const& message, LuaVariadic<Json> args);
|
bool isWorldActive(UniverseServer* universe, String const& worldId);
|
||||||
|
StringList activeWorlds(UniverseServer* universe);
|
||||||
|
RpcThreadPromise<Json> sendWorldMessage(UniverseServer* universe, String const& worldId, String const& message, LuaVariadic<Json> args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user