Door config settings (and some fixes to doorgroup reporting)
[tpg/opendispense2.git] / src / server / server.c
index 80c526d..cd69224 100644 (file)
@@ -23,6 +23,7 @@
 // Statistics
 #define MAX_CONNECTION_QUEUE   5
 #define INPUT_BUFFER_SIZE      256
+#define CLIENT_TIMEOUT 10      // Seconds
 
 #define HASH_TYPE      SHA1
 #define HASH_LENGTH    20
@@ -153,6 +154,18 @@ void Server_Start(void)
                        return ;
                }
                
+               // Set a timeout on the user conneciton
+               {
+                       struct timeval tv;
+                       tv.tv_sec = CLIENT_TIMEOUT;
+                       tv.tv_usec = 0;
+                       if( setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) )
+                       {
+                               perror("setsockopt");
+                               return ;
+                       }
+               }
+               
                // Debug: Print the connection string
                if(giDebugLevel >= 2) {
                        char    ipstr[INET_ADDRSTRLEN];
@@ -225,6 +238,7 @@ void Server_HandleClient(int Socket, int bTrusted)
         *   it is saved to the beginning of `inbuf` and `buf` is updated to
         *   the end of it.
         */
+       // TODO: Use select() instead (to give a timeout)
        while( (bytes = recv(Socket, buf, remspace, 0)) > 0 )
        {
                char    *eol, *start;
@@ -476,16 +490,24 @@ void Server_Cmd_SETEUSER(tClient *Client, char *Args)
  */
 void Server_Cmd_ENUMITEMS(tClient *Client, char *Args)
 {
-        int    i;
+        int    i, count;
 
        if( Args != NULL && strlen(Args) ) {
                sendf(Client->Socket, "407 ENUM_ITEMS takes no arguments\n");
                return ;
        }
+       
+       // Count shown items
+       count = 0;
+       for( i = 0; i < giNumItems; i ++ ) {
+               if( gaItems[i].bHidden )        continue;
+               count ++;
+       }
 
-       sendf(Client->Socket, "201 Items %i\n", giNumItems);
+       sendf(Client->Socket, "201 Items %i\n", count);
 
        for( i = 0; i < giNumItems; i ++ ) {
+               if( gaItems[i].bHidden )        continue;
                sendf(Client->Socket,
                        "202 Item %s:%i %i %s\n",
                         gaItems[i].Handler->Name, gaItems[i].ID, gaItems[i].Price, gaItems[i].Name
@@ -1031,13 +1053,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 ;
        }
        
@@ -1072,9 +1095,9 @@ void _SendUserInfo(tClient *Client, int UserID)
        
        // TODO: User flags/type
        sendf(
-               Client->Socket, "202 User %s %i %s%s\n",
+               Client->Socket, "202 User %s %i %s%s%s\n",
                Bank_GetAcctName(UserID), Bank_GetBalance(UserID),
-               type, disabled
+               type, disabled, door
                );
 }
 
@@ -1149,6 +1172,10 @@ void Server_Cmd_USERFLAGS(tClient *Client, char *Args)
        if( Server_int_ParseFlags(Client, flags, &mask, &value) )
                return ;
        
+       if( giDebugLevel )
+               Debug(Client, "Set %i(%s) flags to %x (masked %x)\n",
+                       uid, username, mask, value);
+       
        // Apply flags
        Bank_SetFlags(uid, mask, value);
        
@@ -1163,7 +1190,7 @@ void Debug(tClient *Client, const char *Format, ...)
        //printf("%010i [%i] ", (int)time(NULL), Client->ID);
        printf("[%i] ", Client->ID);
        va_start(args, Format);
-       vprintf(NULL, 0, Format, args);
+       vprintf(Format, args);
        va_end(args);
        printf("\n");
 }

UCC git Repository :: git.ucc.asn.au