← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1826744-lobby-commands into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1826744-lobby-commands into lp:widelands.

Commit message:
Adding support for /warn and /kick commands of superusers in the internet gaming lobby.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1826744 in widelands: "Implement lobby commands"
  https://bugs.launchpad.net/widelands/+bug/1826744

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1826744-lobby-commands/+merge/368285

/warn is sending a system message to a single user.
/kick is banning the IP of the user for 24 hours to avoid immediate reconnects.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1826744-lobby-commands into lp:widelands.
=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc	2019-06-02 09:29:59 +0000
+++ src/network/internet_gaming.cc	2019-06-03 19:31:05 +0000
@@ -459,14 +459,15 @@
 			return;
 
 		} else if (cmd == IGPCMD_ERROR) {
-			std::string errortype = packet.string();
+			const std::string errortype = packet.string();
 			if (errortype != IGPCMD_LOGIN && errortype != IGPCMD_PWD_CHALLENGE) {
 				log("InternetGaming: Strange ERROR in connecting state: %s\n", errortype.c_str());
 				throw WLWarning(
 				   _("Mixed up"), _("The metaserver sent a strange ERROR during connection"));
 			}
 			// Clients login request got rejected
-			logout(packet.string());
+			const std::string message = packet.string();
+			logout(message);
 			set_error();
 			return;
 
@@ -682,6 +683,14 @@
 				}
 			}
 
+			else if (subcmd == IGPCMD_CMD) {
+				// Something went wrong with the command
+				message += _("Command could not be executed.");
+				message =
+				   (boost::format("%s %s") % message % InternetGamingMessages::get_message(reason))
+					  .str();
+			}
+
 			else if (subcmd == IGPCMD_GAME_OPEN) {
 				// Something went wrong with the newly opened game
 				message = InternetGamingMessages::get_message(reason);
@@ -901,6 +910,15 @@
 		// beginning
 		// with a "/" - let's see...
 
+		if (msg == "/help") {
+			format_and_add_chat("", "", true, _("Supported admin commands:"));
+			format_and_add_chat("", "", true, _("/motd <msg>  sets a permanent greeting message"));
+			format_and_add_chat("", "", true, _("/announcement <msg>  send a one time system message"));
+			format_and_add_chat("", "", true, _("/warn <user> <msg>  send a private system message to the given user"));
+			format_and_add_chat("", "", true, _("/kick <user|game>  removes the given user or game from the metaserver"));
+			return;
+		}
+
 		// Split up in "cmd" "arg"
 		std::string cmd, arg;
 		std::string temp = msg.substr(1);  // cut off '/'
@@ -944,6 +962,15 @@
 			m.string(arg);
 			net->send(m);
 			return;
+		} else if (!arg.empty() && (cmd == "warn" || cmd == "kick")) {
+			// warn a user by sending a private system message or
+			// kick a user or game from the metaserver
+			SendPacket m;
+			m.string(IGPCMD_CMD);
+			m.string(cmd);
+			m.string(arg);
+			net->send(m);
+			return;
 		} else {
 			// let everything else pass
 			goto normal;

=== modified file 'src/network/internet_gaming_protocol.h'
--- src/network/internet_gaming_protocol.h	2019-06-01 16:31:13 +0000
+++ src/network/internet_gaming_protocol.h	2019-06-03 19:31:05 +0000
@@ -299,6 +299,15 @@
 static const std::string IGPCMD_CHAT = "CHAT";
 
 /**
+ * Sent by the client to issue a superuser command.
+ *
+ * The client sends this message to the metaserver with the following payload:
+ * \li string:    the command
+ * \li string:    arbitrary parameters.
+ */
+static const std::string IGPCMD_CMD = "CMD";
+
+/**
  * Sent by the metaserver to inform the client, that the list of games was changed. No payload is
  * sent,
  * as e.g. clients in a game are not really interested about other games and we want to keep traffic


Follow ups