merge master

This commit is contained in:
aozhiwei 2020-08-17 10:14:45 +08:00
commit f30bf003ad
21 changed files with 246 additions and 39 deletions

View File

@ -166,6 +166,7 @@ enum HumanAttrType_e
kHAT_FireRate = 9,
kHAT_Volume = 10,
kHAT_MaxHp = 11,
kHAT_ReloadTime = 14,
kHAT_BulletAngle = 20,
kHAT_End
};
@ -321,6 +322,11 @@ enum ColliderTag_e
kHalfWallTag = 1
};
enum GameChannel_e
{
kWxChannelId = 6001
};
const char* const PROJ_NAME_FMT = "game%d_gameserver";
const char* const PROJ_ROOT_FMT = "/data/logs/%s";

View File

@ -84,6 +84,7 @@ void HandlerMgr::RegisterNetMsgHandlers()
RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_WSP_SocketDisconnect);
RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_Ping);
RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin);
RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMReconnect);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMMove);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMEmote);

View File

@ -135,7 +135,12 @@ void Human::Initialize()
RecalcSelfCollider();
volume_ = meta->volume;
observers_.insert(this);
ability.hp = meta->i->health() + (spec_weapon.meta ? spec_weapon.GetAttrValue(kHAT_MaxHp) : 0);
ability.hp = meta->i->health();
for (auto& weapon : spec_weapons) {
if (weapon.meta) {
ability.hp += weapon.meta ? weapon.GetAttrValue(kHAT_MaxHp) : 0;
}
}
}
float Human::GetSpeed()
@ -829,7 +834,7 @@ void Human::AutoLoadingBullet(bool manual)
on_loading_bullet();
}
StartAction(AT_Reload,
p_weapon->meta->i->reload_time(),
p_weapon->GetAttrValue(kHAT_ReloadTime),
p_weapon->weapon_id,
p_weapon->weapon_idx);
}
@ -848,6 +853,7 @@ void Human::StartAction(ActionType_e action_type,
this->action_target_id == target_id) {
return;
}
action_duration = std::max(0, action_duration);
this->action_type = action_type;
this->action_frameno = room->GetFrameNo();
this->action_duration = action_duration;
@ -3950,7 +3956,12 @@ void Human::OnMetaChange()
curr_weapon = &weapons[0];
}
}
ability.hp = meta->i->health() + (spec_weapon.meta ? spec_weapon.GetAttrValue(kHAT_MaxHp) : 0);
ability.hp = meta->i->health();
for (auto& weapon : spec_weapons) {
if (weapon.meta) {
ability.hp += weapon.meta ? weapon.GetAttrValue(kHAT_MaxHp) : 0;
}
}
room->frame_event.AddHpChg(this);
RecalcBaseAttr();
skill_meta_ = MetaMgr::Instance()->GetSkill(meta->i->active_skill());

View File

@ -129,7 +129,7 @@ class Human : public MoveableEntity
long long send_msg_times = 0;
Weapon spec_weapon;
std::list<Weapon> spec_weapons;
Weapon grow_weapon;
std::map<int, int> weapon_configs;
std::map<int, int> skin_configs;

View File

@ -34,6 +34,7 @@ void JsonDataMgr::Init()
gameserver_cluster_json_.ReadFromFile(gameserver_cluster_json_file);
ip = GetConf()->At("ip")->AsXValue().GetString();
listen_port = GetConf()->At("listen_port")->AsXValue();
server_info = a8::Format("%s:%d", {ip, listen_port});
Reload();
}

View File

@ -16,6 +16,8 @@ public:
std::string ip;
int listen_port = 0;
std::string server_info;
void Reload();
private:

View File

@ -46,4 +46,5 @@ void Loot::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
p->set_item_id(item_id);
p->set_count(count);
p->set_item_level(item_level);
}

View File

@ -4,6 +4,7 @@
#include "room.h"
#include "mapinstance.h"
#include "metamgr.h"
#include "cs_proto.pb.h"
void MapMgr::Init()
{
@ -19,6 +20,12 @@ void MapMgr::Init()
map_instance->Init();
instance_hash_[map_instance->map_id] = map_instance;
}
if (MetaMgr::Instance()->GetMap(4001)) {
MapInstance* map_instance = new MapInstance();
map_instance->map_id = 4001;
map_instance->Init();
instance_hash_[map_instance->map_id] = map_instance;
}
}
void MapMgr::UnInit()
@ -34,7 +41,16 @@ void MapMgr::AttachRoom(Room* room, RoomInitInfo& init_info)
{
MapInstance* map_instance = GetMapInstance(2001);
if (init_info.room_mode == kZombieMode) {
map_instance = GetMapInstance(3001);
if (init_info.creator_channel == kWxChannelId &&
init_info.creator_proto_version == cs::ProtoVersion) {
map_instance = GetMapInstance(4001);
} else {
if (init_info.creator_proto_version == cs::ProtoVersion) {
map_instance = GetMapInstance(4001);
} else {
map_instance = GetMapInstance(3001);
}
}
}
if (!map_instance) {
abort();

View File

@ -3,6 +3,8 @@
#include "metadata.h"
#include "metamgr.h"
#include "framework/cpp/utils.h"
namespace MetaData
{
void Parameter::Init()
@ -102,7 +104,11 @@ namespace MetaData
}
{
std::vector<std::string> strings;
a8::Split(i->attr_type(), strings, '|');
if (!i->spera_type().empty()) {
a8::Split(i->spera_type(), strings, '|');
} else {
a8::Split(i->attr_type(), strings, '|');
}
int level = 1;
for (auto& str : strings) {
if (str.empty()) {

View File

@ -16,6 +16,7 @@
#include "typeconvert.h"
#include "playermgr.h"
#include "perfmonitor.h"
#include "jsondatamgr.h"
const int kREVIVE_BUFF_ID = 1005;
@ -872,22 +873,24 @@ void Player::ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google:
curr_weapon->ammo = add_num;
}
}
if (spec_weapon.weapon_id != 0) {
for (auto& spec_weapon : spec_weapons) {
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquip(spec_weapon.weapon_id);
if (item_meta &&
item_meta->i->equip_type() == EQUIP_TYPE_WEAPON) {
if (item_meta->i->equip_subtype() != 1) {
Weapon* weapon = &weapons[GUN_SLOT1];
weapon->weapon_idx = GUN_SLOT1;
if (curr_weapon != &weapons[GUN_SLOT2]) {
curr_weapon = &weapons[GUN_SLOT1];
int weapon_idx = GUN_SLOT1;
if (weapons[weapon_idx].weapon_id != 0) {
weapon_idx = GUN_SLOT2;
}
if (weapon) {
if (weapons[weapon_idx].weapon_id == 0) {
Weapon* weapon = &weapons[weapon_idx];
weapon->weapon_idx = weapon_idx;
weapon->weapon_id = spec_weapon.weapon_id;
weapon->weapon_lv = spec_weapon.weapon_lv;
weapon->ammo = spec_weapon.ammo;
weapon->meta = item_meta;
weapon->Recalc();
curr_weapon = &weapons[GUN_SLOT1];
}
}
}
@ -906,6 +909,36 @@ void Player::ProcPrepareItems2(const ::google::protobuf::RepeatedPtrField< cs::M
}
}
void Player::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg)
{
int old_socket_handle = socket_handle;
if (socket_handle != 0) {
GGListener::Instance()->ForceCloseChildSocket(socket_handle);
PlayerMgr::Instance()->RemovePlayerBySocket(socket_handle);
}
socket_handle = hdr.socket_handle;
TouchAllLayerHumanList
(
[this] (Human* hum, bool& stop)
{
AddToNewObjects(hum);
}
);
need_sync_active_player = true;
cs::SMReconnect respmsg;
respmsg.set_errcode(0);
respmsg.set_errmsg("战斗重连成功");
SendNotifyMsg(respmsg);
PlayerMgr::Instance()->ReBindSocket(this);
a8::UdpLog::Instance()->Debug
("战斗服重连成功 %s %d %d",
{
account_id,
hdr.socket_handle,
old_socket_handle
});
}
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
{
moving = false;
@ -1314,6 +1347,7 @@ void Player::PushJoinRoomMsg()
cs::SMJoinedNotify notifymsg;
notifymsg.set_error_code(0);
notifymsg.set_room_mode((int)room->GetRoomMode());
notifymsg.set_server_info(JsonDataMgr::Instance()->server_info);
room->FillSMJoinedNotify(this, notifymsg);
GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg);
}

View File

@ -4,6 +4,7 @@
namespace cs
{
class CMReconnect;
class CMMove;
class CMDropItem;
class CMEmote;
@ -88,6 +89,7 @@ class Player : public Human
void ProcPreSettlementInfo(const std::string& pre_settlement_info);
void PushJoinRoomMsg();
void _CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg);
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg);

View File

@ -82,11 +82,12 @@ Player* PlayerMgr::CreatePlayerByCMJoin(Player* hum,
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(weapon.weapon_id());
if (equip_meta) {
hum->weapon_configs[weapon.weapon_id()] = weapon.weapon_lv();
hum->spec_weapon.weapon_id = weapon.weapon_id();
hum->spec_weapon.weapon_lv = weapon.weapon_lv();
hum->spec_weapon.ammo = weapon.ammo();
hum->spec_weapon.meta = equip_meta;
hum->spec_weapon.Recalc();
Weapon& spec_weapon = a8::FastAppend(hum->spec_weapons);
spec_weapon.weapon_id = weapon.weapon_id();
spec_weapon.weapon_lv = weapon.weapon_lv();
spec_weapon.ammo = weapon.ammo();
spec_weapon.meta = equip_meta;
spec_weapon.Recalc();
}
}
}
@ -194,3 +195,8 @@ void PlayerMgr::DecAccountNum(const std::string& account_id)
);
}
}
void PlayerMgr::ReBindSocket(Player* hum)
{
socket_hash_[hum->socket_handle] = hum;
}

View File

@ -36,6 +36,7 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
size_t GetAccountNum() { return account_num_hash_.size(); }
void IncAccountNum(const std::string& account_id);
void DecAccountNum(const std::string& account_id);
void ReBindSocket(Player* hum);
private:
std::map<int, Player*> socket_hash_;

View File

@ -52,6 +52,8 @@ void Room::InitData(RoomInitInfo& init_info)
room_type_ = init_info.room_type;
creator_game_times_ = init_info.creator_game_times;
creator_register_time_ = init_info.creator_register_time;
creator_proto_version_ = init_info.creator_proto_version;
creator_channel_ = init_info.creator_channel;
force_entry_newbie_room_ = init_info.force_entry_newbie_room;
map_tpl_name_ = init_info.map_tpl_name;
@ -736,8 +738,20 @@ int Room::GetAliveTeamNum()
bool Room::CanJoin(const std::string& accountid,
RoomType_e self_room_type,
RoomMode_e self_room_mode)
RoomMode_e self_room_mode,
int self_proto_version,
int self_channel)
{
#if 1
if (creator_channel_ == kWxChannelId) {
if (self_channel != creator_channel_) {
return false;
}
if (self_proto_version != creator_proto_version_) {
return false;
}
}
#endif
if (self_room_mode < kChiJiMode) {
self_room_mode = kChiJiMode;
}
@ -768,15 +782,21 @@ bool Room::CanJoin(const std::string& accountid,
void Room::OnPlayerOffline(Player* hum)
{
bool has_player = false;
for (auto& pair : accountid_hash_) {
if (pair.second->socket_handle != 0) {
has_player = true;
}
}
if (!has_player) {
GameLog::Instance()->ForceOver(this);
RoomMgr::Instance()->AddOverRoom(room_uuid_);
if (GetOnlinePlayerNum() <= 0) {
xtimer.AddDeadLineTimerAndAttach
(
SERVER_FRAME_RATE * 15,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
if (room->GetOnlinePlayerNum() <= 0 && !room->added_to_over_room) {
GameLog::Instance()->ForceOver(room);
RoomMgr::Instance()->AddOverRoom(room->room_uuid_);
}
},
&xtimer_attacher_.timer_list_);
}
}
@ -3295,6 +3315,17 @@ int Room::GetAliveCountByRace(RaceType_e race)
return count;
}
int Room::GetOnlinePlayerNum()
{
int num = 0;
for (auto& pair : accountid_hash_) {
if (pair.second->socket_handle != 0) {
++num;
}
}
return num;
}
size_t Room::GetRoomMaxPlayerNum()
{
if (room_mode_ == kZombieMode) {

View File

@ -43,6 +43,7 @@ public:
GridService* grid_service = nullptr;
MapService* map_service = nullptr;
bool debug_trace = false;
bool added_to_over_room = false;
~Room();
void InitData(RoomInitInfo& init_info);
@ -110,7 +111,9 @@ public:
std::set<Human*>* GetAliveTeam();
bool CanJoin(const std::string& accountid,
RoomType_e self_roomm_type,
RoomMode_e self_room_mode);
RoomMode_e self_room_mode,
int self_proto_version,
int self_channel);
void OnPlayerOffline(Player* hum);
Entity* FindFirstCollisonEntity(const a8::Vec2& aabb_pos, AabbCollider& aabb_box);
void FindLocationWithAabb(Entity* target, const a8::Vec2& aabb_pos, AabbCollider* aabb_box,
@ -142,6 +145,7 @@ public:
void NotifySysPiao(const std::string& msg, int color, int duration);
void OnZombieAppear(Human* hum);
int GetAliveCountByRace(RaceType_e race);
int GetOnlinePlayerNum();
private:
int AllocUniid();
@ -264,6 +268,8 @@ private:
bool show_handed_ = false;
int creator_game_times_ = 0;
int creator_register_time_ = 0;
int creator_proto_version_ = 0;
int creator_channel_ = 0;
bool force_entry_newbie_room_ = false;
xtimer_list* battle_report_timer_ = nullptr;
bool sent_terminator_airdrop = false;

View File

@ -139,10 +139,14 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
int game_times = 0;
RoomType_e self_room_type = GetHumanRoomType(msg, game_times);
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
int proto_version = msg.proto_version();
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
Room* room = GetJoinableRoom(msg,
self_room_type,
game_times,
register_time
register_time,
proto_version,
channel
);
if (!room) {
JoinErrorHandle(msg, 3, hdr.socket_handle);
@ -164,6 +168,49 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
PlayerMgr::Instance()->IncAccountNum(msg.account_id());
}
void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg)
{
auto send_reconnect_failed =
[] (int socket_handle, int errcode, const std::string& errmsg)
{
cs::SMReconnect respmsg;
respmsg.set_errcode(errcode);
respmsg.set_errmsg(errmsg);
GGListener::Instance()->SendToClient(socket_handle, 0, respmsg);
a8::Timer::Instance()->AddDeadLineTimer
(
1000 * 3,
a8::XParams()
.SetSender(socket_handle),
[] (const a8::XParams& param)
{
GGListener::Instance()->ForceCloseChildSocket(param.sender);
}
);
};
Room* room = GetRoomByUuid(a8::XValue(msg.room_uuid()));
if (!room) {
send_reconnect_failed(hdr.socket_handle, 1, "房间已销毁");
a8::UdpLog::Instance()->Debug
("房间已销毁 %s",
{
msg.room_uuid()
});
return;
}
if (room->GetRoomMode() != kChiJiMode) {
send_reconnect_failed(hdr.socket_handle, 1, "只有吃鸡模式支持重连");
return;
}
Player* hum = room->GetPlayerByAccountId(msg.account_id());
if (!hum) {
send_reconnect_failed(hdr.socket_handle, 1, "accountid未在房间列表");
return;
}
hum->_CMReconnect(hdr, msg);
}
int RoomMgr::RoomNum()
{
return room_hash_.size();
@ -177,7 +224,9 @@ int RoomMgr::OverRoomNum()
Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time
int creator_register_time,
int proto_version,
int channel
)
{
std::vector<std::vector<Room*>> group_rooms;
@ -186,7 +235,11 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
}
for (auto& pair : inactive_room_hash_) {
Room* room = pair.second;
if (room->CanJoin(msg.account_id(), self_room_type, (RoomMode_e)msg.room_mode())) {
if (room->CanJoin(msg.account_id(),
self_room_type,
(RoomMode_e)msg.room_mode(),
proto_version,
channel)) {
if (!msg.team_uuid().empty() && room->HaveMyTeam(msg.team_uuid())) {
return room;
}
@ -201,13 +254,17 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
return CreateRoom(msg,
self_room_type,
game_times,
creator_register_time);
creator_register_time,
proto_version,
channel);
}
if (self_room_type == RT_MidBrid) {
return CreateRoom(msg,
self_room_type,
game_times,
creator_register_time);
creator_register_time,
proto_version,
channel);
}
for (int i = 0; i < RT_Max; ++i) {
for (Room* room : group_rooms[i]) {
@ -219,7 +276,9 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
return CreateRoom(msg,
self_room_type,
game_times,
creator_register_time);
creator_register_time,
proto_version,
channel);
}
Room* RoomMgr::GetRoomByUuid(long long room_uuid)
@ -250,6 +309,7 @@ void RoomMgr::AddOverRoom(long long room_uuid)
inactive_room_hash_.erase(room_uuid);
Room* room = GetRoomByUuid(room_uuid);
if (room) {
room->added_to_over_room = true;
a8::Timer::Instance()->AddRepeatTimerAndAttach
(1000 * 5,
a8::XParams()
@ -395,7 +455,9 @@ int RoomMgr::AllocRoomIdx()
Room* RoomMgr::CreateRoom(const cs::CMJoin& msg,
RoomType_e room_type,
int game_times,
int creator_register_time)
int creator_register_time,
int creator_proto_version,
int creator_channel)
{
int room_idx = AllocRoomIdx();
if (room_idx < 1) {
@ -409,6 +471,8 @@ Room* RoomMgr::CreateRoom(const cs::CMJoin& msg,
init_info.room_mode = (RoomMode_e)msg.room_mode();
init_info.creator_game_times = game_times;
init_info.creator_register_time = creator_register_time;
init_info.creator_proto_version = creator_proto_version;
init_info.creator_channel = creator_channel;
init_info.force_entry_newbie_room = msg.force_entry_newbie_room();
if (GetRoomByUuid(init_info.room_uuid)) {
abort();

View File

@ -5,6 +5,7 @@
namespace cs
{
class CMJoin;
class CMReconnect;
}
class Room;
@ -23,6 +24,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
void Update(int delta_time);
void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg);
void _CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg);
void ActiveRoom(long long room_uuid);
int RoomNum();
int OverRoomNum();
@ -36,7 +38,9 @@ class RoomMgr : public a8::Singleton<RoomMgr>
Room* GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time);
int creator_register_time,
int proto_version,
int channel);
void ReportServerState(int instance_id, const std::string& host, int port);
void FreeOverRoom(long long room_uuid);
bool IsLimitJoin();
@ -45,7 +49,9 @@ class RoomMgr : public a8::Singleton<RoomMgr>
Room* CreateRoom(const cs::CMJoin& msg,
RoomType_e room_type,
int game_times,
int creator_register_time);
int creator_register_time,
int creator_proto_version,
int creator_channel);
void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle);
private:

View File

@ -57,6 +57,12 @@ float Weapon::GetAttrValue(HumanAttrType_e attr_type)
(upgrade_meta ? upgrade_meta->GetAttrValue(weapon_lv, attr_type) : 0);
}
break;
case kHAT_ReloadTime:
{
return meta->i->reload_time() -
(upgrade_meta ? upgrade_meta->GetAttrValue(weapon_lv, attr_type) : 0);
}
break;
default:
return 0;
}

View File

@ -160,6 +160,8 @@ struct RoomInitInfo
RoomType_e room_type = RT_NewBrid;
int creator_game_times = 0;
int creator_register_time = 0;
int creator_proto_version = 0;
int creator_channel = 0;
bool force_entry_newbie_room = false;
const MetaData::Map* map_meta = nullptr;

View File

@ -50,7 +50,7 @@ package cs;
//
enum Constant_e
{
ProtoVersion = 2019071501; //
ProtoVersion = 2020081401; //
}
//
@ -743,7 +743,9 @@ message CMReconnect
optional int32 server_id = 1; //
optional string team_uuid = 2; //
optional string account_id = 3; //id
optional string room_uuid = 4; //id
optional string session_id = 4; //session_id
optional string room_uuid = 5; //id
optional string server_info = 6; //
}
//线
@ -877,6 +879,8 @@ message SMJoinedNotify
optional int32 error_code = 7; // 1: 2
optional int32 room_mode = 8; //0: 1:
optional string server_info = 9; //使
}
//

View File

@ -104,6 +104,7 @@ message EquipUpgrade
{
optional int32 id = 1;
optional string attr_type = 4;
optional string spera_type = 5;
}
message Player