This commit is contained in:
aozhiwei 2023-05-28 15:44:19 +08:00
parent d81957040e
commit 608fd18c26
3 changed files with 40 additions and 32 deletions

View File

@ -1,9 +1,18 @@
#pragma once #pragma once
namespace a8
{
class WebSocketClient;
}
class Player class Player
{ {
public: public:
std::string account_id;
std::string session_id; private:
std::string account_id_;
std::string session_id_;
std::shared_ptr<a8::WebSocketClient> web_socket_;
}; };

View File

@ -15,9 +15,21 @@
void PlayerMgr::Init() void PlayerMgr::Init()
{ {
for (int i = 0; i < 10; ++i) {
f8::CoMgr::Instance()->CreateCo f8::CoMgr::Instance()->CreateCo
( (
[] (f8::Coroutine* co) [this, i] (f8::Coroutine* co)
{
CoCreatePlayer(i, co);
});
}
}
void PlayerMgr::UnInit()
{
}
void PlayerMgr::CoCreatePlayer(int idx, f8::Coroutine* co)
{ {
bool ret = false; bool ret = false;
std::shared_ptr<a8::XObject> rsp; std::shared_ptr<a8::XObject> rsp;
@ -35,16 +47,4 @@ void PlayerMgr::Init()
} else { } else {
abort(); abort();
} }
});
web_socket = std::make_shared<a8::WebSocketClient>
(
*IoMgr::Instance()->GetIoContext(0),
"192.168.100.21",
7601
);
web_socket->Open();
}
void PlayerMgr::UnInit()
{
} }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <a8/singleton.h> #include <a8/singleton.h>
#include <a8/websocketclient.h>
class Player; class Player;
class PlayerMgr : public a8::Singleton<PlayerMgr> class PlayerMgr : public a8::Singleton<PlayerMgr>
@ -16,8 +15,8 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
public: public:
void Init(); void Init();
void UnInit(); void UnInit();
void CoCreatePlayer(int idx, f8::Coroutine* co);
private: private:
std::shared_ptr<a8::WebSocketClient> web_socket;
std::map<std::string, std::shared_ptr<Player>> account_id_hash_; std::map<std::string, std::shared_ptr<Player>> account_id_hash_;
}; };