Freeciv-3.3
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 "aiiface.h"
94#include "animals.h"
95#include "auth.h"
96#include "barbarian.h"
97#include "cityhand.h"
98#include "citytools.h"
99#include "cityturn.h"
100#include "connecthand.h"
101#include "console.h"
102#include "fcdb.h"
103#include "diplhand.h"
104#include "edithand.h"
105#include "gamehand.h"
106#include "handchat.h"
107#include "maphand.h"
108#include "meta.h"
109#include "notify.h"
110#include "plrhand.h"
111#include "report.h"
112#include "ruleload.h"
113#include "sanitycheck.h"
114#include "score.h"
115#include "sernet.h"
116#include "settings.h"
117#include "spacerace.h"
118#include "srv_log.h"
119#include "srv_signal.h"
120#include "stdinhand.h"
121#include "techtools.h"
122#include "unithand.h"
123#include "unittools.h"
124#include "voting.h"
125
126/* server/advisors */
127#include "advdata.h"
128#include "autoworkers.h"
129#include "advbuilding.h"
130#include "advspace.h"
131#include "infracache.h"
132
133/* server/savegame */
134#include "savemain.h"
135
136/* server/scripting */
137#include "script_fcdb.h"
138#include "script_server.h"
139#include "luascript_types.h"
140
141/* server/generator */
142#include "mapgen.h"
143#include "mapgen_utils.h"
144
145/* ai */
146#include "aitraits.h"
147#include "difficulty.h"
148
149#include "srv_main.h"
150
151static void end_turn(void);
152static void announce_player(struct player *pplayer);
153static void fc_interface_init_server(void);
154
155static enum known_type mapimg_server_tile_known(const struct tile *ptile,
156 const struct player *pplayer,
157 bool knowledge);
158static struct terrain
159 *mapimg_server_tile_terrain(const struct tile *ptile,
160 const struct player *pplayer, bool knowledge);
161static struct player *mapimg_server_tile_owner(const struct tile *ptile,
162 const struct player *pplayer,
163 bool knowledge);
164static struct player *mapimg_server_tile_city(const struct tile *ptile,
165 const struct player *pplayer,
166 bool knowledge);
167static struct player *mapimg_server_tile_unit(const struct tile *ptile,
168 const struct player *pplayer,
169 bool knowledge);
170
171static int mapimg_server_plrcolor_count(void);
172static struct rgbcolor *mapimg_server_plrcolor_get(int i);
173
174static void save_all_map_images(void);
175
176static void handle_observer_ready(struct connection *pconn);
177
178static void world_peace_update(void);
179
180/* command-line arguments to server */
182
183/* server aggregate information */
185
186/* server state information */
188
189/* This global is checked deep down the netcode.
190 packets handling functions can set it to none-zero, to
191 force end-of-tick asap
192*/
194
196
197/* server initialized flag */
199
200/* time server processing at end-of-turn */
201static struct timer *eot_timer = NULL;
202
203static struct timer *between_turns = NULL;
204
205/**********************************************************************/
209{
210 if (game.server.seed_setting == 0) {
211 /* We strip the high bit for now because neither game file nor
212 server options can handle unsigned ints yet. - Cedric */
214#ifdef FREECIV_TESTMATIC
215 /* Log command to reproduce the gameseed */
216 log_testmatic("set gameseed %u", game.server.seed);
217#else /* FREECIV_TESTMATIC */
218 log_debug("Setting game.seed:%u", game.server.seed);
219#endif /* FREECIV_TESTMATIC */
220 } else {
222 }
223
224 if (!fc_rand_is_init()) {
226 }
227}
228
229/**********************************************************************/
232void srv_init(void)
233{
234 /* fc_interface_init_server() includes low level support like
235 * guaranteeing that fc_vsnprintf() will work after it,
236 * so this need to be early. */
238
239 i_am_server(); /* Tell to libfreeciv that we are server */
240
241#ifdef ENABLE_NLS
242 (void) bindtextdomain("freeciv-nations", get_locale_dir());
243#endif
244
245 /* This is before ai module initializations so that if ai module
246 * wants to use registry files, it can. */
248
249 /* We want this before any AI stuff */
251
252 /* This must be before command line argument parsing.
253 This allocates default ai, and we want that to take place before
254 loading additional ai modules from command line. */
255 ai_init();
256
257 /* Init server arguments... */
258
262 srvarg.identity_name[0] = '\0';
263 srvarg.serverid[0] = '\0';
264
266#ifdef FREECIV_JSON_CONNECTION
268#else /* FREECIV_JSON_CONNECTION */
270#endif /* FREECIV_JSON_CONNECTION */
271
273
275
279 srvarg.load_filename[0] = '\0';
284
285 srvarg.quitidle = 0;
286
292
293 /* Mark as initialized */
295
296 /* Init character encodings. */
298#ifdef ENABLE_NLS
300#endif
301
302 /* Initialize callbacks. */
304
305 /* Initialize global mutexes */
307
308 /* Done */
309 return;
310}
311
312/**********************************************************************/
315void handle_client_info(struct connection *pc, enum gui_type gui,
316 int emerg_version, const char *distribution)
317{
318 pc->client_gui = gui;
319 log_debug("%s's client has %s gui.", pc->username, gui_type_name(gui));
320 if (emerg_version > 0) {
321 log_debug("It's emergency release .%d", emerg_version);
322 }
323 if (strcmp(distribution, "")) {
324 log_debug("It comes from %s distribution.", distribution);
325 }
326
327 /* In case a modified client sends multiple client_info packets */
329
330 if (gui == GUI_WEB) {
332 }
333}
334
335/**********************************************************************/
339{
340 return civserver_state;
341}
342
343/**********************************************************************/
350
351/**********************************************************************/
355{
356 return (!game.info.is_new_game || S_S_INITIAL != server_state());
357}
358
359/**********************************************************************/
369{
370 int candidates, defeated;
371 struct player *victor;
372 int winners = 0;
373 struct astring str = ASTRING_INIT;
374
375 /* Check for scenario victory; dead players can win if they are on a team
376 * with the winners. */
377 players_iterate(pplayer) {
379 || get_player_bonus(pplayer, EFT_VICTORY) > 0) {
380 if (winners) {
381 /* TRANS: Another entry in winners list (", the Tibetans") */
382 astr_add(&str, Q_("?winners:, the %s"),
383 nation_plural_for_player(pplayer));
384 } else {
385 /* TRANS: Beginning of the winners list ("the French") */
386 astr_add(&str, Q_("?winners:the %s"),
387 nation_plural_for_player(pplayer));
388 }
389 pplayer->is_winner = TRUE;
390 winners++;
391 }
393 if (winners) {
395 /* TRANS: There can be several winners listed */
396 _("Scenario victory to %s."), astr_str(&str));
397 log_normal(_("Scenario victory to %s."), astr_str(&str));
398 astr_free(&str);
399 return TRUE;
400 }
401 astr_free(&str);
402
403 /* Count candidates for the victory. */
404 candidates = 0;
405 defeated = 0;
406 victor = NULL;
407 /* Do not use player_iterate_alive() here - dead player must be counted as
408 * defeated to end the game with a victory. */
409 players_iterate(pplayer) {
410 if (is_barbarian(pplayer)) {
411 continue;
412 }
413
414 if ((pplayer)->is_alive
415 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
416 candidates++;
417 victor = pplayer;
418 } else {
419 defeated++;
420 }
422
423 if (0 == candidates) {
425 _("Game is over."));
426 log_normal(_("Game is over."));
427 return TRUE;
428 } else {
429 if (0 < defeated) {
430 /* If nobody conceded the game, it mays be a solo game or a single team
431 * game. */
433
434 /* Quit if we have team victory. */
435 if (1 < team_count()) {
437 const struct player_list *members = team_members(pteam);
438 int team_candidates = 0, team_defeated = 0;
439
440 if (1 == player_list_size(members)) {
441 /* This is not really a team, single players are handled below. */
442 continue;
443 }
444
445 player_list_iterate(members, pplayer) {
446 if (pplayer->is_alive
447 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
449 } else {
451 }
453
456
458 /* We need a player in a other team to conced the game here. */
460 _("Team victory to %s."),
462 log_normal(_("Team victory to %s."), team_name_translation(pteam));
463 /* All players of the team win, even dead and surrended ones. */
464 player_list_iterate(members, pplayer) {
465 pplayer->is_winner = TRUE;
467 return TRUE;
468 }
470 }
471 }
472
473 /* Check for allied victory. */
476
477 /* Try to build a winner list. */
478 players_iterate_alive(pplayer) {
479 if (is_barbarian(pplayer)
480 || player_status_check((pplayer), PSTATUS_SURRENDER)) {
481 continue;
482 }
483
485 if (!pplayers_allied(aplayer, pplayer)) {
488 break;
489 }
491
492 if (NULL == winner_list) {
493 break;
494 }
497
498 if (NULL != winner_list) {
499 bool first = TRUE;
500
502
503 astr_init(&str);
505 if (first) {
506 /* TRANS: Beginning of the winners list ("the French") */
507 astr_add(&str, Q_("?winners:the %s"),
508 nation_plural_for_player(pplayer));
509 first = FALSE;
510 } else {
511 /* TRANS: Another entry in winners list (", the Tibetans") */
512 astr_add(&str, Q_("?winners:, the %s"),
513 nation_plural_for_player(pplayer));
514 }
515 pplayer->is_winner = TRUE;
518 /* TRANS: There can be several winners listed */
519 _("Allied victory to %s."), astr_str(&str));
520 log_normal(_("Allied victory to %s."), astr_str(&str));
521 astr_free(&str);
523 return TRUE;
524 }
525 }
526
527 /* Check for World Peace victory. */
530 bool first = TRUE;
531
532 astr_init(&str);
533
534 players_iterate_alive(pplayer) {
535 if (first) {
536 /* TRANS: Beginning of the winners list ("the French") */
537 astr_add(&str, Q_("?winners:the %s"),
538 nation_plural_for_player(pplayer));
539 first = FALSE;
540 } else {
541 /* TRANS: Another entry in winners list (", the Tibetans") */
542 astr_add(&str, Q_("?winners:, the %s"),
543 nation_plural_for_player(pplayer));
544 }
545
546 pplayer->is_winner = TRUE;
547
549
551 /* TRANS: There can be several winners listed */
552 _("World Peace victory to %s."), astr_str(&str));
553 log_normal(_("World Peace victory to %s."), astr_str(&str));
554 astr_free(&str);
555
556 return TRUE;
557 }
558 }
559
560 /* Check for single player victory. */
561 if (1 == candidates && NULL != victor) {
562 bool found = FALSE; /* We need at least one enemy defeated. */
563
564 players_iterate(pplayer) {
565 if (pplayer != victor
566 && !is_barbarian(pplayer)
567 && (!pplayer->is_alive
569 && pplayer->team != victor->team
571 || !pplayers_allied(victor, pplayer))) {
572 found = TRUE;
573 break;
574 }
576
577 if (found) {
579 _("Game ended in conquest victory for %s."), player_name(victor));
580 log_normal(_("Game ended in conquest victory for %s."), player_name(victor));
581 victor->is_winner = TRUE;
582 return TRUE;
583 }
584 }
585 }
586
587 /* Check for culture victory */
589 struct player *best = NULL;
590 int best_value = -1;
591 int second_value = -1;
592
593 players_iterate(pplayer) {
594 if (is_barbarian(pplayer) || !pplayer->is_alive) {
595 continue;
596 }
597
598 if (pplayer->score.culture > best_value) {
599 best = pplayer;
601 best_value = pplayer->score.culture;
602 } else if (pplayer->score.culture > second_value) {
603 second_value = pplayer->score.culture;
604 }
606
607 if (best != NULL && best_value >= game.info.culture_vic_points
608 && best_value > second_value * (100 + game.info.culture_vic_lead) / 100) {
610 _("Game ended in cultural domination victory for %s."),
611 player_name(best));
612 log_normal(_("Game ended in cultural domination victory for %s."),
613 player_name(best));
614 best->is_winner = TRUE;
615
616 return TRUE;
617 }
618 }
619
620 /* Quit if we are past the turn limit. */
623 _("Game ended as the turn limit was exceeded."));
624 log_normal(_("Game ended as the turn limit was exceeded."));
625 return TRUE;
626 } else if (game.info.turn == game.server.end_turn) {
627 /* Give them a chance to decide to extend the game */
629 _("Notice: game will end at the end of this turn due "
630 "to 'endturn' server setting."));
631 }
632
633 /* Check for a spacerace win (and notify of imminent arrivals).
634 * Check this after checking turn limit, because we are checking for
635 * the spaceship arriving in the year corresponding to the turn
636 * that's about to start. */
637 {
638 int n, i;
640
642
643 for (i = 0; i < n; i++) {
644 struct player *pplayer = arrivals[i];
645 const struct player_list *members;
646 bool win;
647
648 if (game.info.year < (int)spaceship_arrival(pplayer)) {
649 /* We are into the future arrivals */
650 break;
651 }
652
653 /* Mark as arrived and notify everyone. */
654 spaceship_arrived(pplayer);
655
656 if (!game.server.endspaceship) {
657 /* Games does not end on spaceship arrival. At least print all the
658 * arrival messages. */
659 continue;
660 }
661
662 /* This player has won, now check if anybody else wins with them. */
663 members = team_members(pplayer->team);
664 win = FALSE;
666 if (pplayer->is_alive
668 /* We need at least one player to be a winner candidate in the
669 * team. */
670 win = TRUE;
671 break;
672 }
674
675 if (!win) {
676 /* Let's try next arrival. */
677 continue;
678 }
679
680 if (1 < player_list_size(members)) {
682 _("Team victory to %s."),
683 team_name_translation(pplayer->team));
684 /* All players of the team win, even dead and surrendered ones. */
686 pteammate->is_winner = TRUE;
688 } else {
690 _("Game ended in victory for %s."), player_name(pplayer));
691 pplayer->is_winner = TRUE;
692 }
693 return TRUE;
694 }
695
696 /* Print notice(s) of imminent arrival. These are not infallible
697 * (quite apart from risk of enemy action) because arrival is
698 * year-based, and some effect may change the timeline between
699 * now and the end of the next turn.
700 * (Also the order of messages will not always indicate tie-breaks,
701 * if the shuffled order is changed every turn, as it is for
702 * PMT_CONCURRENT games.) */
703 for (; i < n; i++) {
704 const struct player *pplayer = arrivals[i];
705 struct packet_game_info next_info = game.info; /* struct copy */
706
707 /* Advance the calendar in a throwaway copy of game.info. */
709
710 if (next_info.year < (int)spaceship_arrival(pplayer)) {
711 /* Even further in the future */
712 break;
713 }
714
716 _("Notice: the %s spaceship will likely arrive at "
717 "Alpha Centauri next turn."),
719 }
720 }
721
722 return FALSE;
723}
724
725/**********************************************************************/
730void send_all_info(struct conn_list *dest)
731{
732 conn_list_iterate(dest, pconn) {
735 }
737
738 /* Resend player info because it could have more infos (e.g. embassy). */
739 send_player_all_c(NULL, dest);
743 send_map_info(dest);
748
752
756}
757
758/**********************************************************************/
762static void do_reveal_effects(void)
763{
764 phase_players_iterate(pplayer) {
765 if (get_player_bonus(pplayer, EFT_REVEAL_CITIES) > 0) {
766 players_iterate(other_player) {
767 city_list_iterate(other_player->cities, pcity) {
768 map_show_tile(pplayer, pcity->tile);
771 }
772 if (get_player_bonus(pplayer, EFT_REVEAL_MAP) > 0) {
773 /* map_know_all will mark all unknown tiles as known and send
774 * tile, unit, and city updates as necessary. No other actions are
775 * needed. */
776 map_show_all(pplayer);
777 }
779}
780
781/**********************************************************************/
785static void do_have_contacts_effect(void)
786{
787 phase_players_iterate(pplayer) {
788 if (get_player_bonus(pplayer, EFT_HAVE_CONTACTS) > 0) {
790 /* Note this gives pplayer contact with pother, but doesn't give
791 * pother contact with pplayer. This may cause problems in other
792 * parts of the code if we're not careful. */
793 make_contact(pplayer, pother, NULL);
795 }
797}
798
799/**********************************************************************/
802static void do_border_vision_effect(void)
803{
805 /* Border_Vision is useless. If borders are disabled there are no
806 * borders to see inside. If borders are seen they are seen already.
807 * The borders setting can't change after the game has started. */
808 return;
809 }
810
813
814 /* Check the Border_Vision effect for this player. */
816
817 if (new_border_vision != plr->server.border_vision) {
818 /* Border vision changed. */
819
820 /* Update the map */
822 }
824}
825
826/**********************************************************************/
830 int *current, int *accum, int *level,
831 int percent,
832 void (*upset_action_fn)(int))
833{
834 int count;
835
836 count = 0;
837 extra_type_iterate(cause) {
838 if (extra_causes_env_upset(cause, type)) {
839 whole_map_iterate(&(wld.map), ptile) {
840 if (tile_has_extra(ptile, cause)) {
841 count++;
842 }
844 }
846
847 *current = (count * percent) / 100;
848 *accum += count;
849 if (*accum < *level) {
850 *accum = 0;
851 } else {
852 *accum -= *level;
853 if (fc_rand((map_num_tiles() + 19) / 20) < *accum) {
854 upset_action_fn((MAP_NATIVE_WIDTH / 10) + (MAP_NATIVE_HEIGHT / 10) + ((*accum) * 5));
855 *accum = 0;
856 *level += (map_num_tiles() + 999) / 1000;
857 }
858 }
859
860 log_debug("environmental_upset: type=%-4d current=%-2d "
861 "level=%-2d accum=%-2d", type, *current, *level, *accum);
862}
863
864/**********************************************************************/
868 struct player *pguest,
869 int turns_left)
870{
871 int nunits = 0;
872 struct unit *a_unit = NULL;
873
875 struct tile *ptile = unit_tile(punit);
876
877 if (tile_owner(ptile) == phost
880 nunits++;
881 a_unit = punit;
882 }
884
885 if (nunits > 0) {
887
889 /* TRANS: "... 2 military units in Norwegian territory." */
890 PL_("Warning: you still have %d military unit in %s territory.",
891 "Warning: you still have %d military units in %s territory.",
892 nunits),
894 /* If there's one lousy unit left, we may as well include a link for it */
897 /* TRANS: %s is another, separately translated sentence,
898 * ending in a full stop. */
899 PL_("%s Any such units will be disbanded in %d turn, "
900 "in accordance with peace treaty.",
901 "%s Any such units will be disbanded in %d turns, "
902 "in accordance with peace treaty.", turns_left),
903 astr_str(&unitstr), turns_left);
905 }
906}
907
908/**********************************************************************/
911static void remove_illegal_armistice_units(struct player *plr1,
912 struct player *plr2)
913{
914 /* Remove illegal units */
916 struct tile *ptile = unit_tile(punit);
917
918 if (tile_owner(ptile) == plr2
922 _("Your %s was disbanded in accordance with "
923 "your peace treaty with the %s."),
927 }
929
931 struct tile *ptile = unit_tile(punit);
932
933 if (tile_owner(ptile) == plr1
937 _("Your %s was disbanded in accordance with "
938 "your peace treaty with the %s."),
942 }
944}
945
946/**********************************************************************/
950static void update_diplomatics(void)
951{
954 struct player_diplstate *state = player_diplstate_get(plr1, plr2);
955
956 /* Players might just met when first of them was being handled
957 * (pact with third player changed and units got bounced next
958 * to second unit to form first contact)
959 * Do not decrease the counters for the other player yet in this turn */
960 if (state->first_contact_turn != game.info.turn) {
961 struct player_diplstate *state2 = player_diplstate_get(plr2, plr1);
962
963 state->has_reason_to_cancel = MAX(state->has_reason_to_cancel - 1, 0);
964 state->contact_turns_left = MAX(state->contact_turns_left - 1, 0);
965
966 if (state->type == DS_ARMISTICE
967 /* Don't count down if auto canceled this turn. Auto canceling
968 * happens in this loop. */
969 && state->auto_cancel_turn != game.info.turn) {
970 state->turns_left--;
971 if (state->turns_left <= 0) {
972 state->type = DS_PEACE;
973 state2->type = DS_PEACE;
974 state->turns_left = 0;
975 state2->turns_left = 0;
977 } else {
978 notify_illegal_armistice_units(plr1, plr2, state->turns_left);
979 }
980 }
981
982 if (state->type == DS_CEASEFIRE) {
983 state->turns_left--;
984 switch (state->turns_left) {
985 case 1:
987 _("Concerned citizens point out that the cease-fire "
988 "with %s will run out soon."), player_name(plr2));
989 /* Message to plr2 will be done when plr1 and plr2 will be swapped.
990 * Else, we will get a message duplication. Note the case is not
991 * the below, because the state will be changed for both players to
992 * war. */
993 break;
994 case 0:
996 _("The cease-fire with %s has run out. "
997 "You are now at war with the %s."),
998 player_name(plr2),
1001 _("The cease-fire with %s has run out. "
1002 "You are now at war with the %s."),
1003 player_name(plr1),
1005 state->type = DS_WAR;
1006 state2->type = DS_WAR;
1007 state->turns_left = 0;
1008 state2->turns_left = 0;
1009
1010 enter_war(plr1, plr2);
1011
1014 sync_cities();
1015
1016 /* Avoid love-love-hate triangles */
1018 if (plr3 != plr1 && plr3 != plr2
1019 && pplayers_allied(plr3, plr1)
1020 && pplayers_allied(plr3, plr2)) {
1021 struct player_diplstate *to1
1022 = player_diplstate_get(plr3, plr1);
1023 struct player_diplstate *from1
1024 = player_diplstate_get(plr1, plr3);
1025 struct player_diplstate *to2
1026 = player_diplstate_get(plr3, plr2);
1027 struct player_diplstate *from2
1028 = player_diplstate_get(plr2, plr3);
1029 const char *plr1name = player_name(plr1);
1030 const char *plr2name = player_name(plr2);
1031 bool cancel1;
1032 bool cancel2;
1033
1034 if (players_on_same_team(plr3, plr1)) {
1036
1037 cancel1 = FALSE;
1038 cancel2 = TRUE;
1039
1041 _("The cease-fire between %s and %s has run out. "
1042 "They are at war. You cancel your alliance "
1043 "with %s."),
1045 } else if (players_on_same_team(plr3, plr2)) {
1046
1047 cancel1 = TRUE;
1048 cancel2 = FALSE;
1049
1051 _("The cease-fire between %s and %s has run out. "
1052 "They are at war. You cancel your alliance "
1053 "with %s."),
1055 } else {
1056
1057 cancel1 = TRUE;
1058 cancel2 = TRUE;
1059
1061 _("The cease-fire between %s and %s has run out. "
1062 "They are at war. You cancel your alliance "
1063 "with both."),
1064 player_name(plr1),
1065 player_name(plr2));
1066 }
1067
1068 if (cancel1) {
1069 /* Cancel the alliance. */
1070 to1->has_reason_to_cancel = 1;
1072
1073 /* Avoid asymmetric turns_left for the armistice. */
1074 to1->auto_cancel_turn = game.info.turn;
1075 from1->auto_cancel_turn = game.info.turn;
1076
1077 /* Count down for this turn. */
1078 to1->turns_left--;
1079 from1->turns_left--;
1080 }
1081
1082 if (cancel2) {
1083 /* Cancel the alliance. */
1084 to2->has_reason_to_cancel = 1;
1086
1087 /* Avoid asymmetric turns_left for the armistice. */
1088 to2->auto_cancel_turn = game.info.turn;
1089 from2->auto_cancel_turn = game.info.turn;
1090
1091 /* Count down for this turn. */
1092 to2->turns_left--;
1093 from2->turns_left--;
1094 }
1095 }
1097 break;
1098 }
1099 }
1100 }
1103}
1104
1105/**********************************************************************/
1112static void kill_dying_players(void)
1113{
1114 bool voter_died = FALSE;
1115
1116 players_iterate_alive(pplayer) {
1117 /* cities or units remain? */
1118 if (0 == city_list_size(pplayer->cities)
1119 && 0 == unit_list_size(pplayer->units)) {
1121 }
1122 /* also UTYF_GAMELOSS in unittools server_remove_unit() */
1123 if (player_status_check(pplayer, PSTATUS_DYING)) {
1124 /* Can't get more dead than this. */
1125 voter_died = voter_died || pplayer->is_connected;
1126 kill_player(pplayer);
1127 }
1129
1130 if (voter_died) {
1132 }
1133}
1134
1135/**********************************************************************/
1138static void ai_start_phase(void)
1139{
1140 phase_players_iterate(pplayer) {
1141 if (is_ai(pplayer)) {
1142 CALL_PLR_AI_FUNC(first_activities, pplayer, pplayer);
1143 }
1146}
1147
1148/**********************************************************************/
1153static void begin_turn(bool is_new_turn)
1154{
1155 log_debug("Begin turn");
1156
1158
1159 /* Reset this each turn. */
1160 if (is_new_turn) {
1164 }
1165 }
1166
1167 /* NB: Phase logic must match is_player_phase(). */
1168 switch (game.info.phase_mode) {
1169 case PMT_CONCURRENT:
1171 break;
1174 break;
1177 break;
1178 default:
1179 log_error("Unrecognized phase mode %d in begin_turn().",
1182 break;
1183 }
1185
1186 if (is_new_turn) {
1187 script_server_signal_emit("turn_begin",
1190 script_server_signal_emit("turn_started",
1191 game.info.turn > 0
1192 ? (lua_Integer)game.info.turn - 1
1195
1196 /* We build scores at the beginning of every turn. We have to
1197 * build them at the beginning so that the AI can use the data,
1198 * and we are sure to have it when we need it. */
1199 players_iterate(pplayer) {
1200 calc_civ_score(pplayer);
1203
1204 /* Retire useless barbarian units */
1205 players_iterate(pplayer) {
1206 unit_list_iterate_safe(pplayer->units, punit) {
1207 struct tile *ptile = punit->tile;
1208
1211 notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server,
1212 /* TRANS: %s is a unit type */
1213 _("%s retired!"), unit_tile_link(punit));
1215 continue;
1216 }
1219 }
1220
1221 /* find out if users attached to players have been attached to those players
1222 * for long enough. The first user to do so becomes "associated" to that
1223 * player for ranking purposes. */
1224 players_iterate(pplayer) {
1225 if (pplayer->unassigned_ranked
1226 && pplayer->user_turns++ > TURNS_NEEDED_TO_RANK
1227 && pplayer->is_alive) {
1228 sz_strlcpy(pplayer->ranked_username, pplayer->username);
1229 pplayer->unassigned_ranked = pplayer->unassigned_user;
1230 }
1232
1233 if (is_new_turn) {
1234 /* See if the value of fog of war has changed */
1236 if (game.info.fogofwar) {
1239 } else {
1242 }
1243 }
1244
1246 log_debug("Shuffleplayers");
1248 }
1249
1250 game.info.phase = 0;
1251 }
1252
1253 sanity_check();
1254}
1255
1256/**********************************************************************/
1260static void begin_phase(bool is_new_phase)
1261{
1262 log_debug("Begin phase");
1263
1265
1266 phase_players_iterate(pplayer) {
1268 /* Otherwise respect what was loaded from the savegame. */
1269 pplayer->phase_done = FALSE;
1270 }
1271 pplayer->ai_phase_done = FALSE;
1274
1276
1277 if (!is_new_phase || game.info.turn == FIRST_TURN) {
1278 /* Starting from a savegame or from the very beginning */
1282 }
1283
1284 /* Must be the first thing as it is needed for lots of functions below! */
1285 phase_players_iterate(pplayer) {
1286 /* Human players also need this for building advice */
1288 CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, is_new_phase);
1290
1291 if (is_new_phase) {
1292 /* Unit "end of turn" activities - of course these actually go at
1293 * the start of the turn! */
1294 whole_map_iterate(&(wld.map), ptile) {
1295 if (ptile->placing != NULL) {
1296 struct player *owner = NULL;
1297
1299 owner = tile_owner(ptile);
1300 } else {
1301 struct city *pcity = tile_worked(ptile);
1302
1303 if (pcity != NULL) {
1305 }
1306 }
1307
1308 if (owner == NULL) {
1309 /* Abandoned extra placing, clear it. */
1310 ptile->placing = NULL;
1311 } else {
1313 fc_assert(ptile->infra_turns > 0);
1314
1315 ptile->infra_turns--;
1316 if (ptile->infra_turns <= 0) {
1317 create_extra(ptile, ptile->placing, owner);
1318 ptile->placing = NULL;
1319
1320 /* Since extra has been added, tile is certainly
1321 * sent by update_tile_knowledge() including the
1322 * placing info, though it would not sent it if placing
1323 * were the only thing changed. */
1324 update_tile_knowledge(ptile);
1325 }
1326 }
1327 }
1328 }
1330
1331 phase_players_iterate(pplayer) {
1332 update_unit_activities(pplayer);
1333 flush_packets();
1335
1336 /* Execute orders after activities have been completed (roads built,
1337 * pillage done, etc.). */
1338 phase_players_iterate(pplayer) {
1339 int plrid = player_number(pplayer);
1340
1341 script_server_signal_emit("player_phase_begin", pplayer, is_new_phase);
1342 if (player_by_number(plrid) != pplayer) {
1343 /* Removed */
1344 continue;
1345 }
1346 flush_packets();
1348
1349 phase_players_iterate(pplayer) {
1350 city_tc_effect_refresh(pplayer);
1351 unit_tc_effect_refresh(pplayer);
1353
1354 phase_players_iterate(pplayer) {
1357
1358 flush_packets();
1359 }
1360
1361 phase_players_iterate(pplayer) {
1362 log_debug("beginning player turn for #%d (%s)",
1363 player_number(pplayer), player_name(pplayer));
1364 if (is_human(pplayer)) {
1365 building_advisor(pplayer);
1366 }
1368
1369 phase_players_iterate(pplayer) {
1370 send_player_cities(pplayer);
1372
1373 flush_packets(); /* To curb major city spam */
1375
1377 update_revolution(pplayer);
1378 update_capital(pplayer);
1380
1381 if (is_new_phase) {
1382 /* Try to avoid hiding events under a diplomacy dialog */
1383 phase_players_iterate(pplayer) {
1384 if (is_ai(pplayer)) {
1385 CALL_PLR_AI_FUNC(diplomacy_actions, pplayer, pplayer);
1386 }
1388
1389 /* Spend random movement move points before any controlled actions */
1390 phase_players_iterate(pplayer) {
1391 random_movements(pplayer);
1393
1394 log_debug("Aistartturn");
1396
1397 flush_packets();
1398 phase_players_iterate(pplayer) {
1399 unit_list_iterate_safe(pplayer->units, punit) {
1402 }
1404 execute_unit_orders(pplayer);
1405 flush_packets();
1407 } else {
1408 phase_players_iterate(pplayer) {
1409 if (is_ai(pplayer)) {
1410 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
1411 }
1413 }
1414
1415 sanity_check();
1416
1422 ? NULL : "phase");
1425
1426 if (game.server.num_phases == 1) {
1427 /* All players in the same phase.
1428 * This means that AI has been handled above, and server
1429 * will be responsive again */
1431 }
1432}
1433
1434/**********************************************************************/
1438static void end_phase(void)
1439{
1440 log_debug("Endphase");
1441
1442 /*
1443 * This empties the client Messages window; put this before
1444 * everything else below, since otherwise any messages from the
1445 * following parts get wiped out before the user gets a chance to
1446 * see them. --dwp
1447 */
1448 phase_players_iterate(pplayer) {
1449 /* Unlike the start_phase packet we only send this one to the active
1450 * player. */
1451 lsend_packet_end_phase(pplayer->connections);
1453
1454 /* Enact any government and/or policy changes.
1455 * Do this first so that following end-phase activities take the
1456 * change into account. */
1457 phase_players_iterate(pplayer) {
1458 if (pplayer->revolution_finishes <= game.info.turn
1459 && pplayer->target_government != NULL
1460 && pplayer->target_government != game.government_during_revolution
1461 && pplayer->target_government != pplayer->government) {
1462 government_change(pplayer, pplayer->target_government, TRUE);
1463 }
1464
1465 multipliers_iterate(pmul) {
1466 int idx = multiplier_index(pmul);
1467
1468 if (!multiplier_can_be_changed(pmul, pplayer)) {
1469 if (pplayer->multipliers[idx].value != pmul->def) {
1471 _("%s restored to the default value %d"),
1473 pmul->def);
1474 pplayer->multipliers[idx].value = pmul->def;
1475 pplayer->multipliers[idx].changed = game.info.turn;
1476 }
1477 } else {
1478 if (pplayer->multipliers[idx].value != pplayer->multipliers[idx].target) {
1480 _("%s now at value %d"),
1482 pplayer->multipliers[idx].target);
1483
1484 pplayer->multipliers[idx].value = pplayer->multipliers[idx].target;
1485 pplayer->multipliers[idx].changed = game.info.turn;
1486 }
1487 }
1490
1491 phase_players_iterate(pplayer) {
1492 struct research *presearch = research_get(pplayer);
1493
1494 if (A_UNSET == presearch->researching) {
1496 presearch->tech_goal);
1497
1498 if (A_UNSET != next_tech) {
1500 } else {
1502 }
1503 /* Add the researched bulbs to the pool; do *NOT* check for finished
1504 * research */
1505 update_bulbs(pplayer, 0, FALSE, FALSE);
1506 }
1508
1509 /* Freeze sending of cities. */
1511
1512 /* AI end of turn activities */
1513 players_iterate(pplayer) {
1514 unit_list_iterate(pplayer->units, punit) {
1515 CALL_PLR_AI_FUNC(unit_turn_end, pplayer, punit);
1518 phase_players_iterate(pplayer) {
1519 auto_workers_player(pplayer);
1520 if (is_ai(pplayer)) {
1521 CALL_PLR_AI_FUNC(last_activities, pplayer, pplayer);
1522 }
1524
1525 /* Refresh cities */
1526 phase_players_iterate(pplayer) {
1527 research_get(pplayer)->free_bulbs = 0;
1529
1531 int plrid = player_number(pplayer);
1532 int old_gold;
1533
1534 do_tech_parasite_effects(pplayer);
1535 script_server_signal_emit("player_alive_phase_end", pplayer);
1536 if (player_by_number(plrid) != pplayer) {
1537 /* Removed */
1538 continue;
1539 }
1540 if (!pplayer->is_alive) {
1541 /* Died */
1542 continue;
1543 }
1544 player_restore_units(pplayer);
1545
1546 /* If player finished spaceship parts last turn already, and didn't place them
1547 * during this entire turn, autoplace them. */
1548 if (adv_spaceship_autoplace(pplayer, &pplayer->spaceship)) {
1550 _("Automatically placed spaceship parts that were still not placed."));
1551 }
1552
1553 old_gold = pplayer->economic.gold;
1554 pplayer->server.bulbs_last_turn = 0;
1555
1556 update_city_activities(pplayer);
1557
1559
1562
1563 flush_packets();
1565
1566 /* Some player/global effect may have changed cities' vision range */
1567 phase_players_iterate(pplayer) {
1570
1572
1573 /* Unfreeze sending of cities. */
1575
1576 phase_players_iterate(pplayer) {
1577 send_player_cities(pplayer);
1579 flush_packets(); /* to curb major city spam */
1580
1584
1585 phase_players_iterate(pplayer) {
1586 int plrid = player_number(pplayer);
1587
1588 script_server_signal_emit("player_phase_end", pplayer);
1589 if (player_by_number(plrid) != pplayer) {
1590 /* removed */
1591 continue;
1592 }
1593 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1594 /* This has to be after all access to advisor data. */
1595 /* We used to run this for ai players only, but data phase
1596 is initialized for human players also. */
1597 adv_data_phase_done(pplayer);
1599}
1600
1601/**********************************************************************/
1604static void end_turn(void)
1605{
1606 log_debug("Endturn");
1607
1608 /* Hack: because observer players never get an end-phase packet we send
1609 * one here. */
1611 if (NULL == pconn->playing) {
1613 }
1615
1617
1619
1620 /* Update city's counter values */
1621 players_iterate(pplayer) {
1622 city_list_iterate(pplayer->cities, pcity) {
1624 if (pcount->type == CB_CITY_OWNED_TURNS) {
1625 pcity->counter_values[pcount->index]++;
1626 }
1631
1632#ifdef FREECIV_DEBUG
1633 /* Output some AI measurement information
1634 * log_debug() means that the values would never be used outside FREECIV_DEBUG
1635 * build even if we calculated them. */
1636 players_iterate(pplayer) {
1637 int food = 0, shields = 0, trade = 0, settlers = 0;
1638
1639 if (!is_ai(pplayer) || is_barbarian(pplayer)) {
1640 continue;
1641 }
1642
1643 unit_list_iterate(pplayer->units, punit) {
1645 settlers++;
1646 }
1648
1649 city_list_iterate(pplayer->cities, pcity) {
1650 shields += pcity->prod[O_SHIELD];
1651 food += pcity->prod[O_FOOD];
1652 trade += pcity->prod[O_TRADE];
1654
1655 log_debug("%s T%d cities:%d pop:%d food:%d prod:%d "
1656 "trade:%d settlers:%d units:%d", player_name(pplayer),
1657 game.info.turn, city_list_size(pplayer->cities),
1658 total_player_citizens(pplayer), food, shields, trade,
1659 settlers, unit_list_size(pplayer->units));
1660
1662#endif /* FREECIV_DEBUG */
1663
1664 log_debug("Season of native unrests");
1665 summon_barbarians(); /* wild guess really, no idea where to put it, but
1666 * I want to give them chance to move their units */
1667
1668 if (game.server.migration) {
1669 log_debug("Season of migrations");
1670 if (check_city_migrations()) {
1671 /* Make sure everyone has updated information about BOTH ends of the
1672 * migration movements. */
1673 players_iterate(plr) {
1674 city_list_iterate(plr->cities, pcity) {
1678 }
1679 }
1680
1682
1683 /* Check for new achievements during the turn.
1684 * This is not within phase, as multiple players may
1685 * achieve at the same turn and everyone deserves equal opportunity
1686 * to win. */
1688 struct player_list *achievers = player_list_new();
1689 struct player *first = achievement_plr(ach, achievers);
1691
1692 pack.id = achievement_index(ach);
1693 pack.gained = TRUE;
1694
1695 if (first != NULL) {
1697 "%s", achievement_first_msg(ach));
1698
1699 pack.first = TRUE;
1700
1702
1703 script_server_signal_emit("achievement_gained", ach, first, TRUE);
1704
1705 }
1706
1707 pack.first = FALSE;
1708
1709 if (!ach->unique) {
1710 player_list_iterate(achievers, pplayer) {
1711 /* Message already sent to first one */
1712 if (pplayer != first) {
1714 "%s", achievement_later_msg(ach));
1715
1716 lsend_packet_achievement_info(pplayer->connections, &pack);
1717
1718 script_server_signal_emit("achievement_gained", ach, pplayer,
1719 FALSE);
1720 }
1722 }
1723
1724 player_list_destroy(achievers);
1726
1727 if (game.info.global_warming) {
1733 }
1734
1735 if (game.info.nuclear_winter) {
1741 }
1742
1743 /* Handle disappearing extras before appearing extras ->
1744 * Extra never appears only to disappear at the same turn,
1745 * but it can disappear and reappear. */
1747 whole_map_iterate(&(wld.map), ptile) {
1748 if (tile_has_extra(ptile, pextra)
1749 && fc_rand(10000) < pextra->disappearance_chance
1750 && can_extra_disappear(pextra, ptile)) {
1751 tile_extra_rm_apply(ptile, pextra);
1752
1753 update_tile_knowledge(ptile);
1754
1755 if (tile_owner(ptile) != NULL) {
1756 /* TODO: Should notify players nearby even when borders disabled,
1757 * like in case of barbarian uprising */
1758 notify_player(tile_owner(ptile), ptile,
1760 /* TRANS: Small Fish disappears from (32, 72). */
1761 _("%s disappears from %s."),
1762 extra_name_translation(pextra),
1763 tile_link(ptile));
1764 }
1765
1766 /* Activities at the target tile and its neighbors may now
1767 * be illegal because of present reqs. */
1769 }
1772
1774 whole_map_iterate(&(wld.map), ptile) {
1775 if (!tile_has_extra(ptile, pextra)
1776 && fc_rand(10000) < pextra->appearance_chance
1777 && can_extra_appear(pextra, ptile)) {
1778
1779 tile_extra_apply(ptile, pextra);
1780
1781 update_tile_knowledge(ptile);
1782
1783 if (tile_owner(ptile) != NULL) {
1784 /* TODO: Should notify players nearby even when borders disabled,
1785 * like in case of barbarian uprising */
1786 notify_player(tile_owner(ptile), ptile,
1788 /* TRANS: Small Fish appears to (32, 72). */
1789 _("%s appears to %s."),
1790 extra_name_translation(pextra),
1791 tile_link(ptile));
1792 }
1793
1794 /* Activities at the target tile and its neighbors may now
1795 * be illegal because of !present reqs. */
1797 }
1800
1802
1805 settings_turn();
1807 voting_turn();
1809
1810 log_debug("Gamenextyear");
1812 players_iterate_alive(pplayer) {
1813 pplayer->turns_alive++;
1815
1816 log_debug("Updatetimeout");
1818
1819 log_debug("Sendgameinfo");
1821
1822 log_debug("Sendplayerinfo");
1824
1825 log_debug("Sendresearchinfo");
1829
1830 log_debug("Sendyeartoclients");
1832}
1833
1834/**********************************************************************/
1837void save_game_auto(const char *save_reason, enum autosave_type type)
1838{
1839 char filename[512];
1840 const char *reason_filename = NULL;
1841
1842 if (!(game.server.autosaves & (1 << type))) {
1843 return;
1844 }
1845
1846 switch (type) {
1847 case AS_TURN:
1849 break;
1850 case AS_GAME_OVER:
1851 reason_filename = "final";
1852 break;
1853 case AS_QUITIDLE:
1854 reason_filename = "quitidle";
1855 break;
1856 case AS_INTERRUPT:
1857 reason_filename = "interrupted";
1858 break;
1859 case AS_TIMER:
1860 reason_filename = "timer";
1861 break;
1862 }
1863
1865
1866 if (type != AS_TIMER) {
1867 generate_save_name(game.server.save_name, filename, sizeof(filename),
1869 } else {
1870 fc_snprintf(filename, sizeof(filename), "%s-timer", game.server.save_name);
1871 }
1872 save_game(filename, save_reason, FALSE);
1873}
1874
1875/**********************************************************************/
1878void start_game(void)
1879{
1880 if (S_S_INITIAL != server_state()) {
1881 con_puts(C_SYNTAX, _("The game is already running."));
1882 return;
1883 }
1884
1885 /* Remove ALLOW_CTRL from whoever has it (gotten from 'first'). */
1887 if (pconn->access_level == ALLOW_CTRL) {
1889 _("%s lost control cmdlevel on "
1890 "game start. Use voting from now on."),
1891 pconn->username);
1893 }
1896
1897 con_puts(C_OK, _("Starting game."));
1898
1899 /* Prevent problems with commands that only make sense in pregame. */
1901
1902 /* This value defines if the player data should be saved for a scenario. It
1903 * is only FALSE if the editor was used to set it to this value. For
1904 * such scenarios it has to be reset at game start so that player data
1905 * is saved. */
1907
1909 /* There's no stateful packet set to client until srv_ready(). */
1910}
1911
1912/**********************************************************************/
1916{
1917 if (server_state() == S_S_RUNNING) {
1918 /* Quitting mid-game. */
1919
1920 phase_players_iterate(pplayer) {
1921 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1922 /* This has to be after all access to advisor data. */
1923 /* We used to run this for ai players only, but data phase
1924 is initialized for human players also. */
1925 adv_data_phase_done(pplayer);
1927 }
1928
1930
1931 if (game.server.save_timer != NULL) {
1934 }
1935 if (between_turns != NULL) {
1938 }
1939 if (eot_timer != NULL) {
1941 }
1943 mapimg_free();
1945 voting_free();
1947 ai_timer_free();
1948 if (game.server.phase_timer != NULL) {
1951 }
1952 if (game.server.save_timer != NULL) {
1955 }
1956
1957#ifdef HAVE_FCDB
1958 if (srvarg.fcdb_enabled) {
1959 /* If freeciv database has been initialized */
1960 fcdb_free();
1961 }
1962#endif /* HAVE_FCDB */
1963
1964 modpacks_free();
1965 settings_free();
1967 edithand_free();
1968 voting_free();
1972 CALL_FUNC_EACH_AI(module_close);
1977 con_log_close();
1981
1983}
1984
1985/**********************************************************************/
1989{
1990 struct conn_list *dest = pconn->self;
1991
1992 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
1993 log_error("Got a report request %d before game start", type);
1994 return;
1995 }
1996
1997 if (NULL == pconn->playing && !pconn->observer) {
1998 log_error("Got a report request %d from detached connection", type);
1999 return;
2000 }
2001
2002 switch (type) {
2005 return;
2008 return;
2009 case REPORT_TOP_CITIES:
2010 report_top_cities(dest);
2011 return;
2012 case REPORT_DEMOGRAPHIC:
2014 return;
2017 return;
2018 }
2019
2021 _("request for unknown report (type %d)"), type);
2022}
2023
2024/**********************************************************************/
2028{
2030}
2031
2032/**********************************************************************/
2036{
2038}
2039
2040/**********************************************************************/
2043static bool identity_number_is_used(int id)
2044{
2045 return BV_ISSET(identity_numbers_used, id);
2046}
2047
2048/**********************************************************************/
2052{
2053 server.identity_number = (server.identity_number + 1) % IDENTITY_NUMBER_SIZE;
2054 return server.identity_number;
2055}
2056
2057/**********************************************************************/
2062{
2063 int retries = 0;
2064
2066 /* Try again */
2067 if (++retries >= IDENTITY_NUMBER_SIZE) {
2068 /* Always fails. */
2070 "Exhausted city and unit numbers!");
2071 }
2072 }
2073 identity_number_reserve(server.identity_number);
2074 return server.identity_number;
2075}
2076
2077/**********************************************************************/
2084{
2086}
2087
2088/**********************************************************************/
2092bool server_packet_input(struct connection *pconn, void *packet, int type)
2093{
2094 struct player *pplayer;
2095
2096 /* a NULL packet can be returned from receive_packet_goto_route() */
2097 if (!packet) {
2098 return TRUE;
2099 }
2100
2101 /*
2102 * Old pre-delta clients (before 2003-11-28) send a
2103 * PACKET_LOGIN_REQUEST (type 0) to the server. We catch this and
2104 * reply with an old reject packet. Since there is no struct for
2105 * this old packet anymore we build it by hand.
2106 */
2107 if (type == 0) {
2108 unsigned char buffer[4096];
2109 struct raw_data_out dout;
2110
2111 log_normal(_("Warning: rejecting old client %s"),
2113
2114 dio_output_init(&dout, buffer, sizeof(buffer));
2116
2117 /* 1 == PACKET_LOGIN_REPLY in the old client */
2119
2122 _("Your client is too old. To use this server, "
2123 "please upgrade your client to a "
2124 "Freeciv 2.2 or later."));
2126
2127 {
2128 size_t size = dio_output_used(&dout);
2131
2132 /*
2133 * Use send_connection_data instead of send_packet_data to avoid
2134 * compression.
2135 */
2137 }
2138
2139 return FALSE;
2140 }
2141
2144 (struct packet_server_join_req *) packet);
2145 }
2146
2147 /* May be received on a non-established connection. */
2149 return auth_handle_reply(pconn,
2150 ((struct packet_authentication_reply *)
2151 packet)->password);
2152 }
2153
2154 if (type == PACKET_CONN_PONG) {
2156 return TRUE;
2157 }
2158
2159 if (!pconn->established) {
2160 log_error("Received game packet %s(%d) from unaccepted connection %s.",
2162 return TRUE;
2163 }
2164
2165 /* valid packets from established connections but non-players */
2175
2176 /* Except for PACKET_EDIT_MODE (used to set edit mode), check
2177 * that the client is allowed to send the given edit packet. */
2179 && !can_conn_edit(pconn)) {
2181 _("You are not allowed to edit."));
2182 return TRUE;
2183 }
2184
2185 if (!server_handle_packet(type, packet, NULL, pconn)) {
2186 log_error("Received unknown packet %d from %s.",
2188 }
2189 return TRUE;
2190 }
2191
2192 pplayer = pconn->playing;
2193
2194 if (NULL == pplayer || pconn->observer) {
2195 if (type == PACKET_PLAYER_READY && pconn->observer) {
2197 return TRUE;
2198 }
2199 /* don't support these yet */
2200 log_error("Received packet %s(%d) from non-player connection %s.",
2202 return TRUE;
2203 }
2204
2205 if (S_S_RUNNING != server_state()
2210 && type != PACKET_SYNC_SERIAL) {
2211 if (S_S_OVER == server_state()) {
2212 /* This can happen by accident, so we don't want to print
2213 * out lots of error messages. Ie, we use log_debug(). */
2214 log_debug("Got a packet of type %s(%d) in %s.",
2216 } else {
2217 log_error("Got a packet of type %s(%d) outside %s.",
2219 }
2220 return TRUE;
2221 }
2222
2223 pplayer->nturns_idle = 0;
2224
2225 if (!pplayer->is_alive && type != PACKET_REPORT_REQ) {
2226 log_error("Got a packet of type %s(%d) from a dead player.",
2228 return TRUE;
2229 }
2230
2231 /* Make sure to set this back to NULL before leaving this function: */
2232 pplayer->current_conn = pconn;
2233
2234 if (!server_handle_packet(type, packet, pplayer, pconn)) {
2235 log_error("Received unknown packet %d from %s.",
2237 }
2238
2239 if (S_S_RUNNING == server_state()
2240 && type != PACKET_PLAYER_READY) {
2241 /* handle_player_ready() calls start_game(), but the game isn't started
2242 * until the main loop is re-entered, so kill_dying_players would think
2243 * all players are dead. This should be solved by adding a new
2244 * game state (now S_S_GENERATING_WAITING). */
2246 }
2247
2248 pplayer->current_conn = NULL;
2249 return TRUE;
2250}
2251
2252/**********************************************************************/
2257{
2258 bool connected = FALSE;
2259
2260 if (S_S_RUNNING != server_state()) {
2261 /* Not in a running state, no turn done. */
2262 return;
2263 }
2264
2265 /* fixedlength is only applicable if we have a timeout set */
2267 return;
2268 }
2269
2270 /* If there are no connected players, don't automatically advance. This is
2271 * a hack to prevent all-AI games from running rampant. Note that if
2272 * timeout is set to -1 this function call is skipped entirely and the
2273 * server will run rampant. */
2274 players_iterate_alive(pplayer) {
2275 if (pplayer->is_connected && (is_human(pplayer) || pplayer->phase_done)) {
2276 connected = TRUE;
2277 break;
2278 }
2280
2281 if (!connected) {
2282 return;
2283 }
2284
2285 phase_players_iterate(pplayer) {
2286 if (!pplayer->phase_done && pplayer->is_alive) {
2287 if (pplayer->is_connected) {
2288 /* In all cases, we wait for any connected players. */
2289 return;
2290 }
2291 if (game.server.turnblock && is_human(pplayer)) {
2292 /* If turnblock is enabled check for human players, connected
2293 * or not. */
2294 return;
2295 }
2296 if (is_ai(pplayer) && !pplayer->ai_phase_done) {
2297 /* AI player has not finished */
2298 return;
2299 }
2300 }
2302
2304}
2305
2306/**********************************************************************/
2312{
2313 if (!game_was_started() && 0 < map_startpos_count()) {
2314 /* Restrict nations to those for which start positions are defined. */
2315 nations_iterate(pnation) {
2316 fc_assert_action_msg(NULL == pnation->player,
2317 if (pnation->player->nation == pnation) {
2318 /* At least assignment is consistent. Leave nation assigned,
2319 * and make sure that nation is also marked pickable. */
2320 pnation->server.no_startpos = FALSE;
2321 continue;
2322 } else if (NULL != pnation->player->nation) {
2323 /* Not consistent. Just initialize the pointer and hope for the
2324 * best. */
2325 pnation->player->nation->player = NULL;
2326 pnation->player = NULL;
2327 } else {
2328 /* Not consistent. Just initialize the pointer and hope for the
2329 * best. */
2330 pnation->player = NULL;
2331 }, "Player assigned to nation before %s()!", __FUNCTION__);
2332
2333 if (nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
2334 /* Always allow land and sea barbarians regardless of start
2335 * positions. */
2336 pnation->server.no_startpos = FALSE;
2337 } else {
2338 /* Restrict the set of nations offered to players, based on
2339 * start positions.
2340 * If there are no start positions for a nation, remove it from the
2341 * available set. */
2342 pnation->server.no_startpos = TRUE;
2344 if (startpos_nation_allowed(psp, pnation)) {
2345 /* There is at least one start position that allows this nation,
2346 * so allow it to be picked.
2347 * (Depending on what nations players actually pick, it's not
2348 * guaranteed that the server can always find a match between
2349 * nations in this subset and start positions, in which case the
2350 * server may create mismatches.) */
2351 pnation->server.no_startpos = FALSE;
2352 break;
2353 }
2355 }
2357 } else {
2358 /* Not restricting nations by start positions. */
2359 nations_iterate(pnation) {
2360 pnation->server.no_startpos = FALSE;
2362 }
2363}
2364
2365/**********************************************************************/
2370void handle_nation_select_req(struct connection *pc, int player_no,
2371 Nation_type_id nation_no, bool is_male,
2372 const char *name, int style)
2373{
2374 struct nation_type *new_nation;
2375 struct player *pplayer = player_by_number(player_no);
2376
2377 if (!pplayer || !can_conn_edit_players_nation(pc, pplayer)) {
2378 return;
2379 }
2380
2381 new_nation = nation_by_number(nation_no);
2382
2384 char message[1024];
2385
2386 /* check sanity of the packet sent by client */
2388 return;
2389 }
2390
2393 _("%s nation is not available for user selection."),
2395 return;
2396 }
2397 if (new_nation->player && new_nation->player != pplayer) {
2399 _("%s nation is already in use."),
2401 return;
2402 }
2403
2405 message, sizeof(message))) {
2407 ftc_server, "%s", message);
2408 return;
2409 }
2410
2411 /* Should be caught by is_nation_pickable() */
2413
2415 _("%s is the %s ruler %s."),
2416 pplayer->username,
2418 player_name(pplayer));
2419
2420 pplayer->is_male = is_male;
2421 pplayer->style = style_by_number(style);
2422 } else if (name[0] == '\0') {
2423 char message[1024];
2424
2426 message, sizeof(message));
2427 }
2428
2429 (void) player_set_nation(pplayer, new_nation);
2431}
2432
2433/**********************************************************************/
2437{
2438 if (pconn->access_level == ALLOW_HACK) {
2439 players_iterate(plr) {
2440 if (is_human(plr)) {
2441 return;
2442 }
2444
2446 }
2447}
2448
2449/**********************************************************************/
2453 int player_no,
2454 bool is_ready)
2455{
2456 struct player *pplayer = player_by_number(player_no);
2457
2458 if (NULL == pplayer || S_S_INITIAL != server_state()) {
2459 return;
2460 }
2461
2462 if (pplayer != requestor) {
2463 /* Currently you can only change your own readiness. */
2464 return;
2465 }
2466
2467 pplayer->is_ready = is_ready;
2468 send_player_info_c(pplayer, NULL);
2469
2470 /* Note this is called even if the player has pressed /start once
2471 * before. For instance, when a player leaves everyone remaining
2472 * might have pressed /start already but the start won't happen
2473 * until someone presses it again. Also you can press start more
2474 * than once to remind other people to start (which is a good thing
2475 * until somebody does it too much and it gets labeled as spam). */
2476 if (is_ready) {
2477 int num_ready = 0, num_unready = 0;
2478
2479 players_iterate_alive(other_player) {
2480 if (other_player->is_connected) {
2481 if (other_player->is_ready) {
2482 num_ready++;
2483 } else {
2484 num_unready++;
2485 }
2486 }
2488
2489 if (num_unready > 0) {
2491 _("Waiting to start game: %d out of %d alive players "
2492 "are ready to start."),
2494 } else {
2495 /* Check minplayers etc. and then start */
2497 }
2498 }
2499}
2500
2501/**********************************************************************/
2506const char *aifill(int amount)
2507{
2508 char *limitreason = NULL;
2509 int limit;
2510
2511 if (game_was_started()) {
2512 return NULL;
2513 }
2514
2516 if (limit < amount) {
2517 limitreason = _("requested more than 'maxplayers' setting");
2518 }
2519
2520 /* Limit to nations provided by ruleset */
2521 if (limit > server.playable_nations) {
2522 limit = server.playable_nations;
2523 if (nation_set_count() > 1) {
2524 limitreason = _("not enough playable nations in this nation set "
2525 "(see 'nationset' setting)");
2526 } else {
2527 limitreason = _("not enough playable nations");
2528 }
2529 }
2530
2531 if (limit < player_count()) {
2532 int removal = player_slot_count() - 1;
2533
2534 while (limit < player_count() && 0 <= removal) {
2535 struct player *pplayer = player_by_number(removal);
2536
2537 removal--;
2538 if (!pplayer) {
2539 continue;
2540 }
2541
2542 if (!pplayer->is_connected && !pplayer->was_created) {
2543 server_remove_player(pplayer);
2544 }
2545 }
2546
2547 /* 'limit' can be different from 'player_count()' at this point if
2548 * there are more human or created players than the 'limit'. */
2549 return limitreason;
2550 }
2551
2552 while (limit > player_count()) {
2554 int filled = 1;
2555 struct player *pplayer;
2556
2558 NULL, FALSE);
2559 /* !game_was_started() so no need to assign_player_colors() */
2560 if (!pplayer) {
2561 break;
2562 }
2563 server_player_init(pplayer, FALSE, TRUE);
2564
2565 player_set_nation(pplayer, NULL);
2566
2567 do {
2568 fc_snprintf(leader_name, sizeof(leader_name), "AI*%d", filled++);
2569 } while (player_by_name(leader_name));
2571 pplayer->random_name = TRUE;
2572 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
2573 pplayer->unassigned_user = TRUE;
2574
2576 set_as_ai(pplayer);
2578
2579 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
2580
2581 log_normal(_("%s has been added as %s level AI-controlled player (%s)."),
2582 player_name(pplayer),
2584 ai_name(pplayer->ai));
2586 _("%s has been added as %s level AI-controlled player (%s)."),
2587 player_name(pplayer),
2589 ai_name(pplayer->ai));
2590
2591 send_player_info_c(pplayer, NULL);
2592 }
2593
2594 return limitreason;
2595}
2596
2597/**********************************************************************/
2600#define SPECHASH_TAG startpos
2601#define SPECHASH_IKEY_TYPE struct startpos *
2602#define SPECHASH_INT_DATA_TYPE
2603#include "spechash.h"
2604#define startpos_hash_iterate(hash, psp, c) \
2605 TYPED_HASH_ITERATE(struct startpos *, intptr_t, hash, psp, c)
2606#define startpos_hash_iterate_end HASH_ITERATE_END
2607
2608/**********************************************************************/
2611static void player_set_nation_full(struct player *pplayer,
2612 struct nation_type *pnation)
2613{
2614 /* Don't change the name of a created player. */
2615 player_nation_defaults(pplayer, pnation, pplayer->random_name);
2616}
2617
2618/**********************************************************************/
2621void player_nation_defaults(struct player *pplayer, struct nation_type *pnation,
2622 bool set_name)
2623{
2624 struct nation_leader *pleader;
2625
2626 fc_assert(NO_NATION_SELECTED != pnation);
2627 player_set_nation(pplayer, pnation);
2628 fc_assert(pnation == pplayer->nation);
2629
2630 pplayer->style = style_of_nation(pnation);
2631
2632 if (set_name) {
2634 }
2635
2636 if ((pleader = nation_leader_by_name(pnation, player_name(pplayer)))) {
2638 } else {
2639 pplayer->is_male = (fc_rand(2) == 1);
2640 }
2641
2642 ai_traits_init(pplayer);
2643}
2644
2645/**********************************************************************/
2672static void generate_players(void)
2673{
2674 int nations_to_assign = 0;
2675
2676 /* Announce players who already have nations, and select nations based
2677 * on player names. */
2678 players_iterate(pplayer) {
2679 if (pplayer->nation != NO_NATION_SELECTED) {
2680 /* Traits are initialized here, and not already when nation gets
2681 * picked, as player may change their mind after picking one nation,
2682 * and picks another and we want to init traits only once, for the
2683 * correct nation. */
2684 ai_traits_init(pplayer);
2685 announce_player(pplayer);
2686 continue;
2687 }
2688
2689 /* See if the player name matches a known leader name.
2690 * If more than one nation has this leader name, pick one at random.
2691 * No attempt is made to avoid clashes to maximise the number of
2692 * nations that can be assigned in this way. */
2693 {
2695 int n = 0;
2696
2697 allowed_nations_iterate(pnation) {
2698 if (is_nation_playable(pnation)
2699 && client_can_pick_nation(pnation)
2700 && NULL == pnation->player
2701 && (nation_leader_by_name(pnation, player_name(pplayer)))) {
2703 n++;
2704 }
2706 if (n > 0) {
2707 player_set_nation_full(pplayer,
2709 }
2711 }
2712 if (pplayer->nation != NO_NATION_SELECTED) {
2713 announce_player(pplayer);
2714 } else {
2716 }
2718
2719 if (0 < nations_to_assign && 0 < map_startpos_count()) {
2720 /* We're running a scenario game with specified start positions.
2721 * Prefer nations assigned to those positions (but we can fall back
2722 * to others, even if game.scenario.startpos_nations is set). */
2724 struct nation_type *picked;
2725 int c, max = -1;
2726 int i, min;
2727
2728 /* Initialization. */
2730 if (startpos_allows_all(psp)) {
2731 continue;
2732 }
2733
2734 /* Count the already-assigned players whose nations can use this
2735 * start position. */
2736 c = 0;
2737 players_iterate(pplayer) {
2738 if (NO_NATION_SELECTED != pplayer->nation
2739 && startpos_nation_allowed(psp, pplayer->nation)) {
2740 c++;
2741 }
2743
2744 startpos_hash_insert(hash, psp, c);
2745 if (c > max) {
2746 max = c;
2747 }
2749
2750 /* Try to assign nations with start positions to the unassigned
2751 * players, preferring nations whose start positions aren't usable
2752 * by already-assigned players. */
2753 players_iterate(pplayer) {
2754 if (NO_NATION_SELECTED != pplayer->nation) {
2755 continue;
2756 }
2757
2759 min = max;
2760 i = 0;
2761
2762 allowed_nations_iterate(pnation) {
2763 if (!is_nation_playable(pnation)
2764 || NULL != pnation->player) {
2765 /* Not available. */
2766 continue;
2767 }
2768
2769 startpos_hash_iterate(hash, psp, val) {
2770 if (!startpos_nation_allowed(psp, pnation)) {
2771 continue;
2772 }
2773
2774 if (val < min) {
2775 /* Pick this nation, as fewer nations already in the game
2776 * can use this start position. */
2777 picked = pnation;
2778 min = val;
2779 i = 1;
2780 } else if (val == min && 0 == fc_rand(++i)) {
2781 /* More than one nation is equally desirable. Pick one at
2782 * random. */
2783 picked = pnation;
2784 }
2787
2788 if (NO_NATION_SELECTED != picked) {
2791 announce_player(pplayer);
2792 /* Update the counts for the newly assigned nation. */
2793 startpos_hash_iterate(hash, psp, val) {
2794 if (startpos_nation_allowed(psp, picked)) {
2795 startpos_hash_replace(hash, psp, val + 1);
2796 }
2798 } else {
2799 /* No need to continue; we failed to pick a nation this time,
2800 * so we're not going to succeed next time. Fall back to
2801 * standard nation selection. */
2802 break;
2803 }
2805
2807 }
2808
2809 if (0 < nations_to_assign) {
2810 /* Pick random races. Try to select from the set permitted by
2811 * starting positions -- if we fell through here after failing to
2812 * match start positions, this will at least keep the picked
2813 * nations vaguely in keeping with the scenario.
2814 * However, even this may fail (if there are start positions that
2815 * can only be filled by nations outside the current nationset),
2816 * in which case we fall back to completely random nations. */
2817 bool needs_startpos = TRUE;
2818 players_iterate(pplayer) {
2819 if (NO_NATION_SELECTED == pplayer->nation) {
2822 if (pnation == NO_NATION_SELECTED && needs_startpos) {
2825 }
2826 fc_assert(pnation != NO_NATION_SELECTED);
2827 player_set_nation_full(pplayer, pnation);
2829 announce_player(pplayer);
2830 }
2832 }
2833
2835
2837}
2838
2839/**********************************************************************/
2844const char *pick_random_player_name(const struct nation_type *pnation)
2845{
2846 const char *choice = NULL;
2848 int n;
2849
2851 const char *name = nation_leader_name(pleader);
2852
2853 if (NULL == player_by_name(name)
2854 && NULL == player_by_user(name)) {
2856 }
2858
2860 if (n > 0) {
2862 fc_rand(n)));
2863 }
2865
2866 return choice;
2867}
2868
2869/**********************************************************************/
2872static void announce_player(struct player *pplayer)
2873{
2874 log_normal(_("%s rules the %s."),
2875 player_name(pplayer), nation_plural_for_player(pplayer));
2876
2878 ftc_server, _("%s rules the %s."),
2879 player_name(pplayer), nation_plural_for_player(pplayer));
2880
2881 /* Let the clients knows the nation of the players as soon as possible.
2882 * When a player's nation is server assigned its client will think of it
2883 * as NULL until informed about the assigned nation. */
2884 send_player_info_c(pplayer, NULL);
2885}
2886
2887/**********************************************************************/
2890static void srv_running(void)
2891{
2893 bool skip_mapimg = !game.info.is_new_game; /* Do not overwrite start-of-turn image */
2895 int save_counter = game.info.is_new_game ? 1 : 0;
2896
2897 /* We may as well reset is_new_game now. */
2899
2900 log_verbose("srv_running() mostly redundant send_server_settings()");
2902
2904
2905 if (game.server.autosaves & (1 << AS_TIMER)) {
2909 ? NULL : "save interval");
2911 }
2912
2913 /*
2914 * This will freeze the reports and agents at the client.
2915 *
2916 * Do this before the body so that the PACKET_THAW_CLIENT packet is
2917 * balanced.
2918 */
2920
2922 while (S_S_RUNNING == server_state()) {
2923 /* The beginning of a turn.
2924 *
2925 * We have to initialize data as well as do some actions. However when
2926 * loading a game we don't want to do these actions (like AI unit
2927 * movement and AI diplomacy). */
2929
2930 if (game.server.num_phases != 1) {
2931 /* We allow everyone to begin adjusting cities and such
2932 * from the beginning of the turn.
2933 * With simultaneous movement we send begin_turn packet in
2934 * begin_phase() only after AI players have finished their actions. */
2936 }
2937
2939 log_debug("Starting phase %d/%d.", game.info.phase,
2943 /* When loading a savegame, we need to send loaded events, after
2944 * the clients switched to the game page (after the first
2945 * packet_start_phase is received). */
2950 }
2951
2952 is_new_turn = TRUE;
2953
2955
2956 /*
2957 * This will thaw the reports and agents at the client.
2958 */
2960
2961#ifdef LOG_TIMERS
2962 /* Before sniff (human player activites), report time to now: */
2963 log_verbose("End/start-turn server/ai activities: %g seconds",
2965#endif
2966
2967 /* Do auto-saves just before starting server_sniff_all_input(), so that
2968 * autosave happens effectively "at the same time" as manual
2969 * saves, from the point of view of restarting and AI players.
2970 * Post-increment so we don't count the first loop. */
2971 if (game.info.phase == 0) {
2972 /* Create autosaves if requested. */
2974 && game.server.save_nturns > 0) {
2975 save_counter = 0;
2976 save_game_auto("Autosave", AS_TURN);
2977 }
2978 save_counter++;
2979
2980 if (!skip_mapimg) {
2982 } else {
2984 }
2985 }
2986
2987 log_debug("sniffingpackets");
2988 check_for_full_turn_done(); /* HACK: don't wait during AI phases */
2989
2990 if (between_turns != NULL) {
2992 log_debug("Unresponsive between turns %g seconds", game.server.turn_change_time);
2993 }
2994
2996 /* Nothing */
2997 }
2998
3000 between_turns != NULL ? NULL : "between turns");
3002
3003 /* After sniff, re-zero the timer: (read-out above on next loop) */
3006
3008
3009 sanity_check();
3010
3011 /*
3012 * This will freeze the reports and agents at the client.
3013 */
3015
3016 end_phase();
3017
3019
3020 if (S_S_OVER == server_state()) {
3021 break;
3022 }
3024 }
3025
3026 /* Make sure is_new_turn is reset before next turn even if
3027 * we did zero rounds in the loop (i.e. if current phase from
3028 * the savegame was >= num phases). Without this begin_turn()
3029 * would not reset phase, so there would be infinite loop
3030 * where phase is too high for is_new_turn to get set. */
3031 is_new_turn = TRUE;
3032
3033 end_turn();
3034 log_debug("Sendinfotometaserver");
3036
3039 if (game.info.turn > game.server.end_turn) {
3040 /* endturn was reached - rank users based on team scores */
3042 } else {
3043 /* Game ended for victory conditions - rank users based on survival */
3045 }
3046 } else if (S_S_OVER == server_state()) {
3047 /* Game terminated by /endgame command - calculate team scores */
3049 }
3050 }
3051
3052 /* This will thaw the reports and agents at the client. */
3054
3055 if (game.server.save_timer != NULL) {
3058 }
3059 if (between_turns != NULL) {
3062 }
3064}
3065
3066/**********************************************************************/
3069static void srv_prepare(void)
3070{
3071#ifdef HAVE_FCDB
3072 if (!srvarg.auth_enabled) {
3073 con_write(C_COMMENT, _("This freeciv-server program has player "
3074 "authentication support, but it's currently not "
3075 "in use."));
3076 }
3077#endif /* HAVE_FCDB */
3078
3079 /* Make sure it's initialized */
3080 if (!has_been_srv_init) {
3081 srv_init();
3082 }
3083
3085
3086 /* Must be before con_log_init() */
3090 /* Logging available after this point */
3091
3093
3094#if IS_BETA_VERSION || IS_DEVEL_VERSION
3095 con_puts(C_COMMENT, "");
3097 con_puts(C_COMMENT, "");
3098#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
3099
3100 con_flush();
3101
3104 edithand_init();
3105 voting_init();
3106 voting_init();
3107 ai_timer_init();
3108
3109 modpacks_init();
3115
3116#ifdef HAVE_FCDB
3117 if (srvarg.fcdb_enabled) {
3118 bool success;
3119
3121 free(srvarg.fcdb_conf); /* Never needed again */
3123 if (!success) {
3125 }
3126 }
3127#endif /* HAVE_FCDB */
3128
3129 if (srvarg.ruleset != NULL) {
3130 const char *testfilename;
3131
3133 if (testfilename == NULL) {
3134 log_fatal(_("Ruleset directory \"%s\" not found"), srvarg.ruleset);
3136 }
3138 }
3139
3140 /* Try to load a saved game */
3141 if ('\0' == srvarg.load_filename[0]
3143 /* Savegame not loaded */
3145
3146 /* Rulesets are loaded on game initialization, but may be changed later
3147 * if /load or /rulesetdir is done. */
3149 }
3150
3152
3153 if (!(srvarg.metaserver_no_send)) {
3154 log_normal(_("Sending info to metaserver <%s>."), meta_addr_port());
3155 /* Open socket for meta server */
3158 con_write(C_FAIL, _("Not starting without explicitly requested metaserver connection."));
3160 }
3161 }
3162
3163 eot_timer = timer_new(TIMER_CPU, TIMER_ACTIVE, "end-of-turn");
3164}
3165
3166/**********************************************************************/
3169static void srv_scores(void)
3170{
3171 /* Recalculate the scores in case of a spaceship victory */
3172 players_iterate(pplayer) {
3173 calc_civ_score(pplayer);
3175
3177
3181 _("The game is over..."));
3183
3184 if (game.server.save_nturns > 0
3186 || !srvarg.quitidle)) {
3187 /* Save game on game_over, but not when the gameover was caused by
3188 * the -q parameter. Be sure that it's the -q, and not an autogame
3189 * with no human players. */
3190 save_game_auto("Game over", AS_GAME_OVER);
3191 }
3192
3194}
3195
3196/**********************************************************************/
3202{
3203 players_iterate(pplayer) {
3204 struct nation_type *pnation = nation_of_player(pplayer);
3205
3206 pplayer->government = init_government_of_nation(pnation);
3207
3209 /* If we do not do this, an assertion will trigger. This enables us to
3210 * select a valid government on game start. */
3211 pplayer->revolution_finishes = 0;
3212 }
3213
3214 multipliers_iterate(pmul) {
3215 int midx = multiplier_index(pmul);
3216
3217 pplayer->multipliers[midx].value
3218 = pplayer->multipliers[midx].target
3219 = pmul->def;
3222}
3223
3224/**********************************************************************/
3227static void srv_ready(void)
3228{
3230
3232 players_iterate(pplayer) {
3233 if (!pplayer->is_connected && is_human(pplayer)) {
3234 toggle_ai_player_direct(NULL, pplayer);
3235 }
3237 }
3238
3240
3241#ifdef TEST_RANDOM /* not defined anywhere, set it if you want it */
3242 test_random1(200);
3243 test_random1(2000);
3244 test_random1(20000);
3245 test_random1(200000);
3246#endif
3247
3248 if (game.info.is_new_game) {
3249 /* Must come before assign_player_colors() */
3252
3253 game.info.turn++; /* Pregame T0 -> game T1 */
3254 fc_assert(game.info.turn == 1);
3256 }
3257
3258 /* If we have a tile map, and MAPGEN_SCENARIO == map.server.generator,
3259 * call map_fractal_generate() anyway to make the specials, huts and
3260 * continent numbers. */
3261 if (map_is_empty()
3263 && game.info.is_new_game)) {
3264 struct {
3265 const char *name;
3266 char value[MAX_LEN_NAME * 2];
3267 char pretty[MAX_LEN_NAME * 2];
3268 } mapgen_settings[] = {
3269 { "generator", },
3270 { "startpos", },
3271 { "teamplacement", }
3272 };
3273 int i;
3274 /* If a specific seed has been requested, there's no point retrying,
3275 * as the map will be the same every time. */
3276 bool retry_ok = (wld.map.server.seed_setting == 0
3278 int max = retry_ok ? 3 : 1;
3279 bool created = FALSE;
3280 struct unit_type *utype = NULL;
3282
3283 if (sucount > 0) {
3284 for (i = 0; utype == NULL && i < sucount; i++) {
3286 }
3287 } else {
3288 /* First unit the initial city might build. */
3289 utype = get_role_unit(L_FIRSTBUILD, 0);
3290 }
3291 fc_assert(utype != NULL);
3292
3293 /* Register map generator setting main values. */
3294 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3296
3297 fc_assert_action(pset != NULL, continue);
3300 sizeof(mapgen_settings[i].value));
3302 mapgen_settings[i].pretty,
3303 sizeof(mapgen_settings[i].pretty));
3304 }
3305
3306 for (i = 0; !created && i < max ; i++) {
3308 if (!created && max > 1) {
3309 int set;
3310
3311 /* If we're retrying, seed_setting == 0, which will yield a new map
3312 * next time */
3314 if (i == 0) {
3315 /* We will retry only if max attempts allow it */
3316 log_normal(_("Failed to create suitable map, retrying with another mapseed."));
3317 } else {
3318 /* +1 - start human readable count from 1 and not from 0
3319 * +1 - refers to next round, not to one we just did
3320 * ==
3321 * +2 */
3322 log_normal(_("Attempt %d/%d"), i + 2, max);
3323 }
3325
3326 /* Remove old information already present in tiles */
3327 main_map_free();
3329 /* Restore the settings. */
3330 for (set = 0; set < ARRAY_SIZE(mapgen_settings); set++) {
3332#ifdef FREECIV_NDEBUG
3334#else /* FREECIV_NDEBUG */
3335 char error[128];
3336 bool success;
3337
3338 fc_assert_action(pset != NULL, continue);
3340 NULL, error, sizeof(error));
3342 "Failed to restore '%s': %s",
3343 mapgen_settings[set].name,
3344 error);
3345#endif /* FREECIV_NDEBUG */
3346 }
3347 main_map_allocate(); /* NOT map_init() as that would overwrite settings */
3348 }
3349 }
3350 if (!created) {
3351 bugreport_request(_("Cannot create suitable map with given settings."));
3352
3354 }
3355
3357 script_server_signal_emit("map_generated");
3358 }
3359
3360 game_map_init();
3361
3362 /* Test if main map generator settings have changed. */
3363 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3365 char pretty[sizeof(mapgen_settings[i].pretty)];
3366
3367 fc_assert_action(pset != NULL, continue);
3368 if (0 == strcmp(setting_value_name(pset, TRUE, pretty,
3369 sizeof(pretty)),
3370 mapgen_settings[i].pretty)) {
3371 continue; /* Setting didn't change. */
3372 }
3374 _("Setting '%s' has been adjusted from %s to %s."),
3376 mapgen_settings[i].pretty,
3377 pretty);
3378 log_normal(_("Setting '%s' has been adjusted from %s to %s."),
3380 mapgen_settings[i].pretty,
3381 pretty);
3382 }
3383 }
3384
3385 CALL_FUNC_EACH_AI(map_ready);
3386
3387 /* start the game */
3390
3391 if (game.info.is_new_game) {
3393
3394 /* If we're starting a new game, reset the max_players to be at
3395 * least the number of players currently in the game. */
3397
3398 /* Before the player map is allocated (and initialized)! */
3400
3401 players_iterate(pplayer) {
3402 player_map_init(pplayer);
3404 pplayer->economic.gold = game.info.gold;
3405 pplayer->economic.infra_points = game.info.infrapoints;
3407
3408 /* Give initial technologies, as specified in the ruleset and the
3409 * settings. */
3414
3415 /* Set up alliances based on team selections */
3416 players_iterate(pplayer) {
3418 if (players_on_same_team(pplayer, pdest)
3419 && player_number(pplayer) != player_number(pdest)) {
3421 player_diplstate_get(pdest, pplayer),
3422 DS_TEAM);
3423 give_shared_vision(pplayer, pdest);
3424 BV_SET(pplayer->real_embassy, player_index(pdest));
3425 }
3428
3429 /* Assign colors from the ruleset for any players who weren't
3430 * explicitly assigned colors during the pregame.
3431 * This must come after generate_players() since it can depend on
3432 * assigned nations. */
3434
3435 /* Save all settings for the 'reset game' command. */
3437 }
3438
3439 /* FIXME: can this be moved? */
3440 players_iterate(pplayer) {
3443
3444 if (!game.info.is_new_game) {
3445 players_iterate(pplayer) {
3446 if (is_ai(pplayer)) {
3447 set_ai_level_direct(pplayer, pplayer->ai_common.skill_level);
3448 }
3450 } else {
3451 players_iterate(pplayer) {
3452 /* Initialize this again to be sure */
3453 adv_data_default(pplayer);
3455 }
3456
3460
3461 if (game.info.is_new_game) {
3462 /* Place players' initial units, etc */
3463 init_new_game();
3465
3467 players_iterate(pplayer) {
3468 map_show_all(pplayer);
3470 }
3471 }
3472
3474 /* This is a heavy scenario. It may include research. The sciencebox
3475 * setting may have been changed. A change to the sciencebox setting
3476 * may have caused the stored amount of bulbs to be enough to finish
3477 * the current research. */
3478
3479 players_iterate(pplayer) {
3480 /* Check for finished research. */
3481 update_bulbs(pplayer, 0, TRUE, FALSE);
3483 }
3484
3485 if (srvarg.fcdb_enabled) {
3487 &game.server.dbid);
3488 log_debug("dbid: %d", game.server.dbid);
3489 }
3490
3491 CALL_FUNC_EACH_AI(game_start);
3492}
3493
3494/**********************************************************************/
3498{
3499 /* Was redundantly in game_load() */
3500 server.playable_nations = 0;
3501 server.nbarbarians = 0;
3502 server.identity_number = IDENTITY_NUMBER_SKIP;
3503
3506
3509 /* game_init() set game.server.plr_colors to NULL. So we need to
3510 * initialize the colors after. */
3512
3514}
3515
3516/**********************************************************************/
3522{
3524
3525 /* Free all the treaties that were left open when game finished. */
3526 free_treaties();
3527
3528 /* Free the vision data, without sending updates. */
3529 players_iterate(pplayer) {
3530 unit_list_iterate(pplayer->units, punit) {
3531 /* don't bother using vision_clear_sight() */
3533 punit->server.vision->radius_sq[v] = -1;
3538
3539 city_list_iterate(pplayer->cities, pcity) {
3540 /* don't bother using vision_clear_sight() */
3542 pcity->server.vision->radius_sq[v] = -1;
3549
3550 /* Destroy all players; with must be separate as the player information is
3551 * needed above. This also sends the information to the clients. */
3552 players_iterate(pplayer) {
3553 server_remove_player(pplayer);
3555
3559 citymap_free();
3560 game_free();
3561}
3562
3563/**********************************************************************/
3567{
3568 srv_prepare();
3569
3570 /* Run server loop */
3571 do {
3573
3574 /* Load a script file. */
3575 if (NULL != srvarg.script_filename) {
3576 /* Adding an error message more here will duplicate them. */
3578 }
3579
3581 if (!game_was_started()) {
3583 }
3584
3585 log_normal(_("Now accepting new client connections on port %d."),
3586 srvarg.port);
3587 /* Remain in S_S_INITIAL until all players are ready. */
3589 /* When force_end_of_sniff is used in pregame, it means that the server
3590 * is ready to start (usually set within start_game()). */
3591 }
3592
3593 if (S_S_RUNNING > server_state()) {
3594 /* If restarting for lack of players, the state is S_S_OVER,
3595 * so don't try to start the game. */
3596 srv_ready(); /* srv_ready() sets server state to S_S_RUNNING. */
3597 srv_running();
3598 srv_scores();
3599 }
3600
3601 /* Remain in S_S_OVER until players log out */
3602 while (conn_list_size(game.est_connections) > 0) {
3604 }
3605
3606 if (game.info.timeout == -1 || srvarg.exit_on_end) {
3607 /* For autogames or if the -e option is specified, exit the server. */
3608 server_quit();
3609 }
3610
3611 /* Close it even between games. */
3613
3614 /* Reset server */
3618 mapimg_reset();
3622 } while (TRUE);
3623
3624 /* Technically, we won't ever get here. We exit via server_quit(). */
3626}
3627
3628/**********************************************************************/
3631struct color;
3632static inline void server_gui_color_free(struct color *pcolor)
3633{
3635
3636 return;
3637}
3638
3639/**********************************************************************/
3643static int server_plr_tile_city_id_get(const struct tile *ptile,
3644 const struct player *pplayer)
3645{
3646 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3647
3648 return plrtile && plrtile->site ? plrtile->site->identity
3650}
3651
3652/**********************************************************************/
3656{
3657 struct setting *pset = setting_by_name(name);
3658
3659 if (pset) {
3660 return setting_number(pset);
3661 } else {
3662 log_error("No server setting named %s exists.", name);
3663 return SERVER_SETTING_NONE;
3664 }
3665}
3666
3667/**********************************************************************/
3671{
3672 struct setting *pset = setting_by_number(id);
3673
3674 if (pset) {
3675 return setting_name(pset);
3676 } else {
3677 log_error("No server setting with the id %d exists.", id);
3678 return NULL;
3679 }
3680}
3681
3682/**********************************************************************/
3686{
3687 struct setting *pset = setting_by_number(id);
3688
3689 if (pset) {
3690 return setting_type(pset);
3691 } else {
3692 log_error("No server setting with the id %d exists.", id);
3693 return sset_type_invalid();
3694 }
3695}
3696
3697/**********************************************************************/
3701{
3702 struct setting *pset = setting_by_number(id);
3703
3704 if (pset) {
3705 return setting_bool_get(pset);
3706 } else {
3707 log_error("No server setting with the id %d exists.", id);
3708 return FALSE;
3709 }
3710}
3711
3712/**********************************************************************/
3716{
3717 struct setting *pset = setting_by_number(id);
3718
3719 if (pset) {
3720 return setting_int_get(pset);
3721 } else {
3722 log_error("No server setting with the id %d exists.", id);
3723 return 0;
3724 }
3725}
3726
3727/**********************************************************************/
3731{
3732 struct setting *pset = setting_by_number(id);
3733
3734 if (pset) {
3735 return setting_bitwise_get(pset);
3736 } else {
3737 log_error("No server setting with the id %d exists.", id);
3738 return FALSE;
3739 }
3740}
3741
3742/**********************************************************************/
3746{
3748
3749 funcs->server_setting_by_name = server_ss_by_name;
3750 funcs->server_setting_name_get = server_ss_name_get;
3751 funcs->server_setting_type_get = server_ss_type_get;
3752 funcs->server_setting_val_bool_get = server_ss_val_bool_get;
3753 funcs->server_setting_val_int_get = server_ss_val_int_get;
3754 funcs->server_setting_val_bitwise_get = server_ss_val_bitwise_get;
3755 funcs->create_extra = create_extra;
3756 funcs->destroy_extra = destroy_extra;
3757 funcs->destroy_city = remove_city;
3758 funcs->player_tile_vision_get = map_is_known_and_seen;
3759 funcs->player_tile_city_id_get = server_plr_tile_city_id_get;
3760 funcs->gui_color_free = server_gui_color_free;
3761
3762 /* Keep this function call at the end. It checks if all required functions
3763 are defined. */
3765}
3766
3767/**********************************************************************/
3770static enum known_type mapimg_server_tile_known(const struct tile *ptile,
3771 const struct player *pplayer,
3772 bool knowledge)
3773{
3774 if (knowledge && pplayer) {
3775 return tile_get_known(ptile, pplayer);
3776 }
3777
3778 return TILE_KNOWN_SEEN;
3779}
3780
3781/**********************************************************************/
3784static struct terrain
3785 *mapimg_server_tile_terrain(const struct tile *ptile,
3786 const struct player *pplayer, bool knowledge)
3787{
3788 if (knowledge && pplayer) {
3789 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3790 return plrtile->terrain;
3791 }
3792
3793 return tile_terrain(ptile);
3794}
3795
3796/**********************************************************************/
3799static struct player *mapimg_server_tile_owner(const struct tile *ptile,
3800 const struct player *pplayer,
3801 bool knowledge)
3802{
3803 if (knowledge && pplayer
3804 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3805 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3806 return plrtile->owner;
3807 }
3808
3809 return tile_owner(ptile);
3810}
3811
3812/**********************************************************************/
3815static struct player *mapimg_server_tile_city(const struct tile *ptile,
3816 const struct player *pplayer,
3817 bool knowledge)
3818{
3819 struct city *pcity = tile_city(ptile);
3820
3821 if (!pcity) {
3822 return NULL;
3823 }
3824
3825 if (knowledge && pplayer) {
3826 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
3827
3828 if (pdcity) {
3829 return pdcity->owner;
3830 } else {
3831 return NULL;
3832 }
3833 }
3834
3835 return city_owner(tile_city(ptile));
3836}
3837
3838/**********************************************************************/
3841static struct player *mapimg_server_tile_unit(const struct tile *ptile,
3842 const struct player *pplayer,
3843 bool knowledge)
3844{
3845 int unit_count = unit_list_size(ptile->units);
3846
3847 if (unit_count == 0) {
3848 return NULL;
3849 }
3850
3851 if (knowledge && pplayer
3852 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3853 return NULL;
3854 }
3855
3856 return unit_owner(unit_list_get(ptile->units, 0));
3857}
3858
3859/**********************************************************************/
3863{
3864 return playercolor_count();
3865}
3866
3867/**********************************************************************/
3871{
3872 return playercolor_get(i);
3873}
3874
3875/**********************************************************************/
3878static void save_all_map_images(void)
3879{
3880 int count = mapimg_count();
3881 int i;
3882
3883 /* Save map image(s). */
3884 for (i = 0; i < count; i++) {
3885 struct mapdef *pmapdef = mapimg_isvalid(i);
3886
3887 if (pmapdef != NULL) {
3890 } else {
3891 log_error("%s", mapimg_error());
3892 }
3893 }
3894}
3895
3896/**********************************************************************/
3899static bool world_peace_turn(void)
3900{
3901 players_iterate_alive(pplayer) {
3902 bool contact = FALSE;
3903
3905 if (pplayer != other) {
3907
3908 if (dstate->type == DS_WAR) {
3909 return FALSE;
3910 }
3911 if (dstate->type != DS_NO_CONTACT) {
3912 contact = TRUE;
3913 }
3914 }
3916
3917 if (!contact) {
3918 /* Peace only because there's nobody to show aggression against does not count. */
3919 return FALSE;
3920 }
3922
3923 return TRUE;
3924}
3925
3926/**********************************************************************/
3929static void world_peace_update(void)
3930{
3931 if (!world_peace_turn()) {
3932 /* Consecutive world peace turns begin *earliest* after this turn, overwrite older claims. */
3934 }
3935}
int achievement_index(const struct achievement *pach)
struct player * achievement_plr(struct achievement *ach, struct player_list *achievers)
const char * achievement_later_msg(struct achievement *pach)
const char * achievement_first_msg(struct achievement *pach)
#define achievements_iterate_end
#define achievements_iterate(_ach_)
void building_advisor(struct player *pplayer)
void adv_data_analyze_rulesets(struct player *pplayer)
Definition advdata.c:192
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:263
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:566
void adv_data_default(struct player *pplayer)
Definition advdata.c:732
bool adv_spaceship_autoplace(struct player *pplayer, struct player_spaceship *ship)
Definition advspace.c:33
const char * ai_name(const struct ai_type *ai)
Definition ai.c:335
#define ai_timer_free(...)
Definition ai.h:358
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
#define ai_timer_init(...)
Definition ai.h:357
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
void ai_init(void)
Definition aiiface.c:131
const char * default_ai_type_name(void)
Definition aiiface.c:264
void ai_traits_init(struct player *pplayer)
Definition aitraits.c:33
void create_animals(void)
Definition animals.c:96
void astr_free(struct astring *astr)
Definition astring.c:148
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:251
void astr_init(struct astring *astr)
Definition astring.c:139
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:271
#define str
Definition astring.c:76
#define n
Definition astring.c:77
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define ASTRING_INIT
Definition astring.h:44
bool auth_handle_reply(struct connection *pconn, char *password)
Definition auth.c:156
void adv_workers_free(void)
Definition autoworkers.c:86
void auto_workers_player(struct player *pplayer)
void summon_barbarians(void)
Definition barbarian.c:738
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_CLR(bv, bit)
Definition bitvector.h:94
void bugreport_request(const char *reason_format,...)
Definition bugs.c:31
void game_advance_year(void)
Definition calendar.c:91
void game_next_year(struct packet_game_info *info)
Definition calendar.c:30
#define FIRST_TURN
Definition calendar.h:20
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
void free_city_map_index(void)
Definition city.c:609
#define cities_iterate_end
Definition city.h:514
#define city_list_iterate(citylist, pcity)
Definition city.h:505
#define cities_iterate(pcity)
Definition city.h:509
#define city_owner(_pcity_)
Definition city.h:560
#define city_list_iterate_end
Definition city.h:507
void citymap_free(void)
Definition citymap.c:110
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3624
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2368
bool send_city_suppression(bool now)
Definition citytools.c:2170
void sync_cities(void)
Definition citytools.c:3351
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3466
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3385
void remove_city(struct city *pcity)
Definition citytools.c:1713
void city_thaw_workers_queue(void)
Definition citytools.c:197
void send_player_cities(struct player *pplayer)
Definition citytools.c:2348
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2324
bool check_city_migrations(void)
Definition cityturn.c:4240
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4620
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:576
void update_city_activities(struct player *pplayer)
Definition cityturn.c:602
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4641
void check_disasters(void)
Definition cityturn.c:4415
void city_refresh_queue_processing(void)
Definition cityturn.c:213
char * incite_cost
Definition comments.c:76
report_type
Definition conn_types.h:49
@ REPORT_WONDERS_OF_THE_WORLD
Definition conn_types.h:50
@ REPORT_DEMOGRAPHIC
Definition conn_types.h:53
@ REPORT_WONDERS_OF_THE_WORLD_LONG
Definition conn_types.h:51
@ REPORT_ACHIEVEMENTS
Definition conn_types.h:54
@ REPORT_TOP_CITIES
Definition conn_types.h:52
bool handle_login_request(struct connection *pconn, struct packet_server_join_req *req)
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
Definition connecthand.c:72
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:366
bool can_conn_edit(const struct connection *pconn)
Definition connection.c:511
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:732
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:356
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:720
bool conn_controls_player(const struct connection *pconn)
Definition connection.c:745
const char * conn_description(const struct connection *pconn)
Definition connection.c:474
bool connection_send_data(struct connection *pconn, const unsigned char *data, int len)
Definition connection.c:287
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_list_iterate_end
Definition connection.h:110
void con_log_init(const char *log_filename, enum log_level level, int fatal_assertions)
Definition console.c:150
void con_flush(void)
Definition console.c:243
void con_write(enum rfc_status rfc_status, const char *message,...)
Definition console.c:203
void con_puts(enum rfc_status rfc_status, const char *str)
Definition console.c:226
void con_log_close(void)
Definition console.c:167
@ C_FAIL
Definition console.h:45
@ C_SYNTAX
Definition console.h:47
@ C_OK
Definition console.h:41
@ C_COMMENT
Definition console.h:37
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
int dio_put_uint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:265
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Definition dataio_raw.c:171
int dio_put_string_raw(struct raw_data_out *dout, const char *value)
Definition dataio_raw.c:512
int dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:398
int dio_put_uint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:287
size_t dio_output_used(struct raw_data_out *dout)
Definition dataio_raw.c:184
void dio_output_rewind(struct raw_data_out *dout)
Definition dataio_raw.c:193
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
void send_diplomatic_meetings(struct connection *dest)
Definition diplhand.c:885
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:122
void free_treaties(void)
Definition diptreaty.c:348
void edithand_free(void)
Definition edithand.c:96
void edithand_init(void)
Definition edithand.c:78
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1066
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Definition extras.c:1030
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1136
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1152
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define extra_type_by_rmcause_iterate_end
Definition extras.h:358
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition extras.h:353
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
void cmdline_option_values_free(void)
Definition fc_cmdline.c:97
void i_am_server(void)
void libfreeciv_init(bool check_fc_interface)
void libfreeciv_free(void)
struct functions * fc_interface_funcs(void)
environment_upset_type
Definition fc_types.h:986
@ EUT_NUCLEAR_WINTER
Definition fc_types.h:988
@ EUT_GLOBAL_WARMING
Definition fc_types.h:987
int server_setting_id
Definition fc_types.h:778
int Tech_type_id
Definition fc_types.h:236
int Nation_type_id
Definition fc_types.h:239
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_LEN_NAME
Definition fc_types.h:66
@ VC_CULTURE
Definition fc_types.h:981
@ VC_ALLIED
Definition fc_types.h:980
@ VC_WORLDPEACE
Definition fc_types.h:982
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ BORDERS_ENABLED
Definition fc_types.h:746
@ BORDERS_DISABLED
Definition fc_types.h:745
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:92
void fcdb_free(void)
Definition fcdb.c:234
bool fcdb_init(const char *conf_file)
Definition fcdb.c:218
const char * get_internal_encoding(void)
Definition fciconv.c:182
static char void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Definition fciconv.c:70
#define FC_DEFAULT_DATA_ENCODING
Definition fciconv.h:89
const char * get_locale_dir(void)
Definition fcintl.c:111
#define Q_(String)
Definition fcintl.h:70
#define bindtextdomain(Package, Directory)
Definition fcintl.h:82
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
void fc_mutex_init(fc_mutex *mutex)
void fc_mutex_destroy(fc_mutex *mutex)
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:61
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:712
int current_turn_timeout(void)
Definition game.c:853
void game_init(bool keep_ruleset_value)
Definition game.c:445
struct world wld
Definition game.c:62
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:796
#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
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 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 main_map_free(void)
Definition map.c:599
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
Definition map.c:1830
int map_num_tiles(void)
Definition map.c:1152
bool startpos_allows_all(const struct startpos *psp)
Definition map.c:1843
void main_map_allocate(void)
Definition map.c:534
int map_startpos_count(void)
Definition map.c:2008
bool map_is_empty(void)
Definition map.c:148
#define map_startpos_iterate(NAME_psp)
Definition map.h:136
#define map_startpos_iterate_end
Definition map.h:139
#define whole_map_iterate(_map, _tile)
Definition map.h:573
#define whole_map_iterate_end
Definition map.h:582
@ MAPGEN_SCENARIO
Definition map_types.h:47
bool map_fractal_generate(bool autosize, struct unit_type *initial_unit)
Definition mapgen.c:1268
void generator_free(void)
void player_map_init(struct player *pplayer)
Definition maphand.c:1226
void map_set_border_vision(struct player *pplayer, const bool is_enabled)
Definition maphand.c:745
void send_map_info(struct conn_list *dest)
Definition maphand.c:653
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2577
void disable_fog_of_war(void)
Definition maphand.c:1794
void show_map_to_all(void)
Definition maphand.c:1215
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:442
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1372
void enable_fog_of_war(void)
Definition maphand.c:1768
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2512
void map_show_all(struct player *pplayer)
Definition maphand.c:884
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:773
void nuclear_winter(int effect)
Definition maphand.c:117
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2680
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:925
void map_calculate_borders(void)
Definition maphand.c:2329
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1444
void give_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1637
void global_warming(int effect)
Definition maphand.c:104
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1387
void mapimg_free(void)
Definition mapimg.c:558
struct mapdef * mapimg_isvalid(int id)
Definition mapimg.c:1124
void mapimg_init(mapimg_tile_known_func mapimg_tile_known, mapimg_tile_terrain_func mapimg_tile_terrain, mapimg_tile_player_func mapimg_tile_owner, mapimg_tile_player_func mapimg_tile_city, mapimg_tile_player_func mapimg_tile_unit, mapimg_plrcolor_count_func mapimg_plrcolor_count, mapimg_plrcolor_get_func mapimg_plrcolor_get)
Definition mapimg.c:506
int mapimg_count(void)
Definition mapimg.c:573
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
Definition mapimg.c:1335
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:52
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:267
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:290
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:475
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:230
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:200
int nation_set_count(void)
Definition nation.c:691
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Definition nation.c:1187
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:281
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:659
struct nation_style * style_of_nation(const struct nation_type *pnation)
Definition nation.c:672
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:57
#define nations_iterate_end
Definition nation.h:336
#define nations_iterate(NAME_pnation)
Definition nation.h:333
#define nation_leader_list_iterate_end
Definition nation.h:59
#define NO_NATION_SELECTED
Definition nation.h:30
void fc_init_network(void)
Definition netintf.c:198
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void event_cache_remove_old(void)
Definition notify.c:602
void send_pending_events(struct connection *pconn, bool include_public)
Definition notify.c:753
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
void event_cache_clear(void)
Definition notify.c:594
void event_cache_free(void)
Definition notify.c:582
void event_cache_phases_invalidate(void)
Definition notify.c:977
void event_cache_init(void)
Definition notify.c:570
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Definition packets.c:746
const char * packet_name(enum packet_type type)
Definition packets_gen.c:47
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
struct player * player_by_number(const int player_id)
Definition player.c:849
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1480
int player_count(void)
Definition player.c:817
int player_slot_count(void)
Definition player.c:418
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
struct player * player_by_name(const char *name)
Definition player.c:881
int player_index(const struct player *pplayer)
Definition player.c:829
struct player * player_by_user(const char *name)
Definition player.c:940
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
#define player_list_iterate(playerlist, pplayer)
Definition player.h:560
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define is_ai(plr)
Definition player.h:232
#define player_list_iterate_end
Definition player.h:562
#define players_iterate_alive_end
Definition player.h:552
#define set_as_ai(plr)
Definition player.h:234
#define ANON_PLAYER_NAME
Definition player.h:43
#define is_human(plr)
Definition player.h:231
#define players_iterate_alive(_pplayer)
Definition player.h:547
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2270
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1131
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1896
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3217
int normal_player_count(void)
Definition plrhand.c:3209
void playercolor_free(void)
Definition plrhand.c:3348
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:2059
bool server_player_set_name_full(const struct connection *caller, struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Definition plrhand.c:2170
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2458
void playercolor_init(void)
Definition plrhand.c:3338
void kill_player(struct player *pplayer)
Definition plrhand.c:125
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1148
void update_national_activities(struct player *pplayer, int old_gold)
Definition plrhand.c:3478
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3225
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3377
int playercolor_count(void)
Definition plrhand.c:3387
void shuffle_players(void)
Definition plrhand.c:2383
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1945
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Definition plrhand.c:336
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1620
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2305
void update_capital(struct player *pplayer)
Definition plrhand.c:731
void assign_player_colors(void)
Definition plrhand.c:1736
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2619
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2595
void enter_war(struct player *pplayer, struct player *pplayer2)
Definition plrhand.c:848
void update_revolution(struct player *pplayer)
Definition plrhand.c:672
#define alive_phase_players_iterate(pplayer)
Definition plrhand.h:123
#define alive_phase_players_iterate_end
Definition plrhand.h:128
#define phase_players_iterate(pplayer)
Definition plrhand.h:113
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
#define allowed_nations_iterate_end
Definition plrhand.h:73
#define phase_players_iterate_end
Definition plrhand.h:118
bool fc_rand_is_init(void)
Definition rand.c:200
void fc_srand(RANDOM_TYPE seed)
Definition rand.c:161
void test_random1(int n)
Definition rand.c:253
void fc_rand_uninit(void)
Definition rand.c:192
#define fc_rand(_size)
Definition rand.h:56
randseed generate_game_seed(void)
Definition randseed.c:192
void registry_module_init(void)
Definition registry.c:31
void registry_module_close(void)
Definition registry.c:41
void report_final_scores(struct conn_list *dest)
Definition report.c:1724
void report_wonders_of_the_world(struct conn_list *dest)
Definition report.c:604
void report_demographics(struct connection *pconn)
Definition report.c:1205
void report_wonders_of_the_world_long(struct conn_list *dest)
Definition report.c:493
void make_history_report(void)
Definition report.c:1702
void log_civ_score_free(void)
Definition report.c:1514
void report_top_cities(struct conn_list *dest)
Definition report.c:410
void report_achievements(struct connection *pconn)
Definition report.c:1269
void log_civ_score_now(void)
Definition report.c:1544
struct research * research_get(const struct player *pplayer)
Definition research.c:128
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Definition research.c:720
#define researches_iterate(_presearch)
Definition research.h:155
#define researches_iterate_end
Definition research.h:158
void rulesets_deinit(void)
Definition ruleload.c:9268
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:9188
#define sanity_check()
Definition sanitycheck.h:43
void save_system_close(void)
Definition savemain.c:329
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:143
void calc_civ_score(struct player *pplayer)
Definition score.c:251
void rank_users(bool interrupt)
Definition score.c:417
int total_player_citizens(const struct player *pplayer)
Definition score.c:382
bool script_fcdb_call(const char *func_name,...)
void script_server_signal_emit(const char *signal_name,...)
int server_open_socket(void)
Definition sernet.c:1133
void flush_packets(void)
Definition sernet.c:376
void init_connections(void)
Definition sernet.c:1362
enum server_events server_sniff_all_input(void)
Definition sernet.c:522
void readline_atexit(void)
Definition sernet.c:204
void close_connections_and_socket(void)
Definition sernet.c:255
@ S_E_OTHERWISE
Definition sernet.h:30
@ S_E_FORCE_END_OF_SNIFF
Definition sernet.h:31
#define SERVER_SETTING_NONE
void settings_init(bool act)
Definition settings.c:5212
int setting_int_get(struct setting *pset)
Definition settings.c:3788
struct setting * setting_by_name(const char *name)
Definition settings.c:3309
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4267
int setting_number(const struct setting *pset)
Definition settings.c:3324
struct setting * setting_by_number(int id)
Definition settings.c:3301
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3362
void settings_free(void)
Definition settings.c:5254
void settings_turn(void)
Definition settings.c:5246
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
void settings_game_start(void)
Definition settings.c:4812
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4022
const char * setting_name(const struct setting *pset)
Definition settings.c:3333
int setting_bitwise_get(struct setting *pset)
Definition settings.c:4257
bool setting_bool_get(struct setting *pset)
Definition settings.c:3676
void send_server_settings(struct conn_list *dest)
Definition settings.c:5394
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:3069
static struct player * mapimg_server_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3799
static void server_gui_color_free(struct color *pcolor)
Definition srv_main.c:3632
void server_game_init(bool keep_ruleset_value)
Definition srv_main.c:3497
static struct terrain * mapimg_server_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3785
static void save_all_map_images(void)
Definition srv_main.c:3878
static struct player * mapimg_server_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3815
static void update_diplomatics(void)
Definition srv_main.c:950
static struct player * mapimg_server_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3841
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:2370
static void do_have_contacts_effect(void)
Definition srv_main.c:785
static void ai_start_phase(void)
Definition srv_main.c:1138
static struct timer * eot_timer
Definition srv_main.c:201
const char * pick_random_player_name(const struct nation_type *pnation)
Definition srv_main.c:2844
void identity_number_release(int id)
Definition srv_main.c:2027
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2621
static void handle_observer_ready(struct connection *pconn)
Definition srv_main.c:2436
bv_id identity_numbers_used
Definition srv_main.c:195
static void world_peace_update(void)
Definition srv_main.c:3929
void handle_report_req(struct connection *pconn, enum report_type type)
Definition srv_main.c:1988
static void generate_players(void)
Definition srv_main.c:2672
bool force_end_of_sniff
Definition srv_main.c:193
static void do_reveal_effects(void)
Definition srv_main.c:762
static int mapimg_server_plrcolor_count(void)
Definition srv_main.c:3862
void start_game(void)
Definition srv_main.c:1878
void handle_client_info(struct connection *pc, enum gui_type gui, int emerg_version, const char *distribution)
Definition srv_main.c:315
void handle_player_ready(struct player *requestor, int player_no, bool is_ready)
Definition srv_main.c:2452
const char * aifill(int amount)
Definition srv_main.c:2506
static bool identity_number_is_used(int id)
Definition srv_main.c:2043
static void end_phase(void)
Definition srv_main.c:1438
static enum server_states civserver_state
Definition srv_main.c:187
static void begin_turn(bool is_new_turn)
Definition srv_main.c:1153
static void end_turn(void)
Definition srv_main.c:1604
void save_game_auto(const char *save_reason, enum autosave_type type)
Definition srv_main.c:1837
static struct rgbcolor * mapimg_server_plrcolor_get(int i)
Definition srv_main.c:3870
void set_server_state(enum server_states newstate)
Definition srv_main.c:346
static int increment_identity_number(void)
Definition srv_main.c:2051
const char * server_ss_name_get(server_setting_id id)
Definition srv_main.c:3670
static bool world_peace_turn(void)
Definition srv_main.c:3899
static void begin_phase(bool is_new_phase)
Definition srv_main.c:1260
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:829
static void kill_dying_players(void)
Definition srv_main.c:1112
bool game_was_started(void)
Definition srv_main.c:354
static void srv_scores(void)
Definition srv_main.c:3169
#define startpos_hash_iterate(hash, psp, c)
Definition srv_main.c:2604
void identity_number_reserve(int id)
Definition srv_main.c:2035
struct server_arguments srvarg
Definition srv_main.c:181
static void srv_ready(void)
Definition srv_main.c:3227
static void srv_running(void)
Definition srv_main.c:2890
static void final_ruleset_adjustments(void)
Definition srv_main.c:3201
#define startpos_hash_iterate_end
Definition srv_main.c:2606
static int server_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Definition srv_main.c:3643
static bool is_client_edit_packet(int type)
Definition srv_main.c:2083
void fc__noreturn srv_main(void)
Definition srv_main.c:3566
static void notify_illegal_armistice_units(struct player *phost, struct player *pguest, int turns_left)
Definition srv_main.c:867
bool server_ss_val_bool_get(server_setting_id id)
Definition srv_main.c:3700
static void remove_illegal_armistice_units(struct player *plr1, struct player *plr2)
Definition srv_main.c:911
int identity_number(void)
Definition srv_main.c:2061
server_setting_id server_ss_by_name(const char *name)
Definition srv_main.c:3655
void check_for_full_turn_done(void)
Definition srv_main.c:2256
static void player_set_nation_full(struct player *pplayer, struct nation_type *pnation)
Definition srv_main.c:2611
static void announce_player(struct player *pplayer)
Definition srv_main.c:2872
void srv_init(void)
Definition srv_main.c:232
bool server_packet_input(struct connection *pconn, void *packet, int type)
Definition srv_main.c:2092
static void fc_interface_init_server(void)
Definition srv_main.c:3745
int server_ss_val_int_get(server_setting_id id)
Definition srv_main.c:3715
static struct timer * between_turns
Definition srv_main.c:203
unsigned int server_ss_val_bitwise_get(server_setting_id id)
Definition srv_main.c:3730
static bool has_been_srv_init
Definition srv_main.c:198
void send_all_info(struct conn_list *dest)
Definition srv_main.c:730
void init_game_seed(void)
Definition srv_main.c:208
void fc__noreturn server_quit(void)
Definition srv_main.c:1915
void update_nations_with_startpos(void)
Definition srv_main.c:2311
enum sset_type server_ss_type_get(server_setting_id id)
Definition srv_main.c:3685
bool check_for_game_over(void)
Definition srv_main.c:368
static enum known_type mapimg_server_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3770
static void do_border_vision_effect(void)
Definition srv_main.c:802
enum server_states server_state(void)
Definition srv_main.c:338
void server_game_free(void)
Definition srv_main.c:3521
#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:1635
void stdinhand_turn(void)
Definition stdinhand.c:256
void stdinhand_init(void)
Definition stdinhand.c:243
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2005
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
Definition stdinhand.c:1169
void stdinhand_free(void)
Definition stdinhand.c:264
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Definition stdinhand.c:3791
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6118
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:706
Definition city.h:317
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:124
enum borders_mode borders
enum ai_level skill_level
enum phase_mode_type phase_mode
enum ai_level skill_level
Definition player.h:116
char contact_turns_left
Definition player.h:204
int auto_cancel_turn
Definition player.h:206
int first_contact_turn
Definition player.h:201
enum diplstate_type type
Definition player.h:199
char has_reason_to_cancel
Definition player.h:203
int culture
Definition player.h:109
bool random_name
Definition player.h:295
struct player_ai ai_common
Definition player.h:288
bool is_male
Definition player.h:257
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_winner
Definition player.h:269
bool is_connected
Definition player.h:296
int nturns_idle
Definition player.h:265
struct connection * current_conn
Definition player.h:297
struct team * team
Definition player.h:261
bool was_created
Definition player.h:294
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
bool is_alive
Definition player.h:268
struct player_score score
Definition player.h:283
struct nation_type * nation
Definition player.h:260
struct nation_style * style
Definition player.h:279
bool is_ready
Definition player.h:262
bool unassigned_user
Definition player.h:253
int free_bulbs
Definition research.h:67
bool metaconnection_persistent
Definition srv_main.h:30
char * bind_addr
Definition srv_main.h:34
enum log_level loglevel
Definition srv_main.h:40
char metaserver_addr[256]
Definition srv_main.h:29
char * scenarios_pathname
Definition srv_main.h:47
char load_filename[512]
Definition srv_main.h:44
char * fcdb_conf
Definition srv_main.h:56
bool auth_allow_guests
Definition srv_main.h:58
char * saves_pathname
Definition srv_main.h:46
char * log_filename
Definition srv_main.h:42
char * ranklog_filename
Definition srv_main.h:43
bool metaserver_no_send
Definition srv_main.h:28
char * bind_meta_addr
Definition srv_main.h:38
bool auth_allow_newusers
Definition srv_main.h:59
char * script_filename
Definition srv_main.h:45
char serverid[256]
Definition srv_main.h:49
char identity_name[256]
Definition srv_main.h:31
char *const value
Definition settings.c:147
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition timing.c:81
Definition unit.h:140
enum unit_activity activity
Definition unit.h:159
struct vision * vision
Definition unit.h:247
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
v_radius_t radius_sq
Definition vision.h:92
struct civ_map map
struct nation_style * style_by_number(int id)
Definition style.c:88
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define sz_strlcpy(dest, src)
Definition support.h:195
#define fc__noreturn
Definition support.h:125
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
int team_count(void)
Definition team.c:375
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
#define teams_iterate_end
Definition team.h:87
#define teams_iterate(_pteam)
Definition team.h:82
#define A_UNSET
Definition tech.h:48
void init_tech(struct research *research, bool update)
Definition techtools.c:1094
void choose_tech(struct research *research, Tech_type_id tech)
Definition techtools.c:1005
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
void choose_random_tech(struct research *research)
Definition techtools.c:990
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1188
void do_tech_parasite_effects(struct player *pplayer)
Definition techtools.c:143
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech, bool free_bulbs)
Definition techtools.c:654
#define terrain_has_flag(terr, flag)
Definition terrain.h:176
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:575
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_worked(_tile)
Definition tile.h:115
known_type
Definition tile.h:35
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:111
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
#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:2718
bool is_enter_borders_unit(const struct unit *punit)
Definition unit.c:332
#define unit_tile(_pu)
Definition unit.h:404
#define unit_owner(_pu)
Definition unit.h:403
#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:670
void random_movements(struct player *pplayer)
Definition unittools.c:5097
void finalize_unit_phase_beginning(struct player *pplayer)
Definition unittools.c:702
void execute_unit_orders(struct player *pplayer)
Definition unittools.c:680
void do_explore(struct unit *punit)
Definition unittools.c:3099
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2139
void unit_tc_effect_refresh(struct player *pplayer)
Definition unittools.c:692
void player_restore_units(struct player *pplayer)
Definition unittools.c:481
bool unit_can_be_retired(struct unit *punit)
Definition unittools.c:5080
void send_all_known_units(struct conn_list *dest)
Definition unittools.c:2921
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2259
const char * unstable_message(void)
Definition version.c:160
const char * freeciv_datafile_version(void)
Definition version.c:186
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26
void vision_free(struct vision *vision)
Definition vision.c:50
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80
void send_updated_vote_totals(struct conn_list *dest)
Definition voting.c:866
void voting_turn(void)
Definition voting.c:718
void clear_all_votes(void)
Definition voting.c:219
void voting_init(void)
Definition voting.c:707
void voting_free(void)
Definition voting.c:734
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT