+ free( actualUsername );
+ return 0; // 0: EOK
+}
+
+/**
+ * \brief Refund a dispense
+ */
+int DispenseRefund(int ActualUser, int DestUser, tItem *Item, int OverridePrice)
+{
+ int ret;
+ int src_acct, price;
+ char *username, *actualUsername;
+
+ src_acct = _GetSalesAcct(Item);
+
+ if( OverridePrice > 0 )
+ price = OverridePrice;
+ else
+ price = Item->Price;
+
+ ret = _Transfer( src_acct, DestUser, price, "Refund");
+ if(ret) return ret;
+
+ username = Bank_GetAcctName(DestUser);
+ actualUsername = Bank_GetAcctName(ActualUser);
+
+ Log_Info("refund '%s' (%s:%i) to %s by %s [cost %i, balance %i]",
+ Item->Name, Item->Handler->Name, Item->ID,
+ username, actualUsername, price, Bank_GetBalance(DestUser)
+ );
+
+ free(username);
+ free(actualUsername);
+
+ return 0;
+}
+
+/**
+ * \brief Give money from one user to another
+ */
+int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const char *ReasonGiven)
+{
+ int ret;
+ char *actualUsername;
+ char *srcName, *dstName;
+
+ // HACK: Naming a slot "dead" disables it (catch for snack)
+ if( strcmp(ReasonGiven, "dead") == 0 )
+ return 1;
+
+ if( Ammount < 0 ) return 1; // Um... negative give? Not on my watch!
+
+ ret = _Transfer( SrcUser, DestUser, Ammount, ReasonGiven );
+ if(ret) return 2; // No Balance
+
+
+ actualUsername = Bank_GetAcctName(ActualUser);
+ srcName = Bank_GetAcctName(SrcUser);
+ dstName = Bank_GetAcctName(DestUser);
+
+ Log_Info("give %i from %s to %s by %s [balances %i, %i] - %s",
+ Ammount, srcName, dstName, actualUsername,
+ Bank_GetBalance(SrcUser), Bank_GetBalance(DestUser),
+ ReasonGiven
+ );
+
+ free(srcName);
+ free(dstName);
+ free(actualUsername);
+
+ return 0;
+}
+
+#if 0 // Dead Code
+/**
+ * \brief Move money from one user to another (Admin Only)
+ */
+int DispenseTransfer(int ActualUser, int SrcUser, int DestUser, int Ammount, const char *ReasonGiven)
+{
+ int ret;
+ char *actualUsername;
+ char *srcName, *dstName;
+
+ // Make sure the user is an admin
+ if( !(Bank_GetFlags(ActualUser) & USER_FLAG_ADMIN) )
+ return 1;
+
+ ret = _Transfer( SrcUser, DestUser, Ammount, ReasonGiven );
+ if(ret) return 2; // No Balance
+
+
+ actualUsername = Bank_GetAcctName(ActualUser);
+ srcName = Bank_GetAcctName(SrcUser);
+ dstName = Bank_GetAcctName(DestUser);
+
+ Log_Info("move %i from %s to %s by %s [balances %i, %i] - %s",
+ Ammount, srcName, dstName, actualUsername,
+ Bank_GetBalance(SrcUser), Bank_GetBalance(DestUser),
+ ReasonGiven
+ );
+
+ free(srcName);
+ free(dstName);
+ free(actualUsername);
+
+ return 0;
+}
+#endif
+
+/**
+ * \brief Add money to an account
+ */
+int DispenseAdd(int ActualUser, int User, int Ammount, const char *ReasonGiven)
+{
+ int ret;
+ char *dstName, *byName;
+
+#if DISPENSE_ADD_BELOW_MIN
+ ret = _Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT,1), User, Ammount, ReasonGiven );
+#else
+ ret = Bank_Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT,1), User, Ammount, ReasonGiven );
+#endif
+ if(ret) return 2;
+
+ byName = Bank_GetAcctName(ActualUser);
+ dstName = Bank_GetAcctName(User);
+
+ Log_Info("add %i to %s by %s [balance %i] - %s",
+ Ammount, dstName, byName, Bank_GetBalance(User), ReasonGiven
+ );
+
+ free(byName);
+ free(dstName);
+
+ return 0;
+}
+
+int DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven)
+{
+ int curBal = Bank_GetBalance(User);
+ char *byName, *dstName;
+
+ _Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT,1), User, Balance-curBal, ReasonGiven );
+
+ byName = Bank_GetAcctName(ActualUser);
+ dstName = Bank_GetAcctName(User);
+
+ Log_Info("set balance of %s to %i by %s [balance %i] - %s",
+ dstName, Balance, byName, Bank_GetBalance(User), ReasonGiven
+ );
+
+ free(byName);
+ free(dstName);
+
+ return 0;
+}
+
+/**
+ * \brief Donate money to the club
+ */
+int DispenseDonate(int ActualUser, int User, int Ammount, const char *ReasonGiven)
+{
+ int ret;
+ char *srcName, *byName;
+
+ if( Ammount < 0 ) return 2;
+
+ ret = _Transfer( User, Bank_GetAcctByName(COKEBANK_DONATE_ACCT,1), Ammount, ReasonGiven );
+ if(ret) return 2;
+
+ byName = Bank_GetAcctName(ActualUser);
+ srcName = Bank_GetAcctName(User);
+
+ Log_Info("donate %i from %s by %s [balance %i] - %s",
+ Ammount, srcName, byName, Bank_GetBalance(User), ReasonGiven
+ );
+
+ free(byName);
+ free(srcName);
+