完善协议
This commit is contained in:
parent
db26e044ca
commit
e8320d9c5e
8
server/gameserver/entity.cc
Normal file
8
server/gameserver/entity.cc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include "entity.h"
|
||||||
|
|
||||||
|
void Entity::Update(int delta_time)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
25
server/gameserver/entity.h
Normal file
25
server/gameserver/entity.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum EntityType_e
|
||||||
|
{
|
||||||
|
ET_Player = 1,
|
||||||
|
ET_Obstacle = 2,
|
||||||
|
ET_Building = 3,
|
||||||
|
ET_LootSpawner = 4,
|
||||||
|
ET_Loot = 5,
|
||||||
|
ET_DeadBody = 6,
|
||||||
|
ET_Decal = 7,
|
||||||
|
ET_Projectile = 8,
|
||||||
|
ET_Smoke = 9
|
||||||
|
};
|
||||||
|
|
||||||
|
class Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
unsigned short entity_uniid = 0;
|
||||||
|
Vector2D pos;
|
||||||
|
Vector2D dir;
|
||||||
|
int updated_times = 0;
|
||||||
|
|
||||||
|
virtual void Update(int delta_time);
|
||||||
|
};
|
@ -3,10 +3,26 @@
|
|||||||
#include "playermgr.h"
|
#include "playermgr.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "cs_proto.pb.h"
|
#include "cs_proto.pb.h"
|
||||||
|
#include "room.h"
|
||||||
|
|
||||||
void Player::Update(int delta_time)
|
void Player::Update(int delta_time)
|
||||||
{
|
{
|
||||||
|
if (updated_times % 2 == 0) {
|
||||||
|
cs::SMUpdate msg;
|
||||||
|
if (updated_times == 0) {
|
||||||
|
msg.set_active_player_id(entity_uniid);
|
||||||
|
msg.set_alive_count(room->AliveCount());
|
||||||
|
|
||||||
|
{
|
||||||
|
int data_flags32 = 0;
|
||||||
|
a8::SetBitFlag(data_flags32, 5);
|
||||||
|
a8::SetBitFlag(data_flags32, 15);
|
||||||
|
|
||||||
|
msg.set_data_flags32(data_flags32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SendNotifyMsg(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "entity.h"
|
||||||
|
#include "GGListener.h"
|
||||||
|
|
||||||
namespace cs
|
namespace cs
|
||||||
{
|
{
|
||||||
class CMMove;
|
class CMMove;
|
||||||
@ -10,12 +13,13 @@ namespace cs
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Room;
|
class Room;
|
||||||
class Player
|
class Player : public Entity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { HID = HID_Player };
|
enum { HID = HID_Player };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
int socket_handle = 0;
|
||||||
Room* room = nullptr;
|
Room* room = nullptr;
|
||||||
std::string account_id;
|
std::string account_id;
|
||||||
std::string team_uniid;
|
std::string team_uniid;
|
||||||
@ -25,7 +29,6 @@ class Player
|
|||||||
bool use_touch = false;
|
bool use_touch = false;
|
||||||
std::string avatar_url;
|
std::string avatar_url;
|
||||||
|
|
||||||
unsigned short obj_uniid = 0;
|
|
||||||
float health = 0.0;
|
float health = 0.0;
|
||||||
bool dead = false;
|
bool dead = false;
|
||||||
bool downed = false;
|
bool downed = false;
|
||||||
@ -41,7 +44,13 @@ class Player
|
|||||||
int vip = 0;
|
int vip = 0;
|
||||||
int sdmg = 0;
|
int sdmg = 0;
|
||||||
|
|
||||||
void Update(int delta_time);
|
template <typename T>
|
||||||
|
void SendNotifyMsg(T& msg)
|
||||||
|
{
|
||||||
|
GGListener::Instance()->SendToClient(socket_handle, 0, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Update(int delta_time) override;
|
||||||
|
|
||||||
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
||||||
void _CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg);
|
void _CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg);
|
||||||
|
@ -28,7 +28,7 @@ Player* PlayerMgr::GetPlayerSocket(int socket)
|
|||||||
Player* PlayerMgr::CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJoin& msg)
|
Player* PlayerMgr::CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJoin& msg)
|
||||||
{
|
{
|
||||||
Player* hum = new Player();
|
Player* hum = new Player();
|
||||||
hum->obj_uniid = obj_uniid;
|
hum->entity_uniid = obj_uniid;
|
||||||
hum->account_id = msg.account_id();
|
hum->account_id = msg.account_id();
|
||||||
hum->health = 100;
|
hum->health = 100;
|
||||||
hum->team_uniid = msg.team_uuid();
|
hum->team_uniid = msg.team_uuid();
|
||||||
|
@ -9,8 +9,13 @@ const int ROOM_MAX_PLAYER_NUM = 50;
|
|||||||
|
|
||||||
void Room::Update(int delta_time)
|
void Room::Update(int delta_time)
|
||||||
{
|
{
|
||||||
for (auto& pair : uniid_hash_) {
|
elapsed_time_ += delta_time;
|
||||||
pair.second->Update(delta_time);
|
while (elapsed_time_ >= 50) {
|
||||||
|
for (auto& pair : uniid_hash_) {
|
||||||
|
pair.second->Update(50);
|
||||||
|
pair.second->updated_times++;
|
||||||
|
}
|
||||||
|
elapsed_time_ -= 50;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,10 +41,17 @@ Player* Room::GetPlayerByUniId(unsigned short uniid)
|
|||||||
return itr != uniid_hash_.end() ? itr->second : nullptr;
|
return itr != uniid_hash_.end() ? itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Room::AliveCount()
|
||||||
|
{
|
||||||
|
return accountid_hash_.size();
|
||||||
|
}
|
||||||
|
|
||||||
void Room::AddPlayer(Player* hum)
|
void Room::AddPlayer(Player* hum)
|
||||||
{
|
{
|
||||||
|
hum->pos.x = 100 + rand() % 100;
|
||||||
|
hum->pos.y = 200 + rand() % 200;
|
||||||
hum->room = this;
|
hum->room = this;
|
||||||
uniid_hash_[hum->obj_uniid] = hum;
|
uniid_hash_[hum->entity_uniid] = hum;
|
||||||
accountid_hash_[hum->account_id] = hum;
|
accountid_hash_[hum->account_id] = hum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
void Update(int delta_time);
|
void Update(int delta_time);
|
||||||
bool IsFull();
|
bool IsFull();
|
||||||
int GetPlayerNum();
|
int GetPlayerNum();
|
||||||
|
int AliveCount();
|
||||||
Player* GetPlayerByAccountId(const std::string& accountid);
|
Player* GetPlayerByAccountId(const std::string& accountid);
|
||||||
Player* GetPlayerByUniId(unsigned short uniid);
|
Player* GetPlayerByUniId(unsigned short uniid);
|
||||||
void AddPlayer(Player* hum);
|
void AddPlayer(Player* hum);
|
||||||
@ -30,6 +31,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
unsigned short current_uniid = 0;
|
unsigned short current_uniid = 0;
|
||||||
RoomState_e state_ = RS_Inactive;
|
RoomState_e state_ = RS_Inactive;
|
||||||
|
int elapsed_time_ = 0;
|
||||||
|
|
||||||
std::map<std::string, Player*> accountid_hash_;
|
std::map<std::string, Player*> accountid_hash_;
|
||||||
std::map<unsigned short, Player*> uniid_hash_;
|
std::map<unsigned short, Player*> uniid_hash_;
|
||||||
|
@ -41,12 +41,13 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
|||||||
}
|
}
|
||||||
unsigned short new_uniid = room->AllocUniid();
|
unsigned short new_uniid = room->AllocUniid();
|
||||||
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(new_uniid, msg);
|
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(new_uniid, msg);
|
||||||
|
hum->socket_handle = hdr.socket_handle;
|
||||||
room->AddPlayer(hum);
|
room->AddPlayer(hum);
|
||||||
|
|
||||||
{
|
{
|
||||||
cs::SMJoinedNotify notifymsg;
|
cs::SMJoinedNotify notifymsg;
|
||||||
notifymsg.set_team_mode(msg.team_mode());
|
notifymsg.set_team_mode(msg.team_mode());
|
||||||
notifymsg.set_player_id(hum->obj_uniid);
|
notifymsg.set_player_id(hum->entity_uniid);
|
||||||
notifymsg.set_started(false);
|
notifymsg.set_started(false);
|
||||||
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
|
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,8 @@ struct PerfMonitor
|
|||||||
long long read_count = 0;
|
long long read_count = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PB_REPEATED_PTR(type) ::google::protobuf::RepeatedPtrField<type>
|
struct Vector2D
|
||||||
|
|
||||||
namespace GameData
|
|
||||||
{
|
{
|
||||||
|
float x = 0.0;
|
||||||
}
|
float y = 0.0;
|
||||||
|
};
|
||||||
|
@ -24,7 +24,28 @@ package cs;
|
|||||||
0x01 == 1<<0
|
0x01 == 1<<0
|
||||||
0x02 == 1<<1
|
0x02 == 1<<1
|
||||||
0x04 == 1<<2
|
0x04 == 1<<2
|
||||||
*/
|
|
||||||
|
data_flags字段的意义
|
||||||
|
由于protobuf的二义性无法描述repeated字段是否有值(非repeated的字段可以通过msg.xxx == null来a判断)
|
||||||
|
所以给协议添加了data_flags这样的字段用来描述字段是否有值
|
||||||
|
data_flags32:描述id 1-31的字段哪些是赋值
|
||||||
|
data_flags64: 描述id 31-63直接的字段是否赋值
|
||||||
|
data_flags128...... 以此类推
|
||||||
|
message MFRoleInfo
|
||||||
|
{
|
||||||
|
optional int32 role_id = 1;
|
||||||
|
optional int32 role_name = 2;
|
||||||
|
|
||||||
|
optional int32 role_level = 34;
|
||||||
|
|
||||||
|
optional uint32 data_flags32 = 256;
|
||||||
|
optional uint32 data_flags64 = 257;
|
||||||
|
}
|
||||||
|
role_id是否赋值 (data_flags32 & (1<<(1 - 1))) != 0
|
||||||
|
role_name是否赋值 (data_flags32 & (1<<(2 - 1))) != 0
|
||||||
|
role_level是否赋值 (data_flags64 & (1<<(34 - 33)) != 0
|
||||||
|
客户端可以根据protobuf反射得到字段名和字段id的对应关系做到自动化判断
|
||||||
|
*/
|
||||||
|
|
||||||
//心跳
|
//心跳
|
||||||
message CMPing
|
message CMPing
|
||||||
@ -114,21 +135,24 @@ message MFPlayerPart
|
|||||||
message MFPlayerFull
|
message MFPlayerFull
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional float health = 2; //血量
|
optional MFVector2D pos = 2; //位置
|
||||||
optional bool dead = 3; //是否已死亡
|
optional MFVector2D dir = 3; //朝向
|
||||||
optional bool downed = 4; //
|
|
||||||
optional bool disconnected = 5; //是否断网
|
optional float health = 6; //血量
|
||||||
optional int32 anim_type = 6; //
|
optional bool dead = 7; //是否已死亡
|
||||||
optional int32 anim_seq = 7; //
|
optional bool downed = 8; //
|
||||||
optional int32 action_type = 8; //
|
optional bool disconnected = 9; //是否断网
|
||||||
optional int32 skin = 9; //皮肤id
|
optional int32 anim_type = 10; //
|
||||||
|
optional int32 anim_seq = 11; //
|
||||||
|
optional int32 action_type = 12; //
|
||||||
|
optional int32 skin = 13; //皮肤id
|
||||||
//backpack
|
//backpack
|
||||||
optional int32 helmet = 10; //头盔
|
optional int32 helmet = 16; //头盔
|
||||||
optional int32 chest = 11; //
|
optional int32 chest = 17; //
|
||||||
optional int32 weapon = 12; //武器
|
optional int32 weapon = 18; //武器
|
||||||
optional int32 energy_shield = 13; //能量护盾
|
optional int32 energy_shield = 19; //能量护盾
|
||||||
optional int32 vip = 14; //vip
|
optional int32 vip = 20; //vip
|
||||||
optional int32 sdmg = 15;
|
optional int32 sdmg = 21;
|
||||||
}
|
}
|
||||||
|
|
||||||
//阻挡物-部分
|
//阻挡物-部分
|
||||||
@ -143,19 +167,22 @@ message MFObstaclePart
|
|||||||
message MFObstacleFull
|
message MFObstacleFull
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional int32 obstacle_id = 2; //阻挡物id
|
optional MFVector2D pos = 2; //位置
|
||||||
optional float health = 3; //血量
|
optional float scale = 3; //缩放比
|
||||||
optional bool dead = 4; //是否已死亡
|
|
||||||
|
|
||||||
optional bool is_door = 5; //是否门
|
optional int32 obstacle_id = 6; //阻挡物id
|
||||||
optional int32 door_relative_ori = 6; //
|
optional float health = 7; //血量
|
||||||
optional bool door_can_use = 7; //
|
optional bool dead = 8; //是否已死亡
|
||||||
optional int32 door_seq = 8;
|
|
||||||
|
|
||||||
optional bool is_button = 10;
|
optional bool is_door = 9; //是否门
|
||||||
optional bool button_onoff = 11;
|
optional int32 door_relative_ori = 10; //
|
||||||
optional bool button_can_use = 12;
|
optional bool door_can_use = 11; //
|
||||||
optional int32 button_seq = 13;
|
optional int32 door_seq = 12;
|
||||||
|
|
||||||
|
optional bool is_button = 15;
|
||||||
|
optional bool button_onoff = 16;
|
||||||
|
optional bool button_can_use = 17;
|
||||||
|
optional int32 button_seq = 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
//建筑物-部分
|
//建筑物-部分
|
||||||
@ -171,26 +198,27 @@ message MFBuildingPart
|
|||||||
message MFBuildingFull
|
message MFBuildingFull
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional int32 building_id = 2; //建筑物id
|
optional MFVector2D pos = 2; //位置
|
||||||
optional MFVector2D pos = 3; //位置
|
optional int32 building_id = 3; //建筑物id
|
||||||
optional int32 ori = 4;
|
optional int32 ori = 4; //
|
||||||
optional bool ceiling_dead = 5;
|
|
||||||
|
optional bool ceiling_dead = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
//loot出生点-部分 补给箱
|
//loot出生点-部分 补给箱
|
||||||
message MFLootSpawnerPart
|
message MFLootSpawnerPart
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional int32 loot_id = 2; //id
|
optional MFVector2D pos = 2; //位置
|
||||||
optional MFVector2D pos = 3; //位置
|
optional int32 loot_id = 3; //id
|
||||||
}
|
}
|
||||||
|
|
||||||
//loot出生点-全量
|
//loot出生点-全量
|
||||||
message MFLootSpawnerFull
|
message MFLootSpawnerFull
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional int32 loot_id = 2; //id
|
optional MFVector2D pos = 2; //位置
|
||||||
optional MFVector2D pos = 3; //位置
|
optional int32 loot_id = 3; //id
|
||||||
}
|
}
|
||||||
|
|
||||||
//loot-部分
|
//loot-部分
|
||||||
@ -204,9 +232,11 @@ message MFLootPart
|
|||||||
message MFLootFull
|
message MFLootFull
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional string name = 2;
|
optional MFVector2D pos = 2; //位置
|
||||||
optional int32 count = 3;
|
|
||||||
optional int32 age_ms = 4;
|
optional string name = 6;
|
||||||
|
optional int32 count = 7;
|
||||||
|
optional int32 age_ms = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
//尸体-部分
|
//尸体-部分
|
||||||
@ -220,24 +250,25 @@ message MFDeadBodyPart
|
|||||||
message MFDeadBodyFull
|
message MFDeadBodyFull
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional int32 player_id = 2; //玩家id
|
optional MFVector2D pos = 2; //位置
|
||||||
optional int32 inkjet = 3;
|
|
||||||
|
optional int32 inkjet = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
//decal-部分
|
//decal-部分
|
||||||
message MFDecalPart
|
message MFDecalPart
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional int32 decal_id = 2; //id
|
optional MFVector2D pos = 2; //位置
|
||||||
optional MFVector2D pos = 3; //位置
|
optional int32 decal_id = 3; //id
|
||||||
}
|
}
|
||||||
|
|
||||||
//decal-全量
|
//decal-全量
|
||||||
message MFDecalFull
|
message MFDecalFull
|
||||||
{
|
{
|
||||||
optional int32 obj_uniid = 1; //唯一id
|
optional int32 obj_uniid = 1; //唯一id
|
||||||
optional int32 decal_id = 2; //id
|
optional MFVector2D pos = 2; //位置
|
||||||
optional MFVector2D pos = 3; //位置
|
optional int32 decal_id = 3; //id
|
||||||
}
|
}
|
||||||
|
|
||||||
//发射体-部分
|
//发射体-部分
|
||||||
@ -542,7 +573,7 @@ message CMVoice
|
|||||||
message SMJoinedNotify
|
message SMJoinedNotify
|
||||||
{
|
{
|
||||||
optional int32 team_mode = 1; //队伍模式 0:单人 1:多人
|
optional int32 team_mode = 1; //队伍模式 0:单人 1:多人
|
||||||
optional int32 player_id = 2; //玩家id
|
optional int32 player_id = 2; //玩家id(自己)
|
||||||
optional bool started = 3; //游戏是否已开始
|
optional bool started = 3; //游戏是否已开始
|
||||||
repeated MFPlayerInfo player_infos = 4; //玩家信息
|
repeated MFPlayerInfo player_infos = 4; //玩家信息
|
||||||
|
|
||||||
@ -557,7 +588,7 @@ message SMMapInfo
|
|||||||
optional int32 width = 2; //地图宽度
|
optional int32 width = 2; //地图宽度
|
||||||
optional int32 height = 3; //地图高度
|
optional int32 height = 3; //地图高度
|
||||||
optional int32 seed = 4; //没用到
|
optional int32 seed = 4; //没用到
|
||||||
repeated MFPlace places = 5; //没用到
|
repeated MFPlace places = 5; //
|
||||||
repeated MFMapObject objects = 6; //地图对象
|
repeated MFMapObject objects = 6; //地图对象
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,11 +601,11 @@ message SMPlayerInfo
|
|||||||
//帧事件
|
//帧事件
|
||||||
message SMUpdate
|
message SMUpdate
|
||||||
{
|
{
|
||||||
repeated int32 del_objids = 1;
|
repeated int32 del_objids = 2;
|
||||||
repeated MFObjectFull full_objects = 2;
|
repeated MFObjectFull full_objects = 3;
|
||||||
repeated MFObjectPart part_objects = 3;
|
repeated MFObjectPart part_objects = 4;
|
||||||
optional int32 active_player_id = 10; //当前活跃玩家id
|
optional int32 active_player_id = 5; //当前活跃玩家id
|
||||||
optional MFPlayerData active_player_data = 11; //活跃玩家数据
|
optional MFPlayerData active_player_data = 6; //活跃玩家数据
|
||||||
optional int32 alive_count = 15; //存活数量
|
optional int32 alive_count = 15; //存活数量
|
||||||
optional int32 gasT = 16;
|
optional int32 gasT = 16;
|
||||||
optional MFGasData gas_data = 17;
|
optional MFGasData gas_data = 17;
|
||||||
@ -585,6 +616,8 @@ message SMUpdate
|
|||||||
repeated MFExplosion explosions = 22;
|
repeated MFExplosion explosions = 22;
|
||||||
repeated MFEmote emotes = 23;
|
repeated MFEmote emotes = 23;
|
||||||
optional int32 ack = 24;
|
optional int32 ack = 24;
|
||||||
|
|
||||||
|
optional uint32 data_flags32 = 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
//xx
|
//xx
|
||||||
|
Loading…
x
Reference in New Issue
Block a user