154 lines
5.5 KiB
C++
154 lines
5.5 KiB
C++
#include "precompile.h"
|
|
|
|
#include <f8/udplog.h>
|
|
|
|
#include "downstreammgr.h"
|
|
#include "ss_proto.pb.h"
|
|
|
|
#include "downstream.h"
|
|
#include "target_conn.h"
|
|
#include "target_conn_mgr.h"
|
|
#include "GCListener.h"
|
|
#include "app.h"
|
|
|
|
void GameClientMgr::Init()
|
|
{
|
|
}
|
|
|
|
void GameClientMgr::UnInit()
|
|
{
|
|
for (auto& pair : socket_hash_) {
|
|
delete pair.second;
|
|
}
|
|
socket_hash_.clear();
|
|
#if 0
|
|
pending_account_hash_.clear();
|
|
#endif
|
|
}
|
|
|
|
#if 0
|
|
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;
|
|
}
|
|
RemovePendingAccount(param.sender);
|
|
}
|
|
#endif
|
|
|
|
#if 0
|
|
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) {
|
|
RemovePendingAccount(client->socket_handle);
|
|
GCListener::Instance()->ForceCloseClient(client->socket_handle);
|
|
socket_hash_.erase(client->socket_handle);
|
|
delete client;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if 0
|
|
void GameClientMgr::OnTargetServerConnect(a8::XParams& param)
|
|
{
|
|
|
|
}
|
|
#endif
|
|
|
|
DownStream* 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()->GetConnById(conn_instance_id);
|
|
if (conn) {
|
|
DownStream* client = GetGameClientBySocket(socket_handle);
|
|
if (client) {
|
|
client->conn = conn;
|
|
} else {
|
|
client = new DownStream();
|
|
client->socket_handle = socket_handle;
|
|
client->conn = conn;
|
|
socket_hash_[client->socket_handle] = client;
|
|
f8::UdpLog::Instance()->Info("BindTargetConn socket_handle:%d", {socket_handle});
|
|
{
|
|
#if 0
|
|
auto itr = pending_account_hash_.find(socket_handle);
|
|
if (itr != pending_account_hash_.end()) {
|
|
std::string account_id = std::get<0>(itr->second);
|
|
long long req_tick = std::get<1>(itr->second);
|
|
long long cur_tick = a8::XGetTickCount();
|
|
if (cur_tick - req_tick > App::Instance()->perf.max_join_time) {
|
|
App::Instance()->perf.max_join_time = cur_tick - req_tick;
|
|
}
|
|
if (account_id == azw_account_id) {
|
|
f8::UdpLog::Instance()->Info("%s join time:%d",
|
|
{
|
|
account_id,
|
|
cur_tick - req_tick
|
|
});
|
|
}
|
|
f8::UdpLog::Instance()->Info("BindTargetConn account_id:%s", {account_id});
|
|
RemovePendingAccount(socket_handle);
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void GameClientMgr::AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick)
|
|
{
|
|
#if 0
|
|
f8::UdpLog::Instance()->Info("AddPendingAccount %s %d", {account_id, socket_handle});
|
|
auto itr = pending_account_hash_.find(socket_handle);
|
|
if (itr == pending_account_hash_.end()){
|
|
timer_list* timer = a8::Timer::Instance()->AddDeadLineTimerAndAttach(1000 * 10,
|
|
a8::XParams()
|
|
.SetSender(socket_handle),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
GameClientMgr::Instance()->pending_account_hash_.erase(param.sender);
|
|
App::Instance()->perf.max_join_time = std::max((long long)1000 * 10, App::Instance()->perf.max_join_time);
|
|
},
|
|
&timer_attacher_.timer_list_
|
|
|
|
);
|
|
pending_account_hash_[socket_handle] = std::make_tuple(
|
|
account_id,
|
|
req_tick,
|
|
timer
|
|
);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void GameClientMgr::RemovePendingAccount(int socket_handle)
|
|
{
|
|
#if 0
|
|
f8::UdpLog::Instance()->Info("RemovePendingAccount %d", {socket_handle});
|
|
auto itr = pending_account_hash_.find(socket_handle);
|
|
if (itr != pending_account_hash_.end()) {
|
|
#if 0
|
|
f8::Timer::Instance()->DeleteTimer(std::get<2>(itr->second));
|
|
pending_account_hash_.erase(itr);
|
|
#endif
|
|
}
|
|
#endif
|
|
}
|