- if( responseCode != 200 ) {
- fprintf(stderr, "Unknown response from dispense server %i\n'%s'",
- responseCode, buf
- );
- exit(-1);
- }
-
- free(buf);
-}
-
-/**
- * \brief Dispense an item
- * \return Boolean Failure
- */
-int DispenseItem(int Socket, int ItemID)
-{
- int ret, responseCode;
- char *buf;
-
- if( ItemID < 0 || ItemID > giNumItems ) return -1;
-
- // Dispense!
- sendf(Socket, "DISPENSE %s:%i\n", gaItems[ItemID].Type, gaItems[ItemID].ID);
- buf = ReadLine(Socket);
-
- responseCode = atoi(buf);
- switch( responseCode )
- {
- case 200:
- printf("Dispense OK\n");
- ret = 0;
- break;
- case 401:
- printf("Not authenticated\n");
- ret = 1;
- break;
- case 402:
- printf("Insufficient balance\n");
- ret = 1;
- break;
- case 406:
- printf("Bad item name, bug report\n");
- ret = 1;
- break;
- case 500:
- printf("Item failed to dispense, is the slot empty?\n");
- ret = 1;
- break;
- case 501:
- printf("Dispense not possible (slot empty/permissions)\n");
- ret = 1;
- break;
- default:
- printf("Unknown response code %i ('%s')\n", responseCode, buf);
- ret = -2;
- break;
- }
-
- free(buf);
- return ret;
-}
-
-/**
- * \brief Alter a user's balance
- */
-int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const char *Reason)
-{
- char *buf;
- int responseCode;
-
- sendf(Socket, "ADD %s %i %s\n", Username, Ammount, Reason);
- buf = ReadLine(Socket);
-
- responseCode = atoi(buf);
- free(buf);
-
- switch(responseCode)
- {
- case 200: return 0; // OK
- case 402:
- fprintf(stderr, "Insufficient balance\n");
- return 1;
- 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;
-}
-
-/**
- * \brief Set a user's balance
- * \note Only avaliable to dispense admins
- */
-int Dispense_SetBalance(int Socket, const char *Username, int Balance, const char *Reason)
-{
- char *buf;
- int responseCode;
-
- sendf(Socket, "SET %s %i %s\n", Username, Balance, 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 an admin\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;
-}
-
-/**
- * \brief Give money to another user
- */
-int Dispense_Give(int Socket, const char *Username, int Ammount, const char *Reason)
-{
- char *buf;
- int responseCode;
-
- if( Ammount < 0 ) {
- printf("Sorry, you can only give, you can't take.\n");
- return -1;
- }
-
- // Fast return on zero
- if( Ammount == 0 ) {
- printf("Are you actually going to give any?\n");
- return 0;
- }
-
- sendf(Socket, "GIVE %s %i %s\n", Username, Ammount, Reason);
- buf = ReadLine(Socket);
-
- responseCode = atoi(buf);
- free(buf);
-
- switch(responseCode)
- {
- case 200: return 0; // OK
-
- case 402:
- fprintf(stderr, "Insufficient balance\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;
-}
-
-
-/**
- * \brief Donate money to the club
- */
-int Dispense_Donate(int Socket, int Ammount, const char *Reason)
-{
- char *buf;
- int responseCode;
-
- if( Ammount < 0 ) {
- printf("Sorry, you can only give, you can't take.\n");
- return -1;
- }
-
- // Fast return on zero
- if( Ammount == 0 ) {
- printf("Are you actually going to give any?\n");
- return 0;
- }
-
- sendf(Socket, "DONATE %i %s\n", Ammount, Reason);
- buf = ReadLine(Socket);
-
- responseCode = atoi(buf);
- free(buf);
-
- switch(responseCode)
- {
- case 200: return 0; // OK
-
- case 402:
- fprintf(stderr, "Insufficient balance\n");
- return 1;
-
- default:
- fprintf(stderr, "Unknown response code %i\n", responseCode);
- return -1;
- }
-
- return -1;
-}
-
-/**
- * \brief Enumerate users
- */
-int Dispense_EnumUsers(int Socket)
-{
- char *buf;
- int responseCode;
- int nUsers;
- regmatch_t matches[4];
-
- if( giMinimumBalance != INT_MIN ) {
- if( giMaximumBalance != INT_MAX ) {
- sendf(Socket, "ENUM_USERS min_balance:%i max_balance:%i\n", giMinimumBalance, giMaximumBalance);
- }
- else {
- sendf(Socket, "ENUM_USERS min_balance:%i\n", giMinimumBalance);