};
// === PROTOTYPES ===
-static int GetUnixID(const char *Name);
+static int GetUnixID(const char *Username);
// === GLOBALS ===
tUser *gaBank_Users;
FILE *gBank_File;
// === CODE ===
-int Bank_GetUserByUnixID(int UnixID)
+int Bank_GetUserByName(const char *Username)
{
- int i;
+ int i, uid;
+
+ uid = GetUnixID(Username);
+
// Expensive search :(
for( i = 0; i < giBank_NumUsers; i ++ )
{
- if( gaBank_Users[i].UnixID == UnixID )
+ if( gaBank_Users[i].UnixID == uid )
return i;
}
// --- Dispense ---
extern int DispenseItem(int User, tItem *Item);
+extern int DispenseGive(int SrcUser, int DestUser, int Ammount, const char *ReasonGiven);
// --- Logging ---
extern void Log_Error(const char *Format, ...);
}
// And log that it happened
- Log_Info("Dispensed %s (%s:%i) for %s [cost %i, balance %i cents]",
- Item->Name, handler->Name, Item->ID,
- username, Item->Price, GetBalance(User)
+ Log_Info("%s dispensed %s (%s:%i) [cost %i, balance %i cents]",
+ username, Item->Name, handler->Name, Item->ID,
+ 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("%s gave %i to %s (%s)",
+ GetUserName(SrcUser), Ammount, GetUserName(DestUser), ReasonGiven
+ );
+
+ return 0;
+}
*/
char *Server_Cmd_ENUMITEMS(tClient *Client, char *Args)
{
-// int nItems = giNumItems;
int retLen;
int i;
char *ret;
if( iAmmount <= 0 ) return strdup("407 Invalid Argument, ammount must be > zero\n");
// Do give
- switch( Transfer(Client->UID, uid, iAmmount, reason) )
+ switch( DispenseGive(Client->UID, uid, iAmmount, reason) )
{
case 0:
return strdup("200 Give OK\n");
- default:
+ case 2:
return strdup("402 Poor You\n");
+ default:
+ return strdup("500 Unknown error\n");
}
}