c USER_ADD <username>\n
s 200 User Added\n or 403 Not Wheel\n or 404 User Exists\n
--- Set user flags ---
+ <flags> is a comma-separated list of flag values (optionally preceded by
+ - to remove the flag) Valid values are: user,coke,wheel,meta,disabled,door
c USER_FLAGS <username> <flags>\n
s 200 User Updated\n or 403 Not Wheel\n or 404 Bad User\n or 407 Unknown Flags\n
// --- Cokebank Functions ---
extern int Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
extern int GetFlags(int User);
+extern int SetFlags(int User, int Mask, int Value);
extern int GetBalance(int User);
extern char *GetUserName(int User);
extern int GetUserID(const char *Username);
return gaBank_Users[ID].Flags;
}
+int Bank_SetUserFlags(int ID, int Mask, int Value)
+{
+ // Sanity
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return -1;
+
+ // Silently ignore changes to root and meta accounts
+ if( gaBank_Users[ID].UnixID <= 0 ) return 0;
+
+ gaBank_Users[ID].Flags &= Mask;
+ gaBank_Users[ID].Flags |= Value;
+
+ return 0;
+}
+
int Bank_AlterUserBalance(int ID, int Delta)
{
// Sanity
{
char *username, *flags;
char *space;
+ int mask=0, value=0;
+ int uid;
// Check permissions
if( (GetFlags(Client->UID) & USER_FLAG_TYPEMASK) < USER_TYPE_WHEEL ) {
sendf(Client->Socket, "407 USER_FLAGS requires 2 arguments, 1 given\n");
return ;
}
+ *space = '\0';
// - Flags
flags = space + 1;
while( *flags == ' ' ) flags ++;
space = strchr(flags, ' ');
if(space) *space = '\0';
- printf("Username = '%s', flags = '%s'\n", username, flags);
+ // Get UID
+ uid = GetUserID(username);
+ if( uid == -1 ) {
+ sendf(Client->Socket, "404 User '%s' not found\n", username);
+ return ;
+ }
+
+ // Parse flags
+ do {
+ int bRemove = 0;
+ int i;
+ struct {
+ const char *Name;
+ int Mask;
+ int Value;
+ } cFLAGS[] = {
+ {"disabled", USER_FLAG_DISABLED, USER_FLAG_DISABLED},
+ {"door", USER_FLAG_DOORGROUP, USER_FLAG_DOORGROUP},
+ {"user", USER_FLAG_TYPEMASK, USER_TYPE_NORMAL},
+ {"coke", USER_FLAG_TYPEMASK, USER_TYPE_COKE},
+ {"wheel", USER_FLAG_TYPEMASK, USER_TYPE_WHEEL},
+ {"meta", USER_FLAG_TYPEMASK, USER_TYPE_GOD}
+ };
+ const int ciNumFlags = sizeof(cFLAGS)/sizeof(cFLAGS[0]);
+
+ while( *flags == ' ' ) flags ++; // Eat whitespace
+ space = strchr(flags, ','); // Find the end of the flag
+ if(space) *space = '\0';
+
+ // Check for inversion/removal
+ if( *flags == '!' || *flags == '-' ) {
+ bRemove = 1;
+ flags ++;
+ }
+ else if( *flags == '+' ) {
+ flags ++;
+ }
+
+ // Check flag values
+ for( i = 0; i < ciNumFlags; i ++ )
+ {
+ if( strcmp(flags, cFLAGS[i].Name) == 0 ) {
+ mask |= cFLAGS[i].Mask;
+ value &= ~cFLAGS[i].Mask;
+ if( !bRemove )
+ value |= cFLAGS[i].Value;
+ break;
+ }
+ }
+
+ // Error check
+ if( i == ciNumFlags ) {
+ sendf(Client->Socket, "407 Unknown flag value '%s'\n", flags);
+ return ;
+ }
+
+ flags = space + 1;
+ } while(space);
+
+ // Apply flags
+ SetFlags(uid, mask, value);
+ // Return OK
sendf(Client->Socket, "200 User Updated\n");
}