68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
#include "precompile.h"
|
|
|
|
#include "gameclientmgr.h"
|
|
#include "ss_proto.pb.h"
|
|
|
|
#include "gameclient.h"
|
|
#include "target_conn.h"
|
|
#include "target_conn_mgr.h"
|
|
#include "GCListener.h"
|
|
|
|
void GameClientMgr::Init()
|
|
{
|
|
}
|
|
|
|
void GameClientMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
void GameClientMgr::OnClientDisconnect(a8::XParams& param)
|
|
{
|
|
GameClient* client = GetGameClientBySocket(param.sender);
|
|
if (client) {
|
|
if (client->conn) {
|
|
ss::SS_WSP_SocketDisconnect msg;
|
|
client->conn->SendMsg(param.sender, msg);
|
|
}
|
|
socket_hash_.erase(param.sender);
|
|
delete client;
|
|
}
|
|
}
|
|
|
|
void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
|
{
|
|
std::list<GameClient*> delete_client;
|
|
for (auto& pair : socket_hash_) {
|
|
if (pair.second->conn && pair.second->conn->instance_id == param.sender.GetInt()) {
|
|
delete_client.push_back(pair.second);
|
|
}
|
|
}
|
|
for (auto& client : delete_client) {
|
|
GCListener::Instance()->ForceCloseClient(client->socket_handle);
|
|
socket_hash_.erase(client->socket_handle);
|
|
delete client;
|
|
}
|
|
}
|
|
|
|
GameClient* GameClientMgr::GetGameClientBySocket(int sockhandle)
|
|
{
|
|
auto itr = socket_hash_.find(sockhandle);
|
|
return itr != socket_hash_.end() ? itr->second : nullptr;
|
|
}
|
|
|
|
void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id)
|
|
{
|
|
TargetConn* conn = TargetConnMgr::Instance()->GetConnByInstanceId(conn_instance_id);
|
|
if (conn) {
|
|
GameClient* client = GetGameClientBySocket(socket_handle);
|
|
if (client) {
|
|
client->conn = conn;
|
|
} else {
|
|
client = new GameClient();
|
|
client->socket_handle = socket_handle;
|
|
client->conn = conn;
|
|
socket_hash_[client->socket_handle] = client;
|
|
}
|
|
}
|
|
}
|