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");
// 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
// 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);
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
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