1
This commit is contained in:
parent
8be63ace09
commit
0d795ff0dc
@ -10,6 +10,8 @@
|
||||
|
||||
#include "player.h"
|
||||
|
||||
#include "cs_proto.pb.h"
|
||||
|
||||
void Player::Update()
|
||||
{
|
||||
|
||||
@ -57,18 +59,30 @@ void Player::CoLogin(f8::Coroutine* co)
|
||||
{
|
||||
|
||||
};
|
||||
web_socket_->Open();
|
||||
|
||||
{
|
||||
web_socket_->Open();
|
||||
while (!net_connected_) {
|
||||
co->CoYield();
|
||||
}
|
||||
}
|
||||
|
||||
f8::UdpLog::Instance()->Info
|
||||
("WebSocketClient on_connect ok", {});
|
||||
}
|
||||
{
|
||||
cs::CMJoin msg;
|
||||
SendMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::CoGame(f8::Coroutine* co)
|
||||
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);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <f8/protoutils.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
class WebSocketClient;
|
||||
@ -28,8 +30,10 @@ public:
|
||||
const std::string& session_id,
|
||||
std::shared_ptr<a8::WebSocketClient> socket);
|
||||
template <typename T>
|
||||
void SendNotifyMsg(T& msg)
|
||||
void SendMsg(T& msg)
|
||||
{
|
||||
static int msgid = f8::Net_GetMessageId(msg);
|
||||
InternalSendMsg(msgid, msg);
|
||||
}
|
||||
int GetSocketId() { return socket_id_; }
|
||||
bool NetConnected() { return net_connected_; }
|
||||
@ -38,7 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
void CoLogin(f8::Coroutine* co);
|
||||
void CoGame(f8::Coroutine* co);
|
||||
void InternalSendMsg(int msgid, ::google::protobuf::Message& msg);
|
||||
|
||||
private:
|
||||
int socket_id_ = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user