int GameClient::GetData(PacketFunctions& Packet) { int length = -1; Packet.ClearPacket(); length = clientSocket.ReadPack((char*)Packet.Data, NETMAXBUFFERSIZE); return length; }
void SMOnlineRoom::WriteRoomListPacket(PacketFunctions &Packet) { unsigned int numRooms = m_joinrooms.size(); Packet.ClearPacket(); Packet.Write1(NSSMONL + NSServerOffset); Packet.Write1(1); //Room command Packet.Write1(1); //Type (List Rooms) Packet.Write1(numRooms); for (unsigned int x = 0; x < numRooms; ++x) { if (m_joinrooms[x] != NULL) { Packet.WriteNT(m_joinrooms[x]->GetTitle()); Packet.WriteNT(m_joinrooms[x]->GetDescription()); } } //state for (unsigned int x = 0; x < numRooms; ++x) { if (m_joinrooms[x] != NULL) { //TO MAKE CHARLES HAPPY IF PASSWORDED USE 1 (UNSUSED) if (!m_joinrooms[x]->m_passwd.empty() && (m_joinrooms[x]->m_state == RS_OPEN)) Packet.Write1(RS_UNUSED); else Packet.Write1(m_joinrooms[x]->m_state); } } //Flags char flags; for (unsigned int x = 0; x < numRooms; ++x) { if (m_joinrooms[x] != NULL) { flags = 0; //bit 1 passworded if (!m_joinrooms[x]->m_passwd.empty()) flags += 1; Packet.Write1(flags); } } }
void SMOnlineRoom::WriteChatPacket(PacketFunctions& packet, const MString& message) { packet.ClearPacket(); packet.Write1(NSCCM + NSServerOffset); packet.WriteNT(message); }
void SMOnlineRoom::AnalizeChat(unsigned int clientNum, PacketFunctions& Packet) { MString message = Packet.ReadNT(); ChatCommandPack ccp = ParseCommands(message, clientNum); switch(ccp.cmd) { case NONE: RelayChat(clientNum, message); return; case ANNOUNCE: { PacketFunctions reply; reply.ClearPacket(); reply.Write1(NSCSU+NSServerOffset); reply.WriteNT(ccp.data.front()); SERVER->SendToAll(reply); } return; case KICK: { const MString& name = ccp.data.front(); for (unsigned int x = 0; x < m_clients.size(); ++x) for (unsigned int y = 0; y < m_clients[x]->GetNumPlayers(); ++y) if (m_clients[x]->GetPlayer(y)->GetName() == name) { LOG->Write("Kicking " + name); m_kicked[ccp.data.front()] = KickClient(name); ChangeRoom(1, m_joinrooms[0]->GetTitle(), x, "", true); return; } } break; case BAN: { const MString& name = ccp.data.front(); for (unsigned int x = 0; x < m_clients.size(); ++x) for (unsigned int y = 0; y < m_clients[x]->GetNumPlayers(); ++y) if (m_clients[x]->GetPlayer(y)->GetName() == name) { LOG->Write("Banning " + name); m_banned[name] = name; ChangeRoom(1, m_joinrooms[0]->GetTitle(), x, "", true); return; } } break; case PM: { MString user = ccp.data.front(); ccp.data.pop(); MString message = ccp.data.front(); MString tmp; MString success = "PM Failed!"; if ((user.length() > 0) && (message.length() > 0)) { tmp = "PM from "; unsigned int numPlayers = m_clients[m_cNum]->GetNumPlayers(); for (unsigned int x = 0; x < numPlayers; ++x) { tmp += m_clients[m_cNum]->GetPlayerName(x); if ((numPlayers > 1) && (x < (numPlayers - 1))) tmp += "&"; } tmp += ": " + message; if (SERVER->MsgPlayer(user, tmp)) success = "PM Success!"; } PacketFunctions result; result.ClearPacket(); result.Write1(NSCCM + NSServerOffset); result.WriteNT(success); m_clients[m_cNum]->SendData(result); } break; case DROP: { SMOnlineClient* tmp = SERVER->GetPlayerClient(ccp.data.front()); if (tmp != NULL) tmp->connection.close(); } break; // case FORCESTART: // break; default: break; }; }