[Freeciv-Dev] (PR#9513) connection id in chat
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#9513) connection id in chat |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Mon, 26 Jul 2004 15:34:08 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9513 >
This patch is cut out from Raimar's gui-fs patch. It gives the client info
on which connection it is that writes a piece of chat message.
- Per
Index: client/chatline_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/chatline_common.c,v
retrieving revision 1.5
diff -u -r1.5 chatline_common.c
--- client/chatline_common.c 28 Nov 2003 17:37:19 -0000 1.5
+++ client/chatline_common.c 26 Jul 2004 20:21:37 -0000
@@ -19,6 +19,7 @@
#include <string.h>
#include "astring.h"
+#include "log.h"
#include "packets.h"
#include "support.h"
@@ -27,6 +28,14 @@
#include "chatline_common.h"
#include "clinet.h"
+static struct {
+ int lines;
+ struct {
+ char *text;
+ int conn_id;
+ } *line;
+} remaining;
+
/**************************************************************************
Send the message as a chat to the server.
**************************************************************************/
@@ -36,7 +45,6 @@
}
static int frozen_level = 0;
-static struct astring remaining = ASTRING_INIT;
/**************************************************************************
Turn on buffering, using a counter so that calls may be nested.
@@ -46,9 +54,7 @@
frozen_level++;
if (frozen_level == 1) {
- assert(remaining.str == NULL);
- astr_minsize(&remaining, 1);
- remaining.str[0] = '\0';
+ assert(remaining.lines == 0);
}
}
@@ -63,11 +69,14 @@
assert(frozen_level >= 0);
if (frozen_level == 0) {
- if (remaining.n > 2) {
- /* +1 to skip the initial '\n' */
- append_output_window(remaining.str + 1);
+ int i;
+
+ for (i = 0; i < remaining.lines; i++) {
+ base_append_output_window(remaining.line[i].text,
+ remaining.line[i].conn_id);
+ free(remaining.line[i].text);
}
- astr_free(&remaining);
+ remaining.lines = 0;
}
}
@@ -87,20 +96,19 @@
**************************************************************************/
void append_output_window(const char *astring)
{
+ base_append_output_window(astring, -1);
+}
+
+void base_append_output_window(const char *astring, int conn_id)
+{
if (frozen_level == 0) {
- real_append_output_window(astring);
+ real_append_output_window(astring, conn_id);
} else {
- /*
- * len_src doesn't include the trailing '\0'
- * len_dst does include the trailing '\0'
- */
- size_t len_src = strlen(astring), len_dst = remaining.n;
-
- /* +1 for the "\n" */
- astr_minsize(&remaining, len_dst + 1 + len_src);
- remaining.str[len_dst - 1] = '\n';
-
- /* +1 for the "\0" */
- memcpy(&remaining.str[len_dst], astring, len_src + 1);
+ remaining.lines++;
+ remaining.line =
+ fc_realloc(remaining.line,
+ remaining.lines * sizeof(*remaining.line));
+ remaining.line[remaining.lines - 1].text = mystrdup(astring);
+ remaining.line[remaining.lines - 1].conn_id = conn_id;
}
}
Index: client/chatline_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/chatline_common.h,v
retrieving revision 1.2
diff -u -r1.2 chatline_common.h
--- client/chatline_common.h 18 Jul 2003 22:02:24 -0000 1.2
+++ client/chatline_common.h 26 Jul 2004 20:21:37 -0000
@@ -17,6 +17,7 @@
void send_chat(const char *message);
+void base_append_output_window(const char *astring, int conn_id);
void append_output_window(const char *astring);
void output_window_freeze(void);
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.134
diff -u -r1.134 climisc.c
--- client/climisc.c 25 Jun 2004 23:35:55 -0000 1.134
+++ client/climisc.c 26 Jul 2004 20:21:37 -0000
@@ -860,7 +860,7 @@
my_vsnprintf(message, sizeof(message), format, ap);
va_end(ap);
- handle_chat_msg(message, x, y, event);
+ handle_chat_msg(message, x, y, event, aconnection.id);
}
/**************************************************************************
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.390
diff -u -r1.390 packhand.c
--- client/packhand.c 20 Jul 2004 11:05:36 -0000 1.390
+++ client/packhand.c 26 Jul 2004 20:21:38 -0000
@@ -851,7 +851,7 @@
/**************************************************************************
...
**************************************************************************/
-void handle_chat_msg(char *message, int x, int y, enum event_type event)
+void handle_chat_msg(char *message, int x, int y, enum event_type event, int
conn_id)
{
int where = MW_OUTPUT; /* where to display the message */
@@ -863,7 +863,7 @@
}
if (BOOL_VAL(where & MW_OUTPUT)) {
- append_output_window(message);
+ base_append_output_window(message,conn_id);
}
if (BOOL_VAL(where & MW_MESSAGES)) {
add_notify_window(message, x, y, event);
Index: client/gui-gtk/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/chatline.c,v
retrieving revision 1.21
diff -u -r1.21 chatline.c
--- client/gui-gtk/chatline.c 1 Apr 2004 01:28:56 -0000 1.21
+++ client/gui-gtk/chatline.c 26 Jul 2004 20:21:38 -0000
@@ -65,7 +65,7 @@
/**************************************************************************
...
**************************************************************************/
-void real_append_output_window(const char *astring)
+void real_append_output_window(const char *astring, int conn_id)
{
bool scroll;
GtkAdjustment *slider =
Index: client/gui-gtk-2.0/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/chatline.c,v
retrieving revision 1.9
diff -u -r1.9 chatline.c
--- client/gui-gtk-2.0/chatline.c 1 Apr 2004 01:20:20 -0000 1.9
+++ client/gui-gtk-2.0/chatline.c 26 Jul 2004 20:21:38 -0000
@@ -67,7 +67,7 @@
/**************************************************************************
...
**************************************************************************/
-void real_append_output_window(const char *astring)
+void real_append_output_window(const char *astring, int conn_id)
{
GtkWidget *sw;
GtkAdjustment *slider;
Index: client/gui-mui/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/chatline.c,v
retrieving revision 1.7
diff -u -r1.7 chatline.c
--- client/gui-mui/chatline.c 14 Nov 2002 09:14:56 -0000 1.7
+++ client/gui-mui/chatline.c 26 Jul 2004 20:21:38 -0000
@@ -34,7 +34,7 @@
#include "gui_main.h"
#include "muistuff.h"
-void real_append_output_window(const char *astring)
+void real_append_output_window(const char *astring, int conn_id)
{
DoMethod(main_output_listview, MUIM_NList_Insert, astring, -2,
MUIV_List_Insert_Bottom);
set(main_output_listview,MUIA_NList_First, MUIV_NList_First_Bottom);
Index: client/gui-sdl/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/chatline.c,v
retrieving revision 1.14
diff -u -r1.14 chatline.c
--- client/gui-sdl/chatline.c 4 Dec 2003 13:53:12 -0000 1.14
+++ client/gui-sdl/chatline.c 26 Jul 2004 20:21:38 -0000
@@ -132,7 +132,7 @@
Appends the string to the chat output window.
Curretn it is wraper to message subsystem.
**************************************************************************/
-void real_append_output_window(const char *astring)
+void real_append_output_window(const char *astring, int conn_id)
{
if (pConnDlg) {
Uint16 *pUniStr;
Index: client/gui-stub/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/chatline.c,v
retrieving revision 1.4
diff -u -r1.4 chatline.c
--- client/gui-stub/chatline.c 30 Nov 2002 19:27:36 -0000 1.4
+++ client/gui-stub/chatline.c 26 Jul 2004 20:21:38 -0000
@@ -23,7 +23,7 @@
Appends the string to the chat output window. The string should be
inserted on its own line, although it will have no newline.
**************************************************************************/
-void real_append_output_window(const char *astring)
+void real_append_output_window(const char *astring, int conn_id)
{
/* PORTME */
}
Index: client/gui-win32/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/chatline.c,v
retrieving revision 1.10
diff -u -r1.10 chatline.c
--- client/gui-win32/chatline.c 18 Jul 2003 22:02:25 -0000 1.10
+++ client/gui-win32/chatline.c 26 Jul 2004 20:21:38 -0000
@@ -85,10 +85,9 @@
}
/**************************************************************************
-
+ PS We need to add \r to lineends.
**************************************************************************/
-void real_append_output_window(const char *astring)
- /* We need to add \r to lineends */
+void real_append_output_window(const char *astring, int conn_id)
{
const char *str;
Index: client/gui-xaw/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/chatline.c,v
retrieving revision 1.22
diff -u -r1.22 chatline.c
--- client/gui-xaw/chatline.c 24 Oct 2003 00:03:01 -0000 1.22
+++ client/gui-xaw/chatline.c 26 Jul 2004 20:21:38 -0000
@@ -72,7 +72,7 @@
Now uses window's font size and width. Assumes fixed-width font. --jjm
**************************************************************************/
-void real_append_output_window(const char *input_string)
+void real_append_output_window(const char *astring, int conn_id)
{
static int m_width=0;
Index: client/include/chatline_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/chatline_g.h,v
retrieving revision 1.2
diff -u -r1.2 chatline_g.h
--- client/include/chatline_g.h 27 Jun 2002 00:59:21 -0000 1.2
+++ client/include/chatline_g.h 26 Jul 2004 20:21:38 -0000
@@ -15,7 +15,7 @@
#include "chatline_common.h"
-void real_append_output_window(const char *astring);
+void real_append_output_window(const char *astring, int conn_id);
void log_output_window(void);
void clear_output_window(void);
Index: client/include/diplodlg_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/diplodlg_g.h,v
retrieving revision 1.4
diff -u -r1.4 diplodlg_g.h
--- client/include/diplodlg_g.h 2 Feb 2004 07:23:45 -0000 1.4
+++ client/include/diplodlg_g.h 26 Jul 2004 20:21:38 -0000
@@ -13,9 +13,10 @@
#ifndef FC__DIPLODLG_G_H
#define FC__DIPLODLG_G_H
-#include "diptreaty.h"
#include "shared.h"
+#include "diptreaty.h"
+
void handle_diplomacy_init_meeting(int counterpart, int initiated_from);
void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from);
void handle_diplomacy_create_clause(int counterpart, int giver,
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.173
diff -u -r1.173 capstr.c
--- common/capstr.c 20 Jul 2004 11:05:36 -0000 1.173
+++ common/capstr.c 26 Jul 2004 20:21:38 -0000
@@ -73,63 +73,11 @@
* are not directly related to the capability strings discussed here.)
*/
-#define CAPABILITY "+1.14.delta +last_turns_shield_surplus veteran +orders " \
- "+starter +union +iso_maps +big_map_size +orders2client " \
- "+change_production +tilespec1 +no_earth +trans " \
- "+want_hack invasions bombard +killstack2 spec +spec2 " \
- "+city_map startunits +turn_last_built +happyborders"
+#define CAPABILITY "+1.14.connid"
-/* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
+/* "+1.14.connid" is the addition of
+ * chat message that contains the connection id of the source.
*
- * "last_turns_shield_surplus" means the surplus from the previous turn is
- * tracked by the server and sent to the client. This information is used
- * in determining penalties when switching production.
- *
- * "orders" means client orders is used for client-side goto and patrol.
- *
- * "veteran" means the extended veteran system.
- *
- * "starter" means the Starter terrain flag is supported.
- *
- * "union" is team research ability
- *
- * "iso_maps" means iso-maps are supported by both server and client!
- *
- * "big_map_size" means [xy]size info is sent as UINT16
- *
- * "orders2client" means that the server sends back the orders to the client.
- *
- * "change_production" is the E_CITY_PRODUCTION_CHANGED event.
- *
- * "tilespec1" means changed graphic strings in terrain.ruleset.
- *
- * "no_earth" means that the map.is_earth value is gone; replaced by
- * ptile->spec_sprite
- *
- * "trans" means that the transported_by field is sent to the client.
- *
- * "want_hack" means that the client is capable of asking for hack properly.
- *
- * "invasions" means ground units moving from ocean to land now lose all
- * their movement; changable by ruleset option.
- *
- * "killstack2" means ruleset option to ignore unit killstack effect, and now
- * it's a boolean.
- *
- * "bombard" means units support the bombard ability.
- *
- * "spec" is configurable specialists
- *
- * "spec2" is semi-configurable specialists in an array
- *
- * "city_map" means the city_map is sent as an array instead of a bitfield.
- *
- * "startunits" means the initial units are stored as a server string var.
- *
- * "turn_last_built" means that turn_last_built is stored as a turn
- *
- * "happyborders" means that units may not cause unhappiness inside
- * our own borders.
*/
void init_our_capability(void)
Index: common/connection.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/connection.c,v
retrieving revision 1.41
diff -u -r1.41 connection.c
--- common/connection.c 18 Jul 2004 05:52:36 -0000 1.41
+++ common/connection.c 26 Jul 2004 20:21:38 -0000
@@ -55,6 +55,8 @@
neccesary as removing a random connection while we are iterating through
a connection list might corrupt the list. */
int delayed_disconnect = 0;
+
+struct connection *current_connection;
/**************************************************************************
Command access levels for client-side use; at present, they are only
Index: common/connection.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/connection.h,v
retrieving revision 1.34
diff -u -r1.34 connection.h
--- common/connection.h 10 Apr 2004 03:47:49 -0000 1.34
+++ common/connection.h 26 Jul 2004 20:21:38 -0000
@@ -223,6 +223,7 @@
} statistics;
};
+extern struct connection *current_connection;
const char *cmdlevel_name(enum cmdlevel_id lvl);
enum cmdlevel_id cmdlevel_named(const char *token);
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.267
diff -u -r1.267 packets.c
--- common/packets.c 14 Jan 2004 11:58:12 -0000 1.267
+++ common/packets.c 26 Jul 2004 20:21:39 -0000
@@ -604,6 +604,12 @@
void pre_send_packet_chat_msg(struct connection *pc,
struct packet_chat_msg *packet)
{
+ if (current_connection) {
+ packet->conn_id = current_connection->id;
+ } else {
+ packet->conn_id = 255;
+ }
+
if (packet->x == -1 && packet->y == -1) {
/* since we can currently only send unsigned ints... */
assert(!is_normal_map_pos(255, 255));
@@ -620,6 +626,9 @@
packet->x = -1;
packet->y = -1;
}
+ if (packet->conn_id == 255) {
+ packet->conn_id = -1;
+ }
}
void pre_send_packet_player_attribute_chunk(struct connection *pc,
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.33
diff -u -r1.33 packets.def
--- common/packets.def 20 Jul 2004 11:05:37 -0000 1.33
+++ common/packets.def 26 Jul 2004 20:21:39 -0000
@@ -365,6 +365,7 @@
STRING message[MAX_LEN_MSG];
COORD x, y;
EVENT event;
+ CONNECTION conn_id;
end
PACKET_CHAT_MSG_REQ=19;cs,handle-per-conn,dsend
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.121
diff -u -r1.121 sernet.c
--- server/sernet.c 20 Jul 2004 17:05:26 -0000 1.121
+++ server/sernet.c 26 Jul 2004 20:21:42 -0000
@@ -609,6 +609,7 @@
err = gettimeofday(&start, &tz);
assert(!err);
#endif
+ current_connection = pconn;
connection_do_buffer(pconn);
start_processing_request(pconn,
pconn->server.
@@ -621,6 +622,7 @@
finish_processing_request(pconn);
connection_do_unbuffer(pconn);
+ current_connection = NULL;
if (!command_ok) {
close_connection(pconn);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#9513) connection id in chat,
Per I. Mathisen <=
|
|