X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fserver%2Fserver.c;h=8138f1eb63240925a6e991ca1b0cbc8efba0f2c7;hb=ffc52312097ac25aaca6d20a132242f5f0670c5b;hp=9c36f3d7ce279eafa6a13003ef6bebf813d4d0fb;hpb=2402457fd4ea286febae34182d9a9f3b63cb6565;p=tpg%2Fopendispense2.git diff --git a/src/server/server.c b/src/server/server.c index 9c36f3d..8138f1e 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -61,6 +61,7 @@ void Server_Cmd_DISPENSE(tClient *Client, char *Args); void Server_Cmd_GIVE(tClient *Client, char *Args); void Server_Cmd_DONATE(tClient *Client, char *Args); void Server_Cmd_ADD(tClient *Client, char *Args); +void Server_Cmd_SET(tClient *Client, char *Args); void Server_Cmd_ENUMUSERS(tClient *Client, char *Args); void Server_Cmd_USERINFO(tClient *Client, char *Args); void _SendUserInfo(tClient *Client, int UserID); @@ -86,6 +87,7 @@ const struct sClientCommand { {"GIVE", Server_Cmd_GIVE}, {"DONATE", Server_Cmd_DONATE}, {"ADD", Server_Cmd_ADD}, + {"SET", Server_Cmd_SET}, {"ENUM_USERS", Server_Cmd_ENUMUSERS}, {"USER_INFO", Server_Cmd_USERINFO}, {"USER_ADD", Server_Cmd_USERADD}, @@ -771,6 +773,75 @@ void Server_Cmd_ADD(tClient *Client, char *Args) } } +void Server_Cmd_SET(tClient *Client, char *Args) +{ + char *user, *ammount, *reason; + int uid, iAmmount; + + if( !Client->bIsAuthed ) { + sendf(Client->Socket, "401 Not Authenticated\n"); + return ; + } + + user = Args; + + ammount = strchr(Args, ' '); + if( !ammount ) { + sendf(Client->Socket, "407 Invalid Argument, expected 3 parameters, 1 encountered\n"); + return ; + } + *ammount = '\0'; + ammount ++; + + reason = strchr(ammount, ' '); + if( !reason ) { + sendf(Client->Socket, "407 Invalid Argument, expected 3 parameters, 2 encountered\n"); + return ; + } + *reason = '\0'; + reason ++; + + // Check user permissions + if( !(Bank_GetFlags(Client->UID) & USER_FLAG_ADMIN) ) { + sendf(Client->Socket, "403 Not an admin\n"); + return ; + } + + // Get recipient + uid = Bank_GetAcctByName(user); + if( uid == -1 ) { + sendf(Client->Socket, "404 Invalid user\n"); + return ; + } + + // You can't alter an internal account + if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) { + sendf(Client->Socket, "404 Invalid user\n"); + return ; + } + + // Parse ammount + iAmmount = atoi(ammount); + if( iAmmount == 0 && ammount[0] != '0' ) { + sendf(Client->Socket, "407 Invalid Argument\n"); + return ; + } + + // Do give + switch( DispenseSet(Client->UID, uid, iAmmount, reason) ) + { + case 0: + sendf(Client->Socket, "200 Add OK\n"); + return ; + case 2: + sendf(Client->Socket, "402 Poor Guy\n"); + return ; + default: + sendf(Client->Socket, "500 Unknown error\n"); + return ; + } +} + void Server_Cmd_ENUMUSERS(tClient *Client, char *Args) { int i, numRet = 0;