void _SendUserInfo(tClient *Client, int UserID) { char *type, *disabled="", *door=""; int flags = Bank_GetFlags(UserID); if( flags & USER_FLAG_INTERNAL ) { type = "internal"; } else if( flags & USER_FLAG_COKE ) { if( flags & USER_FLAG_ADMIN ) type = "coke,admin"; else type = "coke"; } else if( flags & USER_FLAG_ADMIN ) { type = "admin"; } else { type = "user"; } if( flags & USER_FLAG_DISABLED ) disabled = ",disabled"; if( flags & USER_FLAG_DOORGROUP ) door = ",door"; // TODO: User flags/type sendf( Client->Socket, "202 User %s %i %s%s%s\n", Bank_GetAcctName(UserID), Bank_GetBalance(UserID), type, disabled, door ); }
/* * Transfers money from one user to another * \param SourceUser Source user * \param DestUser Destination user * \param Ammount Ammount of cents to move from \a SourceUser to \a DestUser * \param Reason Reason for the transfer (essentially a comment) * \return Boolean failure */ int Bank_Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason) { int srcBal = Bank_GetBalance(SourceUser); int dstBal = Bank_GetBalance(DestUser); if( srcBal - Ammount < Bank_int_GetMinAllowedBalance(SourceUser) ) return 1; if( dstBal + Ammount < Bank_int_GetMinAllowedBalance(DestUser) ) return 1; Bank_int_AlterUserBalance(DestUser, Ammount); Bank_int_AlterUserBalance(SourceUser, -Ammount); fprintf(gBank_LogFile, "Transfer %ic #%i{%i} > #%i{%i} [%i, %i] (%s)\n", Ammount, SourceUser, srcBal, DestUser, dstBal, srcBal - Ammount, dstBal + Ammount, Reason); return 0; }
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) ) { char *space = Args, *type, *val; do { type = space; while(*type == ' ') type ++; // Get next space space = strchr(space, ' '); if(space) *space = '\0'; // Get type val = strchr(type, ':'); if( val ) { *val = '\0'; val ++; // Types // - Minium Balance if( strcmp(type, "min_balance") == 0 ) { minBal = atoi(val); } // - Maximum Balance else if( strcmp(type, "max_balance") == 0 ) { maxBal = atoi(val); } // - Flags else if( strcmp(type, "flags") == 0 ) { if( Server_int_ParseFlags(Client, val, &flagMask, &flagVal) ) return ; } // - Last seen before timestamp else if( strcmp(type, "last_seen_before") == 0 ) { lastSeenAfter = atoll(val); } // - Last seen after timestamp else if( strcmp(type, "last_seen_after") == 0 ) { lastSeenAfter = atoll(val); } // - Sorting else if( strcmp(type, "sort") == 0 ) { char *dash = strchr(val, '-'); if( dash ) { *dash = '\0'; dash ++; } if( strcmp(val, "name") == 0 ) { sort = BANK_ITFLAG_SORT_NAME; } else if( strcmp(val, "balance") == 0 ) { sort = BANK_ITFLAG_SORT_BAL; } else if( strcmp(val, "lastseen") == 0 ) { sort = BANK_ITFLAG_SORT_LASTSEEN; } else { sendf(Client->Socket, "407 Unknown sort field ('%s')\n", val); return ; } // Handle sort direction if( dash ) { if( strcmp(dash, "desc") == 0 ) { sort |= BANK_ITFLAG_REVSORT; } else { sendf(Client->Socket, "407 Unknown sort direction '%s'\n", dash); return ; } dash[-1] = '-'; } } else { sendf(Client->Socket, "407 Unknown argument to ENUM_USERS '%s:%s'\n", type, val); return ; } val[-1] = ':'; } else { sendf(Client->Socket, "407 Unknown argument to ENUM_USERS '%s'\n", type); return ; } // Eat whitespace if( space ) { *space = ' '; // Repair (to be nice) space ++; while(*space == ' ') space ++; } } while(space); } // Create iterator if( maxBal != INT_MAX ) { flags = sort|BANK_ITFLAG_MAXBALANCE; balValue = maxBal; } else if( minBal != INT_MIN ) { flags = sort|BANK_ITFLAG_MINBALANCE; balValue = minBal; } else { flags = sort; balValue = 0; } if( lastSeenBefore ) { timeValue = lastSeenBefore; flags |= BANK_ITFLAG_SEENBEFORE; } else if( lastSeenAfter ) { timeValue = lastSeenAfter; flags |= BANK_ITFLAG_SEENAFTER; } else { timeValue = 0; } it = Bank_Iterator(flagMask, flagVal, flags, balValue, timeValue); // Get return number while( (i = Bank_IteratorNext(it)) != -1 ) { int bal = Bank_GetBalance(i); if( bal == INT_MIN ) continue; if( bal < minBal ) continue; if( bal > maxBal ) continue; numRet ++; } Bank_DelIterator(it); // Send count sendf(Client->Socket, "201 Users %i\n", numRet); // Create iterator it = Bank_Iterator(flagMask, flagVal, flags, balValue, timeValue); while( (i = Bank_IteratorNext(it)) != -1 ) { int bal = Bank_GetBalance(i); if( bal == INT_MIN ) continue; if( bal < minBal ) continue; if( bal > maxBal ) continue; _SendUserInfo(Client, i); } Bank_DelIterator(it); sendf(Client->Socket, "200 List End\n"); }