use SlotGuard
This commit is contained in:
@@ -7,20 +7,14 @@ namespace server {
|
||||
void IServerState::SetServer(Server* a_Server) {
|
||||
assert(a_Server);
|
||||
m_Server = a_Server;
|
||||
m_Server->m_Socket->OnConnect.Connect(std::bind(&IServerState::OnPlayerJoin, this, std::placeholders::_1));
|
||||
m_Server->m_Socket->OnDisconnect.Connect(std::bind(&IServerState::OnPlayerLeave, this, std::placeholders::_1));
|
||||
m_Server->m_Socket->OnReceive.Connect(std::bind(&IServerState::HandlePacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
Connect(m_Server->m_Socket->OnConnect, std::bind(&IServerState::OnPlayerJoin, this, std::placeholders::_1));
|
||||
Connect(m_Server->m_Socket->OnDisconnect, std::bind(&IServerState::OnPlayerLeave, this, std::placeholders::_1));
|
||||
Connect(m_Server->m_Socket->OnReceive, std::bind(&IServerState::HandlePacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
IServerState::IServerState() : m_Server(nullptr) {}
|
||||
|
||||
IServerState::~IServerState() {
|
||||
if (!m_Server)
|
||||
return;
|
||||
m_Server->m_Socket->OnConnect.Disconnect(std::bind(&IServerState::OnPlayerJoin, this, std::placeholders::_1));
|
||||
m_Server->m_Socket->OnDisconnect.Disconnect(std::bind(&IServerState::OnPlayerLeave, this, std::placeholders::_1));
|
||||
m_Server->m_Socket->OnReceive.Disconnect(std::bind(&IServerState::HandlePacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
IServerState::~IServerState() {}
|
||||
|
||||
void IServerState::SendPacket(PlayerID a_Id, const protocol::PacketBase& a_Packet) {
|
||||
m_Server->m_Socket->Send(a_Id, a_Packet);
|
||||
|
||||
Reference in New Issue
Block a user