--- Give to another user ---
c GIVE <user> <ammount> <reason>\n
s 200 Give OK\n or 402 Poor You\n or 404 Bad User\n
---- Update balance ---
+--- Alter balance ---
c ADD <user> <ammount> <reason>\n
+s 200 Add OK\n or 402 No balance\n or 403 Not Coke\n or 404 Bad User\n
+--- Set balance ---
+c SET <user> <ammount> <reason>\n
s 200 Add OK\n or 403 Not Coke\n or 404 Bad User\n
--- Get Item list ---
// --- Dispense ---
extern int DispenseItem(int User, tItem *Item);
extern int DispenseGive(int SrcUser, int DestUser, int Ammount, const char *ReasonGiven);
+extern int DispenseAdd(int User, int ByUser, int Ammount, const char *ReasonGiven);
// --- Logging ---
extern void Log_Error(const char *Format, ...);
}
// And log that it happened
- Log_Info("%s dispensed %s (%s:%i) [cost %i, balance %i cents]",
- username, Item->Name, handler->Name, Item->ID,
- Item->Price, GetBalance(User)
+ 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 );
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
+ 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
+ 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;
char *Server_Cmd_ENUMITEMS(tClient *Client, char *Args);
char *Server_Cmd_ITEMINFO(tClient *Client, char *Args);
char *Server_Cmd_DISPENSE(tClient *Client, char *Args);
+char *Server_Cmd_GIVE(tClient *Client, char *Args);
+char *Server_Cmd_ADD(tClient *Client, char *Args);
// --- Helpers ---
int GetUserAuth(const char *Salt, const char *Username, const uint8_t *Hash);
void HexBin(uint8_t *Dest, char *Src, int BufSize);
{"AUTOAUTH", Server_Cmd_AUTOAUTH},
{"ENUM_ITEMS", Server_Cmd_ENUMITEMS},
{"ITEM_INFO", Server_Cmd_ITEMINFO},
- {"DISPENSE", Server_Cmd_DISPENSE}
+ {"DISPENSE", Server_Cmd_DISPENSE},
+ {"GIVE", Server_Cmd_GIVE},
+ {"ADD", Server_Cmd_ADD}
};
#define NUM_COMMANDS (sizeof(gaServer_Commands)/sizeof(gaServer_Commands[0]))
int giServer_Socket;
}
}
+char *Server_Cmd_ADD(tClient *Client, char *Args)
+{
+ char *user, *ammount, *reason;
+ int uid, iAmmount;
+
+ if( !Client->bIsAuthed ) return strdup("401 Not Authenticated\n");
+
+ user = Args;
+
+ ammount = strchr(Args, ' ');
+ if( !ammount ) return strdup("407 Invalid Argument, expected 3 parameters, 1 encountered\n");
+ *ammount = '\0';
+ ammount ++;
+
+ reason = strchr(ammount, ' ');
+ if( !reason ) return strdup("407 Invalid Argument, expected 3 parameters, 2 encountered\n");
+ *reason = '\0';
+ reason ++;
+
+ // Get recipient
+ uid = GetUserID(user);
+ if( uid == -1 ) return strdup("404 Invalid user");
+
+ // Parse ammount
+ iAmmount = atoi(ammount);
+ if( iAmmount == 0 && ammount[0] != '0' ) return strdup("407 Invalid Argument, ammount must be > zero\n");
+
+ // Do give
+ switch( DispenseAdd(uid, Client->UID, iAmmount, reason) )
+ {
+ case 0:
+ return strdup("200 Add OK\n");
+ case 2:
+ return strdup("402 Poor Guy\n");
+ default:
+ return strdup("500 Unknown error\n");
+ }
+}
+
/**
* \brief Authenticate a user
* \return User ID, or -1 if authentication failed