From 5052045f47aaa833eb9651e5b90402acd35f6754 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 21 Mar 2014 22:37:11 +0800 Subject: [PATCH] Server - Separate account for 'add' --- dispsrv.conf | 29 ++++++++++++++++++++++------- src/cokebank.h | 3 ++- src/server/common.h | 2 +- src/server/dispense.c | 11 ++++++----- src/server/server.c | 10 ++++------ 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/dispsrv.conf b/dispsrv.conf index 5039948..2043708 100644 --- a/dispsrv.conf +++ b/dispsrv.conf @@ -1,14 +1,29 @@ # # OpenDispense2 Server config file # -daemonise no -server_port 11020 +daemonise yes +server_port 11021 cokebank_database cokebank.db items_file items.cfg -door_serial_port /dev/ttyS0 -coke_modbus_address 130.95.13.72 +# PLC - coke brain +#coke_modbus_address 130.95.13.73 +coke_modbus_address 0.0.0.0 -trusted_host 192.168.1.39 -trusted_host 192.168.1.34 -trusted_host 192.168.1.37 +# Zero price items, defaults to off +test_mode no +#test_mode yes + +# Used to set dispense into a dummy mode when the coke machine is out of action +# and we're dispensing drinks from the fridge (or manually) +coke_dummy_mode no +#coke_dummy_mode yes + +door_serial_port /dev/ttyUSB0 +door_unlocked_delay 10 + +trusted_host 130.95.13.4 # Merlo +trusted_host 130.95.13.7 # motsugo +trusted_host 130.95.13.18 # mussel +trusted_host 130.95.13.23 # martello +trusted_host 130.95.13.42 # meersau diff --git a/src/cokebank.h b/src/cokebank.h index 13d0bb5..1ea8120 100644 --- a/src/cokebank.h +++ b/src/cokebank.h @@ -18,7 +18,8 @@ #define COKEBANK_SALES_ACCT ">sales" //!< Sales made into #define COKEBANK_SALES_PREFIX ">sales:" //!< Sales made into -#define COKEBANK_DEBT_ACCT ">countersum" //!< Credit taken out of +#define COKEBANK_ADDSRC_ACCT ">delta" //!< Credit taken out of +#define COKEBANK_DEBT_ACCT ">countersum" //!< Balancing account (causes sum to be 0) #define COKEBANK_FREE_ACCT ">freeitems" //!< ODay drink costs taken out of #define COKEBANK_DONATE_ACCT ">donations" //!< Donations go here #define COKEBANK_GRAT_ACCR ">gratuities" //!< Coke runs and new users diff --git a/src/server/common.h b/src/server/common.h index 74c42d9..8a80497 100644 --- a/src/server/common.h +++ b/src/server/common.h @@ -91,7 +91,7 @@ extern int DispenseItem(int ActualUser, int User, tItem *Item); extern int DispenseRefund(int ActualUser, int DestUser, tItem *Item, int OverridePrice); extern int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const char *ReasonGiven); extern int DispenseAdd(int ActualUser, int User, int Ammount, const char *ReasonGiven); -extern int DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven); +extern int DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven, int *OrigBalance); extern int DispenseDonate(int ActualUser, int User, int Ammount, const char *ReasonGiven); extern int DispenseUpdateItem(int User, tItem *Item, const char *NewName, int NewPrice); diff --git a/src/server/dispense.c b/src/server/dispense.c index 181181f..8ec7c2e 100644 --- a/src/server/dispense.c +++ b/src/server/dispense.c @@ -203,9 +203,9 @@ int DispenseAdd(int ActualUser, int User, int Ammount, const char *ReasonGiven) char *dstName, *byName; #if DISPENSE_ADD_BELOW_MIN - ret = _Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT,1), User, Ammount, ReasonGiven ); + ret = _Transfer( Bank_GetAcctByName(COKEBANK_ADDSRC_ACCT,1), User, Ammount, ReasonGiven ); #else - ret = Bank_Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT,1), User, Ammount, ReasonGiven ); + ret = Bank_Transfer( Bank_GetAcctByName(COKEBANK_ADDSRC_ACCT,1), User, Ammount, ReasonGiven ); #endif if(ret) return 2; @@ -222,7 +222,7 @@ int DispenseAdd(int ActualUser, int User, int Ammount, const char *ReasonGiven) return 0; } -int DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven) +int DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven, int *OrigBalance) { int curBal = Bank_GetBalance(User); char *byName, *dstName; @@ -232,10 +232,11 @@ int DispenseSet(int ActualUser, int User, int Balance, const char *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 + Log_Info("set balance of %s to %i by %s [was %i, balance %i] - %s", + dstName, Balance, byName, curBal, Bank_GetBalance(User), ReasonGiven ); + *OrigBalance = curBal; free(byName); free(dstName); diff --git a/src/server/server.c b/src/server/server.c index e76c459..c41cc2c 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -1165,17 +1165,15 @@ void Server_Cmd_SET(tClient *Client, char *Args) return ; } + int origBalance, rv; // Do give - switch( DispenseSet(Client->UID, uid, iAmmount, reason) ) + switch( rv = DispenseSet(Client->UID, uid, iAmmount, reason, &origBalance) ) { case 0: - sendf(Client->Socket, "200 Add OK\n"); - return ; - case 2: - sendf(Client->Socket, "402 Poor Guy\n"); + sendf(Client->Socket, "200 Add OK (%i)\n", origBalance); return ; default: - sendf(Client->Socket, "500 Unknown error\n"); + sendf(Client->Socket, "500 Unknown error (%i)\n", rv); return ; } } -- 2.20.1