This commit is contained in:
aozhiwei 2019-04-13 10:46:39 +08:00
commit d49ca2eb95
3 changed files with 65 additions and 29 deletions

View File

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

View File

@ -59,6 +59,7 @@ public:
public: public:
int instance_id = 0; int instance_id = 0;
bool is_test_mode = false; bool is_test_mode = false;
int test_param = 0;
private: private:
long long last_run_tick_ = 0; long long last_run_tick_ = 0;

View File

@ -31,36 +31,70 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
if (!hum_meta) { if (!hum_meta) {
abort(); abort();
} }
Room* room = GetJoinableRoom(msg.account_id()); if (App::Instance()->is_test_mode) {
if (!room) { for (int i = 0; i < App::Instance()->test_param; ++i) {
room = new Room(); Room* room = GetJoinableRoom(msg.account_id());
room->room_uuid = App::Instance()->NewUuid(); if (!room) {
assert(!GetRoomByUuid(room->room_uuid)); room = new Room();
if (GetRoomByUuid(room->room_uuid)) { room->room_uuid = App::Instance()->NewUuid();
abort(); assert(!GetRoomByUuid(room->room_uuid));
} if (GetRoomByUuid(room->room_uuid)) {
room->map_meta = MetaMgr::Instance()->GetMap(1001); abort();
room->Init(); }
inactive_room_hash_[room->room_uuid] = room; room->map_meta = MetaMgr::Instance()->GetMap(1001);
room_hash_[room->room_uuid] = room; room->Init();
} else { inactive_room_hash_[room->room_uuid] = room;
int i = 0; room_hash_[room->room_uuid] = room;
} }
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg); Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle + i * 10, msg);
hum->meta = hum_meta; hum->meta = hum_meta;
room->AddPlayer(hum); room->AddPlayer(hum);
{ if (i == 0) {
cs::SMJoinedNotify notifymsg; {
notifymsg.set_error_code(0); cs::SMJoinedNotify notifymsg;
room->FillSMJoinedNotify(hum, notifymsg); notifymsg.set_error_code(0);
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); 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()); cs::SMMapInfo notifymsg;
room->FillSMMapInfo(notifymsg); notifymsg.set_map_id(room->map_meta->i->map_id());
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); 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);
}
} }
} }