From 5eaf1deb0e3a895b1da60019c95da7ec180998c1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 12 Apr 2019 17:31:13 +0800 Subject: [PATCH] add test mode --- server/gameserver/app.cc | 1 + server/gameserver/app.h | 1 + server/gameserver/roommgr.cc | 92 ++++++++++++++++++++++++------------ 3 files changed, 65 insertions(+), 29 deletions(-) diff --git a/server/gameserver/app.cc b/server/gameserver/app.cc index ce8f987..db3f58f 100755 --- a/server/gameserver/app.cc +++ b/server/gameserver/app.cc @@ -447,6 +447,7 @@ bool App::ParseOpt() case 't': { is_test_mode = true; + test_param = a8::XValue(optarg); } } } diff --git a/server/gameserver/app.h b/server/gameserver/app.h index d4da03f..2039e4b 100644 --- a/server/gameserver/app.h +++ b/server/gameserver/app.h @@ -59,6 +59,7 @@ public: public: int instance_id = 0; bool is_test_mode = false; + int test_param = 0; private: long long last_run_tick_ = 0; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 84ba269..958883f 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -32,36 +32,70 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) if (!hum_meta) { abort(); } - Room* room = GetJoinableRoom(msg.account_id()); - if (!room) { - room = new Room(); - room->room_uuid = App::Instance()->NewUuid(); - assert(!GetRoomByUuid(room->room_uuid)); - if (GetRoomByUuid(room->room_uuid)) { - abort(); - } - room->map_meta = MetaMgr::Instance()->GetMap(1001); - room->Init(); - inactive_room_hash_[room->room_uuid] = room; - room_hash_[room->room_uuid] = room; - } else { - int i = 0; - } - Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg); - hum->meta = hum_meta; - room->AddPlayer(hum); + if (App::Instance()->is_test_mode) { + for (int i = 0; i < App::Instance()->test_param; ++i) { + Room* room = GetJoinableRoom(msg.account_id()); + if (!room) { + room = new Room(); + room->room_uuid = App::Instance()->NewUuid(); + assert(!GetRoomByUuid(room->room_uuid)); + if (GetRoomByUuid(room->room_uuid)) { + abort(); + } + room->map_meta = MetaMgr::Instance()->GetMap(1001); + room->Init(); + inactive_room_hash_[room->room_uuid] = room; + room_hash_[room->room_uuid] = room; + } + Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle + i * 10, msg); + hum->meta = hum_meta; + room->AddPlayer(hum); - { - cs::SMJoinedNotify notifymsg; - notifymsg.set_error_code(0); - room->FillSMJoinedNotify(hum, notifymsg); - GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); - } - { - cs::SMMapInfo notifymsg; - notifymsg.set_map_id(room->map_meta->i->map_id()); - room->FillSMMapInfo(notifymsg); - GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); + if (i == 0) { + { + cs::SMJoinedNotify notifymsg; + notifymsg.set_error_code(0); + room->FillSMJoinedNotify(hum, notifymsg); + GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); + } + { + cs::SMMapInfo notifymsg; + notifymsg.set_map_id(room->map_meta->i->map_id()); + room->FillSMMapInfo(notifymsg); + GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); + } + } + } + } else { + Room* room = GetJoinableRoom(msg.account_id()); + if (!room) { + room = new Room(); + room->room_uuid = App::Instance()->NewUuid(); + assert(!GetRoomByUuid(room->room_uuid)); + if (GetRoomByUuid(room->room_uuid)) { + abort(); + } + room->map_meta = MetaMgr::Instance()->GetMap(1001); + room->Init(); + inactive_room_hash_[room->room_uuid] = room; + room_hash_[room->room_uuid] = room; + } + Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg); + hum->meta = hum_meta; + room->AddPlayer(hum); + + { + cs::SMJoinedNotify notifymsg; + notifymsg.set_error_code(0); + room->FillSMJoinedNotify(hum, notifymsg); + GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); + } + { + cs::SMMapInfo notifymsg; + notifymsg.set_map_id(room->map_meta->i->map_id()); + room->FillSMMapInfo(notifymsg); + GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); + } } }