Author: jtn
Date: Mon Jul 11 21:15:27 2016
New Revision: 33230

URL: http://svn.gna.org/viewcvs/freeciv?rev=33230&view=rev
Log:
Invent common/chat.h, initially containing only the special characters
used in chat messages.

See gna patch #7433.

Added:
    branches/S2_6/common/chat.h
      - copied, changed from r33229, branches/S2_6/server/handchat.h
Modified:
    branches/S2_6/client/gui-gtk-2.0/chatline.c
    branches/S2_6/client/gui-gtk-3.0/chatline.c
    branches/S2_6/client/gui-qt/chatline.cpp
    branches/S2_6/common/Makefile.am
    branches/S2_6/server/handchat.c
    branches/S2_6/server/handchat.h
    branches/S2_6/server/stdinhand.h

Modified: branches/S2_6/client/gui-gtk-2.0/chatline.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/chatline.c?rev=33230&r1=33229&r2=33230&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/chatline.c (original)
+++ branches/S2_6/client/gui-gtk-2.0/chatline.c Mon Jul 11 21:15:27 2016
@@ -30,6 +30,7 @@
 #include "support.h"
 
 /* common */
+#include "chat.h"
 #include "featured_text.h"
 #include "game.h"
 #include "packets.h"
@@ -95,16 +96,11 @@
 **************************************************************************/
 static bool is_plain_public_message(const char *s)
 {
-  /* FIXME: These prefix definitions are duplicated in the server. */
-  const char ALLIES_CHAT_PREFIX = '.';
-  const char SERVER_COMMAND_PREFIX = '/';
-  const char MESSAGE_PREFIX = ':';
-
   const char *p;
 
   /* If it is a server command or an explicit ally
    * message, then it is not a public message. */
-  if (s[0] == SERVER_COMMAND_PREFIX || s[0] == ALLIES_CHAT_PREFIX) {
+  if (s[0] == SERVER_COMMAND_PREFIX || s[0] == CHAT_ALLIES_PREFIX) {
     return FALSE;
   }
 
@@ -129,7 +125,7 @@
   while (p != NULL && *p != '\0') {
     if (fc_isspace(*p)) {
       return TRUE;
-    } else if (*p == MESSAGE_PREFIX) {
+    } else if (*p == CHAT_DIRECT_PREFIX) {
       return FALSE;
     }
     p++;

Modified: branches/S2_6/client/gui-gtk-3.0/chatline.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/chatline.c?rev=33230&r1=33229&r2=33230&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/chatline.c (original)
+++ branches/S2_6/client/gui-gtk-3.0/chatline.c Mon Jul 11 21:15:27 2016
@@ -30,6 +30,7 @@
 #include "support.h"
 
 /* common */
+#include "chat.h"
 #include "featured_text.h"
 #include "game.h"
 #include "packets.h"
@@ -95,16 +96,11 @@
 **************************************************************************/
 static bool is_plain_public_message(const char *s)
 {
-  /* FIXME: These prefix definitions are duplicated in the server. */
-  const char ALLIES_CHAT_PREFIX = '.';
-  const char SERVER_COMMAND_PREFIX = '/';
-  const char MESSAGE_PREFIX = ':';
-
   const char *p;
 
   /* If it is a server command or an explicit ally
    * message, then it is not a public message. */
-  if (s[0] == SERVER_COMMAND_PREFIX || s[0] == ALLIES_CHAT_PREFIX) {
+  if (s[0] == SERVER_COMMAND_PREFIX || s[0] == CHAT_ALLIES_PREFIX) {
     return FALSE;
   }
 
@@ -129,7 +125,7 @@
   while (p != NULL && *p != '\0') {
     if (fc_isspace(*p)) {
       return TRUE;
-    } else if (*p == MESSAGE_PREFIX) {
+    } else if (*p == CHAT_DIRECT_PREFIX) {
       return FALSE;
     }
     p++;

Modified: branches/S2_6/client/gui-qt/chatline.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/chatline.cpp?rev=33230&r1=33229&r2=33230&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/chatline.cpp    (original)
+++ branches/S2_6/client/gui-qt/chatline.cpp    Mon Jul 11 21:15:27 2016
@@ -18,6 +18,9 @@
 //Qt
 #include <QScrollBar>
 #include <QStyleFactory>
+
+// common
+#include "chat.h"
 
 // client
 #include "audio.h"
@@ -186,7 +189,8 @@
   if (chat_line->text() != "") {
     if (client_state() >= C_S_RUNNING && gui_options.gui_qt_allied_chat_only
         && is_plain_public_message(chat_line->text())) {
-      send_chat(QString(". %1")
+      send_chat(QString("%1 %2")
+                  .arg(CHAT_ALLIES_PREFIX)
                   .arg(chat_line->text().toUtf8().data()).toUtf8().data());
     } else {
       send_chat(chat_line->text().toUtf8().data());
@@ -426,24 +430,21 @@
 **************************************************************************/
 static bool is_plain_public_message(QString s)
 {
-  const char ALLIES_CHAT_PREFIX = '.';
-  const char SERVER_COMMAND_PREFIX = '/';
-  const char MESSAGE_PREFIX = ':';
   QString s1, str;
   int i;
 
   str = s.trimmed();
   if (str.at(0) == SERVER_COMMAND_PREFIX
-      || str.at(0) == ALLIES_CHAT_PREFIX
-      || str.at(0) == MESSAGE_PREFIX) {
+      || str.at(0) == CHAT_ALLIES_PREFIX
+      || str.at(0) == CHAT_DIRECT_PREFIX) {
     return false;
   }
 
   /* Search for private message */
-  if (!str.contains(':')) {
+  if (!str.contains(CHAT_DIRECT_PREFIX)) {
     return true;
   }
-  i = str.indexOf(':');
+  i = str.indexOf(CHAT_DIRECT_PREFIX);
   str = str.left(i);
 
   /* Compare all players and connections looking for match */

Modified: branches/S2_6/common/Makefile.am
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/Makefile.am?rev=33230&r1=33229&r2=33230&view=diff
==============================================================================
--- branches/S2_6/common/Makefile.am    (original)
+++ branches/S2_6/common/Makefile.am    Mon Jul 11 21:15:27 2016
@@ -25,6 +25,7 @@
                calendar.h      \
                capstr.c        \
                capstr.h        \
+               chat.h          \
                citizens.c      \
                citizens.h      \
                city.c          \

Copied: branches/S2_6/common/chat.h (from r33229, 
branches/S2_6/server/handchat.h)
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/chat.h?p2=branches/S2_6/common/chat.h&p1=branches/S2_6/server/handchat.h&r1=33229&r2=33230&rev=33230&view=diff
==============================================================================
--- branches/S2_6/server/handchat.h     (original)
+++ branches/S2_6/common/chat.h Mon Jul 11 21:15:27 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -10,13 +10,27 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 ***********************************************************************/
-#ifndef FC__HANDCHAT_H
-#define FC__HANDCHAT_H
+#ifndef FC__CHAT_H
+#define FC__CHAT_H
 
-#define ALLIESCHAT_COMMAND_PREFIX '.'
+/* Definitions related to interpreting chat messages.
+ * Behaviour generally can't be changed at whim because client and
+ * server are assumed to agree on these details. */
 
-struct connection;
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
 
-void handle_chat_msg_req(struct connection *pc, const char *message);
+/* Special characters in chatlines. */
 
-#endif  /* FC__HANDCHAT_H */
+/* The character to mark chatlines as server commands */
+/* FIXME this is still hard-coded in a lot of places */
+#define SERVER_COMMAND_PREFIX '/'
+#define CHAT_ALLIES_PREFIX '.'
+#define CHAT_DIRECT_PREFIX ':'
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif  /* FC__CHAT_H */

Modified: branches/S2_6/server/handchat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/handchat.c?rev=33230&r1=33229&r2=33230&view=diff
==============================================================================
--- branches/S2_6/server/handchat.c     (original)
+++ branches/S2_6/server/handchat.c     Mon Jul 11 21:15:27 2016
@@ -26,6 +26,7 @@
 #include "support.h"
 
 /* common */
+#include "chat.h"
 #include "game.h"
 #include "packets.h"
 #include "player.h"
@@ -336,7 +337,7 @@
      but confusing choice: even before this feature existed,
      novice players were trying /who, /nick etc.
      So consider this an incentive for IRC support,
-     or change it in stdinhand.h - rp
+     or change it in chat.h - rp
   */
   if (real_message[0] == SERVER_COMMAND_PREFIX) {
     /* pass it to the command parser, which will chop the prefix off */
@@ -345,7 +346,7 @@
   }
 
   /* Send to allies command */
-  if (real_message[0] == ALLIESCHAT_COMMAND_PREFIX) {
+  if (real_message[0] == CHAT_ALLIES_PREFIX) {
     /* this won't work if we aren't attached to a player */
     if (NULL == pconn->playing && !pconn->observer) {
       notify_conn(pconn->self, NULL, E_CHAT_ERROR, ftc_server,
@@ -384,7 +385,7 @@
      else complain (might be a typo-ed intended private message)
   */
   
-  cp = strchr(real_message, ':');
+  cp = strchr(real_message, CHAT_DIRECT_PREFIX);
 
   if (cp && (cp != &real_message[0])) {
     enum m_pre_result match_result_player, match_result_conn;
@@ -396,7 +397,7 @@
     (void) fc_strlcpy(name, real_message, MIN(sizeof(name),
                                               cp - real_message + 1));
 
-    double_colon = (*(cp+1) == ':');
+    double_colon = (*(cp+1) == CHAT_DIRECT_PREFIX);
     if (double_colon) {
       conn_dest = conn_by_user_prefix(name, &match_result_conn);
       if (match_result_conn == M_PRE_AMBIGUOUS) {

Modified: branches/S2_6/server/handchat.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/handchat.h?rev=33230&r1=33229&r2=33230&view=diff
==============================================================================
--- branches/S2_6/server/handchat.h     (original)
+++ branches/S2_6/server/handchat.h     Mon Jul 11 21:15:27 2016
@@ -13,8 +13,6 @@
 #ifndef FC__HANDCHAT_H
 #define FC__HANDCHAT_H
 
-#define ALLIESCHAT_COMMAND_PREFIX '.'
-
 struct connection;
 
 void handle_chat_msg_req(struct connection *pc, const char *message);

Modified: branches/S2_6/server/stdinhand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.h?rev=33230&r1=33229&r2=33230&view=diff
==============================================================================
--- branches/S2_6/server/stdinhand.h    (original)
+++ branches/S2_6/server/stdinhand.h    Mon Jul 11 21:15:27 2016
@@ -14,15 +14,13 @@
 #define FC__STDINHAND_H
 
 /* common */
+#include "chat.h"               /* SERVER_COMMAND_PREFIX */
 #include "connection.h"         /* enum cmdlevel */
 #include "fc_types.h"
 
 /* server */
 #include "commands.h"
 #include "console.h"
-
-#define SERVER_COMMAND_PREFIX '/'
-  /* the character to mark chatlines as server commands */
 
 void stdinhand_init(void);
 void stdinhand_turn(void);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to