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 "achievements.h"
70#include "calendar.h"
71#include "capstr.h"
72#include "city.h"
73#include "counters.h"
74#include "culture.h"
75#include "dataio.h"
76#include "effects.h"
77#include "events.h"
78#include "fc_interface.h"
79#include "government.h"
80#include "map.h"
81#include "mapimg.h"
82#include "modpack.h"
83#include "nation.h"
84#include "packets.h"
85#include "player.h"
86#include "research.h"
87#include "tech.h"
88#include "unitlist.h"
89#include "version.h"
90#include "victory.h"
91
92/* server */
93#include "aahand.h"
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 do {
213 /* We strip the high bit for now because neither game file nor
214 server options can handle unsigned ints yet. - Cedric */
216 } while (game.server.seed == 0);
217#ifdef FREECIV_TESTMATIC
218 /* Log command to reproduce the gameseed */
219 log_testmatic("set gameseed %u", game.server.seed);
220#else /* FREECIV_TESTMATIC */
221 log_debug("Setting game.seed:%u", game.server.seed);
222#endif /* FREECIV_TESTMATIC */
223 } else {
225 }
226
227 if (!fc_rand_is_init()) {
229 }
230}
231
232/**********************************************************************/
235void srv_init(void)
236{
237 /* fc_interface_init_server() includes low level support like
238 * guaranteeing that fc_vsnprintf() will work after it,
239 * so this need to be early. */
241
242 i_am_server(); /* Tell to libfreeciv that we are server */
243
244#ifdef ENABLE_NLS
245 (void) bindtextdomain("freeciv-nations", get_locale_dir());
246#endif
247
248 /* This is before ai module initializations so that if ai module
249 * wants to use registry files, it can. */
251
252 /* We want this before any AI stuff */
254
255 /* This must be before command line argument parsing.
256 This allocates default AI, and we want that to take place before
257 loading additional AI modules from command line. */
258 ai_init();
259
260 /* Init server arguments... */
261
265 srvarg.identity_name[0] = '\0';
266 srvarg.serverid[0] = '\0';
267
268 srvarg.bind_addr = nullptr;
269#ifdef FREECIV_JSON_CONNECTION
271#else /* FREECIV_JSON_CONNECTION */
273#endif /* FREECIV_JSON_CONNECTION */
274
275 srvarg.bind_meta_addr = nullptr;
276
278
279 srvarg.log_filename = nullptr;
281 srvarg.ranklog_filename = nullptr;
282 srvarg.load_filename[0] = '\0';
283 srvarg.script_filename = nullptr;
286 srvarg.ruleset = nullptr;
287
288 srvarg.quitidle = 0;
289
291 srvarg.fcdb_conf = nullptr;
295
296 /* Mark as initialized */
298
299 /* Init character encodings. */
301#ifdef ENABLE_NLS
303#endif
304
305 /* Initialize callbacks. */
307
308 /* Initialize global mutexes */
310
311 /* Done */
312 return;
313}
314
315/**********************************************************************/
318void handle_client_info(struct connection *pc, enum gui_type gui,
319 int emerg_version, const char *distribution)
320{
321 pc->client_gui = gui;
322 log_debug("%s's client has %s gui.", pc->username, gui_type_name(gui));
323 if (emerg_version > 0) {
324 log_debug("It's emergency release .%d", emerg_version);
325 }
326 if (strcmp(distribution, "")) {
327 log_debug("It comes from %s distribution.", distribution);
328 }
329
330 /* In case a modified client sends multiple client_info packets */
332
333 if (gui == GUI_WEB) {
335 }
336}
337
338/**********************************************************************/
342{
343 return civserver_state;
344}
345
346/**********************************************************************/
353
354/**********************************************************************/
358{
359 return (!game.info.is_new_game || S_S_INITIAL != server_state());
360}
361
362/**********************************************************************/
372{
373 int candidates, defeated;
374 struct player *victor;
375 int winners = 0;
376 struct astring str = ASTRING_INIT;
377
378 /* Check for scenario victory; dead players can win if they are on a team
379 * with the winners. */
380 players_iterate(pplayer) {
382 || get_player_bonus(pplayer, EFT_VICTORY) > 0) {
383 if (winners) {
384 /* TRANS: Another entry in winners list (", the Tibetans") */
385 astr_add(&str, Q_("?winners:, the %s"),
386 nation_plural_for_player(pplayer));
387 } else {
388 /* TRANS: Beginning of the winners list ("the French") */
389 astr_add(&str, Q_("?winners:the %s"),
390 nation_plural_for_player(pplayer));
391 }
392 pplayer->is_winner = TRUE;
393 winners++;
394 }
396 if (winners) {
398 /* TRANS: There can be several winners listed */
399 _("Scenario victory to %s."), astr_str(&str));
400 log_normal(_("Scenario victory to %s."), astr_str(&str));
401 astr_free(&str);
402 return TRUE;
403 }
404 astr_free(&str);
405
406 /* Count candidates for the victory. */
407 candidates = 0;
408 defeated = 0;
409 victor = nullptr;
410 /* Do not use player_iterate_alive() here - dead player must be counted as
411 * defeated to end the game with a victory. */
412 players_iterate(pplayer) {
413 if (is_barbarian(pplayer)) {
414 continue;
415 }
416
417 if ((pplayer)->is_alive
418 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
419 candidates++;
420 victor = pplayer;
421 } else {
422 defeated++;
423 }
425
426 if (0 == candidates) {
428 _("Game is over."));
429 log_normal(_("Game is over."));
430 return TRUE;
431 } else {
432 if (defeated > 0) {
433 /* If nobody conceded the game, it mays be a solo game or a single team
434 * game. */
435 fc_assert(victor != nullptr);
436
437 /* Quit if we have team victory. */
438 if (1 < team_count()) {
440 const struct player_list *members = team_members(pteam);
441 int team_candidates = 0, team_defeated = 0;
442
443 if (1 == player_list_size(members)) {
444 /* This is not really a team, single players are handled below. */
445 continue;
446 }
447
448 player_list_iterate(members, pplayer) {
449 if (pplayer->is_alive
450 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
452 } else {
454 }
456
459
461 /* We need a player in a other team to conced the game here. */
463 _("Team victory to %s."),
465 log_normal(_("Team victory to %s."), team_name_translation(pteam));
466 /* All players of the team win, even dead and surrendered ones. */
467 player_list_iterate(members, pplayer) {
468 pplayer->is_winner = TRUE;
470
471 return TRUE;
472 }
474 }
475 }
476
477 /* Check for allied victory. */
480
481 /* Try to build a winner list. */
482 players_iterate_alive(pplayer) {
483 if (is_barbarian(pplayer)
484 || player_status_check((pplayer), PSTATUS_SURRENDER)) {
485 continue;
486 }
487
489 if (!pplayers_allied(aplayer, pplayer)) {
491 winner_list = nullptr;
492 break;
493 }
495
496 if (winner_list == nullptr) {
497 break;
498 }
501
502 if (winner_list != nullptr) {
503 bool first = TRUE;
504
506
507 astr_init(&str);
509 if (first) {
510 /* TRANS: Beginning of the winners list ("the French") */
511 astr_add(&str, Q_("?winners:the %s"),
512 nation_plural_for_player(pplayer));
513 first = FALSE;
514 } else {
515 /* TRANS: Another entry in winners list (", the Tibetans") */
516 astr_add(&str, Q_("?winners:, the %s"),
517 nation_plural_for_player(pplayer));
518 }
519 pplayer->is_winner = TRUE;
522 /* TRANS: There can be several winners listed */
523 _("Allied victory to %s."), astr_str(&str));
524 log_normal(_("Allied victory to %s."), astr_str(&str));
525 astr_free(&str);
527 return TRUE;
528 }
529 }
530
531 /* Check for World Peace victory. */
534 bool first = TRUE;
535
536 astr_init(&str);
537
538 players_iterate_alive(pplayer) {
539 if (first) {
540 /* TRANS: Beginning of the winners list ("the French") */
541 astr_add(&str, Q_("?winners:the %s"),
542 nation_plural_for_player(pplayer));
543 first = FALSE;
544 } else {
545 /* TRANS: Another entry in winners list (", the Tibetans") */
546 astr_add(&str, Q_("?winners:, the %s"),
547 nation_plural_for_player(pplayer));
548 }
549
550 pplayer->is_winner = TRUE;
551
553
555 /* TRANS: There can be several winners listed */
556 _("World Peace victory to %s."), astr_str(&str));
557 log_normal(_("World Peace victory to %s."), astr_str(&str));
558 astr_free(&str);
559
560 return TRUE;
561 }
562 }
563
564 /* Check for single player victory. */
565 if (1 == candidates && victor != nullptr) {
566 bool found = FALSE; /* We need at least one enemy defeated. */
567
568 players_iterate(pplayer) {
569 if (pplayer != victor
570 && !is_barbarian(pplayer)
571 && (!pplayer->is_alive
573 && pplayer->team != victor->team
575 || !pplayers_allied(victor, pplayer))) {
576 found = TRUE;
577 break;
578 }
580
581 if (found) {
583 _("Game ended in conquest victory for %s."), player_name(victor));
584 log_normal(_("Game ended in conquest victory for %s."), player_name(victor));
585 victor->is_winner = TRUE;
586 return TRUE;
587 }
588 }
589 }
590
591 /* Check for culture victory */
593 struct player *best = nullptr;
594 long best_value = -1;
595 long second_value = -1;
596
597 players_iterate(pplayer) {
598 if (is_barbarian(pplayer) || !pplayer->is_alive) {
599 continue;
600 }
601
602 if (pplayer->score.culture > best_value) {
603 best = pplayer;
605 best_value = pplayer->score.culture;
606 } else if (pplayer->score.culture > second_value) {
607 second_value = pplayer->score.culture;
608 }
610
611 if (best != nullptr && best_value >= game.info.culture_vic_points
612 && best_value > second_value * (100 + game.info.culture_vic_lead) / 100) {
614 _("Game ended in cultural domination victory for %s."),
615 player_name(best));
616 log_normal(_("Game ended in cultural domination victory for %s."),
617 player_name(best));
618 best->is_winner = TRUE;
619
620 return TRUE;
621 }
622 }
623
624 /* Quit if we are past the turn limit. */
627 _("Game ended as the turn limit was exceeded."));
628 log_normal(_("Game ended as the turn limit was exceeded."));
629 return TRUE;
630 } else if (game.info.turn == game.server.end_turn) {
631 /* Give them a chance to decide to extend the game */
633 _("Notice: game will end at the end of this turn due "
634 "to 'endturn' server setting."));
635 }
636
637 /* Check for a spacerace win (and notify of imminent arrivals).
638 * Check this after checking turn limit, because we are checking for
639 * the spaceship arriving in the year corresponding to the turn
640 * that's about to start. */
641 {
642 int n, i;
644
646
647 for (i = 0; i < n; i++) {
648 struct player *pplayer = arrivals[i];
649 const struct player_list *members;
650 bool win;
651
652 if (game.info.year < (int)spaceship_arrival(pplayer)) {
653 /* We are into the future arrivals */
654 break;
655 }
656
657 /* Mark as arrived and notify everyone. */
658 spaceship_arrived(pplayer);
659
660 if (!game.server.endspaceship) {
661 /* Games does not end on spaceship arrival. At least print all the
662 * arrival messages. */
663 continue;
664 }
665
666 /* This player has won, now check if anybody else wins with them. */
667 members = team_members(pplayer->team);
668 win = FALSE;
670 if (pplayer->is_alive
672 /* We need at least one player to be a winner candidate in the
673 * team. */
674 win = TRUE;
675 break;
676 }
678
679 if (!win) {
680 /* Let's try next arrival. */
681 continue;
682 }
683
684 if (1 < player_list_size(members)) {
685 notify_conn(nullptr, nullptr, E_GAME_END, ftc_server,
686 _("Team victory to %s."),
687 team_name_translation(pplayer->team));
688 /* All players of the team win, even dead and surrendered ones. */
690 pteammate->is_winner = TRUE;
692 } else {
693 notify_conn(nullptr, nullptr, E_GAME_END, ftc_server,
694 _("Game ended in victory for %s."), player_name(pplayer));
695 pplayer->is_winner = TRUE;
696 }
697 return TRUE;
698 }
699
700 /* Print notice(s) of imminent arrival. These are not infallible
701 * (quite apart from risk of enemy action) because arrival is
702 * year-based, and some effect may change the timeline between
703 * now and the end of the next turn.
704 * (Also the order of messages will not always indicate tie-breaks,
705 * if the shuffled order is changed every turn, as it is for
706 * PMT_CONCURRENT games.) */
707 for (; i < n; i++) {
708 const struct player *pplayer = arrivals[i];
709 struct packet_game_info next_info = game.info; /* struct copy */
710
711 /* Advance the calendar in a throwaway copy of game.info. */
713
714 if (next_info.year < (int)spaceship_arrival(pplayer)) {
715 /* Even further in the future */
716 break;
717 }
718
719 notify_player(nullptr, nullptr, E_SPACESHIP, ftc_server,
720 _("Notice: the %s spaceship will likely arrive at "
721 "Alpha Centauri next turn."),
723 }
724 }
725
726 return FALSE;
727}
728
729/**********************************************************************/
734void send_all_info(struct conn_list *dest)
735{
736 conn_list_iterate(dest, pconn) {
739 }
741
742 /* Resend player info because it could have more infos (e.g. embassy). */
743 send_player_all_c(nullptr, dest);
747 send_map_info(dest);
751 send_spaceship_info(nullptr, dest);
752
756
760}
761
762/**********************************************************************/
766static void do_reveal_effects(void)
767{
768 phase_players_iterate(pplayer) {
769 if (get_player_bonus(pplayer, EFT_REVEAL_CITIES) > 0) {
770 players_iterate(other_player) {
771 city_list_iterate(other_player->cities, pcity) {
772 map_show_tile(pplayer, pcity->tile);
775 }
776 if (get_player_bonus(pplayer, EFT_REVEAL_MAP) > 0) {
777 /* map_show_all() will mark all unknown tiles as known and send
778 * tile, unit, and city updates as necessary. No other actions are
779 * needed. */
780 map_show_all(pplayer);
781 }
783}
784
785/**********************************************************************/
789static void do_have_contacts_effect(void)
790{
791 phase_players_iterate(pplayer) {
792 if (get_player_bonus(pplayer, EFT_HAVE_CONTACTS) > 0) {
794 /* Note this gives pplayer contact with pother, but doesn't give
795 * pother contact with pplayer. This may cause problems in other
796 * parts of the code if we're not careful. */
797 make_contact(pplayer, pother, nullptr);
799 }
801}
802
803/**********************************************************************/
806static void do_border_vision_effect(void)
807{
809 /* Border_Vision is useless. If borders are disabled there are no
810 * borders to see inside. If borders are seen they are seen already.
811 * The borders setting can't change after the game has started. */
812 return;
813 }
814
817
818 /* Check the Border_Vision effect for this player. */
820
821 if (new_border_vision != plr->server.border_vision) {
822 /* Border vision changed. */
823
824 /* Update the map */
826 }
828}
829
830/**********************************************************************/
834 int *current, int *accum, int *level,
835 int percent,
836 void (*upset_action_fn)(int))
837{
838 int count;
839
840 count = 0;
841 extra_type_iterate(cause) {
842 if (extra_causes_env_upset(cause, type)) {
843 whole_map_iterate(&(wld.map), ptile) {
844 if (tile_has_extra(ptile, cause)) {
845 count++;
846 }
848 }
850
851 *current = (count * percent) / 100;
852 *accum += count;
853 if (*accum < *level) {
854 *accum = 0;
855 } else {
856 *accum -= *level;
857 if (fc_rand((map_num_tiles() + 19) / 20) < *accum) {
858 upset_action_fn((MAP_NATIVE_WIDTH / 10) + (MAP_NATIVE_HEIGHT / 10) + ((*accum) * 5));
859 *accum = 0;
860 *level += (map_num_tiles() + 999) / 1000;
861 }
862 }
863
864 log_debug("environmental_upset: type=%-4d current=%-2d "
865 "level=%-2d accum=%-2d", type, *current, *level, *accum);
866}
867
868/**********************************************************************/
872 struct player *pguest,
873 int turns_left)
874{
875 int nunits = 0;
876 struct unit *a_unit = nullptr;
877
879 struct tile *ptile = unit_tile(punit);
880
881 if (tile_owner(ptile) == phost
884 nunits++;
885 a_unit = punit;
886 }
888
889 if (nunits > 0) {
891
893 /* TRANS: "... 2 military units in Norwegian territory." */
894 PL_("Warning: you still have %d military unit in %s territory.",
895 "Warning: you still have %d military units in %s territory.",
896 nunits),
898 /* If there's one lousy unit left, we may as well include a link for it */
899 notify_player(pguest, nunits == 1 ? unit_tile(a_unit) : nullptr,
901 /* TRANS: %s is another, separately translated sentence,
902 * ending in a full stop. */
903 PL_("%s Any such units will be disbanded in %d turn, "
904 "in accordance with peace treaty.",
905 "%s Any such units will be disbanded in %d turns, "
906 "in accordance with peace treaty.", turns_left),
907 astr_str(&unitstr), turns_left);
909 }
910}
911
912/**********************************************************************/
915static void remove_illegal_armistice_units(struct player *plr1,
916 struct player *plr2)
917{
918 /* Remove illegal units */
920 struct tile *ptile = unit_tile(punit);
921
922 if (tile_owner(ptile) == plr2
926 _("Your %s was disbanded in accordance with "
927 "your peace treaty with the %s."),
930 wipe_unit(punit, ULR_ARMISTICE, nullptr);
931 }
933
935 struct tile *ptile = unit_tile(punit);
936
937 if (tile_owner(ptile) == plr1
941 _("Your %s was disbanded in accordance with "
942 "your peace treaty with the %s."),
945 wipe_unit(punit, ULR_ARMISTICE, nullptr);
946 }
948}
949
950/**********************************************************************/
954static void update_diplomatics(void)
955{
958 struct player_diplstate *state = player_diplstate_get(plr1, plr2);
959
960 /* Players might just met when first of them was being handled
961 * (pact with third player changed and units got bounced next
962 * to second unit to form first contact)
963 * Do not decrease the counters for the other player yet in this turn */
964 if (state->first_contact_turn != game.info.turn) {
965 struct player_diplstate *state2 = player_diplstate_get(plr2, plr1);
966
967 state->has_reason_to_cancel = MAX(state->has_reason_to_cancel - 1, 0);
968 state->contact_turns_left = MAX(state->contact_turns_left - 1, 0);
969
970 if (state->type == DS_ARMISTICE
971 /* Don't count down if auto canceled this turn. Auto canceling
972 * happens in this loop. */
973 && state->auto_cancel_turn != game.info.turn) {
974 state->turns_left--;
975 if (state->turns_left <= 0) {
976 state->type = DS_PEACE;
977 state2->type = DS_PEACE;
978 state->turns_left = 0;
979 state2->turns_left = 0;
981 } else {
982 notify_illegal_armistice_units(plr1, plr2, state->turns_left);
983 }
984 }
985
986 if (state->type == DS_CEASEFIRE) {
987 state->turns_left--;
988 switch (state->turns_left) {
989 case 1:
990 notify_player(plr1, nullptr, E_DIPLOMACY, ftc_server,
991 _("Concerned citizens point out that the cease-fire "
992 "with %s will run out soon."), player_name(plr2));
993 /* Message to plr2 will be done when plr1 and plr2 will be swapped.
994 * Else, we will get a message duplication. Note the case is not
995 * the below, because the state will be changed for both players to
996 * war. */
997 break;
998 case 0:
999 notify_player(plr1, nullptr, E_DIPLOMACY, ftc_server,
1000 _("The cease-fire with %s has run out. "
1001 "You are now at war with the %s."),
1002 player_name(plr2),
1004 notify_player(plr2, nullptr, E_DIPLOMACY, ftc_server,
1005 _("The cease-fire with %s has run out. "
1006 "You are now at war with the %s."),
1007 player_name(plr1),
1009 state->type = DS_WAR;
1010 state2->type = DS_WAR;
1011 state->turns_left = 0;
1012 state2->turns_left = 0;
1013
1014 enter_war(plr1, plr2);
1015
1018 sync_cities();
1019
1020 /* Avoid love-love-hate triangles */
1022 if (plr3 != plr1 && plr3 != plr2
1023 && pplayers_allied(plr3, plr1)
1024 && pplayers_allied(plr3, plr2)) {
1025 struct player_diplstate *to1
1026 = player_diplstate_get(plr3, plr1);
1027 struct player_diplstate *from1
1028 = player_diplstate_get(plr1, plr3);
1029 struct player_diplstate *to2
1030 = player_diplstate_get(plr3, plr2);
1031 struct player_diplstate *from2
1032 = player_diplstate_get(plr2, plr3);
1033 const char *plr1name = player_name(plr1);
1034 const char *plr2name = player_name(plr2);
1035 bool cancel1;
1036 bool cancel2;
1037
1038 if (players_on_same_team(plr3, plr1)) {
1040
1041 cancel1 = FALSE;
1042 cancel2 = TRUE;
1043
1045 _("The cease-fire between %s and %s has run out. "
1046 "They are at war. You cancel your alliance "
1047 "with %s."),
1049 } else if (players_on_same_team(plr3, plr2)) {
1050
1051 cancel1 = TRUE;
1052 cancel2 = FALSE;
1053
1055 _("The cease-fire between %s and %s has run out. "
1056 "They are at war. You cancel your alliance "
1057 "with %s."),
1059 } else {
1060
1061 cancel1 = TRUE;
1062 cancel2 = TRUE;
1063
1065 _("The cease-fire between %s and %s has run out. "
1066 "They are at war. You cancel your alliance "
1067 "with both."),
1068 player_name(plr1),
1069 player_name(plr2));
1070 }
1071
1072 if (cancel1) {
1073 /* Cancel the alliance. */
1074 to1->has_reason_to_cancel = 1;
1076
1077 /* Avoid asymmetric turns_left for the armistice. */
1078 to1->auto_cancel_turn = game.info.turn;
1079 from1->auto_cancel_turn = game.info.turn;
1080
1081 /* Count down for this turn. */
1082 to1->turns_left--;
1083 from1->turns_left--;
1084 }
1085
1086 if (cancel2) {
1087 /* Cancel the alliance. */
1088 to2->has_reason_to_cancel = 1;
1090
1091 /* Avoid asymmetric turns_left for the armistice. */
1092 to2->auto_cancel_turn = game.info.turn;
1093 from2->auto_cancel_turn = game.info.turn;
1094
1095 /* Count down for this turn. */
1096 to2->turns_left--;
1097 from2->turns_left--;
1098 }
1099 }
1101 break;
1102 }
1103 }
1104 }
1107}
1108
1109/**********************************************************************/
1116static void kill_dying_players(void)
1117{
1118 bool voter_died = FALSE;
1119
1120 players_iterate_alive(pplayer) {
1121 /* cities or units remain? */
1122 if (0 == city_list_size(pplayer->cities)
1123 && 0 == unit_list_size(pplayer->units)) {
1125 }
1126 /* also UTYF_GAMELOSS in unittools server_remove_unit() */
1127 if (player_status_check(pplayer, PSTATUS_DYING)) {
1128 /* Can't get more dead than this. */
1129 voter_died = voter_died || pplayer->is_connected;
1130 kill_player(pplayer);
1131 }
1133
1134 if (voter_died) {
1135 send_updated_vote_totals(nullptr);
1136 }
1137}
1138
1139/**********************************************************************/
1142static void ai_start_phase(void)
1143{
1144 phase_players_iterate(pplayer) {
1145 if (is_ai(pplayer)) {
1146 CALL_PLR_AI_FUNC(first_activities, pplayer, pplayer);
1147 }
1150}
1151
1152/**********************************************************************/
1157static void begin_turn(bool is_new_turn)
1158{
1159 log_debug("Begin turn");
1160
1162
1163 /* Reset this each turn. */
1164 if (is_new_turn) {
1168 }
1169 }
1170
1171 /* NB: Phase logic must match is_player_phase(). */
1172 switch (game.info.phase_mode) {
1173 case PMT_CONCURRENT:
1175 break;
1178 break;
1181 break;
1182 default:
1183 log_error("Unrecognized phase mode %d in begin_turn().",
1186 break;
1187 }
1188 send_game_info(nullptr);
1189
1190 if (is_new_turn) {
1191 script_server_signal_emit("turn_begin",
1194 script_server_signal_emit("turn_started",
1195 game.info.turn > 0
1196 ? (lua_Integer)game.info.turn - 1
1199
1200 /* We build scores at the beginning of every turn. We have to
1201 * build them at the beginning so that the AI can use the data,
1202 * and we are sure to have it when we need it. */
1203 players_iterate(pplayer) {
1204 calc_civ_score(pplayer);
1207
1208 /* Retire useless barbarian units */
1209 players_iterate(pplayer) {
1210 unit_list_iterate_safe(pplayer->units, punit) {
1211 struct tile *ptile = punit->tile;
1212
1215 notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server,
1216 /* TRANS: %s is a unit type */
1217 _("%s retired!"), unit_tile_link(punit));
1218 wipe_unit(punit, ULR_RETIRED, nullptr);
1219 continue;
1220 }
1223 }
1224
1225 /* Find out if users attached to players have been attached to those players
1226 * for long enough. The first user to do so becomes "associated" to that
1227 * player for ranking purposes. */
1228 players_iterate(pplayer) {
1229 if (pplayer->unassigned_ranked
1230 && pplayer->user_turns++ > TURNS_NEEDED_TO_RANK
1231 && pplayer->is_alive) {
1232 sz_strlcpy(pplayer->ranked_username, pplayer->username);
1233 pplayer->unassigned_ranked = pplayer->unassigned_user;
1234 }
1236
1237 if (is_new_turn) {
1238 /* See if the value of fog of war has changed */
1240 if (game.info.fogofwar) {
1243 } else {
1246 }
1247 }
1248
1250 log_debug("Shuffleplayers");
1252 }
1253
1254 game.info.phase = 0;
1255 }
1256
1257 sanity_check();
1258}
1259
1260/**********************************************************************/
1264static void begin_phase(bool is_new_phase)
1265{
1266 log_debug("Begin phase");
1267
1269
1270 phase_players_iterate(pplayer) {
1272 /* Otherwise respect what was loaded from the savegame. */
1273 pplayer->phase_done = FALSE;
1274 }
1275 pplayer->ai_phase_done = FALSE;
1277 send_player_all_c(nullptr, nullptr);
1278
1280
1281 if (!is_new_phase || game.info.turn == FIRST_TURN) {
1282 /* Starting from a savegame or from the very beginning */
1286 }
1287
1288 /* Must be the first thing as it is needed for lots of functions below! */
1289 phase_players_iterate(pplayer) {
1290 /* Human players also need this for building advice */
1292 CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, is_new_phase);
1294
1295 if (is_new_phase) {
1296 /* Unit "end of turn" activities - of course these actually go at
1297 * the start of the turn! */
1298 whole_map_iterate(&(wld.map), ptile) {
1299 if (ptile->placing != nullptr) {
1300 struct player *owner = nullptr;
1301
1303 owner = tile_owner(ptile);
1304 } else {
1305 struct city *pcity = tile_worked(ptile);
1306
1307 if (pcity != nullptr) {
1309 }
1310 }
1311
1312 if (owner == nullptr) {
1313 /* Abandoned extra placing, clear it. */
1314 ptile->placing = nullptr;
1315 } else {
1317 fc_assert(ptile->infra_turns > 0);
1318
1319 ptile->infra_turns--;
1320 if (ptile->infra_turns <= 0) {
1321 create_extra(ptile, ptile->placing, owner);
1322 ptile->placing = nullptr;
1323
1324 /* Since extra has been added, tile is certainly
1325 * sent by update_tile_knowledge() including the
1326 * placing info, though it would not sent it if placing
1327 * were the only thing changed. */
1328 update_tile_knowledge(ptile);
1329 }
1330 }
1331 }
1332 }
1334
1335 phase_players_iterate(pplayer) {
1336 update_unit_activities(pplayer);
1337 flush_packets();
1339
1340 /* Execute orders after activities have been completed (roads built,
1341 * pillage done, etc.). */
1342 phase_players_iterate(pplayer) {
1343 int plrid = player_number(pplayer);
1344
1345 script_server_signal_emit("player_phase_begin", pplayer, is_new_phase);
1346 if (player_by_number(plrid) != pplayer) {
1347 /* Removed */
1348 continue;
1349 }
1350 flush_packets();
1352
1353 phase_players_iterate(pplayer) {
1354 city_tc_effect_refresh(pplayer);
1355 unit_tc_effect_refresh(pplayer);
1357
1358 phase_players_iterate(pplayer) {
1361
1362 flush_packets();
1363 }
1364
1365 phase_players_iterate(pplayer) {
1366 log_debug("beginning player turn for #%d (%s)",
1367 player_number(pplayer), player_name(pplayer));
1368 if (is_human(pplayer)) {
1369 building_advisor(pplayer);
1370 }
1372
1373 phase_players_iterate(pplayer) {
1374 send_player_cities(pplayer);
1376
1377 flush_packets(); /* To curb major city spam */
1379
1381 update_revolution(pplayer);
1382 update_capital(pplayer);
1383 access_areas_refresh(&(wld.map), pplayer);
1385
1386 if (is_new_phase) {
1387 /* Try to avoid hiding events under a diplomacy dialog */
1388 phase_players_iterate(pplayer) {
1389 if (is_ai(pplayer)) {
1390 CALL_PLR_AI_FUNC(diplomacy_actions, pplayer, pplayer);
1391 }
1393
1394 /* Spend random movement move points before any controlled actions */
1395 phase_players_iterate(pplayer) {
1396 random_movements(pplayer);
1398
1399 log_debug("Aistartturn");
1401
1402 flush_packets();
1403 phase_players_iterate(pplayer) {
1404 unit_list_iterate_safe(pplayer->units, punit) {
1407 }
1409 execute_unit_orders(pplayer);
1410 flush_packets();
1412 } else {
1413 phase_players_iterate(pplayer) {
1414 if (is_ai(pplayer)) {
1415 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
1416 }
1418 }
1419
1420 sanity_check();
1421
1426 game.server.phase_timer != nullptr
1427 ? nullptr : "phase");
1429 send_game_info(nullptr);
1430
1431 if (game.server.num_phases == 1) {
1432 /* All players in the same phase.
1433 * This means that AI has been handled above, and server
1434 * will be responsive again */
1436 }
1437}
1438
1439/**********************************************************************/
1443static void end_phase(void)
1444{
1445 log_debug("Endphase");
1446
1447 /*
1448 * This empties the client Messages window; put this before
1449 * everything else below, since otherwise any messages from the
1450 * following parts get wiped out before the user gets a chance to
1451 * see them. --dwp
1452 */
1453 phase_players_iterate(pplayer) {
1454 /* Unlike the start_phase packet we only send this one to the active
1455 * player. */
1456 lsend_packet_end_phase(pplayer->connections);
1458
1459 /* Enact any government and/or policy changes.
1460 * Do this first so that following end-phase activities take the
1461 * change into account. */
1462 phase_players_iterate(pplayer) {
1463 if (pplayer->revolution_finishes <= game.info.turn
1464 && pplayer->target_government != nullptr
1465 && pplayer->target_government != game.government_during_revolution
1466 && pplayer->target_government != pplayer->government) {
1467 government_change(pplayer, pplayer->target_government, TRUE);
1468 }
1469
1470 multipliers_iterate(pmul) {
1471 int idx = multiplier_index(pmul);
1472
1473 if (!multiplier_can_be_changed(pmul, pplayer)) {
1474 if (pplayer->multipliers[idx].value != pmul->def) {
1475 notify_player(pplayer, nullptr, E_MULTIPLIER, ftc_server,
1476 _("%s restored to the default value %d"),
1478 pmul->def);
1479 pplayer->multipliers[idx].value = pmul->def;
1480 pplayer->multipliers[idx].changed = game.info.turn;
1481 }
1482 } else {
1483 if (pplayer->multipliers[idx].value != pplayer->multipliers[idx].target) {
1484 notify_player(pplayer, nullptr, E_MULTIPLIER, ftc_server,
1485 _("%s now at value %d"),
1487 pplayer->multipliers[idx].target);
1488
1489 pplayer->multipliers[idx].value = pplayer->multipliers[idx].target;
1490 pplayer->multipliers[idx].changed = game.info.turn;
1491 }
1492 }
1495
1496 phase_players_iterate(pplayer) {
1497 struct research *presearch = research_get(pplayer);
1498
1499 if (A_UNSET == presearch->researching) {
1501 presearch->tech_goal);
1502
1503 if (A_UNSET != next_tech) {
1505 } else {
1507 }
1508 /* Add the researched bulbs to the pool; do *NOT* check for finished
1509 * research */
1510 update_bulbs(pplayer, 0, FALSE, FALSE);
1511 }
1513
1514 /* Freeze sending of cities. */
1516
1517 /* AI end of turn activities */
1518 players_iterate(pplayer) {
1519 unit_list_iterate(pplayer->units, punit) {
1520 CALL_PLR_AI_FUNC(unit_turn_end, pplayer, punit);
1523 phase_players_iterate(pplayer) {
1524 auto_workers_player(pplayer);
1525 if (is_ai(pplayer)) {
1526 CALL_PLR_AI_FUNC(last_activities, pplayer, pplayer);
1527 }
1529
1530 /* Refresh cities */
1531 phase_players_iterate(pplayer) {
1532 research_get(pplayer)->free_bulbs = 0;
1534
1536 int plrid = player_number(pplayer);
1537 int old_gold;
1538
1539 do_tech_parasite_effects(pplayer);
1540 script_server_signal_emit("player_alive_phase_end", pplayer);
1541 if (player_by_number(plrid) != pplayer) {
1542 /* Removed */
1543 continue;
1544 }
1545 if (!pplayer->is_alive) {
1546 /* Died */
1547 continue;
1548 }
1549 player_restore_units(pplayer);
1550
1551 /* If player finished spaceship parts last turn already, and didn't place them
1552 * during this entire turn, autoplace them. */
1553 if (adv_spaceship_autoplace(pplayer, &pplayer->spaceship)) {
1554 notify_player(pplayer, nullptr, E_SPACESHIP, ftc_server,
1555 _("Automatically placed spaceship parts that were still not placed."));
1556 }
1557
1558 old_gold = pplayer->economic.gold;
1559 pplayer->server.bulbs_last_turn = 0;
1560
1561 update_city_activities(pplayer);
1562
1564
1567
1568 flush_packets();
1570
1571 /* Some player/global effect may have changed cities' vision range */
1572 phase_players_iterate(pplayer) {
1575
1577
1578 /* Unfreeze sending of cities. */
1580
1581 phase_players_iterate(pplayer) {
1582 send_player_cities(pplayer);
1584 flush_packets(); /* To curb major city spam */
1585
1589
1590 phase_players_iterate(pplayer) {
1591 int plrid = player_number(pplayer);
1592
1593 script_server_signal_emit("player_phase_end", pplayer);
1594 if (player_by_number(plrid) != pplayer) {
1595 /* Removed */
1596 continue;
1597 }
1598 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1599 /* This has to be after all access to advisor data. */
1600 /* We used to run this for ai players only, but data phase
1601 is initialized for human players also. */
1602 adv_data_phase_done(pplayer);
1604}
1605
1606/**********************************************************************/
1609static void end_turn(void)
1610{
1611 log_debug("Endturn");
1612
1613 /* Hack: Because observer players never get an end-phase packet we send
1614 * one here. */
1616 if (pconn->playing == nullptr) {
1618 }
1620
1622
1624
1625 /* Update city's counter values */
1626 players_iterate(pplayer) {
1627 city_list_iterate(pplayer->cities, pcity) {
1629 if (pcount->type == CB_CITY_OWNED_TURNS) {
1630 pcity->counter_values[pcount->index]++;
1631 }
1636
1637#ifdef FREECIV_DEBUG
1638 /* Output some AI measurement information
1639 * log_debug() means that the values would never be used outside FREECIV_DEBUG
1640 * build even if we calculated them. */
1641 players_iterate(pplayer) {
1642 int food = 0, shields = 0, trade = 0, settlers = 0;
1643
1644 if (!is_ai(pplayer) || is_barbarian(pplayer)) {
1645 continue;
1646 }
1647
1648 unit_list_iterate(pplayer->units, punit) {
1650 settlers++;
1651 }
1653
1654 city_list_iterate(pplayer->cities, pcity) {
1655 shields += pcity->prod[O_SHIELD];
1656 food += pcity->prod[O_FOOD];
1657 trade += pcity->prod[O_TRADE];
1659
1660 log_debug("%s T%d cities:%d pop:%d food:%d prod:%d "
1661 "trade:%d settlers:%d units:%d", player_name(pplayer),
1662 game.info.turn, city_list_size(pplayer->cities),
1663 total_player_citizens(pplayer), food, shields, trade,
1664 settlers, unit_list_size(pplayer->units));
1665
1667#endif /* FREECIV_DEBUG */
1668
1669 log_debug("Season of native unrests");
1670 summon_barbarians(); /* Wild guess really, no idea where to put it, but
1671 * I want to give them chance to move their units */
1672
1673 if (game.server.migration) {
1674 log_debug("Season of migrations");
1675 if (check_city_migrations()) {
1676 /* Make sure everyone has updated information about BOTH ends of the
1677 * migration movements. */
1678 players_iterate(plr) {
1679 city_list_iterate(plr->cities, pcity) {
1680 send_city_info(nullptr, pcity);
1683 }
1684 }
1685
1687
1688 /* Check for new achievements during the turn.
1689 * This is not within phase, as multiple players may
1690 * achieve at the same turn and everyone deserves equal opportunity
1691 * to win. */
1693 struct player_list *achievers = player_list_new();
1694 struct player *first = achievement_plr(ach, achievers);
1696
1697 pack.id = achievement_index(ach);
1698 pack.gained = TRUE;
1699
1700 if (first != nullptr) {
1702 "%s", achievement_first_msg(ach));
1703
1704 pack.first = TRUE;
1705
1707
1708 script_server_signal_emit("achievement_gained", ach, first, TRUE);
1709
1710 }
1711
1712 pack.first = FALSE;
1713
1714 if (!ach->unique) {
1715 player_list_iterate(achievers, pplayer) {
1716 /* Message already sent to first one */
1717 if (pplayer != first) {
1718 notify_player(pplayer, nullptr, E_ACHIEVEMENT, ftc_server,
1719 "%s", achievement_later_msg(ach));
1720
1721 lsend_packet_achievement_info(pplayer->connections, &pack);
1722
1723 script_server_signal_emit("achievement_gained", ach, pplayer,
1724 FALSE);
1725 }
1727 }
1728
1729 player_list_destroy(achievers);
1731
1732 if (game.info.global_warming) {
1738 }
1739
1740 if (game.info.nuclear_winter) {
1746 }
1747
1748 /* Handle disappearing extras before appearing extras ->
1749 * Extra never appears only to disappear at the same turn,
1750 * but it can disappear and reappear. */
1752 whole_map_iterate(&(wld.map), ptile) {
1753 if (tile_has_extra(ptile, pextra)
1754 && fc_rand(10000) < pextra->disappearance_chance
1755 && can_extra_disappear(pextra, ptile)) {
1756 struct player *owner = tile_owner(ptile);
1757
1758 tile_extra_rm_apply(ptile, pextra);
1759
1760 script_server_signal_emit("spontaneous_extra",
1761 extra_rule_name(pextra),
1762 ptile, FALSE);
1763
1764 update_tile_knowledge(ptile);
1765
1766 if (owner == nullptr) {
1767 owner = extra_owner(ptile);
1768
1769 if (owner == nullptr && game.info.borders == BORDERS_DISABLED) {
1770 /* In case of disabled borders, consider owner of the closest
1771 * city, if within 7 tiles, owner of the tile. */
1772 iterate_outward(&(wld.map), ptile, 7, ctile) {
1773 struct city *pcity = tile_city(ctile);
1774
1775 if (pcity != nullptr) {
1777 break;
1778 }
1780 }
1781 }
1782
1783 if (owner != nullptr && tile_is_seen(ptile, owner)) {
1784 notify_player(owner, ptile,
1786 /* TRANS: Small Fish disappears from (32, 72). */
1787 _("%s disappears from %s."),
1788 extra_name_translation(pextra),
1789 tile_link(ptile));
1790 }
1791
1792 /* Activities at the target tile and its neighbors may now
1793 * be illegal because of present reqs. */
1795 }
1798
1800 whole_map_iterate(&(wld.map), ptile) {
1801 if (!tile_has_extra(ptile, pextra)
1802 && fc_rand(10000) < pextra->appearance_chance
1803 && can_extra_appear(pextra, ptile)) {
1804 struct player *owner = tile_owner(ptile);
1805
1806 tile_extra_apply(ptile, pextra);
1807
1808 script_server_signal_emit("spontaneous_extra",
1809 extra_rule_name(pextra),
1810 ptile, TRUE);
1811
1812 update_tile_knowledge(ptile);
1813
1814 if (owner == nullptr) {
1815 owner = extra_owner(ptile);
1816
1817 if (owner == nullptr && game.info.borders == BORDERS_DISABLED) {
1818 /* In case of disabled borders, consider owner of the closest
1819 * city, if within 7 tiles, owner of the tile. */
1820 iterate_outward(&(wld.map), ptile, 7, ctile) {
1821 struct city *pcity = tile_city(ctile);
1822
1823 if (pcity != nullptr) {
1825 break;
1826 }
1828 }
1829 }
1830
1831 if (owner != nullptr && tile_is_seen(ptile, owner)) {
1832 notify_player(owner, ptile,
1834 /* TRANS: Small Fish appears to (32, 72). */
1835 _("%s appears to %s."),
1836 extra_name_translation(pextra),
1837 tile_link(ptile));
1838 }
1839
1840 /* Activities at the target tile and its neighbors may now
1841 * be illegal because of !present reqs. */
1843 }
1846
1848
1851 voting_turn();
1853
1854 log_debug("Gamenextyear");
1856 players_iterate_alive(pplayer) {
1857 pplayer->turns_alive++;
1858
1859 /* sell off obsolete buildings after everything has
1860 * happened that could affect obsolete_by requirements */
1863
1864 log_debug("Updatetimeout");
1866
1867 log_debug("Sendgameinfo");
1868 send_game_info(nullptr);
1869
1870 log_debug("Sendplayerinfo");
1871 send_player_all_c(nullptr, nullptr);
1872
1873 log_debug("Sendresearchinfo");
1875 send_research_info(presearch, nullptr);
1877
1878 log_debug("Sendyeartoclients");
1880}
1881
1882/**********************************************************************/
1885void save_game_auto(const char *save_reason, enum autosave_type type)
1886{
1887 char filename[512];
1888 const char *reason_filename = nullptr;
1889
1890 if (!(game.server.autosaves & (1 << type))) {
1891 return;
1892 }
1893
1894 switch (type) {
1895 case AS_TURN:
1896 reason_filename = nullptr;
1897 break;
1898 case AS_GAME_OVER:
1899 reason_filename = "final";
1900 break;
1901 case AS_QUITIDLE:
1902 reason_filename = "quitidle";
1903 break;
1904 case AS_INTERRUPT:
1905 reason_filename = "interrupted";
1906 break;
1907 case AS_TIMER:
1908 reason_filename = "timer";
1909 break;
1910 }
1911
1913
1914 if (type != AS_TIMER) {
1915 generate_save_name(game.server.save_name, filename, sizeof(filename),
1917 } else {
1918 fc_snprintf(filename, sizeof(filename), "%s-timer", game.server.save_name);
1919 }
1920 save_game(filename, save_reason, FALSE);
1921}
1922
1923/**********************************************************************/
1926void start_game(void)
1927{
1928 if (S_S_INITIAL != server_state()) {
1929 con_puts(C_SYNTAX, _("The game is already running."));
1930 return;
1931 }
1932
1933 /* Remove ALLOW_CTRL from whoever has it (gotten from 'first'). */
1935 if (pconn->access_level == ALLOW_CTRL) {
1936 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
1937 _("%s lost control cmdlevel on "
1938 "game start. Use voting from now on."),
1939 pconn->username);
1941 }
1944
1945 con_puts(C_OK, _("Starting game."));
1946
1947 /* Prevent problems with commands that only make sense in pregame. */
1949
1950 /* This value defines if the player data should be saved for a scenario.
1951 * It is only FALSE if the editor was used to set it to this value.
1952 * For such scenarios it has to be reset at game start so that player data
1953 * is saved. */
1955
1957 /* There's no stateful packet set to client until srv_ready(). */
1958}
1959
1960/**********************************************************************/
1964{
1965 if (server_state() == S_S_RUNNING) {
1966 /* Quitting mid-game. */
1967
1968 phase_players_iterate(pplayer) {
1969 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1970 /* This has to be after all access to advisor data. */
1971 /* We used to run this for ai players only, but data phase
1972 is initialized for human players also. */
1973 adv_data_phase_done(pplayer);
1975 }
1976
1978
1979 if (game.server.save_timer != nullptr) {
1981 game.server.save_timer = nullptr;
1982 }
1983 if (between_turns != nullptr) {
1985 between_turns = nullptr;
1986 }
1987 if (eot_timer != nullptr) {
1989 }
1991 mapimg_free();
1993 voting_free();
1995 ai_timer_free();
1996 if (game.server.phase_timer != nullptr) {
1998 game.server.phase_timer = nullptr;
1999 }
2000 if (game.server.save_timer != nullptr) {
2002 game.server.save_timer = nullptr;
2003 }
2004
2005#ifdef HAVE_FCDB
2006 if (srvarg.fcdb_enabled) {
2007 /* If freeciv database has been initialized */
2008 fcdb_free();
2009 }
2010#endif /* HAVE_FCDB */
2011
2012 modpacks_free();
2013 settings_free();
2015 edithand_free();
2016 voting_free();
2020 CALL_FUNC_EACH_AI(module_close);
2025 con_log_close();
2029
2031}
2032
2033/**********************************************************************/
2037{
2038 struct conn_list *dest = pconn->self;
2039
2040 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2041 log_error("Got a report request %d before game start", type);
2042 return;
2043 }
2044
2045 if (pconn->playing == nullptr && !pconn->observer) {
2046 log_error("Got a report request %d from detached connection", type);
2047 return;
2048 }
2049
2050 switch (type) {
2053 return;
2056 return;
2057 case REPORT_TOP_CITIES:
2058 report_top_cities(dest);
2059 return;
2060 case REPORT_DEMOGRAPHIC:
2062 return;
2065 return;
2066 }
2067
2068 notify_conn(dest, nullptr, E_BAD_COMMAND, ftc_server,
2069 _("request for unknown report (type %d)"), type);
2070}
2071
2072/**********************************************************************/
2076{
2078}
2079
2080/**********************************************************************/
2084{
2086}
2087
2088/**********************************************************************/
2091static bool identity_number_is_used(int id)
2092{
2093 return BV_ISSET(identity_numbers_used, id);
2094}
2095
2096/**********************************************************************/
2100{
2101 server.identity_number = (server.identity_number + 1) % IDENTITY_NUMBER_SIZE;
2102 return server.identity_number;
2103}
2104
2105/**********************************************************************/
2110{
2111 int retries = 0;
2112
2114 /* Try again */
2115 if (++retries >= IDENTITY_NUMBER_SIZE) {
2116 /* Always fails. */
2118 "Exhausted city and unit numbers!");
2119 }
2120 }
2121 identity_number_reserve(server.identity_number);
2122 return server.identity_number;
2123}
2124
2125/**********************************************************************/
2132{
2134}
2135
2136/**********************************************************************/
2140bool server_packet_input(struct connection *pconn, void *packet, int type)
2141{
2142 struct player *pplayer;
2143
2144 /* A nullptr packet can be returned from receive_packet_goto_route() */
2145 if (!packet) {
2146 return TRUE;
2147 }
2148
2149 /*
2150 * Old pre-delta clients (before 2003-11-28) send a
2151 * PACKET_LOGIN_REQUEST (type 0) to the server. We catch this and
2152 * reply with an old reject packet. Since there is no struct for
2153 * this old packet anymore we build it by hand.
2154 */
2155 if (type == 0) {
2156 unsigned char buffer[4096];
2157 struct raw_data_out d_out;
2158
2159 log_normal(_("Warning: rejecting old client %s"),
2161
2162 dio_output_init(&d_out, buffer, sizeof(buffer));
2164
2165 /* 1 == PACKET_LOGIN_REPLY in the old client */
2167
2170 _("Your client is too old. To use this server, "
2171 "please upgrade your client to a "
2172 "Freeciv 2.2 or later."));
2174
2175 {
2176 size_t size = dio_output_used(&d_out);
2179
2180 /*
2181 * Use send_connection_data instead of send_packet_data to avoid
2182 * compression.
2183 */
2185 }
2186
2187 return FALSE;
2188 }
2189
2192 (struct packet_server_join_req *) packet);
2193 }
2194
2195 /* May be received on a non-established connection. */
2197 return auth_handle_reply(pconn,
2198 ((struct packet_authentication_reply *)
2199 packet)->password);
2200 }
2201
2202 if (type == PACKET_CONN_PONG) {
2204 return TRUE;
2205 }
2206
2207 if (!pconn->established) {
2208 log_error("Received game packet %s(%d) from unaccepted connection %s.",
2210 return TRUE;
2211 }
2212
2213 /* Valid packets from established connections but non-players */
2224
2225 /* Except for PACKET_EDIT_MODE (used to set edit mode), check
2226 * that the client is allowed to send the given edit packet. */
2228 && !can_conn_edit(pconn)) {
2229 notify_conn(pconn->self, nullptr, E_BAD_COMMAND, ftc_editor,
2230 _("You are not allowed to edit."));
2231 return TRUE;
2232 }
2233
2234 if (!server_handle_packet(type, packet, nullptr, pconn)) {
2235 log_error("Received unknown packet %d from %s.",
2237 }
2238 return TRUE;
2239 }
2240
2241 pplayer = pconn->playing;
2242
2243 if (pplayer == nullptr || pconn->observer) {
2244 if (type == PACKET_PLAYER_READY && pconn->observer) {
2246
2247 return TRUE;
2248 }
2249 /* Don't support these yet */
2250 log_error("Received packet %s(%d) from non-player connection %s.",
2252 return TRUE;
2253 }
2254
2255 if (S_S_RUNNING != server_state()
2260 if (S_S_OVER == server_state()) {
2261 /* This can happen by accident, so we don't want to print
2262 * out lots of error messages. Ie, we use log_debug(). */
2263 log_debug("Got a packet of type %s(%d) in %s.",
2265 } else {
2266 log_error("Got a packet of type %s(%d) outside %s.",
2268 }
2269 return TRUE;
2270 }
2271
2272 pplayer->nturns_idle = 0;
2273
2274 if (!pplayer->is_alive && type != PACKET_REPORT_REQ) {
2275 log_error("Got a packet of type %s(%d) from a dead player.",
2277 return TRUE;
2278 }
2279
2280 /* Make sure to set this back to nullptr before leaving this function: */
2281 pplayer->current_conn = pconn;
2282
2283 if (!server_handle_packet(type, packet, pplayer, pconn)) {
2284 log_error("Received unknown packet %d from %s.",
2286 }
2287
2288 if (S_S_RUNNING == server_state()
2289 && type != PACKET_PLAYER_READY) {
2290 /* handle_player_ready() calls start_game(), but the game isn't started
2291 * until the main loop is re-entered, so kill_dying_players() would think
2292 * all players are dead. This should be solved by adding a new
2293 * game state (now S_S_GENERATING_WAITING). */
2295 }
2296
2297 pplayer->current_conn = nullptr;
2298
2299 return TRUE;
2300}
2301
2302/**********************************************************************/
2307{
2308 bool connected = FALSE;
2309
2310 if (S_S_RUNNING != server_state()) {
2311 /* Not in a running state, no turn done. */
2312 return;
2313 }
2314
2315 /* Fixedlength is only applicable if we have a timeout set */
2317 return;
2318 }
2319
2320 /* If there are no connected players, don't automatically advance. This is
2321 * a hack to prevent all-AI games from running rampant. Note that if
2322 * timeout is set to -1 this function call is skipped entirely and the
2323 * server will run rampant. */
2324 players_iterate_alive(pplayer) {
2325 if (pplayer->is_connected && (is_human(pplayer) || pplayer->phase_done)) {
2326 connected = TRUE;
2327 break;
2328 }
2330
2331 if (!connected) {
2332 return;
2333 }
2334
2335 phase_players_iterate(pplayer) {
2336 if (!pplayer->phase_done && pplayer->is_alive) {
2337 if (pplayer->is_connected) {
2338 /* In all cases, we wait for any connected players. */
2339 return;
2340 }
2341 if (game.server.turnblock && is_human(pplayer)) {
2342 /* If turnblock is enabled check for human players, connected
2343 * or not. */
2344 return;
2345 }
2346 if (is_ai(pplayer) && !pplayer->ai_phase_done) {
2347 /* AI player has not finished */
2348 return;
2349 }
2350 }
2352
2354}
2355
2356/**********************************************************************/
2362{
2363 if (!game_was_started() && 0 < map_startpos_count()) {
2364 /* Restrict nations to those for which start positions are defined. */
2365 nations_iterate(pnation) {
2366 fc_assert_action_msg(pnation->player == nullptr,
2367 if (pnation->player->nation == pnation) {
2368 /* At least assignment is consistent. Leave nation assigned,
2369 * and make sure that nation is also marked pickable. */
2370 pnation->server.no_startpos = FALSE;
2371 continue;
2372 } else if (pnation->player->nation != nullptr) {
2373 /* Not consistent. Just initialize the pointer and hope for the
2374 * best. */
2375 pnation->player->nation->player = nullptr;
2376 pnation->player = nullptr;
2377 } else {
2378 /* Not consistent. Just initialize the pointer and hope for the
2379 * best. */
2380 pnation->player = nullptr;
2381 }, "Player assigned to nation before %s()!", __FUNCTION__);
2382
2383 if (nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
2384 /* Always allow land and sea barbarians regardless of start
2385 * positions. */
2386 pnation->server.no_startpos = FALSE;
2387 } else {
2388 /* Restrict the set of nations offered to players, based on
2389 * start positions.
2390 * If there are no start positions for a nation, remove it from the
2391 * available set. */
2392 pnation->server.no_startpos = TRUE;
2394 if (startpos_nation_allowed(psp, pnation)) {
2395 /* There is at least one start position that allows this nation,
2396 * so allow it to be picked.
2397 * (Depending on what nations players actually pick, it's not
2398 * guaranteed that the server can always find a match between
2399 * nations in this subset and start positions, in which case the
2400 * server may create mismatches.) */
2401 pnation->server.no_startpos = FALSE;
2402 break;
2403 }
2405 }
2407 } else {
2408 /* Not restricting nations by start positions. */
2409 nations_iterate(pnation) {
2410 pnation->server.no_startpos = FALSE;
2412 }
2413}
2414
2415/**********************************************************************/
2420void handle_nation_select_req(struct connection *pc, int player_no,
2421 Nation_type_id nation_no, bool is_male,
2422 const char *name, int style)
2423{
2424 struct nation_type *new_nation;
2425 struct player *pplayer = player_by_number(player_no);
2426
2427 if (!pplayer || !can_conn_edit_players_nation(pc, pplayer)) {
2428 return;
2429 }
2430
2431 new_nation = nation_by_number(nation_no);
2432
2434 char message[1024];
2435
2436 /* Check sanity of the packet sent by client */
2438 return;
2439 }
2440
2442 notify_player(pplayer, nullptr, E_NATION_SELECTED, ftc_server,
2443 _("%s nation is not available for user selection."),
2445 return;
2446 }
2447 if (new_nation->player && new_nation->player != pplayer) {
2448 notify_player(pplayer, nullptr, E_NATION_SELECTED, ftc_server,
2449 _("%s nation is already in use."),
2451 return;
2452 }
2453
2455 message, sizeof(message))) {
2456 notify_player(pplayer, nullptr, E_NATION_SELECTED,
2457 ftc_server, "%s", message);
2458 return;
2459 }
2460
2461 /* Should be caught by is_nation_pickable() */
2463
2464 notify_conn(nullptr, nullptr, E_NATION_SELECTED, ftc_server,
2465 _("%s is the %s ruler %s."),
2466 pplayer->username,
2468 player_name(pplayer));
2469
2470 pplayer->is_male = is_male;
2471 pplayer->style = style_by_number(style);
2472 } else if (name[0] == '\0') {
2473 char message[1024];
2474
2476 message, sizeof(message));
2477 }
2478
2479 (void) player_set_nation(pplayer, new_nation);
2481}
2482
2483/**********************************************************************/
2487{
2488 if (pconn->access_level == ALLOW_HACK) {
2489 players_iterate(plr) {
2490 if (is_human(plr)) {
2491 return;
2492 }
2494
2495 start_command(nullptr, FALSE, TRUE);
2496 }
2497}
2498
2499/**********************************************************************/
2503 int player_no,
2504 bool is_ready)
2505{
2506 struct player *pplayer = player_by_number(player_no);
2507
2508 if (pplayer == nullptr || S_S_INITIAL != server_state()) {
2509 return;
2510 }
2511
2512 if (pplayer != requestor) {
2513 /* Currently you can only change your own readiness. */
2514 return;
2515 }
2516
2517 pplayer->is_ready = is_ready;
2518 send_player_info_c(pplayer, nullptr);
2519
2520 /* Note this is called even if the player has pressed /start once
2521 * before. For instance, when a player leaves everyone remaining
2522 * might have pressed /start already but the start won't happen
2523 * until someone presses it again. Also you can press start more
2524 * than once to remind other people to start (which is a good thing
2525 * until somebody does it too much and it gets labeled as spam). */
2526 if (is_ready) {
2527 int num_ready = 0, num_unready = 0;
2528
2529 players_iterate_alive(other_player) {
2530 if (other_player->is_connected) {
2531 if (other_player->is_ready) {
2532 num_ready++;
2533 } else {
2534 num_unready++;
2535 }
2536 }
2538
2539 if (num_unready > 0) {
2540 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
2541 _("Waiting to start game: %d out of %d alive players "
2542 "are ready to start."),
2544 } else {
2545 /* Check minplayers etc. and then start */
2546 start_command(nullptr, FALSE, TRUE);
2547 }
2548 }
2549}
2550
2551/**********************************************************************/
2556const char *aifill(int amount)
2557{
2558 char *limitreason = nullptr;
2559 int limit;
2560
2561 if (game_was_started()) {
2562 return nullptr;
2563 }
2564
2566 if (limit < amount) {
2567 limitreason = _("requested more than 'maxplayers' setting");
2568 }
2569
2570 /* Limit to nations provided by ruleset */
2571 if (limit > server.playable_nations) {
2572 limit = server.playable_nations;
2573 if (nation_set_count() > 1) {
2574 limitreason = _("not enough playable nations in this nation set "
2575 "(see 'nationset' setting)");
2576 } else {
2577 limitreason = _("not enough playable nations");
2578 }
2579 }
2580
2581 if (limit < player_count()) {
2582 int removal = player_slot_count() - 1;
2583
2584 while (limit < player_count() && 0 <= removal) {
2585 struct player *pplayer = player_by_number(removal);
2586
2587 removal--;
2588 if (!pplayer) {
2589 continue;
2590 }
2591
2592 if (!pplayer->is_connected && !pplayer->was_created) {
2593 server_remove_player(pplayer);
2594 }
2595 }
2596
2597 /* 'limit' can be different from 'player_count()' at this point if
2598 * there are more human or created players than the 'limit'. */
2599 return limitreason;
2600 }
2601
2602 while (limit > player_count()) {
2604 int filled = 1;
2605 struct player *pplayer;
2606
2608 nullptr, FALSE);
2609 /* !game_was_started() so no need to assign_player_colors() */
2610 if (!pplayer) {
2611 break;
2612 }
2613 server_player_init(pplayer, FALSE, TRUE);
2614
2615 player_set_nation(pplayer, nullptr);
2616
2617 do {
2618 fc_snprintf(leader_name, sizeof(leader_name), "AI*%d", filled++);
2619 } while (player_by_name(leader_name));
2620
2622 pplayer->random_name = TRUE;
2623 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
2624 pplayer->unassigned_user = TRUE;
2625
2627 set_as_ai(pplayer);
2629
2630 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
2631
2632 log_normal(_("%s has been added as %s level AI-controlled player (%s)."),
2633 player_name(pplayer),
2635 ai_name(pplayer->ai));
2636 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
2637 _("%s has been added as %s level AI-controlled player (%s)."),
2638 player_name(pplayer),
2640 ai_name(pplayer->ai));
2641
2642 send_player_info_c(pplayer, nullptr);
2643 }
2644
2645 return limitreason;
2646}
2647
2648/**********************************************************************/
2651#define SPECHASH_TAG startpos
2652#define SPECHASH_IKEY_TYPE struct startpos *
2653#define SPECHASH_INT_DATA_TYPE
2654#include "spechash.h"
2655#define startpos_hash_iterate(hash, psp, c) \
2656 TYPED_HASH_ITERATE(struct startpos *, intptr_t, hash, psp, c)
2657#define startpos_hash_iterate_end HASH_ITERATE_END
2658
2659/**********************************************************************/
2662static void player_set_nation_full(struct player *pplayer,
2663 struct nation_type *pnation)
2664{
2665 /* Don't change the name of a created player. */
2666 player_nation_defaults(pplayer, pnation, pplayer->random_name);
2667}
2668
2669/**********************************************************************/
2672void player_nation_defaults(struct player *pplayer, struct nation_type *pnation,
2673 bool set_name)
2674{
2675 struct nation_leader *pleader;
2676
2677 fc_assert(NO_NATION_SELECTED != pnation);
2678 player_set_nation(pplayer, pnation);
2679 fc_assert(pnation == pplayer->nation);
2680
2681 pplayer->style = style_of_nation(pnation);
2682
2683 if (set_name) {
2685 }
2686
2687 if ((pleader = nation_leader_by_name(pnation, player_name(pplayer)))) {
2689 } else {
2690 pplayer->is_male = (fc_rand(2) == 1);
2691 }
2692
2693 ai_traits_init(pplayer);
2694}
2695
2696/**********************************************************************/
2723static void generate_players(void)
2724{
2725 int nations_to_assign = 0;
2726
2727 /* Announce players who already have nations, and select nations based
2728 * on player names. */
2729 players_iterate(pplayer) {
2730 if (pplayer->nation != NO_NATION_SELECTED) {
2731 /* Traits are initialized here, and not already when nation gets
2732 * picked, as player may change their mind after picking one nation,
2733 * and picks another and we want to init traits only once, for the
2734 * correct nation. */
2735 ai_traits_init(pplayer);
2736 announce_player(pplayer);
2737 continue;
2738 }
2739
2740 /* See if the player name matches a known leader name.
2741 * If more than one nation has this leader name, pick one at random.
2742 * No attempt is made to avoid clashes to maximise the number of
2743 * nations that can be assigned in this way. */
2744 {
2746 int n = 0;
2747
2748 allowed_nations_iterate(pnation) {
2749 if (is_nation_playable(pnation)
2750 && client_can_pick_nation(pnation)
2751 && pnation->player == nullptr
2752 && (nation_leader_by_name(pnation, player_name(pplayer)))) {
2754 n++;
2755 }
2757 if (n > 0) {
2758 player_set_nation_full(pplayer,
2760 }
2762 }
2763 if (pplayer->nation != NO_NATION_SELECTED) {
2764 announce_player(pplayer);
2765 } else {
2767 }
2769
2770 if (0 < nations_to_assign && 0 < map_startpos_count()) {
2771 /* We're running a scenario game with specified start positions.
2772 * Prefer nations assigned to those positions (but we can fall back
2773 * to others, even if game.scenario.startpos_nations is set). */
2775 struct nation_type *picked;
2776 int c, max = -1;
2777 int i, min;
2778
2779 /* Initialization. */
2781 if (startpos_allows_all(psp)) {
2782 continue;
2783 }
2784
2785 /* Count the already-assigned players whose nations can use this
2786 * start position. */
2787 c = 0;
2788 players_iterate(pplayer) {
2789 if (NO_NATION_SELECTED != pplayer->nation
2790 && startpos_nation_allowed(psp, pplayer->nation)) {
2791 c++;
2792 }
2794
2795 startpos_hash_insert(hash, psp, c);
2796 if (c > max) {
2797 max = c;
2798 }
2800
2801 /* Try to assign nations with start positions to the unassigned
2802 * players, preferring nations whose start positions aren't usable
2803 * by already-assigned players. */
2804 players_iterate(pplayer) {
2805 if (NO_NATION_SELECTED != pplayer->nation) {
2806 continue;
2807 }
2808
2810 min = max;
2811 i = 0;
2812
2813 allowed_nations_iterate(pnation) {
2814 if (!is_nation_playable(pnation)
2815 || pnation->player != nullptr) {
2816 /* Not available. */
2817 continue;
2818 }
2819
2820 startpos_hash_iterate(hash, psp, val) {
2821 if (!startpos_nation_allowed(psp, pnation)) {
2822 continue;
2823 }
2824
2825 if (val < min) {
2826 /* Pick this nation, as fewer nations already in the game
2827 * can use this start position. */
2828 picked = pnation;
2829 min = val;
2830 i = 1;
2831 } else if (val == min && 0 == fc_rand(++i)) {
2832 /* More than one nation is equally desirable. Pick one at
2833 * random. */
2834 picked = pnation;
2835 }
2838
2839 if (NO_NATION_SELECTED != picked) {
2842 announce_player(pplayer);
2843 /* Update the counts for the newly assigned nation. */
2844 startpos_hash_iterate(hash, psp, val) {
2845 if (startpos_nation_allowed(psp, picked)) {
2846 startpos_hash_replace(hash, psp, val + 1);
2847 }
2849 } else {
2850 /* No need to continue; we failed to pick a nation this time,
2851 * so we're not going to succeed next time. Fall back to
2852 * standard nation selection. */
2853 break;
2854 }
2856
2858 }
2859
2860 if (0 < nations_to_assign) {
2861 /* Pick random races. Try to select from the set permitted by
2862 * starting positions -- if we fell through here after failing to
2863 * match start positions, this will at least keep the picked
2864 * nations vaguely in keeping with the scenario.
2865 * However, even this may fail (if there are start positions that
2866 * can only be filled by nations outside the current nationset),
2867 * in which case we fall back to completely random nations. */
2868 bool needs_startpos = TRUE;
2869 players_iterate(pplayer) {
2870 if (NO_NATION_SELECTED == pplayer->nation) {
2871 struct nation_type *pnation = pick_a_nation(nullptr, FALSE, needs_startpos,
2873 if (pnation == NO_NATION_SELECTED && needs_startpos) {
2875 pnation = pick_a_nation(nullptr, FALSE, needs_startpos, NOT_A_BARBARIAN);
2876 }
2877 fc_assert(pnation != NO_NATION_SELECTED);
2878 player_set_nation_full(pplayer, pnation);
2880 announce_player(pplayer);
2881 }
2883 }
2884
2886
2888}
2889
2890/**********************************************************************/
2895const char *pick_random_player_name(const struct nation_type *pnation)
2896{
2897 const char *choice = nullptr;
2899 int n;
2900
2902 const char *name = nation_leader_name(pleader);
2903
2904 if (player_by_name(name) == nullptr
2905 && player_by_user(name) == nullptr) {
2907 }
2909
2911 if (n > 0) {
2913 fc_rand(n)));
2914 }
2916
2917 return choice;
2918}
2919
2920/**********************************************************************/
2923static void announce_player(struct player *pplayer)
2924{
2925 log_normal(_("%s rules the %s."),
2926 player_name(pplayer), nation_plural_for_player(pplayer));
2927
2929 ftc_server, _("%s rules the %s."),
2930 player_name(pplayer), nation_plural_for_player(pplayer));
2931
2932 /* Let the clients knows the nation of the players as soon as possible.
2933 * When a player's nation is server assigned its client will think of it
2934 * as nullptr until informed about the assigned nation. */
2935 send_player_info_c(pplayer, nullptr);
2936}
2937
2938/**********************************************************************/
2941static void srv_running(void)
2942{
2944 bool skip_mapimg = !game.info.is_new_game; /* Do not overwrite start-of-turn image */
2946 int save_counter = game.info.is_new_game ? 1 : 0;
2947
2948 /* We may as well reset is_new_game now. */
2950
2951 log_verbose("srv_running() mostly redundant send_server_settings()");
2952 send_server_settings(nullptr);
2953
2955
2956 if (game.server.autosaves & (1 << AS_TIMER)) {
2959 game.server.save_timer != nullptr
2960 ? nullptr : "save interval");
2962 }
2963
2964 /*
2965 * This will freeze the reports and agents at the client.
2966 *
2967 * Do this before the body so that the PACKET_THAW_CLIENT packet is
2968 * balanced.
2969 */
2971
2973 while (S_S_RUNNING == server_state()) {
2974 /* The beginning of a turn.
2975 *
2976 * We have to initialize data as well as do some actions. However when
2977 * loading a game we don't want to do these actions (like AI unit
2978 * movement and AI diplomacy). */
2980
2981 if (game.server.num_phases != 1) {
2982 /* We allow everyone to begin adjusting cities and such
2983 * from the beginning of the turn.
2984 * With simultaneous movement we send begin_turn packet in
2985 * begin_phase() only after AI players have finished their actions. */
2987 }
2988
2990 log_debug("Starting phase %d/%d.", game.info.phase,
2994 /* When loading a savegame, we need to send loaded events, after
2995 * the clients switched to the game page (after the first
2996 * packet_start_phase is received). */
3001 }
3002
3003 is_new_turn = TRUE;
3004
3006
3007 /*
3008 * This will thaw the reports and agents at the client.
3009 */
3011
3012#ifdef LOG_TIMERS
3013 /* Before sniff (human player activites), report time to now: */
3014 log_verbose("End/start-turn server/ai activities: %g seconds",
3016#endif
3017
3018 /* Do auto-saves just before starting server_sniff_all_input(), so that
3019 * autosave happens effectively "at the same time" as manual
3020 * saves, from the point of view of restarting and AI players.
3021 * Post-increment so we don't count the first loop. */
3022 if (game.info.phase == 0) {
3023 /* Create autosaves if requested. */
3025 && game.server.save_nturns > 0) {
3026 save_counter = 0;
3027 save_game_auto("Autosave", AS_TURN);
3028 }
3029 save_counter++;
3030
3031 if (!skip_mapimg) {
3033 } else {
3035 }
3036 }
3037
3038 log_debug("sniffingpackets");
3039 check_for_full_turn_done(); /* HACK: don't wait during AI phases */
3040
3041 if (between_turns != nullptr) {
3043 log_debug("Unresponsive between turns %g seconds", game.server.turn_change_time);
3044 }
3045
3047 /* Nothing */
3048 }
3049
3051 between_turns != nullptr ? nullptr : "between turns");
3053
3054 /* After sniff, re-zero the timer: (read-out above on next loop) */
3057
3059
3060 sanity_check();
3061
3062 /*
3063 * This will freeze the reports and agents at the client.
3064 */
3066
3067 end_phase();
3068
3070
3071 if (S_S_OVER == server_state()) {
3072 break;
3073 }
3075 }
3076
3077 /* Make sure is_new_turn is reset before next turn even if
3078 * we did zero rounds in the loop (i.e. if current phase from
3079 * the savegame was >= num phases). Without this begin_turn()
3080 * would not reset phase, so there would be infinite loop
3081 * where phase is too high for is_new_turn to get set. */
3082 is_new_turn = TRUE;
3083
3084 end_turn();
3085 log_debug("Sendinfotometaserver");
3087
3090 if (game.info.turn > game.server.end_turn) {
3091 /* Endturn was reached - rank users based on team scores */
3093 } else {
3094 /* Game ended for victory conditions - rank users based on survival */
3096 }
3097 } else if (S_S_OVER == server_state()) {
3098 /* Game terminated by /endgame command - calculate team scores */
3100 }
3101 }
3102
3103 /* This will thaw the reports and agents at the client. */
3105
3106 if (game.server.save_timer != nullptr) {
3108 game.server.save_timer = nullptr;
3109 }
3110 if (between_turns != nullptr) {
3112 between_turns = nullptr;
3113 }
3115}
3116
3117/**********************************************************************/
3120static void srv_prepare(void)
3121{
3122#ifdef HAVE_FCDB
3123 if (!srvarg.auth_enabled) {
3124 con_write(C_COMMENT, _("This freeciv-server program has player "
3125 "authentication support, but it's currently not "
3126 "in use."));
3127 }
3128#endif /* HAVE_FCDB */
3129
3130 /* Make sure it's initialized */
3131 if (!has_been_srv_init) {
3132 srv_init();
3133 }
3134
3136
3137 /* Must be before con_log_init() */
3141 /* Logging available after this point */
3142
3144
3145#if IS_BETA_VERSION || IS_DEVEL_VERSION
3146 con_puts(C_COMMENT, "");
3148 con_puts(C_COMMENT, "");
3149#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
3150
3151 con_flush();
3152
3155 edithand_init();
3156 voting_init();
3157 voting_init();
3158 ai_timer_init();
3159
3160 modpacks_init();
3166
3167#ifdef HAVE_FCDB
3168 if (srvarg.fcdb_enabled) {
3169 bool success;
3170
3172 free(srvarg.fcdb_conf); /* Never needed again */
3173 srvarg.fcdb_conf = nullptr;
3174 if (!success) {
3176 }
3177 }
3178#endif /* HAVE_FCDB */
3179
3180 if (srvarg.ruleset != nullptr) {
3181 const char *testfilename;
3182
3184 if (testfilename == nullptr) {
3185 log_fatal(_("Ruleset directory \"%s\" not found"), srvarg.ruleset);
3187 }
3189 }
3190
3191 /* Try to load a saved game */
3192 if ('\0' == srvarg.load_filename[0]
3193 || !load_command(nullptr, srvarg.load_filename, FALSE, TRUE)) {
3194 /* Savegame not loaded */
3196
3197 /* Rulesets are loaded on game initialization, but may be changed later
3198 * if /load or /rulesetdir is done. */
3199 load_rulesets(nullptr, nullptr, FALSE, nullptr, TRUE, FALSE, TRUE);
3200 }
3201
3203
3204 if (!(srvarg.metaserver_no_send)) {
3205 log_normal(_("Sending info to metaserver <%s>."), meta_addr_port());
3206 /* Open socket for meta server */
3209 con_write(C_FAIL, _("Not starting without explicitly requested metaserver connection."));
3211 }
3212 }
3213
3214 eot_timer = timer_new(TIMER_CPU, TIMER_ACTIVE, "end-of-turn");
3215}
3216
3217/**********************************************************************/
3220static void srv_scores(void)
3221{
3222 /* Recalculate the scores in case of a spaceship victory */
3223 players_iterate(pplayer) {
3224 calc_civ_score(pplayer);
3226
3228
3229 report_final_scores(nullptr);
3231 notify_player(nullptr, nullptr, E_GAME_END, ftc_server,
3232 _("The game is over..."));
3234
3235 if (game.server.save_nturns > 0
3237 || !srvarg.quitidle)) {
3238 /* Save game on game_over, but not when the gameover was caused by
3239 * the -q parameter. Be sure that it's the -q, and not an autogame
3240 * with no human players. */
3241 save_game_auto("Game over", AS_GAME_OVER);
3242 }
3243
3245}
3246
3247/**********************************************************************/
3253{
3254 players_iterate(pplayer) {
3255 struct nation_type *pnation = nation_of_player(pplayer);
3256
3257 pplayer->government = init_government_of_nation(pnation);
3258
3260 /* If we do not do this, an assertion will trigger. This enables us to
3261 * select a valid government on game start. */
3262 pplayer->revolution_finishes = 0;
3263 }
3264
3265 multipliers_iterate(pmul) {
3266 int midx = multiplier_index(pmul);
3267
3268 pplayer->multipliers[midx].value
3269 = pplayer->multipliers[midx].target
3270 = pmul->def;
3273}
3274
3275/**********************************************************************/
3278static void srv_ready(void)
3279{
3281
3283 players_iterate(pplayer) {
3284 if (!pplayer->is_connected && is_human(pplayer)) {
3285 toggle_ai_player_direct(nullptr, pplayer);
3286 }
3288 }
3289
3291
3292#ifdef TEST_RANDOM /* Not defined anywhere, set it if you want it */
3293 test_random1(200);
3294 test_random1(2000);
3295 test_random1(20000);
3296 test_random1(200000);
3297#endif
3298
3299 if (game.info.is_new_game) {
3300 /* Must come before assign_player_colors() */
3303
3304 game.info.turn++; /* Pregame T0 -> game T1 */
3305 fc_assert(game.info.turn == 1);
3307 }
3308
3309 /* If we have a tile map, and MAPGEN_SCENARIO == map.server.generator,
3310 * call map_fractal_generate() anyway to make the specials, huts and
3311 * continent numbers. */
3312 if (map_is_empty()
3314 && game.info.is_new_game)) {
3315 struct {
3316 const char *name;
3317 char value[MAX_LEN_NAME * 2];
3318 char pretty[MAX_LEN_NAME * 2];
3319 } mapgen_settings[] = {
3320 { "generator", },
3321 { "startpos", },
3322 { "teamplacement", }
3323 };
3324 int i;
3325 /* If a specific seed has been requested, there's no point retrying,
3326 * as the map will be the same every time. */
3327 bool retry_ok = (wld.map.server.seed_setting == 0
3329 int max = retry_ok ? 3 : 1;
3330 bool created = FALSE;
3331 struct unit_type *utype = nullptr;
3333
3334 if (sucount > 0) {
3335 for (i = 0; utype == nullptr && i < sucount; i++) {
3336 utype = crole_to_unit_type(game.server.start_units[i], nullptr);
3337 }
3338 } else {
3339 /* First unit the initial city might build. */
3340 utype = get_role_unit(L_FIRSTBUILD, 0);
3341 }
3342 fc_assert(utype != nullptr);
3343
3344 /* Register map generator setting main values. */
3345 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3347
3348 fc_assert_action(pset != nullptr, continue);
3351 sizeof(mapgen_settings[i].value));
3353 mapgen_settings[i].pretty,
3354 sizeof(mapgen_settings[i].pretty));
3355 }
3356
3357 for (i = 0; !created && i < max ; i++) {
3359 if (!created && max > 1) {
3360 int set;
3361
3362 /* If we're retrying, seed_setting == 0, which will yield a new map
3363 * next time */
3365 if (i == 0) {
3366 /* We will retry only if max attempts allow it */
3367 log_normal(_("Failed to create suitable map, retrying with another mapseed."));
3368 } else {
3369 /* +1 - start human readable count from 1 and not from 0
3370 * +1 - refers to next round, not to one we just did
3371 * ==
3372 * +2 */
3373 log_normal(_("Attempt %d/%d"), i + 2, max);
3374 }
3376
3377 /* Remove old information already present in tiles */
3378 main_map_free();
3380 /* Restore the settings. */
3381 for (set = 0; set < ARRAY_SIZE(mapgen_settings); set++) {
3383#ifdef FREECIV_NDEBUG
3384 setting_enum_set(pset, mapgen_settings[set].value, nullptr, nullptr, 0);
3385#else /* FREECIV_NDEBUG */
3386 char error[128];
3387 bool success;
3388
3389 fc_assert_action(pset != nullptr, continue);
3391 nullptr, error, sizeof(error));
3393 "Failed to restore '%s': %s",
3394 mapgen_settings[set].name,
3395 error);
3396#endif /* FREECIV_NDEBUG */
3397 }
3398 main_map_allocate(); /* NOT map_init() as that would overwrite settings */
3399 }
3400 }
3401 if (!created) {
3402 bugreport_request(_("Cannot create suitable map with given settings."));
3403
3405 }
3406
3408 script_server_signal_emit("map_generated");
3409 }
3410
3411 game_map_init();
3412
3413 /* Test if main map generator settings have changed. */
3414 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3416 char pretty[sizeof(mapgen_settings[i].pretty)];
3417
3418 fc_assert_action(pset != nullptr, continue);
3419 if (0 == strcmp(setting_value_name(pset, TRUE, pretty,
3420 sizeof(pretty)),
3421 mapgen_settings[i].pretty)) {
3422 continue; /* Setting didn't change. */
3423 }
3424 notify_conn(nullptr, nullptr, E_SETTING, ftc_server,
3425 _("Setting '%s' has been adjusted from %s to %s."),
3427 mapgen_settings[i].pretty,
3428 pretty);
3429 log_normal(_("Setting '%s' has been adjusted from %s to %s."),
3431 mapgen_settings[i].pretty,
3432 pretty);
3433 }
3434 }
3435
3436 CALL_FUNC_EACH_AI(map_ready);
3437
3438 /* start the game */
3441
3442 if (game.info.is_new_game) {
3444
3445 /* If we're starting a new game, reset the max_players to be at
3446 * least the number of players currently in the game. */
3448
3449 /* Before the player map is allocated (and initialized)! */
3451
3452 players_iterate(pplayer) {
3453 player_map_init(pplayer);
3455 pplayer->economic.gold = game.info.gold;
3456 pplayer->economic.infra_points = game.info.infrapoints;
3458
3459 /* Give initial technologies, as specified in the ruleset and the
3460 * settings. */
3465
3466 /* Set up alliances based on team selections */
3467 players_iterate(pplayer) {
3469 if (players_on_same_team(pplayer, pdest)
3470 && player_number(pplayer) != player_number(pdest)) {
3472 player_diplstate_get(pdest, pplayer),
3473 DS_TEAM);
3474 give_shared_vision(pplayer, pdest);
3475 BV_SET(pplayer->real_embassy, player_index(pdest));
3476 }
3479
3480 /* Assign colors from the ruleset for any players who weren't
3481 * explicitly assigned colors during the pregame.
3482 * This must come after generate_players() since it can depend on
3483 * assigned nations. */
3485
3486 /* Save all settings for the 'reset game' command. */
3488 }
3489
3490 /* FIXME: Can this be moved? */
3491 players_iterate(pplayer) {
3494
3495 if (!game.info.is_new_game) {
3496 players_iterate(pplayer) {
3497 if (is_ai(pplayer)) {
3498 set_ai_level_direct(pplayer, pplayer->ai_common.skill_level);
3499 }
3501 } else {
3502 players_iterate(pplayer) {
3503 /* Initialize this again to be sure */
3504 adv_data_default(pplayer);
3506 }
3507
3511
3512 if (game.info.is_new_game) {
3513 /* Place players' initial units, etc */
3514 init_new_game();
3516
3518 players_iterate(pplayer) {
3519 map_show_all(pplayer);
3521 }
3522 }
3523
3525 /* This is a heavy scenario. It may include research. The sciencebox
3526 * setting may have been changed. A change to the sciencebox setting
3527 * may have caused the stored amount of bulbs to be enough to finish
3528 * the current research. */
3529
3530 players_iterate(pplayer) {
3531 /* Check for finished research. */
3532 update_bulbs(pplayer, 0, TRUE, FALSE);
3534 }
3535
3536 if (srvarg.fcdb_enabled) {
3538 &game.server.dbid);
3539 log_debug("dbid: %d", game.server.dbid);
3540 }
3541
3542 CALL_FUNC_EACH_AI(game_start);
3543}
3544
3545/**********************************************************************/
3549{
3550 /* Was redundantly in game_load() */
3551 server.playable_nations = 0;
3552 server.nbarbarians = 0;
3553 server.identity_number = IDENTITY_NUMBER_SKIP;
3554
3557
3560 /* game_init() set game.server.plr_colors to nullptr. So we need to
3561 * initialize the colors after. */
3563
3565}
3566
3567/**********************************************************************/
3573{
3575
3576 /* Free all the treaties that were left open when game finished. */
3577 free_treaties();
3578
3579 /* Free the vision data, without sending updates. */
3580 players_iterate(pplayer) {
3581 unit_list_iterate(pplayer->units, punit) {
3582 /* Don't bother using vision_clear_sight() */
3584 punit->server.vision->radius_sq[v] = -1;
3587 punit->server.vision = nullptr;
3589
3590 city_list_iterate(pplayer->cities, pcity) {
3591 /* don't bother using vision_clear_sight() */
3593 pcity->server.vision->radius_sq[v] = -1;
3596 pcity->server.vision = nullptr;
3600
3601 /* Destroy all players; with must be separate as the player information is
3602 * needed above. This also sends the information to the clients. */
3603 players_iterate(pplayer) {
3604 server_remove_player(pplayer);
3606
3610 citymap_free();
3611 game_free();
3612}
3613
3614/**********************************************************************/
3618{
3619 srv_prepare();
3620
3621 /* Run server loop */
3622 do {
3624
3625 /* Load a script file. */
3626 if (srvarg.script_filename != nullptr) {
3627 /* Adding an error message more here will duplicate them. */
3629 }
3630
3632 if (!game_was_started()) {
3634 }
3635
3636 log_normal(_("Now accepting new client connections on port %d."),
3637 srvarg.port);
3638 /* Remain in S_S_INITIAL until all players are ready. */
3640 /* When force_end_of_sniff is used in pregame, it means that the server
3641 * is ready to start (usually set within start_game()). */
3642 }
3643
3644 if (S_S_RUNNING > server_state()) {
3645 /* If restarting for lack of players, the state is S_S_OVER,
3646 * so don't try to start the game. */
3647 srv_ready(); /* srv_ready() sets server state to S_S_RUNNING. */
3648 srv_running();
3649 srv_scores();
3650 }
3651
3652 /* Remain in S_S_OVER until players log out */
3653 while (conn_list_size(game.est_connections) > 0) {
3655 }
3656
3657 if (game.info.timeout == -1 || srvarg.exit_on_end) {
3658 /* For autogames or if the -e option is specified, exit the server. */
3659 server_quit();
3660 }
3661
3662 /* Close it even between games. */
3664
3665 /* Reset server */
3669 mapimg_reset();
3671 load_rulesets(nullptr, nullptr, FALSE, nullptr, TRUE, FALSE, TRUE);
3673 } while (TRUE);
3674
3675 /* Technically, we won't ever get here. We exit via server_quit(). */
3677}
3678
3679/**********************************************************************/
3682struct color;
3683static inline void server_gui_color_free(struct color *pcolor)
3684{
3685 fc_assert_ret(pcolor == nullptr);
3686
3687 return;
3688}
3689
3690/**********************************************************************/
3694static int server_plr_tile_city_id_get(const struct tile *ptile,
3695 const struct player *pplayer)
3696{
3697 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3698
3699 return plrtile && plrtile->site ? plrtile->site->identity
3701}
3702
3703/**********************************************************************/
3707{
3708 struct setting *pset = setting_by_name(name);
3709
3710 if (pset) {
3711 return setting_number(pset);
3712 } else {
3713 log_error("No server setting named %s exists.", name);
3714 return SERVER_SETTING_NONE;
3715 }
3716}
3717
3718/**********************************************************************/
3722{
3723 struct setting *pset = setting_by_number(id);
3724
3725 if (pset) {
3726 return setting_name(pset);
3727 } else {
3728 log_error("No server setting with the id %d exists.", id);
3729
3730 return nullptr;
3731 }
3732}
3733
3734/**********************************************************************/
3738{
3739 struct setting *pset = setting_by_number(id);
3740
3741 if (pset) {
3742 return setting_type(pset);
3743 } else {
3744 log_error("No server setting with the id %d exists.", id);
3745 return sset_type_invalid();
3746 }
3747}
3748
3749/**********************************************************************/
3753{
3754 struct setting *pset = setting_by_number(id);
3755
3756 if (pset) {
3757 return setting_bool_get(pset);
3758 } else {
3759 log_error("No server setting with the id %d exists.", id);
3760 return FALSE;
3761 }
3762}
3763
3764/**********************************************************************/
3768{
3769 struct setting *pset = setting_by_number(id);
3770
3771 if (pset) {
3772 return setting_int_get(pset);
3773 } else {
3774 log_error("No server setting with the id %d exists.", id);
3775 return 0;
3776 }
3777}
3778
3779/**********************************************************************/
3783{
3784 struct setting *pset = setting_by_number(id);
3785
3786 if (pset) {
3787 return setting_bitwise_get(pset);
3788 } else {
3789 log_error("No server setting with the id %d exists.", id);
3790 return FALSE;
3791 }
3792}
3793
3794/**********************************************************************/
3798{
3800
3801 funcs->server_setting_by_name = server_ss_by_name;
3802 funcs->server_setting_name_get = server_ss_name_get;
3803 funcs->server_setting_type_get = server_ss_type_get;
3804 funcs->server_setting_val_bool_get = server_ss_val_bool_get;
3805 funcs->server_setting_val_int_get = server_ss_val_int_get;
3806 funcs->server_setting_val_bitwise_get = server_ss_val_bitwise_get;
3807 funcs->create_extra = create_extra;
3808 funcs->destroy_extra = destroy_extra;
3809 funcs->destroy_city = remove_city;
3810 funcs->player_tile_vision_get = map_is_known_and_seen;
3811 funcs->player_tile_city_id_get = server_plr_tile_city_id_get;
3812 funcs->gui_color_free = server_gui_color_free;
3813
3814 /* Keep this function call at the end. It checks if all required functions
3815 are defined. */
3817}
3818
3819/**********************************************************************/
3822static enum known_type mapimg_server_tile_known(const struct tile *ptile,
3823 const struct player *pplayer,
3824 bool knowledge)
3825{
3826 if (knowledge && pplayer) {
3827 return tile_get_known(ptile, pplayer);
3828 }
3829
3830 return TILE_KNOWN_SEEN;
3831}
3832
3833/**********************************************************************/
3836static struct terrain
3837 *mapimg_server_tile_terrain(const struct tile *ptile,
3838 const struct player *pplayer, bool knowledge)
3839{
3840 if (knowledge && pplayer) {
3841 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3842 return plrtile->terrain;
3843 }
3844
3845 return tile_terrain(ptile);
3846}
3847
3848/**********************************************************************/
3851static struct player *mapimg_server_tile_owner(const struct tile *ptile,
3852 const struct player *pplayer,
3853 bool knowledge)
3854{
3855 if (knowledge && pplayer
3856 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3857 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3858 return plrtile->owner;
3859 }
3860
3861 return tile_owner(ptile);
3862}
3863
3864/**********************************************************************/
3867static struct player *mapimg_server_tile_city(const struct tile *ptile,
3868 const struct player *pplayer,
3869 bool knowledge)
3870{
3871 struct city *pcity = tile_city(ptile);
3872
3873 if (!pcity) {
3874 return nullptr;
3875 }
3876
3877 if (knowledge && pplayer) {
3878 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
3879
3880 if (pdcity) {
3881 return pdcity->owner;
3882 } else {
3883 return nullptr;
3884 }
3885 }
3886
3887 return city_owner(tile_city(ptile));
3888}
3889
3890/**********************************************************************/
3893static struct player *mapimg_server_tile_unit(const struct tile *ptile,
3894 const struct player *pplayer,
3895 bool knowledge)
3896{
3897 int unit_count = unit_list_size(ptile->units);
3898
3899 if (unit_count == 0) {
3900 return nullptr;
3901 }
3902
3903 if (knowledge && pplayer
3904 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3905 return nullptr;
3906 }
3907
3908 return unit_owner(unit_list_get(ptile->units, 0));
3909}
3910
3911/**********************************************************************/
3915{
3916 return playercolor_count();
3917}
3918
3919/**********************************************************************/
3923{
3924 return playercolor_get(i);
3925}
3926
3927/**********************************************************************/
3930static void save_all_map_images(void)
3931{
3932 int count = mapimg_count();
3933 int i;
3934
3935 /* Save map image(s). */
3936 for (i = 0; i < count; i++) {
3937 struct mapdef *pmapdef = mapimg_isvalid(i);
3938
3939 if (pmapdef != nullptr) {
3942 } else {
3943 log_error("%s", mapimg_error());
3944 }
3945 }
3946}
3947
3948/**********************************************************************/
3951static bool world_peace_turn(void)
3952{
3953 players_iterate_alive(pplayer) {
3954 bool contact = FALSE;
3955
3957 if (pplayer != other) {
3959
3960 if (dstate->type == DS_WAR) {
3961 return FALSE;
3962 }
3963 if (dstate->type != DS_NO_CONTACT) {
3964 contact = TRUE;
3965 }
3966 }
3968
3969 if (!contact) {
3970 /* Peace only because there's nobody to show aggression against does not count. */
3971 return FALSE;
3972 }
3974
3975 return TRUE;
3976}
3977
3978/**********************************************************************/
3981static void world_peace_update(void)
3982{
3983 if (!world_peace_turn()) {
3984 /* Consecutive world peace turns begin *earliest* after this turn,
3985 overwrite older claims. */
3987 }
3988}
void access_areas_refresh(struct civ_map *nmap, struct player *plr)
Definition aahand.c:33
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:270
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:574
void adv_data_default(struct player *pplayer)
Definition advdata.c:740
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:361
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:390
#define ai_timer_init(...)
Definition ai.h:360
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:380
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:103
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:159
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:564
#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:3633
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2374
bool send_city_suppression(bool now)
Definition citytools.c:2176
void sync_cities(void)
Definition citytools.c:3360
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3475
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3394
void remove_city(struct city *pcity)
Definition citytools.c:1719
void city_thaw_workers_queue(void)
Definition citytools.c:197
void send_player_cities(struct player *pplayer)
Definition citytools.c:2354
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2330
void remove_obsolete_buildings(struct player *pplayer)
Definition cityturn.c:271
bool check_city_migrations(void)
Definition cityturn.c:4417
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4797
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:578
void update_city_activities(struct player *pplayer)
Definition cityturn.c:604
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4818
void check_disasters(void)
Definition cityturn.c:4592
void city_refresh_queue_processing(void)
Definition cityturn.c:214
char * incite_cost
Definition comments.c:77
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_bool32_raw(struct raw_data_out *d_out, bool value)
Definition dataio_raw.c:401
size_t dio_output_used(struct raw_data_out *d_out)
Definition dataio_raw.c:186
int dio_put_uint16_raw(struct raw_data_out *d_out, int value)
Definition dataio_raw.c:289
int dio_put_string_raw(struct raw_data_out *d_out, const char *value)
Definition dataio_raw.c:520
void dio_output_rewind(struct raw_data_out *d_out)
Definition dataio_raw.c:195
void dio_output_init(struct raw_data_out *d_out, void *destination, size_t dest_size)
Definition dataio_raw.c:173
int dio_put_uint8_raw(struct raw_data_out *d_out, int value)
Definition dataio_raw.c:267
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:73
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:77
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:1071
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
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1128
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1136
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
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:973
@ EUT_NUCLEAR_WINTER
Definition fc_types.h:975
@ EUT_GLOBAL_WARMING
Definition fc_types.h:974
int server_setting_id
Definition fc_types.h:765
int Tech_type_id
Definition fc_types.h:238
int Nation_type_id
Definition fc_types.h:241
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_LEN_NAME
Definition fc_types.h:68
@ VC_CULTURE
Definition fc_types.h:968
@ VC_ALLIED
Definition fc_types.h:967
@ VC_WORLDPEACE
Definition fc_types.h:969
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
@ BORDERS_ENABLED
Definition fc_types.h:733
@ BORDERS_DISABLED
Definition fc_types.h:732
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:94
void fcdb_free(void)
Definition fcdb.c:235
bool fcdb_init(const char *conf_file)
Definition fcdb.c:219
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:716
int current_turn_timeout(void)
Definition game.c:858
void game_init(bool keep_ruleset_value)
Definition game.c:445
struct world wld
Definition game.c:63
void game_free(void)
Definition game.c:476
void game_map_init(void)
Definition game.c:463
int generate_save_name(const char *format, char *buf, int buflen, const char *reason)
Definition game.c:801
#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:1839
int map_num_tiles(void)
Definition map.c:1161
bool startpos_allows_all(const struct startpos *psp)
Definition map.c:1852
void main_map_allocate(void)
Definition map.c:534
int map_startpos_count(void)
Definition map.c:2017
bool map_is_empty(void)
Definition map.c:148
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
Definition map.h:373
#define iterate_outward_end
Definition map.h:377
#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:582
#define whole_map_iterate_end
Definition map.h:591
@ 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:271
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:295
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:472
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:231
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:201
int nation_set_count(void)
Definition nation.c:690
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Definition nation.c:1174
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:287
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:212
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:657
struct nation_style * style_of_nation(const struct nation_type *pnation)
Definition nation.c:670
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:57
#define nations_iterate_end
Definition nation.h:364
#define nations_iterate(NAME_pnation)
Definition nation.h:361
#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:753
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:837
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1468
int player_count(void)
Definition player.c:806
int player_slot_count(void)
Definition player.c:415
int player_number(const struct player *pplayer)
Definition player.c:826
const char * player_name(const struct player *pplayer)
Definition player.c:885
struct player * player_by_name(const char *name)
Definition player.c:871
int player_index(const struct player *pplayer)
Definition player.c:818
struct player * player_by_user(const char *name)
Definition player.c:932
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:849
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:325
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1397
#define players_iterate_end
Definition player.h:552
#define players_iterate(_pplayer)
Definition player.h:547
#define player_list_iterate(playerlist, pplayer)
Definition player.h:570
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:499
#define is_ai(plr)
Definition player.h:232
#define player_list_iterate_end
Definition player.h:572
#define players_iterate_alive_end
Definition player.h:562
#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:557
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:3225
int normal_player_count(void)
Definition plrhand.c:3217
void playercolor_free(void)
Definition plrhand.c:3356
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:2466
void playercolor_init(void)
Definition plrhand.c:3346
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:3486
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3233
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3385
int playercolor_count(void)
Definition plrhand.c:3395
void shuffle_players(void)
Definition plrhand.c:2391
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:2627
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2603
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:9539
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:9459
#define sanity_check()
Definition sanitycheck.h:44
void save_system_close(void)
Definition savemain.c:335
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:149
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:5290
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:5430
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:3120
static struct player * mapimg_server_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3851
static void server_gui_color_free(struct color *pcolor)
Definition srv_main.c:3683
void server_game_init(bool keep_ruleset_value)
Definition srv_main.c:3548
static struct terrain * mapimg_server_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3837
static void save_all_map_images(void)
Definition srv_main.c:3930
static struct player * mapimg_server_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3867
static void update_diplomatics(void)
Definition srv_main.c:954
static struct player * mapimg_server_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3893
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:2420
static void do_have_contacts_effect(void)
Definition srv_main.c:789
static void ai_start_phase(void)
Definition srv_main.c:1142
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:2895
void identity_number_release(int id)
Definition srv_main.c:2075
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2672
static void handle_observer_ready(struct connection *pconn)
Definition srv_main.c:2486
bv_id identity_numbers_used
Definition srv_main.c:196
static void world_peace_update(void)
Definition srv_main.c:3981
void handle_report_req(struct connection *pconn, enum report_type type)
Definition srv_main.c:2036
static void generate_players(void)
Definition srv_main.c:2723
bool force_end_of_sniff
Definition srv_main.c:194
static void do_reveal_effects(void)
Definition srv_main.c:766
static int mapimg_server_plrcolor_count(void)
Definition srv_main.c:3914
void start_game(void)
Definition srv_main.c:1926
void handle_client_info(struct connection *pc, enum gui_type gui, int emerg_version, const char *distribution)
Definition srv_main.c:318
void handle_player_ready(struct player *requestor, int player_no, bool is_ready)
Definition srv_main.c:2502
const char * aifill(int amount)
Definition srv_main.c:2556
static bool identity_number_is_used(int id)
Definition srv_main.c:2091
static void end_phase(void)
Definition srv_main.c:1443
static enum server_states civserver_state
Definition srv_main.c:188
static void begin_turn(bool is_new_turn)
Definition srv_main.c:1157
static void end_turn(void)
Definition srv_main.c:1609
void save_game_auto(const char *save_reason, enum autosave_type type)
Definition srv_main.c:1885
static struct rgbcolor * mapimg_server_plrcolor_get(int i)
Definition srv_main.c:3922
void set_server_state(enum server_states newstate)
Definition srv_main.c:349
static int increment_identity_number(void)
Definition srv_main.c:2099
const char * server_ss_name_get(server_setting_id id)
Definition srv_main.c:3721
static bool world_peace_turn(void)
Definition srv_main.c:3951
static void begin_phase(bool is_new_phase)
Definition srv_main.c:1264
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:833
static void kill_dying_players(void)
Definition srv_main.c:1116
bool game_was_started(void)
Definition srv_main.c:357
static void srv_scores(void)
Definition srv_main.c:3220
#define startpos_hash_iterate(hash, psp, c)
Definition srv_main.c:2655
void identity_number_reserve(int id)
Definition srv_main.c:2083
struct server_arguments srvarg
Definition srv_main.c:182
static void srv_ready(void)
Definition srv_main.c:3278
static void srv_running(void)
Definition srv_main.c:2941
static void final_ruleset_adjustments(void)
Definition srv_main.c:3252
#define startpos_hash_iterate_end
Definition srv_main.c:2657
static int server_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Definition srv_main.c:3694
static bool is_client_edit_packet(int type)
Definition srv_main.c:2131
void fc__noreturn srv_main(void)
Definition srv_main.c:3617
static void notify_illegal_armistice_units(struct player *phost, struct player *pguest, int turns_left)
Definition srv_main.c:871
bool server_ss_val_bool_get(server_setting_id id)
Definition srv_main.c:3752
static void remove_illegal_armistice_units(struct player *plr1, struct player *plr2)
Definition srv_main.c:915
int identity_number(void)
Definition srv_main.c:2109
server_setting_id server_ss_by_name(const char *name)
Definition srv_main.c:3706
void check_for_full_turn_done(void)
Definition srv_main.c:2306
static void player_set_nation_full(struct player *pplayer, struct nation_type *pnation)
Definition srv_main.c:2662
static void announce_player(struct player *pplayer)
Definition srv_main.c:2923
void srv_init(void)
Definition srv_main.c:235
bool server_packet_input(struct connection *pconn, void *packet, int type)
Definition srv_main.c:2140
static void fc_interface_init_server(void)
Definition srv_main.c:3797
int server_ss_val_int_get(server_setting_id id)
Definition srv_main.c:3767
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:3782
static bool has_been_srv_init
Definition srv_main.c:199
void send_all_info(struct conn_list *dest)
Definition srv_main.c:734
void init_game_seed(void)
Definition srv_main.c:209
void fc__noreturn server_quit(void)
Definition srv_main.c:1963
void update_nations_with_startpos(void)
Definition srv_main.c:2361
enum sset_type server_ss_type_get(server_setting_id id)
Definition srv_main.c:3737
bool check_for_game_over(void)
Definition srv_main.c:371
static enum known_type mapimg_server_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3822
static void do_border_vision_effect(void)
Definition srv_main.c:806
enum server_states server_state(void)
Definition srv_main.c:341
void server_game_free(void)
Definition srv_main.c:3572
#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:1610
void stdinhand_init(void)
Definition stdinhand.c:246
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:1985
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
Definition stdinhand.c:1145
void stdinhand_free(void)
Definition stdinhand.c:258
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Definition stdinhand.c:3781
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6116
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:675
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:139
enum unit_activity activity
Definition unit.h:158
struct vision * vision
Definition unit.h:246
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:141
v_radius_t radius_sq
Definition vision.h:91
struct civ_map map
struct nation_style * style_by_number(int id)
Definition style.c:84
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:367
const char * team_name_translation(const struct team *pteam)
Definition team.c:409
const struct player_list * team_members(const struct team *pteam)
Definition team.c:443
#define teams_iterate_end
Definition team.h:99
#define teams_iterate(_pteam)
Definition team.h:94
#define A_UNSET
Definition tech.h:48
void init_tech(struct research *research, bool update)
Definition techtools.c:1093
void choose_tech(struct research *research, Tech_type_id tech)
Definition techtools.c:1004
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:989
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1187
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:651
#define terrain_has_flag(terr, flag)
Definition terrain.h:177
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:576
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:408
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:2722
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:672
void random_movements(struct player *pplayer)
Definition unittools.c:5110
void finalize_unit_phase_beginning(struct player *pplayer)
Definition unittools.c:704
void execute_unit_orders(struct player *pplayer)
Definition unittools.c:682
void do_explore(struct unit *punit)
Definition unittools.c:3105
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2145
void unit_tc_effect_refresh(struct player *pplayer)
Definition unittools.c:694
void player_restore_units(struct player *pplayer)
Definition unittools.c:483
bool unit_can_be_retired(struct unit *punit)
Definition unittools.c:5093
void send_all_known_units(struct conn_list *dest)
Definition unittools.c:2927
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2284
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:76
#define vision_layer_iterate_end
Definition vision.h:79
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