changeset 6531:77a5d2b51cfc draft

(svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
author rubidium <rubidium@openttd.org>
date Thu, 26 Apr 2007 07:41:24 +0000 (2007-04-26)
parents 01978c632f97
children c865bac86abd
files src/network/network_client.cpp src/network/network_gui.cpp src/network/network_gui.h src/network/network_server.cpp src/window.h
diffstat 5 files changed, 34 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -184,7 +184,7 @@
 	// Data:
 	//    uint8:  ActionID (see network_data.h, NetworkAction)
 	//    uint8:  Destination Type (see network_data.h, DestType);
-	//    uint8:  Destination Player (1..MAX_PLAYERS)
+	//    uint16: Destination Player
 	//    String: Message (max MAX_TEXT_MSG_LEN)
 	//
 
@@ -192,7 +192,7 @@
 
 	p->Send_uint8 (action);
 	p->Send_uint8 (type);
-	p->Send_uint8 (dest);
+	p->Send_uint16(dest);
 	p->Send_string(msg);
 	MY_CLIENT->Send_Packet(p);
 }
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1469,7 +1469,7 @@
 	if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
 }
 
-static void SendChat(const char *buf, DestType type, byte dest)
+static void SendChat(const char *buf, DestType type, int dest)
 {
 	if (buf[0] == '\0') return;
 	if (!_network_server) {
@@ -1533,7 +1533,7 @@
 static void ChatTabCompletion(Window *w)
 {
 	static char _chat_tab_completion_buf[lengthof(_edit_str_buf)];
-	Textbuf *tb = &WP(w, querystr_d).text;
+	Textbuf *tb = &WP(w, chatquerystr_d).text;
 	uint len, tb_len;
 	uint item;
 	char *tb_buf, *pre_buf;
@@ -1591,7 +1591,7 @@
 			}
 
 			/* Update the textbuffer */
-			UpdateTextBufferSize(&WP(w, querystr_d).text);
+			UpdateTextBufferSize(&WP(w, chatquerystr_d).text);
 
 			SetWindowDirty(w);
 			free(pre_buf);
@@ -1605,17 +1605,17 @@
 		_chat_tab_completion_active = false;
 
 		/* Update the textbuffer */
-		UpdateTextBufferSize(&WP(w, querystr_d).text);
+		UpdateTextBufferSize(&WP(w, chatquerystr_d).text);
 
 		SetWindowDirty(w);
 	}
 	free(pre_buf);
 }
 
-/* uses querystr_d WP macro
- * uses querystr_d->caption to store
- * - type of chat message (Private/Team/All) in bytes 0-7
- * - destination of chat message in the case of Team/Private in bytes 8-15 */
+/*
+ * uses chatquerystr_d WP macro
+ * uses chatquerystr_d->caption to store type of chat message (Private/Team/All)
+ */
 static void ChatWindowWndProc(Window *w, WindowEvent *e)
 {
 	switch (e->event) {
@@ -1634,25 +1634,25 @@
 
 		DrawWindowWidgets(w);
 
-		assert(GB(WP(w, querystr_d).caption, 0, 8) < lengthof(chat_captions));
-		msg = chat_captions[GB(WP(w, querystr_d).caption, 0, 8)];
+		assert(WP(w, chatquerystr_d).caption < lengthof(chat_captions));
+		msg = chat_captions[WP(w, chatquerystr_d).caption];
 		DrawStringRightAligned(w->widget[2].left - 2, w->widget[2].top + 1, msg, 16);
-		DrawEditBox(w, &WP(w, querystr_d), 2);
+		DrawEditBox(w, &WP(w, chatquerystr_d), 2);
 	} break;
 
 	case WE_CLICK:
 		switch (e->we.click.widget) {
 			case 3: { /* Send */
-				DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
-				byte dest = GB(WP(w, querystr_d).caption, 8, 8);
-				SendChat(WP(w, querystr_d).text.buf, type, dest);
+				DestType type = (DestType)WP(w, chatquerystr_d).caption;
+				int dest = WP(w, chatquerystr_d).dest;
+				SendChat(WP(w, chatquerystr_d).text.buf, type, dest);
 			} /* FALLTHROUGH */
 			case 0: /* Cancel */ DeleteWindow(w); break;
 		}
 		break;
 
 	case WE_MOUSELOOP:
-		HandleEditBox(w, &WP(w, querystr_d), 2);
+		HandleEditBox(w, &WP(w, chatquerystr_d), 2);
 		break;
 
 	case WE_KEYPRESS:
@@ -1660,11 +1660,11 @@
 			ChatTabCompletion(w);
 		} else {
 			_chat_tab_completion_active = false;
-			switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) {
+			switch (HandleEditBoxKey(w, &WP(w, chatquerystr_d), 2, e)) {
 				case 1: { /* Return */
-				DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
-				byte dest = GB(WP(w, querystr_d).caption, 8, 8);
-				SendChat(WP(w, querystr_d).text.buf, type, dest);
+				DestType type = (DestType)WP(w, chatquerystr_d).caption;
+				int dest = WP(w, chatquerystr_d).dest;
+				SendChat(WP(w, chatquerystr_d).text.buf, type, dest);
 			} /* FALLTHROUGH */
 				case 2: /* Escape */ DeleteWindow(w); break;
 			}
@@ -1694,7 +1694,7 @@
 	ChatWindowWndProc
 };
 
-void ShowNetworkChatQueryWindow(DestType type, byte dest)
+void ShowNetworkChatQueryWindow(DestType type, int dest)
 {
 	Window *w;
 
@@ -1706,9 +1706,10 @@
 	w = AllocateWindowDesc(&_chat_window_desc);
 
 	LowerWindowWidget(w, 2);
-	WP(w, querystr_d).caption = GB(type, 0, 8) | (dest << 8); // Misuse of caption
-	WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
-	InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0);
+	WP(w, chatquerystr_d).caption = type; // Misuse of caption
+	WP(w, chatquerystr_d).dest    = dest;
+	WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL;
+	InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0);
 }
 
 #endif /* ENABLE_NETWORK */
--- a/src/network/network_gui.h
+++ b/src/network/network_gui.h
@@ -9,7 +9,7 @@
 
 void ShowNetworkNeedPassword(NetworkPasswordType npt);
 void ShowNetworkGiveMoneyWindow(PlayerID player); // PlayerID
-void ShowNetworkChatQueryWindow(DestType type, byte dest);
+void ShowNetworkChatQueryWindow(DestType type, int dest);
 void ShowJoinStatusWindow();
 void ShowNetworkGameWindow();
 void ShowClientList();
@@ -17,7 +17,7 @@
 #else /* ENABLE_NETWORK */
 /* Network function stubs when networking is disabled */
 
-static inline void ShowNetworkChatQueryWindow(byte desttype, byte dest) {}
+static inline void ShowNetworkChatQueryWindow(byte desttype, int dest) {}
 static inline void ShowClientList() {}
 static inline void ShowNetworkGameWindow() {}
 
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1115,7 +1115,7 @@
 {
 	NetworkAction action = (NetworkAction)p->Recv_uint8();
 	DestType desttype = (DestType)p->Recv_uint8();
-	int dest = p->Recv_uint8();
+	int dest = p->Recv_uint16();
 	char msg[MAX_TEXT_MSG_LEN];
 
 	p->Recv_string(msg, MAX_TEXT_MSG_LEN);
--- a/src/window.h
+++ b/src/window.h
@@ -280,6 +280,11 @@
 };
 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d));
 
+struct chatquerystr_d : public querystr_d {
+	int dest;
+};
+assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(chatquerystr_d));
+
 struct menu_d {
 	byte item_count;      ///< follow_vehicle
 	byte sel_index;       ///< scrollpos_x