From e5739641047f800d5c8395d57087c8acf28537d0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 17 Sep 2022 05:48:13 +0300 Subject: [PATCH 09/31] Add server support for (web-)client to request CMA See osdn #45485 Signed-off-by: Marko Lindqvist --- common/networking/packets.def | 13 +++++++++-- fc_version | 2 +- server/cityhand.c | 41 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/common/networking/packets.def b/common/networking/packets.def index 93910bbb41..d0e42d68cb 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -2380,13 +2380,22 @@ PACKET_WEB_CITY_INFO_ADDITION = 256; sc, lsend, is-game-info, force, cancel(PACK TURN granary_turns; end -PACKET_WEB_PLAYER_INFO_ADDITION = 257; sc, is-info, handle-via-fields +PACKET_WEB_CMA_SET = 257; cs, handle-via-fields + CITY id; key + CM_PARAMETER cm_parameter; +end + +PACKET_WEB_CMA_CLEAR = 258; cs, handle-via-fields + CITY id; +end + +PACKET_WEB_PLAYER_INFO_ADDITION = 259; sc, is-info, handle-via-fields PLAYER playerno; key UINT32 expected_income; end -PACKET_WEB_RULESET_UNIT_ADDITION = 258; sc, lsend, handle-via-fields +PACKET_WEB_RULESET_UNIT_ADDITION = 260; sc, lsend, handle-via-fields UNIT_TYPE id; key BV_ACTIONS utype_actions; diff --git a/fc_version b/fc_version index 233b104614..4296f43548 100755 --- a/fc_version +++ b/fc_version @@ -60,7 +60,7 @@ DEFAULT_FOLLOW_TAG=S3_2 # - No new mandatory capabilities can be added to the release branch; doing # so would break network capability of supposedly "compatible" releases. # -NETWORK_CAPSTRING="+Freeciv.Devel-3.2-2022.Sep.15" +NETWORK_CAPSTRING="+Freeciv.Devel-3.2-2022.Sep.17" FREECIV_DISTRIBUTOR="" diff --git a/server/cityhand.c b/server/cityhand.c index cd7723412f..6cd405a895 100644 --- a/server/cityhand.c +++ b/server/cityhand.c @@ -560,3 +560,44 @@ void handle_city_rally_point(struct player *pplayer, send_city_info(pplayer, pcity); } + +/**********************************************************************//** + Handles a request to change city CMA settings. +**************************************************************************/ +void handle_web_cma_set(struct player *pplayer, int id, + const struct cm_parameter *param) +{ + /* Supported only in freeciv-web builds for now - + * Let's be cautious for now, and not give any chance + * of client requests of server side CMA to overload + * server from a standard build. */ +#ifdef FREECIV_WEB + struct city *pcity = player_city_by_number(pplayer, id); + + if (pcity != NULL) { + if (pcity->cm_parameter == NULL) { + pcity->cm_parameter = fc_calloc(1, sizeof(struct cm_parameter)); + } + + cm_copy_parameter(pcity->cm_parameter, param); + + auto_arrange_workers(pcity); + + sync_cities(); + } +#endif /* FREECIV_WEB */ +} + +/**********************************************************************//** + Handles a request to clear city CMA settings. +**************************************************************************/ +void handle_web_cma_clear(struct player *pplayer, int id) +{ + struct city *pcity = player_city_by_number(pplayer, id); + + if (pcity != NULL) { + free(pcity->cm_parameter); + pcity->cm_parameter = NULL; + send_city_info(pplayer, pcity); + } +} -- 2.35.1