Beispiel #1
0
///-----------MAIN LOOP--------------
void Server::MainLoop()
{
    while(serverIsRunning)
    {
        if (SDLNet_UDP_Recv(sock, input)) //Check if the server is receiving data from the clients
        {
            if(RECEIVED_KEY == LOG_IN_KEY)
            {
                string username = GetQueryArgument(input->data, 2);
                char logInStatus[1];
                logInStatus[0] = profile.LogIn(username, GetQueryArgument(input->data, 3));
                if(logInStatus[0] == LOG_IN_SUCCESS)
                    AddNewClient(input->address.host, input->address.port, username, input->channel);
                SendData((Uint8*)logInStatus, sizeof(logInStatus));
            }
            else if(RECEIVED_KEY == REGISTER_KEY)
            {
                char registerStatus[1];
                registerStatus[0] = profile.Register(GetQueryArgument(input->data, 2), GetQueryArgument(input->data, 3));
                SendData((Uint8*)registerStatus, sizeof(registerStatus));
                cout << "New profile registered: " << GetQueryArgument(input->data, 2) << endl;
            }
            else if(RECEIVED_KEY == KICK_KEY)
            {
                KickClient(input->address.host);
            }
            Server::SendBack();
            receivedData = "";
        }
    }
}
Beispiel #2
0
void _DoKick (edict_t * target)
{
	char buf[128];

	sprintf (buf, "more than %i%% voted for.", (int) kickvote_pass->value);
	_ClrKickVotesOn (target);
	if (kickvote_tempban->value)
		Ban_TeamKiller(target, 1); //Ban for 1 game

	KickClient (target, buf);
}
Beispiel #3
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;
    };
}