From f40b3a3845a91d32798ba03d2c58e918104bed05 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 7 Sep 2022 18:15:05 +0300 Subject: [PATCH 44/44] 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 0c5a622452..879354a101 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -2369,13 +2369,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 +PACKET_WEB_CMA_SET = 257; cs + CITY id; key + CM_PARAMETER cm_parameter; +end + +PACKET_WEB_CMA_CLEAR = 258; cs + CITY id; +end + +PACKET_WEB_PLAYER_INFO_ADDITION = 259; sc, is-info PLAYER playerno; key UINT32 expected_income; end -PACKET_WEB_RULESET_UNIT_ADDITION = 258; sc, lsend +PACKET_WEB_RULESET_UNIT_ADDITION = 260; sc, lsend UNIT_TYPE id; key BV_ACTIONS utype_actions; diff --git a/fc_version b/fc_version index 17658499c0..e372e47678 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.07b" +NETWORK_CAPSTRING="+Freeciv.Devel-3.2-2022.Sep.07c" 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