about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorlogin (tilde.temm) <login@tilde.team>2020-02-21 23:27:27 -0500
committerlogin (tilde.temm) <login@tilde.team>2020-02-21 23:27:27 -0500
commit61355a43749cb5507792482e64f45ad5883580dd (patch)
tree10b7c85123eb43a3e54dd772d99d4297bfc52797
parent4f1c68ddeda50c5ed971650e4fc9981d019a2c72 (diff)
downloadtcoin-61355a43749cb5507792482e64f45ad5883580dd.tar.gz
Implemented message-character limits in tcoin.cpp and pcoin.cpp
After having received a 10000-character transaction message from ~jan6@envs.net,
I finally came around to implementing character limits on transaction messages.
Previously, I was of the opinion that one should be able to send a movie as a
transaction message if one so wished.
I took inspiration for an appropriate character limit from Australia's NPP (New
Payments Platform), which has a 280-character limit on transaction messages. I
strongly suspect this limit came from Twitter's analysis of tweets in different
languages and Twitter research that concluded that a 280-character tweet was the
appropriate length of tweet. A transaction message is supposedly like a tweet with
some money sent along with it.
-rw-r--r--pcoin.cpp30
-rw-r--r--tcoin.cpp30
2 files changed, 60 insertions, 0 deletions
diff --git a/pcoin.cpp b/pcoin.cpp
index 61a7945..a7d9baa 100644
--- a/pcoin.cpp
+++ b/pcoin.cpp
@@ -52,10 +52,12 @@
   #define MINERCOIN_CMD_POST_USERNAME "\": )[[:digit:]]+' /home/minerobber/Code/minerbot/minercoin.json"
 #endif
 #define USERNAME_LENGTH_LIMIT 25
+#define TCOIN_MSG_LENGTH 280
 
 #define ERR_MAIN_SEND_TOO_FEW_ARGS 6
 #define ERR_MAIN_SEND_TOO_MANY_ARGS 7
 #define ERR_SILENTSEND 2
+#define ERR_MAIN_MSG_TOO_LONG 19
 #define ERR_UNKNOWN_ARG 3
 #define ERR_TCOIN_TO_SELF 5
 #define ERR_RECEIVER_BLOCKED 4
@@ -1633,6 +1635,16 @@ int add_internal_balance(const char* username, const long long int value_to_add)
   return ERR_ADD_INTERNAL_BALANCE_USERNAME_DOESNT_EXIST;
 }
 
+bool message_is_long(const char* test_string)
+{
+  for(int i=0; i < TCOIN_MSG_LENGTH_LIMIT+1; ++i)
+    if(test_string[i] == '\0')
+    {
+      return false; //message is shorter than TCOIN_MSG_LENGTH_LIMIT characters
+    }
+  return true; //message is longer than TCOIN_MSG_LENGTH_LIMIT characters
+}
+
 int main(int argc, char *argv[])
 {
   if(argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "help") || !strcmp(argv[1], "-h")))
@@ -1861,6 +1873,12 @@ int main(int argc, char *argv[])
       else //argument count is 5 because a custom message was included
       {
         int return_value;
+        return_value = message_is_long(argv[4]);
+        if(return_value) //message is too long
+        {
+          std::cout << "\nSorry, the message was longer than " << TCOIN_MSG_LENGTH_LIMIT << " characters. Please keep messages at or below this limit.n\n";
+          return ERR_MAIN_MSG_TOO_LONG;
+        }
         if(is_number(argv[3]))
           return_value = send(get_username().c_str(), argv[2], strtol100(argv[3]), base_amount, "verbose");
         else
@@ -1880,6 +1898,12 @@ int main(int argc, char *argv[])
       if(!strcmp(argv[2], "-s"))
       { //argument count is 6 because of silent send with custom message included
         int return_value;
+        return_value = message_is_long(argv[5]);
+        if(return_value) //message is too long
+        {
+          std::cout << "\nSorry, the message was longer than " << TCOIN_MSG_LENGTH_LIMIT << " characters. Please keep messages at or below this limit.n\n";
+          return ERR_MAIN_MSG_TOO_LONG;
+        }
         if(is_number(argv[3]))
           return_value = send(get_username().c_str(), argv[4], strtol100(argv[3]), base_amount, "silent");
         else
@@ -1937,6 +1961,12 @@ int main(int argc, char *argv[])
     if(argc==5) //custom message included
     {
       int return_value;
+      return_value = message_is_long(argv[4]);
+      if(return_value) //message is too long
+      {
+        std::cout << "\nSorry, the message was longer than " << TCOIN_MSG_LENGTH_LIMIT << " characters. Please keep messages at or below this limit.n\n";
+        return ERR_MAIN_MSG_TOO_LONG;
+      }
       if(is_number(argv[2]))
         return_value = send(get_username().c_str(), argv[3], strtol100(argv[2]), base_amount, "silent");
       else
diff --git a/tcoin.cpp b/tcoin.cpp
index 5bf6faa..90bedec 100644
--- a/tcoin.cpp
+++ b/tcoin.cpp
@@ -47,6 +47,7 @@
   #define MINERCOIN_CMD_POST_USERNAME "\": )[[:digit:]]+' /home/minerobber/Code/minerbot/minercoin.json"
 #endif
 #define USERNAME_LENGTH_LIMIT 25
+#define TCOIN_MSG_LENGTH_LIMIT 280
 
 #define ERR_NO_INIT 4
 #define ERR_ALREADY_ON 40
@@ -59,6 +60,7 @@
 #define ERR_NOT_LOGGED_IN 5
 #define ERR_MAIN_SEND_TOO_FEW_ARGS 6
 #define ERR_MAIN_SEND_TOO_MANY_ARGS 7
+#define ERR_MAIN_MSG_TOO_LONG 19
 #define ERR_SILENTSEND 2
 #define ERR_UNKNOWN_ARG 3
 #define ERR_TCOIN_TO_SELF 5
@@ -1518,6 +1520,16 @@ bool is_number(const char* test_string)
     return *p == 0;
 }
 
+bool message_is_long(const char* test_string)
+{
+  for(int i=0; i < TCOIN_MSG_LENGTH_LIMIT+1; ++i)
+    if(test_string[i] == '\0')
+    {
+      return false; //message is shorter than TCOIN_MSG_LENGTH_LIMIT characters
+    }
+  return true; //message is longer than TCOIN_MSG_LENGTH_LIMIT characters
+}
+
 int main(int argc, char *argv[])
 {
   //sneaky scrypt magic (process overlaying to maintain suid)
@@ -1708,6 +1720,12 @@ int main(int argc, char *argv[])
       else //argument count is 5 because a custom message was included
       {
         int return_value;
+        return_value = message_is_long(argv[4]);
+        if(return_value) //message is too long
+        {
+          std::cout << "\nSorry, the message was longer than " << TCOIN_MSG_LENGTH_LIMIT << " characters. Please keep messages at or below this limit.n\n";
+          return ERR_MAIN_MSG_TOO_LONG;
+        }
         if(is_number(argv[2]))
           return_value = send(get_username().c_str(), argv[3], strtol100(argv[2]), base_amount, "verbose");
         else
@@ -1726,6 +1744,12 @@ int main(int argc, char *argv[])
       if(!strcmp(argv[2], "-s"))
       { //argument count is 6 because of silent send with custom message included
         int return_value;
+        return_value = message_is_long(argv[5]);
+        if(return_value) //message is too long
+        {
+          std::cout << "\nSorry, the message was longer than " << TCOIN_MSG_LENGTH_LIMIT << " characters. Please keep messages at or below this limit.n\n";
+          return ERR_MAIN_MSG_TOO_LONG;
+        }
         if(is_number(argv[3]))
           return_value = send(get_username().c_str(), argv[4], strtol100(argv[3]), base_amount, "silent");
         else
@@ -1785,6 +1809,12 @@ int main(int argc, char *argv[])
     if(argc==5) //custom message included
     {
       int return_value;
+      return_value = message_is_long(argv[4]);
+      if(return_value) //message is too long
+      {
+        std::cout << "\nSorry, the message was longer than " << TCOIN_MSG_LENGTH_LIMIT << " characters. Please keep messages at or below this limit.n\n";
+        return ERR_MAIN_MSG_TOO_LONG;
+      }
       if(is_number(argv[2]))
         return_value = send(get_username().c_str(), argv[3], strtol100(argv[2]), base_amount, "silent");
       else