From d513f233d390ccb10b3aa3c666888f81b8a1eb26 Mon Sep 17 00:00:00 2001
From: John Hodge <tpg@mutabah.net>
Date: Sun, 11 Jul 2010 22:10:46 +0800
Subject: [PATCH] Compile fixes

---
 server/src/common.h |  1 +
 server/src/main.c   |  3 +++
 server/src/server.c | 21 +++++++++++++++++----
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/server/src/common.h b/server/src/common.h
index f310e9a..f297624 100644
--- a/server/src/common.h
+++ b/server/src/common.h
@@ -48,6 +48,7 @@ struct sHandler
 extern tItem	*gaItems;
 extern int	giNumItems;
 extern tHandler	*gaHandlers;
+extern int	giDebugLevel;
 
 // === FUNCTIONS ===
 // --- Logging ---
diff --git a/server/src/main.c b/server/src/main.c
index 2d9f70e..7d7ba4c 100644
--- a/server/src/main.c
+++ b/server/src/main.c
@@ -16,6 +16,9 @@ extern void	Init_Cokebank(void);
 extern void	Load_Itemlist(void);
 extern void	Server_Start(void);
 
+// === GLOBALS ===
+ int	giDebugLevel = 0;
+
 // === CODE ===
 int main(int argc, char *argv[])
 {
diff --git a/server/src/server.c b/server/src/server.c
index 8c87c65..5d54235 100644
--- a/server/src/server.c
+++ b/server/src/server.c
@@ -21,6 +21,11 @@
 // === TYPES ===
 typedef struct sClient
 {
+	 int	ID;	// Client ID
+	
+	char	*Username;
+	char	Salt[9];
+	
 	 int	UID;
 	 int	bIsAuthed;
 }	tClient;
@@ -62,8 +67,18 @@ void Server_HandleClient(int Socket)
 	 int	remspace = INPUT_BUFFER_SIZE-1;
 	 int	bytes = -1;
 	tClient	clientInfo = {0};
+	
+	// Initialise Client info
+	clientInfo.ID = giServer_NextClientID ++;
 		
 	// Read from client
+	/*
+	 * Notes:
+	 * - The `buf` and `remspace` variables allow a line to span several
+	 *   calls to recv(), if a line is not completed in one recv() call
+	 *   it is saved to the beginning of `inbuf` and `buf` is updated to
+	 *   the end of it.
+	 */
 	while( (bytes = recv(Socket, buf, remspace, 0)) > 0 )
 	{
 		char	*eol, *start;
@@ -147,8 +162,8 @@ char *Server_Cmd_USER(tClient *Client, char *Args)
 	char	*ret;
 	
 	// Debug!
-	if( gbDebugLevel )
-		printf("Client %i authenticating as '%s'\n", Args);
+	if( giDebugLevel )
+		printf("Client %i authenticating as '%s'\n", Client->ID, Args);
 	
 	// Save username
 	if(Client->Username)
@@ -156,8 +171,6 @@ char *Server_Cmd_USER(tClient *Client, char *Args)
 	Client->Username = strdup(Args);
 	
 	// Create a salt (that changes if the username is changed)
-	if(!Client->Salt)
-		Client->Salt = malloc(9);
 	Client->Salt[0] = 0x21 + (rand()&0x3F);
 	Client->Salt[1] = 0x21 + (rand()&0x3F);
 	Client->Salt[2] = 0x21 + (rand()&0x3F);
-- 
GitLab