+
+/**
+ * \brief Parses a client command and calls the required helper function
+ * \param Client Pointer to client state structure
+ */
+char *Server_ParseClientCommand(tClient *Client, char *CommandString)
+{
+ char *space, *args;
+ int i;
+
+ // Split at first space
+ space = strchr(CommandString, ' ');
+ if(space == NULL) {
+ args = NULL;
+ }
+ else {
+ *space = '\0';
+ args = space + 1;
+ }
+
+ // Find command
+ for( i = 0; i < NUM_COMMANDS; i++ )
+ {
+ if(strcmp(CommandString, gaServer_Commands[i].Name) == 0)
+ return gaServer_Commands[i].Function(Client, args);
+ }
+
+ return strdup("400 Unknown Command\n");
+}
+
+// ---
+// Commands
+// ---
+/**
+ * \brief Set client username
+ */
+char *Server_Cmd_USER(tClient *Client, char *Args)
+{
+ char *ret;
+
+ // Debug!
+ if( gbDebugLevel )
+ printf("Client %i authenticating as '%s'\n", Args);
+
+ // Save username
+ if(Client->Username)
+ free(Client->Username);
+ Client->Username = strdup(Args);
+
+ // Create a salt (that changes if the username is changed)
+ if(!Client->Salt)
+ Client->Salt = malloc(9);
+ Client->Salt[0] = 0x21 + (rand()&0x3F);
+ Client->Salt[1] = 0x21 + (rand()&0x3F);
+ Client->Salt[2] = 0x21 + (rand()&0x3F);
+ Client->Salt[3] = 0x21 + (rand()&0x3F);
+ Client->Salt[4] = 0x21 + (rand()&0x3F);
+ Client->Salt[5] = 0x21 + (rand()&0x3F);
+ Client->Salt[6] = 0x21 + (rand()&0x3F);
+ Client->Salt[7] = 0x21 + (rand()&0x3F);
+
+ // "100 Salt xxxxXXXX\n"
+ ret = strdup("100 SALT xxxxXXXX\n");
+ sprintf(ret, "100 SALT %s\n", Client->Salt);
+
+ return ret;
+}