+ // Set slot
+ else if( strcmp(text_args[0], "slot") == 0 )
+ {
+ regmatch_t matches[3];
+ char *item_type, *newname;
+ int item_id, price;
+
+ // Check arguments
+ if( text_argc != 4 ) {
+ fprintf(stderr, "Error: `dispense slot` takes three arguments\n");
+ ShowUsage();
+ return RV_ARGUMENTS;
+ }
+
+ // Parse arguments
+ if( RunRegex(&gUserItemIdentRegex, text_args[1], 3, matches, NULL) != 0 ) {
+ fprintf(stderr, "Error: Invalid item ID passed (<type>:<id> expected)\n");
+ return RV_ARGUMENTS;
+ }
+ item_type = text_args[1] + matches[1].rm_so;
+ text_args[1][ matches[1].rm_eo ] = '\0';
+ item_id = atoi( text_args[1] + matches[2].rm_so );
+
+ // - Price
+ price = atoi( text_args[2] );
+ if( price <= 0 && text_args[2][0] != '0' ) {
+ fprintf(stderr, "Error: Invalid price passed (must be >= 0)\n");
+ return RV_ARGUMENTS;
+ }
+
+ // - New name
+ newname = text_args[3];
+ // -- Sanity
+ {
+ char *pos;
+ for( pos = newname; *pos; pos ++ )
+ {
+ if( !isalnum(*pos) && *pos != ' ' ) {
+ fprintf(stderr, "Error: You should only have letters, numbers and spaces in an item name\n");
+ return RV_ARGUMENTS;
+ }
+ }
+ }
+
+ // Connect & Authenticate
+ sock = OpenConnection(gsDispenseServer, giDispensePort);
+ if( sock < 0 ) return RV_SOCKET_ERROR;
+ ret = Authenticate(sock);
+ if(ret) return ret;
+ // Update the slot
+ ret = Dispense_SetItem(sock, item_type, item_id, price, newname);
+
+ close(sock);
+ return ret;
+ }