forked from mirror/openmw-tes3mp
[Server] Rework OnRequestPluginList callback. Add AddPluginHash function
This commit is contained in:
parent
20a7619a4a
commit
07a5f5296c
5 changed files with 45 additions and 40 deletions
|
@ -446,32 +446,6 @@ RakNet::SystemAddress Networking::getSystemAddress(RakNet::RakNetGUID 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)
|
||||
{
|
||||
running = false;
|
||||
|
@ -595,15 +569,10 @@ void Networking::InitQuery(std::string queryAddr, unsigned short queryPort)
|
|||
void Networking::postInit()
|
||||
{
|
||||
Script::Call<Script::CallbackIdentity("OnServerPostInit")>();
|
||||
samples = getPluginListSample();
|
||||
if (mclient)
|
||||
{
|
||||
for (auto plugin : samples)
|
||||
{
|
||||
if (!plugin.second.empty())
|
||||
mclient->PushPlugin({plugin.first, plugin.second[0]});
|
||||
else
|
||||
mclient->PushPlugin({plugin.first, 0});
|
||||
}
|
||||
}
|
||||
Script::Call<Script::CallbackIdentity("OnRequestPluginList")>();
|
||||
}
|
||||
|
||||
PacketPreInit::PluginContainer &Networking::getSamples()
|
||||
{
|
||||
return samples;
|
||||
}
|
||||
|
|
|
@ -65,9 +65,10 @@ namespace mwmp
|
|||
static Networking *getPtr();
|
||||
|
||||
void postInit();
|
||||
|
||||
PacketPreInit::PluginContainer &getSamples();
|
||||
private:
|
||||
bool preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn);
|
||||
PacketPreInit::PluginContainer getPluginListSample();
|
||||
std::string serverPassword;
|
||||
static Networking *sThis;
|
||||
|
||||
|
|
|
@ -105,3 +105,30 @@ void ServerFunctions::SetRuleValue(const char *key, double value) noexcept
|
|||
if (mc)
|
||||
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},\
|
||||
{"SetServerPassword", ServerFunctions::SetServerPassword},\
|
||||
{"SetRuleString", ServerFunctions::SetRuleString},\
|
||||
{"SetRuleValue", ServerFunctions::SetRuleValue}
|
||||
{"SetRuleValue", ServerFunctions::SetRuleValue},\
|
||||
{"AddPluginHash", ServerFunctions::AddPluginHash}
|
||||
|
||||
class ServerFunctions
|
||||
{
|
||||
|
@ -152,6 +153,13 @@ public:
|
|||
* \return void
|
||||
*/
|
||||
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
|
||||
|
|
|
@ -205,7 +205,7 @@ public:
|
|||
{"OnWorldMap", Function<void, unsigned short>()},
|
||||
{"OnWorldWeather", Function<void, unsigned short>() },
|
||||
{"OnMpNumIncrement", Function<void, int>()},
|
||||
{"OnRequestPluginList", Function<const char *, unsigned int, unsigned int>()}
|
||||
{"OnRequestPluginList", Function<void>()}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue