[General] Add Master Packets
parent
5854f680f0
commit
546bb42abb
@ -0,0 +1,45 @@
|
||||
//
|
||||
// Created by koncord on 22.04.17.
|
||||
//
|
||||
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <iostream>
|
||||
#include "PacketMasterAnnounce.hpp"
|
||||
#include "ProxyMasterPacket.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
using namespace RakNet;
|
||||
using namespace std;
|
||||
|
||||
PacketMasterAnnounce::PacketMasterAnnounce(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
{
|
||||
packetID = ID_MASTER_ANNOUNCE;
|
||||
orderChannel = CHANNEL_MASTER;
|
||||
}
|
||||
|
||||
void PacketMasterAnnounce::Packet(BitStream *bs, bool send)
|
||||
{
|
||||
this->bs = bs;
|
||||
if (send)
|
||||
bs->Write(packetID);
|
||||
|
||||
RW(func, send);
|
||||
|
||||
if(func == FUNCTION_ANNOUNCE)
|
||||
ProxyMasterPacket::addServer(this, *server, send);
|
||||
}
|
||||
|
||||
void PacketMasterAnnounce::SetServer(Server *_server)
|
||||
{
|
||||
server = _server;
|
||||
}
|
||||
|
||||
void PacketMasterAnnounce::SetFunc(int _func)
|
||||
{
|
||||
func = _func;
|
||||
}
|
||||
|
||||
int PacketMasterAnnounce::GetFunc()
|
||||
{
|
||||
return func;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by koncord on 22.04.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PACKETMASTERANNOUNCE_HPP
|
||||
#define OPENMW_PACKETMASTERANNOUNCE_HPP
|
||||
|
||||
#include "../Packets/BasePacket.hpp"
|
||||
#include "MasterData.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProxyMasterPacket;
|
||||
class PacketMasterAnnounce : public BasePacket
|
||||
{
|
||||
friend class ProxyMasterPacket;
|
||||
public:
|
||||
PacketMasterAnnounce(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, bool send);
|
||||
|
||||
void SetServer(Server *server);
|
||||
void SetFunc(int keep);
|
||||
int GetFunc();
|
||||
|
||||
enum Func
|
||||
{
|
||||
FUNCTION_DELETE = 0,
|
||||
FUNCTION_ANNOUNCE,
|
||||
FUNCTION_KEEP
|
||||
};
|
||||
private:
|
||||
Server *server;
|
||||
int func;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PACKETMASTERANNOUNCE_HPP
|
@ -0,0 +1,60 @@
|
||||
//
|
||||
// Created by koncord on 22.04.17.
|
||||
//
|
||||
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <iostream>
|
||||
#include "MasterData.hpp"
|
||||
#include "PacketMasterQuery.hpp"
|
||||
#include "ProxyMasterPacket.hpp"
|
||||
|
||||
|
||||
using namespace mwmp;
|
||||
using namespace std;
|
||||
using namespace RakNet;
|
||||
|
||||
PacketMasterQuery::PacketMasterQuery(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
{
|
||||
packetID = ID_MASTER_QUERY;
|
||||
orderChannel = CHANNEL_MASTER;
|
||||
}
|
||||
|
||||
void PacketMasterQuery::Packet(RakNet::BitStream *bs, bool send)
|
||||
{
|
||||
this->bs = bs;
|
||||
if (send)
|
||||
bs->Write(packetID);
|
||||
|
||||
int serversCount = servers->size();
|
||||
|
||||
RW(serversCount, send);
|
||||
|
||||
map<SystemAddress, Server>::iterator serverIt;
|
||||
if(send)
|
||||
serverIt = servers->begin();
|
||||
|
||||
Server server;
|
||||
SystemAddress sa;
|
||||
while(serversCount--)
|
||||
{
|
||||
if(send)
|
||||
{
|
||||
sa = serverIt->first;
|
||||
server = serverIt->second;
|
||||
}
|
||||
|
||||
RW(sa, send);
|
||||
ProxyMasterPacket::addServer(this, server, send);
|
||||
|
||||
if(send)
|
||||
serverIt++;
|
||||
else
|
||||
servers->insert(pair<SystemAddress, Server>(sa, server));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PacketMasterQuery::SetServers(map<SystemAddress, Server> *serverMap)
|
||||
{
|
||||
servers = serverMap;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by koncord on 22.04.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PACKETMASTERQUERY_HPP
|
||||
#define OPENMW_PACKETMASTERQUERY_HPP
|
||||
|
||||
#include "../Packets/BasePacket.hpp"
|
||||
#include "MasterData.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProxyMasterPacket;
|
||||
class PacketMasterQuery : public BasePacket
|
||||
{
|
||||
friend class ProxyMasterPacket;
|
||||
public:
|
||||
PacketMasterQuery(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, bool send);
|
||||
|
||||
void SetServers(std::map<RakNet::SystemAddress, Server> *serverMap);
|
||||
private:
|
||||
std::map<RakNet::SystemAddress, Server> *servers;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PACKETMASTERQUERY_HPP
|
@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by koncord on 22.04.17.
|
||||
//
|
||||
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include "PacketMasterUpdate.hpp"
|
||||
#include "ProxyMasterPacket.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
using namespace std;
|
||||
using namespace RakNet;
|
||||
|
||||
PacketMasterUpdate::PacketMasterUpdate(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
{
|
||||
packetID = ID_MASTER_UPDATE;
|
||||
orderChannel = CHANNEL_MASTER;
|
||||
}
|
||||
|
||||
void PacketMasterUpdate::Packet(RakNet::BitStream *bs, bool send)
|
||||
{
|
||||
this->bs = bs;
|
||||
if (send)
|
||||
bs->Write(packetID);
|
||||
|
||||
RW(server->first, send);
|
||||
|
||||
ProxyMasterPacket::addServer(this, server->second, send);
|
||||
|
||||
}
|
||||
|
||||
void PacketMasterUpdate::SetServer(std::pair<RakNet::SystemAddress, Server> *serverPair)
|
||||
{
|
||||
server = serverPair;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by koncord on 22.04.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PACKETMASTERUPDATE_HPP
|
||||
#define OPENMW_PACKETMASTERUPDATE_HPP
|
||||
|
||||
#include "../Packets/BasePacket.hpp"
|
||||
#include "MasterData.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProxyMasterPacket;
|
||||
class PacketMasterUpdate : public BasePacket
|
||||
{
|
||||
friend class ProxyMasterPacket;
|
||||
public:
|
||||
PacketMasterUpdate(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, bool send);
|
||||
|
||||
void SetServer(std::pair<RakNet::SystemAddress, Server> *serverPair);
|
||||
private:
|
||||
std::pair<RakNet::SystemAddress, Server> *server;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PACKETMASTERUPDATE_HPP
|
@ -0,0 +1,107 @@
|
||||
//
|
||||
// Created by koncord on 22.04.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PROXYMASTERPACKET_HPP
|
||||
#define OPENMW_PROXYMASTERPACKET_HPP
|
||||
|
||||
#include <components/openmw-mp/Packets/BasePacket.hpp>
|
||||
#include "MasterData.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProxyMasterPacket : public BasePacket
|
||||
{
|
||||
private:
|
||||
ProxyMasterPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
template<class Packet>
|
||||
static void addServer(Packet *packet, Server &server, bool send)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
int rulesSize = server.rules.size();
|
||||
|
||||
packet->RW(rulesSize, send);
|
||||
|
||||
map<string, ServerRule>::iterator ruleIt;
|
||||
if (send)
|
||||
ruleIt = server.rules.begin();
|
||||
|
||||
while (rulesSize--)
|
||||
{
|
||||
ServerRule *rule = 0;
|
||||
string key;
|
||||
if (send)
|
||||
{
|
||||
key = ruleIt->first;
|
||||
rule = &ruleIt->second;
|
||||
}
|
||||
|
||||
packet->RW(key, send);
|
||||
if (!send)
|
||||
{
|
||||
ruleIt = server.rules.insert(pair<string, ServerRule>(key, ServerRule())).first;
|
||||
rule = &ruleIt->second;
|
||||
}
|
||||
|
||||
packet->RW(rule->type, send);
|
||||
|
||||
if (rule->type == 's')
|
||||
packet->RW(rule->str, send);
|
||||
else
|
||||
packet->RW(rule->val, send);
|
||||
|
||||
if (send)
|
||||
ruleIt++;
|
||||
}
|
||||
|
||||
list<string>::iterator plIt;
|
||||
|
||||
if (send)
|
||||
plIt = server.players.begin();
|
||||
else
|
||||
server.players.clear();
|
||||
|
||||
int playersCount = server.GetPlayers();
|
||||
while (playersCount--)
|
||||
{
|
||||
string player;
|
||||
if (send)
|
||||
player = *plIt;
|
||||
|
||||
packet->RW(player, send);
|
||||
|
||||
if (!send)
|
||||
server.players.push_back(player);
|
||||
}
|
||||
|
||||
int pluginsCount = server.plugins.size();
|
||||
packet->RW(pluginsCount, send);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PROXYMASTERPACKET_HPP
|
Loading…
Reference in New Issue