+
+int Server_int_ParseFlags(tClient *Client, const char *Str, int *Mask, int *Value)
+{
+ struct {
+ const char *Name;
+ int Mask;
+ int Value;
+ } cFLAGS[] = {
+ {"disabled", USER_FLAG_DISABLED, USER_FLAG_DISABLED}
+ ,{"door", USER_FLAG_DOORGROUP, USER_FLAG_DOORGROUP}
+ ,{"coke", USER_FLAG_COKE, USER_FLAG_COKE}
+ ,{"admin", USER_FLAG_ADMIN, USER_FLAG_ADMIN}
+ ,{"internal", USER_FLAG_INTERNAL, USER_FLAG_INTERNAL}
+ };
+ const int ciNumFlags = sizeof(cFLAGS)/sizeof(cFLAGS[0]);
+
+ char *space;
+
+ *Mask = 0;
+ *Value = 0;
+
+ do {
+ int bRemove = 0;
+ int i;
+ int len;
+
+ while( *Str == ' ' ) Str ++; // Eat whitespace
+ space = strchr(Str, ','); // Find the end of the flag
+ if(space)
+ len = space - Str;
+ else
+ len = strlen(Str);
+
+ // Check for inversion/removal
+ if( *Str == '!' || *Str == '-' ) {
+ bRemove = 1;
+ Str ++;
+ }
+ else if( *Str == '+' ) {
+ Str ++;
+ }
+
+ // Check flag values
+ for( i = 0; i < ciNumFlags; i ++ )
+ {
+ if( strncmp(Str, cFLAGS[i].Name, len) == 0 ) {
+ *Mask |= cFLAGS[i].Mask;
+ *Value &= ~cFLAGS[i].Mask;
+ if( !bRemove )
+ *Value |= cFLAGS[i].Value;
+ break;
+ }
+ }
+
+ // Error check
+ if( i == ciNumFlags ) {
+ char val[len+1];
+ strncpy(val, Str, len+1);
+ sendf(Client->Socket, "407 Unknown flag value '%s'\n", val);
+ return -1;
+ }
+
+ Str = space + 1;
+ } while(space);
+
+ return 0;
+}