Author: cazfi
Date: Tue Jun 28 19:29:14 2016
New Revision: 33091

URL: http://svn.gna.org/viewcvs/freeciv?rev=33091&view=rev
Log:
Allow observer with hack access to start the game from the client gui,
if there's no human players to do it.

See paych #7334

Modified:
    branches/S2_6/client/client_main.c
    branches/S2_6/client/gui-gtk-2.0/pages.c
    branches/S2_6/client/gui-gtk-3.0/pages.c
    branches/S2_6/client/gui-qt/fc_client.cpp
    branches/S2_6/client/gui-qt/pages.cpp
    branches/S2_6/server/srv_main.c

Modified: branches/S2_6/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.c?rev=33091&r1=33090&r2=33091&view=diff
==============================================================================
--- branches/S2_6/client/client_main.c  (original)
+++ branches/S2_6/client/client_main.c  Tue Jun 28 19:29:14 2016
@@ -1218,7 +1218,7 @@
 bool can_client_control(void)
 {
   return (NULL != client.conn.playing
-         && !client_is_observer());
+          && !client_is_observer());
 }
 
 /**************************************************************************

Modified: branches/S2_6/client/gui-gtk-2.0/pages.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/pages.c?rev=33091&r1=33090&r2=33091&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/pages.c    (original)
+++ branches/S2_6/client/gui-gtk-2.0/pages.c    Tue Jun 28 19:29:14 2016
@@ -2063,6 +2063,8 @@
     dsend_packet_player_ready(&client.conn,
                               player_number(client_player()),
                               !client_player()->is_ready);
+  } else {
+    dsend_packet_player_ready(&client.conn, 0, TRUE);
   }
 }
 
@@ -2141,7 +2143,19 @@
     }
   } else {
     text = _("_Start");
-    sensitive = FALSE;
+    if (can_client_access_hack()) {
+      sensitive = TRUE;
+      players_iterate(plr) {
+        if (!plr->ai_controlled) {
+          /* There's human controlled player(s) in game, so it's their
+           * job to start the game. */
+          sensitive = FALSE;
+          break;
+        }
+      } players_iterate_end;
+    } else {
+      sensitive = FALSE;
+    }
   }
   gtk_stockbutton_set_label(ready_button, text);
   gtk_widget_set_sensitive(ready_button, sensitive);

Modified: branches/S2_6/client/gui-gtk-3.0/pages.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/pages.c?rev=33091&r1=33090&r2=33091&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/pages.c    (original)
+++ branches/S2_6/client/gui-gtk-3.0/pages.c    Tue Jun 28 19:29:14 2016
@@ -2128,6 +2128,8 @@
     dsend_packet_player_ready(&client.conn,
                               player_number(client_player()),
                               !client_player()->is_ready);
+  } else {
+    dsend_packet_player_ready(&client.conn, 0, TRUE);
   }
 }
 
@@ -2206,7 +2208,19 @@
     }
   } else {
     text = _("_Start");
-    sensitive = FALSE;
+    if (can_client_access_hack()) {
+      sensitive = TRUE;
+      players_iterate(plr) {
+        if (!plr->ai_controlled) {
+          /* There's human controlled player(s) in game, so it's their
+           * job to start the game. */
+          sensitive = FALSE;
+          break;
+        }
+      } players_iterate_end;
+    } else {
+      sensitive = FALSE;
+    }
   }
   gtk_stockbutton_set_label(ready_button, text);
   gtk_widget_set_sensitive(ready_button, sensitive);

Modified: branches/S2_6/client/gui-qt/fc_client.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/fc_client.cpp?rev=33091&r1=33090&r2=33091&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fc_client.cpp   (original)
+++ branches/S2_6/client/gui-qt/fc_client.cpp   Tue Jun 28 19:29:14 2016
@@ -500,6 +500,8 @@
     dsend_packet_player_ready(&client.conn,
                               player_number(client_player()),
                               !client_player()->is_ready);
+  } else {
+    dsend_packet_player_ready(&client.conn, 0, TRUE);
   }
 }
 

Modified: branches/S2_6/client/gui-qt/pages.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/pages.cpp?rev=33091&r1=33090&r2=33091&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/pages.cpp       (original)
+++ branches/S2_6/client/gui-qt/pages.cpp       Tue Jun 28 19:29:14 2016
@@ -1504,7 +1504,19 @@
     }
   } else {
     text = _("Start");
-    sensitive = false;
+    if (can_client_access_hack()) {
+      sensitive = true;
+      players_iterate(plr) {
+        if (!plr->ai_controlled) {
+          /* There's human controlled player(s) in game, so it's their
+           * job to start the game. */
+          sensitive = false;
+          break;
+        }
+      } players_iterate_end;
+    } else {
+      sensitive = false;
+    }
   }
   li = pages_layout[PAGE_START]->itemAtPosition(5, 7);
   pb = qobject_cast<QPushButton *>(li->widget());

Modified: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=33091&r1=33090&r2=33091&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Tue Jun 28 19:29:14 2016
@@ -160,6 +160,8 @@
 static int mapimg_server_plrcolor_count(void);
 static struct rgbcolor *mapimg_server_plrcolor_get(int i);
 
+static void handle_observer_ready(struct connection *pconn);
+
 /* command-line arguments to server */
 struct server_arguments srvarg;
 
@@ -1767,16 +1769,17 @@
 }
 
 /**************************************************************************
-Returns 0 if connection should be closed (because the clients was
-rejected). Returns 1 else.
+  Returns FALSE if connection should be closed (because the clients was
+  rejected). Returns TRUE else.
 **************************************************************************/
 bool server_packet_input(struct connection *pconn, void *packet, int type)
 {
   struct player *pplayer;
 
   /* a NULL packet can be returned from receive_packet_goto_route() */
-  if (!packet)
+  if (!packet) {
     return TRUE;
+  }
 
   /* 
    * Old pre-delta clients (before 2003-11-28) send a
@@ -1841,7 +1844,7 @@
               packet_name(type), type, conn_description(pconn));
     return TRUE;
   }
-  
+
   /* valid packets from established connections but non-players */
   if (type == PACKET_CHAT_MSG_REQ
       || type == PACKET_SINGLE_WANT_HACK_REQ
@@ -1872,6 +1875,10 @@
   pplayer = pconn->playing;
 
   if (NULL == pplayer || pconn->observer) {
+    if (type == PACKET_PLAYER_READY && pconn->observer) {
+      handle_observer_ready(pconn);
+      return TRUE;
+    }
     /* don't support these yet */
     log_error("Received packet %s(%d) from non-player connection %s.",
               packet_name(type), type, conn_description(pconn));
@@ -2097,6 +2104,22 @@
 
   (void) player_set_nation(pplayer, new_nation);
   send_player_info_c(pplayer, game.est_connections);
+}
+
+/****************************************************************************
+  Handle a player-ready packet from global observer.
+****************************************************************************/
+static void handle_observer_ready(struct connection *pconn)
+{
+  if (pconn->access_level == ALLOW_HACK) {
+    players_iterate(plr) {
+      if (!plr->ai_controlled) {
+        return;
+      }
+    } players_iterate_end;
+
+    start_command(NULL, FALSE, TRUE);
+  }
 }
 
 /****************************************************************************


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

Reply via email to