mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
[General] Explicitly use limitations of the master server
This commit is contained in:
parent
a48d5b48ef
commit
d162f6fd3a
9 changed files with 70 additions and 73 deletions
|
@ -83,7 +83,7 @@ void MasterClient::SetRuleString(std::string key, std::string value)
|
|||
{
|
||||
ServerRule rule;
|
||||
rule.str = value;
|
||||
rule.type = 's';
|
||||
rule.type = ServerRule::Type::string;
|
||||
queryData.rules.insert({key, rule});
|
||||
updated = true;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ void MasterClient::SetRuleValue(std::string key, double value)
|
|||
{
|
||||
ServerRule rule;
|
||||
rule.val = value;
|
||||
rule.type = 'v';
|
||||
rule.type = ServerRule::Type::number;
|
||||
queryData.rules.insert({key, rule});
|
||||
updated = true;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define NEWMASTERPROTO_MASTERDATA_HPP
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
@ -20,7 +21,11 @@ enum MASTER_PACKETS
|
|||
|
||||
struct ServerRule
|
||||
{
|
||||
char type;
|
||||
enum Type : char
|
||||
{
|
||||
string = 's',
|
||||
number = 'v'
|
||||
} type;
|
||||
|
||||
std::string str;
|
||||
double val;
|
||||
|
@ -30,48 +35,54 @@ struct Plugin
|
|||
{
|
||||
std::string name;
|
||||
unsigned hash;
|
||||
Plugin(std::string name = "", unsigned hash = 0): name(name), hash(hash) {};
|
||||
Plugin(std::string name = "", unsigned hash = 0): name(std::move(name)), hash(hash) {};
|
||||
};
|
||||
|
||||
struct QueryData
|
||||
{
|
||||
QueryData()
|
||||
{
|
||||
rules["name"].type = 's';
|
||||
rules["name"].type = ServerRule::Type::string;
|
||||
rules["name"].str = "";
|
||||
rules["version"].type = 's';
|
||||
rules["version"].type = ServerRule::Type::string;
|
||||
rules["version"].str = "";
|
||||
rules["players"].type = 'v';
|
||||
rules["players"].type = ServerRule::Type::number;
|
||||
rules["players"].val = 0;
|
||||
rules["maxPlayers"].type = 'v';
|
||||
rules["maxPlayers"].type = ServerRule::Type::number;
|
||||
rules["maxPlayers"].val = 0;
|
||||
rules["gamemode"].type = 's';
|
||||
rules["gamemode"].type = ServerRule::Type::string;
|
||||
rules["gamemode"].str = "";
|
||||
rules["passw"].type = 'v';
|
||||
rules["passw"].type = ServerRule::Type::number;
|
||||
rules["passw"].val = 0;
|
||||
}
|
||||
const char *GetName() { return rules["name"].str.c_str(); }
|
||||
const char *GetName() const { return rules.at("name").str.c_str(); }
|
||||
void SetName(const char *name) { rules["name"].str = name; }
|
||||
|
||||
const char *GetVersion() { return rules["version"].str.c_str(); }
|
||||
const char *GetVersion() const { return rules.at("version").str.c_str(); }
|
||||
void SetVersion(const char *version) { rules["version"].str = version; }
|
||||
|
||||
int GetPlayers() { return rules["players"].val; }
|
||||
int GetPlayers() const { return rules.at("players").val; }
|
||||
void SetPlayers(int players) { rules["players"].val = players; }
|
||||
|
||||
int GetMaxPlayers() { return rules["maxPlayers"].val; }
|
||||
int GetMaxPlayers() const { return rules.at("maxPlayers").val; }
|
||||
void SetMaxPlayers(int players) { rules["maxPlayers"].val = players; }
|
||||
|
||||
const char *GetGameMode() { return rules["gamemode"].str.c_str(); }
|
||||
const char *GetGameMode() const { return rules.at("gamemode").str.c_str(); }
|
||||
void SetGameMode(const char *str) { rules["gamemode"].str = str; }
|
||||
|
||||
void SetPassword(int value) { rules["passw"].val = value; };
|
||||
int GetPassword() { return rules["passw"].val; }
|
||||
int GetPassword() const { return rules.at("passw").val; }
|
||||
|
||||
|
||||
std::vector<std::string> players;
|
||||
std::map<std::string, ServerRule> rules;
|
||||
std::vector<Plugin> plugins;
|
||||
const static int predefinedRules = 6;
|
||||
const static int maxRules = 128;
|
||||
const static int maxUserRules = maxRules - predefinedRules;
|
||||
const static int maxPlayers = 100; // will shown only maxPlayers players
|
||||
const static int maxPlugins = 256;
|
||||
const static int maxStringLength = 256;
|
||||
};
|
||||
|
||||
#endif //NEWMASTERPROTO_MASTERDATA_HPP
|
||||
|
|
|
@ -35,7 +35,7 @@ void PacketMasterAnnounce::SetServer(QueryData *_server)
|
|||
server = _server;
|
||||
}
|
||||
|
||||
void PacketMasterAnnounce::SetFunc(int _func)
|
||||
void PacketMasterAnnounce::SetFunc(uint32_t _func)
|
||||
{
|
||||
func = _func;
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ namespace mwmp
|
|||
{
|
||||
friend class ProxyMasterPacket;
|
||||
public:
|
||||
PacketMasterAnnounce(RakNet::RakPeerInterface *peer);
|
||||
explicit PacketMasterAnnounce(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, bool send);
|
||||
void Packet(RakNet::BitStream *bs, bool send) override;
|
||||
|
||||
void SetServer(QueryData *server);
|
||||
void SetFunc(int keep);
|
||||
void SetFunc(uint32_t keep);
|
||||
int GetFunc();
|
||||
|
||||
enum Func
|
||||
|
@ -31,7 +31,7 @@ namespace mwmp
|
|||
};
|
||||
private:
|
||||
QueryData *server;
|
||||
int func;
|
||||
uint32_t func;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ void PacketMasterQuery::Packet(RakNet::BitStream *bs, bool send)
|
|||
if (send)
|
||||
bs->Write(packetID);
|
||||
|
||||
int serversCount = servers->size();
|
||||
int32_t serversCount = servers->size();
|
||||
|
||||
RW(serversCount, send);
|
||||
|
||||
|
@ -36,7 +36,7 @@ void PacketMasterQuery::Packet(RakNet::BitStream *bs, bool send)
|
|||
|
||||
QueryData server;
|
||||
string addr;
|
||||
unsigned short port;
|
||||
uint16_t port;
|
||||
while (serversCount--)
|
||||
{
|
||||
if (send)
|
||||
|
@ -50,6 +50,12 @@ void PacketMasterQuery::Packet(RakNet::BitStream *bs, bool send)
|
|||
|
||||
ProxyMasterPacket::addServer(this, server, send);
|
||||
|
||||
if(addr.empty())
|
||||
{
|
||||
std::cerr << "Address empty. Aborting PacketMasterQuery::Packet" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (send)
|
||||
serverIt++;
|
||||
else
|
||||
|
|
|
@ -15,9 +15,9 @@ namespace mwmp
|
|||
{
|
||||
friend class ProxyMasterPacket;
|
||||
public:
|
||||
PacketMasterQuery(RakNet::RakPeerInterface *peer);
|
||||
explicit PacketMasterQuery(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, bool send);
|
||||
void Packet(RakNet::BitStream *bs, bool send) override;
|
||||
|
||||
void SetServers(std::map<RakNet::SystemAddress, QueryData> *serverMap);
|
||||
private:
|
||||
|
|
|
@ -24,7 +24,7 @@ void PacketMasterUpdate::Packet(RakNet::BitStream *bs, bool send)
|
|||
bs->Write(packetID);
|
||||
|
||||
string addr = server->first.ToString(false);
|
||||
unsigned short port = server->first.GetPort();
|
||||
uint16_t port = server->first.GetPort();
|
||||
|
||||
RW(addr, send);
|
||||
RW(port, send);
|
||||
|
|
|
@ -15,9 +15,9 @@ namespace mwmp
|
|||
{
|
||||
friend class ProxyMasterPacket;
|
||||
public:
|
||||
PacketMasterUpdate(RakNet::RakPeerInterface *peer);
|
||||
explicit PacketMasterUpdate(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, bool send);
|
||||
void Packet(RakNet::BitStream *bs, bool send) override;
|
||||
|
||||
void SetServer(std::pair<RakNet::SystemAddress, QueryData> *serverPair);
|
||||
private:
|
||||
|
|
|
@ -14,9 +14,8 @@ namespace mwmp
|
|||
class ProxyMasterPacket : public BasePacket
|
||||
{
|
||||
private:
|
||||
ProxyMasterPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
explicit ProxyMasterPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -25,11 +24,10 @@ namespace mwmp
|
|||
{
|
||||
using namespace std;
|
||||
|
||||
int rulesSize = server.rules.size();
|
||||
|
||||
int32_t rulesSize = server.rules.size();
|
||||
packet->RW(rulesSize, send);
|
||||
|
||||
if (rulesSize > 2000)
|
||||
if (rulesSize > QueryData::maxRules)
|
||||
rulesSize = 0;
|
||||
|
||||
map<string, ServerRule>::iterator ruleIt;
|
||||
|
@ -38,7 +36,7 @@ namespace mwmp
|
|||
|
||||
while (rulesSize--)
|
||||
{
|
||||
ServerRule *rule = 0;
|
||||
ServerRule *rule = nullptr;
|
||||
string key;
|
||||
if (send)
|
||||
{
|
||||
|
@ -46,7 +44,7 @@ namespace mwmp
|
|||
rule = &ruleIt->second;
|
||||
}
|
||||
|
||||
packet->RW(key, send);
|
||||
packet->RW(key, send, QueryData::maxStringLength);
|
||||
if (!send)
|
||||
{
|
||||
ruleIt = server.rules.insert(pair<string, ServerRule>(key, ServerRule())).first;
|
||||
|
@ -55,8 +53,8 @@ namespace mwmp
|
|||
|
||||
packet->RW(rule->type, send);
|
||||
|
||||
if (rule->type == 's')
|
||||
packet->RW(rule->str, send);
|
||||
if (rule->type == ServerRule::Type::string)
|
||||
packet->RW(rule->str, send, QueryData::maxStringLength);
|
||||
else
|
||||
packet->RW(rule->val, send);
|
||||
|
||||
|
@ -66,56 +64,38 @@ namespace mwmp
|
|||
|
||||
vector<string>::iterator plIt;
|
||||
|
||||
if (send)
|
||||
plIt = server.players.begin();
|
||||
else
|
||||
server.players.clear();
|
||||
|
||||
int playersCount = server.players.size();
|
||||
int32_t playersCount = server.players.size();
|
||||
packet->RW(playersCount, send);
|
||||
|
||||
if (playersCount > 2000)
|
||||
if (playersCount > QueryData::maxPlayers)
|
||||
playersCount = 0;
|
||||
|
||||
while (playersCount--)
|
||||
{
|
||||
string player;
|
||||
if (send)
|
||||
player = *plIt;
|
||||
|
||||
packet->RW(player, send);
|
||||
|
||||
if (!send)
|
||||
server.players.push_back(player);
|
||||
else
|
||||
plIt++;
|
||||
{
|
||||
server.players.clear();
|
||||
server.players.resize(playersCount);
|
||||
}
|
||||
|
||||
int pluginsCount = server.plugins.size();
|
||||
for(auto &&player : server.players)
|
||||
packet->RW(player, send, QueryData::maxStringLength);
|
||||
|
||||
|
||||
int32_t pluginsCount = server.plugins.size();
|
||||
packet->RW(pluginsCount, send);
|
||||
|
||||
if (pluginsCount > 2000)
|
||||
if (pluginsCount > QueryData::maxPlugins)
|
||||
pluginsCount = 0;
|
||||
|
||||
vector<Plugin>::iterator pluginIt;
|
||||
|
||||
if (send)
|
||||
pluginIt = server.plugins.begin();
|
||||
else
|
||||
server.plugins.clear();
|
||||
|
||||
while (pluginsCount--)
|
||||
{
|
||||
Plugin plugin;
|
||||
if (send)
|
||||
plugin = *pluginIt;
|
||||
|
||||
packet->RW(plugin.name, send);
|
||||
packet->RW(plugin.hash, send);
|
||||
if (!send)
|
||||
server.plugins.push_back(plugin);
|
||||
else
|
||||
pluginIt++;
|
||||
{
|
||||
server.plugins.clear();
|
||||
server.plugins.resize(pluginsCount);
|
||||
}
|
||||
|
||||
for (auto &&plugin : server.plugins)
|
||||
{
|
||||
packet->RW(plugin.name, send, QueryData::maxStringLength);
|
||||
packet->RW(plugin.hash, send);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue