This commit is contained in:
aozhiwei 2024-03-26 14:58:47 +08:00
commit 6656555c96
5 changed files with 3 additions and 548 deletions

View File

@ -86,6 +86,7 @@ void CustomBattle::ParseResult(a8::XObject& obj)
member->session_id_ = member_obj->Get("session_id").GetString();
member->name_ = member_obj->Get("name").GetString();
member->sex_ = member_obj->Get("sex");
member->avatar_url_ = member_obj->Get("head_id").GetString();
member->battle_context_ = std::make_shared<BattleDataContext>();
member->battle_context_->ParseResult(*member_obj);
if (!member->battle_context_->parse_ok) {

View File

@ -2462,7 +2462,7 @@ long long Room::GetGasInactiveTime()
}
#endif
if (IsMobaModeRoom()) {
inactive_time = 16;
inactive_time = 7;
}
inactive_time = std::max((long long)0, inactive_time - acc_inactive_time_);
if (IsNewerMap()) {

View File

@ -29,9 +29,6 @@
#include "mt/Hero.h"
#include "mt/Equip.h"
#include "mt/Map.h"
#include "mt/PveGemini.h"
#include "mt/PveGeminiMode.h"
#include "mt/PveGeminiContent.h"
#include <f8/httpclientpool.h>
#include <f8/utils.h>
@ -41,42 +38,6 @@
static const int ROOM_NUM_UP_LIMIT = 1000;
static const int HUM_NUM_DOWN_LIMIT = 2500;
static RoomType_e GetHumanRoomType(const std::shared_ptr<BattleDataContext> netdata)
{
long long hero_uniid = 0;
int hero_lv = 0;
int quality = 0;
netdata->GetHeroLvQuality(hero_uniid, hero_lv, quality);
if (netdata->join_msg->room_mode() == kPvpRankMode) {
#if 1
auto rank_mode_conf = mt::Param::GetRankModeConfByHeroLv(hero_lv);
if (!rank_mode_conf) {
abort();
}
#else
auto rank_mode_conf = mt::Param::GetRankModeConfByElo(netdata->GetElo());
if (!rank_mode_conf) {
abort();
}
#endif
return rank_mode_conf->room_type;
} else {
if (hero_lv < mt::Param::s().new_room_max_level) {
return RoomType_OldBrid1;
}
#if 1
if (hero_lv < mt::Param::s().mid_room_max_level) {
return RoomType_OldBrid2;
}
#else
if (netdata->GetRank() < mt::Param::s().mid_room_max_rank) {
return RoomType_OldBrid2;
}
#endif
return RoomType_OldBrid3;
}
}
void RoomMgr::Init()
{
InstallReportStateTimer();
@ -129,85 +90,6 @@ void RoomMgr::_CMJoin(f8::MsgHdr* hdr, const cs::CMJoin& msg)
DispatchSpecRoom(hdr, msg);
return;
}
const mt::Map* map_meta = mt::Map::GetById(msg.mapid());
if (!map_meta || !map_meta->IsOpen()) {
JoinErrorHandle(msg, 3, hdr->socket_handle);
return;
}
std::shared_ptr<cs::CMJoin> join_msg = std::make_shared<cs::CMJoin>();
*join_msg = msg;
std::vector<std::shared_ptr<cs::CMJoin>> join_msgs{join_msg};
auto ip_saddr = hdr->ip_saddr;
auto socket_handle = hdr->socket_handle;
auto cb =
[ip_saddr, socket_handle, join_msg]
(std::vector<std::shared_ptr<BattleDataContext>>& results)
{
cs::CMJoin& msg = *join_msg;
if (RoomMgr::Instance()->IsLimitJoin()) {
RoomMgr::Instance()->JoinErrorHandle(msg, 2, socket_handle);
return;
}
if (!results.at(0)->parse_ok) {
return;
}
int game_times = 0;
RoomType_e self_room_type = GetHumanRoomType(results.at(0));
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
int proto_version = msg.proto_version();
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
std::shared_ptr<Room> room = RoomMgr::Instance()->GetJoinableRoom
(
msg,
self_room_type,
game_times,
register_time,
proto_version,
channel
);
if (!room) {
#ifdef MYDEBUG
a8::XPrintf("GetJoinableRoom error %s\n", {msg.account_id()});
#endif
RoomMgr::Instance()->JoinErrorHandle(msg, 3, socket_handle);
return;
}
Player* hum = room->NewPlayer();
hum->proto_version = msg.proto_version();
#if 0
hum->hero_uniid = a8::XValue(msg.hero_uniid());
#endif
hum->battle_uuid = results.at(0)->battle_uuid;
hum->is_valid_battle = results.at(0)->is_valid_battle;
hum->payload = results.at(0)->payload;
PlayerMgr::Instance()->
CreatePlayerByCMJoin(hum,
ip_saddr,
socket_handle,
msg
);
hum->meta = mt::Hero::GetById(msg.hero_id());
if (!hum->meta) {
hum->meta = mt::Param::s().human_meta;
}
hum->room = room.get();
hum->SetNetData(results.at(0));
hum->GetNetData()->Init(hum);
{
long long hero_uniid = 0;
int hero_lv = 1;
int quality = 1;
hum->GetNetData()->GetHeroLvQuality(hero_uniid, hero_lv, quality);
hum->hero_uniid = hero_uniid;
}
room->AddPlayer(hum);
hum->ProcSkillList();
hum->SetHP(hum->GetNetData()->GetMaxHP());
hum->SetMaxHP(hum->GetHP());
PlayerMgr::Instance()->IncAccountNum(msg.account_id());
RoomMgr::Instance()->OnJoinRoomOk(msg, hum);
};
SendGetBattleData(0, join_msgs, cb);
}
void RoomMgr::_CMReconnect(f8::MsgHdr* hdr, const cs::CMReconnect& msg)
@ -274,66 +156,6 @@ int RoomMgr::OverRoomNum()
return over_room_hash_.size();
}
std::shared_ptr<Room> RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel
)
{
std::vector<std::vector<std::shared_ptr<Room>>> group_rooms;
for (int i = 0; i < RoomType_Max; ++i) {
group_rooms.push_back(std::vector<std::shared_ptr<Room>>());
}
for (auto& pair : inactive_room_hash_) {
auto& room = pair.second;
if (!room->GetCustomBattle() &&
room->CanJoin(msg.account_id(),
self_room_type,
(RoomMode_e)msg.room_mode(),
proto_version,
channel,
msg.mapid(),
msg)) {
if (!msg.team_uuid().empty() && room->HaveMyTeam(msg.team_uuid())) {
return room;
}
group_rooms[room->GetRoomType()].push_back(room);
}
}
if (!group_rooms[self_room_type].empty()) {
return group_rooms[self_room_type][rand() % group_rooms[self_room_type].size()];
}
if (msg.room_mode() == kPvpRankMode) {
} else {
if (self_room_type == RoomType_OldBrid2) {
for (auto& room : group_rooms[RoomType_OldBrid3]) {
if (room->GetGasInactiveReaminTime() > 8 &&
room->GetPlayerNum() + 8 < room->GetRoomMaxPlayerNum()) {
return room;
}
}
} else if (self_room_type == RoomType_OldBrid3) {
for (auto& room : group_rooms[RoomType_OldBrid2]) {
if (room->GetGasInactiveReaminTime() > 8 &&
room->GetPlayerNum() + 8 < room->GetRoomMaxPlayerNum()) {
return room;
}
}
}
}
return CreateRoom(self_room_type,
game_times,
creator_register_time,
proto_version,
channel,
msg.mapid(),
(RoomMode_e)msg.room_mode(),
nullptr);
}
std::shared_ptr<Room> RoomMgr::GetJoinableRoom(std::shared_ptr<CustomBattle> p)
{
if (p->IsMoba()) {
@ -634,196 +456,8 @@ bool RoomMgr::IsGM(const std::string& account_id)
return gm_hash_.find(account_id) != gm_hash_.end();
}
std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map<std::string, std::string>* team_hash)
{
std::string data;
data += a8::Format("team_uuid:%s ", {team_uuid});
for (auto pair : *team_hash) {
data += a8::Format("%s->%d ", {pair.first, pair.second});
}
return data;
}
void RoomMgr::OnJoinRoomOk(const cs::CMJoin& msg, Player* hum)
{
if (msg.team_uuid().empty()) {
return;
}
std::map<std::string, std::string>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(msg.team_uuid());
if (itr == team_room_hash_.end()) {
team_room_hash_[msg.team_uuid()] = std::map<std::string, std::string>();
itr = team_room_hash_.find(msg.team_uuid());
team_hash = &itr->second;
for (auto& team_member : msg.team_members()) {
team_hash->insert(std::make_pair(team_member.account_id(), ""));
}
std::string team_uuid = msg.team_uuid();
f8::Timer::Instance()->SetTimeout
(1000 * 60,
[team_uuid] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
RoomMgr::Instance()->TeamRoomTimeOut(team_uuid);
}
}
);
} else {
team_hash = &itr->second;
}
}
if (!team_hash) {
A8_ABORT();
}
hum->init_team_member_num = team_hash->size();
{
auto itr = team_hash->find(hum->account_id);
if (itr != team_hash->end()) {
itr->second = hum->room->GetRoomUuid();
} else {
f8::UdpLog::Instance()->Warning
("team_data:%s account_id:%s not exists",
{
GenTeamHashData(msg.team_uuid(), team_hash),
hum->account_id
});
}
}
}
void RoomMgr::TeamRoomTimeOut(const std::string& team_uuid)
{
std::map<std::string, std::string>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(team_uuid);
if (itr != team_room_hash_.end()) {
team_hash = &itr->second;
}
}
if (team_hash) {
bool ok = true;
for (auto pair : *team_hash) {
if (pair.second.empty()) {
ok = false;
break;
}
}
if (!ok) {
f8::UdpLog::Instance()->Warning
("team match failed team_data:%s ",
{
GenTeamHashData(team_uuid, team_hash),
});
}
team_room_hash_.erase(team_uuid);
} else {
f8::UdpLog::Instance()->Warning
("team not found team_uuid:s",
{
team_uuid
});
}
}
void RoomMgr::SendGetBattleData(int mode,
std::vector<std::shared_ptr<cs::CMJoin>>& join_msgs,
std::function<
void(std::vector<std::shared_ptr<BattleDataContext>>&)> cb)
{
if (join_msgs.empty()) {
abort();
}
std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>> result =
std::make_shared<std::vector<std::shared_ptr<BattleDataContext>>>();
bool is_old_version = false;
for (auto& msg : join_msgs) {
std::shared_ptr<BattleDataContext> context = std::make_shared<BattleDataContext>();
context->join_msg = msg;
context->battle_uuid = f8::App::Instance()->NewGlobalUuid();
context->errcode = 100;
context->errmsg = "";
result->push_back(context);
if (msg->proto_version() < 2022032201) {
is_old_version = true;
}
}
{
std::string url;
JsonDataMgr::Instance()->GetApiUrl(url);
if (url.find('?') != std::string::npos) {
url += "&c=Battle&a=getBattleData";
} else {
url += "?&c=Battle&a=getBattleData";
}
auto url_params = a8::MutableXObject::CreateObject();
{
auto members = a8::MutableXObject::CreateArray();
int i = 0;
for (auto msg : join_msgs) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", msg->account_id());
member->SetVal("session_id", msg->session_id());
member->SetVal("hero_uniid", msg->hero_uniid());
member->SetVal("battle_uuid", result->at(i)->battle_uuid);
member->SetVal("weapon_uuid1",
msg->weapons().size() > 0 ? msg->weapons(0).weapon_uniid() : "");
member->SetVal("weapon_uuid2",
msg->weapons().size() > 1 ? msg->weapons(1).weapon_uniid() : "");
#if 0
member->SetVal("cmjoin", f8::PbToJson(msg.get()));
#endif
++i;
members->Push(*member.get());
}
url_params->SetVal("account_id", join_msgs[0]->account_id());
url_params->SetVal("session_id", join_msgs[0]->session_id());
url_params->SetVal("team_uuid", join_msgs[0]->team_uuid());
url_params->SetVal("mode", mode);
url_params->SetVal("members", members->ToJsonStr());
}
HttpProxy::Instance()->HttpGet
(
[result, cb]
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{
if (ok) {
f8::UdpLog::Instance()->Info
("GetBattleData ok %s",
{
rsp_obj->ToJsonStr()
});
if (rsp_obj->GetType() == a8::XOT_OBJECT) {
int match_mode = rsp_obj->Get("match_mode");
RoomMgr::Instance()->SetMatchMode(match_mode ? 1 : 0);
if (rsp_obj->HasKey("members")) {
auto members = rsp_obj->At("members");
if (members->GetType() == a8::XOT_ARRAY && members->Size() == result->size()) {
for (int i = 0; i < members->Size(); ++i) {
auto& ctx = result->at(i);
auto member = members->At(i);
if (member->GetType() == a8::XOT_OBJECT) {
ctx->ParseResult(*member);
}
}
}
}
}
cb(*result);
} else {
f8::UdpLog::Instance()->Warning
("GetBattleData error %s",
{
""
});
cb(*result);
}
},
url.c_str(),
*url_params
);
}
}
void RoomMgr::SetMatchMode(int mode)
@ -834,172 +468,6 @@ void RoomMgr::SetMatchMode(int mode)
void RoomMgr::AdjustCMJoin(cs::CMJoin* msg)
{
msg->set_pve_instance_id(0);
#if 1
const mt::Map* map_meta = mt::Map::GetById(msg->mapid());
if (map_meta && map_meta->is_moba()) {
msg->set_room_mode(kMobaMode);
#if 0
{
auto data = a8::MutableXObject::CreateObject();
data->SetVal("zone_id", 1);
data->SetVal("node_id", 1);
data->SetVal("room_uuid", f8::App::Instance()->NewGlobalUuid());
data->SetVal("start_time", f8::App::Instance()->GetNowTime());
auto team_list = a8::MutableXObject::CreateArray();
{
std::map<std::string, std::string> test_members;
test_members[msg->account_id()] = msg->session_id();
auto team = a8::MutableXObject::CreateObject();
auto members = a8::MutableXObject::CreateArray();
team->SetVal("team_uuid", f8::App::Instance()->NewGlobalUuid());
for (auto& pair : test_members) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", pair.first);
//member->SetVal("session_id", pair.second);
members->Push(*member.get());
}
team->SetVal("members", *members.get());
team_list->Push(*team.get());
}
{
std::string test_account_id = "6513_2006_2";
std::map<std::string, std::string> test_members;
test_members[test_account_id] = test_account_id;
auto team = a8::MutableXObject::CreateObject();
auto members = a8::MutableXObject::CreateArray();
team->SetVal("team_uuid", f8::App::Instance()->NewGlobalUuid());
for (auto& pair : test_members) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", pair.first);
//member->SetVal("session_id", pair.second);
members->Push(*member.get());
}
team->SetVal("members", *members.get());
team_list->Push(*team.get());
}
#if 0
{
std::string test_account_id = "6513_2006_3";
std::map<std::string, std::string> test_members;
test_members[test_account_id] = test_account_id;
auto team = a8::MutableXObject::CreateObject();
auto members = a8::MutableXObject::CreateArray();
team->SetVal("team_uuid", f8::App::Instance()->NewGlobalUuid());
for (auto& pair : test_members) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", pair.first);
//member->SetVal("session_id", pair.second);
members->Push(*member.get());
}
team->SetVal("members", *members.get());
team_list->Push(*team.get());
}
#endif
data->SetVal("team_list", *team_list.get());
{
std::string custom_data = a8::openssl::md5
(data->ToJsonStr() + "520d8eAbB(8cf1^#$^&!@d833a42c820432PDAFE^^)") + ":moba_room|" +
data->ToJsonStr();
msg->set_payload_data(custom_data);
}
}
#endif
return;
}
#endif
#ifdef MYDEBUG1
{
auto data = a8::MutableXObject::CreateObject();
data->SetVal("zone_id", 1);
data->SetVal("node_id", 1);
data->SetVal("room_uuid", f8::App::Instance()->NewGlobalUuid());
data->SetVal("start_time", f8::App::Instance()->GetNowTime());
auto team_list = a8::MutableXObject::CreateArray();
{
std::map<std::string, std::string> test_members;
test_members[msg->account_id()] = msg->session_id();
auto team = a8::MutableXObject::CreateObject();
auto members = a8::MutableXObject::CreateArray();
team->SetVal("team_uuid", f8::App::Instance()->NewGlobalUuid());
for (auto& pair : test_members) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", pair.first);
//member->SetVal("session_id", pair.second);
members->Push(*member.get());
}
team->SetVal("members", *members.get());
team_list->Push(*team.get());
}
{
std::string test_account_id = "6513_2006_2";
std::map<std::string, std::string> test_members;
test_members[test_account_id] = test_account_id;
auto team = a8::MutableXObject::CreateObject();
auto members = a8::MutableXObject::CreateArray();
team->SetVal("team_uuid", f8::App::Instance()->NewGlobalUuid());
for (auto& pair : test_members) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", pair.first);
//member->SetVal("session_id", pair.second);
members->Push(*member.get());
}
team->SetVal("members", *members.get());
team_list->Push(*team.get());
}
{
std::string test_account_id = "6513_2006_3";
std::map<std::string, std::string> test_members;
test_members[test_account_id] = test_account_id;
auto team = a8::MutableXObject::CreateObject();
auto members = a8::MutableXObject::CreateArray();
team->SetVal("team_uuid", f8::App::Instance()->NewGlobalUuid());
for (auto& pair : test_members) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", pair.first);
//member->SetVal("session_id", pair.second);
members->Push(*member.get());
}
team->SetVal("members", *members.get());
team_list->Push(*team.get());
}
data->SetVal("team_list", *team_list.get());
{
std::string custom_data = a8::openssl::md5
(data->ToJsonStr() + "520d8eAbB(8cf1^#$^&!@d833a42c820432PDAFE^^)") + "|" +
data->ToJsonStr();
msg->set_custom_room_payload(custom_data);
}
}
#endif
#ifdef MYDEBUG
a8::XPrintf("custom_room_payload %s\n",
{
msg->payload_data()
});
#endif
#if 0
if (msg->proto_version() < cs::ProtoVersion) {
msg->set_mapid(2001);
}
#endif
#ifdef MYDEBUG1
if (DebugCmd::Enable()) {
msg->set_room_mode(kPvpRankMode);
}
#endif
if (msg->room_mode() < kPvpMode ||
msg->room_mode() >= kRoomModeEnd) {
#ifdef MYDEBUG
a8::XPrintf("AdjustCMJoin room_mode:%d pve_instance_id:%d\n",
{
msg->room_mode(),
msg->pve_instance_id()
});
#endif
msg->set_room_mode(kPvpMode);
msg->set_pve_instance_id(0);
return;
}
}
std::shared_ptr<CustomBattle> RoomMgr::GetCustomRoom(const std::string& room_uuid)

View File

@ -7,6 +7,7 @@
#include <f8/timer.h>
#include "netdata.h"
namespace cs
{
class CMJoin;
@ -23,7 +24,6 @@ namespace MetaData
class GridService;
class MapService;
class MapInstance;
class Building;
class CustomBattle;
struct RoomInitInfo
{
@ -78,10 +78,6 @@ class RoomMgr : public a8::Singleton<RoomMgr>
std::shared_ptr<Room> GetRoomByUuid(const std::string& uuid);
void AddOverRoom(const std::string& room_uuid);
bool IsGM(const std::string& account_id);
void SendGetBattleData(int mode,
std::vector<std::shared_ptr<cs::CMJoin>>& join_msgs,
std::function<
void(std::vector<std::shared_ptr<BattleDataContext>>&)> cb);
int GetMatchMode() { return match_mode_; };
void SetMatchMode(int mode);
bool HasTask();
@ -90,12 +86,6 @@ class RoomMgr : public a8::Singleton<RoomMgr>
private:
void InstallReportStateTimer();
std::shared_ptr<Room> GetRoomByIdx(int room_idx);
std::shared_ptr<Room> GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel);
std::shared_ptr<Room> GetJoinableRoom(std::shared_ptr<CustomBattle> p);
void ReportServerState(int instance_id, const std::string& host, int port);
void FreeOverRoom(const std::string& room_uuid);
@ -111,8 +101,6 @@ class RoomMgr : public a8::Singleton<RoomMgr>
RoomMode_e room_mode,
std::shared_ptr<CustomBattle> custom_battle);
void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle);
std::string GenTeamHashData(const std::string& team_uuid, std::map<std::string, std::string>* team_hash);
void TeamRoomTimeOut(const std::string& team_uuid);
void AdjustCMJoin(cs::CMJoin* msg);
std::shared_ptr<CustomBattle> GetCustomRoom(const std::string& room_uuid);
std::shared_ptr<CustomBattle> GetHisCustomRoom(const std::string& room_uuid);
@ -132,7 +120,6 @@ class RoomMgr : public a8::Singleton<RoomMgr>
std::map<std::string, std::shared_ptr<Room>> over_room_hash_;
f8::Attacher reportstate_timer_attacher_;
std::map<std::string, int> gm_hash_;
std::map<std::string, std::map<std::string, std::string>> team_room_hash_;
std::map<std::string, std::shared_ptr<CustomBattle>> custom_room_hash_;
std::map<std::string, std::shared_ptr<CustomBattle>> his_custom_room_hash_;
};

View File

@ -46,7 +46,6 @@ class Team : public std::enable_shared_from_this<Team>
bool CanCombine(Human* member);
void AddCombineMemberNum(int member_num);
Human* GetMemberByUniId(int member_id);
int GetInitTeamMemberNum() { return init_team_member_num_; };
bool HasReviveCoin(Human* member);
bool IsFreeTeam();
bool HasPlayer();