From: John Hodge Date: Fri, 4 Mar 2011 08:40:50 +0000 (+0800) Subject: Updating more return values, added commands to comments X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c8cb15c40d7afdf434e9b139ef0dd410a2e20002;p=tpg%2Fopendispense2.git Updating more return values, added commands to comments --- diff --git a/src/client/main.c b/src/client/main.c index 7dc9499..7d43db7 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -49,8 +49,10 @@ enum eReturnValues RV_PERMISSIONS, RV_ARGUMENTS, RV_BALANCE, + RV_SERVER_ERROR, // Generic for 5xx codes RV_UNKNOWN_ERROR = -1, - RV_SOCKET_ERROR = -2 + RV_SOCKET_ERROR = -2, + RV_UNKNOWN_RESPONSE = -3, }; // === TYPES === @@ -63,8 +65,8 @@ typedef struct sItem { } tItem; // === PROTOTYPES === - int main(int argc, char *argv[]); void ShowUsage(void); + int main(int argc, char *argv[]); // --- GUI --- int ShowNCursesUI(void); int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted); @@ -114,6 +116,60 @@ char *gsUserFlags; //!< User's flag set int giDispenseCount = 1; //!< Number of dispenses to do // === CODE === +void ShowUsage(void) +{ + printf( + "Usage:\n" + " == Everyone ==\n" + " dispense\n" + " Show interactive list\n" + " dispense ||\n" + " Dispense named item ( matches if it is a unique prefix)\n" + " dispense give \"\"\n" + " Give money to another user\n" + " dispense donate \"\"\n" + " Donate to the club\n" + " dispense iteminfo \n" + " Get the name and price for an item\n" + " == Coke members == \n" + " dispense acct []\n" + " Show user balances\n" + " dispense acct [+-] \"\"\n" + " Alter a account value\n" + " dispense refund []\n" + " Refund an item to a user (with optional price override)\n" + " == Dispense administrators ==\n" + " dispense acct = \"\"\n" + " Set an account balance\n" + " dispense user add \n" + " Create new account\n" + " dispense user type \n" + " Alter a user's flags\n" + " is a comma-separated list of user, coke, admin, internal or disabled\n" + " Flags are removed by preceding the name with '-' or '!'\n" + "\n" + "General Options:\n" + " -c \n" + " Dispense multiple times\n" + " -u \n" + " Set a different user (Coke members only)\n" + " -h / -?\n" + " Show help text\n" + " -G\n" + " Use alternate GUI\n" + " -n\n" + " Dry run - Do not actually do dispenses\n" + " -m \n" + " -M \n" + " Set the Maximum/Minimum balances shown in `dispense acct`\n" + "Definitions:\n" + " \n" + " Item ID of the form : where is a non-empty string of alpha-numeric characters, and is a non-negative integer\n" +// " \n" +// " Account name\n" + ); +} + int main(int argc, char *argv[]) { int sock; @@ -642,51 +698,6 @@ int main(int argc, char *argv[]) return ret; } -void ShowUsage(void) -{ - printf( - "Usage:\n" - " == Everyone ==\n" - " dispense\n" - " Show interactive list\n" - " dispense ||\n" - " Dispense named item ( matches if it is a unique prefix)\n" - " dispense give \"\"\n" - " Give money to another user\n" - " dispense donate \"\"\n" - " Donate to the club\n" - " dispense iteminfo :\n" - " Get the name and price for an item\n" - " == Coke members == \n" - " dispense acct []\n" - " Show user balances\n" - " dispense acct [+-] \"\"\n" - " Alter a account value\n" - " == Dispense administrators ==\n" - " dispense acct = \"\"\n" - " Set an account balance\n" - " dispense user add \n" - " Create new coke account (Admins only)\n" - " dispense user type \n" - " Alter a user's flags\n" - " is a comma-separated list of user, coke, admin or disabled\n" - " Flags are removed by preceding the name with '-' or '!'\n" - "\n" - "General Options:\n" - " -c \n" - " Dispense multiple times\n" - " -u \n" - " Set a different user (Coke members only)\n" - " -h / -?\n" - " Show help text\n" - " -G\n" - " Use alternate GUI\n" - " -m \n" - " -M \n" - " Set the Maximum/Minimum balances shown in `dispense acct`\n" - ); -} - // ------------------- // --- NCurses GUI --- // ------------------- @@ -1530,11 +1541,11 @@ int DispenseItem(int Socket, const char *Type, int ID) break; case 500: printf("Item failed to dispense, is the slot empty?\n"); - ret = 1; + ret = RV_SERVER_ERROR; break; case 501: printf("Dispense not possible (slot empty/permissions)\n"); - ret = 1; + ret = RV_SERVER_ERROR; break; default: printf("Unknown response code %i ('%s')\n", responseCode, buf); @@ -1577,16 +1588,16 @@ int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const c case 200: return 0; // OK case 402: fprintf(stderr, "Insufficient balance\n"); - return 1; + return RV_BAD_ITEM; case 403: // Not in coke fprintf(stderr, "You are not in coke (sucker)\n"); - return 1; + return RV_PERMISSIONS; case 404: // Unknown user fprintf(stderr, "Unknown user '%s'\n", Username); - return 2; + return RV_INVALID_USER; default: fprintf(stderr, "Unknown response code %i\n", responseCode); - return -1; + return RV_UNKNOWN_RESPONSE; } return -1; @@ -1618,13 +1629,13 @@ int Dispense_SetBalance(int Socket, const char *Username, int Balance, const cha case 200: return 0; // OK case 403: // Not in coke fprintf(stderr, "You are not an admin\n"); - return 1; + return RV_PERMISSIONS; case 404: // Unknown user fprintf(stderr, "Unknown user '%s'\n", Username); - return 2; + return RV_INVALID_USER; default: fprintf(stderr, "Unknown response code %i\n", responseCode); - return -1; + return RV_UNKNOWN_RESPONSE; } return -1; @@ -1640,13 +1651,13 @@ int Dispense_Give(int Socket, const char *Username, int Ammount, const char *Rea if( Ammount < 0 ) { printf("Sorry, you can only give, you can't take.\n"); - return 1; + return RV_ARGUMENTS; } // Fast return on zero if( Ammount == 0 ) { printf("Are you actually going to give any?\n"); - return 1; + return RV_ARGUMENTS; } // Check for a dry run @@ -1664,19 +1675,19 @@ int Dispense_Give(int Socket, const char *Username, int Ammount, const char *Rea { case 200: printf("Give succeeded\n"); - return 0; // OK + return RV_SUCCESS; // OK case 402: fprintf(stderr, "Insufficient balance\n"); - return 1; + return RV_BALANCE; case 404: // Unknown user fprintf(stderr, "Unknown user '%s'\n", Username); - return 2; + return RV_INVALID_USER; default: fprintf(stderr, "Unknown response code %i\n", responseCode); - return -1; + return RV_UNKNOWN_RESPONSE; } return -1; @@ -1702,7 +1713,7 @@ int Dispense_Refund(int Socket, const char *Username, const char *Item, int Pric } // Send the query - sendf(Socket, "REFUND %s %s %i", Username, Item, PriceOverride); + sendf(Socket, "REFUND %s %s %i\n", Username, Item, PriceOverride); buf = ReadLine(Socket); responseCode = atoi(buf);