1
This commit is contained in:
parent
7bdd79eb3a
commit
aa2105b30c
@ -340,7 +340,7 @@ void App::UnInitLog()
|
||||
bool App::ParseOpt()
|
||||
{
|
||||
int ch = 0;
|
||||
while ((ch = getopt(argc, argv, "i:t:r:f:n:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "i:t:r:f:n:r:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'n':
|
||||
{
|
||||
@ -367,6 +367,13 @@ bool App::ParseOpt()
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
{
|
||||
robot_num = a8::XValue(optarg);
|
||||
robot_num = std::min(robot_num, 100);
|
||||
robot_num = std::max(robot_num, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return instance_id > 0 && node_id > 0;
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
public:
|
||||
int instance_id = 0;
|
||||
int node_id = 0;
|
||||
int robot_num = 1;
|
||||
bool is_test_mode = false;
|
||||
int test_param = 0;
|
||||
bool servicing = true;
|
||||
|
@ -22,7 +22,7 @@ void Player::Init(int idx,
|
||||
const std::string& session_id,
|
||||
std::shared_ptr<a8::WebSocketClient> socket)
|
||||
{
|
||||
socket_id_ = idx;
|
||||
socket_handle_ = idx;
|
||||
account_id_ = account_id;
|
||||
session_id_ = session_id;
|
||||
web_socket_ = socket;
|
||||
@ -81,11 +81,11 @@ void Player::Init(int idx,
|
||||
(
|
||||
[this] (f8::Coroutine* co)
|
||||
{
|
||||
CoLogin(co);
|
||||
CoGame(co);
|
||||
});
|
||||
}
|
||||
|
||||
void Player::CoLogin(f8::Coroutine* co)
|
||||
void Player::CoGame(f8::Coroutine* co)
|
||||
{
|
||||
{
|
||||
web_socket_->Open();
|
||||
@ -103,6 +103,13 @@ void Player::CoLogin(f8::Coroutine* co)
|
||||
msg.set_hero_id(30800);
|
||||
SendMsg(msg);
|
||||
}
|
||||
{
|
||||
while (!join_ok_) {
|
||||
co->CoYield();
|
||||
}
|
||||
f8::UdpLog::Instance()->Info
|
||||
("join ok", {});
|
||||
}
|
||||
}
|
||||
|
||||
void Player::InternalSendMsg(int msgid, ::google::protobuf::Message& msg)
|
||||
@ -156,6 +163,7 @@ void Player::_SMMatchCancel(f8::MsgHdr& hdr, const cs::SMMatchCancel& msg)
|
||||
void Player::_SMJoinedNotify(f8::MsgHdr& hdr, const cs::SMJoinedNotify& msg)
|
||||
{
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
join_ok_ = true;
|
||||
}
|
||||
|
||||
void Player::_SMMapInfo(f8::MsgHdr& hdr, const cs::SMMapInfo& msg)
|
||||
@ -195,7 +203,7 @@ void Player::_SMDebugMsg(f8::MsgHdr& hdr, const cs::SMDebugMsg& msg)
|
||||
|
||||
void Player::_SMUiUpdate(f8::MsgHdr& hdr, const cs::SMUiUpdate& msg)
|
||||
{
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
}
|
||||
|
||||
void Player::_SMGameStart(f8::MsgHdr& hdr, const cs::SMGameStart& msg)
|
||||
|
@ -13,13 +13,6 @@ namespace f8
|
||||
class Coroutine;
|
||||
}
|
||||
|
||||
A8_DECLARE_ENUM(PlayerState_e,
|
||||
Init = 0,
|
||||
ConnectNet,
|
||||
Login,
|
||||
Game
|
||||
);
|
||||
|
||||
class Player
|
||||
{
|
||||
public:
|
||||
@ -39,7 +32,7 @@ public:
|
||||
static int msgid = f8::Net_GetMessageId(msg);
|
||||
InternalSendMsg(msgid, msg);
|
||||
}
|
||||
int GetSocketId() { return socket_id_; }
|
||||
int GetSocketId() { return socket_handle_; }
|
||||
bool NetConnected() { return net_connected_; }
|
||||
const std::string& GetAccountId() { return account_id_; }
|
||||
auto GetWebSocket() { return web_socket_; }
|
||||
@ -73,18 +66,18 @@ public:
|
||||
void _SMNewBieEnd(f8::MsgHdr& hdr, const cs::SMNewBieEnd& msg);
|
||||
|
||||
private:
|
||||
void CoLogin(f8::Coroutine* co);
|
||||
void CoGame(f8::Coroutine* co);
|
||||
void InternalSendMsg(int msgid, ::google::protobuf::Message& msg);
|
||||
|
||||
private:
|
||||
int socket_id_ = 0;
|
||||
PlayerState_e state_ = PlayerState_e::Init;
|
||||
int socket_handle_ = 0;
|
||||
std::string account_id_;
|
||||
std::string session_id_;
|
||||
std::string remote_ip_;
|
||||
int remote_port_ = 0;
|
||||
|
||||
bool net_connected_ = false;
|
||||
bool join_ok_ = false;
|
||||
|
||||
std::shared_ptr<a8::WebSocketClient> web_socket_;
|
||||
|
||||
|
@ -13,10 +13,11 @@
|
||||
#include "player.h"
|
||||
#include "httpproxy.h"
|
||||
#include "iomgr.h"
|
||||
#include "app.h"
|
||||
|
||||
void PlayerMgr::Init()
|
||||
{
|
||||
for (int i = 1; i <= 1; ++i) {
|
||||
for (int i = 1; i <= App::Instance()->robot_num; ++i) {
|
||||
f8::CoMgr::Instance()->CreateCo
|
||||
(
|
||||
[this, i] (f8::Coroutine* co)
|
||||
|
Loading…
x
Reference in New Issue
Block a user