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
+39 -37
View File
@@ -10,6 +10,7 @@ void StepManiaLanServer::ServerStop() { }
void StepManiaLanServer::ServerUpdate() { }
StepManiaLanServer::StepManiaLanServer() { }
StepManiaLanServer::~StepManiaLanServer() { }
bool StepManiaLanServer::IsBanned(in_addr &ip) {}
#else
LanPlayer::LanPlayer()
@@ -64,7 +65,10 @@ bool StepManiaLanServer::ServerStart()
void StepManiaLanServer::ServerStop()
{
for (unsigned int x = 0; x < Client.size(); ++x)
{
delete Client[x];
Client[x] = NULL;
}
Client.clear();
server.close();
@@ -90,8 +94,7 @@ 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))
if (Client[x]->GetData(Packet) >= 0)
if (CheckConnection(x) && (Client[x]->GetData(Packet) >= 0))
ParseData(Packet, x);
}
@@ -116,6 +119,7 @@ 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
@@ -127,12 +131,13 @@ void StepManiaLanServer::Disconnect(const unsigned int clientNum)
if (x == clientNum)
{
delete Client[x];
Client[x] = NULL;
Client.erase(Iterator);
}
++Iterator;
}
}
SendUserList ();
SendUserList();
}
int GameClient::GetData(PacketFunctions& Packet)
@@ -274,16 +279,13 @@ void StepManiaLanServer::CheckReady()
unsigned int x;
//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]->GotStartRequest)
if (Client[x]->isStarting && !Client[x]->GotStartRequest)
canStart = false;
//For Start for courses
if (Client[x]->inNetMusicSelect == false)
if (Client[x]->hasSong == false)
if (Client[x]->GotStartRequest)
//Start for courses
if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest)
canStart = true;
}
@@ -308,9 +310,7 @@ void StepManiaLanServer::CheckReady()
}
//For Start for courses
if (Client[x]->inNetMusicSelect == false)
if (Client[x]->hasSong == false)
if (Client[x]->GotStartRequest)
if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest)
{
Client[x]->clientSocket.blocking = true;
Client[x]->GotStartRequest = false;
@@ -324,8 +324,7 @@ void StepManiaLanServer::CheckReady()
SendValue(NSCGSR + NSServerOffset, x);
//For Start for courses
if (Client[x]->inNetMusicSelect == false)
if (Client[x]->hasSong == false)
if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong)
SendValue(NSCGSR + NSServerOffset, x);
}
@@ -345,8 +344,7 @@ void StepManiaLanServer::CheckReady()
}
//For Start for courses
if (Client[x]->inNetMusicSelect == false)
if (Client[x]->hasSong == false)
if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong)
{
if (Client[x]->startPosition == 1)
{
@@ -362,7 +360,6 @@ void StepManiaLanServer::CheckReady()
}
}
void StepManiaLanServer::GameOver(PacketFunctions& Packet, const unsigned int clientNum)
{
bool allOver = true;
@@ -383,8 +380,7 @@ void StepManiaLanServer::GameOver(PacketFunctions& Packet, const unsigned int cl
if (allOver)
{
for (x = 0; x < Client.size(); ++x)
if (Client[x]->wasIngame)
if (Client[x]->lowerJudge)
if (Client[x]->wasIngame && Client[x]->lowerJudge)
for (int y = 0; y < 2; ++y)
Client[x]->Player[y].options = "TIMING " + playersPtr[x]->options;
@@ -430,6 +426,9 @@ void StepManiaLanServer::AssignPlayerIDs()
void StepManiaLanServer::PopulatePlayersPtr(vector<LanPlayer*> &playersPtr) {
for (unsigned int x = 0; x < playersPtr.size(); ++x)
playersPtr[x] = NULL;
playersPtr.clear();
//Populate with in game players only
@@ -579,9 +578,15 @@ void StepManiaLanServer::NewClientCheck()
AssignPlayerIDs();
}
else
{
delete tmp;
tmp = NULL;
}
else
{
delete tmp;
tmp = NULL;
}
}
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);
if ((command.compare("list") == 0)||(command.compare("have") == 0))
{
if (command.compare("list") == 0)
{
Reply.ClearPacket();
@@ -614,7 +620,9 @@ void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int
Client[clientNum]->forceHas = true;
ServerChat(message);
}
}
else
{
if (clientNum == 0)
{
if (command.compare("force_start") == 0)
@@ -638,6 +646,7 @@ void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int
SendNetPacket(clientNum, Reply);
}
}
}
else
RelayChat(message, clientNum);
}
@@ -690,9 +699,9 @@ void StepManiaLanServer::SelectSong(PacketFunctions& Packet, unsigned int client
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)
if (strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0)
if (strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0)
if ((strcmp(CurrentSongInfo.title, LastSongInfo.title) == 0) &&
(strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0) &&
(strcmp(CurrentSongInfo.subtitle, LastSongInfo.subtitle) == 0))
SecondSameSelect = true;
if (!SecondSameSelect)
@@ -761,8 +770,7 @@ void StepManiaLanServer::ClientsSongSelectStart()
//Only send data to clients currently in ScreenNetMusicSelect that use hasSong
for (unsigned int x = 0; x < Client.size(); ++x)
if (Client[x]->inNetMusicSelect)
if (Client[x]->hasSong)
if (Client[x]->inNetMusicSelect && Client[x]->hasSong)
{
SendNetPacket(x, Reply);
//Designate the client is starting,
@@ -774,8 +782,7 @@ void StepManiaLanServer::ClientsSongSelectStart()
bool StepManiaLanServer::CheckHasSongState()
{
for (unsigned int x = 0; x < Client.size(); ++x)
if (Client[x]->inNetMusicSelect)
if (!Client[x]->hasSong)
if (Client[x]->inNetMusicSelect && !Client[x]->hasSong)
return false;
return true;
@@ -893,9 +900,8 @@ CString StepManiaLanServer::ListPlayers()
void StepManiaLanServer::Kick(CString &name)
{
bool kicked;
for (unsigned int x = 0; x < Client.size(); ++x) {
kicked = false;
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)
{
@@ -903,14 +909,12 @@ void StepManiaLanServer::Kick(CString &name)
Disconnect(x);
kicked = true;
}
}
}
void StepManiaLanServer::Ban(CString &name)
{
bool kicked;
for (unsigned int x = 0; x < Client.size(); ++x) {
kicked = false;
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)
{
@@ -919,7 +923,6 @@ void StepManiaLanServer::Ban(CString &name)
Disconnect(x);
kicked = true;
}
}
}
bool StepManiaLanServer::IsBanned(CString &ip)
@@ -945,8 +948,7 @@ void StepManiaLanServer::ForceStart()
//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)
if(Client[x]->forceHas)
if (Client[x]->inNetMusicSelect && Client[x]->forceHas)
{
SendNetPacket(x, Reply);
//Designate the client is starting,