NULL pointers after deleting

Clean up nested if statements
Fix comparing artist twice
This commit is contained in:
Josh Allen
2004-10-30 04:13:45 +00:00
parent 8d51f577de
commit 093d66ecec
+37 -35
View File
@@ -10,6 +10,7 @@ void StepManiaLanServer::ServerStop() { }
void StepManiaLanServer::ServerUpdate() { } void StepManiaLanServer::ServerUpdate() { }
StepManiaLanServer::StepManiaLanServer() { } StepManiaLanServer::StepManiaLanServer() { }
StepManiaLanServer::~StepManiaLanServer() { } StepManiaLanServer::~StepManiaLanServer() { }
bool StepManiaLanServer::IsBanned(in_addr &ip) {}
#else #else
LanPlayer::LanPlayer() LanPlayer::LanPlayer()
@@ -64,7 +65,10 @@ bool StepManiaLanServer::ServerStart()
void StepManiaLanServer::ServerStop() void StepManiaLanServer::ServerStop()
{ {
for (unsigned int x = 0; x < Client.size(); ++x) for (unsigned int x = 0; x < Client.size(); ++x)
{
delete Client[x]; delete Client[x];
Client[x] = NULL;
}
Client.clear(); Client.clear();
server.close(); server.close();
@@ -90,8 +94,7 @@ void StepManiaLanServer::UpdateClients()
//Go through all the clients and check to see if it is being used. //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. //If so then try to get a backet and parse the data.
for (unsigned int x = 0; x < Client.size(); ++x) for (unsigned int x = 0; x < Client.size(); ++x)
if (CheckConnection(x)) if (CheckConnection(x) && (Client[x]->GetData(Packet) >= 0))
if (Client[x]->GetData(Packet) >= 0)
ParseData(Packet, x); ParseData(Packet, x);
} }
@@ -116,6 +119,7 @@ void StepManiaLanServer::Disconnect(const unsigned int clientNum)
if (clientNum == (Client.size()-1)) if (clientNum == (Client.size()-1))
{ {
delete Client[Client.size()-1]; delete Client[Client.size()-1];
Client[Client.size()-1] = NULL;
Client.pop_back(); Client.pop_back();
} }
else else
@@ -127,6 +131,7 @@ void StepManiaLanServer::Disconnect(const unsigned int clientNum)
if (x == clientNum) if (x == clientNum)
{ {
delete Client[x]; delete Client[x];
Client[x] = NULL;
Client.erase(Iterator); Client.erase(Iterator);
} }
++Iterator; ++Iterator;
@@ -276,14 +281,11 @@ void StepManiaLanServer::CheckReady()
//Only check clients that are starting (after ScreenNetMusicSelect before InGame). //Only check clients that are starting (after ScreenNetMusicSelect before InGame).
for (x = 0; (x < Client.size()) && canStart; ++x) for (x = 0; (x < Client.size()) && canStart; ++x)
{ {
if (Client[x]->isStarting) if (Client[x]->isStarting && !Client[x]->GotStartRequest)
if (!Client[x]->GotStartRequest)
canStart = false; canStart = false;
//For Start for courses //Start for courses
if (Client[x]->inNetMusicSelect == false) if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest)
if (Client[x]->hasSong == false)
if (Client[x]->GotStartRequest)
canStart = true; canStart = true;
} }
@@ -308,9 +310,7 @@ void StepManiaLanServer::CheckReady()
} }
//For Start for courses //For Start for courses
if (Client[x]->inNetMusicSelect == false) if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest)
if (Client[x]->hasSong == false)
if (Client[x]->GotStartRequest)
{ {
Client[x]->clientSocket.blocking = true; Client[x]->clientSocket.blocking = true;
Client[x]->GotStartRequest = false; Client[x]->GotStartRequest = false;
@@ -324,8 +324,7 @@ void StepManiaLanServer::CheckReady()
SendValue(NSCGSR + NSServerOffset, x); SendValue(NSCGSR + NSServerOffset, x);
//For Start for courses //For Start for courses
if (Client[x]->inNetMusicSelect == false) if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong)
if (Client[x]->hasSong == false)
SendValue(NSCGSR + NSServerOffset, x); SendValue(NSCGSR + NSServerOffset, x);
} }
@@ -345,8 +344,7 @@ void StepManiaLanServer::CheckReady()
} }
//For Start for courses //For Start for courses
if (Client[x]->inNetMusicSelect == false) if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong)
if (Client[x]->hasSong == false)
{ {
if (Client[x]->startPosition == 1) if (Client[x]->startPosition == 1)
{ {
@@ -362,7 +360,6 @@ void StepManiaLanServer::CheckReady()
} }
} }
void StepManiaLanServer::GameOver(PacketFunctions& Packet, const unsigned int clientNum) void StepManiaLanServer::GameOver(PacketFunctions& Packet, const unsigned int clientNum)
{ {
bool allOver = true; bool allOver = true;
@@ -383,8 +380,7 @@ void StepManiaLanServer::GameOver(PacketFunctions& Packet, const unsigned int cl
if (allOver) if (allOver)
{ {
for (x = 0; x < Client.size(); ++x) for (x = 0; x < Client.size(); ++x)
if (Client[x]->wasIngame) if (Client[x]->wasIngame && Client[x]->lowerJudge)
if (Client[x]->lowerJudge)
for (int y = 0; y < 2; ++y) for (int y = 0; y < 2; ++y)
Client[x]->Player[y].options = "TIMING " + playersPtr[x]->options; Client[x]->Player[y].options = "TIMING " + playersPtr[x]->options;
@@ -430,6 +426,9 @@ void StepManiaLanServer::AssignPlayerIDs()
void StepManiaLanServer::PopulatePlayersPtr(vector<LanPlayer*> &playersPtr) { void StepManiaLanServer::PopulatePlayersPtr(vector<LanPlayer*> &playersPtr) {
for (unsigned int x = 0; x < playersPtr.size(); ++x)
playersPtr[x] = NULL;
playersPtr.clear(); playersPtr.clear();
//Populate with in game players only //Populate with in game players only
@@ -579,9 +578,15 @@ void StepManiaLanServer::NewClientCheck()
AssignPlayerIDs(); AssignPlayerIDs();
} }
else else
{
delete tmp; delete tmp;
tmp = NULL;
}
else else
{
delete tmp; delete tmp;
tmp = NULL;
}
} }
void StepManiaLanServer::SendValue(uint8_t value, const unsigned int clientNum) void StepManiaLanServer::SendValue(uint8_t value, const unsigned int clientNum)
@@ -596,6 +601,7 @@ void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int
{ {
CString command = message.substr(1, message.find(" ")-1); CString command = message.substr(1, message.find(" ")-1);
if ((command.compare("list") == 0)||(command.compare("have") == 0)) if ((command.compare("list") == 0)||(command.compare("have") == 0))
{
if (command.compare("list") == 0) if (command.compare("list") == 0)
{ {
Reply.ClearPacket(); Reply.ClearPacket();
@@ -614,7 +620,9 @@ void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int
Client[clientNum]->forceHas = true; Client[clientNum]->forceHas = true;
ServerChat(message); ServerChat(message);
} }
}
else else
{
if (clientNum == 0) if (clientNum == 0)
{ {
if (command.compare("force_start") == 0) if (command.compare("force_start") == 0)
@@ -638,6 +646,7 @@ void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int
SendNetPacket(clientNum, Reply); SendNetPacket(clientNum, Reply);
} }
} }
}
else else
RelayChat(message, clientNum); RelayChat(message, clientNum);
} }
@@ -690,9 +699,9 @@ void StepManiaLanServer::SelectSong(PacketFunctions& Packet, unsigned int client
SendNetPacket(x, Reply); SendNetPacket(x, Reply);
//The following code forces the host to select the same song twice in order to play it. //The following code forces the host to select the same song twice in order to play it.
if (strcmp(CurrentSongInfo.title, LastSongInfo.title) == 0) if ((strcmp(CurrentSongInfo.title, LastSongInfo.title) == 0) &&
if (strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0) (strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0) &&
if (strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0) (strcmp(CurrentSongInfo.subtitle, LastSongInfo.subtitle) == 0))
SecondSameSelect = true; SecondSameSelect = true;
if (!SecondSameSelect) if (!SecondSameSelect)
@@ -761,8 +770,7 @@ void StepManiaLanServer::ClientsSongSelectStart()
//Only send data to clients currently in ScreenNetMusicSelect that use hasSong //Only send data to clients currently in ScreenNetMusicSelect that use hasSong
for (unsigned int x = 0; x < Client.size(); ++x) for (unsigned int x = 0; x < Client.size(); ++x)
if (Client[x]->inNetMusicSelect) if (Client[x]->inNetMusicSelect && Client[x]->hasSong)
if (Client[x]->hasSong)
{ {
SendNetPacket(x, Reply); SendNetPacket(x, Reply);
//Designate the client is starting, //Designate the client is starting,
@@ -774,8 +782,7 @@ void StepManiaLanServer::ClientsSongSelectStart()
bool StepManiaLanServer::CheckHasSongState() bool StepManiaLanServer::CheckHasSongState()
{ {
for (unsigned int x = 0; x < Client.size(); ++x) for (unsigned int x = 0; x < Client.size(); ++x)
if (Client[x]->inNetMusicSelect) if (Client[x]->inNetMusicSelect && !Client[x]->hasSong)
if (!Client[x]->hasSong)
return false; return false;
return true; return true;
@@ -893,9 +900,8 @@ CString StepManiaLanServer::ListPlayers()
void StepManiaLanServer::Kick(CString &name) void StepManiaLanServer::Kick(CString &name)
{ {
bool kicked; bool kicked = false;
for (unsigned int x = 0; x < Client.size(); ++x) { for (unsigned int x = 0; x < Client.size(); ++x)
kicked = false;
for (int y = 0; (y < 2)&&(kicked == false); ++y) for (int y = 0; (y < 2)&&(kicked == false); ++y)
if (name == Client[x]->Player[y].name) if (name == Client[x]->Player[y].name)
{ {
@@ -904,13 +910,11 @@ void StepManiaLanServer::Kick(CString &name)
kicked = true; kicked = true;
} }
} }
}
void StepManiaLanServer::Ban(CString &name) void StepManiaLanServer::Ban(CString &name)
{ {
bool kicked; bool kicked = false;
for (unsigned int x = 0; x < Client.size(); ++x) { for (unsigned int x = 0; x < Client.size(); ++x)
kicked = false;
for (int y = 0; (y < 2)&&(kicked == false); ++y) for (int y = 0; (y < 2)&&(kicked == false); ++y)
if (name == Client[x]->Player[y].name) if (name == Client[x]->Player[y].name)
{ {
@@ -920,7 +924,6 @@ void StepManiaLanServer::Ban(CString &name)
kicked = true; kicked = true;
} }
} }
}
bool StepManiaLanServer::IsBanned(CString &ip) bool StepManiaLanServer::IsBanned(CString &ip)
{ {
@@ -945,8 +948,7 @@ void StepManiaLanServer::ForceStart()
//Only send force_start data to clients currently in ScreenNetMusicSelect using forceHas //Only send force_start data to clients currently in ScreenNetMusicSelect using forceHas
for (unsigned int x = 0; x < Client.size(); ++x) for (unsigned int x = 0; x < Client.size(); ++x)
if (Client[x]->inNetMusicSelect) if (Client[x]->inNetMusicSelect && Client[x]->forceHas)
if(Client[x]->forceHas)
{ {
SendNetPacket(x, Reply); SendNetPacket(x, Reply);
//Designate the client is starting, //Designate the client is starting,