add test mode

This commit is contained in:
aozhiwei 2019-04-12 17:31:13 +08:00
parent b3da54c99c
commit 5eaf1deb0e
3 changed files with 65 additions and 29 deletions

View File

@ -447,6 +447,7 @@ bool App::ParseOpt()
case 't':
{
is_test_mode = true;
test_param = a8::XValue(optarg);
}
}
}

View File

@ -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;

View File

@ -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);
}
}
}