diff --git a/server/gameserver/GGListener.cc b/server/gameserver/GGListener.cc index 49d8920..baa4ba9 100644 --- a/server/gameserver/GGListener.cc +++ b/server/gameserver/GGListener.cc @@ -31,7 +31,7 @@ public: } App::Instance()->AddSocketMsg(SF_GameGate, (socket_handle << 16) + p->socket_handle, - saddr, + p->ip_saddr, p->msgid, p->seqid, &buf[offset + sizeof(f8::WSProxyPackHead_C)], diff --git a/server/gameserver/gamelog.cc b/server/gameserver/gamelog.cc new file mode 100644 index 0000000..455af46 --- /dev/null +++ b/server/gameserver/gamelog.cc @@ -0,0 +1,74 @@ +#include "precompile.h" +#include "gamelog.h" +#include "framework/cpp/utils.h" +#include "framework/cpp/tglog.h" +#include +#include "player.h" +#include "app.h" +#include "room.h" +#include "metadata.h" + +void GameLog::GameStart(Player* hum) +{ + int logclass1 = 11; + int logclass2 = 4; + int game_id = f8::ExtractGameIdFromAccountId(hum->account_id); + std::string channel = a8::XValue(f8::ExtractChannelIdFromAccountId(hum->account_id)); + + a8::MutableXObject* prop = a8::MutableXObject::NewObject(); + prop->SetVal("channel", channel); + prop->SetVal("from_appid", hum->from_appid); + prop->SetVal("account_id", hum->account_id); + prop->SetVal("account_register_utctime", hum->account_registertime); + prop->SetVal("account_register_date", a8::TimestampToDateTime(hum->account_registertime)); + prop->SetVal("game_uniid", a8::XValue(hum->room->room_uuid).GetString()); + //prop->SetVal("game_param", ""); + prop->SetVal("nickname", hum->name); + //prop->SetVal("localuuid", ""); + //prop->SetVal("start_param", ""); + + prop->SetVal("map_id", hum->room->map_meta->i->map_id()); + prop->SetVal("map_name", hum->room->map_meta->i->map_name()); + prop->SetVal("map_tpl_name", hum->room->map_tpl_name); + + f8::TGLog::Instance()->AddTrackLog(game_id, hum->account_id, hum->ip_saddr, logclass1, logclass2, prop); + + delete prop; + prop = nullptr; +} + +void GameLog::GameEnd(Player* hum) +{ + int logclass1 = 11; + int logclass2 = 6; + int game_id = f8::ExtractGameIdFromAccountId(hum->account_id); + std::string channel = a8::XValue(f8::ExtractChannelIdFromAccountId(hum->account_id)); + + a8::MutableXObject* prop = a8::MutableXObject::NewObject(); + prop->SetVal("channel", channel); + prop->SetVal("from_appid", hum->from_appid); + prop->SetVal("account_id", hum->account_id); + prop->SetVal("account_register_utctime", hum->account_registertime); + prop->SetVal("account_register_date", a8::TimestampToDateTime(hum->account_registertime)); + prop->SetVal("game_uniid", a8::XValue(hum->room->room_uuid).GetString()); + //prop->SetVal("game_param", ""); + prop->SetVal("game_score", hum->stats.score); + prop->SetVal("nickname", hum->name); + //prop->SetVal("localuuid", ""); + prop->SetVal("game_time", a8::XGetTickCount() - hum->create_tick); + //prop->SetVal("start_param", ""); + + prop->SetVal("map_id", hum->room->map_meta->i->map_id()); + prop->SetVal("map_name", hum->room->map_meta->i->map_name()); + prop->SetVal("map_tpl_name", hum->room->map_tpl_name); + if (!hum->dead) { + prop->SetVal("alive_time", hum->room->frame_no * 1000.0f / SERVER_FRAME_RATE); + } else { + prop->SetVal("alive_time", hum->dead_frameno * 1000.0f / SERVER_FRAME_RATE); + } + + f8::TGLog::Instance()->AddTrackLog(game_id, hum->account_id, hum->ip_saddr, logclass1, logclass2, prop); + + delete prop; + prop = nullptr; +} diff --git a/server/gameserver/gamelog.h b/server/gameserver/gamelog.h new file mode 100644 index 0000000..d86a30d --- /dev/null +++ b/server/gameserver/gamelog.h @@ -0,0 +1,15 @@ +#pragma once + +class Player; +class GameLog : public a8::Singleton +{ + private: + GameLog(){}; + friend class a8::Singleton; + public: + void GameStart(Player* hum); + void GameEnd(Player* hum); + + private: + +}; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index c0223fb..32643c8 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -15,6 +15,7 @@ #include "app.h" #include "roommgr.h" #include "android.h" +#include "gamelog.h" #include "framework/cpp/utils.h" #include "framework/cpp/httpclientpool.h" @@ -1884,6 +1885,10 @@ void Human::InternalSendGameOver() cs::SMGameOver msg; hum->FillSMGameOver(msg); hum->SendNotifyMsg(msg); + if (!hum->sent_game_end_ && hum->entity_subtype == EST_Player) { + GameLog::Instance()->GameEnd((Player*)hum); + hum->sent_game_end_ = true; + } } } }; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index dc55c47..f646bb8 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -34,9 +34,12 @@ class Human : public Entity { public: int socket_handle = 0; + long ip_saddr = 0; int team_id = 0; std::string account_id; + std::string from_appid; std::string team_uuid; + int account_registertime = 0; MetaData::Player* meta = nullptr; MetaData::Equip* helmet_meta = nullptr; MetaData::Equip* chest_meta = nullptr; @@ -226,6 +229,7 @@ private: bool already_report_battle_ = false; bool sending_gameover_ = false; + bool sent_game_end_ = false; int send_gameover_trycount_ = 0; friend class FrameMaker; diff --git a/server/gameserver/player.h b/server/gameserver/player.h index cfdbd22..9a1ac2f 100644 --- a/server/gameserver/player.h +++ b/server/gameserver/player.h @@ -25,6 +25,7 @@ class Player : public Human int player_count = 0; bool auto_fill = false; bool use_touch = false; + long long create_tick = 0; int last_seq_id = 0; bool moving = false; diff --git a/server/gameserver/playermgr.cc b/server/gameserver/playermgr.cc index 720dbc5..bd87ce6 100644 --- a/server/gameserver/playermgr.cc +++ b/server/gameserver/playermgr.cc @@ -33,10 +33,11 @@ Player* PlayerMgr::GetPlayerBySocket(int socket) return itr != socket_hash_.end() ? itr->second : nullptr; } -Player* PlayerMgr::CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg) +Player* PlayerMgr::CreatePlayerByCMJoin(long ip_saddr, int socket, const cs::CMJoin& msg) { Player* hum = new Player(); hum->socket_handle = socket; + hum->ip_saddr = ip_saddr; hum->account_id = msg.account_id(); hum->name = msg.name(); hum->health = 0; @@ -47,6 +48,7 @@ Player* PlayerMgr::CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg) hum->use_touch = msg.use_touch(); hum->avatar_url = msg.avatar_url(); hum->energy_shield = msg.energy_shield(); + hum->create_tick = a8::XGetTickCount(); for (auto& weapon : msg.weapons()) { if (weapon.weapon_id() != 0 && weapon.weapon_lv() > 0) { hum->weapon_configs[weapon.weapon_id()] = weapon.weapon_lv(); diff --git a/server/gameserver/playermgr.h b/server/gameserver/playermgr.h index 59ccf29..6bbbed6 100644 --- a/server/gameserver/playermgr.h +++ b/server/gameserver/playermgr.h @@ -28,7 +28,7 @@ class PlayerMgr : public a8::Singleton int OnlineNum(); Player* GetPlayerBySocket(int socket); - Player* CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg); + Player* CreatePlayerByCMJoin(long ip_saddr, int socket, const cs::CMJoin& msg); void OnClientDisconnect(a8::XParams& param); void RemovePlayerBySocket(int socket_handle); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 5d76468..2a94c7d 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -21,6 +21,7 @@ #include "roommgr.h" #include "app.h" #include "hero.h" +#include "gamelog.h" const int ROOM_MAX_PLAYER_NUM = 50; @@ -890,11 +891,14 @@ void Room::UpdateGas() { if (a8::HasBitFlag(hum->status, HS_Fly)) { hum->DoJump(); + if (hum->entity_subtype == EST_Player) { + GameLog::Instance()->GameStart((Player*)hum); + } } return true; }); gas_data.gas_mode = GasWaiting; - gas_data.old_area_meta = MetaMgr::Instance()->GetSafeArea(30001); + gas_data.old_area_meta = MetaMgr::Instance()->GetSafeArea(30001); gas_data.new_area_meta = MetaMgr::Instance()->GetSafeArea(30002); gas_data.gas_progress = gas_data.old_area_meta->i->rad(); gas_data.gas_start_frameno = frame_no; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 5d992e5..63d3083 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -84,9 +84,9 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) } if (i == 0) { { - Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg); - hum->meta = hum_meta; - room->AddPlayer(hum); + Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr, hdr.socket_handle, msg); + hum->meta = hum_meta; + room->AddPlayer(hum); cs::SMJoinedNotify notifymsg; notifymsg.set_error_code(0); @@ -115,7 +115,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) inactive_room_hash_[room->room_uuid] = room; room_hash_[room->room_uuid] = room; } - Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg); + Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr, hdr.socket_handle, msg); hum->meta = hum_meta; room->AddPlayer(hum); diff --git a/third_party/a8engine b/third_party/a8engine index f9222e3..c086156 160000 --- a/third_party/a8engine +++ b/third_party/a8engine @@ -1 +1 @@ -Subproject commit f9222e376f8a678a252932c4a3fb93860d7625f2 +Subproject commit c086156f8094a8ecce9faf5f30667d22e3918dc1