1
This commit is contained in:
parent
7be35d366c
commit
515f1a9b6f
@ -129,85 +129,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 +195,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()) {
|
||||
@ -726,106 +587,6 @@ void RoomMgr::TeamRoomTimeOut(const std::string& 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)
|
||||
{
|
||||
match_mode_ = mode;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <f8/timer.h>
|
||||
|
||||
#include "netdata.h"
|
||||
|
||||
namespace cs
|
||||
{
|
||||
class CMJoin;
|
||||
@ -78,10 +79,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 +87,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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user