From: John Hodge Date: Sat, 5 Mar 2011 08:16:23 +0000 (+0800) Subject: Fixing up logging (slot renames and gives) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=7aab29aca5fcb29bf86beb6602a721bec4ba1d08;p=tpg%2Fopendispense2.git Fixing up logging (slot renames and gives) --- diff --git a/src/server/common.h b/src/server/common.h index d5fd43c..a216dd5 100644 --- a/src/server/common.h +++ b/src/server/common.h @@ -88,6 +88,7 @@ extern int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, 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 DispenseDonate(int ActualUser, int User, int Ammount, const char *ReasonGiven); +extern int DispenseUpdateItem(int User, tItem *Item, const char *NewName, int NewPrice); // --- Logging --- extern void Log_Error(const char *Format, ...); diff --git a/src/server/dispense.c b/src/server/dispense.c index 01b53c8..4c6bd51 100644 --- a/src/server/dispense.c +++ b/src/server/dispense.c @@ -31,6 +31,10 @@ int DispenseItem(int ActualUser, int User, tItem *Item) handler = Item->Handler; + // KNOWN HACK: Naming a slot "dead" disables it + if( strcmp(Item->Name, "dead") == 0 ) + return 1; + // Check if the dispense is possible if( handler->CanDispense ) { ret = handler->CanDispense( User, Item->ID ); @@ -44,8 +48,8 @@ int DispenseItem(int ActualUser, int User, tItem *Item) if( handler->DoDispense ) { ret = handler->DoDispense( User, Item->ID ); if(ret) { - Log_Error("Dispense failed (%s dispensing '%s' - %ic)", - username, Item->Name, Item->Price); + Log_Error("Dispense failed (%s dispensing %s:%i '%s')", + username, Item->Name, Item->Handler->Name, Item->ID); free( username ); return -1; // 1: Unknown Error again } @@ -125,8 +129,8 @@ int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const c srcName = Bank_GetAcctName(SrcUser); dstName = Bank_GetAcctName(DestUser); - Log_Info("give %i to %s from %s by %s [balances %i, %i] - %s", - Ammount, dstName, srcName, actualUsername, + 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 ); @@ -138,6 +142,7 @@ int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const c return 0; } +#if 0 // Dead Code /** * \brief Move money from one user to another (Admin Only) */ @@ -159,8 +164,8 @@ int DispenseTransfer(int ActualUser, int SrcUser, int DestUser, int Ammount, con srcName = Bank_GetAcctName(SrcUser); dstName = Bank_GetAcctName(DestUser); - Log_Info("move %i to %s from %s by %s [balances %i, %i] - %s", - Ammount, dstName, srcName, actualUsername, + 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 ); @@ -171,6 +176,8 @@ int DispenseTransfer(int ActualUser, int SrcUser, int DestUser, int Ammount, con return 0; } +#endif + /** * \brief Add money to an account */ @@ -245,6 +252,35 @@ int DispenseDonate(int ActualUser, int User, int Ammount, const char *ReasonGive return 0; } +int DispenseUpdateItem(int User, tItem *Item, const char *NewName, int NewPrice) +{ + char *username; + + // Sanity checks + if( NewPrice < 0 ) return 2; + if( !Item ) return 2; + if( strlen(NewName) < 1 ) return 2; + + // Update the item + free(Item->Name); + Item->Name = strdup(NewName); + Item->Price = NewPrice; + + username = Bank_GetAcctName(User); + + Log_Info("item %s:%i updated to '%s' %i by %s", + Item->Handler->Name, Item->ID, + NewName, NewPrice, username + ); + + free(username); + + // Update item file + Items_UpdateFile(); + + return 0; +} + // --- Internal Functions --- int _GetMinBalance(int Account) { diff --git a/src/server/server.c b/src/server/server.c index 26c7fb2..158726c 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -585,6 +585,10 @@ void Server_int_SendItem(tClient *Client, tItem *Item) } } + // KNOWN HACK: Naming a slot 'dead' disables it + if( strcmp(Item->Name, "dead") == 0 ) + status = "sold"; // Another status? + sendf(Client->Socket, "202 Item %s:%i %s %i %s\n", Item->Handler->Name, Item->ID, status, Item->Price, Item->Name @@ -1321,16 +1325,15 @@ void Server_Cmd_UPDATEITEM(tClient *Client, char *Args) sendf(Client->Socket, "407 Invalid price set\n"); } - // Update the item - free(item->Name); - item->Name = strdup(description); - item->Price = price; - - // Update item file - Items_UpdateFile(); - - // Return OK - sendf(Client->Socket, "200 Item updated\n"); + switch( DispenseUpdateItem( Client->UID, item, description, price ) ) + { + case 0: + // Return OK + sendf(Client->Socket, "200 Item updated\n"); + break; + default: + break; + } } // --- INTERNAL HELPERS ---