1
This commit is contained in:
parent
d81957040e
commit
608fd18c26
@ -1,9 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
namespace a8
|
||||
{
|
||||
class WebSocketClient;
|
||||
}
|
||||
|
||||
class Player
|
||||
{
|
||||
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_;
|
||||
|
||||
};
|
||||
|
@ -15,36 +15,36 @@
|
||||
|
||||
void PlayerMgr::Init()
|
||||
{
|
||||
f8::CoMgr::Instance()->CreateCo
|
||||
(
|
||||
[] (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();
|
||||
}
|
||||
});
|
||||
web_socket = std::make_shared<a8::WebSocketClient>
|
||||
(
|
||||
*IoMgr::Instance()->GetIoContext(0),
|
||||
"192.168.100.21",
|
||||
7601
|
||||
);
|
||||
web_socket->Open();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
f8::CoMgr::Instance()->CreateCo
|
||||
(
|
||||
[this, i] (f8::Coroutine* co)
|
||||
{
|
||||
CoCreatePlayer(i, co);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/singleton.h>
|
||||
#include <a8/websocketclient.h>
|
||||
|
||||
class Player;
|
||||
class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||
@ -16,8 +15,8 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||
public:
|
||||
void Init();
|
||||
void UnInit();
|
||||
void CoCreatePlayer(int idx, f8::Coroutine* co);
|
||||
|
||||
private:
|
||||
std::shared_ptr<a8::WebSocketClient> web_socket;
|
||||
std::map<std::string, std::shared_ptr<Player>> account_id_hash_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user