85 lines
3.0 KiB
C++
85 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include <f8/protoutils.h>
|
|
|
|
#include "cs_proto.pb.h"
|
|
namespace a8
|
|
{
|
|
class WebSocketClient;
|
|
}
|
|
|
|
namespace f8
|
|
{
|
|
class Coroutine;
|
|
}
|
|
|
|
class Player
|
|
{
|
|
public:
|
|
enum { HID = HID_Player };
|
|
|
|
public:
|
|
|
|
void Update();
|
|
|
|
void Init(int idx,
|
|
const std::string& account_id,
|
|
const std::string& session_id,
|
|
std::shared_ptr<a8::WebSocketClient> socket);
|
|
template <typename T>
|
|
void SendMsg(T& msg)
|
|
{
|
|
static int msgid = f8::Net_GetMessageId(msg);
|
|
InternalSendMsg(msgid, msg);
|
|
}
|
|
int GetSocketId() { return socket_handle_; }
|
|
bool NetConnected() { return net_connected_; }
|
|
const std::string& GetAccountId() { return account_id_; }
|
|
auto GetWebSocket() { return web_socket_; }
|
|
|
|
void _SMKcpHandshake(f8::MsgHdr& hdr, const cs::SMKcpHandshake& msg);
|
|
void _SMPing(f8::MsgHdr& hdr, const cs::SMPing& msg);
|
|
void _SMRpcError(f8::MsgHdr& hdr, const cs::SMRpcError& msg);
|
|
void _SMReconnect(f8::MsgHdr& hdr, const cs::SMReconnect& msg);
|
|
void _SMWatchWar(f8::MsgHdr& hdr, const cs::SMWatchWar& msg);
|
|
void _SMLeave(f8::MsgHdr& hdr, const cs::SMLeave& msg);
|
|
void _SMMatchCancel(f8::MsgHdr& hdr, const cs::SMMatchCancel& msg);
|
|
void _SMJoinedNotify(f8::MsgHdr& hdr, const cs::SMJoinedNotify& msg);
|
|
void _SMMapInfo(f8::MsgHdr& hdr, const cs::SMMapInfo& msg);
|
|
void _SMUpdate(f8::MsgHdr& hdr, const cs::SMUpdate& msg);
|
|
void _SMRollMsg(f8::MsgHdr& hdr, const cs::SMRollMsg& msg);
|
|
void _SMVoiceNotify(f8::MsgHdr& hdr, const cs::SMVoiceNotify& msg);
|
|
void _SMDisconnectNotify(f8::MsgHdr& hdr, const cs::SMDisconnectNotify& msg);
|
|
void _SMGameOver(f8::MsgHdr& hdr, const cs::SMGameOver& msg);
|
|
void _SMDebugMsg(f8::MsgHdr& hdr, const cs::SMDebugMsg& msg);
|
|
void _SMUiUpdate(f8::MsgHdr& hdr, const cs::SMUiUpdate& msg);
|
|
void _SMGameStart(f8::MsgHdr& hdr, const cs::SMGameStart& msg);
|
|
void _SMSysPiaoMsg(f8::MsgHdr& hdr, const cs::SMSysPiaoMsg& msg);
|
|
void _SMShowCountdown(f8::MsgHdr& hdr, const cs::SMShowCountdown& msg);
|
|
void _SMShowTeamUI(f8::MsgHdr& hdr, const cs::SMShowTeamUI& msg);
|
|
void _SMUpdateMatchInfo(f8::MsgHdr& hdr, const cs::SMUpdateMatchInfo& msg);
|
|
void _SMGetItemNotify(f8::MsgHdr& hdr, const cs::SMGetItemNotify& msg);
|
|
void _SMMatchMemberMsgNotify(f8::MsgHdr& hdr, const cs::SMMatchMemberMsgNotify& msg);
|
|
void _SMPvePassWave(f8::MsgHdr& hdr, const cs::SMPvePassWave& msg);
|
|
void _SMTeamMarkTargetPosList(f8::MsgHdr& hdr, const cs::SMTeamMarkTargetPosList& msg);
|
|
void _SMDebugCmd(f8::MsgHdr& hdr, const cs::SMDebugCmd& msg);
|
|
void _SMNewBieEnd(f8::MsgHdr& hdr, const cs::SMNewBieEnd& msg);
|
|
|
|
private:
|
|
void CoGame(f8::Coroutine* co);
|
|
void InternalSendMsg(int msgid, ::google::protobuf::Message& msg);
|
|
|
|
private:
|
|
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_;
|
|
|
|
};
|