game2006/server/robotserver/playermgr.cc
aozhiwei d27dfdb922 1
2023-12-06 11:36:55 +08:00

52 lines
1.2 KiB
C++

#include "precompile.h"
#include <a8/websocketclient.h>
#include <a8/mutable_xobject.h>
#include <f8/udplog.h>
#include <f8/utils.h>
#include <f8/msgqueue.h>
#include <f8/comgr.h>
#include <f8/coroutine.h>
#include "playermgr.h"
#include "player.h"
#include "httpproxy.h"
#include "iomgr.h"
#include "app.h"
void PlayerMgr::Init()
{
for (int i = 1; i <= 1; ++i) {
int idx = i;
std::string account_id = a8::Format("6513_2006_%d", {idx});
auto hum = std::make_shared<Player>();
hum->Init(idx, account_id);
account_id_hash_[hum->GetAccountId()] = hum;
socket_id_hash_[hum->GetSocketId()] = hum;
}
}
void PlayerMgr::UnInit()
{
}
void PlayerMgr::Update()
{
for (auto& pair : account_id_hash_) {
pair.second->Update();
}
}
std::shared_ptr<Player> PlayerMgr::GetPlayerByAccountId(const std::string& account_id)
{
auto itr = account_id_hash_.find(account_id);
return itr != account_id_hash_.end() ? itr->second : nullptr;
}
std::shared_ptr<Player> PlayerMgr::GetPlayerBySocketHandle(int socket_handle)
{
auto itr = socket_id_hash_.find(socket_handle);
return itr != socket_id_hash_.end() ? itr->second : nullptr;
}