(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
authortruelight
Thu, 23 Dec 2004 20:33:57 +0000
changeset 793 0fbdcb357a2c
parent 792 d8a4164fdb14
child 794 88fbc4381828
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
-Fix: You can enter some more chars in the chatbox
main_gui.c
network.h
network_gui.c
network_server.c
--- a/main_gui.c	Thu Dec 23 20:23:05 2004 +0000
+++ b/main_gui.c	Thu Dec 23 20:33:57 2004 +0000
@@ -163,7 +163,7 @@
 	case 2: ShowPatchesSelection(); return;
 	case 3: ShowNewgrf(); return;
 
-	case 5: DeleteAllNonVitalWindows(); return; 
+	case 5: DeleteAllNonVitalWindows(); return;
 	case 6: _display_opt ^= DO_SHOW_TOWN_NAMES; MarkWholeScreenDirty(); return;
 	case 7: _display_opt ^= DO_SHOW_STATION_NAMES; MarkWholeScreenDirty(); return;
 	case 8: _display_opt ^= DO_SHOW_SIGNS; MarkWholeScreenDirty(); return;
@@ -339,7 +339,7 @@
 {
 	_rename_id = desttype + (dest << 8);
 	_rename_what = 2;
-	ShowChatWindow(STR_EMPTY, STR_NETWORK_CHAT_QUERY_CAPTION, 60, 250, 1, 0);
+	ShowChatWindow(STR_EMPTY, STR_NETWORK_CHAT_QUERY_CAPTION, 150, 338, 1, 0);
 }
 
 void ShowNetworkGiveMoneyWindow(byte player)
--- a/network.h	Thu Dec 23 20:23:05 2004 +0000
+++ b/network.h	Thu Dec 23 20:33:57 2004 +0000
@@ -47,6 +47,7 @@
 #define NETWORK_REVISION_LENGTH 10
 #define NETWORK_PASSWORD_LENGTH 20
 #define NETWORK_PLAYERS_LENGTH 200
+#define NETWORK_CLIENT_NAME_LENGTH 25
 
 // This is the struct used by both client and server
 //  some fields will be empty on the client (like game_password) by default
@@ -88,7 +89,7 @@
 
 typedef struct NetworkClientInfo {
 	uint16 client_index;														// Index of the client (same as ClientState->index)
-	char client_name[NETWORK_NAME_LENGTH];					// Name of the client
+	char client_name[NETWORK_CLIENT_NAME_LENGTH];		// Name of the client
 	byte client_lang;																// The language of the client
 	byte client_playas;															// As which player is this client playing
 	uint32 client_ip;																// IP-address of the client (so he can be banned)
--- a/network_gui.c	Thu Dec 23 20:23:05 2004 +0000
+++ b/network_gui.c	Thu Dec 23 20:33:57 2004 +0000
@@ -1408,9 +1408,9 @@
 
 static const Widget _chat_window_widgets[] = {
 {     WWT_IMGBTN,    14,     0,   639,     0,    13, 0x0,							STR_NULL}, // background
-{     WWT_IMGBTN,    14,     2,   379,     1,    12, 0x0,							STR_NULL}, // text box
-{    WWT_TEXTBTN,    14,   380,   509,     1,    12, STR_NETWORK_SEND,STR_NULL}, // send button
-{    WWT_TEXTBTN,    14,   510,   639,     1,    12, STR_012E_CANCEL,	STR_NULL}, // cancel button
+{     WWT_IMGBTN,    14,     2,   399,     1,    12, 0x0,							STR_NULL}, // text box
+{    WWT_TEXTBTN,    14,   400,   519,     1,    12, STR_NETWORK_SEND,STR_NULL}, // send button
+{    WWT_TEXTBTN,    14,   520,   639,     1,    12, STR_012E_CANCEL,	STR_NULL}, // cancel button
 {   WIDGETS_END},
 };
 
--- a/network_server.c	Thu Dec 23 20:23:05 2004 +0000
+++ b/network_server.c	Thu Dec 23 20:33:57 2004 +0000
@@ -135,7 +135,7 @@
 
 	NetworkClientState *new_cs;
 	char str[100];
-	char client_name[NETWORK_NAME_LENGTH];
+	char client_name[NETWORK_CLIENT_NAME_LENGTH];
 
 	Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR);
 	NetworkSend_uint8(p, error);
@@ -712,7 +712,7 @@
 {
 	// Client has the map, now start syncing
 	if (cs->status == STATUS_DONE_MAP && !cs->quited) {
-		char client_name[NETWORK_NAME_LENGTH];
+		char client_name[NETWORK_CLIENT_NAME_LENGTH];
 		NetworkClientState *new_cs;
 
 		NetworkGetClientName(client_name, sizeof(client_name), cs);
@@ -849,7 +849,7 @@
 	NetworkClientState *new_cs;
 	byte errorno = NetworkRecv_uint8(p);
 	char str[100];
-	char client_name[NETWORK_NAME_LENGTH];
+	char client_name[NETWORK_CLIENT_NAME_LENGTH];
 
 	// The client was never joined.. thank the client for the packet, but ignore it
 	if (cs->status < STATUS_DONE_MAP || cs->quited) {
@@ -880,7 +880,7 @@
 	//  clients.
 	NetworkClientState *new_cs;
 	char str[100];
-	char client_name[NETWORK_NAME_LENGTH];
+	char client_name[NETWORK_CLIENT_NAME_LENGTH];
 
 	// The client was never joined.. thank the client for the packet, but ignore it
 	if (cs->status < STATUS_DONE_MAP || cs->quited) {
@@ -1043,17 +1043,17 @@
 
 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
 {
-	char name[NETWORK_NAME_LENGTH];
+	char client_name[NETWORK_CLIENT_NAME_LENGTH];
 	NetworkClientInfo *ci;
 
-	NetworkRecv_string(p, name, sizeof(name));
+	NetworkRecv_string(p, client_name, sizeof(client_name));
 	ci = DEREF_CLIENT_INFO(cs);
 
 	if (ci != NULL) {
 		// Display change
-		if (NetworkFindName(name)) {
-			NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, name);
-			ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
+		if (NetworkFindName(client_name)) {
+			NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, client_name);
+			ttd_strlcpy(ci->client_name, client_name, sizeof(ci->client_name));
 			NetworkUpdateClientInfo(ci->client_index);
 		}
 	}
@@ -1229,7 +1229,7 @@
 		ttd_strlcpy(_network_player_info[ci->client_playas-1].players, ci->client_name, sizeof(_network_player_info[ci->client_playas-1].players));
 
 	FOR_ALL_CLIENTS(cs) {
-		char client_name[NETWORK_NAME_LENGTH];
+		char client_name[NETWORK_CLIENT_NAME_LENGTH];
 
 		NetworkGetClientName(client_name, sizeof(client_name), cs);
 
@@ -1339,22 +1339,22 @@
 
 // This function changes new_name to a name that is unique (by adding #1 ...)
 //  and it returns true if that succeeded.
-bool NetworkFindName(char new_name[NETWORK_NAME_LENGTH])
+bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH])
 {
 	NetworkClientState *new_cs;
 	NetworkClientInfo *ci;
 	bool found_name = false;
 	byte number = 0;
-	char original_name[NETWORK_NAME_LENGTH];
+	char original_name[NETWORK_CLIENT_NAME_LENGTH];
 
 	// We use NETWORK_NAME_LENGTH in here, because new_name is really a pointer
-	ttd_strlcpy(original_name, new_name, NETWORK_NAME_LENGTH);
+	ttd_strlcpy(original_name, new_name, NETWORK_CLIENT_NAME_LENGTH);
 
 	while (!found_name) {
 		found_name = true;
 		FOR_ALL_CLIENTS(new_cs) {
 			ci = DEREF_CLIENT_INFO(new_cs);
-			if (strncmp(ci->client_name, new_name, NETWORK_NAME_LENGTH) == 0) {
+			if (strncmp(ci->client_name, new_name, NETWORK_CLIENT_NAME_LENGTH) == 0) {
 				// Name already in use
 				found_name = false;
 				break;
@@ -1363,7 +1363,7 @@
 		// Check if it is the same as the server-name
 		ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 		if (ci != NULL) {
-			if (strncmp(ci->client_name, new_name, NETWORK_NAME_LENGTH) == 0) {
+			if (strncmp(ci->client_name, new_name, NETWORK_CLIENT_NAME_LENGTH) == 0) {
 				// Name already in use
 				found_name = false;
 			}
@@ -1374,7 +1374,7 @@
 
 			// Stop if we tried for more then 50 times..
 			if (number++ > 50) break;
-			snprintf(new_name, NETWORK_NAME_LENGTH, "%s #%d", original_name, number);
+			snprintf(new_name, NETWORK_CLIENT_NAME_LENGTH, "%s #%d", original_name, number);
 		}
 	}