205 lines
5.7 KiB
C++
205 lines
5.7 KiB
C++
#include "precompile.h"
|
|
|
|
#include "playermgr.h"
|
|
#include "player.h"
|
|
#include "cs_proto.pb.h"
|
|
#include "ss_proto.pb.h"
|
|
#include "room.h"
|
|
#include "metamgr.h"
|
|
|
|
#include "framework/cpp/utils.h"
|
|
|
|
void PlayerMgr::Init()
|
|
{
|
|
}
|
|
|
|
void PlayerMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
void PlayerMgr::_SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg)
|
|
{
|
|
Player* hum = GetPlayerBySocket(hdr.socket_handle);
|
|
if (hum) {
|
|
RemovePlayerBySocket(hdr.socket_handle);
|
|
hum->room->OnPlayerOffline(hum);
|
|
}
|
|
}
|
|
|
|
void PlayerMgr::_SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg)
|
|
{
|
|
ss::SS_Pong respmsg;
|
|
GGListener::Instance()->SendToClient(hdr.socket_handle, 0, respmsg);
|
|
}
|
|
|
|
int PlayerMgr::OnlineNum()
|
|
{
|
|
return socket_hash_.size();
|
|
}
|
|
|
|
Player* PlayerMgr::GetPlayerBySocket(int socket)
|
|
{
|
|
auto itr = socket_hash_.find(socket);
|
|
return itr != socket_hash_.end() ? itr->second : nullptr;
|
|
}
|
|
|
|
Player* PlayerMgr::CreatePlayerByCMJoin(Player* hum,
|
|
long ip_saddr,
|
|
int socket,
|
|
const cs::CMJoin& msg)
|
|
{
|
|
hum->socket_handle = socket;
|
|
hum->ip_saddr = ip_saddr;
|
|
hum->account_id = msg.account_id();
|
|
hum->session_id = msg.session_id();
|
|
hum->from_appid = msg.from_appid();
|
|
hum->name = msg.name();
|
|
hum->team_uuid = msg.team_uuid();
|
|
hum->team_mode = msg.team_mode();
|
|
hum->auto_fill = msg.auto_fill();
|
|
hum->use_touch = msg.use_touch();
|
|
hum->avatar_url = msg.avatar_url();
|
|
hum->energy_shield = msg.energy_shield();
|
|
hum->today_enter_times = msg.today_enter_times();
|
|
hum->create_tick = a8::XGetTickCount();
|
|
hum->account_registertime = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
|
|
hum->channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
|
|
hum->atk_add = msg.atk_add();
|
|
hum->emoji1 = msg.emoji1();
|
|
hum->emoji2 = msg.emoji2();
|
|
hum->parachute = msg.parachute();
|
|
hum->has_pass = msg.has_pass();
|
|
hum->user_value1 = msg.user_value1();
|
|
hum->user_value2 = msg.user_value2();
|
|
hum->user_value3 = msg.user_value3();
|
|
hum->guild_id = msg.guild_id();
|
|
#if 0
|
|
if (hum->atk_add > 0.9999f) {
|
|
hum->atk_add = hum->atk_add / 100.0f;
|
|
a8::SetBitFlag(hum->status, HS_AtkAdd);
|
|
}
|
|
#endif
|
|
for (auto& weapon : msg.weapons()) {
|
|
if (weapon.weapon_id() != 0 && weapon.weapon_lv() > 0) {
|
|
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(weapon.weapon_id());
|
|
if (equip_meta) {
|
|
hum->weapon_configs[weapon.weapon_id()] = weapon.weapon_lv();
|
|
Weapon& spec_weapon = a8::FastAppend(hum->spec_weapons);
|
|
spec_weapon.weapon_id = weapon.weapon_id();
|
|
spec_weapon.weapon_lv = weapon.weapon_lv();
|
|
spec_weapon.ammo = weapon.ammo();
|
|
spec_weapon.meta = equip_meta;
|
|
spec_weapon.Recalc();
|
|
}
|
|
}
|
|
}
|
|
for (auto& weapon : msg.grow_weapons()) {
|
|
if (weapon.weapon_id() != 0) {
|
|
hum->grow_weapon.weapon_id = weapon.weapon_id();
|
|
hum->grow_weapon.weapon_lv = weapon.weapon_lv();
|
|
hum->grow_weapon.ammo = weapon.ammo();
|
|
}
|
|
}
|
|
for (auto& skin : msg.skins()) {
|
|
if (skin.skin_id() != 0 && skin.skin_lv() > 0) {
|
|
hum->skin_configs[skin.skin_id()] = skin.skin_lv();
|
|
}
|
|
}
|
|
#if 1
|
|
{
|
|
int idx = 0;
|
|
for (int skin_id : msg.baseskin()) {
|
|
hum->SetSkin(idx, skin_id);
|
|
++idx;
|
|
}
|
|
}
|
|
#else
|
|
hum->SetSkinInfo(msg.baseskin());
|
|
#endif
|
|
socket_hash_[socket] = hum;
|
|
return hum;
|
|
}
|
|
|
|
void PlayerMgr::OnClientDisconnect(a8::XParams& param)
|
|
{
|
|
int gg_socket = param.sender;
|
|
|
|
std::vector<int> socket_list;
|
|
for (auto& pair : socket_hash_) {
|
|
unsigned short parent_socket_handle = (pair.first >> 16) & 0xFFFF;
|
|
if (parent_socket_handle == gg_socket) {
|
|
socket_list.push_back(pair.first);
|
|
}
|
|
}
|
|
for (int socket_handle : socket_list) {
|
|
Player* hum = GetPlayerBySocket(socket_handle);
|
|
if (hum) {
|
|
RemovePlayerBySocket(socket_handle);
|
|
hum->room->OnPlayerOffline(hum);
|
|
}
|
|
}
|
|
}
|
|
|
|
void PlayerMgr::RemovePlayerBySocket(int socket_handle)
|
|
{
|
|
auto itr = socket_hash_.find(socket_handle);
|
|
if (itr != socket_hash_.end()) {
|
|
itr->second->socket_handle = 0;
|
|
socket_hash_.erase(itr);
|
|
}
|
|
}
|
|
|
|
void PlayerMgr::IncAccountNum(const std::string& account_id)
|
|
{
|
|
auto itr = account_num_hash_.find(account_id);
|
|
if (itr != account_num_hash_.end()) {
|
|
++(itr->second);
|
|
if (itr->second > 3) {
|
|
a8::UdpLog::Instance()->Warning
|
|
(
|
|
"IncAccountNum account_id:%s num:%d > 3",
|
|
{
|
|
account_id,
|
|
itr->second
|
|
}
|
|
);
|
|
}
|
|
} else {
|
|
account_num_hash_[account_id] = 1;
|
|
}
|
|
}
|
|
|
|
void PlayerMgr::DecAccountNum(const std::string& account_id)
|
|
{
|
|
auto itr = account_num_hash_.find(account_id);
|
|
if (itr != account_num_hash_.end()) {
|
|
--(itr->second);
|
|
if (itr->second < 0) {
|
|
a8::UdpLog::Instance()->Warning
|
|
(
|
|
"DecAccountNum account_id:%s num:%d < 0",
|
|
{
|
|
account_id,
|
|
itr->second
|
|
}
|
|
);
|
|
}
|
|
if (itr->second <= 0) {
|
|
account_num_hash_.erase(itr);
|
|
}
|
|
} else {
|
|
a8::UdpLog::Instance()->Warning
|
|
(
|
|
"DecAccountNum account_id:%s not exits",
|
|
{
|
|
account_id
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
void PlayerMgr::ReBindSocket(Player* hum)
|
|
{
|
|
socket_hash_[hum->socket_handle] = hum;
|
|
}
|