Added finger support
[tpg/opendispense2.git] / src / client / main.c
index 8c4237e..8d46af2 100644 (file)
@@ -134,16 +134,18 @@ void ShowUsage(void)
                        "        Show interactive list\n"
                        "    dispense <name>|<index>|<itemid>\n"
                        "        Dispense named item (<name> matches if it is a unique prefix)\n"
+                       "    dispense finger\n"
+                       "        Show the finger output\n"
                        );
        if( giTextArgc == 0 || strcmp(gsTextArgs[0], "give") == 0 )
                printf(
-                       "    dispense give <user> <ammount> \"<reason>\"\n"
+                       "    dispense give <user> <amount> \"<reason>\"\n"
                        "        Give money to another user\n"
                        );
        
        if( giTextArgc == 0 || strcmp(gsTextArgs[0], "donate") == 0 )
                printf(
-                       "    dispense donate <ammount> \"<reason>\"\n"
+                       "    dispense donate <amount> \"<reason>\"\n"
                        "        Donate to the club\n"
                        );
        if( giTextArgc == 0 || strcmp(gsTextArgs[0], "iteminfo") == 0 )
@@ -162,9 +164,9 @@ void ShowUsage(void)
                printf(
                        "    dispense acct [<user>]\n"
                        "        Show user balances\n"
-                       "    dispense acct <user> [+-]<ammount> \"<reason>\"\n"
+                       "    dispense acct <user> [+-]<amount> \"<reason>\"\n"
                        "        Alter a account value\n"
-                       "    dispense acct <user> =<ammount> \"<reason>\"\n"
+                       "    dispense acct <user> =<amount> \"<reason>\"\n"
                        "        Set an account balance\n"
                        );
        if( giTextArgc == 0 || strcmp(gsTextArgs[0], "refund") == 0 )
@@ -375,6 +377,37 @@ int main(int argc, char *argv[])
        
        }
 
+       //
+       // `dispense finger`
+       // -
+       if( strcmp(gsTextArgs[0], "finger") == 0 )
+       {
+               // Connect to server
+               sock = OpenConnection(gsDispenseServer, giDispensePort);
+               if( sock < 0 )  return RV_SOCKET_ERROR;
+
+               // Get items
+               PopulateItemList(sock);
+
+               // Only get coke slot statuses
+               for( i = 0; i <= 6; i ++ )
+               {
+                       const char *status;
+                       switch(gaItems[i].Status)
+                       {
+                       case 0: status = "Avail";       break;
+                       case 1: status = "Sold ";       break;
+                       default:
+                               status = "Error";
+                               break;
+                       }
+                       printf("%i - %s %3i %s\n", gaItems[i].ID, status, gaItems[i].Price, gaItems[i].Desc);
+                       
+               }
+
+               return 0;
+       }
+
        //
        // `dispense acct`
        // - 
@@ -1112,7 +1145,7 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted)
        if( Width > 0 )
        {
                // 4 preceding, 5 price
-               int nameWidth = Width - 4 - 4 - snprintf(NULL, 0, "%i", price/100);
+               int nameWidth = Width - 4 - snprintf(NULL, 0, " %4i", price);
                move( Row, Col );
                
                if( Index >= 0 )
@@ -1138,7 +1171,7 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted)
                        
                        printw("%-*.*s", nameWidth, nameWidth, name);
                
-                       printw(" %i.%02i", price/100, price%100);
+                       printw(" %4i", price);
                }
                else
                {
@@ -1716,7 +1749,7 @@ int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const c
 
        // Sanity
        if( Ammount == 0 ) {
-               printf("An ammount would be nice\n");
+               printf("An amount would be nice\n");
                return RV_ARGUMENTS;
        }
        
@@ -2253,9 +2286,10 @@ char *ReadLine(int Socket)
                if( newline ) {
                         int    newLen = newline - (buf+bufPos) + 1;
                        bufValid = len - newLen;
-                       bufPos += newLen;
+                       len = newLen;
                }
                if( len + bufPos == BUFSIZ - 1 )        bufPos = 0;
+               else    bufPos += len;
        }
        
        #if DEBUG_TRACE_SERVER

UCC git Repository :: git.ucc.asn.au