[Server] Rework OnRequestPluginList callback. Add AddPluginHash function

pull/484/head
Koncord 6 years ago
parent 20a7619a4a
commit 07a5f5296c

@ -446,32 +446,6 @@ RakNet::SystemAddress Networking::getSystemAddress(RakNet::RakNetGUID guid)
return peer->GetSystemAddressFromGuid(guid); return peer->GetSystemAddressFromGuid(guid);
} }
PacketPreInit::PluginContainer Networking::getPluginListSample()
{
PacketPreInit::PluginContainer pls;
unsigned id = 0;
while (true)
{
unsigned field = 0;
auto name = "";
Script::Call<Script::CallbackIdentity("OnRequestPluginList")>(name, id, field++);
if (strlen(name) == 0)
break;
PacketPreInit::HashList hashList;
while (true)
{
auto hash = "";
Script::Call<Script::CallbackIdentity("OnRequestPluginList")>(hash, id, field++);
if (strlen(hash) == 0)
break;
hashList.push_back((unsigned)stoul(hash));
}
pls.push_back({name, hashList});
id++;
}
return pls;
}
void Networking::stopServer(int code) void Networking::stopServer(int code)
{ {
running = false; running = false;
@ -595,15 +569,10 @@ void Networking::InitQuery(std::string queryAddr, unsigned short queryPort)
void Networking::postInit() void Networking::postInit()
{ {
Script::Call<Script::CallbackIdentity("OnServerPostInit")>(); Script::Call<Script::CallbackIdentity("OnServerPostInit")>();
samples = getPluginListSample(); Script::Call<Script::CallbackIdentity("OnRequestPluginList")>();
if (mclient)
{
for (auto plugin : samples)
{
if (!plugin.second.empty())
mclient->PushPlugin({plugin.first, plugin.second[0]});
else
mclient->PushPlugin({plugin.first, 0});
}
} }
PacketPreInit::PluginContainer &Networking::getSamples()
{
return samples;
} }

@ -65,9 +65,10 @@ namespace mwmp
static Networking *getPtr(); static Networking *getPtr();
void postInit(); void postInit();
PacketPreInit::PluginContainer &getSamples();
private: private:
bool preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn); bool preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn);
PacketPreInit::PluginContainer getPluginListSample();
std::string serverPassword; std::string serverPassword;
static Networking *sThis; static Networking *sThis;

@ -105,3 +105,30 @@ void ServerFunctions::SetRuleValue(const char *key, double value) noexcept
if (mc) if (mc)
mc->SetRuleValue(key, value); mc->SetRuleValue(key, value);
} }
void ServerFunctions::AddPluginHash(const char *pluginName, const char *hashStr) noexcept
{
auto &samples = mwmp::Networking::getPtr()->getSamples();
auto it = std::find_if(samples.begin(), samples.end(), [&pluginName](mwmp::PacketPreInit::PluginPair &item) {
return item.first == pluginName;
});
if (it != samples.end())
it->second.push_back((unsigned) std::stoul(hashStr));
else
{
mwmp::PacketPreInit::HashList hashList;
unsigned hash = 0;
if (strlen(hashStr) != 0)
{
hash = (unsigned) std::stoul(hashStr);
hashList.push_back(hash);
}
samples.emplace_back(pluginName, hashList);
auto mclient = mwmp::Networking::getPtr()->getMasterClient();
if (mclient)
mclient->PushPlugin({pluginName, hash});
}
}

@ -22,7 +22,8 @@
{"SetHostname", ServerFunctions::SetHostname},\ {"SetHostname", ServerFunctions::SetHostname},\
{"SetServerPassword", ServerFunctions::SetServerPassword},\ {"SetServerPassword", ServerFunctions::SetServerPassword},\
{"SetRuleString", ServerFunctions::SetRuleString},\ {"SetRuleString", ServerFunctions::SetRuleString},\
{"SetRuleValue", ServerFunctions::SetRuleValue} {"SetRuleValue", ServerFunctions::SetRuleValue},\
{"AddPluginHash", ServerFunctions::AddPluginHash}
class ServerFunctions class ServerFunctions
{ {
@ -152,6 +153,13 @@ public:
* \return void * \return void
*/ */
static void SetRuleValue(const char *key, double value) noexcept; static void SetRuleValue(const char *key, double value) noexcept;
/**
* \brief Adds plugins to the internal server structure to validate players.
* @param pluginName Name with extension of the plugin or master file.
* @param hash Hash string
*/
static void AddPluginHash(const char *pluginName, const char *hash) noexcept;
}; };
#endif //OPENMW_SERVERAPI_HPP #endif //OPENMW_SERVERAPI_HPP

@ -205,7 +205,7 @@ public:
{"OnWorldMap", Function<void, unsigned short>()}, {"OnWorldMap", Function<void, unsigned short>()},
{"OnWorldWeather", Function<void, unsigned short>() }, {"OnWorldWeather", Function<void, unsigned short>() },
{"OnMpNumIncrement", Function<void, int>()}, {"OnMpNumIncrement", Function<void, int>()},
{"OnRequestPluginList", Function<const char *, unsigned int, unsigned int>()} {"OnRequestPluginList", Function<void>()}
}; };
}; };

Loading…
Cancel
Save