From 4e91f9add30adc2c1947c9d9336724ad672c9024 Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Fri, 24 Nov 2006 07:13:27 +0000 Subject: [PATCH] Pull out the SMLAN server. Its very out of date and not used, besides the SMO server can act as a lan server. --- stepmania/src/NetworkSyncManager.h | 1 - stepmania/src/NetworkSyncServer.cpp | 1039 ------------------------ stepmania/src/NetworkSyncServer.h | 169 ---- stepmania/src/ScreenNetworkOptions.cpp | 58 -- stepmania/src/StepMania-net2005.vcproj | 8 - 5 files changed, 1275 deletions(-) delete mode 100644 stepmania/src/NetworkSyncServer.cpp delete mode 100644 stepmania/src/NetworkSyncServer.h diff --git a/stepmania/src/NetworkSyncManager.h b/stepmania/src/NetworkSyncManager.h index fe00b4b26a..06bb5dd633 100644 --- a/stepmania/src/NetworkSyncManager.h +++ b/stepmania/src/NetworkSyncManager.h @@ -149,7 +149,6 @@ public: PacketFunctions m_SMOnlinePacket; - bool isLanServer; //Must be public for ScreenNetworkOptions StepManiaLanServer *LANserver; int GetSMOnlineSalt(); diff --git a/stepmania/src/NetworkSyncServer.cpp b/stepmania/src/NetworkSyncServer.cpp deleted file mode 100644 index 82d7118eda..0000000000 --- a/stepmania/src/NetworkSyncServer.cpp +++ /dev/null @@ -1,1039 +0,0 @@ -#include "global.h" -#include "GamePreferences.h" -#include "NetworkSyncServer.h" -#include "RageLog.h" -#include "Player.h" -#include - -#if defined(WITHOUT_NETWORKING) -bool StepManiaLanServer::ServerStart() { return false; } -void StepManiaLanServer::ServerStop() { } -void StepManiaLanServer::ServerUpdate() { } -StepManiaLanServer::StepManiaLanServer() { } -StepManiaLanServer::~StepManiaLanServer() { } -#else - -static Preference g_fStartWait( "ServerWaitSeconds", 2 ); - -LanPlayer::LanPlayer() -{ - score = 0; - health = 0; - feet = 0; - projgrade = 0; - combo = 0; - currstep = 0; - maxCombo = 0; - Grade = 0; - offset = 0; - options = ""; -} - -StepManiaLanServer::StepManiaLanServer() -{ - stop = true; - SecondSameSelect = false; - AssignPlayerIDs(); -} - -StepManiaLanServer::~StepManiaLanServer() -{ - ServerStop(); -} - -bool StepManiaLanServer::ServerStart() -{ - server.blocking = 0; /* Turn off blocking */ - if (server.create()) - if (server.bind(8765)) - if (server.listen()) - { - broadcast.create( IPPROTO_UDP ); - broadcast.connect( "255.255.255.255", 8765 ); - stop = false; - statsTime = time(NULL); - return true; - } - else - lastError = "Failed to make socket listen."; - else - lastError = "Failed to bind socket"; - else - lastError = "Failed to create socket"; - - lastErrorCode = server.lastCode; - //Hopefully we will not get here. If we did, something went wrong above. - return false; -} - -void StepManiaLanServer::ServerStop() -{ - for (unsigned int x = 0; x < Client.size(); ++x) - { - delete Client[x]; - Client[x] = NULL; - } - - Client.clear(); - server.close(); - stop = true; -} - -void StepManiaLanServer::ServerUpdate() -{ - if (!stop) - { - NewClientCheck(); /* See if there is another client wanting to play */ - UpdateClients(); - if (time(NULL) > statsTime) - { - BroadcastInfo(); - SendStatsToClients(); - statsTime = time(NULL); - } - } -} - -void StepManiaLanServer::UpdateClients() -{ - //Go through all the clients and check to see if it is being used. - //If so then try to get a backet and parse the data. - for (unsigned int x = 0; x < Client.size(); ++x) - if (CheckConnection(x) && (Client[x]->GetData(Packet) >= 0)) - ParseData(Packet, x); -} - -GameClient::GameClient() -{ - GotStartRequest = 0; - clientSocket.blocking = 0; - twoPlayers = false; - version = 0; - startPosition = 0; - InGame = 0; - hasSong = forceHas = false; - inNetMusicSelect = false; - isStarting = false; //Used for after ScreenNetMusicSelect but before InGame - wasIngame = false; - lowerJudge = false; - NetScreenInfo = NS_NOWHERE; -} - -void StepManiaLanServer::Disconnect(const unsigned int clientNum) -{ - if (clientNum == (Client.size()-1)) - { - delete Client[Client.size()-1]; - Client[Client.size()-1] = NULL; - Client.pop_back(); - } - else - { - vector::iterator Iterator; - Iterator = Client.begin(); - for (unsigned int x = 0; x < Client.size(); ++x) - { - if (x == clientNum) - { - delete Client[x]; - Client[x] = NULL; - Client.erase(Iterator); - } - ++Iterator; - } - } - SendUserList(); -} - -int GameClient::GetData(PacketFunctions& Packet) -{ - int length = -1; - Packet.ClearPacket(); - length = clientSocket.ReadPack((char*)Packet.Data, NETMAXBUFFERSIZE); - return length; -} - -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; - } -} - -void StepManiaLanServer::Hello(PacketFunctions& Packet, const unsigned int clientNum) -{ - int ClientVersion = Packet.Read1(); - RString 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; - -} - -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(); - } -} - -void GameClient::SetClientVersion(int ver, const RString& b) -{ - version = ver; - build = b; -} - -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; -} - -void StepManiaLanServer::CheckReady() -{ - bool canStart = true; - unsigned int x; - - //Only check clients that are starting (after ScreenNetMusicSelect before InGame). - for (x = 0; (x < Client.size()) && canStart; ++x) - { - if (Client[x]->isStarting && !Client[x]->GotStartRequest) - canStart = false; - - //Start for courses - if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest) - canStart = true; - } - - if (canStart) - { - //(Test this) - //For whatever reason we need to pause in a way - //that will not use a lot of CPU. - //When you try playing the music as soon as it's loaded - //it will not always play ... immediately - usleep( int( g_fStartWait * 1000000.0 ) ); - - //The next three loops are seperate because we want to minimize what is done - //during the actual loop that starts the clients. This is in an atempt - //to start all the clients as close together as possible. - for (x = 0; x < Client.size(); ++x) - { - if (Client[x]->isStarting) - { - Client[x]->clientSocket.blocking = true; - Client[x]->GotStartRequest = false; - } - - //For Start for courses - if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest) - { - Client[x]->clientSocket.blocking = true; - Client[x]->GotStartRequest = false; - } - } - - //Start clients waiting for a start between ScreenNetMusicSelect and the game. - for (x = 0; x < Client.size(); ++x) - { - if (Client[x]->isStarting) - SendValue(NSCGSR + NSServerOffset, x); - - //For Start for courses - if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong) - SendValue(NSCGSR + NSServerOffset, x); - } - - for (x = 0; x < Client.size(); ++x) - { - if (Client[x]->isStarting) - { - if (Client[x]->startPosition == 1) - { - Client[x]->isStarting = false; - Client[x]->InGame = true; - Client[x]->lowerJudge = false; - //After we start the clients, clear each client's hasSong. - Client[x]->hasSong = false; - } - Client[x]->clientSocket.blocking = false; - } - - //For Start for courses - if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong) - { - if (Client[x]->startPosition == 1) - { - Client[x]->isStarting = false; - Client[x]->InGame = true; - Client[x]->lowerJudge = false; - //After we start the clients, clear each client's hasSong. - Client[x]->hasSong = false; - } - Client[x]->clientSocket.blocking = false; - } - } - } -} - -void StepManiaLanServer::GameOver(PacketFunctions& Packet, const unsigned int clientNum) -{ - bool allOver = true; - unsigned int x; - - unsigned int numPlayers = playersPtr.size(); - - Client[clientNum]->hasSong = Client[clientNum]->forceHas = 0; - Client[clientNum]->GotStartRequest = false; - Client[clientNum]->InGame = false; - Client[clientNum]->wasIngame = true; - - for (x = 0; (x < Client.size())&&allOver ; ++x) - if (Client[x]->InGame) - allOver = false; - - //Wait until everyone is done before sending - if (allOver) - { - for (x = 0; x < Client.size(); ++x) - if (Client[x]->wasIngame && Client[x]->lowerJudge) - for (int y = 0; y < 2; ++y) - Client[x]->Player[y].options = "TIMING " + playersPtr[x]->options; - - SortStats(playersPtr); - Reply.ClearPacket(); - Reply.Write1( NSCGON + NSServerOffset ); - Reply.Write1( (uint8_t) numPlayers ); - for (x = 0; x < numPlayers; ++x) - Reply.Write1((uint8_t)playersPtr[x]->PlayerID); - for (x = 0; x < numPlayers; ++x) - Reply.Write4(playersPtr[x]->score); - for (x = 0; x < numPlayers; ++x) - Reply.Write1( (uint8_t) playersPtr[x]->projgrade ); - for (x = 0; x < numPlayers; ++x) - Reply.Write1( (uint8_t) playersPtr[x]->diff ); - for (int y = 6; y >= 1; --y) - for (x = 0; x < numPlayers; ++x) - Reply.Write2( (uint16_t) playersPtr[x]->steps[y] ); - for (x = 0; x < numPlayers; ++x) - Reply.Write2( (uint16_t) playersPtr[x]->steps[8] ); //Tack on OK - for (x = 0; x < numPlayers; ++x) - Reply.Write2( (uint16_t) playersPtr[x]->maxCombo ); - for (x = 0; x < numPlayers; ++x) - Reply.WriteNT( playersPtr[x]->options ); - - for (x = 0; x < Client.size(); ++x) - if(Client[x]->wasIngame) - { - SendNetPacket(x, Reply); - Client[x]->wasIngame = false; - } - } -} - -void StepManiaLanServer::AssignPlayerIDs() -{ - unsigned int counter = 0; - //Future: Figure out how to do dynamic numbering. - for (unsigned int x = 0; x < Client.size(); ++x) - for(int y = 0; y < 2; ++y) - Client[x]->Player[y].PlayerID = counter++; -} - -void StepManiaLanServer::PopulatePlayersPtr(vector &playersPtr) { - - for (unsigned int x = 0; x < playersPtr.size(); ++x) - playersPtr[x] = NULL; - - playersPtr.clear(); - - //Populate with in game players only - for (unsigned int x = 0; x < Client.size(); ++x) - if (Client[x]->InGame||Client[x]->wasIngame) - for (int y = 0; y < 2; ++y) - if (Client[x]->IsPlaying(y)) - playersPtr.push_back(&Client[x]->Player[y]); -} - -int StepManiaLanServer::SortStats(vector &playersPtr) -{ - LanPlayer *tmp; - bool isChanged; - - PopulatePlayersPtr(playersPtr); - - do - { - isChanged = false; - for (int x = 0; x < int(playersPtr.size())-1; ++x) - if ((playersPtr[x]->score) < (playersPtr[x+1]->score)) - { - tmp = playersPtr[x]; - playersPtr[x] = playersPtr[x+1]; - playersPtr[x+1] = tmp; - isChanged = true; - } - } while (isChanged); - - return playersPtr.size(); -} - -void StepManiaLanServer::SendStatsToClients() -{ - unsigned int x; - - SortStats(playersPtr); //Return number of players - - /* Write and Send name packet */ - Reply.ClearPacket(); - Reply.Write1(NSCGSU + NSServerOffset); - Reply.Write1(0); - Reply.Write1( (uint8_t) playersPtr.size()); - StatsNameColumn(Reply, playersPtr); - - //Send to in game clients only. - for (x = 0; x < Client.size(); ++x) - if (Client[x]->InGame) - SendNetPacket(x, Reply); - - - /* Write and send Combo packet */ - Reply.ClearPacket(); - - Reply.Write1(NSCGSU + NSServerOffset); - Reply.Write1(1); - Reply.Write1( (uint8_t) playersPtr.size() ); - StatsComboColumn(Reply, playersPtr); - - //Send to in game clients only. - for (x = 0; x < Client.size(); ++x) - if (Client[x]->InGame) - SendNetPacket(x, Reply); - - - /* Write and send projgrade packet*/ - //Is it worth the programing troube to save a small amount of bandwidth here? - //Probably not. Sends all everytime unless developer feelings change. - Reply.ClearPacket(); - - Reply.Write1(NSCGSU + NSServerOffset); - Reply.Write1(2); - Reply.Write1( (uint8_t) playersPtr.size()); - StatsProjgradeColumn(Reply, playersPtr); - - //Send to in game clients only. - for (x = 0; x < Client.size(); ++x) - if (Client[x]->InGame) - SendNetPacket(x, Reply); - -} - -void StepManiaLanServer::SendNetPacket(const unsigned int client, PacketFunctions& Packet) -{ - if ( client < Client.size() ) - Client[client]->clientSocket.SendPack((char*)Packet.Data, Packet.Position); -} - -void StepManiaLanServer::StatsNameColumn(PacketFunctions &data, vector &playresPtr) -{ - for (unsigned int x = 0; x < playersPtr.size(); ++x) - data.Write1( (uint8_t) playersPtr[x]->PlayerID ); -} - -void StepManiaLanServer::StatsComboColumn(PacketFunctions &data, vector &playresPtr) -{ - for(unsigned int x = 0; x < playersPtr.size(); ++x ) - data.Write2( (uint16_t) playersPtr[x]->combo); -} - -void StepManiaLanServer::StatsProjgradeColumn(PacketFunctions& data, vector &playresPtr) -{ - for(unsigned int x = 0; x < playersPtr.size(); ++x ) - data.Write1( (uint8_t) playersPtr[x]->projgrade ); -} - -bool GameClient::IsPlaying(int x) -{ - //If the feet setting is above 0, there must be a player. - if (Player[x].feet > 0) - return true; - - return false; -} - -void GameClient::UpdateStats(PacketFunctions& Packet) -{ - //Get the Stats from a packet - char firstbyte = Packet.Read1(); - char secondbyte = Packet.Read1(); - int pID = int(firstbyte/16); /* MSN */ - - Player[pID].currstep = int(firstbyte%16); /* LSN */ - Player[pID].projgrade = int(secondbyte/16); - Player[pID].score = Packet.Read4(); - Player[pID].combo = Packet.Read2(); - - if (Player[pID].combo > Player[pID].maxCombo) - Player[pID].maxCombo = Player[pID].combo; - - Player[pID].health = Packet.Read2(); - Player[pID].offset = ((double)abs(int(Packet.Read2())-32767)/2000); - Player[pID].steps[Player[pID].currstep]++; -} - -void StepManiaLanServer::NewClientCheck() -{ - //Make a new client and accept a connection to it. - //If no connection is accepted, delete the client. - - GameClient *tmp = new GameClient; - - if (server.accept(tmp->clientSocket) == 1) - if (!IsBanned(tmp->clientSocket.address)) - { - Client.push_back(tmp); - AssignPlayerIDs(); - } - else - { - delete tmp; - tmp = NULL; - } - else - { - delete tmp; - tmp = NULL; - } -} - -void StepManiaLanServer::SendValue(uint8_t value, const unsigned int clientNum) -{ - if ( clientNum < Client.size() ) - Client[clientNum]->clientSocket.SendPack((char*)&value, sizeof(uint8_t)); -} - -void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int clientNum) -{ - RString message = Packet.ReadNT(); - if (message.at(0) == '/') - { - RString 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) - { - RString name = message.substr(message.find(" ")+1); - Kick(name); - } - if (command.compare("ban") == 0) - { - RString 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); -} - -void StepManiaLanServer::RelayChat(RString &passedmessage, const unsigned int clientNum) -{ - Reply.ClearPacket(); - RString message = ""; - - message += Client[clientNum]->Player[0].name; - - if (Client[clientNum]->twoPlayers) - message += "&"; - - message += Client[clientNum]->Player[1].name; - - message += ": "; - message += passedmessage; - Reply.Write1(NSCCM + NSServerOffset); - Reply.WriteNT(message); - - SendToAllClients(Reply); -} - -void StepManiaLanServer::SelectSong(PacketFunctions& Packet, unsigned int clientNum) -{ - int use = Packet.Read1(); - RString 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(); - } -} - -void StepManiaLanServer::ClientsSongSelectStart() -{ - Reply.ClearPacket(); - Reply.Write1(NSCRSG + NSServerOffset); - Reply.Write1(2); - Reply.WriteNT(CurrentSongInfo.title); - Reply.WriteNT(CurrentSongInfo.artist); - Reply.WriteNT(CurrentSongInfo.subtitle); - - //Only send data to clients currently in ScreenNetMusicSelect that use hasSong - for (unsigned int x = 0; x < Client.size(); ++x) - if (Client[x]->inNetMusicSelect && Client[x]->hasSong) - { - SendNetPacket(x, Reply); - //Designate the client is starting, - //after ScreenNetMusicSelect but before game play (InGame). - Client[x]->isStarting = true; - } -} - -bool StepManiaLanServer::CheckHasSongState() -{ - for (unsigned int x = 0; x < Client.size(); ++x) - if (Client[x]->inNetMusicSelect && !Client[x]->hasSong) - return false; - - return true; -} - -void StepManiaLanServer::ClearHasSong() -{ - for (unsigned int x = 0; x < Client.size(); ++x) - Client[x]->hasSong = false; - -} - -void StepManiaLanServer::SendToAllClients(PacketFunctions& Packet) -{ - for (unsigned int x = 0; x < Client.size(); ++x) - SendNetPacket(x, Packet); - -} -void StepManiaLanServer::ServerChat(const RString& message) -{ - RString x = servername + ": " + message; - Reply.ClearPacket(); - Reply.Write1(NSCCM + NSServerOffset); - Reply.WriteNT(x); - SendToAllClients(Reply); -} - -bool StepManiaLanServer::CheckConnection(const unsigned int clientNum) -{ - //If there is an error close the socket. - - if ( clientNum >= Client.size() ) - return false; - - if (Client[clientNum]->clientSocket.IsError()) - { - Disconnect(clientNum); - return false; - } - return true; -} - -void StepManiaLanServer::SendUserList() -{ - Reply.ClearPacket(); - Reply.Write1(NSCUUL + NSServerOffset); - Reply.Write1( (uint8_t) Client.size()*2 ); - Reply.Write1( (uint8_t) Client.size()*2 ); - - for (unsigned int x = 0; x < Client.size(); ++x) - for (int y = 0; y < 2; ++y) - { - if (Client[x]->Player[y].name.length() == 0) - Reply.Write1(0); - else - Reply.Write1( (int8_t)Client[x]->NetScreenInfo + 1); - Reply.WriteNT(Client[x]->Player[y].name); - } - - SendToAllClients(Reply); -} - -void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, unsigned int clientNum) -{ - RString message = ""; - int EntExitCode = Packet.Read1(); - - message += Client[clientNum]->Player[0].name; - if (Client[clientNum]->twoPlayers) - message += "&"; - message += Client[clientNum]->Player[1].name; - - if (EntExitCode % 2 == 1) - Client[clientNum]->inNetMusicSelect = true; - else - Client[clientNum]->inNetMusicSelect = false; - - GameClient::LastNetScreen LastScreenInfo = GameClient::NS_NOWHERE; - - switch (EntExitCode) - { - case 0: - message += " left the song selection."; - break; - case 1: - message += " entered the song selection."; - LastScreenInfo = GameClient::NS_SELECTSCREEN; - break; - case 2: - message += " exited options."; - break; - case 3: - message += " went into options."; - LastScreenInfo = GameClient::NS_OPTIONS; - break; - case 4: - //no need to mention exiting of options - break; - case 5: - message += " finished the game."; - LastScreenInfo = GameClient::NS_EVALUATION; - break; - } - ServerChat(message); - Client[clientNum]->NetScreenInfo = LastScreenInfo; - SendUserList (); -} - -RString StepManiaLanServer::ListPlayers() -{ - RString list= "Player List:\n"; - for (unsigned int x = 0; x < Client.size(); ++x) - if (Client[x]->inNetMusicSelect) - for (int y = 0; y < 2; ++y) - if (Client[x]->Player[y].name.length() > 0) - list += Client[x]->Player[y].name + "\n"; - return list; -} - -void StepManiaLanServer::Kick(RString &name) -{ - bool kicked = false; - for (unsigned int x = 0; x < Client.size(); ++x) - for (int y = 0; (y < 2)&&(kicked == false); ++y) - if (name == Client[x]->Player[y].name) - { - ServerChat("Kicked " + name + "."); - Disconnect(x); - kicked = true; - } -} - -void StepManiaLanServer::Ban(RString &name) -{ - bool kicked = false; - for (unsigned int x = 0; x < Client.size(); ++x) - for (int y = 0; (y < 2)&&(kicked == false); ++y) - if (name == Client[x]->Player[y].name) - { - ServerChat("Banned " + name + "."); - bannedIPs.push_back(Client[x]->clientSocket.address); - Disconnect(x); - kicked = true; - } -} - -bool StepManiaLanServer::IsBanned(RString &ip) -{ - for (unsigned int x = 0; x < bannedIPs.size(); ++x) - if (ip == bannedIPs[x]) - return true; - return false; -} - -void StepManiaLanServer::ForceStart() -{ - //Send the normal stat to clients using hasSong. - ClientsSongSelectStart(); - - //Reset last song in case host picks same song again (otherwise dual select is bypassed) - ResetLastSongInfo(); - - //Prepate force_start packet - Reply.ClearPacket(); - Reply.Write1(NSCRSG + NSServerOffset); - Reply.Write1(3); - - //Only send force_start data to clients currently in ScreenNetMusicSelect using forceHas - for (unsigned int x = 0; x < Client.size(); ++x) - if (Client[x]->inNetMusicSelect && Client[x]->forceHas) - { - SendNetPacket(x, Reply); - //Designate the client is starting, - //after ScreenNetMusicSelect but before game play (InGame). - Client[x]->isStarting = true; - } -} - -void StepManiaLanServer::ResetLastSongInfo() -{ - LastSongInfo.title = ""; - LastSongInfo.artist = ""; - LastSongInfo.subtitle = ""; -} - -void StepManiaLanServer::CheckLowerJudge(const unsigned int clientNum) -{ - for (int x = 0; x < 2; ++x) - if (Client[clientNum]->IsPlaying(x)) - { - if ((Client[clientNum]->Player[x].currstep == 2)&& - (Player::GetWindowSeconds(TW_W5) < Client[clientNum]->Player[x].offset)) - Client[clientNum]->lowerJudge = true; - if ((Client[clientNum]->Player[x].currstep == 3)&& - (Player::GetWindowSeconds(TW_W4) < Client[clientNum]->Player[x].offset)) - Client[clientNum]->lowerJudge = true; - if ((Client[clientNum]->Player[x].currstep == 4)&& - (Player::GetWindowSeconds(TW_W3) < Client[clientNum]->Player[x].offset)) - Client[clientNum]->lowerJudge = true; - if ((Client[clientNum]->Player[x].currstep == 5)&& - (Player::GetWindowSeconds(TW_W2) < Client[clientNum]->Player[x].offset)) - Client[clientNum]->lowerJudge = true; - if ((Client[clientNum]->Player[x].currstep == 6)&& - (Player::GetWindowSeconds(TW_W1) < Client[clientNum]->Player[x].offset)) - Client[clientNum]->lowerJudge = true; - } -} - -void StepManiaLanServer::BroadcastInfo() -{ - PacketFunctions Binfo; - Binfo.ClearPacket(); - Binfo.Write1( 141 ); //Code 13 + 128 - Binfo.WriteNT( servername ); - Binfo.Write2( 8765 ); - Binfo.Write2( (uint16_t) Client.size() ); - - broadcast.SendPack( (char*)&Binfo.Data, Binfo.Position ); -} - -#endif - -/* - * (c) 2003-2005 Joshua Allen, Charles Lohr - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, and/or sell copies of the Software, and to permit persons to - * whom the Software is furnished to do so, provided that the above - * copyright notice(s) and this permission notice appear in all copies of - * the Software and that both the above copyright notice(s) and this - * permission notice appear in supporting documentation. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF - * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS - * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT - * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - diff --git a/stepmania/src/NetworkSyncServer.h b/stepmania/src/NetworkSyncServer.h deleted file mode 100644 index a0813f807b..0000000000 --- a/stepmania/src/NetworkSyncServer.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef NetworkSyncServer_H -#define NetworkSyncServer_H - -#include "NetworkSyncManager.h" - -#if !defined(WITHOUT_NETWORKING) -#include "ezsockets.h" -#define NETMAXBUFFERSIZE 1020 - -class LanPlayer -{ -public: - RString name; - long score; - int health; - int feet; - int projgrade; - int combo; - int currstep; - int steps[9]; - int maxCombo; - int Grade; - double offset; - int PlayerID; - int diff; - RString options; - LanPlayer(); -}; - -class GameInfo -{ -public: - RString title; - RString subtitle; - RString artist; - RString course; -}; - -class GameClient -{ -public: - bool GotStartRequest; - EzSockets clientSocket; - void UpdateStats(PacketFunctions &Packet); - void SetClientVersion(int ver, const RString& b); - void StartRequest(PacketFunctions &Packet); - int GetData(PacketFunctions &Packet); - GameClient(); - LanPlayer Player[2]; - bool IsPlaying(int Player); - void StyleUpdate(PacketFunctions &Packet); - bool InGame; - int twoPlayers; - bool hasSong; - bool forceHas; - bool inNetMusicSelect; - int startPosition; - bool isStarting; - bool wasIngame; - bool lowerJudge; - - enum LastNetScreen - { - NS_NOWHERE = 0, - NS_SELECTSCREEN, - NS_OPTIONS, - NS_EVALUATION - } NetScreenInfo; - -private: - string build; - GameInfo gameInfo; - int version; -}; -#endif - -class StepManiaLanServer -{ -public: - bool ServerStart(); - void ServerStop(); - void ServerUpdate(); - StepManiaLanServer(); - ~StepManiaLanServer(); - RString servername; - RString lastError; - int lastErrorCode; - -private: -#if !defined(WITHOUT_NETWORKING) - bool stop; - PacketFunctions Packet; - PacketFunctions Reply; - vector Client; - EzSockets server; - EzSockets broadcast; - int ClientHost; - vector playersPtr; - time_t statsTime; - GameInfo CurrentSongInfo; - GameInfo LastSongInfo; - bool SecondSameSelect; - vector bannedIPs; - - void Hello(PacketFunctions& Packet, const unsigned int clientNum); - void UpdateClients(); - void NewClientCheck(); - void ParseData(PacketFunctions& Packet, const unsigned int clientNum); - void SendValue(uint8_t value, const unsigned int clientNum); - void CheckReady(); - void MoveClientToHost(); - void StatsComboColumn(PacketFunctions &data, vector &playresPtr); - void SendStatsToClients(); - void StatsProjgradeColumn(PacketFunctions& data, vector &playresPtr); - void StatsNameColumn(PacketFunctions& data, vector &playresPtr); - void SendNetPacket(const unsigned int clientNum, PacketFunctions &Packet); - int SortStats(vector &playresPtr); - void RelayChat(RString &passedmessage, const unsigned int clientNum); - void SelectSong(PacketFunctions& Packet, const unsigned int clientNum); - void ServerChat(const RString& message); - void SendToAllClients(PacketFunctions& Packet); - bool CheckHasSongState(); - void ClearHasSong(); - void AssignPlayerIDs(); - void SendUserList(); - void GameOver(PacketFunctions& Packet, const unsigned int clientNum); - void ScreenNetMusicSelectStatus(PacketFunctions& Packet, const unsigned int clientNum); - void AnalizeChat(PacketFunctions &Packet, const unsigned int clientNum); - RString ListPlayers(); - void Kick(RString &name); - void Ban(RString &name); - bool IsBanned(RString &ip); - void ForceStart(); - void CheckLowerJudge(const unsigned int clientNum); - bool CheckConnection(const unsigned int clientNum); - void PopulatePlayersPtr(vector &playersPtr); - void Disconnect(const unsigned int clientNum); - void ClientsSongSelectStart(); - void ResetLastSongInfo(); - void BroadcastInfo(); -#endif -}; - -#endif - -/* - * (c) 2003-2004 Joshua Allen - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, and/or sell copies of the Software, and to permit persons to - * whom the Software is furnished to do so, provided that the above - * copyright notice(s) and this permission notice appear in all copies of - * the Software and that both the above copyright notice(s) and this - * permission notice appear in supporting documentation. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF - * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS - * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT - * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ diff --git a/stepmania/src/ScreenNetworkOptions.cpp b/stepmania/src/ScreenNetworkOptions.cpp index c36a219550..b900f0fa5a 100644 --- a/stepmania/src/ScreenNetworkOptions.cpp +++ b/stepmania/src/ScreenNetworkOptions.cpp @@ -16,34 +16,21 @@ static LocalizedString CLIENT_CONNECT ( "ScreenNetworkOptions", "Connect" ); static LocalizedString CLIENT_DISCONNECT ( "ScreenNetworkOptions", "Disconnect" ); -static LocalizedString SERVER_START ( "ScreenNetworkOptions", "Start" ); -static LocalizedString SERVER_STOP ( "ScreenNetworkOptions", "Stop" ); static LocalizedString SCORE_ON ( "ScreenNetworkOptions", "ScoreOn" ); static LocalizedString SCORE_OFF ( "ScreenNetworkOptions", "ScoreOff" ); -static LocalizedString SERVER_STARTED ( "ScreenNetworkOptions", "Server started." ); -static LocalizedString SERVER_FAILED ( "ScreenNetworkOptions", "Server failed: %s Code:%d" ); static LocalizedString DISCONNECTED ( "ScreenNetworkOptions", "Disconnected from server." ); -static LocalizedString SERVER_STOPPED ( "ScreenNetworkOptions", "Server stopped." ); static LocalizedString ENTER_NETWORK_ADDRESS ( "ScreenNetworkOptions", "Enter a network address." ); static LocalizedString CONNECT_TO_YOURSELF ( "ScreenNetworkOptions", "Use 127.0.0.1 to connect to yourself." ); -static LocalizedString ENTER_A_SERVER_NAME ( "ScreenNetworkOptions", "Enter a server name." ); enum { PO_CONNECTION, - PO_SERVER, PO_SCOREBOARD, PO_SERVERS, NUM_NETWORK_OPTIONS_LINES }; -enum -{ - NO_STOP_SERVER=0, - NO_START_SERVER -}; - enum { NO_SCOREBOARD_OFF=0, @@ -51,7 +38,6 @@ enum }; AutoScreenMessage( SM_DoneConnecting ) -AutoScreenMessage( SM_ServerNameEnter ) Preference g_sLastServer( "LastConnectedServer", "" ); @@ -72,15 +58,6 @@ void ScreenNetworkOptions::Init() else pHand->m_Def.m_vsChoices.push_back(CLIENT_CONNECT); } - { - OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull(); - vHands.push_back( pHand ); - pHand->m_Def.m_bAllowThemeItems = false; - pHand->m_Def.m_bOneChoiceForAllPlayers = true; - pHand->m_Def.m_sName = "Server"; - pHand->m_Def.m_vsChoices.push_back(SERVER_STOP); - pHand->m_Def.m_vsChoices.push_back(SERVER_START); - } { OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull(); vHands.push_back( pHand ); @@ -123,24 +100,6 @@ void ScreenNetworkOptions::HandleScreenMessage( const ScreenMessage SM ) g_sLastServer.Set( ScreenTextEntry::s_sLastAnswer ); } } - else if( SM == SM_ServerNameEnter ) - { - if( !ScreenTextEntry::s_bCancelledLast ) - { - if ( NSMAN->LANserver == NULL) - NSMAN->LANserver = new StepManiaLanServer; - NSMAN->LANserver->servername = ScreenTextEntry::s_sLastAnswer; - if (NSMAN->LANserver->ServerStart()) - { - NSMAN->isLanServer = true; - SCREENMAN->SystemMessage( SERVER_STARTED ); - } - else - { - SCREENMAN->SystemMessage( ssprintf(SERVER_FAILED.GetValue(),NSMAN->LANserver->lastError.c_str(),NSMAN->LANserver->lastErrorCode) ); - } - } - } ScreenOptions::HandleScreenMessage( SM ); } @@ -161,23 +120,6 @@ void ScreenNetworkOptions::MenuStart( const InputEventPlus &input ) UpdateConnectStatus( ); } break; - case PO_SERVER: - switch( m_pRows[GetCurrentRow()]->GetOneSharedSelection() ) - { - case NO_START_SERVER: - if (!NSMAN->isLanServer) - { - ScreenTextEntry::TextEntry( SM_ServerNameEnter, ENTER_A_SERVER_NAME, "", 128); - } - break; - case NO_STOP_SERVER: - if ( NSMAN->LANserver != NULL ) - NSMAN->LANserver->ServerStop(); - SCREENMAN->SystemMessage( SERVER_STOPPED ); - NSMAN->isLanServer = false; - break; - } - break; case PO_SCOREBOARD: if (m_pRows[PO_SCOREBOARD]->GetOneSharedSelection() == NO_SCOREBOARD_ON) PREFSMAN->m_bEnableScoreboard.Set(true); diff --git a/stepmania/src/StepMania-net2005.vcproj b/stepmania/src/StepMania-net2005.vcproj index 0c93ef8dbe..00938b51f2 100644 --- a/stepmania/src/StepMania-net2005.vcproj +++ b/stepmania/src/StepMania-net2005.vcproj @@ -4786,14 +4786,6 @@ RelativePath="NetworkSyncManager.h" > - - - -