From 7a2112fc0ccb165d3b106d8ec5ce0f372274c834 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 25 Jun 2022 16:40:08 +0300 Subject: [PATCH 52/52] Send web packet additions to web clients only This partial implementation affects web_send_packet() only, web_lsend_packet() is not changed as the list may have mixed set of webclient and desktop client connections. See osdn #44942 Signed-off-by: Marko Lindqvist --- common/networking/connection.c | 2 ++ common/networking/connection.h | 4 +++- common/networking/packets.h | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/common/networking/connection.c b/common/networking/connection.c index c13f206d15..7b1d658789 100644 --- a/common/networking/connection.c +++ b/common/networking/connection.c @@ -620,6 +620,8 @@ void connection_common_init(struct connection *pconn) byte_vector_init(&pconn->compression.queue); pconn->compression.frozen_level = 0; #endif /* USE_COMPRESSION */ + + pconn->client_gui = GUI_STUB; } /**********************************************************************//** diff --git a/common/networking/connection.h b/common/networking/connection.h index 0e452c642b..a970be857c 100644 --- a/common/networking/connection.h +++ b/common/networking/connection.h @@ -183,7 +183,7 @@ struct connection { enum gui_type client_gui; - void (*notify_of_writable_data) (struct connection * pc, + void (*notify_of_writable_data) (struct connection *pc, bool data_available_and_socket_full); union { @@ -369,6 +369,8 @@ struct conn_pattern *conn_pattern_from_string(const char *pattern, bool conn_is_valid(const struct connection *pconn); +#define conn_is_webclient(__pconn__) ((__pconn__)->client_gui == GUI_WEB) + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/common/networking/packets.h b/common/networking/packets.h index bf3d249985..8ef1d45d95 100644 --- a/common/networking/packets.h +++ b/common/networking/packets.h @@ -44,12 +44,16 @@ struct data_in; #define MAX_LEN_ROUTE 2000 /* MAX_LEN_PACKET / 2 - header */ #ifdef FREECIV_WEB -#define web_send_packet(packetname, ...) \ - send_packet_web_ ##packetname( __VA_ARGS__ ) +#define web_send_packet(packetname, pconn, ...) \ +do { \ + if (conn_is_webclient(pconn)) { \ + send_packet_web_ ##packetname(pconn, __VA_ARGS__ ); \ + } \ +} while (FALSE) #define web_lsend_packet(packetname, ...) \ lsend_packet_web_ ##packetname( __VA_ARGS__ ) #else /* FREECIV_WEB */ -#define web_send_packet(packetname, ...) +#define web_send_packet(packetname, pconn, ...) #define web_lsend_packet(packetname, ...) #endif /* FREECIV_WEB */ -- 2.35.1