Fixed up some error reporting
authorJohn Hodge <[email protected]>
Fri, 10 May 2013 08:26:12 +0000 (16:26 +0800)
committerJohn Hodge <[email protected]>
Fri, 10 May 2013 08:26:12 +0000 (16:26 +0800)
src/client/main.c
src/client/protocol.c
src/server/server.c

index da301be..1f4485d 100644 (file)
@@ -345,7 +345,6 @@ int main(int argc, char *argv[])
                                break;
                        }
                        printf("%i - %s %3i %s\n", gaItems[i].ID, status, gaItems[i].Price, gaItems[i].Desc);
-                       
                }
 
                printf("\nMay your pink fish bing into the distance.\n");
@@ -386,19 +385,20 @@ int main(int argc, char *argv[])
                        // gsTextArgs[1]: Username
                        // gsTextArgs[2]: Ammount
                        // gsTextArgs[3]: Reason
+                        char   *tmp = NULL;
+                       long int balance = strtol(gsTextArgs[2]+(gsTextArgs[2][0] == '='), &tmp, 10);
+                       if(!tmp || *tmp != '\0') {
+                               fprintf(stderr, "dispense acct: Value must be a decimal number of cents\n");
+                               return RV_ARGUMENTS;
+                       }
                        
                        if( gsTextArgs[2][0] == '=' ) {
                                // Set balance
-                               if( gsTextArgs[2][1] != '0' && atoi(gsTextArgs[2]+1) == 0 ) {
-                                       fprintf(stderr, "Error: Invalid balance to be set\n");
-                                       exit(1);
-                               }
-                               
-                               ret = Dispense_SetBalance(sock, gsTextArgs[1], atoi(gsTextArgs[2]+1), gsTextArgs[3]);
+                               ret = Dispense_SetBalance(sock, gsTextArgs[1], balance, gsTextArgs[3]);
                        }
                        else {
                                // Alter balance
-                               ret = Dispense_AlterBalance(sock, gsTextArgs[1], atoi(gsTextArgs[2]), gsTextArgs[3]);
+                               ret = Dispense_AlterBalance(sock, gsTextArgs[1], balance, gsTextArgs[3]);
                        }
                }
                // On error, quit
@@ -435,8 +435,14 @@ int main(int argc, char *argv[])
                // Authenticate
                ret = Authenticate(sock);
                if(ret) return ret;
-               
-               ret = Dispense_Give(sock, gsTextArgs[1], atoi(gsTextArgs[2]), gsTextArgs[3]);
+
+               char    *tmp = NULL;
+               int amt = strtol(gsTextArgs[2], &tmp, 10);
+               if( !tmp || *tmp != '\0' ) {
+                       fprintf(stderr, "dispense give: Balance is invalid, must be decimal number of cents");
+                       return RV_ARGUMENTS;
+               }
+               ret = Dispense_Give(sock, gsTextArgs[1], amt, gsTextArgs[3]);
 
                close(sock);
        
index dae51cb..fb69850 100644 (file)
@@ -701,7 +701,7 @@ int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const c
                rv = RV_BAD_ITEM;
                break;
        case 403:       // Not in coke
-               fprintf(stderr, "You are not in coke (sucker)\n");
+               fprintf(stderr, "Permissions error: %s\n", buf+4);
                rv = RV_PERMISSIONS;
                break;
        case 404:       // Unknown user
@@ -742,7 +742,7 @@ int Dispense_SetBalance(int Socket, const char *Username, int Balance, const cha
        switch(responseCode)
        {
        case 200:       return 0;       // OK
-       case 403:       // Not in coke
+       case 403:       // Not an administrator
                fprintf(stderr, "You are not an admin\n");
                return RV_PERMISSIONS;
        case 404:       // Unknown user
index a48b69a..6077b9b 100644 (file)
@@ -1104,7 +1104,7 @@ void Server_Cmd_ADD(tClient *Client, char *Args)
        if( !(Bank_GetFlags(Client->UID) & USER_FLAG_ADMIN) )
        {
                if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
-                       sendf(Client->Socket, "404 Invalid user\n");
+                       sendf(Client->Socket, "403 Admin only\n");
                        return ;
                }
                // TODO: Maybe disallow changes to disabled?

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