房间内所有玩家下线后自动释放房间对象
This commit is contained in:
parent
87ac55c041
commit
027a3de2ea
@ -1867,9 +1867,10 @@ void Human::InternalSendGameOver()
|
|||||||
};
|
};
|
||||||
auto on_error = [] (a8::XParams& param, const std::string& response)
|
auto on_error = [] (a8::XParams& param, const std::string& response)
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Error("battleReport params: ",
|
a8::UdpLog::Instance()->Error("battleReport params: %s response: %s",
|
||||||
{
|
{
|
||||||
param.param2
|
param.param2,
|
||||||
|
response
|
||||||
});
|
});
|
||||||
long long room_uuid = param.sender;
|
long long room_uuid = param.sender;
|
||||||
int hum_uniid = param.param1;
|
int hum_uniid = param.param1;
|
||||||
@ -1901,7 +1902,7 @@ void Human::InternalSendGameOver()
|
|||||||
f8::HttpClientPool::Instance()->HttpGet(
|
f8::HttpClientPool::Instance()->HttpGet(
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(room->room_uuid)
|
.SetSender(room->room_uuid)
|
||||||
.SetParam1(entity_uniid),
|
.SetParam1(entity_uniid)
|
||||||
.SetParam2(data),
|
.SetParam2(data),
|
||||||
on_ok,
|
on_ok,
|
||||||
on_error,
|
on_error,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "playermgr.h"
|
#include "playermgr.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "cs_proto.pb.h"
|
#include "cs_proto.pb.h"
|
||||||
|
#include "room.h"
|
||||||
|
|
||||||
void PlayerMgr::Init()
|
void PlayerMgr::Init()
|
||||||
{
|
{
|
||||||
@ -14,10 +15,10 @@ void PlayerMgr::UnInit()
|
|||||||
|
|
||||||
void PlayerMgr::_SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg)
|
void PlayerMgr::_SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg)
|
||||||
{
|
{
|
||||||
auto itr = socket_hash_.find(hdr.socket_handle);
|
Player* hum = GetPlayerBySocket(hdr.socket_handle);
|
||||||
if (itr != socket_hash_.end()) {
|
if (hum) {
|
||||||
itr->second->socket_handle = 0;
|
RemovePlayerBySocket(hdr.socket_handle);
|
||||||
socket_hash_.erase(itr);
|
hum->room->OnPlayerOffline(hum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,11 +79,19 @@ void PlayerMgr::OnClientDisconnect(a8::XParams& param)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int socket_handle : socket_list) {
|
for (int socket_handle : socket_list) {
|
||||||
socket_hash_.erase(socket_handle);
|
Player* hum = GetPlayerBySocket(socket_handle);
|
||||||
|
if (hum) {
|
||||||
|
RemovePlayerBySocket(socket_handle);
|
||||||
|
hum->room->OnPlayerOffline(hum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMgr::RemovePlayerBySocket(int socket_handle)
|
void PlayerMgr::RemovePlayerBySocket(int socket_handle)
|
||||||
{
|
{
|
||||||
socket_hash_.erase(socket_handle);
|
auto itr = socket_hash_.find(socket_handle);
|
||||||
|
if (itr != socket_hash_.end()) {
|
||||||
|
itr->second->socket_handle = 0;
|
||||||
|
socket_hash_.erase(itr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -713,6 +713,19 @@ bool Room::CanJoin(const std::string& accountid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Room::OnPlayerOffline(Player* hum)
|
||||||
|
{
|
||||||
|
bool has_player = false;
|
||||||
|
for (auto& pair : accountid_hash_) {
|
||||||
|
if (pair.second->socket_handle != 0) {
|
||||||
|
has_player = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!has_player) {
|
||||||
|
RoomMgr::Instance()->AddOverRoom(room_uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::set<Human*>* Room::GetAliveTeam()
|
std::set<Human*>* Room::GetAliveTeam()
|
||||||
{
|
{
|
||||||
for (auto& pair : team_hash_) {
|
for (auto& pair : team_hash_) {
|
||||||
|
@ -88,6 +88,7 @@ public:
|
|||||||
int GetAliveTeamNum();
|
int GetAliveTeamNum();
|
||||||
std::set<Human*>* GetAliveTeam();
|
std::set<Human*>* GetAliveTeam();
|
||||||
bool CanJoin(const std::string& accountid);
|
bool CanJoin(const std::string& accountid);
|
||||||
|
void OnPlayerOffline(Player* hum);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned short AllocUniid();
|
unsigned short AllocUniid();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user