Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4595) new client function send_chat
Home

[Freeciv-Dev] (PR#4595) new client function send_chat

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4595) new client function send_chat
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Jul 2003 12:26:06 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch adds a new client function, send_chat().  This makes the GUI 
code for this action simpler.

The new function initializes the other values of the packet, which is 
good in general (we shouldn't send uninitialized values over the 
network; there's a PR# for this but I can't find it) and especially in 
this case (since these include map positions and we want to be 
particularly rigorous with them).

jason

Index: client/chatline_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/chatline_common.c,v
retrieving revision 1.3
diff -u -r1.3 chatline_common.c
--- client/chatline_common.c    2003/04/04 15:47:45     1.3
+++ client/chatline_common.c    2003/07/17 19:16:53
@@ -19,10 +19,27 @@
 #include <string.h>
 
 #include "astring.h"
+#include "packets.h"
+#include "support.h"
 
 #include "chatline_g.h"
 
 #include "chatline_common.h"
+#include "clinet.h"
+
+/**************************************************************************
+  Send the message as a chat to the server.
+**************************************************************************/
+void send_chat(const char *message)
+{
+  struct packet_generic_message apacket;
+
+  mystrlcpy(apacket.message, message, MAX_LEN_MSG - MAX_LEN_USERNAME + 1);
+  apacket.x = apacket.y = -1;
+  apacket.event = 0; /* ? */
+
+  send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+}
 
 static int frozen_level = 0;
 static struct astring remaining = ASTRING_INIT;
Index: client/chatline_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/chatline_common.h,v
retrieving revision 1.1
diff -u -r1.1 chatline_common.h
--- client/chatline_common.h    2002/06/27 01:00:48     1.1
+++ client/chatline_common.h    2003/07/17 19:16:53
@@ -15,6 +15,8 @@
 
 #include "shared.h"            /* bool type */
 
+void send_chat(const char *message);
+
 void append_output_window(const char *astring);
 
 void output_window_freeze(void);
Index: client/gui-gtk/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/chatline.c,v
retrieving revision 1.19
diff -u -r1.19 chatline.c
--- client/gui-gtk/chatline.c   2003/04/04 15:47:46     1.19
+++ client/gui-gtk/chatline.c   2003/07/17 19:16:53
@@ -40,14 +40,12 @@
 **************************************************************************/
 void inputline_return(GtkWidget *w, gpointer data)
 {
-  struct packet_generic_message apacket;
   char *theinput;
 
   theinput = gtk_entry_get_text(GTK_ENTRY(w));
   
   if (*theinput) {
-    mystrlcpy(apacket.message, theinput, MAX_LEN_MSG-MAX_LEN_USERNAME+1);
-    send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+    send_chat(theinput);
 
     if (genlist_size(&history_list) >= MAX_CHATLINE_HISTORY) {
       void *data;
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.7
diff -u -r1.7 chatline.c
--- client/gui-gtk-2.0/chatline.c       2002/11/14 09:14:55     1.7
+++ client/gui-gtk-2.0/chatline.c       2003/07/17 19:16:53
@@ -42,14 +42,12 @@
 **************************************************************************/
 void inputline_return(GtkEntry *w, gpointer data)
 {
-  struct packet_generic_message apacket;
   const char *theinput;
 
   theinput = gtk_entry_get_text(w);
   
   if (*theinput) {
-    mystrlcpy(apacket.message, theinput, MAX_LEN_MSG-MAX_LEN_USERNAME+1);
-    send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+    send_chat(theinput);
 
     if (genlist_size(&history_list) >= MAX_CHATLINE_HISTORY) {
       void *data;
Index: client/gui-mui/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/gui_main.c,v
retrieving revision 1.77
diff -u -r1.77 gui_main.c
--- client/gui-mui/gui_main.c   2003/07/02 16:40:18     1.77
+++ client/gui-mui/gui_main.c   2003/07/17 19:16:53
@@ -323,7 +323,6 @@
 *****************************************************************/
 static void inputline_return(void)     /* from chatline.c */
 {
-  struct packet_generic_message apacket;
   char *theinput;
   int contents;
 
@@ -332,8 +331,7 @@
 
   if (*theinput)
   {
-    mystrlcpy(apacket.message, theinput, MAX_LEN_MSG-MAX_LEN_USERNAME+1);
-    send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+    send_chat(theinput);
     contents = TRUE;
   }
   else
Index: client/gui-sdl/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/chatline.c,v
retrieving revision 1.9
diff -u -r1.9 chatline.c
--- client/gui-sdl/chatline.c   2003/07/07 20:15:31     1.9
+++ client/gui-sdl/chatline.c   2003/07/17 19:16:53
@@ -59,7 +59,6 @@
 **************************************************************************/
 static int inputline_return_callback(struct GUI *pWidget)
 {
-  struct packet_generic_message apacket;
   char *theinput = NULL;
 
   if (!pWidget->string16->text) {
@@ -69,9 +68,7 @@
   theinput = convert_to_chars(pWidget->string16->text);
 
   if (*theinput) {
-    mystrlcpy(apacket.message, theinput,
-             MAX_LEN_MSG - MAX_LEN_USERNAME + 1);
-    send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+    send_chat(theinput);
 
     real_append_output_window(theinput);
     FREE(theinput);
Index: client/gui-win32/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/chatline.c,v
retrieving revision 1.9
diff -u -r1.9 chatline.c
--- client/gui-win32/chatline.c 2003/01/23 21:39:32     1.9
+++ client/gui-win32/chatline.c 2003/07/17 19:16:53
@@ -62,11 +62,10 @@
 {
   static char msg_buf[MAX_LEN_MSG-MAX_LEN_USERNAME+1];
   char msg_buf2[MAX_LEN_MSG-MAX_LEN_USERNAME+1];
-  struct packet_generic_message apacket;
+
   GetWindowText(hchatline,msg_buf2,sizeof(msg_buf2));
   if (strchr(msg_buf2,'\n')) {
-    sz_strlcpy(apacket.message, msg_buf);
-    send_packet_generic_message(&aconnection, PACKET_CHAT_MSG,&apacket);
+    send_chat(msg_buf);
     SetWindowText(hchatline,"");
   } else {
     sz_strlcpy(msg_buf, msg_buf2);
Index: client/gui-win32/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/connectdlg.c,v
retrieving revision 1.13
diff -u -r1.13 connectdlg.c
--- client/gui-win32/connectdlg.c       2003/04/12 18:24:42     1.13
+++ client/gui-win32/connectdlg.c       2003/07/17 19:16:53
@@ -891,9 +891,7 @@
        server_autoconnect();
        add_server_control_buttons();
        if (Button_GetCheck(GetDlgItem(win,IDYES))==BST_CHECKED) {
-         struct packet_generic_message apacket;
-         mystrlcpy(apacket.message,"/start", MAX_LEN_MSG-MAX_LEN_USERNAME+1);
-         send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+         send_chat("/start");
        }
        DestroyWindow(win);
       }
@@ -1052,35 +1050,30 @@
 **************************************************************************/
 static void set_new_game_params(HWND win)
 {
-  int aifill;
-  struct packet_generic_message apacket;
+  int aifill, char aifill_str[MAX_LEN_MSG - MAX_LEN_USERNAME + 1];
+
   if (!is_server_running())
     start_server_for_new_game();
   GetWindowText(GetDlgItem(win,ID_NAME),user_name,512);
   server_autoconnect();
   add_server_control_buttons();
   if (IsDlgButtonChecked(win,ID_EASY)) {
-    mystrlcpy(apacket.message, "/easy", MAX_LEN_MSG-MAX_LEN_USERNAME+1);
+    send_chat("/easy");
   } else if (IsDlgButtonChecked(win,ID_MEDIUM)) {
-    mystrlcpy(apacket.message, "/normal", MAX_LEN_MSG-MAX_LEN_USERNAME+1);
+    send_chat("/normal");
   } else {
-    mystrlcpy(apacket.message, "/hard", MAX_LEN_MSG-MAX_LEN_USERNAME+1);   
+    send_chat("/hard");
   }
-  send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
 #if 0 
-  mystrlcpy(apacket.message, "/set autotoggle 1",
-           MAX_LEN_MSG-MAX_LEN_USERNAME+1);
-  send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+  send_chat("/set autotoggle 1");
 #endif
   aifill=ScrollBar_GetPos(GetDlgItem(win,ID_AIFILL));
-  my_snprintf(apacket.message, MAX_LEN_MSG-MAX_LEN_USERNAME+1,
-             "/set aifill %d", aifill);
-  send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+
+  my_snprintf(aifill_str, sizeof(aifill_str), "/set aifill %d", aifill);
+  send_chat(aifill);
    
   if (Button_GetCheck(GetDlgItem(win,ID_STARTGAME))==BST_CHECKED) {
-    struct packet_generic_message apacket;
-    mystrlcpy(apacket.message,"/start", MAX_LEN_MSG-MAX_LEN_USERNAME+1);
-    send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+    send_chat("/start");
   }
 }
 
Index: client/gui-xaw/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/chatline.c,v
retrieving revision 1.20
diff -u -r1.20 chatline.c
--- client/gui-xaw/chatline.c   2002/11/14 09:14:59     1.20
+++ client/gui-xaw/chatline.c   2003/07/17 19:16:53
@@ -42,15 +42,13 @@
 **************************************************************************/
 void chatline_key_send(Widget w)
 {
-  struct packet_generic_message apacket;
   String theinput;
   String empty="";
 
   XtVaGetValues(w, XtNstring, &theinput, NULL);
   
   if(*theinput) {
-    mystrlcpy(apacket.message, theinput, MAX_LEN_MSG-MAX_LEN_USERNAME+1);
-    send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+    send_chat(theinput);
   }
 
   XtVaSetValues(w, XtNstring, empty, NULL);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4595) new client function send_chat, Jason Short <=