+ else
+ {
+ fprintf(stderr, "Error: Unknown sub-command for `dispense user`\n");
+ ShowUsage();
+ return RV_ARGUMENTS;
+ }
+ close(sock);
+ return ret;
+ }
+ // Donation!
+ else if( strcmp(gsTextArgs[0], "donate") == 0 )
+ {
+ // Check argument count
+ if( giTextArgc != 3 ) {
+ fprintf(stderr, "Error: `dispense donate` requires two arguments\n");
+ ShowUsage();
+ return RV_ARGUMENTS;
+ }
+
+ // Connect to server
+ sock = OpenConnection(gsDispenseServer, giDispensePort);
+ if( sock < 0 ) return RV_SOCKET_ERROR;
+
+ // Attempt authentication
+ ret = Authenticate(sock);
+ if(ret) return ret;
+
+ // Do donation
+ ret = Dispense_Donate(sock, atoi(gsTextArgs[1]), gsTextArgs[2]);
+
+ close(sock);
+
+ return ret;
+ }
+ // Refund an item
+ else if( strcmp(gsTextArgs[0], "refund") == 0 )
+ {
+ int price = 0;
+ // Check argument count
+ if( giTextArgc != 3 && giTextArgc != 4 ) {
+ fprintf(stderr, "Error: `dispense refund` takes 2 or 3 arguments\n");
+ ShowUsage();
+ return RV_ARGUMENTS;
+ }
+
+ // Connect to server
+ sock = OpenConnection(gsDispenseServer, giDispensePort);
+ if(sock < 0) return RV_SOCKET_ERROR;
+
+ // Attempt authentication
+ ret = Authenticate(sock);
+ if(ret) return ret;
+
+ if( giTextArgc == 4 ) {
+ price = atoi(gsTextArgs[3]);
+ if( price <= 0 ) {
+ fprintf(stderr, "Error: Override price is invalid (should be > 0)\n");
+ return RV_ARGUMENTS;
+ }
+ }
+
+ // Username, Item, cost
+ ret = Dispense_Refund(sock, gsTextArgs[1], gsTextArgs[2], price);
+
+ // TODO: More
+ close(sock);
+ return ret;
+ }
+ // Query an item price
+ else if( strcmp(gsTextArgs[0], "iteminfo") == 0 )
+ {
+ regmatch_t matches[3];
+ char *type;
+ int id;
+ // Check argument count
+ if( giTextArgc != 2 ) {
+ fprintf(stderr, "Error: `dispense iteminfo` requires an argument\n");
+ ShowUsage();
+ return RV_ARGUMENTS;
+ }
+ // Parse item ID
+ if( RunRegex(&gUserItemIdentRegex, gsTextArgs[1], 3, matches, NULL) != 0 ) {
+ fprintf(stderr, "Error: Invalid item ID passed (<type>:<id> expected)\n");
+ return RV_ARGUMENTS;
+ }
+ type = gsTextArgs[1] + matches[1].rm_so;
+ gsTextArgs[1][ matches[1].rm_eo ] = '\0';
+ id = atoi( gsTextArgs[1] + matches[2].rm_so );
+
+ sock = OpenConnection(gsDispenseServer, giDispensePort);
+ if( sock < 0 ) return RV_SOCKET_ERROR;
+
+ ret = Dispense_ItemInfo(sock, type, id);
+ close(sock);
+ return ret;
+ }
+ // Set slot
+ else if( strcmp(gsTextArgs[0], "slot") == 0 )
+ {
+ regmatch_t matches[3];
+ char *item_type, *newname;
+ int item_id, price;
+
+ // Check arguments
+ if( giTextArgc != 4 ) {
+ fprintf(stderr, "Error: `dispense slot` takes three arguments\n");
+ ShowUsage();
+ return RV_ARGUMENTS;
+ }
+
+ // Parse arguments
+ if( RunRegex(&gUserItemIdentRegex, gsTextArgs[1], 3, matches, NULL) != 0 ) {
+ fprintf(stderr, "Error: Invalid item ID passed (<type>:<id> expected)\n");
+ return RV_ARGUMENTS;
+ }
+ item_type = gsTextArgs[1] + matches[1].rm_so;
+ gsTextArgs[1][ matches[1].rm_eo ] = '\0';
+ item_id = atoi( gsTextArgs[1] + matches[2].rm_so );
+
+ // - Price
+ price = atoi( gsTextArgs[2] );
+ if( price <= 0 && gsTextArgs[2][0] != '0' ) {
+ fprintf(stderr, "Error: Invalid price passed (must be >= 0)\n");
+ return RV_ARGUMENTS;