<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15260 >

On 19/07/07, Ulrik Sverdrup  wrote:
>
> Bug [for global observers, not attached to player] :
> - 'Wonders of the World' and 'Top Five Cities' should be
> available but doesn't currently have any effect when selected.
>
> QUESTION: This patch allows even detached connections to send report
> packets and get the reports back. Is this a fundamental problem? If
> observers are not allowed at all in a game, they could still get this
> information.

 Modified your patches to fix that problem.


 - ML

diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-09-09 19:55:29.000000000 +0300
+++ freeciv/server/srv_main.c	2007-09-10 01:36:41.000000000 +0300
@@ -995,6 +995,12 @@
     return;
   }
 
+  if (pconn->player == NULL && !pconn->observer) {
+    freelog(LOG_ERROR,
+            "Got a report request %d from detached connection", type);
+    return;
+  }
+
   switch(type) {
   case REPORT_WONDERS_OF_THE_WORLD:
     report_wonders_of_the_world(dest);
@@ -1126,6 +1132,7 @@
   if (type == PACKET_CHAT_MSG_REQ
       || type == PACKET_SINGLE_WANT_HACK_REQ
       || type == PACKET_NATION_SELECT_REQ
+      || type == PACKET_REPORT_REQ
       || type == PACKET_EDIT_MODE
       || type == PACKET_EDIT_TILE
       || type == PACKET_EDIT_UNIT
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-08-21 21:41:47.000000000 +0300
+++ freeciv/common/packets.def	2007-09-10 01:22:29.000000000 +0300
@@ -1288,7 +1288,7 @@
 /*********************************************************
  Below are the packets that control single-player mode.  
 *********************************************************/
-PACKET_SINGLE_WANT_HACK_REQ=108;cs,handle-per-conn,no-handle
+PACKET_SINGLE_WANT_HACK_REQ=108;cs,handle-per-conn,handle-via-packet
  STRING token[MAX_LEN_NAME];
 end
 
diff -Nurd -X.diff_ignore freeciv/server/gamehand.c freeciv/server/gamehand.c
--- freeciv/server/gamehand.c	2007-07-04 14:04:17.000000000 +0300
+++ freeciv/server/gamehand.c	2007-09-10 01:22:29.000000000 +0300
@@ -508,8 +508,7 @@
 the file values. Sends an answer to the client once it's done.
 **************************************************************************/
 void handle_single_want_hack_req(struct connection *pc,
-    				 const struct packet_single_want_hack_req
-				 *packet)
+                                 struct packet_single_want_hack_req *packet)
 {
   struct section_file file;
   char *token = NULL;
diff -Nurd -X.diff_ignore freeciv/server/gamehand.h freeciv/server/gamehand.h
--- freeciv/server/gamehand.h	2007-03-05 19:13:46.000000000 +0200
+++ freeciv/server/gamehand.h	2007-09-10 01:22:29.000000000 +0300
@@ -28,10 +28,4 @@
 
 const char *new_challenge_filename(struct connection *pc);
 
-struct packet_single_want_hack_req;
-
-void handle_single_want_hack_req(struct connection *pc,
-    				 const struct packet_single_want_hack_req
-				 *packet);
-
 #endif  /* FC__GAMEHAND_H */
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-09-09 19:55:15.000000000 +0300
+++ freeciv/server/srv_main.c	2007-09-10 01:26:23.000000000 +0300
@@ -938,7 +938,7 @@
 }
 
 /**************************************************************************
-...
+  
 **************************************************************************/
 void handle_report_req(struct connection *pconn, enum report_type type)
 {
@@ -949,6 +949,12 @@
     return;
   }
 
+  if (pconn->player == NULL && !pconn->observer) {
+    freelog(LOG_ERROR,
+            "Got a report request %d from detached connection", type);
+    return;
+  }
+
   switch(type) {
   case REPORT_WONDERS_OF_THE_WORLD:
     report_wonders_of_the_world(dest);
@@ -1077,15 +1083,13 @@
   }
   
   /* valid packets from established connections but non-players */
-  if (type == PACKET_CHAT_MSG_REQ) {
-    handle_chat_msg_req(pconn,
-			((struct packet_chat_msg_req *) packet)->message);
-    return TRUE;
-  }
-
-  if (type == PACKET_SINGLE_WANT_HACK_REQ) {
-    handle_single_want_hack_req(pconn,
-		                (struct packet_single_want_hack_req *) packet);
+  if (type == PACKET_CHAT_MSG_REQ
+      || type == PACKET_SINGLE_WANT_HACK_REQ
+      || type == PACKET_REPORT_REQ) {
+    if (!server_handle_packet(type, packet, NULL, pconn)) {
+      freelog(LOG_ERROR, "Received unknown packet %d from %s",
+	      type, conn_description(pconn));
+    }
     return TRUE;
   }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to