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