(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
authortruelight
Tue, 21 Dec 2004 17:31:10 +0000
changeset 748 fa61195ee8a8
parent 747 4bf34cf669d0
child 749 64499422315d
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
lang/english.txt
network_client.c
network_data.h
network_server.c
--- a/lang/english.txt	Tue Dec 21 17:12:20 2004 +0000
+++ b/lang/english.txt	Tue Dec 21 17:31:10 2004 +0000
@@ -1336,6 +1336,7 @@
 STR_NETWORK_ERR_WRONG_PASSWORD					:{WHITE} Wrong password
 STR_NETWORK_ERR_SERVER_FULL					:{WHITE} The server is full
 STR_NETWORK_ERR_KICKED						:{WHITE} You were kicked out of the game
+STR_NETWORK_ERR_CHEATER						:{WHITE} Cheating is not allowed on this server
 
 STR_NETWORK_ERR_LEFT						:has left the game
 ############ Leave those lines in this order!!
@@ -1351,6 +1352,7 @@
 STR_NETWORK_ERR_CLIENT_WRONG_PASSWORD				:wrong game-password
 STR_NETWORK_ERR_CLIENT_PLAYER_MISMATCH				:wrong player-id in DoCommand
 STR_NETWORK_ERR_CLIENT_KICKED					:kicked by server
+STR_NETWORK_ERR_CLIENT_CHEATER					:was trying to use a cheat
 ############ End of leave-in-this-order
 STR_NETWORK_CLIENT_JOINED					:has joined the game
 STR_NETWORK_GIVE_MONEY						:gave your company some money ({CURRENCY})
--- a/network_client.c	Tue Dec 21 17:12:20 2004 +0000
+++ b/network_client.c	Tue Dec 21 17:31:10 2004 +0000
@@ -377,6 +377,8 @@
 		_switch_mode_errorstr = STR_NETWORK_ERR_WRONG_PASSWORD;
 	} else if (error == NETWORK_ERROR_KICKED) {
 		_switch_mode_errorstr = STR_NETWORK_ERR_KICKED;
+	} else if (error == NETWORK_ERROR_CHEATER) {
+		_switch_mode_errorstr = STR_NETWORK_ERR_CHEATER;
 	}
 
 	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
--- a/network_data.h	Tue Dec 21 17:12:20 2004 +0000
+++ b/network_data.h	Tue Dec 21 17:31:10 2004 +0000
@@ -87,6 +87,7 @@
 	NETWORK_ERROR_WRONG_PASSWORD,
 	NETWORK_ERROR_PLAYER_MISMATCH, // Happens in CLIENT_COMMAND
 	NETWORK_ERROR_KICKED,
+	NETWORK_ERROR_CHEATER,
 } NetworkErrorCode;
 
 // Actions that can be used for NetworkTextMessage
--- a/network_server.c	Tue Dec 21 17:12:20 2004 +0000
+++ b/network_server.c	Tue Dec 21 17:31:10 2004 +0000
@@ -785,16 +785,29 @@
 		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
 		return;
 	}
-	if (cp->cmd == CMD_PLAYER_CTRL) {
-		if (cp->p1 == 0)
-			// UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl
-			cp->p2 = cs - _clients;
-		else {
-			/* We do NOT allow any client to send any PLAYER_CTRL packet..
-			    (they can delete random players with it if they like */
-			SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
-			return;
-		}
+	switch (cp->cmd) {
+		/* Player_ctrl is not always allowed */
+		case CMD_PLAYER_CTRL:
+		{
+			/* cp->p1 == 0, is allowed */
+			if (cp->p1 == 0) {
+				// UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl
+				cp->p2 = cs - _clients;
+			} else {
+			/* The rest are cheats */
+				SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER);
+				return;
+			}
+		} break;
+
+		/* Don't allow those commands if server == advertising (considered cheating) */
+		case CMD_MONEY_CHEAT:
+		{
+			if (_network_advertise) {
+				SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER);
+				return;
+			}
+		} break;
 	}