diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index b0f30bd..40530bf 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -466,7 +466,6 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id) dead = true; health = 0.0f; dead_frameno = room->frame_no; - send_gameover = true; room->OnHumanDie(this); SyncAroundPlayers(); if (team_members) { @@ -477,6 +476,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id) } } } + SendGameOver(); } } @@ -1266,72 +1266,13 @@ void Human::SendUpdateMsg() ++send_msg_times; } ClearFrameData(); - if (send_gameover) { - UpdateGameOver(); - } } -void Human::UpdateGameOver() +void Human::SendGameOver() { - a8::MutableXObject* params = a8::MutableXObject::NewObject(); - GenBattleReportData(params); - auto on_ok = [] (a8::XParams& param, a8::XObject& data) - { - long long room_uuid = param.sender; - int hum_uniid = param.param1; - Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); - if (room) { - Entity* entity = room->GetEntityByUniId(hum_uniid); - if (entity && entity->entity_type == ET_Player) { - Human* hum = (Human*)entity; - hum->stats.history_time_alive = data.Get("alive_time_his"); - hum->stats.history_kills = data.Get("kill_his"); - hum->stats.history_damage_amount = data.Get("harm_his"); - hum->stats.history_heal_amount = data.Get("add_HP_his"); - cs::SMGameOver msg; - hum->FillSMGameOver(msg); - hum->SendNotifyMsg(msg); - } - } - }; - auto on_error = [] (a8::XParams& param, const std::string& response) - { - long long room_uuid = param.sender; - int hum_uniid = param.param1; - Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); - if (room) { - Entity* entity = room->GetEntityByUniId(hum_uniid); - if (entity && entity->entity_type == ET_Player) { - Human* hum = (Human*)entity; - ++hum->send_gameover_trycount; - if (hum->send_gameover_trycount < 10){ - hum->send_gameover = true; - } - } - } - }; - std::string url; - if (!f8::IsOnlineEnv()) { - if (App::Instance()->flags.find(3) != App::Instance()->flags.end()) { - url = "http://192.168.100.41/webapp/index.php?c=Role&a=battleReport"; - } else { - url = "https://game2001api-test.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; - } - } else { - url = "https://game2001api.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; + if (!sending_gameover_) { + InternalSendGameOver(); } - f8::HttpClientPool::Instance()->HttpGet( - a8::XParams() - .SetSender(room->room_uuid) - .SetParam1(entity_uniid), - on_ok, - on_error, - url.c_str(), - *params, - rand() - ); - delete params; - send_gameover = false; } void Human::FollowTarget(Human* target) @@ -1486,3 +1427,75 @@ void Human::GenBattleReportData(a8::MutableXObject* params) } params->SetVal("score", 0); } + +void Human::InternalSendGameOver() +{ + if (already_report_battle_) { + cs::SMGameOver msg; + FillSMGameOver(msg); + SendNotifyMsg(msg); + return; + } + a8::MutableXObject* params = a8::MutableXObject::NewObject(); + GenBattleReportData(params); + auto on_ok = [] (a8::XParams& param, a8::XObject& data) + { + long long room_uuid = param.sender; + int hum_uniid = param.param1; + Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); + if (room) { + Entity* entity = room->GetEntityByUniId(hum_uniid); + if (entity && entity->entity_type == ET_Player) { + Human* hum = (Human*)entity; + hum->sending_gameover_ = false; + hum->already_report_battle_ = true; + hum->stats.history_time_alive = data.Get("alive_time_his"); + hum->stats.history_kills = data.Get("kill_his"); + hum->stats.history_damage_amount = data.Get("harm_his"); + hum->stats.history_heal_amount = data.Get("add_HP_his"); + cs::SMGameOver msg; + hum->FillSMGameOver(msg); + hum->SendNotifyMsg(msg); + } + } + }; + auto on_error = [] (a8::XParams& param, const std::string& response) + { + long long room_uuid = param.sender; + int hum_uniid = param.param1; + Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); + if (room) { + Entity* entity = room->GetEntityByUniId(hum_uniid); + if (entity && entity->entity_type == ET_Player) { + Human* hum = (Human*)entity; + hum->sending_gameover_ = false; + ++hum->send_gameover_trycount_; + if (hum->send_gameover_trycount_ < 10){ + hum->SendGameOver(); + } + } + } + }; + std::string url; + if (!f8::IsOnlineEnv()) { + if (App::Instance()->flags.find(3) != App::Instance()->flags.end()) { + url = "http://192.168.100.41/webapp/index.php?c=Role&a=battleReport"; + } else { + url = "https://game2001api-test.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; + } + } else { + url = "https://game2001api.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; + } + f8::HttpClientPool::Instance()->HttpGet( + a8::XParams() + .SetSender(room->room_uuid) + .SetParam1(entity_uniid), + on_ok, + on_error, + url.c_str(), + *params, + rand() + ); + delete params; + sending_gameover_ = true; +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 63faa09..cb33329 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -87,9 +87,6 @@ class Human : public Entity PlayerStats stats; - bool send_gameover = false; - int send_gameover_trycount = 0; - int pain_killer_frameno = 0; int pain_killer_lastingtime = 0; xtimer_list* pain_killer_timer = nullptr; @@ -167,13 +164,14 @@ class Human : public Entity { GGListener::Instance()->SendToClient(socket_handle, 0, msg); } - void UpdateGameOver(); + void SendGameOver(); void FollowTarget(Human* target); void SendDebugMsg(const std::string& debug_msg); private: void ClearFrameData(); void GenBattleReportData(a8::MutableXObject* params); + void InternalSendGameOver(); protected: long long last_shot_frameno_ = 0; @@ -205,6 +203,11 @@ protected: private: CircleCollider* self_collider_ = nullptr; long long last_sync_gas_frameno = 0; + + bool already_report_battle_ = false; + bool sending_gameover_ = false; + int send_gameover_trycount_ = 0; + friend class FrameMaker; friend class FrameEvent; }; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 032ae4e..b0fc84d 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -825,8 +825,8 @@ void Room::UpdateGas() if (pair.second->dead) { continue; } - if (game_over) { - pair.second->send_gameover = true; + if (game_over && game_over_frameno == frame_no) { + pair.second->SendGameOver(); } bool b1 = CircleContainCircle(gas_data.pos_old, gas_data.gas_progress,