Quellcode durchsuchen

status output contains username and ip:port

Denys vor 5 Jahren
Ursprung
Commit
ddb15a138d
5 geänderte Dateien mit 25 neuen und 12 gelöschten Zeilen
  1. 1 1
      cli/README.md
  2. 6 0
      cli/include/cmdman.h
  3. 1 1
      cli/src/batchioman.cpp
  4. 16 9
      cli/src/cmdman.cpp
  5. 1 1
      cli/src/userioman.cpp

+ 1 - 1
cli/README.md

@@ -47,7 +47,7 @@ The following commands can be sent when the user is connected to a server.
 
 
 `status`: <br/>
-Shows wether a file transfer between server and client is running.
+Shows username, ip and port and wether a file transfer between server and client is running.
 
 `extendedstatus`: <br/>
 Shows detailed information about ongoing transfers at the server.

+ 6 - 0
cli/include/cmdman.h

@@ -104,6 +104,12 @@ private:
 	vector<string> cmdAllowAlways = {"help", "keyfile", "closekey", "exit"};
 	vector<string> cmdAllowAfterConnect = {"login", "signup", "disconnect"};
 
+	/**
+	 * Fields used for status output.
+	 */
+	string username, ip;
+	unsigned int port;
+
 	/**
 	 * Help strings and method prototypes for commands to be used by a user
 	 */

+ 1 - 1
cli/src/batchioman.cpp

@@ -311,7 +311,7 @@ std::string BatchIoMan::printHelp(Json::Value root) {
 	return ret;
 }
 
-std::string BatchIoMan::printStatus(Json::Value root) { return std::string("Server reports status: ") + root["response"].asString(); }
+std::string BatchIoMan::printStatus(Json::Value root) { return root["response"].asString(); }
 
 std::string BatchIoMan::printExtendedstatus(Json::Value root) {
 	if (!root["accept"].asBool()) {

+ 16 - 9
cli/src/cmdman.cpp

@@ -394,14 +394,18 @@ CmdMan::CmdRet CmdMan::cmdConnect(vector<string> args) {
 	if (args.size() < 1) {
 		retval.type = error;
 		root["error"] = "not enough arguments, at least 1 argument required";
-	} else if (args.size() < 2) {
-		retval.type = connect;
-		root["address"] = args[0];
-		root["port"] = 1234;
 	} else {
+		// set internal ip and port fields first
+		ip = args[0];
+		if (args.size() < 2) {
+			port = 1234;
+		} else {
+			port = (unsigned int)stoul(args[1]);
+		}
+		// construct json
 		retval.type = connect;
-		root["address"] = args[0];
-		root["port"] = (unsigned int)stoul(args[1]);
+		root["address"] = ip;
+		root["port"] = port;
 	}
 	retval.msg = root;
 
@@ -574,7 +578,7 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
 	} else {
 		if (currentState == loginpossible) {
 			currentState = dologin;
-			root["user"] = args[0];
+			root["user"] = username = args[0];
 			root["pass"] = args[1];
 			root["login"] = true;
 			root["cancel"] = false;
@@ -605,7 +609,7 @@ CmdMan::CmdRet CmdMan::cmdSignup(vector<string> args) {
 	} else {
 		if (currentState == loginpossible) {
 			currentState = dosignup;
-			root["user"] = args[0];
+			root["user"] = username = args[0];
 			root["pass"] = args[1];
 			root["login"] = false;
 			root["cancel"] = false;
@@ -718,9 +722,12 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
 
 CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
 	CmdRet retval;
+	Json::Value output;
 	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
 	retval.type = print;
-	retval.msg = root;
+	output["command"] = "status";
+	output["response"] = username + "@" + ip + ":" + std::to_string(port) + " - Status: " + root["response"].asString();
+	retval.msg = output;
 
 	return retval;
 }

+ 1 - 1
cli/src/userioman.cpp

@@ -111,7 +111,7 @@ void UserIoMan::printHelp(Json::Value root) {
 		std::cout << i.asString() << std::endl;
 }
 
-void UserIoMan::printStatus(Json::Value root) { std::cout << "Server reports status: " << root["response"].asString() << std::endl; }
+void UserIoMan::printStatus(Json::Value root) { std::cout << root["response"].asString() << std::endl; }
 
 void UserIoMan::printExtendedstatus(Json::Value root) {