mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-23 03:40:05 +00:00
Added "/rscripts" command to reload all script states
This commit is contained in:
parent
cb85f7b7c9
commit
c2853d9271
@ -10,6 +10,8 @@
|
||||
#include "Transport.hpp"
|
||||
#include "Missions.hpp"
|
||||
|
||||
#include "lua/LuaManager.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <math.h>
|
||||
@ -1190,6 +1192,12 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
Chat::sendServerMessage(sock, "[PATH] Unknown argument '" + args[1] + "'");
|
||||
}
|
||||
|
||||
static void reloadScriptsCommand(std::string full, std::vector<std::string>& args, CNSocket *sock) {
|
||||
// reloads all scripts
|
||||
LuaManager::stopScripts();
|
||||
LuaManager::loadScripts();
|
||||
}
|
||||
|
||||
static void registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr, std::string help) {
|
||||
commands[cmd] = ChatCommand(requiredLevel, handlr, help);
|
||||
}
|
||||
@ -1229,4 +1237,5 @@ void CustomCommands::init() {
|
||||
registerCommand("unregisterall", 50, unregisterallCommand, "clear all SCAMPER and MSS destinations");
|
||||
registerCommand("redeem", 100, redeemCommand, "redeem a code item");
|
||||
registerCommand("path", 30, pathCommand, "edit NPC paths");
|
||||
registerCommand("rscripts", 30, reloadScriptsCommand, "stops all script states and reloads all scripts");
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "lua/WorldWrapper.hpp"
|
||||
#include "lua/PlayerWrapper.hpp"
|
||||
|
||||
#include "PlayerManager.hpp"
|
||||
#include "servers/CNShardServer.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
@ -61,7 +62,9 @@ struct scheduledThread {
|
||||
};
|
||||
std::map<lua_State*, scheduledThread> scheduleQueue;
|
||||
|
||||
// pauses the script for x seconds
|
||||
// pauses the script for x seconds, not very accurate but should be
|
||||
// called within ~60ms or less of when it was schedueled
|
||||
// will also return the time the thread was paused
|
||||
int OF_wait(lua_State *state) {
|
||||
double seconds = luaL_checknumber(state, 1);
|
||||
|
||||
@ -121,7 +124,8 @@ void LuaManager::init() {
|
||||
|
||||
activeScripts = std::map<lua_State*, Script*>();
|
||||
|
||||
REGISTER_SHARD_TIMER(luaScheduler, 200);
|
||||
// we want to be called after every poll(), so our timer delta is set to 0
|
||||
REGISTER_SHARD_TIMER(luaScheduler, 0);
|
||||
|
||||
// load our scripts
|
||||
loadScripts();
|
||||
@ -142,6 +146,14 @@ void LuaManager::stopScripts() {
|
||||
|
||||
// finally clear the map
|
||||
activeScripts.clear();
|
||||
|
||||
// walk through each player and unregister each event
|
||||
for (auto pair: PlayerManager::players) {
|
||||
if (pair.second->onChat != nullptr) {
|
||||
delete pair.second->onChat;
|
||||
pair.second->onChat = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LuaManager::loadScripts() {
|
||||
|
Loading…
Reference in New Issue
Block a user