about summary refs log tree commit diff stats
path: root/tcoin.cpp
diff options
context:
space:
mode:
authorlogin <login@tilde.team>2022-03-11 13:36:07 +0000
committerlogin <login@tilde.team>2022-03-11 13:36:07 +0000
commita7e69a46df485b55d84e15ae657aa3be354c991b (patch)
tree3489056ad2eefdc3d8e3f420183a193404fbfeda /tcoin.cpp
parent397d299c55e25676a85e648423c3439af998f61c (diff)
downloadtcoin-a7e69a46df485b55d84e15ae657aa3be354c991b.tar.gz
Adding jmjl's 'ju coin' to the balance
Adding jmjl's 'ju coin' (which is a copy of tildebot) to the tcoin and pcoin balance
Diffstat (limited to 'tcoin.cpp')
-rw-r--r--tcoin.cpp94
1 files changed, 59 insertions, 35 deletions
diff --git a/tcoin.cpp b/tcoin.cpp
index b8b7566..9876c60 100644
--- a/tcoin.cpp
+++ b/tcoin.cpp
@@ -37,8 +37,8 @@
 #define LS_HOME_CMD "/bin/ls /home"
 #define BIN_ECHO_CMD "/bin/echo $$"
 #ifndef KROWBAR_OFF
-  #define KROWBAR_SCORE_PATH_OLD "/home/krowbar/Code/irc/data/tildescores.txt"
-  #define KROWBAR_SCORE_PATH "/home/jmjl/dev/juju/data/tildescores.txt"
+  #define KROWBAR_SCORE_PATH "/home/krowbar/Code/irc/data/tildescores.txt"
+  #define JU_SCORE_PATH "/home/jmjl/dev/juju/data/tildescores.txt"
 #endif
 #if !defined(TILDEINSTITUTE) && !defined(TILDEGURU)
   #define WHOAMI_PATH "/usr/bin/whoami"
@@ -390,25 +390,26 @@ void cout_formatted_amount(long long int const& amount, char const* appended_cha
 
 long long int base_amount;
 long long int user_amount;
-long long int krowbar_amount; //krowbar's tilde game amount
+long long int krowbar_amount[2]; //krowbar's and ju's tilde game amount
 long long int da_amount; //troido's daily adventure amount
 long long int minercoin_amount; //minerbot's minercoin game amount
 
-void show_breakdown(const long long int &amount0 = 0, char const* amount0_source = "", const long long int &amount1 = 0, char const* amount1_source = "", const long long int &amount2 = 0, char const* amount2_source = "", const long long int &amount3 = 0, char const* amount3_source = "", const long long int &amount4 = 0, char const* amount4_source = "")
+void show_breakdown(const long long int &amount0 = 0, char const* amount0_source = "", const long long int &amount1 = 0, char const* amount1_source = "", const long long int &amount2 = 0, char const* amount2_source = "", const long long int &amount3 = 0, char const* amount3_source = "", const long long int &amount4 = 0, char const* amount4_source = "", const long long int &amount5 = 0, char const* amount5_source = "")
 {
   bool a0 = (amount0 != 0 && strcmp(amount0_source, ""));
   bool a1 = (amount1 != 0 && strcmp(amount1_source, ""));
   bool a2 = (amount2 != 0 && strcmp(amount2_source, ""));
   bool a3 = (amount3 != 0 && strcmp(amount3_source, ""));
   bool a4 = (amount4 != 0 && strcmp(amount4_source, ""));
-  if(a0 || a1 || a2 || a3 || a4)
+  bool a5 = (amount5 != 0 && strcmp(amount5_source, ""));
+  if(a0 || a1 || a2 || a3 || a4 || a5)
   {
     std::cout << "Breakdown: ";
     if(a0)
     {
       cout_formatted_amount(amount0, "", "", true);
       std::cout << " [" << amount0_source << "]";
-      if(a1 || a2 || a3 || a4)
+      if(a1 || a2 || a3 || a4 || a5)
       {
         std::cout << " + ";
       }
@@ -417,7 +418,7 @@ void show_breakdown(const long long int &amount0 = 0, char const* amount0_source
     {
       cout_formatted_amount(amount1, "", "", true);
       std::cout << " [" << amount1_source << "]";
-      if(a2 || a3 || a4)
+      if(a2 || a3 || a4 || a5)
       {
         std::cout << " + ";
       }
@@ -426,7 +427,7 @@ void show_breakdown(const long long int &amount0 = 0, char const* amount0_source
     {
       cout_formatted_amount(amount2, "", "", true);
       std::cout << " [" << amount2_source << "]";
-      if(a3 || a4)
+      if(a3 || a4 || a5)
       {
         std::cout << " + ";
       }
@@ -435,7 +436,7 @@ void show_breakdown(const long long int &amount0 = 0, char const* amount0_source
     {
       cout_formatted_amount(amount3, "", "", true);
       std::cout << " [" << amount3_source << "]";
-      if(a4)
+      if(a4 || a5)
       {
         std::cout << " + ";
       }
@@ -444,12 +445,21 @@ void show_breakdown(const long long int &amount0 = 0, char const* amount0_source
     {
       cout_formatted_amount(amount4, "", "", true);
       std::cout << " [" << amount4_source << "]";
+      if(a5)
+      {
+        std::cout << " + ";
+      }
+    }
+    if(a5)
+    {
+      cout_formatted_amount(amount5, "", "", true);
+      std::cout << " [" << amount5_source << "]";
     }
     std::cout << "\n";
   }
 }
 
-void show_balance(char const* username, const long long int &amount, const long long int &amount0 = 0, char const* amount0_source = "", const long long int &amount1 = 0, char const* amount1_source = "", const long long int &amount2 = 0, char const* amount2_source = "", const long long int &amount3 = 0, char const* amount3_source = "", const long long int &amount4 = 0, char const* amount4_source = "")
+void show_balance(char const* username, const long long int &amount, const long long int &amount0 = 0, char const* amount0_source = "", const long long int &amount1 = 0, char const* amount1_source = "", const long long int &amount2 = 0, char const* amount2_source = "", const long long int &amount3 = 0, char const* amount3_source = "", const long long int &amount4 = 0, char const* amount4_source = "", const long long int &amount5 = 0, char const* amount5_source = "")
 {
   std::cout << username << ", you have ";
   cout_formatted_amount(amount, " tildecoins", " tildecoin");
@@ -1636,39 +1646,53 @@ int main(int argc, char *argv[])
     std::string line;
     const std::string username = get_username();
     const int username_length = username.length();
-    std::ifstream fin(KROWBAR_SCORE_PATH);
-    while(std::getline(fin, line))
+    std::string score_file_path;
+    std::ifstream fin;
+
+    for(int j=0; j<2; ++j)
     {
-      char* line_c_string = new char[line.length()+1];
-      std::strcpy(line_c_string, line.c_str());
+      if(j == 0)
+        score_file_path.assign(KROWBAR_SCORE_PATH);
+      else if(j == 1)
+        score_file_path.assign(JU_SCORE_PATH);
 
-      const int irc_username_length = username_length > USERNAME_LENGTH_LIMIT ? USERNAME_LENGTH_LIMIT : username_length;
+      fin.open(score_file_path);
 
-      if(!std::strncmp(username.c_str(), line_c_string, irc_username_length))
+      while(std::getline(fin, line))
       {
-        char number_of_tildes[21];
-        number_of_tildes[0] = '0'; //just in case the loop below doesn't detect any digits
-        number_of_tildes[1] = '\0';
+        char* line_c_string = new char[line.length()+1];
+        std::strcpy(line_c_string, line.c_str());
+
+        const int irc_username_length = username_length > USERNAME_LENGTH_LIMIT ? USERNAME_LENGTH_LIMIT : username_length;
 
-        for(int i=0; i < 20; ++i)
+        if(!std::strncmp(username.c_str(), line_c_string, irc_username_length))
         {
-          if(std::isdigit(line_c_string[irc_username_length+3+i]))
-            number_of_tildes[i] = line_c_string[irc_username_length+3+i];
-          else
+          char number_of_tildes[21];
+          number_of_tildes[0] = '0'; //just in case the loop below doesn't detect any digits
+          number_of_tildes[1] = '\0';
+
+          for(int i=0; i < 20; ++i)
           {
-            number_of_tildes[i] = '\0'; //manually terminating the string
-            break;
+            if(std::isdigit(line_c_string[irc_username_length+3+i]))
+              number_of_tildes[i] = line_c_string[irc_username_length+3+i];
+            else
+            {
+              number_of_tildes[i] = '\0'; //manually terminating the string
+              break;
+            }
           }
-        }
-        number_of_tildes[20] = '\0'; //incase the number overflows 20 characters
+          number_of_tildes[20] = '\0'; //incase the number overflows 20 characters
 
-        krowbar_amount = strtol100(number_of_tildes);
-        base_amount += krowbar_amount;
-        //multiplied by 100 inside strtol100() to convert tildecoins to centitildecoins, which
-        //is the unit used throughout the program (and converted appropriately when displayed)
-        break;
+          krowbar_amount[j] = strtol100(number_of_tildes);
+
+          base_amount += krowbar_amount[j];
+          //multiplied by 100 inside strtol100() to convert tildecoins to centitildecoins, which
+          //is the unit used throughout the program (and converted appropriately when displayed)
+          break;
+        }
+        delete[] line_c_string;
       }
-      delete[] line_c_string;
+      fin.close();
     }
   }
   #endif
@@ -1751,13 +1775,13 @@ int main(int argc, char *argv[])
   {
     //show last 10 messages
     show_messages_tail(get_username().c_str(), 10);
-    show_balance(get_username().c_str(), total_amount, unaltered_base_amount, "base amount", user_amount, "transfers", krowbar_amount, "tilde game", da_amount, "daily-adventure game", minercoin_amount, "MinerCoin game");
+    show_balance(get_username().c_str(), total_amount, unaltered_base_amount, "base amount", user_amount, "transfers", krowbar_amount[0], "tilde game", krowbar_amount[1], "ju game", da_amount, "daily-adventure game", minercoin_amount, "MinerCoin game");
   }
   else if(!strcmp(argv[1], "breakdown") || !strcmp(argv[1], "-bd"))
   {
     std::cout << "Total balance: ";
     cout_formatted_amount(total_amount, " tildecoins\n", " tildecoin\n");
-    show_breakdown(unaltered_base_amount, "base amount", user_amount, "transfers", krowbar_amount, "tilde game", da_amount, "daily-adventure game", minercoin_amount, "MinerCoin game");
+    show_breakdown(unaltered_base_amount, "base amount", user_amount, "transfers", krowbar_amount[0], "tilde game", krowbar_amount[1], "ju game", da_amount, "daily-adventure game", minercoin_amount, "MinerCoin game");
   }
   else if(!strcmp(argv[1], "balance") || !strcmp(argv[1], "-b"))
     cout_formatted_amount(total_amount, "\n");