From: John Hodge Date: Thu, 6 Jan 2011 03:08:53 +0000 (+0800) Subject: Removed debug from server, cleaning client X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=aa3dd36e517de4388f798eb433ca71b77c6642e9;p=tpg%2Fopendispense2.git Removed debug from server, cleaning client - Removed the last use of 'recv' from the client code. - Added a catch to the cokebank code for the username 'root' --- diff --git a/src/client/main.c b/src/client/main.c index 33f3fe4..d4af6dd 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -664,8 +664,7 @@ int Authenticate(int Socket) */ void PopulateItemList(int Socket) { - char buffer[BUFSIZ]; - int len; + char *buf; int responseCode; char *itemType, *itemStart; @@ -674,14 +673,11 @@ void PopulateItemList(int Socket) // Ask server for stock list send(Socket, "ENUM_ITEMS\n", 11, 0); - len = recv(Socket, buffer, BUFSIZ-1, 0); - buffer[len] = '\0'; - - trim(buffer); + buf = ReadLine(Socket); - //printf("Output: %s\n", buffer); + //printf("Output: %s\n", buf); - responseCode = atoi(buffer); + responseCode = atoi(buf); if( responseCode != 201 ) { fprintf(stderr, "Unknown response from dispense server (Response Code %i)\n", responseCode); exit(-1); @@ -690,10 +686,10 @@ void PopulateItemList(int Socket) // - Get item list - // Expected format: 201 Items ... - RunRegex(&gArrayRegex, buffer, 4, matches, "Malformed server response"); + RunRegex(&gArrayRegex, buf, 4, matches, "Malformed server response"); - itemType = &buffer[ matches[2].rm_so ]; buffer[ matches[2].rm_eo ] = '\0'; - count = atoi( &buffer[ matches[3].rm_so ] ); + itemType = &buf[ matches[2].rm_so ]; buf[ matches[2].rm_eo ] = '\0'; + count = atoi( &buf[ matches[3].rm_so ] ); // Check array type if( strcmp(itemType, "Items") != 0 ) { @@ -703,7 +699,7 @@ void PopulateItemList(int Socket) exit(-1); } - itemStart = &buffer[ matches[3].rm_eo ]; + itemStart = &buf[ matches[3].rm_eo ]; gaItems = malloc( count * sizeof(tItem) ); @@ -715,6 +711,8 @@ void PopulateItemList(int Socket) itemStart = next; } + free(buf); + // Fetch item information for( i = 0; i < giNumItems; i ++ ) { @@ -722,22 +720,22 @@ void PopulateItemList(int Socket) // Get item info sendf(Socket, "ITEM_INFO %s\n", gaItems[i].Ident); - len = recv(Socket, buffer, BUFSIZ-1, 0); - buffer[len] = '\0'; - trim(buffer); + buf = ReadLine(Socket); - responseCode = atoi(buffer); + responseCode = atoi(buf); if( responseCode != 202 ) { fprintf(stderr, "Unknown response from dispense server (Response Code %i)\n", responseCode); exit(-1); } - RunRegex(&gItemRegex, buffer, 6, matches, "Malformed server response"); + RunRegex(&gItemRegex, buf, 6, matches, "Malformed server response"); + + buf[ matches[3].rm_eo ] = '\0'; - buffer[ matches[3].rm_eo ] = '\0'; + gaItems[i].Price = atoi( buf + matches[4].rm_so ); + gaItems[i].Desc = strdup( buf + matches[5].rm_so ); - gaItems[i].Price = atoi( buffer + matches[4].rm_so ); - gaItems[i].Desc = strdup( buffer + matches[5].rm_so ); + free(buf); } } diff --git a/src/cokebank_basic/bank.c b/src/cokebank_basic/bank.c index 0f07a17..07b8271 100644 --- a/src/cokebank_basic/bank.c +++ b/src/cokebank_basic/bank.c @@ -124,6 +124,9 @@ int Bank_AddUser(const char *Username) if( strcmp(Username, ">liability") == 0 ) { gaBank_Users[giBank_NumUsers].Flags = USER_TYPE_GOD; // No minium } + else if( strcmp(Username, "root") == 0 ) { + gaBank_Users[giBank_NumUsers].Flags = USER_TYPE_GOD; // No minium + } // Commit to file fseek(gBank_File, giBank_NumUsers*sizeof(gaBank_Users[0]), SEEK_SET); diff --git a/src/server/server.c b/src/server/server.c index af9dc34..4549ff6 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -208,7 +208,11 @@ void Server_HandleClient(int Socket, int bTrusted) char *ret; *eol = '\0'; ret = Server_ParseClientCommand(&clientInfo, start); - printf("ret = %s", ret); + + #if DEBUG_TRACE_CLIENT + //printf("ret = %s", ret); + #endif + // `ret` is a string on the heap send(Socket, ret, strlen(ret), 0); free(ret);