[Server] use std::unique_ptr for packet controllers and MasterClient

sol2-server-rewrite
Koncord 7 years ago
parent 2bfd4627ed
commit 44c549211e

@ -41,9 +41,9 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
sThis = this; sThis = this;
this->peer = peer; this->peer = peer;
playerPacketController = new PlayerPacketController(peer); playerPacketController = make_unique<PlayerPacketController>(peer);
actorPacketController = new ActorPacketController(peer); actorPacketController = make_unique<ActorPacketController>(peer);
worldPacketController = new WorldPacketController(peer); worldPacketController = make_unique<WorldPacketController>(peer);
// Set send stream // Set send stream
playerPacketController->SetStream(nullptr, &bsOut); playerPacketController->SetStream(nullptr, &bsOut);
@ -62,10 +62,6 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
Networking::~Networking() Networking::~Networking()
{ {
luaState.getEventCtrl().Call<CoreEvent::ON_EXIT>(false); luaState.getEventCtrl().Call<CoreEvent::ON_EXIT>(false);
delete playerPacketController;
delete actorPacketController;
delete worldPacketController;
} }
void Networking::setServerPassword(std::string passw) noexcept void Networking::setServerPassword(std::string passw) noexcept
@ -334,17 +330,17 @@ void Networking::disconnectPlayer(RakNet::RakNetGUID guid)
PlayerPacketController *Networking::getPlayerPacketController() const PlayerPacketController *Networking::getPlayerPacketController() const
{ {
return playerPacketController; return playerPacketController.get();
} }
ActorPacketController *Networking::getActorPacketController() const ActorPacketController *Networking::getActorPacketController() const
{ {
return actorPacketController; return actorPacketController.get();
} }
WorldPacketController *Networking::getWorldPacketController() const WorldPacketController *Networking::getWorldPacketController() const
{ {
return worldPacketController; return worldPacketController.get();
} }
BaseActorList *Networking::getLastActorList() BaseActorList *Networking::getLastActorList()
@ -525,12 +521,12 @@ int Networking::getAvgPing(RakNet::AddressOrGUID addr) const
MasterClient *Networking::getMasterClient() MasterClient *Networking::getMasterClient()
{ {
return mclient; return mclient.get();
} }
void Networking::InitQuery(const std::string &queryAddr, unsigned short queryPort) void Networking::InitQuery(const std::string &queryAddr, unsigned short queryPort)
{ {
mclient = new MasterClient(peer, queryAddr, queryPort); mclient = make_unique<MasterClient>(peer, queryAddr, queryPort);
} }
void Networking::postInit() void Networking::postInit()

@ -87,14 +87,14 @@ namespace mwmp
RakNet::RakPeerInterface *peer; RakNet::RakPeerInterface *peer;
RakNet::BitStream bsOut; RakNet::BitStream bsOut;
MasterClient *mclient; std::unique_ptr<MasterClient> mclient;
BaseActorList baseActorList; BaseActorList baseActorList;
BaseEvent baseEvent; BaseEvent baseEvent;
PlayerPacketController *playerPacketController; std::unique_ptr<PlayerPacketController> playerPacketController;
ActorPacketController *actorPacketController; std::unique_ptr<ActorPacketController> actorPacketController;
WorldPacketController *worldPacketController; std::unique_ptr<WorldPacketController> worldPacketController;
bool running; bool running;
int exitCode; int exitCode;

Loading…
Cancel
Save