int ret;
tHandler *handler;
char *username;
+ char *reason;
handler = Item->Handler;
// Check if the dispense is possible
if( handler->CanDispense ) {
ret = handler->CanDispense( User, Item->ID );
- if(!ret) return 1; // 1: Unknown Error
+ if(ret) return 1; // 1: Unable to dispense
}
-
+
// Subtract the balance
- ret = Transfer( User, GetUserID(">sales"), Item->Price, "" );
- // What value should I use for this error?
- // AlterBalance should return the final user balance
- if(ret != 0) return 2; // 2: No balance
+ reason = mkstr("Dispense - %s:%i %s", handler->Name, Item->ID, Item->Name);
+ if( !reason ) reason = Item->Name; // TODO: Should I instead return an error?
+ ret = Transfer( User, GetUserID(">sales"), Item->Price, reason);
+ free(reason);
+ if(ret) return 2; // 2: No balance
// Get username for debugging
username = GetUserName(User);
}
// And log that it happened
- Log_Info("Dispensed %s (%i:%i) for %s [cost %i, balance %i cents]",
+ Log_Info("dispense %s (%s:%i) by %s [cost %i, balance %i cents]",
Item->Name, handler->Name, Item->ID,
username, Item->Price, GetBalance(User)
);
free( username );
return 0; // 0: EOK
}
+
+/**
+ * \brief Give money from one user to another
+ */
+int DispenseGive(int SrcUser, int DestUser, int Ammount, const char *ReasonGiven)
+{
+ int ret;
+ if( Ammount < 0 ) return 1; // Um... negative give? Not on my watch!
+
+ ret = Transfer( SrcUser, DestUser, Ammount, ReasonGiven );
+ if(ret) return 2; // No Balance
+
+ Log_Info("give %i to %s from %s (%s)",
+ Ammount, GetUserName(DestUser), GetUserName(SrcUser), ReasonGiven
+ );
+
+ return 0;
+}
+
+int DispenseAdd(int User, int ByUser, int Ammount, const char *ReasonGiven)
+{
+ int ret;
+
+ ret = Transfer( GetUserID(">liability"), User, Ammount, ReasonGiven );
+
+ if(ret) return 2;
+
+ Log_Info("add %i to %s by %s (%s)",
+ Ammount, GetUserName(User), GetUserName(ByUser), ReasonGiven
+ );
+
+ return 0;
+}