Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2003:
[Freeciv-Dev] (PR#6997) Reject old clients
Home

[Freeciv-Dev] (PR#6997) Reject old clients

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#6997) Reject old clients
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Sun, 30 Nov 2003 09:56:18 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=6997 >

Add code to reject old pre-delta clients at the server. The connection
attempt is recognized and a proper reject packet is sent back.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  (On the statement print "42 monkeys"+"1 snake"): BTW, both perl and Python
  get this wrong. Perl gives 43 and Python gives "42 monkeys1 snake", when 
  the answer is clearly "41 monkeys and 1 fat snake".  
    -- Jim Fulton, 10 Aug 1999

Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.147
diff -u -u -r1.147 srv_main.c
--- server/srv_main.c   2003/11/28 17:37:22     1.147
+++ server/srv_main.c   2003/11/30 17:55:14
@@ -47,6 +47,7 @@
 #include "capability.h"
 #include "capstr.h"
 #include "city.h"
+#include "dataio.h"
 #include "events.h"
 #include "fcintl.h"
 #include "game.h"
@@ -728,6 +729,47 @@
   /* a NULL packet can be returned from receive_packet_goto_route() */
   if (!packet)
     return TRUE;
+
+  /* 
+   * Old pre-delta clients (before 2003-11-28) send a
+   * PACKET_LOGIN_REQUEST (type 0) to the server. We catch this and
+   * reply with an old reject packet. Since there is no struct for
+   * this old packet anymore we build it by hand.
+   */
+  if (type == 0) {
+    unsigned char buffer[4096];
+    struct data_out dout;
+
+    freelog(LOG_ERROR,
+           _("Warning: rejecting old client %s"), conn_description(pconn));
+
+    dio_output_init(&dout, buffer, sizeof(buffer));
+    dio_put_uint16(&dout, 0);
+
+    /* 1 == PACKET_LOGIN_REPLY in the old client */
+    dio_put_uint8(&dout, 1);
+
+    dio_put_bool32(&dout, FALSE);
+    dio_put_string(&dout, _("Your client is too old. To use this server "
+                           "please upgrade your client to a CVS version "
+                           "later than 2003-11-28 or Freeciv 1.15.0 or "
+                           "later."));
+    dio_put_string(&dout, "");
+
+    {
+      size_t size = dio_output_used(&dout);
+      dio_output_rewind(&dout);
+      dio_put_uint16(&dout, size);
+
+      /* 
+       * Use send_connection_data instead of send_packet_data to avoid
+       * compression.
+       */
+      send_connection_data(pconn, buffer, size);
+    }
+
+    return FALSE;
+  }
 
   if (type == PACKET_SERVER_JOIN_REQ) {
     bool result =

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#6997) Reject old clients, Raimar Falke <=