main_gui.c
changeset 5107 8791beb0ae51
parent 5102 ce4b27298f90
child 5108 dc67d70b5a45
--- a/main_gui.c	Thu Nov 16 20:52:39 2006 +0000
+++ b/main_gui.c	Thu Nov 16 20:57:23 2006 +0000
@@ -2298,11 +2298,23 @@
 				break;
 
 #ifdef ENABLE_NETWORK
-			case WKC_RETURN: case 'T': // send to all players or to your team depending on setting
+			case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all
 				if (_networking) {
-					const NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
-					ShowNetworkChatQueryWindow(_patches.chat_target ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, ci->client_playas);
-					break;
+					const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index);
+					bool teamchat = false;
+
+					/* Only players actually playing can speak to team. Eg spectators cannot */
+					if (_patches.prefer_teamchat && IsValidPlayer(cio->client_playas)) {
+						const NetworkClientInfo *ci;
+						FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
+							if (ci->client_playas == cio->client_playas && ci != cio) {
+								teamchat = true;
+								break;
+							}
+						}
+					}
+
+					ShowNetworkChatQueryWindow(teamchat ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
 				}
 				break;