void SMOnlineRoom::CreateRoom(PacketFunctions& Packet) { bool origional_name = true; SMOnlineRoom* tmp = NULL; int type = Packet.Read1(); MString title = Packet.ReadNT(); MString sub = Packet.ReadNT(); MString passwd = Packet.ReadNT(); if (!title.empty()) { if (title.size() > m_roomNameLength) title = title.substr(0, m_roomNameLength); for (unsigned int x = 0; (x < m_joinrooms.size()) && origional_name; ++x) if (title == m_joinrooms[x]->m_title) origional_name = false; if (origional_name) { if (type) { tmp = new SMOnlineGameRoom(title, sub); } else { tmp = new SMOnlineRoom(title, sub); } if (tmp) { LOG->Write("Created room"); if (!passwd.empty()) tmp->m_passwd = passwd; SERVER->GetRooms().push_back(tmp); JoinToRoom(tmp); SendRoomList(); } } } }
bool SMOnlineRoom::AddClient(SMOnlineClient *client, const MString& pw, bool ignorePass) { //IN_GAME is the only state that we are not allowed to add clients if (m_state == RS_INGAME) return false; //Check for self for (unsigned int i = 0; i < m_clients.size(); ++i) if (m_clients[i] == client) return false; if ( CheckForBan(client) || CheckForKick(client) ) return false; //ignorePass must be false and m_password must not be empty if ( !ignorePass && !m_passwd.empty()) if (pw != m_passwd) return false; int cnum = m_clients.size(); m_clients.push_back(client); client->SetInRoom(true); SendRoomTitle(cnum); SendRoomList(cnum); PopulatePlayersList(); SendPlayersList(); return true; }
// 룸 리스트를 요청받았을 때 처리하는 함수 ERROR_CODE PacketProcess::LobbyRoomList(PacketInfo packetInfo) { CHECK_START // 현재 로비에 있는지 조사한다. // 룸 리스트를 보내준다. auto pUserRet = m_pRefUserMgr->GetUser(packetInfo.sessionIndex); auto errorCode = std::get<0>(pUserRet); if (errorCode != ERROR_CODE::NONE) { CHECK_ERROR(errorCode); } auto pUser = std::get<1>(pUserRet); if (pUser->IsCurDomainInLobby() == false) { CHECK_ERROR(ERROR_CODE::LOBBY_ROOM_LIST_INVALID_DOMAIN); } auto pLobby = m_pRefLobbyMgr->GetLobby(pUser->GetLobbyIndex()); if (pLobby == nullptr) { CHECK_ERROR(ERROR_CODE::LOBBY_ROOM_LIST_INVALID_LOBBY_INDEX); } auto reqPkt = (NCommon::PktLobbyRoomListReq*)packetInfo.dataAddress; pLobby->SendRoomList(pUser->GetSessioIndex(), reqPkt->StartRoomIndex); return ERROR_CODE::NONE; CHECK_ERR: NCommon::PktLobbyRoomListRes resPkt; resPkt.SetError(__result); m_pRefNetwork->SendData(packetInfo.sessionIndex, (short)PACKET_ID::LOBBY_ENTER_ROOM_LIST_RES, sizeof(NCommon::PktBase), (char*)&resPkt); return (ERROR_CODE)__result; }
void SMOnlineRoom::JoinToRoom(SMOnlineRoom *room) { //join other room to this room. m_joinrooms.push_back(room); //join this room to the other room room->m_joinrooms.push_back(this); //Let users in both rooms know of the added rooms SendRoomList(); room->SendRoomList(); }
void SMOnlineRoom::UnjoinToRoom(const MString &roomname) { SMOnlineRoom* tmproom; for (unsigned int x = 0; x < m_joinrooms.size(); ++x) if (m_joinrooms[x]->GetTitle() == roomname) { tmproom = m_joinrooms[x]; m_joinrooms[x] = NULL; m_joinrooms.erase(m_joinrooms.begin()+x); tmproom->UnjoinToRoom(m_title); //Remove the other room's link to this room break; //end the search } SendRoomList(); }
void SMOnlineRoom::ParseData(PacketFunctions& Packet, int clientnum) { /* Try not to do any Packet Parsing here here because a lot of parsing was done in the Client. Parsing again would be a waste. Packet has been unaltered previous to this point.*/ int command = Packet.Read1(); switch (command) { case NSCPing: // No Operation // SendValue(NSServerOffset + NSCPingR, clientNum); break; case NSCPingR: // No Operation response break; case NSCHello: // Hello break; case NSCSU: // Style Update break; case NSCCM: // Chat message AnalizeChat(clientnum, Packet); break; case NSCSMS: //Room Status Change SendRoomTitle(clientnum); SendRoomList(clientnum); break; case NSSMONL: SMOnlineParse(Packet, clientnum); break; default: break; } }