Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2006:
[Freeciv-Dev] (PR#15844) per-conn for several packets
Home

[Freeciv-Dev] (PR#15844) per-conn for several packets

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#15844) per-conn for several packets
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 10 Mar 2006 15:35:00 -0800
Reply-to: bugs@xxxxxxxxxxx

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

These patches allow the toggle-ready and pick-nation packets to be 
handled per-conn.  This allows non-controlling players to send these 
packets.

As an example, you can now:

* Start a game.
* Set aifill 5.
* Observe.
* Pick nations for all 5 players.
* Start the game.

Previously the last 2 steps were impossible.

This was reported by Per in PR#15841.

-jason

Index: server/hand_gen.c
===================================================================
--- server/hand_gen.c   (revision 11752)
+++ server/hand_gen.c   (working copy)
@@ -21,7 +21,7 @@
 {
   switch(type) {
   case PACKET_NATION_SELECT_REQ:
-    handle_nation_select_req(pplayer,
+    handle_nation_select_req(pconn,
       ((struct packet_nation_select_req *)packet)->player_no,
       ((struct packet_nation_select_req *)packet)->nation_no,
       ((struct packet_nation_select_req *)packet)->is_male,
@@ -30,7 +30,7 @@
     return TRUE;
 
   case PACKET_PLAYER_READY:
-    handle_player_ready(pplayer,
+    handle_player_ready(pconn,
       ((struct packet_player_ready *)packet)->player_no,
       ((struct packet_player_ready *)packet)->is_ready);
     return TRUE;
Index: server/hand_gen.h
===================================================================
--- server/hand_gen.h   (revision 11752)
+++ server/hand_gen.h   (working copy)
@@ -20,8 +20,8 @@
 bool server_handle_packet(enum packet_type type, void *packet,
                          struct player *pplayer, struct connection *pconn);
 
-void handle_nation_select_req(struct player *pplayer, int player_no, 
Nation_type_id nation_no, bool is_male, char *name, int city_style);
-void handle_player_ready(struct player *pplayer, int player_no, bool is_ready);
+void handle_nation_select_req(struct connection *pc, int player_no, 
Nation_type_id nation_no, bool is_male, char *name, int city_style);
+void handle_player_ready(struct connection *pc, int player_no, bool is_ready);
 void handle_chat_msg_req(struct connection *pc, char *message);
 void handle_city_sell(struct player *pplayer, int city_id, int build_id);
 void handle_city_buy(struct player *pplayer, int city_id);
Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (revision 11752)
+++ server/srv_main.c   (working copy)
@@ -1029,6 +1029,8 @@
   /* valid packets from established connections but non-players */
   if (type == PACKET_CHAT_MSG_REQ
       || type == PACKET_SINGLE_WANT_HACK_REQ
+      || type == PACKET_NATION_SELECT_REQ
+      || type == PACKET_PLAYER_READY
       || type == PACKET_EDIT_MODE
       || type == PACKET_EDIT_TILE
       || type == PACKET_EDIT_UNIT
@@ -1268,7 +1270,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void handle_nation_select_req(struct player *requestor,
+void handle_nation_select_req(struct connection *pconn,
                              int player_no,
                              Nation_type_id nation_no, bool is_male,
                              char *name, int city_style)
@@ -1280,7 +1282,7 @@
     return;
   }
 
-  if (!can_conn_edit_players_nation(requestor->current_conn, pplayer)) {
+  if (!can_conn_edit_players_nation(pconn, pplayer)) {
     return;
   }
 
@@ -1340,7 +1342,7 @@
 /****************************************************************************
   Handle a player-ready packet.
 ****************************************************************************/
-void handle_player_ready(struct player *requestor,
+void handle_player_ready(struct connection *pconn,
                         int player_no,
                         bool is_ready)
 {
@@ -1352,8 +1354,8 @@
     return;
   }
 
-  if (pplayer != requestor) {
-    /* Currently you can only change your own readiness. */
+  if (!pplayer || (pplayer != pconn->player
+                  && pconn->access_level <= ALLOW_CTRL)) {
     return;
   }
 
Index: server/stdinhand.c
===================================================================
--- server/stdinhand.c  (revision 11752)
+++ server/stdinhand.c  (working copy)
@@ -3685,7 +3685,7 @@
       /* A detached or observer player can't do /start. */
       return TRUE;
     } else {
-      handle_player_ready(caller->player, caller->player->player_no, TRUE);
+      handle_player_ready(caller, caller->player->player_no, TRUE);
       return TRUE;
     }
   case GAME_OVER_STATE:
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 11752)
+++ common/packets.def  (working copy)
@@ -296,7 +296,7 @@
 PACKET_SERVER_SHUTDOWN=8;sc,lsend
 end
 
-PACKET_NATION_SELECT_REQ=10;cs,dsend
+PACKET_NATION_SELECT_REQ=10;cs,handle-per-conn,dsend
   PLAYER player_no;
   NATION nation_no;
   BOOL is_male;
@@ -304,7 +304,7 @@
   UINT8 city_style;
 end
 
-PACKET_PLAYER_READY=116;cs,dsend
+PACKET_PLAYER_READY=116;cs,handle-per-conn,dsend
   PLAYER player_no;
   BOOL is_ready;
 end
Index: server/hand_gen.c
===================================================================
--- server/hand_gen.c   (revision 11752)
+++ server/hand_gen.c   (working copy)
@@ -21,7 +21,7 @@
 {
   switch(type) {
   case PACKET_NATION_SELECT_REQ:
-    handle_nation_select_req(pplayer,
+    handle_nation_select_req(pconn,
       ((struct packet_nation_select_req *)packet)->player_no,
       ((struct packet_nation_select_req *)packet)->nation_no,
       ((struct packet_nation_select_req *)packet)->is_male,
@@ -30,7 +30,7 @@
     return TRUE;
 
   case PACKET_PLAYER_READY:
-    handle_player_ready(pplayer,
+    handle_player_ready(pconn,
       ((struct packet_player_ready *)packet)->player_no,
       ((struct packet_player_ready *)packet)->is_ready);
     return TRUE;
@@ -312,6 +312,10 @@
       ((struct packet_spaceship_place *)packet)->num);
     return TRUE;
 
+  case PACKET_SINGLE_WANT_HACK_REQ:
+    handle_single_want_hack_req(pconn, packet);
+    return TRUE;
+
   default:
     return FALSE;
   }
Index: server/hand_gen.h
===================================================================
--- server/hand_gen.h   (revision 11752)
+++ server/hand_gen.h   (working copy)
@@ -20,8 +20,8 @@
 bool server_handle_packet(enum packet_type type, void *packet,
                          struct player *pplayer, struct connection *pconn);
 
-void handle_nation_select_req(struct player *pplayer, int player_no, 
Nation_type_id nation_no, bool is_male, char *name, int city_style);
-void handle_player_ready(struct player *pplayer, int player_no, bool is_ready);
+void handle_nation_select_req(struct connection *pc, int player_no, 
Nation_type_id nation_no, bool is_male, char *name, int city_style);
+void handle_player_ready(struct connection *pc, int player_no, bool is_ready);
 void handle_chat_msg_req(struct connection *pc, char *message);
 void handle_city_sell(struct player *pplayer, int city_id, int build_id);
 void handle_city_buy(struct player *pplayer, int city_id);
@@ -73,5 +73,7 @@
 void handle_conn_pong(struct connection *pc);
 void handle_spaceship_launch(struct player *pplayer);
 void handle_spaceship_place(struct player *pplayer, enum spaceship_place_type 
type, int num);
+struct packet_single_want_hack_req;
+void handle_single_want_hack_req(struct connection *pc, struct 
packet_single_want_hack_req *packet);
 
 #endif /* FC__HAND_GEN_H */
Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (revision 11752)
+++ server/srv_main.c   (working copy)
@@ -1027,18 +1027,20 @@
   }
   
   /* 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);
+  if (type == PACKET_CHAT_MSG_REQ
+      || type == PACKET_SINGLE_WANT_HACK_REQ
+      || type == PACKET_NATION_SELECT_REQ
+      || type == PACKET_PLAYER_READY) {
+#if 0
+    || type == PACKET_REPORT_REQ) {
+#endif
+    if (!server_handle_packet(type, packet, NULL, pconn)) {
+      freelog(LOG_ERROR, "Received unknown packet %d from %s",
+             type, conn_description(pconn));
+    }
     return TRUE;
   }
 
-  if (type == PACKET_SINGLE_WANT_HACK_REQ) {
-    handle_single_want_hack_req(pconn,
-                               (struct packet_single_want_hack_req *) packet);
-    return TRUE;
-  }
-
   pplayer = pconn->player;
 
   if(!pplayer) {
@@ -1266,7 +1268,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void handle_nation_select_req(struct player *requestor,
+void handle_nation_select_req(struct connection *pconn,
                              int player_no,
                              Nation_type_id nation_no, bool is_male,
                              char *name, int city_style)
@@ -1278,7 +1280,7 @@
     return;
   }
 
-  if (!can_conn_edit_players_nation(requestor->current_conn, pplayer)) {
+  if (!can_conn_edit_players_nation(pconn, pplayer)) {
     return;
   }
 
@@ -1338,7 +1340,7 @@
 /****************************************************************************
   Handle a player-ready packet.
 ****************************************************************************/
-void handle_player_ready(struct player *requestor,
+void handle_player_ready(struct connection *pconn,
                         int player_no,
                         bool is_ready)
 {
@@ -1350,8 +1352,8 @@
     return;
   }
 
-  if (pplayer != requestor) {
-    /* Currently you can only change your own readiness. */
+  if (!pplayer || (pplayer != pconn->player
+                  && pconn->access_level <= ALLOW_CTRL)) {
     return;
   }
 
Index: server/gamehand.c
===================================================================
--- server/gamehand.c   (revision 11752)
+++ server/gamehand.c   (working copy)
@@ -501,8 +501,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;
Index: server/gamehand.h
===================================================================
--- server/gamehand.h   (revision 11752)
+++ server/gamehand.h   (working copy)
@@ -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 */
Index: server/stdinhand.c
===================================================================
--- server/stdinhand.c  (revision 11752)
+++ server/stdinhand.c  (working copy)
@@ -3685,7 +3685,7 @@
       /* A detached or observer player can't do /start. */
       return TRUE;
     } else {
-      handle_player_ready(caller->player, caller->player->player_no, TRUE);
+      handle_player_ready(caller, caller->player->player_no, TRUE);
       return TRUE;
     }
   case GAME_OVER_STATE:
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 11752)
+++ common/packets.def  (working copy)
@@ -294,7 +294,7 @@
 PACKET_SERVER_SHUTDOWN=8;sc,lsend
 end
 
-PACKET_NATION_SELECT_REQ=10;cs,dsend
+PACKET_NATION_SELECT_REQ=10;cs,handle-per-conn,dsend
   PLAYER player_no;
   NATION nation_no;
   BOOL is_male;
@@ -302,7 +302,7 @@
   UINT8 city_style;
 end
 
-PACKET_PLAYER_READY=116;cs,dsend
+PACKET_PLAYER_READY=116;cs,handle-per-conn,dsend
   PLAYER player_no;
   BOOL is_ready;
 end
@@ -1271,7 +1271,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
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#15844) per-conn for several packets, Jason Short <=