Added server commands (/list, etc...)
This commit is contained in:
@@ -62,7 +62,8 @@ bool StepManiaLanServer::ServerStart()
|
|||||||
|
|
||||||
void StepManiaLanServer::ServerStop()
|
void StepManiaLanServer::ServerStop()
|
||||||
{
|
{
|
||||||
for (int x = 0; x < NUMBERCLIENTS; ++x) {
|
for (int x = 0; x < NUMBERCLIENTS; ++x)
|
||||||
|
{
|
||||||
Client[x].clientSocket.close();
|
Client[x].clientSocket.close();
|
||||||
Client[x].Used = false;
|
Client[x].Used = false;
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,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 (int x = 0; x < NUMBERCLIENTS; x++)
|
for (int x = 0; x < NUMBERCLIENTS; ++x)
|
||||||
if (Client[x].Used == 1)
|
if (Client[x].Used == 1)
|
||||||
if (Client[x].GetData(Packet) >= 0)
|
if (Client[x].GetData(Packet) >= 0)
|
||||||
ParseData(Packet, x);
|
ParseData(Packet, x);
|
||||||
@@ -111,6 +112,12 @@ GameClient::GameClient()
|
|||||||
wasIngame = false;
|
wasIngame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameClient::Disconnect()
|
||||||
|
{
|
||||||
|
clientSocket.close();
|
||||||
|
GameClient();
|
||||||
|
}
|
||||||
|
|
||||||
int GameClient::GetData(PacketFunctions& Packet)
|
int GameClient::GetData(PacketFunctions& Packet)
|
||||||
{
|
{
|
||||||
int length = -1;
|
int length = -1;
|
||||||
@@ -156,7 +163,7 @@ void StepManiaLanServer::ParseData(PacketFunctions& Packet, int clientNum)
|
|||||||
break;
|
break;
|
||||||
case NSCCM:
|
case NSCCM:
|
||||||
// Chat message
|
// Chat message
|
||||||
RelayChat(Packet, clientNum);
|
AnalizeChat(Packet, clientNum);
|
||||||
break;
|
break;
|
||||||
case NSCRSG:
|
case NSCRSG:
|
||||||
SelectSong(Packet, clientNum);
|
SelectSong(Packet, clientNum);
|
||||||
@@ -197,7 +204,7 @@ void GameClient::StyleUpdate(PacketFunctions& Packet)
|
|||||||
int playernumber = 0;
|
int playernumber = 0;
|
||||||
Player[0].name = Player[1].name = "";
|
Player[0].name = Player[1].name = "";
|
||||||
twoPlayers = Packet.Read1()-1;
|
twoPlayers = Packet.Read1()-1;
|
||||||
for (int x = 0; x < twoPlayers+1; x++)
|
for (int x = 0; x < twoPlayers+1; ++x)
|
||||||
{
|
{
|
||||||
playernumber = Packet.Read1();
|
playernumber = Packet.Read1();
|
||||||
Player[playernumber].name = Packet.ReadNT();
|
Player[playernumber].name = Packet.ReadNT();
|
||||||
@@ -510,6 +517,9 @@ void StepManiaLanServer::NewClientCheck()
|
|||||||
if (server.accept(Client[CurrentEmptyClient].clientSocket) == 1)
|
if (server.accept(Client[CurrentEmptyClient].clientSocket) == 1)
|
||||||
Client[CurrentEmptyClient].Used = 1;
|
Client[CurrentEmptyClient].Used = 1;
|
||||||
|
|
||||||
|
if (IsBanned(Client[CurrentEmptyClient].clientSocket.GetIn_addr()))
|
||||||
|
Client[CurrentEmptyClient].Disconnect();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepManiaLanServer::SendValue(uint8_t value, int clientNum)
|
void StepManiaLanServer::SendValue(uint8_t value, int clientNum)
|
||||||
@@ -517,7 +527,58 @@ void StepManiaLanServer::SendValue(uint8_t value, int clientNum)
|
|||||||
Client[clientNum].clientSocket.SendPack((char*)&value, sizeof(uint8_t));
|
Client[clientNum].clientSocket.SendPack((char*)&value, sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepManiaLanServer::RelayChat(PacketFunctions& Packet, int clientNum)
|
void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, int clientNum)
|
||||||
|
{
|
||||||
|
CString message = Packet.ReadNT();
|
||||||
|
char firstc = message.at(0);
|
||||||
|
if (message.at(0) == '/')
|
||||||
|
{
|
||||||
|
CString 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
|
||||||
|
Client[clientNum].hasSong = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (clientNum == 0)
|
||||||
|
{
|
||||||
|
if (command.compare("force_start") == 0)
|
||||||
|
ForceStart();
|
||||||
|
if (command.compare("kick") == 0)
|
||||||
|
{
|
||||||
|
CString name = message.substr(message.find(" ")+1);
|
||||||
|
Kick(name);
|
||||||
|
}
|
||||||
|
if (command.compare("ban") == 0)
|
||||||
|
{
|
||||||
|
CString 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((CString&)message, clientNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StepManiaLanServer::RelayChat(CString &passedmessage, int clientNum)
|
||||||
{
|
{
|
||||||
Reply.ClearPacket();
|
Reply.ClearPacket();
|
||||||
CString message = "";
|
CString message = "";
|
||||||
@@ -530,7 +591,7 @@ void StepManiaLanServer::RelayChat(PacketFunctions& Packet, int clientNum)
|
|||||||
message += Client[clientNum].Player[1].name;
|
message += Client[clientNum].Player[1].name;
|
||||||
|
|
||||||
message += ": ";
|
message += ": ";
|
||||||
message += Packet.ReadNT();
|
message += passedmessage;
|
||||||
Reply.Write1(NSCCM + NSServerOffset);
|
Reply.Write1(NSCCM + NSServerOffset);
|
||||||
Reply.WriteNT(message);
|
Reply.WriteNT(message);
|
||||||
|
|
||||||
@@ -577,9 +638,8 @@ void StepManiaLanServer::SelectSong(PacketFunctions& Packet, int clientNum)
|
|||||||
LastSongInfo.title = CurrentSongInfo.title;
|
LastSongInfo.title = CurrentSongInfo.title;
|
||||||
LastSongInfo.artist = CurrentSongInfo.artist;
|
LastSongInfo.artist = CurrentSongInfo.artist;
|
||||||
LastSongInfo.subtitle = CurrentSongInfo.subtitle;
|
LastSongInfo.subtitle = CurrentSongInfo.subtitle;
|
||||||
message = servername;
|
message = "Play \"";
|
||||||
message += ":Play \"";
|
message += CurrentSongInfo.title + " " + CurrentSongInfo.subtitle;
|
||||||
message += CurrentSongInfo.title;
|
|
||||||
message += "\"?";
|
message += "\"?";
|
||||||
ServerChat(message);
|
ServerChat(message);
|
||||||
}
|
}
|
||||||
@@ -600,9 +660,7 @@ void StepManiaLanServer::SelectSong(PacketFunctions& Packet, int clientNum)
|
|||||||
{
|
{
|
||||||
//If user dosn't have song
|
//If user dosn't have song
|
||||||
Client[clientNum].hasSong = false;
|
Client[clientNum].hasSong = false;
|
||||||
message = servername;
|
message = Client[clientNum].Player[0].name;
|
||||||
message += ": ";
|
|
||||||
message += Client[clientNum].Player[0].name;
|
|
||||||
|
|
||||||
if (Client[clientNum].twoPlayers)
|
if (Client[clientNum].twoPlayers)
|
||||||
{
|
{
|
||||||
@@ -636,7 +694,7 @@ void StepManiaLanServer::SelectSong(PacketFunctions& Packet, int clientNum)
|
|||||||
LastSongInfo.subtitle = "";
|
LastSongInfo.subtitle = "";
|
||||||
|
|
||||||
//Only send data to clients currently in ScreenNetMusicSelect
|
//Only send data to clients currently in ScreenNetMusicSelect
|
||||||
for (int x = 0; x < NUMBERCLIENTS; x++)
|
for (int x = 0; x < NUMBERCLIENTS; ++x)
|
||||||
if (Client[x].inNetMusicSelect)
|
if (Client[x].inNetMusicSelect)
|
||||||
{
|
{
|
||||||
SendNetPacket(x, Reply);
|
SendNetPacket(x, Reply);
|
||||||
@@ -676,9 +734,10 @@ void StepManiaLanServer::SendToAllClients(PacketFunctions& Packet)
|
|||||||
}
|
}
|
||||||
void StepManiaLanServer::ServerChat(const CString& message)
|
void StepManiaLanServer::ServerChat(const CString& message)
|
||||||
{
|
{
|
||||||
|
CString x = servername + ": " + message;
|
||||||
Reply.ClearPacket();
|
Reply.ClearPacket();
|
||||||
Reply.Write1(NSCCM + NSServerOffset);
|
Reply.Write1(NSCCM + NSServerOffset);
|
||||||
Reply.WriteNT(message);
|
Reply.WriteNT(x);
|
||||||
SendToAllClients(Reply);
|
SendToAllClients(Reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,8 +797,7 @@ void StepManiaLanServer::SendUserList()
|
|||||||
|
|
||||||
void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, int clientNum)
|
void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, int clientNum)
|
||||||
{
|
{
|
||||||
CString message = servername;
|
CString message = "";
|
||||||
message += ": ";
|
|
||||||
int EntExitCode = Packet.Read1();
|
int EntExitCode = Packet.Read1();
|
||||||
|
|
||||||
message += Client[clientNum].Player[0].name;
|
message += Client[clientNum].Player[0].name;
|
||||||
@@ -769,8 +827,77 @@ void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, int
|
|||||||
}
|
}
|
||||||
ServerChat(message);
|
ServerChat(message);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
CString StepManiaLanServer::ListPlayers()
|
||||||
|
{
|
||||||
|
CString list= "Player List:\n";
|
||||||
|
for (int x = 0; x < NUMBERCLIENTS; ++x)
|
||||||
|
if ((Client[x].Used)&&(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(CString &name)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < NUMBERCLIENTS; ++x)
|
||||||
|
if (Client[x].Used)
|
||||||
|
for (int y = 0; y < 2; ++y)
|
||||||
|
if (name == Client[x].Player[y].name)
|
||||||
|
{
|
||||||
|
ServerChat("Kicked " + name + ".");
|
||||||
|
Client[x].Disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StepManiaLanServer::Ban(CString &name)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < NUMBERCLIENTS; ++x)
|
||||||
|
if (Client[x].Used)
|
||||||
|
for (int y = 0; y < 2; y++)
|
||||||
|
if (name == Client[x].Player[y].name)
|
||||||
|
{
|
||||||
|
ServerChat("Banned " + name + ".");
|
||||||
|
bannedIPs.push_back(Client[x].clientSocket.GetIn_addr());
|
||||||
|
Client[x].Disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StepManiaLanServer::IsBanned(in_addr &ip)
|
||||||
|
{
|
||||||
|
for (unsigned int x = 0; x < bannedIPs.size(); ++x)
|
||||||
|
if (ip.S_un.S_addr == bannedIPs[x].S_un.S_addr)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StepManiaLanServer::ForceStart()
|
||||||
|
{
|
||||||
|
Reply.ClearPacket();
|
||||||
|
Reply.Write1(NSCRSG + NSServerOffset);
|
||||||
|
Reply.Write1(2);
|
||||||
|
Reply.WriteNT(CurrentSongInfo.title);
|
||||||
|
Reply.WriteNT(CurrentSongInfo.artist);
|
||||||
|
Reply.WriteNT(CurrentSongInfo.subtitle);
|
||||||
|
|
||||||
|
//Reset last song in case host picks same song again (otherwise dual select is bypassed)
|
||||||
|
LastSongInfo.title = "";
|
||||||
|
LastSongInfo.artist = "";
|
||||||
|
LastSongInfo.subtitle = "";
|
||||||
|
|
||||||
|
//Only send data to clients currently in ScreenNetMusicSelect
|
||||||
|
for (int x = 0; x < NUMBERCLIENTS; ++x)
|
||||||
|
if (Client[x].inNetMusicSelect)
|
||||||
|
if(Client[x].hasSong)
|
||||||
|
{
|
||||||
|
SendNetPacket(x, Reply);
|
||||||
|
//Designate the client is starting,
|
||||||
|
//after ScreenNetMusicSelect but before game play (InGame).
|
||||||
|
Client[x].isStarting = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* (c) 2003-2004 Joshua Allen
|
* (c) 2003-2004 Joshua Allen
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
class LanPlayer
|
class LanPlayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
string name;
|
CString name;
|
||||||
long score;
|
long score;
|
||||||
int health;
|
int health;
|
||||||
int feet;
|
int feet;
|
||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
int offset;
|
int offset;
|
||||||
int PlayerID;
|
int PlayerID;
|
||||||
int diff;
|
int diff;
|
||||||
string options;
|
CString options;
|
||||||
LanPlayer();
|
LanPlayer();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ public:
|
|||||||
void CheckConnection();
|
void CheckConnection();
|
||||||
bool IsPlaying(int Player);
|
bool IsPlaying(int Player);
|
||||||
void StyleUpdate(PacketFunctions &Packet);
|
void StyleUpdate(PacketFunctions &Packet);
|
||||||
|
void Disconnect();
|
||||||
bool InGame;
|
bool InGame;
|
||||||
int twoPlayers;
|
int twoPlayers;
|
||||||
bool hasSong;
|
bool hasSong;
|
||||||
@@ -95,6 +96,7 @@ private:
|
|||||||
bool StatsNameChange;
|
bool StatsNameChange;
|
||||||
bool SecondSameSelect;
|
bool SecondSameSelect;
|
||||||
int numPlayers;
|
int numPlayers;
|
||||||
|
vector<in_addr> bannedIPs;
|
||||||
|
|
||||||
void Hello(PacketFunctions& Packet, int clientNum);
|
void Hello(PacketFunctions& Packet, int clientNum);
|
||||||
void UpdateClients();
|
void UpdateClients();
|
||||||
@@ -111,7 +113,7 @@ private:
|
|||||||
void StatsNameColumn(PacketFunctions& data, LanPlayer *playersPtr[], int numPlayers);
|
void StatsNameColumn(PacketFunctions& data, LanPlayer *playersPtr[], int numPlayers);
|
||||||
void SendNetPacket(int client, PacketFunctions &Packet);
|
void SendNetPacket(int client, PacketFunctions &Packet);
|
||||||
int SortStats(LanPlayer *playersPtr[]);
|
int SortStats(LanPlayer *playersPtr[]);
|
||||||
void RelayChat(PacketFunctions& Packet, int clientNum);
|
void RelayChat(CString &passedmessage, int clientNum);
|
||||||
void SelectSong(PacketFunctions& Packet, int clientNum);
|
void SelectSong(PacketFunctions& Packet, int clientNum);
|
||||||
void ServerChat(const CString& message);
|
void ServerChat(const CString& message);
|
||||||
void SendToAllClients(PacketFunctions& Packet);
|
void SendToAllClients(PacketFunctions& Packet);
|
||||||
@@ -121,11 +123,18 @@ private:
|
|||||||
void SendUserList();
|
void SendUserList();
|
||||||
void GameOver(PacketFunctions& Packet, int clientNum);
|
void GameOver(PacketFunctions& Packet, int clientNum);
|
||||||
void ScreenNetMusicSelectStatus(PacketFunctions& Packet, int clientNum);
|
void ScreenNetMusicSelectStatus(PacketFunctions& Packet, int clientNum);
|
||||||
#endif
|
void AnalizeChat(PacketFunctions &Packet, int clientNum);
|
||||||
|
CString StepManiaLanServer::ListPlayers();
|
||||||
|
void Kick(CString &name);
|
||||||
|
void Ban(CString &name);
|
||||||
|
bool IsBanned(in_addr &ip);
|
||||||
|
void ForceStart();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) 2003-2004 Joshua Allen
|
* (c) 2003-2004 Joshua Allen
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
Reference in New Issue
Block a user