+ fprintf(stderr, "Unknown response code %i\n", responseCode);
+ return -1;
+ }
+
+ return -1;
+}
+
+/**
+ * \brief Alter a user's balance
+ */
+int Dispense_SetBalance(int Socket, const char *Username, int Ammount, const char *Reason)
+{
+ char *buf;
+ int responseCode;
+
+ sendf(Socket, "SET %s %i %s\n", Username, Ammount, Reason);
+ buf = ReadLine(Socket);
+
+ responseCode = atoi(buf);
+ free(buf);
+
+ switch(responseCode)
+ {
+ case 200: return 0; // OK
+ case 403: // Not in coke
+ fprintf(stderr, "You are not in coke (sucker)\n");
+ return 1;
+ case 404: // Unknown user
+ fprintf(stderr, "Unknown user '%s'\n", Username);
+ return 2;
+ default:
+ fprintf(stderr, "Unknown response code %i\n", responseCode);
+ return -1;
+ }
+
+ return -1;
+}
+
+int Dispense_EnumUsers(int Socket)
+{
+ printf("TODO: Dispense_EnumUsers\n");
+ return -1;
+}
+
+int Dispense_ShowUser(int Socket, const char *Username)
+{
+ char *buf;
+ int responseCode, ret;
+
+ sendf(Socket, "USER_INFO %s\n", Username);
+ buf = ReadLine(Socket);
+
+ responseCode = atoi(buf);
+
+ switch(responseCode)
+ {
+ case 202:
+ _PrintUserLine(buf);
+ ret = 0;
+ break;
+
+ case 404:
+ printf("Unknown user '%s'\n", Username);
+ ret = 1;
+ break;
+
+ default:
+ fprintf(stderr, "Unknown response code %i '%s'\n", responseCode, buf);
+ ret = -1;
+ break;
+ }
+
+ free(buf);
+
+ return ret;
+}
+
+void _PrintUserLine(const char *Line)
+{
+ regmatch_t matches[6];
+ int bal;
+
+ RunRegex(&gUserInfoRegex, Line, 6, matches, "Malformed server response");
+ // 3: Username
+ // 4: Balance
+ // 5: Flags
+ {
+ int usernameLen = matches[3].rm_eo - matches[3].rm_so;
+ char username[usernameLen + 1];
+ int flagsLen = matches[5].rm_eo - matches[5].rm_so;
+ char flags[flagsLen + 1];
+
+ memcpy(username, Line + matches[3].rm_so, usernameLen);
+ username[usernameLen] = '\0';
+ memcpy(flags, Line + matches[5].rm_so, flagsLen);
+ flags[flagsLen] = '\0';
+
+ bal = atoi(Line + matches[4].rm_so);
+ printf("%-15s: $%i.%02i (%s)\n", username, bal/100, bal%100, flags);