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,36 +15,36 @@
void PlayerMgr::Init() void PlayerMgr::Init()
{ {
f8::CoMgr::Instance()->CreateCo for (int i = 0; i < 10; ++i) {
( f8::CoMgr::Instance()->CreateCo
[] (f8::Coroutine* co) (
{ [this, i] (f8::Coroutine* co)
bool ret = false; {
std::shared_ptr<a8::XObject> rsp; CoCreatePlayer(i, co);
co->CoAwait });
(HttpProxy::Instance()->CoHttpGet }
(
"https://game2006-test.kingsome.cn/webapp/index.php?c=Ops&a=selfChecking&",
a8::XObject(),
&ret,
&rsp
)
);
if (ret) {
a8::XPrintf("rsp:%s\n", {rsp->ToJsonStr()});
} else {
abort();
}
});
web_socket = std::make_shared<a8::WebSocketClient>
(
*IoMgr::Instance()->GetIoContext(0),
"192.168.100.21",
7601
);
web_socket->Open();
} }
void PlayerMgr::UnInit() void PlayerMgr::UnInit()
{ {
} }
void PlayerMgr::CoCreatePlayer(int idx, f8::Coroutine* co)
{
bool ret = false;
std::shared_ptr<a8::XObject> rsp;
co->CoAwait
(HttpProxy::Instance()->CoHttpGet
(
"https://game2006-test.kingsome.cn/webapp/index.php?c=Ops&a=selfChecking&",
a8::XObject(),
&ret,
&rsp
)
);
if (ret) {
a8::XPrintf("rsp:%s\n", {rsp->ToJsonStr()});
} else {
abort();
}
}

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_;
}; };