mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-15 01:51:45 +00:00
commit
911079e0bc
8 changed files with 69 additions and 69 deletions
|
@ -585,8 +585,8 @@ void Networking::InitQuery(std::string queryAddr, unsigned short queryPort)
|
||||||
|
|
||||||
void Networking::postInit()
|
void Networking::postInit()
|
||||||
{
|
{
|
||||||
|
Script::Call<Script::CallbackIdentity("OnRequestDataFileList")>();
|
||||||
Script::Call<Script::CallbackIdentity("OnServerPostInit")>();
|
Script::Call<Script::CallbackIdentity("OnServerPostInit")>();
|
||||||
Script::Call<Script::CallbackIdentity("OnRequestPluginList")>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketPreInit::PluginContainer &Networking::getSamples()
|
PacketPreInit::PluginContainer &Networking::getSamples()
|
||||||
|
|
|
@ -21,7 +21,7 @@ int ScriptFunctions::CreateTimerEx(ScriptFunc callback, int msec, const char *ty
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
vector<boost::any> params;
|
vector<boost::any> params;
|
||||||
GetArguments(params, args, types);
|
Utils::getArguments(params, args, types);
|
||||||
|
|
||||||
return mwmp::TimerAPI::CreateTimer(callback, msec, types, params);
|
return mwmp::TimerAPI::CreateTimer(callback, msec, types, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,7 @@ public:
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, e.what());
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, e.what());
|
||||||
|
Script::Call<Script::CallbackIdentity("OnServerScriptCrash")>(e.what());
|
||||||
|
|
||||||
if (!mwmp::Networking::getPtr()->getScriptErrorIgnoringState())
|
if (!mwmp::Networking::getPtr()->getScriptErrorIgnoringState())
|
||||||
throw;
|
throw;
|
||||||
|
|
|
@ -13,62 +13,6 @@ constexpr ScriptCallbackData ScriptFunctions::callbacks[];
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void ScriptFunctions::GetArguments(std::vector<boost::any> ¶ms, va_list args, const std::string &def)
|
|
||||||
{
|
|
||||||
params.reserve(def.length());
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (char c : def)
|
|
||||||
{
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 'i':
|
|
||||||
params.emplace_back(va_arg(args, unsigned int));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'q':
|
|
||||||
params.emplace_back(va_arg(args, signed int));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
params.emplace_back(va_arg(args, unsigned long long));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'w':
|
|
||||||
params.emplace_back(va_arg(args, signed long long));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'f':
|
|
||||||
params.emplace_back(va_arg(args, double));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'p':
|
|
||||||
params.emplace_back(va_arg(args, void*));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
params.emplace_back(va_arg(args, const char*));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'b':
|
|
||||||
params.emplace_back(va_arg(args, int));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw runtime_error("C++ call: Unknown argument identifier " + c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
va_end(args);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptFunctions::MakePublic(ScriptFunc _public, const char *name, char ret_type, const char *def) noexcept
|
void ScriptFunctions::MakePublic(ScriptFunc _public, const char *name, char ret_type, const char *def) noexcept
|
||||||
{
|
{
|
||||||
Public::MakePublic(_public, name, ret_type, def);
|
Public::MakePublic(_public, name, ret_type, def);
|
||||||
|
@ -81,7 +25,7 @@ boost::any ScriptFunctions::CallPublic(const char *name, va_list args) noexcept
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string def = Public::GetDefinition(name);
|
string def = Public::GetDefinition(name);
|
||||||
GetArguments(params, args, def);
|
Utils::getArguments(params, args, def);
|
||||||
|
|
||||||
return Public::Call(name, params);
|
return Public::Call(name, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ class ScriptFunctions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static void GetArguments(std::vector<boost::any> ¶ms, va_list args, const std::string &def);
|
|
||||||
static void MakePublic(ScriptFunc _public, const char *name, char ret_type, const char *def) noexcept;
|
static void MakePublic(ScriptFunc _public, const char *name, char ret_type, const char *def) noexcept;
|
||||||
static boost::any CallPublic(const char *name, va_list args) noexcept;
|
static boost::any CallPublic(const char *name, va_list args) noexcept;
|
||||||
|
|
||||||
|
@ -157,6 +156,7 @@ public:
|
||||||
{"OnServerInit", Callback<>()},
|
{"OnServerInit", Callback<>()},
|
||||||
{"OnServerPostInit", Callback<>()},
|
{"OnServerPostInit", Callback<>()},
|
||||||
{"OnServerExit", Callback<bool>()},
|
{"OnServerExit", Callback<bool>()},
|
||||||
|
{"OnServerScriptCrash", Callback<const char*>()},
|
||||||
{"OnPlayerConnect", Callback<unsigned short>()},
|
{"OnPlayerConnect", Callback<unsigned short>()},
|
||||||
{"OnPlayerDisconnect", Callback<unsigned short>()},
|
{"OnPlayerDisconnect", Callback<unsigned short>()},
|
||||||
{"OnPlayerDeath", Callback<unsigned short>()},
|
{"OnPlayerDeath", Callback<unsigned short>()},
|
||||||
|
@ -209,7 +209,7 @@ public:
|
||||||
{"OnWorldMap", Callback<unsigned short>()},
|
{"OnWorldMap", Callback<unsigned short>()},
|
||||||
{"OnWorldWeather", Callback<unsigned short>() },
|
{"OnWorldWeather", Callback<unsigned short>() },
|
||||||
{"OnMpNumIncrement", Callback<int>()},
|
{"OnMpNumIncrement", Callback<int>()},
|
||||||
{"OnRequestPluginList", Callback<>()}
|
{"OnRequestDataFileList", Callback<>()}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
//
|
|
||||||
// Created by koncord on 04.03.17.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
|
#include <cstdarg>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const vector<string> Utils::split(const string &str, int delimiter)
|
const vector<string> Utils::split(const string &str, int delimiter)
|
||||||
|
@ -52,3 +50,59 @@ ESM::Cell Utils::getCellFromDescription(std::string cellDescription)
|
||||||
|
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Utils::getArguments(std::vector<boost::any> ¶ms, va_list args, const std::string &def)
|
||||||
|
{
|
||||||
|
params.reserve(def.length());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (char c : def)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'i':
|
||||||
|
params.emplace_back(va_arg(args, unsigned int));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'q':
|
||||||
|
params.emplace_back(va_arg(args, signed int));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
params.emplace_back(va_arg(args, unsigned long long));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'w':
|
||||||
|
params.emplace_back(va_arg(args, signed long long));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
params.emplace_back(va_arg(args, double));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
params.emplace_back(va_arg(args, void*));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
params.emplace_back(va_arg(args, const char*));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
params.emplace_back(va_arg(args, int));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw runtime_error("C++ call: Unknown argument identifier " + c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
va_end(args);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
//
|
|
||||||
// Created by koncord on 04.03.17.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef OPENMW_UTILS_HPP
|
#ifndef OPENMW_UTILS_HPP
|
||||||
#define OPENMW_UTILS_HPP
|
#define OPENMW_UTILS_HPP
|
||||||
|
|
||||||
|
@ -9,6 +5,8 @@
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
#include <components/esm/loadcell.hpp>
|
#include <components/esm/loadcell.hpp>
|
||||||
|
|
||||||
#include <components/openmw-mp/Utils.hpp>
|
#include <components/openmw-mp/Utils.hpp>
|
||||||
|
@ -27,6 +25,8 @@ namespace Utils
|
||||||
|
|
||||||
ESM::Cell getCellFromDescription(std::string cellDescription);
|
ESM::Cell getCellFromDescription(std::string cellDescription);
|
||||||
|
|
||||||
|
void getArguments(std::vector<boost::any> ¶ms, va_list args, const std::string &def);
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
constexpr unsigned int hash(const char(&str)[N], size_t I = N)
|
constexpr unsigned int hash(const char(&str)[N], size_t I = N)
|
||||||
{
|
{
|
||||||
|
|
|
@ -307,6 +307,7 @@ int main(int argc, char *argv[])
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, e.what());
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, e.what());
|
||||||
|
Script::Call<Script::CallbackIdentity("OnServerScriptCrash")>(e.what());
|
||||||
throw; //fall through
|
throw; //fall through
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue