예제 #1
0
void GameClient::StartRequest(PacketFunctions& Packet)
{
	int firstbyte = Packet.Read1();
	int secondbyte = Packet.Read1();
	int thirdbyte = Packet.Read1();
	Player[0].feet = firstbyte/16;
	Player[1].feet = firstbyte%16;

	if ((Player[0].feet > 0)&&(Player[1].feet > 0))
		twoPlayers = true;

	Player[0].diff = secondbyte/16;
	Player[1].diff = secondbyte%16;

	startPosition = thirdbyte/16;
	gameInfo.title = Packet.ReadNT();
	gameInfo.subtitle = Packet.ReadNT();
	gameInfo.artist = Packet.ReadNT();
	gameInfo.course = Packet.ReadNT();

	for (int x = 0; x < 2; ++x)
	 {
		Player[x].score = 0;
		Player[x].combo = 0;
		Player[x].projgrade = 0;
		Player[x].maxCombo = 0;

		memset(Player[x].steps, 0, sizeof(int)*9);
	}

	GotStartRequest = true;
}
예제 #2
0
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();
            }
        }
    }
}
예제 #3
0
void SMOnlineRoom::SMOnlineParse(PacketFunctions &Packet, int clientnum) {
    int command = Packet.Read1();
    switch (command) {
    case 0:
        //Login
        break;
    case 1:
        //Change Room
    {
        int command = Packet.Read1();
        MString title = Packet.ReadNT();
        MString pw = Packet.ReadNT();
        ChangeRoom(command, title, clientnum, pw);
    }
    break;
    case 2:
        //Create new room
        if (m_allowgamerooms) {
            CreateRoom(Packet);
            ChangeRoom(1, m_joinrooms[m_joinrooms.size()-1]->GetTitle(), clientnum, "", true);
        }
        break;
    case 3:
        //Additional room info
        GenAdditionalInfo(Packet.ReadNT(), clientnum);
        break;
    default:
        LOG->Write(ssprintf("Invalid SMOnline command:%d", command));
        break;
    }
}
예제 #4
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);
}
예제 #5
0
void GameClient::StyleUpdate(PacketFunctions& Packet)
{
	int playernumber = 0;
	Player[0].name = Player[1].name = "";
	twoPlayers = Packet.Read1()-1;
	for (int x = 0; x < twoPlayers+1; ++x)
	{
		playernumber = Packet.Read1();
		Player[playernumber].name = Packet.ReadNT();
	}
}
예제 #6
0
void StepManiaLanServer::ParseData(PacketFunctions& Packet, const unsigned int clientNum)
{
	int command = Packet.Read1();
	switch (command)
	{
	case NSCPing:
		// No Operation
		SendValue(NSServerOffset + NSCPingR, clientNum);
		break;
	case NSCPingR:
		// No Operation response
		break;
	case NSCHello:
		// Hello
		Hello(Packet, clientNum);
		break;
	case NSCGSR:
		// Start Request
		Client[clientNum]->StartRequest(Packet);
		CheckReady();  //This is what ACTUALLY starts the games
		break;
	case NSCGON:
		// GameOver 
		GameOver(Packet, clientNum);
		break;
	case NSCGSU:
		// StatsUpdate
		Client[clientNum]->UpdateStats(Packet);
		if (!Client[clientNum]->lowerJudge)
			CheckLowerJudge(clientNum);
		break;
	case NSCSU:
		// Style Update
		Client[clientNum]->StyleUpdate(Packet);
		SendUserList();
		break;
	case NSCCM:
		// Chat message
		AnalizeChat(Packet, clientNum);
		break;
	case NSCRSG:
		SelectSong(Packet, clientNum);
		break;
	case NSCSMS:
		ScreenNetMusicSelectStatus(Packet, clientNum);
		break;
	case NSCUPOpts:
		Client[clientNum]->Player[0].options = Packet.ReadNT();		
		Client[clientNum]->Player[1].options = Packet.ReadNT();		
		break;
	default:
		break;
	}
}	 
예제 #7
0
void StepManiaLanServer::Hello(PacketFunctions& Packet, const unsigned int clientNum)
{
	int ClientVersion = Packet.Read1();
	CString build = Packet.ReadNT();

	Client[clientNum]->SetClientVersion(ClientVersion, build);

	Reply.ClearPacket();
	Reply.Write1( NSCHello + NSServerOffset );
	Reply.Write1(1);
	Reply.WriteNT(servername);

	SendNetPacket(clientNum, Reply);

	if (ClientHost == -1)
		ClientHost = clientNum;

}
예제 #8
0
void StepManiaLanServer::SelectSong(PacketFunctions& Packet, unsigned int clientNum)
{
	int use = Packet.Read1();
	CString message;

	if (use == 2)
	{
		if (clientNum == 0)
		{ 
			SecondSameSelect = false;

			CurrentSongInfo.title = Packet.ReadNT();
			CurrentSongInfo.artist = Packet.ReadNT();
			CurrentSongInfo.subtitle = Packet.ReadNT();

			Reply.ClearPacket();
			Reply.Write1(NSCRSG + NSServerOffset);
			Reply.Write1(1);
			Reply.WriteNT(CurrentSongInfo.title);
			Reply.WriteNT(CurrentSongInfo.artist);
			Reply.WriteNT(CurrentSongInfo.subtitle);		

			//Only send data to clients currently in ScreenNetMusicSelect
			for (unsigned int x = 0; x < Client.size(); ++x)
				if (Client[x]->inNetMusicSelect)
					SendNetPacket(x, Reply);

			//The following code forces the host to select the same song twice in order to play it.
			if ((strcmp(CurrentSongInfo.title, LastSongInfo.title) == 0) &&
				(strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0) &&
				(strcmp(CurrentSongInfo.subtitle, LastSongInfo.subtitle) == 0))
					SecondSameSelect = true;

			if (!SecondSameSelect)
			{
				LastSongInfo.title = CurrentSongInfo.title;
				LastSongInfo.artist = CurrentSongInfo.artist;
				LastSongInfo.subtitle = CurrentSongInfo.subtitle;
				message = "Play \"";
				message += CurrentSongInfo.title + " " + CurrentSongInfo.subtitle;
				message += "\"?";
				ServerChat(message);
			}

		}
		else
		{
			message = servername;
			message += ": You do not have permission to pick a song.";
			Reply.ClearPacket();
			Reply.Write1(NSCCM + NSServerOffset);
			Reply.WriteNT(message);
			SendNetPacket(clientNum, Reply);
		}
	}

	if (use == 1)
	{
		//If user dosn't have song
		Client[clientNum]->hasSong = false;
		message = Client[clientNum]->Player[0].name;

		if (Client[clientNum]->twoPlayers)
		{
			message += "&";
			message += Client[clientNum]->Player[1].name;
		}

		message += " lacks song \"";
		message += CurrentSongInfo.title;
		message += "\"";
		ServerChat(message);
	}

	//If client has song
	if (use == 0)
		Client[clientNum]->hasSong = true;

	//Only play if everyone has the same song and the host has select the same song twice.
	if ( CheckHasSongState() && SecondSameSelect && (clientNum == 0) )
	{
		ClientsSongSelectStart();

		//Reset last song in case host picks same song again (otherwise dual select is bypassed)
		ResetLastSongInfo();
	}
}
예제 #9
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;
    };
}