+ tItem *item;
+ int uid, price_override = 0;
+ char *username, *itemname, *price_str;
+
+ if( Server_int_ParseArgs(0, Args, &username, &itemname, &price_str, NULL) ) {
+ if( !itemname || price_str ) {
+ sendf(Client->Socket, "407 REFUND takes 2 or 3 arguments\n");
+ return ;
+ }
+ }
+
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
+ return ;
+ }
+
+ // Check user permissions
+ if( !(Bank_GetFlags(Client->UID) & (USER_FLAG_COKE|USER_FLAG_ADMIN)) ) {
+ sendf(Client->Socket, "403 Not in coke\n");
+ return ;
+ }
+
+ uid = Bank_GetAcctByName(username, 0);
+ if( uid == -1 ) {
+ sendf(Client->Socket, "404 Unknown user\n");
+ return ;
+ }
+
+ item = _GetItemFromString(itemname);
+ if( !item ) {
+ sendf(Client->Socket, "406 Bad Item ID\n");
+ return ;
+ }
+
+ if( price_str )
+ price_override = atoi(price_str);
+
+ switch( DispenseRefund( Client->UID, uid, item, price_override ) )
+ {
+ case 0: sendf(Client->Socket, "200 Item Refunded\n"); return ;
+ default:
+ sendf(Client->Socket, "500 Dispense Error\n");
+ return;
+ }
+}
+
+void Server_Cmd_GIVE(tClient *Client, char *Args)
+{
+ char *recipient, *ammount, *reason;
+ int uid, iAmmount;
+ int thisUid;
+
+ // Parse arguments
+ if( Server_int_ParseArgs(1, Args, &recipient, &ammount, &reason, NULL) ) {
+ sendf(Client->Socket, "407 GIVE takes only 3 arguments\n");
+ return ;
+ }
+
+ // Check for authed
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
+ return ;
+ }
+
+ // Get recipient
+ uid = Bank_GetAcctByName(recipient, 0);
+ if( uid == -1 ) {
+ sendf(Client->Socket, "404 Invalid target user\n");
+ return ;
+ }
+
+ // You can't alter an internal account
+// if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
+// sendf(Client->Socket, "404 Invalid target user\n");
+// return ;
+// }
+
+ // Parse ammount
+ iAmmount = atoi(ammount);
+ if( iAmmount <= 0 ) {
+ sendf(Client->Socket, "407 Invalid Argument, ammount must be > zero\n");
+ return ;
+ }
+
+ if( Client->EffectiveUID != -1 ) {
+ thisUid = Client->EffectiveUID;
+ }
+ else {
+ thisUid = Client->UID;
+ }
+
+ // Do give
+ switch( DispenseGive(Client->UID, thisUid, uid, iAmmount, reason) )
+ {
+ case 0:
+ sendf(Client->Socket, "200 Give OK\n");
+ return ;
+ case 2:
+ sendf(Client->Socket, "402 Poor You\n");
+ return ;
+ default:
+ sendf(Client->Socket, "500 Unknown error\n");
+ return ;
+ }
+}
+
+void Server_Cmd_DONATE(tClient *Client, char *Args)
+{
+ char *ammount, *reason;
+ int iAmmount;
+ int thisUid;
+
+ // Parse arguments
+ if( Server_int_ParseArgs(1, Args, &ammount, &reason, NULL) ) {
+ sendf(Client->Socket, "407 DONATE takes 2 arguments\n");
+ return ;
+ }
+
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
+ return ;
+ }
+
+ // Parse ammount
+ iAmmount = atoi(ammount);
+ if( iAmmount <= 0 ) {
+ sendf(Client->Socket, "407 Invalid Argument, ammount must be > zero\n");
+ return ;
+ }
+
+ // Handle effective users
+ if( Client->EffectiveUID != -1 ) {
+ thisUid = Client->EffectiveUID;
+ }
+ else {
+ thisUid = Client->UID;
+ }
+
+ // Do give
+ switch( DispenseDonate(Client->UID, thisUid, iAmmount, reason) )
+ {
+ case 0:
+ sendf(Client->Socket, "200 Give OK\n");
+ return ;
+ case 2:
+ sendf(Client->Socket, "402 Poor You\n");
+ return ;
+ default:
+ sendf(Client->Socket, "500 Unknown error\n");
+ return ;
+ }
+}
+
+void Server_Cmd_ADD(tClient *Client, char *Args)
+{
+ char *user, *ammount, *reason;
+ int uid, iAmmount;
+
+ // Parse arguments
+ if( Server_int_ParseArgs(1, Args, &user, &ammount, &reason, NULL) ) {
+ sendf(Client->Socket, "407 ADD takes 3 arguments\n");
+ return ;
+ }
+
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
+ return ;
+ }
+
+ // Check user permissions
+ if( !(Bank_GetFlags(Client->UID) & (USER_FLAG_COKE|USER_FLAG_ADMIN)) ) {
+ sendf(Client->Socket, "403 Not in coke\n");
+ return ;
+ }
+
+ #if !ROOT_CAN_ADD
+ if( strcmp( Client->Username, "root" ) == 0 ) {
+ // Allow adding for new users
+ if( strcmp(reason, "treasurer: new user") != 0 ) {
+ sendf(Client->Socket, "403 Root may not add\n");
+ return ;
+ }
+ }
+ #endif
+
+ #if HACK_NO_REFUNDS
+ if( strstr(reason, "refund") != NULL || strstr(reason, "misdispense") != NULL )
+ {
+ sendf(Client->Socket, "499 Don't use `dispense acct` for refunds, use `dispense refund` (and `dispense -G` to get item IDs)\n");
+ return ;
+ }
+ #endif
+
+ // Get recipient
+ uid = Bank_GetAcctByName(user, 0);
+ if( uid == -1 ) {
+ sendf(Client->Socket, "404 Invalid user\n");
+ return ;
+ }
+
+ // You can't alter an internal account
+ if( !(Bank_GetFlags(Client->UID) & USER_FLAG_ADMIN) )
+ {
+ if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
+ sendf(Client->Socket, "404 Invalid user\n");
+ return ;
+ }
+ // TODO: Maybe disallow changes to disabled?
+ }
+
+ // Parse ammount
+ iAmmount = atoi(ammount);
+ if( iAmmount == 0 && ammount[0] != '0' ) {
+ sendf(Client->Socket, "407 Invalid Argument\n");
+ return ;
+ }
+
+ // Do give
+ switch( DispenseAdd(Client->UID, uid, iAmmount, reason) )
+ {
+ case 0:
+ sendf(Client->Socket, "200 Add OK\n");
+ return ;
+ case 2:
+ sendf(Client->Socket, "402 Poor Guy\n");
+ return ;
+ default:
+ sendf(Client->Socket, "500 Unknown error\n");
+ return ;
+ }
+}
+
+void Server_Cmd_SET(tClient *Client, char *Args)
+{
+ char *user, *ammount, *reason;
+ int uid, iAmmount;
+
+ // Parse arguments
+ if( Server_int_ParseArgs(1, Args, &user, &ammount, &reason, NULL) ) {
+ sendf(Client->Socket, "407 SET takes 3 arguments\n");
+ return ;
+ }
+
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
+ return ;
+ }
+
+ // Check user permissions
+ if( !(Bank_GetFlags(Client->UID) & USER_FLAG_ADMIN) ) {
+ sendf(Client->Socket, "403 Not an admin\n");
+ return ;
+ }
+
+ // Get recipient
+ uid = Bank_GetAcctByName(user, 0);
+ if( uid == -1 ) {
+ sendf(Client->Socket, "404 Invalid user\n");
+ return ;
+ }
+
+ // Parse ammount
+ iAmmount = atoi(ammount);
+ if( iAmmount == 0 && ammount[0] != '0' ) {
+ sendf(Client->Socket, "407 Invalid Argument\n");
+ return ;
+ }
+
+ // Do give
+ switch( DispenseSet(Client->UID, uid, iAmmount, reason) )
+ {
+ case 0:
+ sendf(Client->Socket, "200 Add OK\n");
+ return ;
+ case 2:
+ sendf(Client->Socket, "402 Poor Guy\n");
+ return ;
+ default:
+ sendf(Client->Socket, "500 Unknown error\n");
+ return ;
+ }
+}
+
+void Server_Cmd_ENUMUSERS(tClient *Client, char *Args)
+{
+ int i, numRet = 0;
+ tAcctIterator *it;
+ int maxBal = INT_MAX, minBal = INT_MIN;
+ int flagMask = 0, flagVal = 0;
+ int sort = BANK_ITFLAG_SORT_NAME;
+ time_t lastSeenAfter=0, lastSeenBefore=0;
+
+ int flags; // Iterator flags
+ int balValue; // Balance value for iterator
+ time_t timeValue; // Time value for iterator
+
+ // Parse arguments
+ if( Args && strlen(Args) )