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
+72 -70
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,9 +94,8 @@ 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);
} }
GameClient::GameClient() GameClient::GameClient()
@@ -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,12 +131,13 @@ 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;
} }
} }
SendUserList (); SendUserList();
} }
int GameClient::GetData(PacketFunctions& Packet) int GameClient::GetData(PacketFunctions& Packet)
@@ -274,17 +279,14 @@ void StepManiaLanServer::CheckReady()
unsigned int x; unsigned int x;
//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) canStart = true;
if (Client[x]->GotStartRequest)
canStart = true;
} }
if (canStart) if (canStart)
@@ -308,13 +310,11 @@ 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]->GotStartRequest = false;
Client[x]->clientSocket.blocking = true; }
Client[x]->GotStartRequest = false;
}
} }
//Start clients waiting for a start between ScreenNetMusicSelect and the game. //Start clients waiting for a start between ScreenNetMusicSelect and the game.
@@ -324,9 +324,8 @@ 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);
} }
for (x = 0; x < Client.size(); ++x) for (x = 0; x < Client.size(); ++x)
@@ -345,24 +344,22 @@ 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) Client[x]->isStarting = false;
{ Client[x]->InGame = true;
Client[x]->isStarting = false; Client[x]->lowerJudge = false;
Client[x]->InGame = true; //After we start the clients, clear each client's hasSong.
Client[x]->lowerJudge = false; Client[x]->hasSong = false;
//After we start the clients, clear each client's hasSong.
Client[x]->hasSong = false;
}
Client[x]->clientSocket.blocking = false;
} }
Client[x]->clientSocket.blocking = false;
}
} }
} }
} }
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,10 +380,9 @@ 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;
SortStats(playersPtr); SortStats(playersPtr);
Reply.ClearPacket(); Reply.ClearPacket();
@@ -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)
@@ -637,6 +645,7 @@ void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int
Reply.WriteNT("You do not have permission to use server commands."); Reply.WriteNT("You do not have permission to use server commands.");
SendNetPacket(clientNum, Reply); SendNetPacket(clientNum, Reply);
} }
}
} }
else else
RelayChat(message, clientNum); RelayChat(message, clientNum);
@@ -690,10 +699,10 @@ 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,22 +770,20 @@ 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, //after ScreenNetMusicSelect but before game play (InGame).
//after ScreenNetMusicSelect but before game play (InGame). Client[x]->isStarting = true;
Client[x]->isStarting = true; }
}
} }
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)
{ {
@@ -903,14 +909,12 @@ void StepManiaLanServer::Kick(CString &name)
Disconnect(x); Disconnect(x);
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)
{ {
@@ -919,7 +923,6 @@ void StepManiaLanServer::Ban(CString &name)
Disconnect(x); Disconnect(x);
kicked = true; kicked = true;
} }
}
} }
bool StepManiaLanServer::IsBanned(CString &ip) bool StepManiaLanServer::IsBanned(CString &ip)
@@ -945,14 +948,13 @@ 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, //after ScreenNetMusicSelect but before game play (InGame).
//after ScreenNetMusicSelect but before game play (InGame). Client[x]->isStarting = true;
Client[x]->isStarting = true; }
}
} }
void StepManiaLanServer::ResetLastSongInfo() void StepManiaLanServer::ResetLastSongInfo()