+
+// Takes a series of char *'s in
+/**
+ * \brief Parse space-separated entries into
+ */
+int Server_int_ParseArgs(int bUseLongLast, char *ArgStr, ...)
+{
+ va_list args;
+ char savedChar;
+ char **dest;
+ va_start(args, ArgStr);
+
+ // Check for null
+ if( !ArgStr )
+ {
+ while( (dest = va_arg(args, char **)) )
+ *dest = NULL;
+ va_end(args);
+ return 1;
+ }
+
+ savedChar = *ArgStr;
+
+ while( (dest = va_arg(args, char **)) )
+ {
+ // Trim leading spaces
+ while( *ArgStr == ' ' || *ArgStr == '\t' )
+ ArgStr ++;
+
+ // ... oops, not enough arguments
+ if( *ArgStr == '\0' )
+ {
+ // NULL unset arguments
+ do {
+ *dest = NULL;
+ } while( (dest = va_arg(args, char **)) );
+ va_end(args);
+ return -1;
+ }
+
+ if( *ArgStr == '"' )
+ {
+ ArgStr ++;
+ *dest = ArgStr;
+ // Read until quote
+ while( *ArgStr && *ArgStr != '"' )
+ ArgStr ++;
+ }
+ else
+ {
+ // Set destination
+ *dest = ArgStr;
+ // Read until a space
+ while( *ArgStr && *ArgStr != ' ' && *ArgStr != '\t' )
+ ArgStr ++;
+ }
+ savedChar = *ArgStr; // savedChar is used to un-mangle the last string
+ *ArgStr = '\0';
+ ArgStr ++;
+ }
+ va_end(args);
+
+ // Oops, extra arguments, and greedy not set
+ if( (savedChar == ' ' || savedChar == '\t') && !bUseLongLast ) {
+ return -1;
+ }
+
+ // Un-mangle last
+ if(bUseLongLast) {
+ ArgStr --;
+ *ArgStr = savedChar;
+ }
+
+ return 0; // Success!
+}
+
+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;
+}