From: John Hodge Date: Wed, 23 Feb 2011 13:33:43 +0000 (+0800) Subject: Commenting, fixed Ctrl-C not working, Fixed a segfault in the server, X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f3e7bcadc603e1632c268d3a209d218123423bfa;p=tpg%2Fopendispense2.git Commenting, fixed Ctrl-C not working, Fixed a segfault in the server, Added Dispense_Transfer (not implemented as a command yet) --- diff --git a/src/client/main.c b/src/client/main.c index 07fb0b4..95fd74e 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -182,11 +182,7 @@ int main(int argc, char *argv[]) case 'n': // Dry Run / read-only gbDryRun = 1; break; - case '0': case '1': - case '2': case '3': - case '4': case '5': - case '6': case '7': - case '8': case '9': + default: if( text_argc + 1 == MAX_TXT_ARGS ) { fprintf(stderr, "ERROR: Too many arguments\n"); @@ -217,7 +213,7 @@ int main(int argc, char *argv[]) // Connect to server sock = OpenConnection(gsDispenseServer, giDispensePort); if( sock < 0 ) return -1; - // List accounts? + // List accounts? if( text_argc == 1 ) { ret = Dispense_EnumUsers(sock); close(sock); @@ -641,7 +637,7 @@ int ShowNCursesUI(void) // Enter curses mode initscr(); - raw(); noecho(); + cbreak(); noecho(); // Get max index maxItemIndex = ShowItemAt(0, 0, 0, -1, 0); diff --git a/src/server/dispense.c b/src/server/dispense.c index 3fb5652..215e580 100644 --- a/src/server/dispense.c +++ b/src/server/dispense.c @@ -105,6 +105,39 @@ int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const c return 0; } +/** + * \brief Move money from one user to another (Admin Only) + */ +int DispenseTransfer(int ActualUser, int SrcUser, int DestUser, int Ammount, const char *ReasonGiven) +{ + int ret; + char *actualUsername; + char *srcName, *dstName; + + // Make sure the user is an admin + if( !(Bank_GetFlags(ActualUser) & USER_FLAG_ADMIN) ) + return 1; + + ret = _Transfer( SrcUser, DestUser, Ammount, ReasonGiven ); + if(ret) return 2; // No Balance + + + actualUsername = Bank_GetAcctName(ActualUser); + 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, + Bank_GetBalance(SrcUser), Bank_GetBalance(DestUser), + ReasonGiven + ); + + free(srcName); + free(dstName); + free(actualUsername); + + return 0; +} /** * \brief Add money to an account */ diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index 12e2431..867ac6a 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -21,7 +21,7 @@ #include #define READ_TIMEOUT 2 // 2 seconds for ReadChar -#define TRACE_COKE 1 +#define TRACE_COKE 0 #if TRACE_COKE # define TRACE(v...) do{printf("%s: ",__func__);printf(v);}while(0) diff --git a/src/server/server.c b/src/server/server.c index dbcc94b..aa9f008 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -310,6 +310,7 @@ void Server_ParseClientCommand(tClient *Client, char *CommandString) if( Server_int_ParseArgs(1, CommandString, &command, &args, NULL) ) { + if( command == NULL ) return ; // printf("command=%s, args=%s\n", command, args); // Is this an error? (just ignore for now) //args = "";