Improved handling of new clients.

This commit is contained in:
Josh Allen
2004-09-19 03:36:28 +00:00
parent 7573856a99
commit 5561f6a39d
+14 -29
View File
@@ -113,14 +113,15 @@ GameClient::GameClient()
void StepManiaLanServer::Disconnect(const unsigned int clientNum) void StepManiaLanServer::Disconnect(const unsigned int clientNum)
{ {
vector<GameClient*>::iterator Iterator;
Iterator = Client.begin();
if (clientNum == (Client.size()-1)) if (clientNum == (Client.size()-1))
{ {
delete Client[clientNum]; delete Client[Client.size()-1];
Client.pop_back(); Client.pop_back();
} }
else else
{
vector<GameClient*>::iterator Iterator;
Iterator = Client.begin();
for (unsigned int x = 0; x < Client.size(); ++x) for (unsigned int x = 0; x < Client.size(); ++x)
{ {
if (x == clientNum) if (x == clientNum)
@@ -128,7 +129,8 @@ void StepManiaLanServer::Disconnect(const unsigned int clientNum)
delete Client[x]; delete Client[x];
Client.erase(Iterator); Client.erase(Iterator);
} }
Iterator++; ++Iterator;
}
} }
} }
@@ -383,8 +385,6 @@ void StepManiaLanServer::AssignPlayerIDs()
} }
void StepManiaLanServer::PopulatePlayersPtr(vector<LanPlayer*> &playersPtr) { void StepManiaLanServer::PopulatePlayersPtr(vector<LanPlayer*> &playersPtr) {
// for (unsigned int x = 0; x < Client.size(); ++x)
// delete playersPtr[x];
playersPtr.clear(); playersPtr.clear();
@@ -393,11 +393,7 @@ void StepManiaLanServer::PopulatePlayersPtr(vector<LanPlayer*> &playersPtr) {
if (Client[x]->InGame||Client[x]->wasIngame) if (Client[x]->InGame||Client[x]->wasIngame)
for (int y = 0; y < 2; ++y) for (int y = 0; y < 2; ++y)
if (Client[x]->IsPlaying(y)) if (Client[x]->IsPlaying(y))
{
// playersPtr.push_back(new LanPlayer);
// playersPtr[playersPtr.size()-1] = &Client[x]->Player[y];
playersPtr.push_back(&Client[x]->Player[y]); playersPtr.push_back(&Client[x]->Player[y]);
}
} }
int StepManiaLanServer::SortStats(vector<LanPlayer*> &playersPtr) int StepManiaLanServer::SortStats(vector<LanPlayer*> &playersPtr)
@@ -407,7 +403,6 @@ int StepManiaLanServer::SortStats(vector<LanPlayer*> &playersPtr)
PopulatePlayersPtr(playersPtr); PopulatePlayersPtr(playersPtr);
do do
{ {
isChanged = false; isChanged = false;
@@ -481,7 +476,6 @@ void StepManiaLanServer::SendNetPacket(const unsigned int client, PacketFunction
void StepManiaLanServer::StatsNameColumn(PacketFunctions &data, vector<LanPlayer*> &playresPtr) void StepManiaLanServer::StatsNameColumn(PacketFunctions &data, vector<LanPlayer*> &playresPtr)
{ {
CString numname;
for (unsigned int x = 0; x < playersPtr.size(); ++x) for (unsigned int x = 0; x < playersPtr.size(); ++x)
data.Write1( (uint8_t) playersPtr[x]->PlayerID ); data.Write1( (uint8_t) playersPtr[x]->PlayerID );
} }
@@ -530,23 +524,20 @@ void GameClient::UpdateStats(PacketFunctions& Packet)
void StepManiaLanServer::NewClientCheck() void StepManiaLanServer::NewClientCheck()
{ {
//Make a new client and accept a connection to it. //Make a new client and accept a connection to it.
// no connection is accepted, delete the client. //If no connection is accepted, delete the client.
Client.push_back(new GameClient); GameClient *tmp = new GameClient;
if (server.accept(Client[Client.size()-1]->clientSocket) == 1) if (server.accept(tmp->clientSocket) == 1)
if (!IsBanned(tmp->clientSocket.address))
{ {
Client.push_back(tmp);
AssignPlayerIDs(); AssignPlayerIDs();
if (IsBanned(Client[Client.size()-1]->clientSocket.address))
{
Disconnect(Client.size()-1);
}
} }
else else
{ delete tmp;
Disconnect(Client.size()-1); else
} delete tmp;
} }
void StepManiaLanServer::SendValue(uint8_t value, const unsigned int clientNum) void StepManiaLanServer::SendValue(uint8_t value, const unsigned int clientNum)
@@ -561,7 +552,6 @@ 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();
@@ -580,9 +570,7 @@ 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)
@@ -606,11 +594,8 @@ void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int
SendNetPacket(clientNum, Reply); SendNetPacket(clientNum, Reply);
} }
} }
}
else else
{
RelayChat(message, clientNum); RelayChat(message, clientNum);
}
} }
void StepManiaLanServer::RelayChat(CString &passedmessage, const unsigned int clientNum) void StepManiaLanServer::RelayChat(CString &passedmessage, const unsigned int clientNum)