|
@@ -121,7 +121,15 @@ CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
Json::Value root;
|
|
Json::Value root;
|
|
root["command"] = "status";
|
|
root["command"] = "status";
|
|
- retval.type = send;
|
|
|
|
|
|
+ if (currentState == normal) {
|
|
|
|
+ retval.type = send;
|
|
|
|
+ } else if (currentState == connectionpossible || currentState == disconnecttoexit || currentState == disconnecttoexitearly) {
|
|
|
|
+ retval.type = print;
|
|
|
|
+ root["response"] = "You are not connected.";
|
|
|
|
+ } else {
|
|
|
|
+ retval.type = print;
|
|
|
|
+ root["response"] = "Connected to " + ip + ":" + std::to_string(port) + ". Not logged in.";
|
|
|
|
+ }
|
|
retval.msg = root;
|
|
retval.msg = root;
|
|
|
|
|
|
return retval;
|
|
return retval;
|
|
@@ -406,16 +414,19 @@ CmdMan::CmdRet CmdMan::cmdConnect(vector<string> args) {
|
|
retval.type = error;
|
|
retval.type = error;
|
|
root["command"] = "error"; // analogous to execute() method when command unavailable
|
|
root["command"] = "error"; // analogous to execute() method when command unavailable
|
|
root["error"] = "Connecting not possible, you are already connected to a server.";
|
|
root["error"] = "Connecting not possible, you are already connected to a server.";
|
|
- } else if (args.size() < 2) {
|
|
|
|
- retval.type = connect;
|
|
|
|
- root["command"] = "connect";
|
|
|
|
- root["address"] = args[0];
|
|
|
|
- root["port"] = 1234;
|
|
|
|
} else {
|
|
} 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;
|
|
retval.type = connect;
|
|
root["command"] = "connect";
|
|
root["command"] = "connect";
|
|
- root["address"] = args[0];
|
|
|
|
- root["port"] = (unsigned int)stoul(args[1]);
|
|
|
|
|
|
+ root["address"] = ip;
|
|
|
|
+ root["port"] = port;
|
|
}
|
|
}
|
|
retval.msg = root;
|
|
retval.msg = root;
|
|
|
|
|
|
@@ -485,7 +496,7 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
if (cmd.compare("version") && cmd.compare("connect")) {
|
|
if (cmd.compare("version") && cmd.compare("connect")) {
|
|
retval.type = error;
|
|
retval.type = error;
|
|
root["command"] = "error";
|
|
root["command"] = "error";
|
|
- root["error"] = string("Not connected. Connect using \"connect ip [port]\".");
|
|
|
|
|
|
+ root["error"] = "Not connected. Please connect.";
|
|
retval.msg = root;
|
|
retval.msg = root;
|
|
cmdmutex.unlock();
|
|
cmdmutex.unlock();
|
|
return retval;
|
|
return retval;
|
|
@@ -594,7 +605,7 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
} else {
|
|
} else {
|
|
if (currentState == loginpossible) {
|
|
if (currentState == loginpossible) {
|
|
currentState = dologin;
|
|
currentState = dologin;
|
|
- root["user"] = args[0];
|
|
|
|
|
|
+ root["user"] = username = args[0];
|
|
root["pass"] = args[1];
|
|
root["pass"] = args[1];
|
|
root["login"] = true;
|
|
root["login"] = true;
|
|
root["cancel"] = false;
|
|
root["cancel"] = false;
|
|
@@ -624,7 +635,7 @@ CmdMan::CmdRet CmdMan::cmdSignup(vector<string> args) {
|
|
} else {
|
|
} else {
|
|
if (currentState == loginpossible) {
|
|
if (currentState == loginpossible) {
|
|
currentState = dosignup;
|
|
currentState = dosignup;
|
|
- root["user"] = args[0];
|
|
|
|
|
|
+ root["user"] = username = args[0];
|
|
root["pass"] = args[1];
|
|
root["pass"] = args[1];
|
|
root["login"] = false;
|
|
root["login"] = false;
|
|
root["cancel"] = false;
|
|
root["cancel"] = false;
|
|
@@ -741,9 +752,12 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ Json::Value output;
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
retval.type = print;
|
|
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;
|
|
return retval;
|
|
}
|
|
}
|
|
@@ -814,7 +828,6 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
output["command"] = "putdata";
|
|
output["command"] = "putdata";
|
|
output["file"] = fileman.getPutName();
|
|
output["file"] = fileman.getPutName();
|
|
- output["speed"] = 0.0f; // TODO
|
|
|
|
output["cancel"] = true;
|
|
output["cancel"] = true;
|
|
|
|
|
|
if (root["cancel"].asBool()) {
|
|
if (root["cancel"].asBool()) {
|
|
@@ -843,8 +856,6 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
if (!root["received"].asInt()) {
|
|
if (!root["received"].asInt()) {
|
|
// everything sent
|
|
// everything sent
|
|
retval.type = print;
|
|
retval.type = print;
|
|
- // TODO
|
|
|
|
- //~ retval.msg = "succesfully uploaded file " + fileman.getPutName();
|
|
|
|
fileman.closePut();
|
|
fileman.closePut();
|
|
} else {
|
|
} else {
|
|
retval.type = print | send;
|
|
retval.type = print | send;
|
|
@@ -892,7 +903,6 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
output["command"] = "getdata";
|
|
output["command"] = "getdata";
|
|
output["file"] = fileman.getGetName();
|
|
output["file"] = fileman.getGetName();
|
|
- output["speed"] = 0.0f; // TODO
|
|
|
|
output["cancel"] = true;
|
|
output["cancel"] = true;
|
|
|
|
|
|
if (root["cancel"].asBool()) {
|
|
if (root["cancel"].asBool()) {
|
|
@@ -919,7 +929,6 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
|
|
if (!root["remaining"].asInt()) {
|
|
if (!root["remaining"].asInt()) {
|
|
// everything received
|
|
// everything received
|
|
retval.type = print;
|
|
retval.type = print;
|
|
- //~ retval.msg = "succesfully downloaded file " + fileman.getGetName();
|
|
|
|
fileman.closeGet();
|
|
fileman.closeGet();
|
|
} else {
|
|
} else {
|
|
retval.type = print | send;
|
|
retval.type = print | send;
|