229 lines
7.1 KiB
C++
229 lines
7.1 KiB
C++
#include "precompile.h"
|
|
|
|
#include <a8/awaiter.h>
|
|
#include <a8/promise.h>
|
|
#include <a8/websocketclient.h>
|
|
|
|
#include <f8/udplog.h>
|
|
#include <f8/utils.h>
|
|
|
|
#include "player.h"
|
|
#include "app.h"
|
|
|
|
void Player::Update()
|
|
{
|
|
|
|
}
|
|
|
|
void Player::Init(int idx,
|
|
const std::string& account_id,
|
|
const std::string& session_id,
|
|
std::shared_ptr<a8::WebSocketClient> socket)
|
|
{
|
|
socket_handle_ = idx;
|
|
account_id_ = account_id;
|
|
session_id_ = session_id;
|
|
web_socket_ = socket;
|
|
web_socket_->on_error =
|
|
[this] (a8::WebSocketClient*,int err_code)
|
|
{
|
|
f8::UdpLog::Instance()->Warning
|
|
("WebSocketClient on_error %d", {err_code});
|
|
};
|
|
web_socket_->on_connect =
|
|
[this] (a8::WebSocketClient* )
|
|
{
|
|
net_connected_ = true;
|
|
f8::UdpLog::Instance()->Info
|
|
("WebSocketClient on_connect", {});
|
|
};
|
|
web_socket_->on_disconnect =
|
|
[this] (a8::WebSocketClient* )
|
|
{
|
|
f8::UdpLog::Instance()->Warning
|
|
("WebSocketClient on_disconnect", {});
|
|
};
|
|
web_socket_->on_decode_userpacket =
|
|
[this, socket_handle = GetSocketId()]
|
|
(char* buf, int& offset, unsigned int buflen)
|
|
{
|
|
bool warning = false;
|
|
while (buflen - offset >= sizeof(f8::PackHead)) {
|
|
f8::PackHead* p = (f8::PackHead*)&buf[offset];
|
|
if (p->magic_code == f8::MAGIC_CODE) {
|
|
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
|
|
break;
|
|
}
|
|
f8::App::Instance()->AddSocketMsg
|
|
(MSF_GameGate,
|
|
socket_handle,
|
|
//p->ip_saddr,
|
|
0,
|
|
p->msgid,
|
|
p->seqid,
|
|
&buf[offset + sizeof(f8::PackHead)],
|
|
p->packlen,
|
|
0);
|
|
offset += sizeof(f8::PackHead) + p->packlen;
|
|
} else {
|
|
warning = true;
|
|
offset++;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (warning) {
|
|
f8::UdpLog::Instance()->Warning("收到client非法数据包", {});
|
|
}
|
|
};
|
|
}
|
|
|
|
void Player::InternalSendMsg(int msgid, ::google::protobuf::Message& msg)
|
|
{
|
|
int packlen = msg.ByteSize();
|
|
|
|
char* buff = (char*)malloc(sizeof(f8::PackHead) + packlen);
|
|
f8::PackHead* head = (f8::PackHead*)buff;
|
|
head->packlen = packlen;
|
|
head->msgid = msgid;
|
|
head->magic_code = f8::MAGIC_CODE;
|
|
msg.SerializeToArray(buff + sizeof(f8::PackHead), packlen);
|
|
web_socket_->SendBuff(buff, sizeof(f8::PackHead) + packlen);
|
|
}
|
|
|
|
void Player::_SMKcpHandshake(f8::MsgHdr* hdr, const cs::SMKcpHandshake& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMPing(f8::MsgHdr* hdr, const cs::SMPing& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMRpcError(f8::MsgHdr* hdr, const cs::SMRpcError& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMReconnect(f8::MsgHdr* hdr, const cs::SMReconnect& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMWatchWar(f8::MsgHdr* hdr, const cs::SMWatchWar& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMLeave(f8::MsgHdr* hdr, const cs::SMLeave& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMMatchCancel(f8::MsgHdr* hdr, const cs::SMMatchCancel& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&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)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMUpdate(f8::MsgHdr* hdr, const cs::SMUpdate& msg)
|
|
{
|
|
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMRollMsg(f8::MsgHdr* hdr, const cs::SMRollMsg& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMVoiceNotify(f8::MsgHdr* hdr, const cs::SMVoiceNotify& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMDisconnectNotify(f8::MsgHdr* hdr, const cs::SMDisconnectNotify& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMGameOver(f8::MsgHdr* hdr, const cs::SMGameOver& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMDebugMsg(f8::MsgHdr* hdr, const cs::SMDebugMsg& msg)
|
|
{
|
|
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMUiUpdate(f8::MsgHdr* hdr, const cs::SMUiUpdate& msg)
|
|
{
|
|
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMGameStart(f8::MsgHdr* hdr, const cs::SMGameStart& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMSysPiaoMsg(f8::MsgHdr* hdr, const cs::SMSysPiaoMsg& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMShowCountdown(f8::MsgHdr* hdr, const cs::SMShowCountdown& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMShowTeamUI(f8::MsgHdr* hdr, const cs::SMShowTeamUI& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMUpdateMatchInfo(f8::MsgHdr* hdr, const cs::SMUpdateMatchInfo& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMGetItemNotify(f8::MsgHdr* hdr, const cs::SMGetItemNotify& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMMatchMemberMsgNotify(f8::MsgHdr* hdr, const cs::SMMatchMemberMsgNotify& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMPvePassWave(f8::MsgHdr* hdr, const cs::SMPvePassWave& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMTeamMarkTargetPosList(f8::MsgHdr* hdr, const cs::SMTeamMarkTargetPosList& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMDebugCmd(f8::MsgHdr* hdr, const cs::SMDebugCmd& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|
|
|
|
void Player::_SMNewBieEnd(f8::MsgHdr* hdr, const cs::SMNewBieEnd& msg)
|
|
{
|
|
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
|
}
|