Freeciv-3.4
Loading...
Searching...
No Matches
srv_main.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include "fc_prehdrs.h"
19
20#include <ctype.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <time.h>
25
26#ifdef HAVE_NETDB_H
27#include <netdb.h>
28#endif
29#ifdef HAVE_SYS_IOCTL_H
30#include <sys/ioctl.h>
31#endif
32#ifdef HAVE_SYS_TERMIO_H
33#include <sys/termio.h>
34#endif
35#ifdef FREECIV_HAVE_SYS_TYPES_H
36#include <sys/types.h>
37#endif
38#ifdef HAVE_TERMIOS_H
39#include <termios.h>
40#endif
41#ifdef HAVE_UNISTD_H
42#include <unistd.h>
43#endif
44
45/* dependencies/lua */
46#include "lua.h" /* lua_Integer */
47
48/* utility */
49#include "astring.h"
50#include "bitvector.h"
51#include "bugs.h"
52#include "capability.h"
53#include "fc_cmdline.h"
54#include "fciconv.h"
55#include "fcintl.h"
56#include "log.h"
57#include "mem.h"
58#include "netintf.h"
59#include "rand.h"
60#include "randseed.h"
61#include "registry.h"
62#include "support.h"
63#include "timing.h"
64
65/* common/aicore */
66#include "citymap.h"
67
68/* common */
69#include "accessarea.h"
70#include "achievements.h"
71#include "calendar.h"
72#include "capstr.h"
73#include "city.h"
74#include "counters.h"
75#include "culture.h"
76#include "dataio.h"
77#include "effects.h"
78#include "events.h"
79#include "fc_interface.h"
80#include "government.h"
81#include "map.h"
82#include "mapimg.h"
83#include "modpack.h"
84#include "nation.h"
85#include "packets.h"
86#include "player.h"
87#include "research.h"
88#include "tech.h"
89#include "unitlist.h"
90#include "version.h"
91#include "victory.h"
92
93/* server */
94#include "aiiface.h"
95#include "animals.h"
96#include "auth.h"
97#include "barbarian.h"
98#include "cityhand.h"
99#include "citytools.h"
100#include "cityturn.h"
101#include "connecthand.h"
102#include "console.h"
103#include "fcdb.h"
104#include "diplhand.h"
105#include "edithand.h"
106#include "gamehand.h"
107#include "handchat.h"
108#include "maphand.h"
109#include "meta.h"
110#include "notify.h"
111#include "plrhand.h"
112#include "report.h"
113#include "ruleload.h"
114#include "sanitycheck.h"
115#include "score.h"
116#include "sernet.h"
117#include "settings.h"
118#include "spacerace.h"
119#include "srv_log.h"
120#include "srv_signal.h"
121#include "stdinhand.h"
122#include "techtools.h"
123#include "unithand.h"
124#include "unittools.h"
125#include "voting.h"
126
127/* server/advisors */
128#include "advdata.h"
129#include "autoworkers.h"
130#include "advbuilding.h"
131#include "advspace.h"
132#include "infracache.h"
133
134/* server/savegame */
135#include "savemain.h"
136
137/* server/scripting */
138#include "script_fcdb.h"
139#include "script_server.h"
140#include "luascript_types.h"
141
142/* server/generator */
143#include "mapgen.h"
144#include "mapgen_utils.h"
145
146/* ai */
147#include "aitraits.h"
148#include "difficulty.h"
149
150#include "srv_main.h"
151
152static void end_turn(void);
153static void announce_player(struct player *pplayer);
154static void fc_interface_init_server(void);
155
156static enum known_type mapimg_server_tile_known(const struct tile *ptile,
157 const struct player *pplayer,
158 bool knowledge);
159static struct terrain
160 *mapimg_server_tile_terrain(const struct tile *ptile,
161 const struct player *pplayer, bool knowledge);
162static struct player *mapimg_server_tile_owner(const struct tile *ptile,
163 const struct player *pplayer,
164 bool knowledge);
165static struct player *mapimg_server_tile_city(const struct tile *ptile,
166 const struct player *pplayer,
167 bool knowledge);
168static struct player *mapimg_server_tile_unit(const struct tile *ptile,
169 const struct player *pplayer,
170 bool knowledge);
171
172static int mapimg_server_plrcolor_count(void);
173static struct rgbcolor *mapimg_server_plrcolor_get(int i);
174
175static void save_all_map_images(void);
176
177static void handle_observer_ready(struct connection *pconn);
178
179static void world_peace_update(void);
180
181/* Command-line arguments to server */
183
184/* Server aggregate information */
186
187/* Server state information */
189
190/* This global is checked deep down the netcode.
191 packets handling functions can set it to none-zero, to
192 force end-of-tick asap
193*/
195
197
198/* Server initialized flag */
200
201/* Time server processing at end-of-turn */
202static struct timer *eot_timer = nullptr;
203
204static struct timer *between_turns = nullptr;
205
206/**********************************************************************/
210{
211 if (game.server.seed_setting == 0) {
212 /* We strip the high bit for now because neither game file nor
213 server options can handle unsigned ints yet. - Cedric */
215#ifdef FREECIV_TESTMATIC
216 /* Log command to reproduce the gameseed */
217 log_testmatic("set gameseed %u", game.server.seed);
218#else /* FREECIV_TESTMATIC */
219 log_debug("Setting game.seed:%u", game.server.seed);
220#endif /* FREECIV_TESTMATIC */
221 } else {
223 }
224
225 if (!fc_rand_is_init()) {
227 }
228}
229
230/**********************************************************************/
233void srv_init(void)
234{
235 /* fc_interface_init_server() includes low level support like
236 * guaranteeing that fc_vsnprintf() will work after it,
237 * so this need to be early. */
239
240 i_am_server(); /* Tell to libfreeciv that we are server */
241
242#ifdef ENABLE_NLS
243 (void) bindtextdomain("freeciv-nations", get_locale_dir());
244#endif
245
246 /* This is before ai module initializations so that if ai module
247 * wants to use registry files, it can. */
249
250 /* We want this before any AI stuff */
252
253 /* This must be before command line argument parsing.
254 This allocates default AI, and we want that to take place before
255 loading additional AI modules from command line. */
256 ai_init();
257
258 /* Init server arguments... */
259
263 srvarg.identity_name[0] = '\0';
264 srvarg.serverid[0] = '\0';
265
266 srvarg.bind_addr = nullptr;
267#ifdef FREECIV_JSON_CONNECTION
269#else /* FREECIV_JSON_CONNECTION */
271#endif /* FREECIV_JSON_CONNECTION */
272
273 srvarg.bind_meta_addr = nullptr;
274
276
277 srvarg.log_filename = nullptr;
279 srvarg.ranklog_filename = nullptr;
280 srvarg.load_filename[0] = '\0';
281 srvarg.script_filename = nullptr;
284 srvarg.ruleset = nullptr;
285
286 srvarg.quitidle = 0;
287
289 srvarg.fcdb_conf = nullptr;
293
294 /* Mark as initialized */
296
297 /* Init character encodings. */
299#ifdef ENABLE_NLS
301#endif
302
303 /* Initialize callbacks. */
305
306 /* Initialize global mutexes */
308
309 /* Done */
310 return;
311}
312
313/**********************************************************************/
316void handle_client_info(struct connection *pc, enum gui_type gui,
317 int emerg_version, const char *distribution)
318{
319 pc->client_gui = gui;
320 log_debug("%s's client has %s gui.", pc->username, gui_type_name(gui));
321 if (emerg_version > 0) {
322 log_debug("It's emergency release .%d", emerg_version);
323 }
324 if (strcmp(distribution, "")) {
325 log_debug("It comes from %s distribution.", distribution);
326 }
327
328 /* In case a modified client sends multiple client_info packets */
330
331 if (gui == GUI_WEB) {
333 }
334}
335
336/**********************************************************************/
340{
341 return civserver_state;
342}
343
344/**********************************************************************/
351
352/**********************************************************************/
356{
357 return (!game.info.is_new_game || S_S_INITIAL != server_state());
358}
359
360/**********************************************************************/
370{
371 int candidates, defeated;
372 struct player *victor;
373 int winners = 0;
374 struct astring str = ASTRING_INIT;
375
376 /* Check for scenario victory; dead players can win if they are on a team
377 * with the winners. */
378 players_iterate(pplayer) {
380 || get_player_bonus(pplayer, EFT_VICTORY) > 0) {
381 if (winners) {
382 /* TRANS: Another entry in winners list (", the Tibetans") */
383 astr_add(&str, Q_("?winners:, the %s"),
384 nation_plural_for_player(pplayer));
385 } else {
386 /* TRANS: Beginning of the winners list ("the French") */
387 astr_add(&str, Q_("?winners:the %s"),
388 nation_plural_for_player(pplayer));
389 }
390 pplayer->is_winner = TRUE;
391 winners++;
392 }
394 if (winners) {
396 /* TRANS: There can be several winners listed */
397 _("Scenario victory to %s."), astr_str(&str));
398 log_normal(_("Scenario victory to %s."), astr_str(&str));
399 astr_free(&str);
400 return TRUE;
401 }
402 astr_free(&str);
403
404 /* Count candidates for the victory. */
405 candidates = 0;
406 defeated = 0;
407 victor = nullptr;
408 /* Do not use player_iterate_alive() here - dead player must be counted as
409 * defeated to end the game with a victory. */
410 players_iterate(pplayer) {
411 if (is_barbarian(pplayer)) {
412 continue;
413 }
414
415 if ((pplayer)->is_alive
416 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
417 candidates++;
418 victor = pplayer;
419 } else {
420 defeated++;
421 }
423
424 if (0 == candidates) {
426 _("Game is over."));
427 log_normal(_("Game is over."));
428 return TRUE;
429 } else {
430 if (defeated > 0) {
431 /* If nobody conceded the game, it mays be a solo game or a single team
432 * game. */
433 fc_assert(victor != nullptr);
434
435 /* Quit if we have team victory. */
436 if (1 < team_count()) {
438 const struct player_list *members = team_members(pteam);
439 int team_candidates = 0, team_defeated = 0;
440
441 if (1 == player_list_size(members)) {
442 /* This is not really a team, single players are handled below. */
443 continue;
444 }
445
446 player_list_iterate(members, pplayer) {
447 if (pplayer->is_alive
448 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
450 } else {
452 }
454
457
459 /* We need a player in a other team to conced the game here. */
461 _("Team victory to %s."),
463 log_normal(_("Team victory to %s."), team_name_translation(pteam));
464 /* All players of the team win, even dead and surrended ones. */
465 player_list_iterate(members, pplayer) {
466 pplayer->is_winner = TRUE;
468
469 return TRUE;
470 }
472 }
473 }
474
475 /* Check for allied victory. */
478
479 /* Try to build a winner list. */
480 players_iterate_alive(pplayer) {
481 if (is_barbarian(pplayer)
482 || player_status_check((pplayer), PSTATUS_SURRENDER)) {
483 continue;
484 }
485
487 if (!pplayers_allied(aplayer, pplayer)) {
489 winner_list = nullptr;
490 break;
491 }
493
494 if (winner_list == nullptr) {
495 break;
496 }
499
500 if (winner_list != nullptr) {
501 bool first = TRUE;
502
504
505 astr_init(&str);
507 if (first) {
508 /* TRANS: Beginning of the winners list ("the French") */
509 astr_add(&str, Q_("?winners:the %s"),
510 nation_plural_for_player(pplayer));
511 first = FALSE;
512 } else {
513 /* TRANS: Another entry in winners list (", the Tibetans") */
514 astr_add(&str, Q_("?winners:, the %s"),
515 nation_plural_for_player(pplayer));
516 }
517 pplayer->is_winner = TRUE;
520 /* TRANS: There can be several winners listed */
521 _("Allied victory to %s."), astr_str(&str));
522 log_normal(_("Allied victory to %s."), astr_str(&str));
523 astr_free(&str);
525 return TRUE;
526 }
527 }
528
529 /* Check for World Peace victory. */
532 bool first = TRUE;
533
534 astr_init(&str);
535
536 players_iterate_alive(pplayer) {
537 if (first) {
538 /* TRANS: Beginning of the winners list ("the French") */
539 astr_add(&str, Q_("?winners:the %s"),
540 nation_plural_for_player(pplayer));
541 first = FALSE;
542 } else {
543 /* TRANS: Another entry in winners list (", the Tibetans") */
544 astr_add(&str, Q_("?winners:, the %s"),
545 nation_plural_for_player(pplayer));
546 }
547
548 pplayer->is_winner = TRUE;
549
551
553 /* TRANS: There can be several winners listed */
554 _("World Peace victory to %s."), astr_str(&str));
555 log_normal(_("World Peace victory to %s."), astr_str(&str));
556 astr_free(&str);
557
558 return TRUE;
559 }
560 }
561
562 /* Check for single player victory. */
563 if (1 == candidates && victor != nullptr) {
564 bool found = FALSE; /* We need at least one enemy defeated. */
565
566 players_iterate(pplayer) {
567 if (pplayer != victor
568 && !is_barbarian(pplayer)
569 && (!pplayer->is_alive
571 && pplayer->team != victor->team
573 || !pplayers_allied(victor, pplayer))) {
574 found = TRUE;
575 break;
576 }
578
579 if (found) {
581 _("Game ended in conquest victory for %s."), player_name(victor));
582 log_normal(_("Game ended in conquest victory for %s."), player_name(victor));
583 victor->is_winner = TRUE;
584 return TRUE;
585 }
586 }
587 }
588
589 /* Check for culture victory */
591 struct player *best = nullptr;
592 long best_value = -1;
593 long second_value = -1;
594
595 players_iterate(pplayer) {
596 if (is_barbarian(pplayer) || !pplayer->is_alive) {
597 continue;
598 }
599
600 if (pplayer->score.culture > best_value) {
601 best = pplayer;
603 best_value = pplayer->score.culture;
604 } else if (pplayer->score.culture > second_value) {
605 second_value = pplayer->score.culture;
606 }
608
609 if (best != nullptr && best_value >= game.info.culture_vic_points
610 && best_value > second_value * (100 + game.info.culture_vic_lead) / 100) {
612 _("Game ended in cultural domination victory for %s."),
613 player_name(best));
614 log_normal(_("Game ended in cultural domination victory for %s."),
615 player_name(best));
616 best->is_winner = TRUE;
617
618 return TRUE;
619 }
620 }
621
622 /* Quit if we are past the turn limit. */
625 _("Game ended as the turn limit was exceeded."));
626 log_normal(_("Game ended as the turn limit was exceeded."));
627 return TRUE;
628 } else if (game.info.turn == game.server.end_turn) {
629 /* Give them a chance to decide to extend the game */
631 _("Notice: game will end at the end of this turn due "
632 "to 'endturn' server setting."));
633 }
634
635 /* Check for a spacerace win (and notify of imminent arrivals).
636 * Check this after checking turn limit, because we are checking for
637 * the spaceship arriving in the year corresponding to the turn
638 * that's about to start. */
639 {
640 int n, i;
642
644
645 for (i = 0; i < n; i++) {
646 struct player *pplayer = arrivals[i];
647 const struct player_list *members;
648 bool win;
649
650 if (game.info.year < (int)spaceship_arrival(pplayer)) {
651 /* We are into the future arrivals */
652 break;
653 }
654
655 /* Mark as arrived and notify everyone. */
656 spaceship_arrived(pplayer);
657
658 if (!game.server.endspaceship) {
659 /* Games does not end on spaceship arrival. At least print all the
660 * arrival messages. */
661 continue;
662 }
663
664 /* This player has won, now check if anybody else wins with them. */
665 members = team_members(pplayer->team);
666 win = FALSE;
668 if (pplayer->is_alive
670 /* We need at least one player to be a winner candidate in the
671 * team. */
672 win = TRUE;
673 break;
674 }
676
677 if (!win) {
678 /* Let's try next arrival. */
679 continue;
680 }
681
682 if (1 < player_list_size(members)) {
683 notify_conn(nullptr, nullptr, E_GAME_END, ftc_server,
684 _("Team victory to %s."),
685 team_name_translation(pplayer->team));
686 /* All players of the team win, even dead and surrendered ones. */
688 pteammate->is_winner = TRUE;
690 } else {
691 notify_conn(nullptr, nullptr, E_GAME_END, ftc_server,
692 _("Game ended in victory for %s."), player_name(pplayer));
693 pplayer->is_winner = TRUE;
694 }
695 return TRUE;
696 }
697
698 /* Print notice(s) of imminent arrival. These are not infallible
699 * (quite apart from risk of enemy action) because arrival is
700 * year-based, and some effect may change the timeline between
701 * now and the end of the next turn.
702 * (Also the order of messages will not always indicate tie-breaks,
703 * if the shuffled order is changed every turn, as it is for
704 * PMT_CONCURRENT games.) */
705 for (; i < n; i++) {
706 const struct player *pplayer = arrivals[i];
707 struct packet_game_info next_info = game.info; /* struct copy */
708
709 /* Advance the calendar in a throwaway copy of game.info. */
711
712 if (next_info.year < (int)spaceship_arrival(pplayer)) {
713 /* Even further in the future */
714 break;
715 }
716
717 notify_player(nullptr, nullptr, E_SPACESHIP, ftc_server,
718 _("Notice: the %s spaceship will likely arrive at "
719 "Alpha Centauri next turn."),
721 }
722 }
723
724 return FALSE;
725}
726
727/**********************************************************************/
732void send_all_info(struct conn_list *dest)
733{
734 conn_list_iterate(dest, pconn) {
737 }
739
740 /* Resend player info because it could have more infos (e.g. embassy). */
741 send_player_all_c(nullptr, dest);
745 send_map_info(dest);
749 send_spaceship_info(nullptr, dest);
750
754
758}
759
760/**********************************************************************/
764static void do_reveal_effects(void)
765{
766 phase_players_iterate(pplayer) {
767 if (get_player_bonus(pplayer, EFT_REVEAL_CITIES) > 0) {
768 players_iterate(other_player) {
769 city_list_iterate(other_player->cities, pcity) {
770 map_show_tile(pplayer, pcity->tile);
773 }
774 if (get_player_bonus(pplayer, EFT_REVEAL_MAP) > 0) {
775 /* map_show_all() will mark all unknown tiles as known and send
776 * tile, unit, and city updates as necessary. No other actions are
777 * needed. */
778 map_show_all(pplayer);
779 }
781}
782
783/**********************************************************************/
787static void do_have_contacts_effect(void)
788{
789 phase_players_iterate(pplayer) {
790 if (get_player_bonus(pplayer, EFT_HAVE_CONTACTS) > 0) {
792 /* Note this gives pplayer contact with pother, but doesn't give
793 * pother contact with pplayer. This may cause problems in other
794 * parts of the code if we're not careful. */
795 make_contact(pplayer, pother, nullptr);
797 }
799}
800
801/**********************************************************************/
804static void do_border_vision_effect(void)
805{
807 /* Border_Vision is useless. If borders are disabled there are no
808 * borders to see inside. If borders are seen they are seen already.
809 * The borders setting can't change after the game has started. */
810 return;
811 }
812
815
816 /* Check the Border_Vision effect for this player. */
818
819 if (new_border_vision != plr->server.border_vision) {
820 /* Border vision changed. */
821
822 /* Update the map */
824 }
826}
827
828/**********************************************************************/
832 int *current, int *accum, int *level,
833 int percent,
834 void (*upset_action_fn)(int))
835{
836 int count;
837
838 count = 0;
839 extra_type_iterate(cause) {
840 if (extra_causes_env_upset(cause, type)) {
841 whole_map_iterate(&(wld.map), ptile) {
842 if (tile_has_extra(ptile, cause)) {
843 count++;
844 }
846 }
848
849 *current = (count * percent) / 100;
850 *accum += count;
851 if (*accum < *level) {
852 *accum = 0;
853 } else {
854 *accum -= *level;
855 if (fc_rand((map_num_tiles() + 19) / 20) < *accum) {
856 upset_action_fn((MAP_NATIVE_WIDTH / 10) + (MAP_NATIVE_HEIGHT / 10) + ((*accum) * 5));
857 *accum = 0;
858 *level += (map_num_tiles() + 999) / 1000;
859 }
860 }
861
862 log_debug("environmental_upset: type=%-4d current=%-2d "
863 "level=%-2d accum=%-2d", type, *current, *level, *accum);
864}
865
866/**********************************************************************/
870 struct player *pguest,
871 int turns_left)
872{
873 int nunits = 0;
874 struct unit *a_unit = nullptr;
875
877 struct tile *ptile = unit_tile(punit);
878
879 if (tile_owner(ptile) == phost
882 nunits++;
883 a_unit = punit;
884 }
886
887 if (nunits > 0) {
889
891 /* TRANS: "... 2 military units in Norwegian territory." */
892 PL_("Warning: you still have %d military unit in %s territory.",
893 "Warning: you still have %d military units in %s territory.",
894 nunits),
896 /* If there's one lousy unit left, we may as well include a link for it */
897 notify_player(pguest, nunits == 1 ? unit_tile(a_unit) : nullptr,
899 /* TRANS: %s is another, separately translated sentence,
900 * ending in a full stop. */
901 PL_("%s Any such units will be disbanded in %d turn, "
902 "in accordance with peace treaty.",
903 "%s Any such units will be disbanded in %d turns, "
904 "in accordance with peace treaty.", turns_left),
905 astr_str(&unitstr), turns_left);
907 }
908}
909
910/**********************************************************************/
913static void remove_illegal_armistice_units(struct player *plr1,
914 struct player *plr2)
915{
916 /* Remove illegal units */
918 struct tile *ptile = unit_tile(punit);
919
920 if (tile_owner(ptile) == plr2
924 _("Your %s was disbanded in accordance with "
925 "your peace treaty with the %s."),
928 wipe_unit(punit, ULR_ARMISTICE, nullptr);
929 }
931
933 struct tile *ptile = unit_tile(punit);
934
935 if (tile_owner(ptile) == plr1
939 _("Your %s was disbanded in accordance with "
940 "your peace treaty with the %s."),
943 wipe_unit(punit, ULR_ARMISTICE, nullptr);
944 }
946}
947
948/**********************************************************************/
952static void update_diplomatics(void)
953{
956 struct player_diplstate *state = player_diplstate_get(plr1, plr2);
957
958 /* Players might just met when first of them was being handled
959 * (pact with third player changed and units got bounced next
960 * to second unit to form first contact)
961 * Do not decrease the counters for the other player yet in this turn */
962 if (state->first_contact_turn != game.info.turn) {
963 struct player_diplstate *state2 = player_diplstate_get(plr2, plr1);
964
965 state->has_reason_to_cancel = MAX(state->has_reason_to_cancel - 1, 0);
966 state->contact_turns_left = MAX(state->contact_turns_left - 1, 0);
967
968 if (state->type == DS_ARMISTICE
969 /* Don't count down if auto canceled this turn. Auto canceling
970 * happens in this loop. */
971 && state->auto_cancel_turn != game.info.turn) {
972 state->turns_left--;
973 if (state->turns_left <= 0) {
974 state->type = DS_PEACE;
975 state2->type = DS_PEACE;
976 state->turns_left = 0;
977 state2->turns_left = 0;
979 } else {
980 notify_illegal_armistice_units(plr1, plr2, state->turns_left);
981 }
982 }
983
984 if (state->type == DS_CEASEFIRE) {
985 state->turns_left--;
986 switch (state->turns_left) {
987 case 1:
988 notify_player(plr1, nullptr, E_DIPLOMACY, ftc_server,
989 _("Concerned citizens point out that the cease-fire "
990 "with %s will run out soon."), player_name(plr2));
991 /* Message to plr2 will be done when plr1 and plr2 will be swapped.
992 * Else, we will get a message duplication. Note the case is not
993 * the below, because the state will be changed for both players to
994 * war. */
995 break;
996 case 0:
997 notify_player(plr1, nullptr, E_DIPLOMACY, ftc_server,
998 _("The cease-fire with %s has run out. "
999 "You are now at war with the %s."),
1000 player_name(plr2),
1002 notify_player(plr2, nullptr, E_DIPLOMACY, ftc_server,
1003 _("The cease-fire with %s has run out. "
1004 "You are now at war with the %s."),
1005 player_name(plr1),
1007 state->type = DS_WAR;
1008 state2->type = DS_WAR;
1009 state->turns_left = 0;
1010 state2->turns_left = 0;
1011
1012 enter_war(plr1, plr2);
1013
1016 sync_cities();
1017
1018 /* Avoid love-love-hate triangles */
1020 if (plr3 != plr1 && plr3 != plr2
1021 && pplayers_allied(plr3, plr1)
1022 && pplayers_allied(plr3, plr2)) {
1023 struct player_diplstate *to1
1024 = player_diplstate_get(plr3, plr1);
1025 struct player_diplstate *from1
1026 = player_diplstate_get(plr1, plr3);
1027 struct player_diplstate *to2
1028 = player_diplstate_get(plr3, plr2);
1029 struct player_diplstate *from2
1030 = player_diplstate_get(plr2, plr3);
1031 const char *plr1name = player_name(plr1);
1032 const char *plr2name = player_name(plr2);
1033 bool cancel1;
1034 bool cancel2;
1035
1036 if (players_on_same_team(plr3, plr1)) {
1038
1039 cancel1 = FALSE;
1040 cancel2 = TRUE;
1041
1043 _("The cease-fire between %s and %s has run out. "
1044 "They are at war. You cancel your alliance "
1045 "with %s."),
1047 } else if (players_on_same_team(plr3, plr2)) {
1048
1049 cancel1 = TRUE;
1050 cancel2 = FALSE;
1051
1053 _("The cease-fire between %s and %s has run out. "
1054 "They are at war. You cancel your alliance "
1055 "with %s."),
1057 } else {
1058
1059 cancel1 = TRUE;
1060 cancel2 = TRUE;
1061
1063 _("The cease-fire between %s and %s has run out. "
1064 "They are at war. You cancel your alliance "
1065 "with both."),
1066 player_name(plr1),
1067 player_name(plr2));
1068 }
1069
1070 if (cancel1) {
1071 /* Cancel the alliance. */
1072 to1->has_reason_to_cancel = 1;
1074
1075 /* Avoid asymmetric turns_left for the armistice. */
1076 to1->auto_cancel_turn = game.info.turn;
1077 from1->auto_cancel_turn = game.info.turn;
1078
1079 /* Count down for this turn. */
1080 to1->turns_left--;
1081 from1->turns_left--;
1082 }
1083
1084 if (cancel2) {
1085 /* Cancel the alliance. */
1086 to2->has_reason_to_cancel = 1;
1088
1089 /* Avoid asymmetric turns_left for the armistice. */
1090 to2->auto_cancel_turn = game.info.turn;
1091 from2->auto_cancel_turn = game.info.turn;
1092
1093 /* Count down for this turn. */
1094 to2->turns_left--;
1095 from2->turns_left--;
1096 }
1097 }
1099 break;
1100 }
1101 }
1102 }
1105}
1106
1107/**********************************************************************/
1114static void kill_dying_players(void)
1115{
1116 bool voter_died = FALSE;
1117
1118 players_iterate_alive(pplayer) {
1119 /* cities or units remain? */
1120 if (0 == city_list_size(pplayer->cities)
1121 && 0 == unit_list_size(pplayer->units)) {
1123 }
1124 /* also UTYF_GAMELOSS in unittools server_remove_unit() */
1125 if (player_status_check(pplayer, PSTATUS_DYING)) {
1126 /* Can't get more dead than this. */
1127 voter_died = voter_died || pplayer->is_connected;
1128 kill_player(pplayer);
1129 }
1131
1132 if (voter_died) {
1133 send_updated_vote_totals(nullptr);
1134 }
1135}
1136
1137/**********************************************************************/
1140static void ai_start_phase(void)
1141{
1142 phase_players_iterate(pplayer) {
1143 if (is_ai(pplayer)) {
1144 CALL_PLR_AI_FUNC(first_activities, pplayer, pplayer);
1145 }
1148}
1149
1150/**********************************************************************/
1155static void begin_turn(bool is_new_turn)
1156{
1157 log_debug("Begin turn");
1158
1160
1161 /* Reset this each turn. */
1162 if (is_new_turn) {
1166 }
1167 }
1168
1169 /* NB: Phase logic must match is_player_phase(). */
1170 switch (game.info.phase_mode) {
1171 case PMT_CONCURRENT:
1173 break;
1176 break;
1179 break;
1180 default:
1181 log_error("Unrecognized phase mode %d in begin_turn().",
1184 break;
1185 }
1186 send_game_info(nullptr);
1187
1188 if (is_new_turn) {
1189 script_server_signal_emit("turn_begin",
1192 script_server_signal_emit("turn_started",
1193 game.info.turn > 0
1194 ? (lua_Integer)game.info.turn - 1
1197
1198 /* We build scores at the beginning of every turn. We have to
1199 * build them at the beginning so that the AI can use the data,
1200 * and we are sure to have it when we need it. */
1201 players_iterate(pplayer) {
1202 calc_civ_score(pplayer);
1205
1206 /* Retire useless barbarian units */
1207 players_iterate(pplayer) {
1208 unit_list_iterate_safe(pplayer->units, punit) {
1209 struct tile *ptile = punit->tile;
1210
1213 notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server,
1214 /* TRANS: %s is a unit type */
1215 _("%s retired!"), unit_tile_link(punit));
1216 wipe_unit(punit, ULR_RETIRED, nullptr);
1217 continue;
1218 }
1221 }
1222
1223 /* Find out if users attached to players have been attached to those players
1224 * for long enough. The first user to do so becomes "associated" to that
1225 * player for ranking purposes. */
1226 players_iterate(pplayer) {
1227 if (pplayer->unassigned_ranked
1228 && pplayer->user_turns++ > TURNS_NEEDED_TO_RANK
1229 && pplayer->is_alive) {
1230 sz_strlcpy(pplayer->ranked_username, pplayer->username);
1231 pplayer->unassigned_ranked = pplayer->unassigned_user;
1232 }
1234
1235 if (is_new_turn) {
1236 /* See if the value of fog of war has changed */
1238 if (game.info.fogofwar) {
1241 } else {
1244 }
1245 }
1246
1248 log_debug("Shuffleplayers");
1250 }
1251
1252 game.info.phase = 0;
1253 }
1254
1255 sanity_check();
1256}
1257
1258/**********************************************************************/
1262static void begin_phase(bool is_new_phase)
1263{
1264 log_debug("Begin phase");
1265
1267
1268 phase_players_iterate(pplayer) {
1270 /* Otherwise respect what was loaded from the savegame. */
1271 pplayer->phase_done = FALSE;
1272 }
1273 pplayer->ai_phase_done = FALSE;
1275 send_player_all_c(nullptr, nullptr);
1276
1278
1279 if (!is_new_phase || game.info.turn == FIRST_TURN) {
1280 /* Starting from a savegame or from the very beginning */
1284 }
1285
1286 /* Must be the first thing as it is needed for lots of functions below! */
1287 phase_players_iterate(pplayer) {
1288 /* Human players also need this for building advice */
1290 CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, is_new_phase);
1292
1293 if (is_new_phase) {
1294 /* Unit "end of turn" activities - of course these actually go at
1295 * the start of the turn! */
1296 whole_map_iterate(&(wld.map), ptile) {
1297 if (ptile->placing != nullptr) {
1298 struct player *owner = nullptr;
1299
1301 owner = tile_owner(ptile);
1302 } else {
1303 struct city *pcity = tile_worked(ptile);
1304
1305 if (pcity != nullptr) {
1307 }
1308 }
1309
1310 if (owner == nullptr) {
1311 /* Abandoned extra placing, clear it. */
1312 ptile->placing = nullptr;
1313 } else {
1315 fc_assert(ptile->infra_turns > 0);
1316
1317 ptile->infra_turns--;
1318 if (ptile->infra_turns <= 0) {
1319 create_extra(ptile, ptile->placing, owner);
1320 ptile->placing = nullptr;
1321
1322 /* Since extra has been added, tile is certainly
1323 * sent by update_tile_knowledge() including the
1324 * placing info, though it would not sent it if placing
1325 * were the only thing changed. */
1326 update_tile_knowledge(ptile);
1327 }
1328 }
1329 }
1330 }
1332
1333 phase_players_iterate(pplayer) {
1334 update_unit_activities(pplayer);
1335 flush_packets();
1337
1338 /* Execute orders after activities have been completed (roads built,
1339 * pillage done, etc.). */
1340 phase_players_iterate(pplayer) {
1341 int plrid = player_number(pplayer);
1342
1343 script_server_signal_emit("player_phase_begin", pplayer, is_new_phase);
1344 if (player_by_number(plrid) != pplayer) {
1345 /* Removed */
1346 continue;
1347 }
1348 flush_packets();
1350
1351 phase_players_iterate(pplayer) {
1352 city_tc_effect_refresh(pplayer);
1353 unit_tc_effect_refresh(pplayer);
1355
1356 phase_players_iterate(pplayer) {
1359
1360 flush_packets();
1361 }
1362
1363 phase_players_iterate(pplayer) {
1364 log_debug("beginning player turn for #%d (%s)",
1365 player_number(pplayer), player_name(pplayer));
1366 if (is_human(pplayer)) {
1367 building_advisor(pplayer);
1368 }
1370
1371 phase_players_iterate(pplayer) {
1372 send_player_cities(pplayer);
1374
1375 flush_packets(); /* To curb major city spam */
1377
1379 update_revolution(pplayer);
1380 update_capital(pplayer);
1381 access_areas_refresh(&(wld.map), pplayer);
1383
1384 if (is_new_phase) {
1385 /* Try to avoid hiding events under a diplomacy dialog */
1386 phase_players_iterate(pplayer) {
1387 if (is_ai(pplayer)) {
1388 CALL_PLR_AI_FUNC(diplomacy_actions, pplayer, pplayer);
1389 }
1391
1392 /* Spend random movement move points before any controlled actions */
1393 phase_players_iterate(pplayer) {
1394 random_movements(pplayer);
1396
1397 log_debug("Aistartturn");
1399
1400 flush_packets();
1401 phase_players_iterate(pplayer) {
1402 unit_list_iterate_safe(pplayer->units, punit) {
1405 }
1407 execute_unit_orders(pplayer);
1408 flush_packets();
1410 } else {
1411 phase_players_iterate(pplayer) {
1412 if (is_ai(pplayer)) {
1413 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
1414 }
1416 }
1417
1418 sanity_check();
1419
1424 game.server.phase_timer != nullptr
1425 ? nullptr : "phase");
1427 send_game_info(nullptr);
1428
1429 if (game.server.num_phases == 1) {
1430 /* All players in the same phase.
1431 * This means that AI has been handled above, and server
1432 * will be responsive again */
1434 }
1435}
1436
1437/**********************************************************************/
1441static void end_phase(void)
1442{
1443 log_debug("Endphase");
1444
1445 /*
1446 * This empties the client Messages window; put this before
1447 * everything else below, since otherwise any messages from the
1448 * following parts get wiped out before the user gets a chance to
1449 * see them. --dwp
1450 */
1451 phase_players_iterate(pplayer) {
1452 /* Unlike the start_phase packet we only send this one to the active
1453 * player. */
1454 lsend_packet_end_phase(pplayer->connections);
1456
1457 /* Enact any government and/or policy changes.
1458 * Do this first so that following end-phase activities take the
1459 * change into account. */
1460 phase_players_iterate(pplayer) {
1461 if (pplayer->revolution_finishes <= game.info.turn
1462 && pplayer->target_government != nullptr
1463 && pplayer->target_government != game.government_during_revolution
1464 && pplayer->target_government != pplayer->government) {
1465 government_change(pplayer, pplayer->target_government, TRUE);
1466 }
1467
1468 multipliers_iterate(pmul) {
1469 int idx = multiplier_index(pmul);
1470
1471 if (!multiplier_can_be_changed(pmul, pplayer)) {
1472 if (pplayer->multipliers[idx].value != pmul->def) {
1473 notify_player(pplayer, nullptr, E_MULTIPLIER, ftc_server,
1474 _("%s restored to the default value %d"),
1476 pmul->def);
1477 pplayer->multipliers[idx].value = pmul->def;
1478 pplayer->multipliers[idx].changed = game.info.turn;
1479 }
1480 } else {
1481 if (pplayer->multipliers[idx].value != pplayer->multipliers[idx].target) {
1482 notify_player(pplayer, nullptr, E_MULTIPLIER, ftc_server,
1483 _("%s now at value %d"),
1485 pplayer->multipliers[idx].target);
1486
1487 pplayer->multipliers[idx].value = pplayer->multipliers[idx].target;
1488 pplayer->multipliers[idx].changed = game.info.turn;
1489 }
1490 }
1493
1494 phase_players_iterate(pplayer) {
1495 struct research *presearch = research_get(pplayer);
1496
1497 if (A_UNSET == presearch->researching) {
1499 presearch->tech_goal);
1500
1501 if (A_UNSET != next_tech) {
1503 } else {
1505 }
1506 /* Add the researched bulbs to the pool; do *NOT* check for finished
1507 * research */
1508 update_bulbs(pplayer, 0, FALSE, FALSE);
1509 }
1511
1512 /* Freeze sending of cities. */
1514
1515 /* AI end of turn activities */
1516 players_iterate(pplayer) {
1517 unit_list_iterate(pplayer->units, punit) {
1518 CALL_PLR_AI_FUNC(unit_turn_end, pplayer, punit);
1521 phase_players_iterate(pplayer) {
1522 auto_workers_player(pplayer);
1523 if (is_ai(pplayer)) {
1524 CALL_PLR_AI_FUNC(last_activities, pplayer, pplayer);
1525 }
1527
1528 /* Refresh cities */
1529 phase_players_iterate(pplayer) {
1530 research_get(pplayer)->free_bulbs = 0;
1532
1534 int plrid = player_number(pplayer);
1535 int old_gold;
1536
1537 do_tech_parasite_effects(pplayer);
1538 script_server_signal_emit("player_alive_phase_end", pplayer);
1539 if (player_by_number(plrid) != pplayer) {
1540 /* Removed */
1541 continue;
1542 }
1543 if (!pplayer->is_alive) {
1544 /* Died */
1545 continue;
1546 }
1547 player_restore_units(pplayer);
1548
1549 /* If player finished spaceship parts last turn already, and didn't place them
1550 * during this entire turn, autoplace them. */
1551 if (adv_spaceship_autoplace(pplayer, &pplayer->spaceship)) {
1552 notify_player(pplayer, nullptr, E_SPACESHIP, ftc_server,
1553 _("Automatically placed spaceship parts that were still not placed."));
1554 }
1555
1556 old_gold = pplayer->economic.gold;
1557 pplayer->server.bulbs_last_turn = 0;
1558
1559 update_city_activities(pplayer);
1560
1562
1565
1566 flush_packets();
1568
1569 /* Some player/global effect may have changed cities' vision range */
1570 phase_players_iterate(pplayer) {
1573
1575
1576 /* Unfreeze sending of cities. */
1578
1579 phase_players_iterate(pplayer) {
1580 send_player_cities(pplayer);
1582 flush_packets(); /* To curb major city spam */
1583
1587
1588 phase_players_iterate(pplayer) {
1589 int plrid = player_number(pplayer);
1590
1591 script_server_signal_emit("player_phase_end", pplayer);
1592 if (player_by_number(plrid) != pplayer) {
1593 /* Removed */
1594 continue;
1595 }
1596 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1597 /* This has to be after all access to advisor data. */
1598 /* We used to run this for ai players only, but data phase
1599 is initialized for human players also. */
1600 adv_data_phase_done(pplayer);
1602}
1603
1604/**********************************************************************/
1607static void end_turn(void)
1608{
1609 log_debug("Endturn");
1610
1611 /* Hack: Because observer players never get an end-phase packet we send
1612 * one here. */
1614 if (pconn->playing == nullptr) {
1616 }
1618
1620
1622
1623 /* Update city's counter values */
1624 players_iterate(pplayer) {
1625 city_list_iterate(pplayer->cities, pcity) {
1627 if (pcount->type == CB_CITY_OWNED_TURNS) {
1628 pcity->counter_values[pcount->index]++;
1629 }
1634
1635#ifdef FREECIV_DEBUG
1636 /* Output some AI measurement information
1637 * log_debug() means that the values would never be used outside FREECIV_DEBUG
1638 * build even if we calculated them. */
1639 players_iterate(pplayer) {
1640 int food = 0, shields = 0, trade = 0, settlers = 0;
1641
1642 if (!is_ai(pplayer) || is_barbarian(pplayer)) {
1643 continue;
1644 }
1645
1646 unit_list_iterate(pplayer->units, punit) {
1648 settlers++;
1649 }
1651
1652 city_list_iterate(pplayer->cities, pcity) {
1653 shields += pcity->prod[O_SHIELD];
1654 food += pcity->prod[O_FOOD];
1655 trade += pcity->prod[O_TRADE];
1657
1658 log_debug("%s T%d cities:%d pop:%d food:%d prod:%d "
1659 "trade:%d settlers:%d units:%d", player_name(pplayer),
1660 game.info.turn, city_list_size(pplayer->cities),
1661 total_player_citizens(pplayer), food, shields, trade,
1662 settlers, unit_list_size(pplayer->units));
1663
1665#endif /* FREECIV_DEBUG */
1666
1667 log_debug("Season of native unrests");
1668 summon_barbarians(); /* Wild guess really, no idea where to put it, but
1669 * I want to give them chance to move their units */
1670
1671 if (game.server.migration) {
1672 log_debug("Season of migrations");
1673 if (check_city_migrations()) {
1674 /* Make sure everyone has updated information about BOTH ends of the
1675 * migration movements. */
1676 players_iterate(plr) {
1677 city_list_iterate(plr->cities, pcity) {
1678 send_city_info(nullptr, pcity);
1681 }
1682 }
1683
1685
1686 /* Check for new achievements during the turn.
1687 * This is not within phase, as multiple players may
1688 * achieve at the same turn and everyone deserves equal opportunity
1689 * to win. */
1691 struct player_list *achievers = player_list_new();
1692 struct player *first = achievement_plr(ach, achievers);
1694
1695 pack.id = achievement_index(ach);
1696 pack.gained = TRUE;
1697
1698 if (first != nullptr) {
1700 "%s", achievement_first_msg(ach));
1701
1702 pack.first = TRUE;
1703
1705
1706 script_server_signal_emit("achievement_gained", ach, first, TRUE);
1707
1708 }
1709
1710 pack.first = FALSE;
1711
1712 if (!ach->unique) {
1713 player_list_iterate(achievers, pplayer) {
1714 /* Message already sent to first one */
1715 if (pplayer != first) {
1716 notify_player(pplayer, nullptr, E_ACHIEVEMENT, ftc_server,
1717 "%s", achievement_later_msg(ach));
1718
1719 lsend_packet_achievement_info(pplayer->connections, &pack);
1720
1721 script_server_signal_emit("achievement_gained", ach, pplayer,
1722 FALSE);
1723 }
1725 }
1726
1727 player_list_destroy(achievers);
1729
1730 if (game.info.global_warming) {
1736 }
1737
1738 if (game.info.nuclear_winter) {
1744 }
1745
1746 /* Handle disappearing extras before appearing extras ->
1747 * Extra never appears only to disappear at the same turn,
1748 * but it can disappear and reappear. */
1750 whole_map_iterate(&(wld.map), ptile) {
1751 if (tile_has_extra(ptile, pextra)
1752 && fc_rand(10000) < pextra->disappearance_chance
1753 && can_extra_disappear(pextra, ptile)) {
1754 tile_extra_rm_apply(ptile, pextra);
1755
1756 update_tile_knowledge(ptile);
1757
1758 if (tile_owner(ptile) != nullptr) {
1759 /* TODO: Should notify players nearby even when borders disabled,
1760 * like in case of barbarian uprising */
1761 notify_player(tile_owner(ptile), ptile,
1763 /* TRANS: Small Fish disappears from (32, 72). */
1764 _("%s disappears from %s."),
1765 extra_name_translation(pextra),
1766 tile_link(ptile));
1767 }
1768
1769 /* Activities at the target tile and its neighbors may now
1770 * be illegal because of present reqs. */
1772 }
1775
1777 whole_map_iterate(&(wld.map), ptile) {
1778 if (!tile_has_extra(ptile, pextra)
1779 && fc_rand(10000) < pextra->appearance_chance
1780 && can_extra_appear(pextra, ptile)) {
1781
1782 tile_extra_apply(ptile, pextra);
1783
1784 update_tile_knowledge(ptile);
1785
1786 if (tile_owner(ptile) != nullptr) {
1787 /* TODO: Should notify players nearby even when borders disabled,
1788 * like in case of barbarian uprising */
1789 notify_player(tile_owner(ptile), ptile,
1791 /* TRANS: Small Fish appears to (32, 72). */
1792 _("%s appears to %s."),
1793 extra_name_translation(pextra),
1794 tile_link(ptile));
1795 }
1796
1797 /* Activities at the target tile and its neighbors may now
1798 * be illegal because of !present reqs. */
1800 }
1803
1805
1808 settings_turn();
1810 voting_turn();
1812
1813 log_debug("Gamenextyear");
1815 players_iterate_alive(pplayer) {
1816 pplayer->turns_alive++;
1818
1819 log_debug("Updatetimeout");
1821
1822 log_debug("Sendgameinfo");
1823 send_game_info(nullptr);
1824
1825 log_debug("Sendplayerinfo");
1826 send_player_all_c(nullptr, nullptr);
1827
1828 log_debug("Sendresearchinfo");
1830 send_research_info(presearch, nullptr);
1832
1833 log_debug("Sendyeartoclients");
1835}
1836
1837/**********************************************************************/
1840void save_game_auto(const char *save_reason, enum autosave_type type)
1841{
1842 char filename[512];
1843 const char *reason_filename = nullptr;
1844
1845 if (!(game.server.autosaves & (1 << type))) {
1846 return;
1847 }
1848
1849 switch (type) {
1850 case AS_TURN:
1851 reason_filename = nullptr;
1852 break;
1853 case AS_GAME_OVER:
1854 reason_filename = "final";
1855 break;
1856 case AS_QUITIDLE:
1857 reason_filename = "quitidle";
1858 break;
1859 case AS_INTERRUPT:
1860 reason_filename = "interrupted";
1861 break;
1862 case AS_TIMER:
1863 reason_filename = "timer";
1864 break;
1865 }
1866
1868
1869 if (type != AS_TIMER) {
1870 generate_save_name(game.server.save_name, filename, sizeof(filename),
1872 } else {
1873 fc_snprintf(filename, sizeof(filename), "%s-timer", game.server.save_name);
1874 }
1875 save_game(filename, save_reason, FALSE);
1876}
1877
1878/**********************************************************************/
1881void start_game(void)
1882{
1883 if (S_S_INITIAL != server_state()) {
1884 con_puts(C_SYNTAX, _("The game is already running."));
1885 return;
1886 }
1887
1888 /* Remove ALLOW_CTRL from whoever has it (gotten from 'first'). */
1890 if (pconn->access_level == ALLOW_CTRL) {
1891 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
1892 _("%s lost control cmdlevel on "
1893 "game start. Use voting from now on."),
1894 pconn->username);
1896 }
1899
1900 con_puts(C_OK, _("Starting game."));
1901
1902 /* Prevent problems with commands that only make sense in pregame. */
1904
1905 /* This value defines if the player data should be saved for a scenario.
1906 * It is only FALSE if the editor was used to set it to this value.
1907 * For such scenarios it has to be reset at game start so that player data
1908 * is saved. */
1910
1912 /* There's no stateful packet set to client until srv_ready(). */
1913}
1914
1915/**********************************************************************/
1919{
1920 if (server_state() == S_S_RUNNING) {
1921 /* Quitting mid-game. */
1922
1923 phase_players_iterate(pplayer) {
1924 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1925 /* This has to be after all access to advisor data. */
1926 /* We used to run this for ai players only, but data phase
1927 is initialized for human players also. */
1928 adv_data_phase_done(pplayer);
1930 }
1931
1933
1934 if (game.server.save_timer != nullptr) {
1936 game.server.save_timer = nullptr;
1937 }
1938 if (between_turns != nullptr) {
1940 between_turns = nullptr;
1941 }
1942 if (eot_timer != nullptr) {
1944 }
1946 mapimg_free();
1948 voting_free();
1950 ai_timer_free();
1951 if (game.server.phase_timer != nullptr) {
1953 game.server.phase_timer = nullptr;
1954 }
1955 if (game.server.save_timer != nullptr) {
1957 game.server.save_timer = nullptr;
1958 }
1959
1960#ifdef HAVE_FCDB
1961 if (srvarg.fcdb_enabled) {
1962 /* If freeciv database has been initialized */
1963 fcdb_free();
1964 }
1965#endif /* HAVE_FCDB */
1966
1967 modpacks_free();
1968 settings_free();
1970 edithand_free();
1971 voting_free();
1975 CALL_FUNC_EACH_AI(module_close);
1980 con_log_close();
1984
1986}
1987
1988/**********************************************************************/
1992{
1993 struct conn_list *dest = pconn->self;
1994
1995 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
1996 log_error("Got a report request %d before game start", type);
1997 return;
1998 }
1999
2000 if (pconn->playing == nullptr && !pconn->observer) {
2001 log_error("Got a report request %d from detached connection", type);
2002 return;
2003 }
2004
2005 switch (type) {
2008 return;
2011 return;
2012 case REPORT_TOP_CITIES:
2013 report_top_cities(dest);
2014 return;
2015 case REPORT_DEMOGRAPHIC:
2017 return;
2020 return;
2021 }
2022
2023 notify_conn(dest, nullptr, E_BAD_COMMAND, ftc_server,
2024 _("request for unknown report (type %d)"), type);
2025}
2026
2027/**********************************************************************/
2031{
2033}
2034
2035/**********************************************************************/
2039{
2041}
2042
2043/**********************************************************************/
2046static bool identity_number_is_used(int id)
2047{
2048 return BV_ISSET(identity_numbers_used, id);
2049}
2050
2051/**********************************************************************/
2055{
2056 server.identity_number = (server.identity_number + 1) % IDENTITY_NUMBER_SIZE;
2057 return server.identity_number;
2058}
2059
2060/**********************************************************************/
2065{
2066 int retries = 0;
2067
2069 /* Try again */
2070 if (++retries >= IDENTITY_NUMBER_SIZE) {
2071 /* Always fails. */
2073 "Exhausted city and unit numbers!");
2074 }
2075 }
2076 identity_number_reserve(server.identity_number);
2077 return server.identity_number;
2078}
2079
2080/**********************************************************************/
2087{
2089}
2090
2091/**********************************************************************/
2095bool server_packet_input(struct connection *pconn, void *packet, int type)
2096{
2097 struct player *pplayer;
2098
2099 /* A nullptr packet can be returned from receive_packet_goto_route() */
2100 if (!packet) {
2101 return TRUE;
2102 }
2103
2104 /*
2105 * Old pre-delta clients (before 2003-11-28) send a
2106 * PACKET_LOGIN_REQUEST (type 0) to the server. We catch this and
2107 * reply with an old reject packet. Since there is no struct for
2108 * this old packet anymore we build it by hand.
2109 */
2110 if (type == 0) {
2111 unsigned char buffer[4096];
2112 struct raw_data_out dout;
2113
2114 log_normal(_("Warning: rejecting old client %s"),
2116
2117 dio_output_init(&dout, buffer, sizeof(buffer));
2119
2120 /* 1 == PACKET_LOGIN_REPLY in the old client */
2122
2125 _("Your client is too old. To use this server, "
2126 "please upgrade your client to a "
2127 "Freeciv 2.2 or later."));
2129
2130 {
2131 size_t size = dio_output_used(&dout);
2134
2135 /*
2136 * Use send_connection_data instead of send_packet_data to avoid
2137 * compression.
2138 */
2140 }
2141
2142 return FALSE;
2143 }
2144
2147 (struct packet_server_join_req *) packet);
2148 }
2149
2150 /* May be received on a non-established connection. */
2152 return auth_handle_reply(pconn,
2153 ((struct packet_authentication_reply *)
2154 packet)->password);
2155 }
2156
2157 if (type == PACKET_CONN_PONG) {
2159 return TRUE;
2160 }
2161
2162 if (!pconn->established) {
2163 log_error("Received game packet %s(%d) from unaccepted connection %s.",
2165 return TRUE;
2166 }
2167
2168 /* Valid packets from established connections but non-players */
2179
2180 /* Except for PACKET_EDIT_MODE (used to set edit mode), check
2181 * that the client is allowed to send the given edit packet. */
2183 && !can_conn_edit(pconn)) {
2184 notify_conn(pconn->self, nullptr, E_BAD_COMMAND, ftc_editor,
2185 _("You are not allowed to edit."));
2186 return TRUE;
2187 }
2188
2189 if (!server_handle_packet(type, packet, nullptr, pconn)) {
2190 log_error("Received unknown packet %d from %s.",
2192 }
2193 return TRUE;
2194 }
2195
2196 pplayer = pconn->playing;
2197
2198 if (pplayer == nullptr || pconn->observer) {
2199 if (type == PACKET_PLAYER_READY && pconn->observer) {
2201
2202 return TRUE;
2203 }
2204 /* Don't support these yet */
2205 log_error("Received packet %s(%d) from non-player connection %s.",
2207 return TRUE;
2208 }
2209
2210 if (S_S_RUNNING != server_state()
2215 if (S_S_OVER == server_state()) {
2216 /* This can happen by accident, so we don't want to print
2217 * out lots of error messages. Ie, we use log_debug(). */
2218 log_debug("Got a packet of type %s(%d) in %s.",
2220 } else {
2221 log_error("Got a packet of type %s(%d) outside %s.",
2223 }
2224 return TRUE;
2225 }
2226
2227 pplayer->nturns_idle = 0;
2228
2229 if (!pplayer->is_alive && type != PACKET_REPORT_REQ) {
2230 log_error("Got a packet of type %s(%d) from a dead player.",
2232 return TRUE;
2233 }
2234
2235 /* Make sure to set this back to nullptr before leaving this function: */
2236 pplayer->current_conn = pconn;
2237
2238 if (!server_handle_packet(type, packet, pplayer, pconn)) {
2239 log_error("Received unknown packet %d from %s.",
2241 }
2242
2243 if (S_S_RUNNING == server_state()
2244 && type != PACKET_PLAYER_READY) {
2245 /* handle_player_ready() calls start_game(), but the game isn't started
2246 * until the main loop is re-entered, so kill_dying_players() would think
2247 * all players are dead. This should be solved by adding a new
2248 * game state (now S_S_GENERATING_WAITING). */
2250 }
2251
2252 pplayer->current_conn = nullptr;
2253
2254 return TRUE;
2255}
2256
2257/**********************************************************************/
2262{
2263 bool connected = FALSE;
2264
2265 if (S_S_RUNNING != server_state()) {
2266 /* Not in a running state, no turn done. */
2267 return;
2268 }
2269
2270 /* Fixedlength is only applicable if we have a timeout set */
2272 return;
2273 }
2274
2275 /* If there are no connected players, don't automatically advance. This is
2276 * a hack to prevent all-AI games from running rampant. Note that if
2277 * timeout is set to -1 this function call is skipped entirely and the
2278 * server will run rampant. */
2279 players_iterate_alive(pplayer) {
2280 if (pplayer->is_connected && (is_human(pplayer) || pplayer->phase_done)) {
2281 connected = TRUE;
2282 break;
2283 }
2285
2286 if (!connected) {
2287 return;
2288 }
2289
2290 phase_players_iterate(pplayer) {
2291 if (!pplayer->phase_done && pplayer->is_alive) {
2292 if (pplayer->is_connected) {
2293 /* In all cases, we wait for any connected players. */
2294 return;
2295 }
2296 if (game.server.turnblock && is_human(pplayer)) {
2297 /* If turnblock is enabled check for human players, connected
2298 * or not. */
2299 return;
2300 }
2301 if (is_ai(pplayer) && !pplayer->ai_phase_done) {
2302 /* AI player has not finished */
2303 return;
2304 }
2305 }
2307
2309}
2310
2311/**********************************************************************/
2317{
2318 if (!game_was_started() && 0 < map_startpos_count()) {
2319 /* Restrict nations to those for which start positions are defined. */
2320 nations_iterate(pnation) {
2321 fc_assert_action_msg(pnation->player == nullptr,
2322 if (pnation->player->nation == pnation) {
2323 /* At least assignment is consistent. Leave nation assigned,
2324 * and make sure that nation is also marked pickable. */
2325 pnation->server.no_startpos = FALSE;
2326 continue;
2327 } else if (pnation->player->nation != nullptr) {
2328 /* Not consistent. Just initialize the pointer and hope for the
2329 * best. */
2330 pnation->player->nation->player = nullptr;
2331 pnation->player = nullptr;
2332 } else {
2333 /* Not consistent. Just initialize the pointer and hope for the
2334 * best. */
2335 pnation->player = nullptr;
2336 }, "Player assigned to nation before %s()!", __FUNCTION__);
2337
2338 if (nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
2339 /* Always allow land and sea barbarians regardless of start
2340 * positions. */
2341 pnation->server.no_startpos = FALSE;
2342 } else {
2343 /* Restrict the set of nations offered to players, based on
2344 * start positions.
2345 * If there are no start positions for a nation, remove it from the
2346 * available set. */
2347 pnation->server.no_startpos = TRUE;
2349 if (startpos_nation_allowed(psp, pnation)) {
2350 /* There is at least one start position that allows this nation,
2351 * so allow it to be picked.
2352 * (Depending on what nations players actually pick, it's not
2353 * guaranteed that the server can always find a match between
2354 * nations in this subset and start positions, in which case the
2355 * server may create mismatches.) */
2356 pnation->server.no_startpos = FALSE;
2357 break;
2358 }
2360 }
2362 } else {
2363 /* Not restricting nations by start positions. */
2364 nations_iterate(pnation) {
2365 pnation->server.no_startpos = FALSE;
2367 }
2368}
2369
2370/**********************************************************************/
2375void handle_nation_select_req(struct connection *pc, int player_no,
2376 Nation_type_id nation_no, bool is_male,
2377 const char *name, int style)
2378{
2379 struct nation_type *new_nation;
2380 struct player *pplayer = player_by_number(player_no);
2381
2382 if (!pplayer || !can_conn_edit_players_nation(pc, pplayer)) {
2383 return;
2384 }
2385
2386 new_nation = nation_by_number(nation_no);
2387
2389 char message[1024];
2390
2391 /* Check sanity of the packet sent by client */
2393 return;
2394 }
2395
2397 notify_player(pplayer, nullptr, E_NATION_SELECTED, ftc_server,
2398 _("%s nation is not available for user selection."),
2400 return;
2401 }
2402 if (new_nation->player && new_nation->player != pplayer) {
2403 notify_player(pplayer, nullptr, E_NATION_SELECTED, ftc_server,
2404 _("%s nation is already in use."),
2406 return;
2407 }
2408
2410 message, sizeof(message))) {
2411 notify_player(pplayer, nullptr, E_NATION_SELECTED,
2412 ftc_server, "%s", message);
2413 return;
2414 }
2415
2416 /* Should be caught by is_nation_pickable() */
2418
2419 notify_conn(nullptr, nullptr, E_NATION_SELECTED, ftc_server,
2420 _("%s is the %s ruler %s."),
2421 pplayer->username,
2423 player_name(pplayer));
2424
2425 pplayer->is_male = is_male;
2426 pplayer->style = style_by_number(style);
2427 } else if (name[0] == '\0') {
2428 char message[1024];
2429
2431 message, sizeof(message));
2432 }
2433
2434 (void) player_set_nation(pplayer, new_nation);
2436}
2437
2438/**********************************************************************/
2442{
2443 if (pconn->access_level == ALLOW_HACK) {
2444 players_iterate(plr) {
2445 if (is_human(plr)) {
2446 return;
2447 }
2449
2450 start_command(nullptr, FALSE, TRUE);
2451 }
2452}
2453
2454/**********************************************************************/
2458 int player_no,
2459 bool is_ready)
2460{
2461 struct player *pplayer = player_by_number(player_no);
2462
2463 if (pplayer == nullptr || S_S_INITIAL != server_state()) {
2464 return;
2465 }
2466
2467 if (pplayer != requestor) {
2468 /* Currently you can only change your own readiness. */
2469 return;
2470 }
2471
2472 pplayer->is_ready = is_ready;
2473 send_player_info_c(pplayer, nullptr);
2474
2475 /* Note this is called even if the player has pressed /start once
2476 * before. For instance, when a player leaves everyone remaining
2477 * might have pressed /start already but the start won't happen
2478 * until someone presses it again. Also you can press start more
2479 * than once to remind other people to start (which is a good thing
2480 * until somebody does it too much and it gets labeled as spam). */
2481 if (is_ready) {
2482 int num_ready = 0, num_unready = 0;
2483
2484 players_iterate_alive(other_player) {
2485 if (other_player->is_connected) {
2486 if (other_player->is_ready) {
2487 num_ready++;
2488 } else {
2489 num_unready++;
2490 }
2491 }
2493
2494 if (num_unready > 0) {
2495 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
2496 _("Waiting to start game: %d out of %d alive players "
2497 "are ready to start."),
2499 } else {
2500 /* Check minplayers etc. and then start */
2501 start_command(nullptr, FALSE, TRUE);
2502 }
2503 }
2504}
2505
2506/**********************************************************************/
2511const char *aifill(int amount)
2512{
2513 char *limitreason = nullptr;
2514 int limit;
2515
2516 if (game_was_started()) {
2517 return nullptr;
2518 }
2519
2521 if (limit < amount) {
2522 limitreason = _("requested more than 'maxplayers' setting");
2523 }
2524
2525 /* Limit to nations provided by ruleset */
2526 if (limit > server.playable_nations) {
2527 limit = server.playable_nations;
2528 if (nation_set_count() > 1) {
2529 limitreason = _("not enough playable nations in this nation set "
2530 "(see 'nationset' setting)");
2531 } else {
2532 limitreason = _("not enough playable nations");
2533 }
2534 }
2535
2536 if (limit < player_count()) {
2537 int removal = player_slot_count() - 1;
2538
2539 while (limit < player_count() && 0 <= removal) {
2540 struct player *pplayer = player_by_number(removal);
2541
2542 removal--;
2543 if (!pplayer) {
2544 continue;
2545 }
2546
2547 if (!pplayer->is_connected && !pplayer->was_created) {
2548 server_remove_player(pplayer);
2549 }
2550 }
2551
2552 /* 'limit' can be different from 'player_count()' at this point if
2553 * there are more human or created players than the 'limit'. */
2554 return limitreason;
2555 }
2556
2557 while (limit > player_count()) {
2559 int filled = 1;
2560 struct player *pplayer;
2561
2563 nullptr, FALSE);
2564 /* !game_was_started() so no need to assign_player_colors() */
2565 if (!pplayer) {
2566 break;
2567 }
2568 server_player_init(pplayer, FALSE, TRUE);
2569
2570 player_set_nation(pplayer, nullptr);
2571
2572 do {
2573 fc_snprintf(leader_name, sizeof(leader_name), "AI*%d", filled++);
2574 } while (player_by_name(leader_name));
2575
2577 pplayer->random_name = TRUE;
2578 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
2579 pplayer->unassigned_user = TRUE;
2580
2582 set_as_ai(pplayer);
2584
2585 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
2586
2587 log_normal(_("%s has been added as %s level AI-controlled player (%s)."),
2588 player_name(pplayer),
2590 ai_name(pplayer->ai));
2591 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
2592 _("%s has been added as %s level AI-controlled player (%s)."),
2593 player_name(pplayer),
2595 ai_name(pplayer->ai));
2596
2597 send_player_info_c(pplayer, nullptr);
2598 }
2599
2600 return limitreason;
2601}
2602
2603/**********************************************************************/
2606#define SPECHASH_TAG startpos
2607#define SPECHASH_IKEY_TYPE struct startpos *
2608#define SPECHASH_INT_DATA_TYPE
2609#include "spechash.h"
2610#define startpos_hash_iterate(hash, psp, c) \
2611 TYPED_HASH_ITERATE(struct startpos *, intptr_t, hash, psp, c)
2612#define startpos_hash_iterate_end HASH_ITERATE_END
2613
2614/**********************************************************************/
2617static void player_set_nation_full(struct player *pplayer,
2618 struct nation_type *pnation)
2619{
2620 /* Don't change the name of a created player. */
2621 player_nation_defaults(pplayer, pnation, pplayer->random_name);
2622}
2623
2624/**********************************************************************/
2627void player_nation_defaults(struct player *pplayer, struct nation_type *pnation,
2628 bool set_name)
2629{
2630 struct nation_leader *pleader;
2631
2632 fc_assert(NO_NATION_SELECTED != pnation);
2633 player_set_nation(pplayer, pnation);
2634 fc_assert(pnation == pplayer->nation);
2635
2636 pplayer->style = style_of_nation(pnation);
2637
2638 if (set_name) {
2640 }
2641
2642 if ((pleader = nation_leader_by_name(pnation, player_name(pplayer)))) {
2644 } else {
2645 pplayer->is_male = (fc_rand(2) == 1);
2646 }
2647
2648 ai_traits_init(pplayer);
2649}
2650
2651/**********************************************************************/
2678static void generate_players(void)
2679{
2680 int nations_to_assign = 0;
2681
2682 /* Announce players who already have nations, and select nations based
2683 * on player names. */
2684 players_iterate(pplayer) {
2685 if (pplayer->nation != NO_NATION_SELECTED) {
2686 /* Traits are initialized here, and not already when nation gets
2687 * picked, as player may change their mind after picking one nation,
2688 * and picks another and we want to init traits only once, for the
2689 * correct nation. */
2690 ai_traits_init(pplayer);
2691 announce_player(pplayer);
2692 continue;
2693 }
2694
2695 /* See if the player name matches a known leader name.
2696 * If more than one nation has this leader name, pick one at random.
2697 * No attempt is made to avoid clashes to maximise the number of
2698 * nations that can be assigned in this way. */
2699 {
2701 int n = 0;
2702
2703 allowed_nations_iterate(pnation) {
2704 if (is_nation_playable(pnation)
2705 && client_can_pick_nation(pnation)
2706 && pnation->player == nullptr
2707 && (nation_leader_by_name(pnation, player_name(pplayer)))) {
2709 n++;
2710 }
2712 if (n > 0) {
2713 player_set_nation_full(pplayer,
2715 }
2717 }
2718 if (pplayer->nation != NO_NATION_SELECTED) {
2719 announce_player(pplayer);
2720 } else {
2722 }
2724
2725 if (0 < nations_to_assign && 0 < map_startpos_count()) {
2726 /* We're running a scenario game with specified start positions.
2727 * Prefer nations assigned to those positions (but we can fall back
2728 * to others, even if game.scenario.startpos_nations is set). */
2730 struct nation_type *picked;
2731 int c, max = -1;
2732 int i, min;
2733
2734 /* Initialization. */
2736 if (startpos_allows_all(psp)) {
2737 continue;
2738 }
2739
2740 /* Count the already-assigned players whose nations can use this
2741 * start position. */
2742 c = 0;
2743 players_iterate(pplayer) {
2744 if (NO_NATION_SELECTED != pplayer->nation
2745 && startpos_nation_allowed(psp, pplayer->nation)) {
2746 c++;
2747 }
2749
2750 startpos_hash_insert(hash, psp, c);
2751 if (c > max) {
2752 max = c;
2753 }
2755
2756 /* Try to assign nations with start positions to the unassigned
2757 * players, preferring nations whose start positions aren't usable
2758 * by already-assigned players. */
2759 players_iterate(pplayer) {
2760 if (NO_NATION_SELECTED != pplayer->nation) {
2761 continue;
2762 }
2763
2765 min = max;
2766 i = 0;
2767
2768 allowed_nations_iterate(pnation) {
2769 if (!is_nation_playable(pnation)
2770 || pnation->player != nullptr) {
2771 /* Not available. */
2772 continue;
2773 }
2774
2775 startpos_hash_iterate(hash, psp, val) {
2776 if (!startpos_nation_allowed(psp, pnation)) {
2777 continue;
2778 }
2779
2780 if (val < min) {
2781 /* Pick this nation, as fewer nations already in the game
2782 * can use this start position. */
2783 picked = pnation;
2784 min = val;
2785 i = 1;
2786 } else if (val == min && 0 == fc_rand(++i)) {
2787 /* More than one nation is equally desirable. Pick one at
2788 * random. */
2789 picked = pnation;
2790 }
2793
2794 if (NO_NATION_SELECTED != picked) {
2797 announce_player(pplayer);
2798 /* Update the counts for the newly assigned nation. */
2799 startpos_hash_iterate(hash, psp, val) {
2800 if (startpos_nation_allowed(psp, picked)) {
2801 startpos_hash_replace(hash, psp, val + 1);
2802 }
2804 } else {
2805 /* No need to continue; we failed to pick a nation this time,
2806 * so we're not going to succeed next time. Fall back to
2807 * standard nation selection. */
2808 break;
2809 }
2811
2813 }
2814
2815 if (0 < nations_to_assign) {
2816 /* Pick random races. Try to select from the set permitted by
2817 * starting positions -- if we fell through here after failing to
2818 * match start positions, this will at least keep the picked
2819 * nations vaguely in keeping with the scenario.
2820 * However, even this may fail (if there are start positions that
2821 * can only be filled by nations outside the current nationset),
2822 * in which case we fall back to completely random nations. */
2823 bool needs_startpos = TRUE;
2824 players_iterate(pplayer) {
2825 if (NO_NATION_SELECTED == pplayer->nation) {
2826 struct nation_type *pnation = pick_a_nation(nullptr, FALSE, needs_startpos,
2828 if (pnation == NO_NATION_SELECTED && needs_startpos) {
2830 pnation = pick_a_nation(nullptr, FALSE, needs_startpos, NOT_A_BARBARIAN);
2831 }
2832 fc_assert(pnation != NO_NATION_SELECTED);
2833 player_set_nation_full(pplayer, pnation);
2835 announce_player(pplayer);
2836 }
2838 }
2839
2841
2843}
2844
2845/**********************************************************************/
2850const char *pick_random_player_name(const struct nation_type *pnation)
2851{
2852 const char *choice = nullptr;
2854 int n;
2855
2857 const char *name = nation_leader_name(pleader);
2858
2859 if (player_by_name(name) == nullptr
2860 && player_by_user(name) == nullptr) {
2862 }
2864
2866 if (n > 0) {
2868 fc_rand(n)));
2869 }
2871
2872 return choice;
2873}
2874
2875/**********************************************************************/
2878static void announce_player(struct player *pplayer)
2879{
2880 log_normal(_("%s rules the %s."),
2881 player_name(pplayer), nation_plural_for_player(pplayer));
2882
2884 ftc_server, _("%s rules the %s."),
2885 player_name(pplayer), nation_plural_for_player(pplayer));
2886
2887 /* Let the clients knows the nation of the players as soon as possible.
2888 * When a player's nation is server assigned its client will think of it
2889 * as nullptr until informed about the assigned nation. */
2890 send_player_info_c(pplayer, nullptr);
2891}
2892
2893/**********************************************************************/
2896static void srv_running(void)
2897{
2899 bool skip_mapimg = !game.info.is_new_game; /* Do not overwrite start-of-turn image */
2901 int save_counter = game.info.is_new_game ? 1 : 0;
2902
2903 /* We may as well reset is_new_game now. */
2905
2906 log_verbose("srv_running() mostly redundant send_server_settings()");
2907 send_server_settings(nullptr);
2908
2910
2911 if (game.server.autosaves & (1 << AS_TIMER)) {
2914 game.server.save_timer != nullptr
2915 ? nullptr : "save interval");
2917 }
2918
2919 /*
2920 * This will freeze the reports and agents at the client.
2921 *
2922 * Do this before the body so that the PACKET_THAW_CLIENT packet is
2923 * balanced.
2924 */
2926
2928 while (S_S_RUNNING == server_state()) {
2929 /* The beginning of a turn.
2930 *
2931 * We have to initialize data as well as do some actions. However when
2932 * loading a game we don't want to do these actions (like AI unit
2933 * movement and AI diplomacy). */
2935
2936 if (game.server.num_phases != 1) {
2937 /* We allow everyone to begin adjusting cities and such
2938 * from the beginning of the turn.
2939 * With simultaneous movement we send begin_turn packet in
2940 * begin_phase() only after AI players have finished their actions. */
2942 }
2943
2945 log_debug("Starting phase %d/%d.", game.info.phase,
2949 /* When loading a savegame, we need to send loaded events, after
2950 * the clients switched to the game page (after the first
2951 * packet_start_phase is received). */
2956 }
2957
2958 is_new_turn = TRUE;
2959
2961
2962 /*
2963 * This will thaw the reports and agents at the client.
2964 */
2966
2967#ifdef LOG_TIMERS
2968 /* Before sniff (human player activites), report time to now: */
2969 log_verbose("End/start-turn server/ai activities: %g seconds",
2971#endif
2972
2973 /* Do auto-saves just before starting server_sniff_all_input(), so that
2974 * autosave happens effectively "at the same time" as manual
2975 * saves, from the point of view of restarting and AI players.
2976 * Post-increment so we don't count the first loop. */
2977 if (game.info.phase == 0) {
2978 /* Create autosaves if requested. */
2980 && game.server.save_nturns > 0) {
2981 save_counter = 0;
2982 save_game_auto("Autosave", AS_TURN);
2983 }
2984 save_counter++;
2985
2986 if (!skip_mapimg) {
2988 } else {
2990 }
2991 }
2992
2993 log_debug("sniffingpackets");
2994 check_for_full_turn_done(); /* HACK: don't wait during AI phases */
2995
2996 if (between_turns != nullptr) {
2998 log_debug("Unresponsive between turns %g seconds", game.server.turn_change_time);
2999 }
3000
3002 /* Nothing */
3003 }
3004
3006 between_turns != nullptr ? nullptr : "between turns");
3008
3009 /* After sniff, re-zero the timer: (read-out above on next loop) */
3012
3014
3015 sanity_check();
3016
3017 /*
3018 * This will freeze the reports and agents at the client.
3019 */
3021
3022 end_phase();
3023
3025
3026 if (S_S_OVER == server_state()) {
3027 break;
3028 }
3030 }
3031
3032 /* Make sure is_new_turn is reset before next turn even if
3033 * we did zero rounds in the loop (i.e. if current phase from
3034 * the savegame was >= num phases). Without this begin_turn()
3035 * would not reset phase, so there would be infinite loop
3036 * where phase is too high for is_new_turn to get set. */
3037 is_new_turn = TRUE;
3038
3039 end_turn();
3040 log_debug("Sendinfotometaserver");
3042
3045 if (game.info.turn > game.server.end_turn) {
3046 /* Endturn was reached - rank users based on team scores */
3048 } else {
3049 /* Game ended for victory conditions - rank users based on survival */
3051 }
3052 } else if (S_S_OVER == server_state()) {
3053 /* Game terminated by /endgame command - calculate team scores */
3055 }
3056 }
3057
3058 /* This will thaw the reports and agents at the client. */
3060
3061 if (game.server.save_timer != nullptr) {
3063 game.server.save_timer = nullptr;
3064 }
3065 if (between_turns != nullptr) {
3067 between_turns = nullptr;
3068 }
3070}
3071
3072/**********************************************************************/
3075static void srv_prepare(void)
3076{
3077#ifdef HAVE_FCDB
3078 if (!srvarg.auth_enabled) {
3079 con_write(C_COMMENT, _("This freeciv-server program has player "
3080 "authentication support, but it's currently not "
3081 "in use."));
3082 }
3083#endif /* HAVE_FCDB */
3084
3085 /* Make sure it's initialized */
3086 if (!has_been_srv_init) {
3087 srv_init();
3088 }
3089
3091
3092 /* Must be before con_log_init() */
3096 /* Logging available after this point */
3097
3099
3100#if IS_BETA_VERSION || IS_DEVEL_VERSION
3101 con_puts(C_COMMENT, "");
3103 con_puts(C_COMMENT, "");
3104#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
3105
3106 con_flush();
3107
3110 edithand_init();
3111 voting_init();
3112 voting_init();
3113 ai_timer_init();
3114
3115 modpacks_init();
3121
3122#ifdef HAVE_FCDB
3123 if (srvarg.fcdb_enabled) {
3124 bool success;
3125
3127 free(srvarg.fcdb_conf); /* Never needed again */
3128 srvarg.fcdb_conf = nullptr;
3129 if (!success) {
3131 }
3132 }
3133#endif /* HAVE_FCDB */
3134
3135 if (srvarg.ruleset != nullptr) {
3136 const char *testfilename;
3137
3139 if (testfilename == nullptr) {
3140 log_fatal(_("Ruleset directory \"%s\" not found"), srvarg.ruleset);
3142 }
3144 }
3145
3146 /* Try to load a saved game */
3147 if ('\0' == srvarg.load_filename[0]
3148 || !load_command(nullptr, srvarg.load_filename, FALSE, TRUE)) {
3149 /* Savegame not loaded */
3151
3152 /* Rulesets are loaded on game initialization, but may be changed later
3153 * if /load or /rulesetdir is done. */
3154 load_rulesets(nullptr, nullptr, FALSE, nullptr, TRUE, FALSE, TRUE);
3155 }
3156
3158
3159 if (!(srvarg.metaserver_no_send)) {
3160 log_normal(_("Sending info to metaserver <%s>."), meta_addr_port());
3161 /* Open socket for meta server */
3164 con_write(C_FAIL, _("Not starting without explicitly requested metaserver connection."));
3166 }
3167 }
3168
3169 eot_timer = timer_new(TIMER_CPU, TIMER_ACTIVE, "end-of-turn");
3170}
3171
3172/**********************************************************************/
3175static void srv_scores(void)
3176{
3177 /* Recalculate the scores in case of a spaceship victory */
3178 players_iterate(pplayer) {
3179 calc_civ_score(pplayer);
3181
3183
3184 report_final_scores(nullptr);
3186 notify_player(nullptr, nullptr, E_GAME_END, ftc_server,
3187 _("The game is over..."));
3189
3190 if (game.server.save_nturns > 0
3192 || !srvarg.quitidle)) {
3193 /* Save game on game_over, but not when the gameover was caused by
3194 * the -q parameter. Be sure that it's the -q, and not an autogame
3195 * with no human players. */
3196 save_game_auto("Game over", AS_GAME_OVER);
3197 }
3198
3200}
3201
3202/**********************************************************************/
3208{
3209 players_iterate(pplayer) {
3210 struct nation_type *pnation = nation_of_player(pplayer);
3211
3212 pplayer->government = init_government_of_nation(pnation);
3213
3215 /* If we do not do this, an assertion will trigger. This enables us to
3216 * select a valid government on game start. */
3217 pplayer->revolution_finishes = 0;
3218 }
3219
3220 multipliers_iterate(pmul) {
3221 int midx = multiplier_index(pmul);
3222
3223 pplayer->multipliers[midx].value
3224 = pplayer->multipliers[midx].target
3225 = pmul->def;
3228}
3229
3230/**********************************************************************/
3233static void srv_ready(void)
3234{
3236
3238 players_iterate(pplayer) {
3239 if (!pplayer->is_connected && is_human(pplayer)) {
3240 toggle_ai_player_direct(nullptr, pplayer);
3241 }
3243 }
3244
3246
3247#ifdef TEST_RANDOM /* Not defined anywhere, set it if you want it */
3248 test_random1(200);
3249 test_random1(2000);
3250 test_random1(20000);
3251 test_random1(200000);
3252#endif
3253
3254 if (game.info.is_new_game) {
3255 /* Must come before assign_player_colors() */
3258
3259 game.info.turn++; /* Pregame T0 -> game T1 */
3260 fc_assert(game.info.turn == 1);
3262 }
3263
3264 /* If we have a tile map, and MAPGEN_SCENARIO == map.server.generator,
3265 * call map_fractal_generate() anyway to make the specials, huts and
3266 * continent numbers. */
3267 if (map_is_empty()
3269 && game.info.is_new_game)) {
3270 struct {
3271 const char *name;
3272 char value[MAX_LEN_NAME * 2];
3273 char pretty[MAX_LEN_NAME * 2];
3274 } mapgen_settings[] = {
3275 { "generator", },
3276 { "startpos", },
3277 { "teamplacement", }
3278 };
3279 int i;
3280 /* If a specific seed has been requested, there's no point retrying,
3281 * as the map will be the same every time. */
3282 bool retry_ok = (wld.map.server.seed_setting == 0
3284 int max = retry_ok ? 3 : 1;
3285 bool created = FALSE;
3286 struct unit_type *utype = nullptr;
3288
3289 if (sucount > 0) {
3290 for (i = 0; utype == nullptr && i < sucount; i++) {
3291 utype = crole_to_unit_type(game.server.start_units[i], nullptr);
3292 }
3293 } else {
3294 /* First unit the initial city might build. */
3295 utype = get_role_unit(L_FIRSTBUILD, 0);
3296 }
3297 fc_assert(utype != nullptr);
3298
3299 /* Register map generator setting main values. */
3300 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3302
3303 fc_assert_action(pset != nullptr, continue);
3306 sizeof(mapgen_settings[i].value));
3308 mapgen_settings[i].pretty,
3309 sizeof(mapgen_settings[i].pretty));
3310 }
3311
3312 for (i = 0; !created && i < max ; i++) {
3314 if (!created && max > 1) {
3315 int set;
3316
3317 /* If we're retrying, seed_setting == 0, which will yield a new map
3318 * next time */
3320 if (i == 0) {
3321 /* We will retry only if max attempts allow it */
3322 log_normal(_("Failed to create suitable map, retrying with another mapseed."));
3323 } else {
3324 /* +1 - start human readable count from 1 and not from 0
3325 * +1 - refers to next round, not to one we just did
3326 * ==
3327 * +2 */
3328 log_normal(_("Attempt %d/%d"), i + 2, max);
3329 }
3331
3332 /* Remove old information already present in tiles */
3333 main_map_free();
3335 /* Restore the settings. */
3336 for (set = 0; set < ARRAY_SIZE(mapgen_settings); set++) {
3338#ifdef FREECIV_NDEBUG
3339 setting_enum_set(pset, mapgen_settings[set].value, nullptr, nullptr, 0);
3340#else /* FREECIV_NDEBUG */
3341 char error[128];
3342 bool success;
3343
3344 fc_assert_action(pset != nullptr, continue);
3346 nullptr, error, sizeof(error));
3348 "Failed to restore '%s': %s",
3349 mapgen_settings[set].name,
3350 error);
3351#endif /* FREECIV_NDEBUG */
3352 }
3353 main_map_allocate(); /* NOT map_init() as that would overwrite settings */
3354 }
3355 }
3356 if (!created) {
3357 bugreport_request(_("Cannot create suitable map with given settings."));
3358
3360 }
3361
3363 script_server_signal_emit("map_generated");
3364 }
3365
3366 game_map_init();
3367
3368 /* Test if main map generator settings have changed. */
3369 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3371 char pretty[sizeof(mapgen_settings[i].pretty)];
3372
3373 fc_assert_action(pset != nullptr, continue);
3374 if (0 == strcmp(setting_value_name(pset, TRUE, pretty,
3375 sizeof(pretty)),
3376 mapgen_settings[i].pretty)) {
3377 continue; /* Setting didn't change. */
3378 }
3379 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
3380 _("Setting '%s' has been adjusted from %s to %s."),
3382 mapgen_settings[i].pretty,
3383 pretty);
3384 log_normal(_("Setting '%s' has been adjusted from %s to %s."),
3386 mapgen_settings[i].pretty,
3387 pretty);
3388 }
3389 }
3390
3391 CALL_FUNC_EACH_AI(map_ready);
3392
3393 /* start the game */
3396
3397 if (game.info.is_new_game) {
3399
3400 /* If we're starting a new game, reset the max_players to be at
3401 * least the number of players currently in the game. */
3403
3404 /* Before the player map is allocated (and initialized)! */
3406
3407 players_iterate(pplayer) {
3408 player_map_init(pplayer);
3410 pplayer->economic.gold = game.info.gold;
3411 pplayer->economic.infra_points = game.info.infrapoints;
3413
3414 /* Give initial technologies, as specified in the ruleset and the
3415 * settings. */
3420
3421 /* Set up alliances based on team selections */
3422 players_iterate(pplayer) {
3424 if (players_on_same_team(pplayer, pdest)
3425 && player_number(pplayer) != player_number(pdest)) {
3427 player_diplstate_get(pdest, pplayer),
3428 DS_TEAM);
3429 give_shared_vision(pplayer, pdest);
3430 BV_SET(pplayer->real_embassy, player_index(pdest));
3431 }
3434
3435 /* Assign colors from the ruleset for any players who weren't
3436 * explicitly assigned colors during the pregame.
3437 * This must come after generate_players() since it can depend on
3438 * assigned nations. */
3440
3441 /* Save all settings for the 'reset game' command. */
3443 }
3444
3445 /* FIXME: Can this be moved? */
3446 players_iterate(pplayer) {
3449
3450 if (!game.info.is_new_game) {
3451 players_iterate(pplayer) {
3452 if (is_ai(pplayer)) {
3453 set_ai_level_direct(pplayer, pplayer->ai_common.skill_level);
3454 }
3456 } else {
3457 players_iterate(pplayer) {
3458 /* Initialize this again to be sure */
3459 adv_data_default(pplayer);
3461 }
3462
3466
3467 if (game.info.is_new_game) {
3468 /* Place players' initial units, etc */
3469 init_new_game();
3471
3473 players_iterate(pplayer) {
3474 map_show_all(pplayer);
3476 }
3477 }
3478
3480 /* This is a heavy scenario. It may include research. The sciencebox
3481 * setting may have been changed. A change to the sciencebox setting
3482 * may have caused the stored amount of bulbs to be enough to finish
3483 * the current research. */
3484
3485 players_iterate(pplayer) {
3486 /* Check for finished research. */
3487 update_bulbs(pplayer, 0, TRUE, FALSE);
3489 }
3490
3491 if (srvarg.fcdb_enabled) {
3493 &game.server.dbid);
3494 log_debug("dbid: %d", game.server.dbid);
3495 }
3496
3497 CALL_FUNC_EACH_AI(game_start);
3498}
3499
3500/**********************************************************************/
3504{
3505 /* Was redundantly in game_load() */
3506 server.playable_nations = 0;
3507 server.nbarbarians = 0;
3508 server.identity_number = IDENTITY_NUMBER_SKIP;
3509
3512
3515 /* game_init() set game.server.plr_colors to nullptr. So we need to
3516 * initialize the colors after. */
3518
3520}
3521
3522/**********************************************************************/
3528{
3530
3531 /* Free all the treaties that were left open when game finished. */
3532 free_treaties();
3533
3534 /* Free the vision data, without sending updates. */
3535 players_iterate(pplayer) {
3536 unit_list_iterate(pplayer->units, punit) {
3537 /* Don't bother using vision_clear_sight() */
3539 punit->server.vision->radius_sq[v] = -1;
3542 punit->server.vision = nullptr;
3544
3545 city_list_iterate(pplayer->cities, pcity) {
3546 /* don't bother using vision_clear_sight() */
3548 pcity->server.vision->radius_sq[v] = -1;
3551 pcity->server.vision = nullptr;
3555
3556 /* Destroy all players; with must be separate as the player information is
3557 * needed above. This also sends the information to the clients. */
3558 players_iterate(pplayer) {
3559 server_remove_player(pplayer);
3561
3565 citymap_free();
3566 game_free();
3567}
3568
3569/**********************************************************************/
3573{
3574 srv_prepare();
3575
3576 /* Run server loop */
3577 do {
3579
3580 /* Load a script file. */
3581 if (srvarg.script_filename != nullptr) {
3582 /* Adding an error message more here will duplicate them. */
3584 }
3585
3587 if (!game_was_started()) {
3589 }
3590
3591 log_normal(_("Now accepting new client connections on port %d."),
3592 srvarg.port);
3593 /* Remain in S_S_INITIAL until all players are ready. */
3595 /* When force_end_of_sniff is used in pregame, it means that the server
3596 * is ready to start (usually set within start_game()). */
3597 }
3598
3599 if (S_S_RUNNING > server_state()) {
3600 /* If restarting for lack of players, the state is S_S_OVER,
3601 * so don't try to start the game. */
3602 srv_ready(); /* srv_ready() sets server state to S_S_RUNNING. */
3603 srv_running();
3604 srv_scores();
3605 }
3606
3607 /* Remain in S_S_OVER until players log out */
3608 while (conn_list_size(game.est_connections) > 0) {
3610 }
3611
3612 if (game.info.timeout == -1 || srvarg.exit_on_end) {
3613 /* For autogames or if the -e option is specified, exit the server. */
3614 server_quit();
3615 }
3616
3617 /* Close it even between games. */
3619
3620 /* Reset server */
3624 mapimg_reset();
3626 load_rulesets(nullptr, nullptr, FALSE, nullptr, TRUE, FALSE, TRUE);
3628 } while (TRUE);
3629
3630 /* Technically, we won't ever get here. We exit via server_quit(). */
3632}
3633
3634/**********************************************************************/
3637struct color;
3638static inline void server_gui_color_free(struct color *pcolor)
3639{
3640 fc_assert_ret(pcolor == nullptr);
3641
3642 return;
3643}
3644
3645/**********************************************************************/
3649static int server_plr_tile_city_id_get(const struct tile *ptile,
3650 const struct player *pplayer)
3651{
3652 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3653
3654 return plrtile && plrtile->site ? plrtile->site->identity
3656}
3657
3658/**********************************************************************/
3662{
3663 struct setting *pset = setting_by_name(name);
3664
3665 if (pset) {
3666 return setting_number(pset);
3667 } else {
3668 log_error("No server setting named %s exists.", name);
3669 return SERVER_SETTING_NONE;
3670 }
3671}
3672
3673/**********************************************************************/
3677{
3678 struct setting *pset = setting_by_number(id);
3679
3680 if (pset) {
3681 return setting_name(pset);
3682 } else {
3683 log_error("No server setting with the id %d exists.", id);
3684
3685 return nullptr;
3686 }
3687}
3688
3689/**********************************************************************/
3693{
3694 struct setting *pset = setting_by_number(id);
3695
3696 if (pset) {
3697 return setting_type(pset);
3698 } else {
3699 log_error("No server setting with the id %d exists.", id);
3700 return sset_type_invalid();
3701 }
3702}
3703
3704/**********************************************************************/
3708{
3709 struct setting *pset = setting_by_number(id);
3710
3711 if (pset) {
3712 return setting_bool_get(pset);
3713 } else {
3714 log_error("No server setting with the id %d exists.", id);
3715 return FALSE;
3716 }
3717}
3718
3719/**********************************************************************/
3723{
3724 struct setting *pset = setting_by_number(id);
3725
3726 if (pset) {
3727 return setting_int_get(pset);
3728 } else {
3729 log_error("No server setting with the id %d exists.", id);
3730 return 0;
3731 }
3732}
3733
3734/**********************************************************************/
3738{
3739 struct setting *pset = setting_by_number(id);
3740
3741 if (pset) {
3742 return setting_bitwise_get(pset);
3743 } else {
3744 log_error("No server setting with the id %d exists.", id);
3745 return FALSE;
3746 }
3747}
3748
3749/**********************************************************************/
3753{
3755
3756 funcs->server_setting_by_name = server_ss_by_name;
3757 funcs->server_setting_name_get = server_ss_name_get;
3758 funcs->server_setting_type_get = server_ss_type_get;
3759 funcs->server_setting_val_bool_get = server_ss_val_bool_get;
3760 funcs->server_setting_val_int_get = server_ss_val_int_get;
3761 funcs->server_setting_val_bitwise_get = server_ss_val_bitwise_get;
3762 funcs->create_extra = create_extra;
3763 funcs->destroy_extra = destroy_extra;
3764 funcs->destroy_city = remove_city;
3765 funcs->player_tile_vision_get = map_is_known_and_seen;
3766 funcs->player_tile_city_id_get = server_plr_tile_city_id_get;
3767 funcs->gui_color_free = server_gui_color_free;
3768
3769 /* Keep this function call at the end. It checks if all required functions
3770 are defined. */
3772}
3773
3774/**********************************************************************/
3777static enum known_type mapimg_server_tile_known(const struct tile *ptile,
3778 const struct player *pplayer,
3779 bool knowledge)
3780{
3781 if (knowledge && pplayer) {
3782 return tile_get_known(ptile, pplayer);
3783 }
3784
3785 return TILE_KNOWN_SEEN;
3786}
3787
3788/**********************************************************************/
3791static struct terrain
3792 *mapimg_server_tile_terrain(const struct tile *ptile,
3793 const struct player *pplayer, bool knowledge)
3794{
3795 if (knowledge && pplayer) {
3796 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3797 return plrtile->terrain;
3798 }
3799
3800 return tile_terrain(ptile);
3801}
3802
3803/**********************************************************************/
3806static struct player *mapimg_server_tile_owner(const struct tile *ptile,
3807 const struct player *pplayer,
3808 bool knowledge)
3809{
3810 if (knowledge && pplayer
3811 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3812 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3813 return plrtile->owner;
3814 }
3815
3816 return tile_owner(ptile);
3817}
3818
3819/**********************************************************************/
3822static struct player *mapimg_server_tile_city(const struct tile *ptile,
3823 const struct player *pplayer,
3824 bool knowledge)
3825{
3826 struct city *pcity = tile_city(ptile);
3827
3828 if (!pcity) {
3829 return nullptr;
3830 }
3831
3832 if (knowledge && pplayer) {
3833 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
3834
3835 if (pdcity) {
3836 return pdcity->owner;
3837 } else {
3838 return nullptr;
3839 }
3840 }
3841
3842 return city_owner(tile_city(ptile));
3843}
3844
3845/**********************************************************************/
3848static struct player *mapimg_server_tile_unit(const struct tile *ptile,
3849 const struct player *pplayer,
3850 bool knowledge)
3851{
3852 int unit_count = unit_list_size(ptile->units);
3853
3854 if (unit_count == 0) {
3855 return nullptr;
3856 }
3857
3858 if (knowledge && pplayer
3859 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3860 return nullptr;
3861 }
3862
3863 return unit_owner(unit_list_get(ptile->units, 0));
3864}
3865
3866/**********************************************************************/
3870{
3871 return playercolor_count();
3872}
3873
3874/**********************************************************************/
3878{
3879 return playercolor_get(i);
3880}
3881
3882/**********************************************************************/
3885static void save_all_map_images(void)
3886{
3887 int count = mapimg_count();
3888 int i;
3889
3890 /* Save map image(s). */
3891 for (i = 0; i < count; i++) {
3892 struct mapdef *pmapdef = mapimg_isvalid(i);
3893
3894 if (pmapdef != nullptr) {
3897 } else {
3898 log_error("%s", mapimg_error());
3899 }
3900 }
3901}
3902
3903/**********************************************************************/
3906static bool world_peace_turn(void)
3907{
3908 players_iterate_alive(pplayer) {
3909 bool contact = FALSE;
3910
3912 if (pplayer != other) {
3914
3915 if (dstate->type == DS_WAR) {
3916 return FALSE;
3917 }
3918 if (dstate->type != DS_NO_CONTACT) {
3919 contact = TRUE;
3920 }
3921 }
3923
3924 if (!contact) {
3925 /* Peace only because there's nobody to show aggression against does not count. */
3926 return FALSE;
3927 }
3929
3930 return TRUE;
3931}
3932
3933/**********************************************************************/
3936static void world_peace_update(void)
3937{
3938 if (!world_peace_turn()) {
3939 /* Consecutive world peace turns begin *earliest* after this turn,
3940 overwrite older claims. */
3942 }
3943}
void access_areas_refresh(struct civ_map *nmap, struct player *plr)
Definition accessarea.c:96
int achievement_index(const struct achievement *pach)
struct player * achievement_plr(struct achievement *ach, struct player_list *achievers)
const char * achievement_later_msg(struct achievement *pach)
const char * achievement_first_msg(struct achievement *pach)
#define achievements_iterate_end
#define achievements_iterate(_ach_)
void building_advisor(struct player *pplayer)
void adv_data_analyze_rulesets(struct player *pplayer)
Definition advdata.c:192
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:263
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:566
void adv_data_default(struct player *pplayer)
Definition advdata.c:732
bool adv_spaceship_autoplace(struct player *pplayer, struct player_spaceship *ship)
Definition advspace.c:33
const char * ai_name(const struct ai_type *ai)
Definition ai.c:335
#define ai_timer_free(...)
Definition ai.h:358
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
#define ai_timer_init(...)
Definition ai.h:357
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
void ai_init(void)
Definition aiiface.c:127
const char * default_ai_type_name(void)
Definition aiiface.c:249
void ai_traits_init(struct player *pplayer)
Definition aitraits.c:33
void create_animals(void)
Definition animals.c:96
void astr_free(struct astring *astr)
Definition astring.c:148
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:251
void astr_init(struct astring *astr)
Definition astring.c:139
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:271
#define str
Definition astring.c:76
#define n
Definition astring.c:77
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define ASTRING_INIT
Definition astring.h:44
bool auth_handle_reply(struct connection *pconn, char *password)
Definition auth.c:156
void adv_workers_free(void)
Definition autoworkers.c:86
void auto_workers_player(struct player *pplayer)
void summon_barbarians(void)
Definition barbarian.c:738
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_CLR(bv, bit)
Definition bitvector.h:94
void bugreport_request(const char *reason_format,...)
Definition bugs.c:31
void game_advance_year(void)
Definition calendar.c:91
void game_next_year(struct packet_game_info *info)
Definition calendar.c:30
#define FIRST_TURN
Definition calendar.h:20
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
void free_city_map_index(void)
Definition city.c:609
#define cities_iterate_end
Definition city.h:517
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define cities_iterate(pcity)
Definition city.h:512
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
void citymap_free(void)
Definition citymap.c:110
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3627
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2368
bool send_city_suppression(bool now)
Definition citytools.c:2170
void sync_cities(void)
Definition citytools.c:3354
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3469
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3388
void remove_city(struct city *pcity)
Definition citytools.c:1713
void city_thaw_workers_queue(void)
Definition citytools.c:197
void send_player_cities(struct player *pplayer)
Definition citytools.c:2348
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2324
bool check_city_migrations(void)
Definition cityturn.c:4365
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4745
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:576
void update_city_activities(struct player *pplayer)
Definition cityturn.c:602
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4766
void check_disasters(void)
Definition cityturn.c:4540
void city_refresh_queue_processing(void)
Definition cityturn.c:213
char * incite_cost
Definition comments.c:76
report_type
Definition conn_types.h:49
@ REPORT_WONDERS_OF_THE_WORLD
Definition conn_types.h:50
@ REPORT_DEMOGRAPHIC
Definition conn_types.h:53
@ REPORT_WONDERS_OF_THE_WORLD_LONG
Definition conn_types.h:51
@ REPORT_ACHIEVEMENTS
Definition conn_types.h:54
@ REPORT_TOP_CITIES
Definition conn_types.h:52
bool handle_login_request(struct connection *pconn, struct packet_server_join_req *req)
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
Definition connecthand.c:72
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:368
bool can_conn_edit(const struct connection *pconn)
Definition connection.c:513
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:734
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:358
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:722
bool conn_controls_player(const struct connection *pconn)
Definition connection.c:747
const char * conn_description(const struct connection *pconn)
Definition connection.c:476
bool connection_send_data(struct connection *pconn, const unsigned char *data, int len)
Definition connection.c:288
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_list_iterate_end
Definition connection.h:110
void con_log_init(const char *log_filename, enum log_level level, int fatal_assertions)
Definition console.c:150
void con_flush(void)
Definition console.c:243
void con_write(enum rfc_status rfc_status, const char *message,...)
Definition console.c:203
void con_puts(enum rfc_status rfc_status, const char *str)
Definition console.c:226
void con_log_close(void)
Definition console.c:167
@ C_FAIL
Definition console.h:45
@ C_SYNTAX
Definition console.h:47
@ C_OK
Definition console.h:41
@ C_COMMENT
Definition console.h:37
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
int dio_put_uint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:265
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Definition dataio_raw.c:171
int dio_put_string_raw(struct raw_data_out *dout, const char *value)
Definition dataio_raw.c:512
int dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:398
int dio_put_uint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:287
size_t dio_output_used(struct raw_data_out *dout)
Definition dataio_raw.c:184
void dio_output_rewind(struct raw_data_out *dout)
Definition dataio_raw.c:193
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
void send_diplomatic_meetings(struct connection *dest)
Definition diplhand.c:885
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:122
void free_treaties(void)
Definition diptreaty.c:348
void edithand_free(void)
Definition edithand.c:96
void edithand_init(void)
Definition edithand.c:78
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1066
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Definition extras.c:1030
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1136
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1152
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define extra_type_by_rmcause_iterate_end
Definition extras.h:358
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition extras.h:353
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
void cmdline_option_values_free(void)
Definition fc_cmdline.c:97
void i_am_server(void)
void libfreeciv_init(bool check_fc_interface)
void libfreeciv_free(void)
struct functions * fc_interface_funcs(void)
environment_upset_type
Definition fc_types.h:971
@ EUT_NUCLEAR_WINTER
Definition fc_types.h:973
@ EUT_GLOBAL_WARMING
Definition fc_types.h:972
int server_setting_id
Definition fc_types.h:763
int Tech_type_id
Definition fc_types.h:237
int Nation_type_id
Definition fc_types.h:240
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_LEN_NAME
Definition fc_types.h:67
@ VC_CULTURE
Definition fc_types.h:966
@ VC_ALLIED
Definition fc_types.h:965
@ VC_WORLDPEACE
Definition fc_types.h:967
@ O_SHIELD
Definition fc_types.h:102
@ O_FOOD
Definition fc_types.h:102
@ O_TRADE
Definition fc_types.h:102
@ BORDERS_ENABLED
Definition fc_types.h:731
@ BORDERS_DISABLED
Definition fc_types.h:730
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:93
void fcdb_free(void)
Definition fcdb.c:234
bool fcdb_init(const char *conf_file)
Definition fcdb.c:218
const char * get_internal_encoding(void)
Definition fciconv.c:182
static char void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Definition fciconv.c:70
#define FC_DEFAULT_DATA_ENCODING
Definition fciconv.h:89
const char * get_locale_dir(void)
Definition fcintl.c:111
#define Q_(String)
Definition fcintl.h:70
#define bindtextdomain(Package, Directory)
Definition fcintl.h:82
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
void fc_mutex_init(fc_mutex *mutex)
Definition fcthread.c:128
void fc_mutex_destroy(fc_mutex *mutex)
Definition fcthread.c:136
const char * tile_link(const struct tile *ptile)
const struct ft_color ftc_server
const struct ft_color ftc_editor
const char * unit_tile_link(const struct unit *punit)
struct civ_game game
Definition game.c:62
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:715
int current_turn_timeout(void)
Definition game.c:856
void game_init(bool keep_ruleset_value)
Definition game.c:446
struct world wld
Definition game.c:63
void game_free(void)
Definition game.c:477
void game_map_init(void)
Definition game.c:464
int generate_save_name(const char *format, char *buf, int buflen, const char *reason)
Definition game.c:799
#define TURNS_NEEDED_TO_RANK
Definition game.h:80
autosave_type
Definition game.h:59
@ AS_INTERRUPT
Definition game.h:63
@ AS_GAME_OVER
Definition game.h:61
@ AS_QUITIDLE
Definition game.h:62
@ AS_TIMER
Definition game.h:64
@ AS_TURN
Definition game.h:60
void send_year_to_clients(void)
Definition gamehand.c:884
int update_timeout(void)
Definition gamehand.c:988
void send_game_info(struct conn_list *dest)
Definition gamehand.c:910
void init_new_game(void)
Definition gamehand.c:454
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Definition gamehand.c:120
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
static GHashTable * hash
Definition wldlg.c:322
static char * leader_name
Definition dialogs.c:97
static struct gui_funcs funcs
void adv_city_free(struct city *pcity)
Definition infracache.c:502
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert_exit_msg(condition, message,...)
Definition log.h:212
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_action_msg(condition, action, message,...)
Definition log.h:202
#define log_fatal(message,...)
Definition log.h:101
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_normal(message,...)
Definition log.h:108
@ LOG_NORMAL
Definition log.h:33
#define log_error(message,...)
Definition log.h:104
#define log_testmatic(message,...)
Definition log.h:124
void lsend_packet_begin_turn(struct conn_list *dest)
int send_packet_end_phase(struct connection *pc)
void dlsend_packet_start_phase(struct conn_list *dest, int phase)
void lsend_packet_freeze_client(struct conn_list *dest)
void lsend_packet_end_phase(struct conn_list *dest)
void lsend_packet_achievement_info(struct conn_list *dest, const struct packet_achievement_info *packet)
void lsend_packet_end_turn(struct conn_list *dest)
void lsend_packet_thaw_client(struct conn_list *dest)
@ PACKET_SAVE_SCENARIO
@ PACKET_EDIT_MODE
@ PACKET_EDIT_GAME
@ PACKET_NATION_SELECT_REQ
@ PACKET_SERVER_JOIN_REQ
@ PACKET_REPORT_REQ
@ PACKET_CHAT_MSG_REQ
@ PACKET_CLIENT_HEARTBEAT
@ PACKET_RULESET_SELECT
@ PACKET_CLIENT_INFO
@ PACKET_SYNC_SERIAL
@ PACKET_AUTHENTICATION_REPLY
@ PACKET_SINGLE_WANT_HACK_REQ
@ PACKET_VOTE_SUBMIT
@ PACKET_PLAYER_READY
@ PACKET_CONN_PONG
bool server_handle_packet(enum packet_type type, const void *packet, struct player *pplayer, struct connection *pconn)
Definition hand_gen.c:17
void handle_conn_pong(struct connection *pc)
Definition sernet.c:1441
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:882
void main_map_free(void)
Definition map.c:599
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
Definition map.c:1830
int map_num_tiles(void)
Definition map.c:1152
bool startpos_allows_all(const struct startpos *psp)
Definition map.c:1843
void main_map_allocate(void)
Definition map.c:534
int map_startpos_count(void)
Definition map.c:2008
bool map_is_empty(void)
Definition map.c:148
#define map_startpos_iterate(NAME_psp)
Definition map.h:136
#define map_startpos_iterate_end
Definition map.h:139
#define whole_map_iterate(_map, _tile)
Definition map.h:573
#define whole_map_iterate_end
Definition map.h:582
@ MAPGEN_SCENARIO
Definition map_types.h:47
bool map_fractal_generate(bool autosize, struct unit_type *initial_unit)
Definition mapgen.c:1268
void generator_free(void)
void player_map_init(struct player *pplayer)
Definition maphand.c:1226
void map_set_border_vision(struct player *pplayer, const bool is_enabled)
Definition maphand.c:745
void send_map_info(struct conn_list *dest)
Definition maphand.c:653
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2577
void disable_fog_of_war(void)
Definition maphand.c:1794
void show_map_to_all(void)
Definition maphand.c:1215
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:442
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1372
void enable_fog_of_war(void)
Definition maphand.c:1768
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2512
void map_show_all(struct player *pplayer)
Definition maphand.c:884
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:773
void nuclear_winter(int effect)
Definition maphand.c:117
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2680
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:925
void map_calculate_borders(void)
Definition maphand.c:2329
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1444
void give_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1637
void global_warming(int effect)
Definition maphand.c:104
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1387
void mapimg_free(void)
Definition mapimg.c:558
struct mapdef * mapimg_isvalid(int id)
Definition mapimg.c:1124
void mapimg_init(mapimg_tile_known_func mapimg_tile_known, mapimg_tile_terrain_func mapimg_tile_terrain, mapimg_tile_player_func mapimg_tile_owner, mapimg_tile_player_func mapimg_tile_city, mapimg_tile_player_func mapimg_tile_unit, mapimg_plrcolor_count_func mapimg_plrcolor_count, mapimg_plrcolor_get_func mapimg_plrcolor_get)
Definition mapimg.c:506
int mapimg_count(void)
Definition mapimg.c:573
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
Definition mapimg.c:1333
const char * mapimg_error(void)
Definition mapimg.c:759
void mapimg_reset(void)
Definition mapimg.c:541
void maybe_automatic_meta_message(const char *automatic)
Definition meta.c:152
char * meta_addr_port(void)
Definition meta.c:203
const char * default_meta_message_string(void)
Definition meta.c:91
bool send_server_info_to_metaserver(enum meta_flag flag)
Definition meta.c:491
bool server_open_meta(bool persistent)
Definition meta.c:464
#define DEFAULT_META_SERVER_ADDR
Definition meta.h:21
#define DEFAULT_META_SERVER_NO_SEND
Definition meta.h:20
@ META_INFO
Definition meta.h:26
@ META_REFRESH
Definition meta.h:27
void modpacks_free(void)
Definition modpack.c:62
void modpacks_init(void)
Definition modpack.c:50
static mpgui * gui
Definition mpgui_qt.cpp:53
const char * multiplier_name_translation(const struct multiplier *pmul)
Definition multipliers.c:97
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Definition nation.c:270
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:296
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:149
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:493
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:230
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:458
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:200
int nation_set_count(void)
Definition nation.c:715
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Definition nation.c:1226
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:286
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:682
struct nation_style * style_of_nation(const struct nation_type *pnation)
Definition nation.c:695
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:57
#define nations_iterate_end
Definition nation.h:338
#define nations_iterate(NAME_pnation)
Definition nation.h:335
#define nation_leader_list_iterate_end
Definition nation.h:59
#define NO_NATION_SELECTED
Definition nation.h:30
void fc_init_network(void)
Definition netintf.c:198
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void event_cache_remove_old(void)
Definition notify.c:602
void send_pending_events(struct connection *pconn, bool include_public)
Definition notify.c:753
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
void event_cache_clear(void)
Definition notify.c:594
void event_cache_free(void)
Definition notify.c:582
void event_cache_phases_invalidate(void)
Definition notify.c:977
void event_cache_init(void)
Definition notify.c:570
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Definition packets.c:746
const char * packet_name(enum packet_type type)
Definition packets_gen.c:47
struct player * player_by_number(const int player_id)
Definition player.c:852
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1488
int player_count(void)
Definition player.c:819
int player_slot_count(void)
Definition player.c:420
int player_number(const struct player *pplayer)
Definition player.c:839
const char * player_name(const struct player *pplayer)
Definition player.c:900
struct player * player_by_name(const char *name)
Definition player.c:886
int player_index(const struct player *pplayer)
Definition player.c:831
struct player * player_by_user(const char *name)
Definition player.c:947
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:864
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1417
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
#define player_list_iterate(playerlist, pplayer)
Definition player.h:560
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define is_ai(plr)
Definition player.h:232
#define player_list_iterate_end
Definition player.h:562
#define players_iterate_alive_end
Definition player.h:552
#define set_as_ai(plr)
Definition player.h:234
#define ANON_PLAYER_NAME
Definition player.h:43
#define is_human(plr)
Definition player.h:231
#define players_iterate_alive(_pplayer)
Definition player.h:547
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2270
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1131
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1896
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3217
int normal_player_count(void)
Definition plrhand.c:3209
void playercolor_free(void)
Definition plrhand.c:3348
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:2059
bool server_player_set_name_full(const struct connection *caller, struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Definition plrhand.c:2170
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2458
void playercolor_init(void)
Definition plrhand.c:3338
void kill_player(struct player *pplayer)
Definition plrhand.c:125
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1148
void update_national_activities(struct player *pplayer, int old_gold)
Definition plrhand.c:3478
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3225
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3377
int playercolor_count(void)
Definition plrhand.c:3387
void shuffle_players(void)
Definition plrhand.c:2383
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1945
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Definition plrhand.c:336
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1620
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2305
void update_capital(struct player *pplayer)
Definition plrhand.c:731
void assign_player_colors(void)
Definition plrhand.c:1736
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2619
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2595
void enter_war(struct player *pplayer, struct player *pplayer2)
Definition plrhand.c:848
void update_revolution(struct player *pplayer)
Definition plrhand.c:672
#define alive_phase_players_iterate(pplayer)
Definition plrhand.h:123
#define alive_phase_players_iterate_end
Definition plrhand.h:128
#define phase_players_iterate(pplayer)
Definition plrhand.h:113
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
#define allowed_nations_iterate_end
Definition plrhand.h:73
#define phase_players_iterate_end
Definition plrhand.h:118
bool fc_rand_is_init(void)
Definition rand.c:200
void fc_srand(RANDOM_TYPE seed)
Definition rand.c:161
void test_random1(int n)
Definition rand.c:253
void fc_rand_uninit(void)
Definition rand.c:192
#define fc_rand(_size)
Definition rand.h:56
randseed generate_game_seed(void)
Definition randseed.c:192
void registry_module_init(void)
Definition registry.c:31
void registry_module_close(void)
Definition registry.c:41
void report_final_scores(struct conn_list *dest)
Definition report.c:1724
void report_wonders_of_the_world(struct conn_list *dest)
Definition report.c:604
void report_demographics(struct connection *pconn)
Definition report.c:1205
void report_wonders_of_the_world_long(struct conn_list *dest)
Definition report.c:493
void make_history_report(void)
Definition report.c:1702
void log_civ_score_free(void)
Definition report.c:1514
void report_top_cities(struct conn_list *dest)
Definition report.c:410
void report_achievements(struct connection *pconn)
Definition report.c:1269
void log_civ_score_now(void)
Definition report.c:1544
struct research * research_get(const struct player *pplayer)
Definition research.c:130
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Definition research.c:723
#define researches_iterate(_presearch)
Definition research.h:155
#define researches_iterate_end
Definition research.h:158
void rulesets_deinit(void)
Definition ruleload.c:9493
bool load_rulesets(const char *restore, const char *alt, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleload.c:9413
#define sanity_check()
Definition sanitycheck.h:43
void save_system_close(void)
Definition savemain.c:329
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:143
void calc_civ_score(struct player *pplayer)
Definition score.c:251
void rank_users(bool interrupt)
Definition score.c:417
int total_player_citizens(const struct player *pplayer)
Definition score.c:382
bool script_fcdb_call(const char *func_name,...)
void script_server_signal_emit(const char *signal_name,...)
int server_open_socket(void)
Definition sernet.c:1133
void flush_packets(void)
Definition sernet.c:376
void init_connections(void)
Definition sernet.c:1362
enum server_events server_sniff_all_input(void)
Definition sernet.c:522
void readline_atexit(void)
Definition sernet.c:204
void close_connections_and_socket(void)
Definition sernet.c:255
@ S_E_OTHERWISE
Definition sernet.h:30
@ S_E_FORCE_END_OF_SNIFF
Definition sernet.h:31
#define SERVER_SETTING_NONE
void settings_init(bool act)
Definition settings.c:5257
int setting_int_get(struct setting *pset)
Definition settings.c:3830
struct setting * setting_by_name(const char *name)
Definition settings.c:3349
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4311
int setting_number(const struct setting *pset)
Definition settings.c:3365
struct setting * setting_by_number(int id)
Definition settings.c:3341
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3404
void settings_free(void)
Definition settings.c:5299
void settings_turn(void)
Definition settings.c:5291
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
void settings_game_start(void)
Definition settings.c:4857
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4065
const char * setting_name(const struct setting *pset)
Definition settings.c:3375
int setting_bitwise_get(struct setting *pset)
Definition settings.c:4301
bool setting_bool_get(struct setting *pset)
Definition settings.c:3718
void send_server_settings(struct conn_list *dest)
Definition settings.c:5439
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#define MAX_UINT32
Definition shared.h:81
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
int rank_spaceship_arrival(struct player **result)
Definition spacerace.c:460
double spaceship_arrival(const struct player *pplayer)
Definition spacerace.c:446
void send_spaceship_info(struct player *src, struct conn_list *dest)
Definition spacerace.c:129
void spaceship_arrived(struct player *pplayer)
Definition spacerace.c:420
size_t size
Definition specvec.h:72
void timing_log_init(void)
Definition srv_log.c:218
void timing_log_free(void)
Definition srv_log.c:236
static void srv_prepare(void)
Definition srv_main.c:3075
static struct player * mapimg_server_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3806
static void server_gui_color_free(struct color *pcolor)
Definition srv_main.c:3638
void server_game_init(bool keep_ruleset_value)
Definition srv_main.c:3503
static struct terrain * mapimg_server_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3792
static void save_all_map_images(void)
Definition srv_main.c:3885
static struct player * mapimg_server_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3822
static void update_diplomatics(void)
Definition srv_main.c:952
static struct player * mapimg_server_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3848
void handle_nation_select_req(struct connection *pc, int player_no, Nation_type_id nation_no, bool is_male, const char *name, int style)
Definition srv_main.c:2375
static void do_have_contacts_effect(void)
Definition srv_main.c:787
static void ai_start_phase(void)
Definition srv_main.c:1140
static struct timer * eot_timer
Definition srv_main.c:202
const char * pick_random_player_name(const struct nation_type *pnation)
Definition srv_main.c:2850
void identity_number_release(int id)
Definition srv_main.c:2030
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2627
static void handle_observer_ready(struct connection *pconn)
Definition srv_main.c:2441
bv_id identity_numbers_used
Definition srv_main.c:196
static void world_peace_update(void)
Definition srv_main.c:3936
void handle_report_req(struct connection *pconn, enum report_type type)
Definition srv_main.c:1991
static void generate_players(void)
Definition srv_main.c:2678
bool force_end_of_sniff
Definition srv_main.c:194
static void do_reveal_effects(void)
Definition srv_main.c:764
static int mapimg_server_plrcolor_count(void)
Definition srv_main.c:3869
void start_game(void)
Definition srv_main.c:1881
void handle_client_info(struct connection *pc, enum gui_type gui, int emerg_version, const char *distribution)
Definition srv_main.c:316
void handle_player_ready(struct player *requestor, int player_no, bool is_ready)
Definition srv_main.c:2457
const char * aifill(int amount)
Definition srv_main.c:2511
static bool identity_number_is_used(int id)
Definition srv_main.c:2046
static void end_phase(void)
Definition srv_main.c:1441
static enum server_states civserver_state
Definition srv_main.c:188
static void begin_turn(bool is_new_turn)
Definition srv_main.c:1155
static void end_turn(void)
Definition srv_main.c:1607
void save_game_auto(const char *save_reason, enum autosave_type type)
Definition srv_main.c:1840
static struct rgbcolor * mapimg_server_plrcolor_get(int i)
Definition srv_main.c:3877
void set_server_state(enum server_states newstate)
Definition srv_main.c:347
static int increment_identity_number(void)
Definition srv_main.c:2054
const char * server_ss_name_get(server_setting_id id)
Definition srv_main.c:3676
static bool world_peace_turn(void)
Definition srv_main.c:3906
static void begin_phase(bool is_new_phase)
Definition srv_main.c:1262
static void update_environmental_upset(enum environment_upset_type type, int *current, int *accum, int *level, int percent, void(*upset_action_fn)(int))
Definition srv_main.c:831
static void kill_dying_players(void)
Definition srv_main.c:1114
bool game_was_started(void)
Definition srv_main.c:355
static void srv_scores(void)
Definition srv_main.c:3175
#define startpos_hash_iterate(hash, psp, c)
Definition srv_main.c:2610
void identity_number_reserve(int id)
Definition srv_main.c:2038
struct server_arguments srvarg
Definition srv_main.c:182
static void srv_ready(void)
Definition srv_main.c:3233
static void srv_running(void)
Definition srv_main.c:2896
static void final_ruleset_adjustments(void)
Definition srv_main.c:3207
#define startpos_hash_iterate_end
Definition srv_main.c:2612
static int server_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Definition srv_main.c:3649
static bool is_client_edit_packet(int type)
Definition srv_main.c:2086
void fc__noreturn srv_main(void)
Definition srv_main.c:3572
static void notify_illegal_armistice_units(struct player *phost, struct player *pguest, int turns_left)
Definition srv_main.c:869
bool server_ss_val_bool_get(server_setting_id id)
Definition srv_main.c:3707
static void remove_illegal_armistice_units(struct player *plr1, struct player *plr2)
Definition srv_main.c:913
int identity_number(void)
Definition srv_main.c:2064
server_setting_id server_ss_by_name(const char *name)
Definition srv_main.c:3661
void check_for_full_turn_done(void)
Definition srv_main.c:2261
static void player_set_nation_full(struct player *pplayer, struct nation_type *pnation)
Definition srv_main.c:2617
static void announce_player(struct player *pplayer)
Definition srv_main.c:2878
void srv_init(void)
Definition srv_main.c:233
bool server_packet_input(struct connection *pconn, void *packet, int type)
Definition srv_main.c:2095
static void fc_interface_init_server(void)
Definition srv_main.c:3752
int server_ss_val_int_get(server_setting_id id)
Definition srv_main.c:3722
static struct timer * between_turns
Definition srv_main.c:204
unsigned int server_ss_val_bitwise_get(server_setting_id id)
Definition srv_main.c:3737
static bool has_been_srv_init
Definition srv_main.c:199
void send_all_info(struct conn_list *dest)
Definition srv_main.c:732
void init_game_seed(void)
Definition srv_main.c:209
void fc__noreturn server_quit(void)
Definition srv_main.c:1918
void update_nations_with_startpos(void)
Definition srv_main.c:2316
enum sset_type server_ss_type_get(server_setting_id id)
Definition srv_main.c:3692
bool check_for_game_over(void)
Definition srv_main.c:369
static enum known_type mapimg_server_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3777
static void do_border_vision_effect(void)
Definition srv_main.c:804
enum server_states server_state(void)
Definition srv_main.c:339
void server_game_free(void)
Definition srv_main.c:3527
#define IDENTITY_NUMBER_SIZE
Definition srv_main.h:71
#define IDENTITY_NUMBER_SKIP
Definition srv_main.h:85
void signal_timer_free(void)
Definition srv_signal.c:149
void set_running_game_access_level(void)
Definition stdinhand.c:1613
void stdinhand_turn(void)
Definition stdinhand.c:256
void stdinhand_init(void)
Definition stdinhand.c:243
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:1988
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
Definition stdinhand.c:1148
void stdinhand_free(void)
Definition stdinhand.c:264
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Definition stdinhand.c:3784
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6119
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:681
Definition city.h:318
int num_phases
Definition game.h:176
void(* unit_deallocate)(int unit_id)
Definition game.h:309
int world_peace_start
Definition game.h:245
struct civ_game::@32::@36::@41 mutexes
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:196
int save_nturns
Definition game.h:190
float turn_change_time
Definition game.h:225
bool fixedlength
Definition game.h:153
struct packet_ruleset_control control
Definition game.h:83
bool fogofwar_old
Definition game.h:241
int end_turn
Definition game.h:151
fc_mutex city_list
Definition game.h:278
struct conn_list * est_connections
Definition game.h:97
struct civ_game::@34 callbacks
struct packet_game_info info
Definition game.h:89
unsigned autosaves
Definition game.h:192
struct timer * save_timer
Definition game.h:224
bool endspaceship
Definition game.h:152
char rulesetdir[MAX_LEN_NAME]
Definition game.h:246
int start_year
Definition game.h:198
bool migration
Definition game.h:171
int additional_phase_seconds
Definition game.h:219
randseed seed
Definition game.h:234
int dbid
Definition game.h:255
struct packet_scenario_info scenario
Definition game.h:87
struct conn_list * web_client_connections
Definition game.h:99
randseed seed_setting
Definition game.h:233
struct timer * phase_timer
Definition game.h:218
int nuclear_winter_percent
Definition game.h:239
unsigned revealmap
Definition game.h:184
char orig_game_version[MAX_LEN_NAME]
Definition game.h:228
char save_name[MAX_LEN_NAME]
Definition game.h:227
struct civ_game::@32::@36 server
struct packet_timeout_info tinfo
Definition game.h:91
int phase_mode_stored
Definition game.h:223
int max_players
Definition game.h:163
bool auto_ai_toggle
Definition game.h:137
int global_warming_percent
Definition game.h:237
struct government * government_during_revolution
Definition game.h:94
bool turnblock
Definition game.h:204
bool have_resources
Definition map_types.h:121
randseed seed_setting
Definition map_types.h:104
struct civ_map::@44::@46 server
enum map_generator generator
Definition map_types.h:111
Definition colors.h:21
struct government * init_government
Definition nation.h:126
enum borders_mode borders
enum ai_level skill_level
enum phase_mode_type phase_mode
enum ai_level skill_level
Definition player.h:116
char contact_turns_left
Definition player.h:204
int auto_cancel_turn
Definition player.h:206
int first_contact_turn
Definition player.h:201
enum diplstate_type type
Definition player.h:199
char has_reason_to_cancel
Definition player.h:203
int culture
Definition player.h:109
bool random_name
Definition player.h:295
struct player_ai ai_common
Definition player.h:288
bool is_male
Definition player.h:257
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_winner
Definition player.h:269
bool is_connected
Definition player.h:296
int nturns_idle
Definition player.h:265
struct connection * current_conn
Definition player.h:297
struct team * team
Definition player.h:261
bool was_created
Definition player.h:294
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
bool is_alive
Definition player.h:268
struct player_score score
Definition player.h:283
struct nation_type * nation
Definition player.h:260
struct nation_style * style
Definition player.h:279
bool is_ready
Definition player.h:262
bool unassigned_user
Definition player.h:253
int free_bulbs
Definition research.h:67
bool metaconnection_persistent
Definition srv_main.h:30
char * bind_addr
Definition srv_main.h:34
enum log_level loglevel
Definition srv_main.h:40
char metaserver_addr[256]
Definition srv_main.h:29
char * scenarios_pathname
Definition srv_main.h:47
char load_filename[512]
Definition srv_main.h:44
char * fcdb_conf
Definition srv_main.h:56
bool auth_allow_guests
Definition srv_main.h:58
char * saves_pathname
Definition srv_main.h:46
char * log_filename
Definition srv_main.h:42
char * ranklog_filename
Definition srv_main.h:43
bool metaserver_no_send
Definition srv_main.h:28
char * bind_meta_addr
Definition srv_main.h:38
bool auth_allow_newusers
Definition srv_main.h:59
char * script_filename
Definition srv_main.h:45
char serverid[256]
Definition srv_main.h:49
char identity_name[256]
Definition srv_main.h:31
char *const value
Definition settings.c:147
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition timing.c:81
Definition unit.h:140
enum unit_activity activity
Definition unit.h:159
struct vision * vision
Definition unit.h:247
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
v_radius_t radius_sq
Definition vision.h:92
struct civ_map map
struct nation_style * style_by_number(int id)
Definition style.c:88
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define sz_strlcpy(dest, src)
Definition support.h:195
#define fc__noreturn
Definition support.h:125
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
int team_count(void)
Definition team.c:375
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
#define teams_iterate_end
Definition team.h:87
#define teams_iterate(_pteam)
Definition team.h:82
#define A_UNSET
Definition tech.h:48
void init_tech(struct research *research, bool update)
Definition techtools.c:1094
void choose_tech(struct research *research, Tech_type_id tech)
Definition techtools.c:1005
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
void choose_random_tech(struct research *research)
Definition techtools.c:990
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1188
void do_tech_parasite_effects(struct player *pplayer)
Definition techtools.c:143
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech, bool free_bulbs)
Definition techtools.c:654
#define terrain_has_flag(terr, flag)
Definition terrain.h:176
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:576
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:602
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:393
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_worked(_tile)
Definition tile.h:119
known_type
Definition tile.h:35
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:115
#define tile_has_extra(ptile, pextra)
Definition tile.h:152
#define tile_owner(_tile)
Definition tile.h:97
void timer_clear(struct timer *t)
Definition timing.c:252
void timer_destroy(struct timer *t)
Definition timing.c:208
void timer_start(struct timer *t)
Definition timing.c:263
struct timer * timer_new(enum timer_timetype type, enum timer_use use, const char *name)
Definition timing.c:160
double timer_read_seconds(struct timer *t)
Definition timing.c:379
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use, const char *name)
Definition timing.c:180
@ TIMER_ACTIVE
Definition timing.h:46
@ TIMER_CPU
Definition timing.h:41
@ TIMER_USER
Definition timing.h:42
static int best_value(const void *a, const void *b)
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2745
bool is_enter_borders_unit(const struct unit *punit)
Definition unit.c:351
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void update_unit_activities(struct player *pplayer)
Definition unittools.c:671
void random_movements(struct player *pplayer)
Definition unittools.c:5109
void finalize_unit_phase_beginning(struct player *pplayer)
Definition unittools.c:703
void execute_unit_orders(struct player *pplayer)
Definition unittools.c:681
void do_explore(struct unit *punit)
Definition unittools.c:3104
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2144
void unit_tc_effect_refresh(struct player *pplayer)
Definition unittools.c:693
void player_restore_units(struct player *pplayer)
Definition unittools.c:482
bool unit_can_be_retired(struct unit *punit)
Definition unittools.c:5092
void send_all_known_units(struct conn_list *dest)
Definition unittools.c:2926
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2279
const char * unstable_message(void)
Definition version.c:160
const char * freeciv_datafile_version(void)
Definition version.c:186
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26
void vision_free(struct vision *vision)
Definition vision.c:50
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80
void send_updated_vote_totals(struct conn_list *dest)
Definition voting.c:866
void voting_turn(void)
Definition voting.c:718
void clear_all_votes(void)
Definition voting.c:219
void voting_init(void)
Definition voting.c:707
void voting_free(void)
Definition voting.c:734
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT