From: root Date: Sat, 19 Feb 2011 04:16:28 +0000 (+0800) Subject: Fixing crappy code in coke handler, debug in others X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=10fc79a2f4f72165cb1ce1ba78c84faa8d56f5db;p=tpg%2Fopendispense2.git Fixing crappy code in coke handler, debug in others --- diff --git a/items.cfg b/items.cfg index c2b27e1..2d9df3e 100644 --- a/items.cfg +++ b/items.cfg @@ -2,8 +2,8 @@ # Type ID Price Description # Drinks -coke 0 75 Screaming Soda -coke 1 75 Green Solo +coke 0 200 Blue Powerade +coke 1 200 Mother Energy Drink coke 2 75 Solo coke 3 75 Lemonade coke 4 75 Orange Foo diff --git a/src/cokebank_sqlite/main.c b/src/cokebank_sqlite/main.c index 504ec4e..e539105 100644 --- a/src/cokebank_sqlite/main.c +++ b/src/cokebank_sqlite/main.c @@ -15,6 +15,8 @@ #include "../cokebank.h" #include +#define DEBUG 1 + const char * const csBank_DatabaseSetup = "CREATE TABLE IF NOT EXISTS accounts (" " acct_id INTEGER PRIMARY KEY NOT NULL," diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index dbc2a81..decdf4d 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -108,7 +108,9 @@ int Coke_CanDispense(int UNUSED(User), int Item) // Read from the machine (ignoring empty lines) while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == 0 ); printf("ret = %i, tmp = '%s'\n", ret, tmp); - if( tmp[0] == ':' ) { + // Read back-echoed lines + while( tmp[0] == ':' || tmp[1] != 'l' ) + { ret = ReadLine(sizeof(tmp)-1, tmp); printf("ret = %i, tmp = '%s'\n", ret, tmp); } @@ -157,7 +159,7 @@ int Coke_CanDispense(int UNUSED(User), int Item) int Coke_DoDispense(int UNUSED(User), int Item) { char tmp[32]; - int i, ret; + int ret; // Sanity please if( Item < 0 || Item > 6 ) return -1; @@ -190,17 +192,14 @@ int Coke_DoDispense(int UNUSED(User), int Item) sprintf(tmp, "d%i\r\n", Item); write(giCoke_SerialFD, tmp, 4); - // Read empty lines - while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == -1 ); - if( ret == -1 ) return -1; - // Read d%i - while( tmp[0] == ':' ) { + // Read empty lines and echo-backs + do { ret = ReadLine(sizeof(tmp)-1, tmp); if( ret == -1 ) return -1; - } - // Get status - ret = ReadLine(sizeof(tmp)-1, tmp); - if( ret == -1 ) return -1; + #if TRACE_COKE + printf("Coke_DoDispense: read %i '%s'\n", ret, tmp); + #endif + } while( ret == 0 || tmp[0] == ':' || tmp[0] == 'd' ); WaitForColon(); // Eat up rest of response diff --git a/src/server/main.c b/src/server/main.c index 714f513..0692d6a 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -103,6 +103,9 @@ int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *match int ret; ret = regexec(regex, string, nMatches, matches, 0); + if( ret == REG_NOMATCH ) { + return -1; + } if( ret ) { size_t len = regerror(ret, regex, NULL, 0); char errorStr[len]; diff --git a/src/server/server.c b/src/server/server.c index 17e8549..315b129 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -1031,13 +1031,14 @@ void Server_Cmd_USERINFO(tClient *Client, char *Args) space = strchr(user, ' '); if(space) *space = '\0'; - if( giDebugLevel ) - Debug(Client, "User Info '%s'", user); + if( giDebugLevel ) Debug(Client, "User Info '%s'", user); // Get recipient uid = Bank_GetAcctByName(user); + + if( giDebugLevel >= 2 ) Debug(Client, "uid = %i", uid); if( uid == -1 ) { - sendf(Client->Socket, "404 Invalid user"); + sendf(Client->Socket, "404 Invalid user\n"); return ; }