Example #1
0
void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int clientNum)
{
	CString message = Packet.ReadNT();
	if (message.at(0) == '/')
	{
		CString command = message.substr(1, message.find(" ")-1);
		if ((command.compare("list") == 0)||(command.compare("have") == 0))
		{
			if (command.compare("list") == 0)
			{
				Reply.ClearPacket();
				Reply.Write1(NSCCM + NSServerOffset);
				Reply.WriteNT(ListPlayers());
				SendNetPacket(clientNum, Reply);
			}
			else
			{
				message = "";
				message += Client[clientNum]->Player[0].name;
				if (Client[clientNum]->twoPlayers)
					message += "&";
				message += Client[clientNum]->Player[1].name;
				message += " forces has song.";
				Client[clientNum]->forceHas = true;
				ServerChat(message);
			}
		}
		else
		{
			if (clientNum == 0)
			{
				if (command.compare("force_start") == 0)
					ForceStart();
				if (command.compare("kick") == 0)
				{
					CString name = message.substr(message.find(" ")+1);
					Kick(name);
				}
				if (command.compare("ban") == 0)
				{
					CString name = message.substr(message.find(" ")+1);
					Ban(name);
				}
			}
			else
			{
				Reply.ClearPacket();
				Reply.Write1(NSCCM + NSServerOffset);
				Reply.WriteNT("You do not have permission to use server commands.");
				SendNetPacket(clientNum, Reply);
			}
		}
	}
	else
		RelayChat(message, clientNum);
}
Example #2
0
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;
    };
}