Freeciv-3.2
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 "nation.h"
83#include "packets.h"
84#include "player.h"
85#include "research.h"
86#include "tech.h"
87#include "unitlist.h"
88#include "version.h"
89#include "victory.h"
90
91/* server */
92#include "aiiface.h"
93#include "animals.h"
94#include "auth.h"
95#include "barbarian.h"
96#include "cityhand.h"
97#include "citytools.h"
98#include "cityturn.h"
99#include "connecthand.h"
100#include "console.h"
101#include "fcdb.h"
102#include "diplhand.h"
103#include "edithand.h"
104#include "gamehand.h"
105#include "handchat.h"
106#include "maphand.h"
107#include "meta.h"
108#include "notify.h"
109#include "plrhand.h"
110#include "report.h"
111#include "ruleset.h"
112#include "sanitycheck.h"
113#include "score.h"
114#include "sernet.h"
115#include "settings.h"
116#include "spacerace.h"
117#include "srv_log.h"
118#include "srv_signal.h"
119#include "stdinhand.h"
120#include "techtools.h"
121#include "unithand.h"
122#include "unittools.h"
123#include "voting.h"
124
125/* server/advisors */
126#include "advdata.h"
127#include "autosettlers.h"
128#include "advbuilding.h"
129#include "advspace.h"
130#include "infracache.h"
131
132/* server/savegame */
133#include "savemain.h"
134
135/* server/scripting */
136#include "script_fcdb.h"
137#include "script_server.h"
138#include "luascript_types.h"
139
140/* server/generator */
141#include "mapgen.h"
142#include "mapgen_utils.h"
143
144/* ai */
145#include "aitraits.h"
146#include "difficulty.h"
147
148#include "srv_main.h"
149
150static void end_turn(void);
151static void announce_player(struct player *pplayer);
152static void fc_interface_init_server(void);
153
154static enum known_type mapimg_server_tile_known(const struct tile *ptile,
155 const struct player *pplayer,
156 bool knowledge);
157static struct terrain
158 *mapimg_server_tile_terrain(const struct tile *ptile,
159 const struct player *pplayer, bool knowledge);
160static struct player *mapimg_server_tile_owner(const struct tile *ptile,
161 const struct player *pplayer,
162 bool knowledge);
163static struct player *mapimg_server_tile_city(const struct tile *ptile,
164 const struct player *pplayer,
165 bool knowledge);
166static struct player *mapimg_server_tile_unit(const struct tile *ptile,
167 const struct player *pplayer,
168 bool knowledge);
169
170static int mapimg_server_plrcolor_count(void);
171static struct rgbcolor *mapimg_server_plrcolor_get(int i);
172
173static void handle_observer_ready(struct connection *pconn);
174
175/* command-line arguments to server */
177
178/* server aggregate information */
180
181/* server state information */
183
184/* This global is checked deep down the netcode.
185 packets handling functions can set it to none-zero, to
186 force end-of-tick asap
187*/
189
191
192/* server initialized flag */
194
195/* time server processing at end-of-turn */
196static struct timer *eot_timer = NULL;
197
198static struct timer *between_turns = NULL;
199
200/**********************************************************************/
204{
205 if (game.server.seed_setting == 0) {
206 /* We strip the high bit for now because neither game file nor
207 server options can handle unsigned ints yet. - Cedric */
209#ifdef FREECIV_TESTMATIC
210 /* Log command to reproduce the gameseed */
211 log_testmatic("set gameseed %u", game.server.seed);
212#else /* FREECIV_TESTMATIC */
213 log_debug("Setting game.seed:%u", game.server.seed);
214#endif /* FREECIV_TESTMATIC */
215 } else {
217 }
218
219 if (!fc_rand_is_init()) {
221 }
222}
223
224/**********************************************************************/
227void srv_init(void)
228{
229 /* fc_interface_init_server() includes low level support like
230 * guaranteeing that fc_vsnprintf() will work after it,
231 * so this need to be early. */
233
234 i_am_server(); /* Tell to libfreeciv that we are server */
235
236#ifdef ENABLE_NLS
237 (void) bindtextdomain("freeciv-nations", get_locale_dir());
238#endif
239
240 /* This is before ai module initializations so that if ai module
241 * wants to use registry files, it can. */
243
244 /* We want this before any AI stuff */
246
247 /* This must be before command line argument parsing.
248 This allocates default ai, and we want that to take place before
249 loading additional ai modules from command line. */
250 ai_init();
251
252 /* Init server arguments... */
253
257 srvarg.identity_name[0] = '\0';
258 srvarg.serverid[0] = '\0';
259
261#ifdef FREECIV_JSON_CONNECTION
263#else /* FREECIV_JSON_CONNECTION */
265#endif /* FREECIV_JSON_CONNECTION */
266
268
270
274 srvarg.load_filename[0] = '\0';
279
280 srvarg.quitidle = 0;
281
287
288 /* Mark as initialized */
290
291 /* Init character encodings. */
293#ifdef ENABLE_NLS
295#endif
296
297 /* Initialize callbacks. */
299
300 /* Initialize global mutexes */
302
303 /* Done */
304 return;
305}
306
307/**********************************************************************/
310void handle_client_info(struct connection *pc, enum gui_type gui,
311 int emerg_version, const char *distribution)
312{
313 pc->client_gui = gui;
314 log_debug("%s's client has %s gui.", pc->username, gui_type_name(gui));
315 if (emerg_version > 0) {
316 log_debug("It's emergency release .%d", emerg_version);
317 }
318 if (strcmp(distribution, "")) {
319 log_debug("It comes from %s distribution.", distribution);
320 }
321
322 /* In case a modified client sends multiple client_info packets */
324
325 if (gui == GUI_WEB) {
327 }
328}
329
330/**********************************************************************/
334{
335 return civserver_state;
336}
337
338/**********************************************************************/
345
346/**********************************************************************/
350{
351 return (!game.info.is_new_game || S_S_INITIAL != server_state());
352}
353
354/**********************************************************************/
364{
365 int candidates, defeated;
366 struct player *victor;
367 int winners = 0;
368 struct astring str = ASTRING_INIT;
369
370 /* Check for scenario victory; dead players can win if they are on a team
371 * with the winners. */
372 players_iterate(pplayer) {
374 || get_player_bonus(pplayer, EFT_VICTORY) > 0) {
375 if (winners) {
376 /* TRANS: Another entry in winners list (", the Tibetans") */
377 astr_add(&str, Q_("?winners:, the %s"),
378 nation_plural_for_player(pplayer));
379 } else {
380 /* TRANS: Beginning of the winners list ("the French") */
381 astr_add(&str, Q_("?winners:the %s"),
382 nation_plural_for_player(pplayer));
383 }
384 pplayer->is_winner = TRUE;
385 winners++;
386 }
388 if (winners) {
390 /* TRANS: There can be several winners listed */
391 _("Scenario victory to %s."), astr_str(&str));
392 log_normal(_("Scenario victory to %s."), astr_str(&str));
393 astr_free(&str);
394 return TRUE;
395 }
396 astr_free(&str);
397
398 /* Count candidates for the victory. */
399 candidates = 0;
400 defeated = 0;
401 victor = NULL;
402 /* Do not use player_iterate_alive here - dead player must be counted as
403 * defeated to end the game with a victory. */
404 players_iterate(pplayer) {
405 if (is_barbarian(pplayer)) {
406 continue;
407 }
408
409 if ((pplayer)->is_alive
410 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
411 candidates++;
412 victor = pplayer;
413 } else {
414 defeated++;
415 }
417
418 if (0 == candidates) {
420 _("Game is over."));
421 log_normal(_("Game is over."));
422 return TRUE;
423 } else {
424 if (0 < defeated) {
425 /* If nobody conceded the game, it mays be a solo game or a single team
426 * game. */
428
429 /* Quit if we have team victory. */
430 if (1 < team_count()) {
432 const struct player_list *members = team_members(pteam);
433 int team_candidates = 0, team_defeated = 0;
434
435 if (1 == player_list_size(members)) {
436 /* This is not really a team, single players are handled below. */
437 continue;
438 }
439
440 player_list_iterate(members, pplayer) {
441 if (pplayer->is_alive
442 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
444 } else {
446 }
448
451
453 /* We need a player in a other team to conced the game here. */
455 _("Team victory to %s."),
457 log_normal(_("Team victory to %s."), team_name_translation(pteam));
458 /* All players of the team win, even dead and surrended ones. */
459 player_list_iterate(members, pplayer) {
460 pplayer->is_winner = TRUE;
462 return TRUE;
463 }
465 }
466 }
467
468 /* Check for allied victory. */
471
472 /* Try to build a winner list. */
473 players_iterate_alive(pplayer) {
474 if (is_barbarian(pplayer)
475 || player_status_check((pplayer), PSTATUS_SURRENDER)) {
476 continue;
477 }
478
480 if (!pplayers_allied(aplayer, pplayer)) {
483 break;
484 }
486
487 if (NULL == winner_list) {
488 break;
489 }
492
493 if (NULL != winner_list) {
494 bool first = TRUE;
495
497
498 astr_init(&str);
500 if (first) {
501 /* TRANS: Beginning of the winners list ("the French") */
502 astr_add(&str, Q_("?winners:the %s"),
503 nation_plural_for_player(pplayer));
504 first = FALSE;
505 } else {
506 /* TRANS: Another entry in winners list (", the Tibetans") */
507 astr_add(&str, Q_("?winners:, the %s"),
508 nation_plural_for_player(pplayer));
509 }
510 pplayer->is_winner = TRUE;
513 /* TRANS: There can be several winners listed */
514 _("Allied victory to %s."), astr_str(&str));
515 log_normal(_("Allied victory to %s."), astr_str(&str));
516 astr_free(&str);
518 return TRUE;
519 }
520 }
521
522 /* Check for single player victory. */
523 if (1 == candidates && NULL != victor) {
524 bool found = FALSE; /* We need at least one enemy defeated. */
525
526 players_iterate(pplayer) {
527 if (pplayer != victor
528 && !is_barbarian(pplayer)
529 && (!pplayer->is_alive
531 && pplayer->team != victor->team
533 || !pplayers_allied(victor, pplayer))) {
534 found = TRUE;
535 break;
536 }
538
539 if (found) {
541 _("Game ended in conquest victory for %s."), player_name(victor));
542 log_normal(_("Game ended in conquest victory for %s."), player_name(victor));
543 victor->is_winner = TRUE;
544 return TRUE;
545 }
546 }
547 }
548
549 /* Check for culture victory */
551 struct player *best = NULL;
552 int best_value = -1;
553 int second_value = -1;
554
555 players_iterate(pplayer) {
556 if (is_barbarian(pplayer) || !pplayer->is_alive) {
557 continue;
558 }
559
560 if (pplayer->score.culture > best_value) {
561 best = pplayer;
563 best_value = pplayer->score.culture;
564 } else if (pplayer->score.culture > second_value) {
565 second_value = pplayer->score.culture;
566 }
568
569 if (best != NULL && best_value >= game.info.culture_vic_points
570 && best_value > second_value * (100 + game.info.culture_vic_lead) / 100) {
572 _("Game ended in cultural domination victory for %s."),
573 player_name(best));
574 log_normal(_("Game ended in cultural domination victory for %s."),
575 player_name(best));
576 best->is_winner = TRUE;
577
578 return TRUE;
579 }
580 }
581
582 /* Quit if we are past the turn limit. */
585 _("Game ended as the turn limit was exceeded."));
586 log_normal(_("Game ended as the turn limit was exceeded."));
587 return TRUE;
588 } else if (game.info.turn == game.server.end_turn) {
589 /* Give them a chance to decide to extend the game */
591 _("Notice: game will end at the end of this turn due "
592 "to 'endturn' server setting."));
593 }
594
595 /* Check for a spacerace win (and notify of imminent arrivals).
596 * Check this after checking turn limit, because we are checking for
597 * the spaceship arriving in the year corresponding to the turn
598 * that's about to start. */
599 {
600 int n, i;
602
604
605 for (i = 0; i < n; i++) {
606 struct player *pplayer = arrivals[i];
607 const struct player_list *members;
608 bool win;
609
610 if (game.info.year < (int)spaceship_arrival(pplayer)) {
611 /* We are into the future arrivals */
612 break;
613 }
614
615 /* Mark as arrived and notify everyone. */
616 spaceship_arrived(pplayer);
617
618 if (!game.server.endspaceship) {
619 /* Games does not end on spaceship arrival. At least print all the
620 * arrival messages. */
621 continue;
622 }
623
624 /* This player has won, now check if anybody else wins with them. */
625 members = team_members(pplayer->team);
626 win = FALSE;
628 if (pplayer->is_alive
630 /* We need at least one player to be a winner candidate in the
631 * team. */
632 win = TRUE;
633 break;
634 }
636
637 if (!win) {
638 /* Let's try next arrival. */
639 continue;
640 }
641
642 if (1 < player_list_size(members)) {
644 _("Team victory to %s."),
645 team_name_translation(pplayer->team));
646 /* All players of the team win, even dead and surrendered ones. */
648 pteammate->is_winner = TRUE;
650 } else {
652 _("Game ended in victory for %s."), player_name(pplayer));
653 pplayer->is_winner = TRUE;
654 }
655 return TRUE;
656 }
657
658 /* Print notice(s) of imminent arrival. These are not infallible
659 * (quite apart from risk of enemy action) because arrival is
660 * year-based, and some effect may change the timeline between
661 * now and the end of the next turn.
662 * (Also the order of messages will not always indicate tie-breaks,
663 * if the shuffled order is changed every turn, as it is for
664 * PMT_CONCURRENT games.) */
665 for (; i < n; i++) {
666 const struct player *pplayer = arrivals[i];
667 struct packet_game_info next_info = game.info; /* struct copy */
668
669 /* Advance the calendar in a throwaway copy of game.info. */
671
672 if (next_info.year < (int)spaceship_arrival(pplayer)) {
673 /* Even further in the future */
674 break;
675 }
676
678 _("Notice: the %s spaceship will likely arrive at "
679 "Alpha Centauri next turn."),
681 }
682 }
683
684 return FALSE;
685}
686
687/**********************************************************************/
692void send_all_info(struct conn_list *dest)
693{
694 conn_list_iterate(dest, pconn) {
697 }
699
700 /* Resend player info because it could have more infos (e.g. embassy). */
701 send_player_all_c(NULL, dest);
705 send_map_info(dest);
710
711 cities_iterate(pcity) {
714
715 cities_iterate(pcity) {
718}
719
720/**********************************************************************/
724static void do_reveal_effects(void)
725{
726 phase_players_iterate(pplayer) {
727 if (get_player_bonus(pplayer, EFT_REVEAL_CITIES) > 0) {
728 players_iterate(other_player) {
729 city_list_iterate(other_player->cities, pcity) {
730 map_show_tile(pplayer, pcity->tile);
733 }
734 if (get_player_bonus(pplayer, EFT_REVEAL_MAP) > 0) {
735 /* map_know_all will mark all unknown tiles as known and send
736 * tile, unit, and city updates as necessary. No other actions are
737 * needed. */
738 map_show_all(pplayer);
739 }
741}
742
743/**********************************************************************/
747static void do_have_contacts_effect(void)
748{
749 phase_players_iterate(pplayer) {
750 if (get_player_bonus(pplayer, EFT_HAVE_CONTACTS) > 0) {
752 /* Note this gives pplayer contact with pother, but doesn't give
753 * pother contact with pplayer. This may cause problems in other
754 * parts of the code if we're not careful. */
755 make_contact(pplayer, pother, NULL);
757 }
759}
760
761/**********************************************************************/
764static void do_border_vision_effect(void)
765{
767 /* Border_Vision is useless. If borders are disabled there are no
768 * borders to see inside. If borders are seen they are seen already.
769 * The borders setting can't change after the game has started. */
770 return;
771 }
772
775
776 /* Check the Border_Vision effect for this player. */
778
779 if (new_border_vision != plr->server.border_vision) {
780 /* Border vision changed. */
781
782 /* Update the map */
784 }
786}
787
788/**********************************************************************/
792 int *current, int *accum, int *level,
793 int percent,
794 void (*upset_action_fn)(int))
795{
796 int count;
797
798 count = 0;
799 extra_type_iterate(cause) {
800 if (extra_causes_env_upset(cause, type)) {
801 whole_map_iterate(&(wld.map), ptile) {
802 if (tile_has_extra(ptile, cause)) {
803 count++;
804 }
806 }
808
809 *current = (count * percent) / 100;
810 *accum += count;
811 if (*accum < *level) {
812 *accum = 0;
813 } else {
814 *accum -= *level;
815 if (fc_rand((map_num_tiles() + 19) / 20) < *accum) {
816 upset_action_fn((wld.map.xsize / 10) + (wld.map.ysize / 10) + ((*accum) * 5));
817 *accum = 0;
818 *level += (map_num_tiles() + 999) / 1000;
819 }
820 }
821
822 log_debug("environmental_upset: type=%-4d current=%-2d "
823 "level=%-2d accum=%-2d", type, *current, *level, *accum);
824}
825
826/**********************************************************************/
830 struct player *pguest,
831 int turns_left)
832{
833 int nunits = 0;
834 struct unit *a_unit = NULL;
835
837 struct tile *ptile = unit_tile(punit);
838
839 if (tile_owner(ptile) == phost
842 nunits++;
843 a_unit = punit;
844 }
846
847 if (nunits > 0) {
849
851 /* TRANS: "... 2 military units in Norwegian territory." */
852 PL_("Warning: you still have %d military unit in %s territory.",
853 "Warning: you still have %d military units in %s territory.",
854 nunits),
856 /* If there's one lousy unit left, we may as well include a link for it */
859 /* TRANS: %s is another, separately translated sentence,
860 * ending in a full stop. */
861 PL_("%s Any such units will be disbanded in %d turn, "
862 "in accordance with peace treaty.",
863 "%s Any such units will be disbanded in %d turns, "
864 "in accordance with peace treaty.", turns_left),
865 astr_str(&unitstr), turns_left);
867 }
868}
869
870/**********************************************************************/
873static void remove_illegal_armistice_units(struct player *plr1,
874 struct player *plr2)
875{
876 /* Remove illegal units */
878 struct tile *ptile = unit_tile(punit);
879
880 if (tile_owner(ptile) == plr2
884 _("Your %s was disbanded in accordance with "
885 "your peace treaty with the %s."),
889 }
891
893 struct tile *ptile = unit_tile(punit);
894
895 if (tile_owner(ptile) == plr1
899 _("Your %s was disbanded in accordance with "
900 "your peace treaty with the %s."),
904 }
906}
907
908/**********************************************************************/
912static void update_diplomatics(void)
913{
916 struct player_diplstate *state = player_diplstate_get(plr1, plr2);
917
918 /* Players might just met when first of them was being handled
919 * (pact with third player changed and units got bounced next
920 * to second unit to form first contact)
921 * Do not decrease the counters for the other player yet in this turn */
922 if (state->first_contact_turn != game.info.turn) {
923 struct player_diplstate *state2 = player_diplstate_get(plr2, plr1);
924
925 state->has_reason_to_cancel = MAX(state->has_reason_to_cancel - 1, 0);
926 state->contact_turns_left = MAX(state->contact_turns_left - 1, 0);
927
928 if (state->type == DS_ARMISTICE
929 /* Don't count down if auto canceled this turn. Auto canceling
930 * happens in this loop. */
931 && state->auto_cancel_turn != game.info.turn) {
932 state->turns_left--;
933 if (state->turns_left <= 0) {
934 state->type = DS_PEACE;
935 state2->type = DS_PEACE;
936 state->turns_left = 0;
937 state2->turns_left = 0;
939 } else {
940 notify_illegal_armistice_units(plr1, plr2, state->turns_left);
941 }
942 }
943
944 if (state->type == DS_CEASEFIRE) {
945 state->turns_left--;
946 switch (state->turns_left) {
947 case 1:
949 _("Concerned citizens point out that the cease-fire "
950 "with %s will run out soon."), player_name(plr2));
951 /* Message to plr2 will be done when plr1 and plr2 will be swapped.
952 * Else, we will get a message duplication. Note the case is not
953 * the below, because the state will be changed for both players to
954 * war. */
955 break;
956 case 0:
958 _("The cease-fire with %s has run out. "
959 "You are now at war with the %s."),
960 player_name(plr2),
963 _("The cease-fire with %s has run out. "
964 "You are now at war with the %s."),
965 player_name(plr1),
967 state->type = DS_WAR;
968 state2->type = DS_WAR;
969 state->turns_left = 0;
970 state2->turns_left = 0;
971
972 enter_war(plr1, plr2);
973
976 sync_cities();
977
978 /* Avoid love-love-hate triangles */
980 if (plr3 != plr1 && plr3 != plr2
981 && pplayers_allied(plr3, plr1)
982 && pplayers_allied(plr3, plr2)) {
983 struct player_diplstate *to1
984 = player_diplstate_get(plr3, plr1);
985 struct player_diplstate *from1
986 = player_diplstate_get(plr1, plr3);
987 struct player_diplstate *to2
988 = player_diplstate_get(plr3, plr2);
989 struct player_diplstate *from2
990 = player_diplstate_get(plr2, plr3);
991 const char *plr1name = player_name(plr1);
992 const char *plr2name = player_name(plr2);
993 bool cancel1;
994 bool cancel2;
995
996 if (players_on_same_team(plr3, plr1)) {
998
999 cancel1 = FALSE;
1000 cancel2 = TRUE;
1001
1003 _("The cease-fire between %s and %s has run out. "
1004 "They are at war. You cancel your alliance "
1005 "with %s."),
1007 } else if (players_on_same_team(plr3, plr2)) {
1008
1009 cancel1 = TRUE;
1010 cancel2 = FALSE;
1011
1013 _("The cease-fire between %s and %s has run out. "
1014 "They are at war. You cancel your alliance "
1015 "with %s."),
1017 } else {
1018
1019 cancel1 = TRUE;
1020 cancel2 = TRUE;
1021
1023 _("The cease-fire between %s and %s has run out. "
1024 "They are at war. You cancel your alliance "
1025 "with both."),
1026 player_name(plr1),
1027 player_name(plr2));
1028 }
1029
1030 if (cancel1) {
1031 /* Cancel the alliance. */
1032 to1->has_reason_to_cancel = 1;
1034
1035 /* Avoid asymmetric turns_left for the armistice. */
1036 to1->auto_cancel_turn = game.info.turn;
1037 from1->auto_cancel_turn = game.info.turn;
1038
1039 /* Count down for this turn. */
1040 to1->turns_left--;
1041 from1->turns_left--;
1042 }
1043
1044 if (cancel2) {
1045 /* Cancel the alliance. */
1046 to2->has_reason_to_cancel = 1;
1048
1049 /* Avoid asymmetric turns_left for the armistice. */
1050 to2->auto_cancel_turn = game.info.turn;
1051 from2->auto_cancel_turn = game.info.turn;
1052
1053 /* Count down for this turn. */
1054 to2->turns_left--;
1055 from2->turns_left--;
1056 }
1057 }
1059 break;
1060 }
1061 }
1062 }
1065}
1066
1067/**********************************************************************/
1074static void kill_dying_players(void)
1075{
1076 bool voter_died = FALSE;
1077
1078 players_iterate_alive(pplayer) {
1079 /* cities or units remain? */
1080 if (0 == city_list_size(pplayer->cities)
1081 && 0 == unit_list_size(pplayer->units)) {
1083 }
1084 /* also UTYF_GAMELOSS in unittools server_remove_unit() */
1085 if (player_status_check(pplayer, PSTATUS_DYING)) {
1086 /* Can't get more dead than this. */
1087 voter_died = voter_died || pplayer->is_connected;
1088 kill_player(pplayer);
1089 }
1091
1092 if (voter_died) {
1094 }
1095}
1096
1097/**********************************************************************/
1100static void ai_start_phase(void)
1101{
1102 phase_players_iterate(pplayer) {
1103 if (is_ai(pplayer)) {
1104 CALL_PLR_AI_FUNC(first_activities, pplayer, pplayer);
1105 }
1108}
1109
1110/**********************************************************************/
1115static void begin_turn(bool is_new_turn)
1116{
1117 log_debug("Begin turn");
1118
1120
1121 /* Reset this each turn. */
1122 if (is_new_turn) {
1126 }
1127 }
1128
1129 /* NB: Phase logic must match is_player_phase(). */
1130 switch (game.info.phase_mode) {
1131 case PMT_CONCURRENT:
1133 break;
1136 break;
1139 break;
1140 default:
1141 log_error("Unrecognized phase mode %d in begin_turn().",
1144 break;
1145 }
1147
1148 if (is_new_turn) {
1149 script_server_signal_emit("turn_begin",
1152 script_server_signal_emit("turn_started",
1153 game.info.turn > 0
1154 ? (lua_Integer)game.info.turn - 1
1157
1158 /* We build scores at the beginning of every turn. We have to
1159 * build them at the beginning so that the AI can use the data,
1160 * and we are sure to have it when we need it. */
1161 players_iterate(pplayer) {
1162 calc_civ_score(pplayer);
1165
1166 /* Retire useless barbarian units */
1167 players_iterate(pplayer) {
1168 unit_list_iterate_safe(pplayer->units, punit) {
1169 struct tile *ptile = punit->tile;
1170
1173 notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server,
1174 /* TRANS: %s is a unit type */
1175 _("%s retired!"), unit_tile_link(punit));
1177 continue;
1178 }
1181 }
1182
1183 /* find out if users attached to players have been attached to those players
1184 * for long enough. The first user to do so becomes "associated" to that
1185 * player for ranking purposes. */
1186 players_iterate(pplayer) {
1187 if (pplayer->unassigned_ranked
1188 && pplayer->user_turns++ > TURNS_NEEDED_TO_RANK
1189 && pplayer->is_alive) {
1190 sz_strlcpy(pplayer->ranked_username, pplayer->username);
1191 pplayer->unassigned_ranked = pplayer->unassigned_user;
1192 }
1194
1195 if (is_new_turn) {
1196 /* See if the value of fog of war has changed */
1198 if (game.info.fogofwar) {
1201 } else {
1204 }
1205 }
1206
1208 log_debug("Shuffleplayers");
1210 }
1211
1212 game.info.phase = 0;
1213 }
1214
1215 sanity_check();
1216}
1217
1218/**********************************************************************/
1222static void begin_phase(bool is_new_phase)
1223{
1224 log_debug("Begin phase");
1225
1227
1228 phase_players_iterate(pplayer) {
1230 /* Otherwise respect what was loaded from the savegame. */
1231 pplayer->phase_done = FALSE;
1232 }
1233 pplayer->ai_phase_done = FALSE;
1236
1238
1239 if (!is_new_phase || game.info.turn == FIRST_TURN) {
1240 /* Starting from a savegame or from the very beginning */
1244 }
1245
1246 /* Must be the first thing as it is needed for lots of functions below! */
1247 phase_players_iterate(pplayer) {
1248 /* Human players also need this for building advice */
1250 CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, is_new_phase);
1252
1253 if (is_new_phase) {
1254 /* Unit "end of turn" activities - of course these actually go at
1255 * the start of the turn! */
1256 whole_map_iterate(&(wld.map), ptile) {
1257 if (ptile->placing != NULL) {
1258 struct player *owner = NULL;
1259
1261 owner = tile_owner(ptile);
1262 } else {
1263 struct city *pcity = tile_worked(ptile);
1264
1265 if (pcity != NULL) {
1266 owner = city_owner(pcity);
1267 }
1268 }
1269
1270 if (owner == NULL) {
1271 /* Abandoned extra placing, clear it. */
1272 ptile->placing = NULL;
1273 } else {
1275 fc_assert(ptile->infra_turns > 0);
1276
1277 ptile->infra_turns--;
1278 if (ptile->infra_turns <= 0) {
1279 create_extra(ptile, ptile->placing, owner);
1280 ptile->placing = NULL;
1281
1282 /* Since extra has been added, tile is certainly
1283 * sent by update_tile_knowledge() including the
1284 * placing info, though it would not sent it if placing
1285 * were the only thing changed. */
1286 update_tile_knowledge(ptile);
1287 }
1288 }
1289 }
1290 }
1292
1293 phase_players_iterate(pplayer) {
1294 update_unit_activities(pplayer);
1295 flush_packets();
1297
1298 /* Execute orders after activities have been completed (roads built,
1299 * pillage done, etc.). */
1300 phase_players_iterate(pplayer) {
1301 int plrid = player_number(pplayer);
1302
1303 script_server_signal_emit("player_phase_begin", pplayer, is_new_phase);
1304 if (player_by_number(plrid) != pplayer) {
1305 /* Removed */
1306 continue;
1307 }
1308 flush_packets();
1310
1311 phase_players_iterate(pplayer) {
1312 city_tc_effect_refresh(pplayer);
1313 unit_tc_effect_refresh(pplayer);
1315
1316 phase_players_iterate(pplayer) {
1319
1320 flush_packets();
1321 }
1322
1323 phase_players_iterate(pplayer) {
1324 log_debug("beginning player turn for #%d (%s)",
1325 player_number(pplayer), player_name(pplayer));
1326 if (is_human(pplayer)) {
1327 building_advisor(pplayer);
1328 }
1330
1331 phase_players_iterate(pplayer) {
1332 send_player_cities(pplayer);
1334
1335 flush_packets(); /* To curb major city spam */
1337
1339 update_revolution(pplayer);
1340 update_capital(pplayer);
1342
1343 if (is_new_phase) {
1344 /* Try to avoid hiding events under a diplomacy dialog */
1345 phase_players_iterate(pplayer) {
1346 if (is_ai(pplayer)) {
1347 CALL_PLR_AI_FUNC(diplomacy_actions, pplayer, pplayer);
1348 }
1350
1351 /* Spend random movement move points before any controlled actions */
1352 phase_players_iterate(pplayer) {
1353 random_movements(pplayer);
1355
1356 log_debug("Aistartturn");
1358
1359 flush_packets();
1360 phase_players_iterate(pplayer) {
1361 unit_list_iterate_safe(pplayer->units, punit) {
1364 }
1366 execute_unit_orders(pplayer);
1367 flush_packets();
1369 } else {
1370 phase_players_iterate(pplayer) {
1371 if (is_ai(pplayer)) {
1372 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
1373 }
1375 }
1376
1377 sanity_check();
1378
1384 ? NULL : "phase");
1387
1388 if (game.server.num_phases == 1) {
1389 /* All players in the same phase.
1390 * This means that AI has been handled above, and server
1391 * will be responsive again */
1393 }
1394}
1395
1396/**********************************************************************/
1400static void end_phase(void)
1401{
1402 log_debug("Endphase");
1403
1404 /*
1405 * This empties the client Messages window; put this before
1406 * everything else below, since otherwise any messages from the
1407 * following parts get wiped out before the user gets a chance to
1408 * see them. --dwp
1409 */
1410 phase_players_iterate(pplayer) {
1411 /* Unlike the start_phase packet we only send this one to the active
1412 * player. */
1413 lsend_packet_end_phase(pplayer->connections);
1415
1416 /* Enact any government and/or policy changes.
1417 * Do this first so that following end-phase activities take the
1418 * change into account. */
1419 phase_players_iterate(pplayer) {
1420 if (pplayer->revolution_finishes <= game.info.turn
1421 && pplayer->target_government != NULL
1422 && pplayer->target_government != game.government_during_revolution
1423 && pplayer->target_government != pplayer->government) {
1424 government_change(pplayer, pplayer->target_government, TRUE);
1425 }
1426
1427 multipliers_iterate(pmul) {
1428 int idx = multiplier_index(pmul);
1429
1430 if (!multiplier_can_be_changed(pmul, pplayer)) {
1431 if (pplayer->multipliers[idx].value != pmul->def) {
1433 _("%s restored to the default value %d"),
1435 pmul->def);
1436 pplayer->multipliers[idx].value = pmul->def;
1437 pplayer->multipliers[idx].changed = game.info.turn;
1438 }
1439 } else {
1440 if (pplayer->multipliers[idx].value != pplayer->multipliers[idx].target) {
1442 _("%s now at value %d"),
1444 pplayer->multipliers[idx].target);
1445
1446 pplayer->multipliers[idx].value = pplayer->multipliers[idx].target;
1447 pplayer->multipliers[idx].changed = game.info.turn;
1448 }
1449 }
1452
1453 phase_players_iterate(pplayer) {
1454 struct research *presearch = research_get(pplayer);
1455
1456 if (A_UNSET == presearch->researching) {
1458 presearch->tech_goal);
1459
1460 if (A_UNSET != next_tech) {
1462 } else {
1464 }
1465 /* Add the researched bulbs to the pool; do *NOT* check for finished
1466 * research */
1467 update_bulbs(pplayer, 0, FALSE, FALSE);
1468 }
1470
1471 /* Freeze sending of cities. */
1473
1474 /* AI end of turn activities */
1475 players_iterate(pplayer) {
1476 unit_list_iterate(pplayer->units, punit) {
1477 CALL_PLR_AI_FUNC(unit_turn_end, pplayer, punit);
1480 phase_players_iterate(pplayer) {
1481 auto_settlers_player(pplayer);
1482 if (is_ai(pplayer)) {
1483 CALL_PLR_AI_FUNC(last_activities, pplayer, pplayer);
1484 }
1486
1487 /* Refresh cities */
1488 phase_players_iterate(pplayer) {
1489 research_get(pplayer)->free_bulbs = 0;
1491
1493 int plrid = player_number(pplayer);
1494 int old_gold;
1495
1496 do_tech_parasite_effects(pplayer);
1497 script_server_signal_emit("player_alive_phase_end", pplayer);
1498 if (player_by_number(plrid) != pplayer) {
1499 /* Removed */
1500 continue;
1501 }
1502 if (!pplayer->is_alive) {
1503 /* Died */
1504 continue;
1505 }
1506 player_restore_units(pplayer);
1507
1508 /* If player finished spaceship parts last turn already, and didn't place them
1509 * during this entire turn, autoplace them. */
1510 if (adv_spaceship_autoplace(pplayer, &pplayer->spaceship)) {
1512 _("Automatically placed spaceship parts that were still not placed."));
1513 }
1514
1515 old_gold = pplayer->economic.gold;
1516 pplayer->server.bulbs_last_turn = 0;
1517
1518 update_city_activities(pplayer);
1519
1521
1524
1525 flush_packets();
1527
1528 /* Some player/global effect may have changed cities' vision range */
1529 phase_players_iterate(pplayer) {
1532
1534
1535 /* Unfreeze sending of cities. */
1537
1538 phase_players_iterate(pplayer) {
1539 send_player_cities(pplayer);
1541 flush_packets(); /* to curb major city spam */
1542
1546
1547 phase_players_iterate(pplayer) {
1548 int plrid = player_number(pplayer);
1549
1550 script_server_signal_emit("player_phase_end", pplayer);
1551 if (player_by_number(plrid) != pplayer) {
1552 /* removed */
1553 continue;
1554 }
1555 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1556 /* This has to be after all access to advisor data. */
1557 /* We used to run this for ai players only, but data phase
1558 is initialized for human players also. */
1559 adv_data_phase_done(pplayer);
1561}
1562
1563/**********************************************************************/
1566static void end_turn(void)
1567{
1568 log_debug("Endturn");
1569
1570 /* Hack: because observer players never get an end-phase packet we send
1571 * one here. */
1573 if (NULL == pconn->playing) {
1575 }
1577
1579
1581
1582 /* Update city's counter values */
1583 players_iterate(pplayer) {
1584 city_list_iterate(pplayer->cities, pcity) {
1586 if (pcount->type == CB_CITY_OWNED_TURNS) {
1587 pcity->counter_values[pcount->index]++;
1588 }
1590 city_counters_refresh(pcity);
1593
1594#ifdef FREECIV_DEBUG
1595 /* Output some AI measurement information
1596 * log_debug() means that the values would never be used outside FREECIV_DEBUG
1597 * build even if we calculated them. */
1598 players_iterate(pplayer) {
1599 int food = 0, shields = 0, trade = 0, settlers = 0;
1600
1601 if (!is_ai(pplayer) || is_barbarian(pplayer)) {
1602 continue;
1603 }
1604
1605 unit_list_iterate(pplayer->units, punit) {
1607 settlers++;
1608 }
1610
1611 city_list_iterate(pplayer->cities, pcity) {
1612 shields += pcity->prod[O_SHIELD];
1613 food += pcity->prod[O_FOOD];
1614 trade += pcity->prod[O_TRADE];
1616
1617 log_debug("%s T%d cities:%d pop:%d food:%d prod:%d "
1618 "trade:%d settlers:%d units:%d", player_name(pplayer),
1619 game.info.turn, city_list_size(pplayer->cities),
1620 total_player_citizens(pplayer), food, shields, trade,
1621 settlers, unit_list_size(pplayer->units));
1622
1624#endif /* FREECIV_DEBUG */
1625
1626 log_debug("Season of native unrests");
1627 summon_barbarians(); /* wild guess really, no idea where to put it, but
1628 * I want to give them chance to move their units */
1629
1630 if (game.server.migration) {
1631 log_debug("Season of migrations");
1632 if (check_city_migrations()) {
1633 /* Make sure everyone has updated information about BOTH ends of the
1634 * migration movements. */
1635 players_iterate(plr) {
1636 city_list_iterate(plr->cities, pcity) {
1637 send_city_info(NULL, pcity);
1640 }
1641 }
1642
1644
1645 /* Check for new achievements during the turn.
1646 * This is not within phase, as multiple players may
1647 * achieve at the same turn and everyone deserves equal opportunity
1648 * to win. */
1650 struct player_list *achievers = player_list_new();
1651 struct player *first = achievement_plr(ach, achievers);
1653
1654 pack.id = achievement_index(ach);
1655 pack.gained = TRUE;
1656
1657 if (first != NULL) {
1659 "%s", achievement_first_msg(ach));
1660
1661 pack.first = TRUE;
1662
1664
1665 script_server_signal_emit("achievement_gained", ach, first, TRUE);
1666
1667 }
1668
1669 pack.first = FALSE;
1670
1671 if (!ach->unique) {
1672 player_list_iterate(achievers, pplayer) {
1673 /* Message already sent to first one */
1674 if (pplayer != first) {
1676 "%s", achievement_later_msg(ach));
1677
1678 lsend_packet_achievement_info(pplayer->connections, &pack);
1679
1680 script_server_signal_emit("achievement_gained", ach, pplayer,
1681 FALSE);
1682 }
1684 }
1685
1686 player_list_destroy(achievers);
1688
1689 if (game.info.global_warming) {
1695 }
1696
1697 if (game.info.nuclear_winter) {
1703 }
1704
1705 /* Handle disappearing extras before appearing extras ->
1706 * Extra never appears only to disappear at the same turn,
1707 * but it can disappear and reappear. */
1709 whole_map_iterate(&(wld.map), ptile) {
1710 if (tile_has_extra(ptile, pextra)
1711 && fc_rand(10000) < pextra->disappearance_chance
1712 && can_extra_disappear(pextra, ptile)) {
1713 tile_extra_rm_apply(ptile, pextra);
1714
1715 update_tile_knowledge(ptile);
1716
1717 if (tile_owner(ptile) != NULL) {
1718 /* TODO: Should notify players nearby even when borders disabled,
1719 * like in case of barbarian uprising */
1720 notify_player(tile_owner(ptile), ptile,
1722 /* TRANS: Small Fish disappears from (32, 72). */
1723 _("%s disappears from %s."),
1724 extra_name_translation(pextra),
1725 tile_link(ptile));
1726 }
1727
1728 /* Activities at the target tile and its neighbors may now
1729 * be illegal because of present reqs. */
1731 }
1734
1736 whole_map_iterate(&(wld.map), ptile) {
1737 if (!tile_has_extra(ptile, pextra)
1738 && fc_rand(10000) < pextra->appearance_chance
1739 && can_extra_appear(pextra, ptile)) {
1740
1741 tile_extra_apply(ptile, pextra);
1742
1743 update_tile_knowledge(ptile);
1744
1745 if (tile_owner(ptile) != NULL) {
1746 /* TODO: Should notify players nearby even when borders disabled,
1747 * like in case of barbarian uprising */
1748 notify_player(tile_owner(ptile), ptile,
1750 /* TRANS: Small Fish appears to (32, 72). */
1751 _("%s appears to %s."),
1752 extra_name_translation(pextra),
1753 tile_link(ptile));
1754 }
1755
1756 /* Activities at the target tile and its neighbors may now
1757 * be illegal because of !present reqs. */
1759 }
1762
1765 settings_turn();
1767 voting_turn();
1769
1770 log_debug("Gamenextyear");
1772 players_iterate_alive(pplayer) {
1773 pplayer->turns_alive++;
1775
1776 log_debug("Updatetimeout");
1778
1779 log_debug("Sendgameinfo");
1781
1782 log_debug("Sendplayerinfo");
1784
1785 log_debug("Sendresearchinfo");
1789
1790 log_debug("Sendyeartoclients");
1792}
1793
1794/**********************************************************************/
1797void save_game_auto(const char *save_reason, enum autosave_type type)
1798{
1799 char filename[512];
1800 const char *reason_filename = NULL;
1801
1802 if (!(game.server.autosaves & (1 << type))) {
1803 return;
1804 }
1805
1806 switch (type) {
1807 case AS_TURN:
1809 break;
1810 case AS_GAME_OVER:
1811 reason_filename = "final";
1812 break;
1813 case AS_QUITIDLE:
1814 reason_filename = "quitidle";
1815 break;
1816 case AS_INTERRUPT:
1817 reason_filename = "interrupted";
1818 break;
1819 case AS_TIMER:
1820 reason_filename = "timer";
1821 break;
1822 }
1823
1825
1826 if (type != AS_TIMER) {
1827 generate_save_name(game.server.save_name, filename, sizeof(filename),
1829 } else {
1830 fc_snprintf(filename, sizeof(filename), "%s-timer", game.server.save_name);
1831 }
1832 save_game(filename, save_reason, FALSE);
1833}
1834
1835/**********************************************************************/
1838void start_game(void)
1839{
1840 if (S_S_INITIAL != server_state()) {
1841 con_puts(C_SYNTAX, _("The game is already running."));
1842 return;
1843 }
1844
1845 /* Remove ALLOW_CTRL from whoever has it (gotten from 'first'). */
1847 if (pconn->access_level == ALLOW_CTRL) {
1849 _("%s lost control cmdlevel on "
1850 "game start. Use voting from now on."),
1851 pconn->username);
1853 }
1856
1857 con_puts(C_OK, _("Starting game."));
1858
1859 /* Prevent problems with commands that only make sense in pregame. */
1861
1862 /* This value defines if the player data should be saved for a scenario. It
1863 * is only FALSE if the editor was used to set it to this value. For
1864 * such scenarios it has to be reset at game start so that player data
1865 * is saved. */
1867
1869 /* There's no stateful packet set to client until srv_ready(). */
1870}
1871
1872/**********************************************************************/
1876{
1877 if (server_state() == S_S_RUNNING) {
1878 /* Quitting mid-game. */
1879
1880 phase_players_iterate(pplayer) {
1881 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1882 /* This has to be after all access to advisor data. */
1883 /* We used to run this for ai players only, but data phase
1884 is initialized for human players also. */
1885 adv_data_phase_done(pplayer);
1887 }
1888
1890
1891 if (game.server.save_timer != NULL) {
1894 }
1895 if (between_turns != NULL) {
1898 }
1899 if (eot_timer != NULL) {
1901 }
1903 mapimg_free();
1905 voting_free();
1907 ai_timer_free();
1908 if (game.server.phase_timer != NULL) {
1911 }
1912 if (game.server.save_timer != NULL) {
1915 }
1916
1917#ifdef HAVE_FCDB
1918 if (srvarg.fcdb_enabled) {
1919 /* If freeciv database has been initialized */
1920 fcdb_free();
1921 }
1922#endif /* HAVE_FCDB */
1923
1924 settings_free();
1926 edithand_free();
1927 voting_free();
1931 CALL_FUNC_EACH_AI(module_close);
1936 con_log_close();
1940
1942}
1943
1944/**********************************************************************/
1948{
1949 struct conn_list *dest = pconn->self;
1950
1951 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
1952 log_error("Got a report request %d before game start", type);
1953 return;
1954 }
1955
1956 if (NULL == pconn->playing && !pconn->observer) {
1957 log_error("Got a report request %d from detached connection", type);
1958 return;
1959 }
1960
1961 switch (type) {
1964 return;
1967 return;
1968 case REPORT_TOP_CITIES:
1969 report_top_cities(dest);
1970 return;
1971 case REPORT_DEMOGRAPHIC:
1973 return;
1976 return;
1977 }
1978
1980 _("request for unknown report (type %d)"), type);
1981}
1982
1983/**********************************************************************/
1987{
1989}
1990
1991/**********************************************************************/
1995{
1997}
1998
1999/**********************************************************************/
2002static bool identity_number_is_used(int id)
2003{
2004 return BV_ISSET(identity_numbers_used, id);
2005}
2006
2007/**********************************************************************/
2011{
2012 server.identity_number = (server.identity_number + 1) % IDENTITY_NUMBER_SIZE;
2013 return server.identity_number;
2014}
2015
2016/**********************************************************************/
2021{
2022 int retries = 0;
2023
2025 /* try again */
2026 if (++retries >= IDENTITY_NUMBER_SIZE) {
2027 /* Always fails. */
2029 "Exhausted city and unit numbers!");
2030 }
2031 }
2032 identity_number_reserve(server.identity_number);
2033 return server.identity_number;
2034}
2035
2036/**********************************************************************/
2043{
2045}
2046
2047/**********************************************************************/
2051bool server_packet_input(struct connection *pconn, void *packet, int type)
2052{
2053 struct player *pplayer;
2054
2055 /* A NULL packet can be returned from receive_packet_goto_route() */
2056 if (!packet) {
2057 return TRUE;
2058 }
2059
2060 /*
2061 * Old pre-delta clients (before 2003-11-28) send a
2062 * PACKET_LOGIN_REQUEST (type 0) to the server. We catch this and
2063 * reply with an old reject packet. Since there is no struct for
2064 * this old packet anymore we build it by hand.
2065 */
2066 if (type == 0) {
2067 unsigned char buffer[4096];
2068 struct raw_data_out dout;
2069
2070 log_normal(_("Warning: rejecting old client %s"),
2072
2073 dio_output_init(&dout, buffer, sizeof(buffer));
2075
2076 /* 1 == PACKET_LOGIN_REPLY in the old client */
2078
2081 _("Your client is too old. To use this server, "
2082 "please upgrade your client to a "
2083 "Freeciv 2.2 or later."));
2085
2086 {
2087 size_t size = dio_output_used(&dout);
2090
2091 /*
2092 * Use send_connection_data instead of send_packet_data to avoid
2093 * compression.
2094 */
2096 }
2097
2098 return FALSE;
2099 }
2100
2103 (struct packet_server_join_req *) packet);
2104 }
2105
2106 /* May be received on a non-established connection. */
2108 return auth_handle_reply(pconn,
2109 ((struct packet_authentication_reply *)
2110 packet)->password);
2111 }
2112
2113 if (type == PACKET_CONN_PONG) {
2115 return TRUE;
2116 }
2117
2118 if (!pconn->established) {
2119 log_error("Received game packet %s(%d) from unaccepted connection %s.",
2121 return TRUE;
2122 }
2123
2124 /* Valid packets from established connections but non-players */
2135
2136 /* Except for PACKET_EDIT_MODE (used to set edit mode), check
2137 * that the client is allowed to send the given edit packet. */
2139 && !can_conn_edit(pconn)) {
2141 _("You are not allowed to edit."));
2142 return TRUE;
2143 }
2144
2145 if (!server_handle_packet(type, packet, NULL, pconn)) {
2146 log_error("Received unknown packet %d from %s.",
2148 }
2149 return TRUE;
2150 }
2151
2152 pplayer = pconn->playing;
2153
2154 if (NULL == pplayer || pconn->observer) {
2155 if (type == PACKET_PLAYER_READY && pconn->observer) {
2157 return TRUE;
2158 }
2159 /* Don't support these yet */
2160 log_error("Received packet %s(%d) from non-player connection %s.",
2162 return TRUE;
2163 }
2164
2165 if (S_S_RUNNING != server_state()
2170 if (S_S_OVER == server_state()) {
2171 /* This can happen by accident, so we don't want to print
2172 * out lots of error messages. Ie, we use log_debug(). */
2173 log_debug("Got a packet of type %s(%d) in %s.",
2175 } else {
2176 log_error("Got a packet of type %s(%d) outside %s.",
2178 }
2179 return TRUE;
2180 }
2181
2182 pplayer->nturns_idle = 0;
2183
2184 if (!pplayer->is_alive && type != PACKET_REPORT_REQ) {
2185 log_error("Got a packet of type %s(%d) from a dead player.",
2187 return TRUE;
2188 }
2189
2190 /* Make sure to set this back to NULL before leaving this function: */
2191 pplayer->current_conn = pconn;
2192
2193 if (!server_handle_packet(type, packet, pplayer, pconn)) {
2194 log_error("Received unknown packet %d from %s.",
2196 }
2197
2198 if (S_S_RUNNING == server_state()
2199 && type != PACKET_PLAYER_READY) {
2200 /* handle_player_ready() calls start_game(), but the game isn't started
2201 * until the main loop is re-entered, so kill_dying_players would think
2202 * all players are dead. This should be solved by adding a new
2203 * game state (now S_S_GENERATING_WAITING). */
2205 }
2206
2207 pplayer->current_conn = NULL;
2208
2209 return TRUE;
2210}
2211
2212/**********************************************************************/
2217{
2218 bool connected = FALSE;
2219
2220 if (S_S_RUNNING != server_state()) {
2221 /* Not in a running state, no turn done. */
2222 return;
2223 }
2224
2225 /* fixedlength is only applicable if we have a timeout set */
2227 return;
2228 }
2229
2230 /* If there are no connected players, don't automatically advance. This is
2231 * a hack to prevent all-AI games from running rampant. Note that if
2232 * timeout is set to -1 this function call is skipped entirely and the
2233 * server will run rampant. */
2234 players_iterate_alive(pplayer) {
2235 if (pplayer->is_connected && (is_human(pplayer) || pplayer->phase_done)) {
2236 connected = TRUE;
2237 break;
2238 }
2240
2241 if (!connected) {
2242 return;
2243 }
2244
2245 phase_players_iterate(pplayer) {
2246 if (!pplayer->phase_done && pplayer->is_alive) {
2247 if (pplayer->is_connected) {
2248 /* In all cases, we wait for any connected players. */
2249 return;
2250 }
2251 if (game.server.turnblock && is_human(pplayer)) {
2252 /* If turnblock is enabled check for human players, connected
2253 * or not. */
2254 return;
2255 }
2256 if (is_ai(pplayer) && !pplayer->ai_phase_done) {
2257 /* AI player has not finished */
2258 return;
2259 }
2260 }
2262
2264}
2265
2266/**********************************************************************/
2272{
2273 if (!game_was_started() && 0 < map_startpos_count()) {
2274 /* Restrict nations to those for which start positions are defined. */
2275 nations_iterate(pnation) {
2276 fc_assert_action_msg(NULL == pnation->player,
2277 if (pnation->player->nation == pnation) {
2278 /* At least assignment is consistent. Leave nation assigned,
2279 * and make sure that nation is also marked pickable. */
2280 pnation->server.no_startpos = FALSE;
2281 continue;
2282 } else if (NULL != pnation->player->nation) {
2283 /* Not consistent. Just initialize the pointer and hope for the
2284 * best. */
2285 pnation->player->nation->player = NULL;
2286 pnation->player = NULL;
2287 } else {
2288 /* Not consistent. Just initialize the pointer and hope for the
2289 * best. */
2290 pnation->player = NULL;
2291 }, "Player assigned to nation before %s()!", __FUNCTION__);
2292
2293 if (nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
2294 /* Always allow land and sea barbarians regardless of start
2295 * positions. */
2296 pnation->server.no_startpos = FALSE;
2297 } else {
2298 /* Restrict the set of nations offered to players, based on
2299 * start positions.
2300 * If there are no start positions for a nation, remove it from the
2301 * available set. */
2302 pnation->server.no_startpos = TRUE;
2304 if (startpos_nation_allowed(psp, pnation)) {
2305 /* There is at least one start position that allows this nation,
2306 * so allow it to be picked.
2307 * (Depending on what nations players actually pick, it's not
2308 * guaranteed that the server can always find a match between
2309 * nations in this subset and start positions, in which case the
2310 * server may create mismatches.) */
2311 pnation->server.no_startpos = FALSE;
2312 break;
2313 }
2315 }
2317 } else {
2318 /* Not restricting nations by start positions. */
2319 nations_iterate(pnation) {
2320 pnation->server.no_startpos = FALSE;
2322 }
2323}
2324
2325/**********************************************************************/
2330void handle_nation_select_req(struct connection *pc, int player_no,
2331 Nation_type_id nation_no, bool is_male,
2332 const char *name, int style)
2333{
2334 struct nation_type *new_nation;
2335 struct player *pplayer = player_by_number(player_no);
2336
2337 if (!pplayer || !can_conn_edit_players_nation(pc, pplayer)) {
2338 return;
2339 }
2340
2341 new_nation = nation_by_number(nation_no);
2342
2344 char message[1024];
2345
2346 /* check sanity of the packet sent by client */
2348 return;
2349 }
2350
2353 _("%s nation is not available for user selection."),
2355 return;
2356 }
2357 if (new_nation->player && new_nation->player != pplayer) {
2359 _("%s nation is already in use."),
2361 return;
2362 }
2363
2365 message, sizeof(message))) {
2367 ftc_server, "%s", message);
2368 return;
2369 }
2370
2371 /* Should be caught by is_nation_pickable() */
2373
2375 _("%s is the %s ruler %s."),
2376 pplayer->username,
2378 player_name(pplayer));
2379
2380 pplayer->is_male = is_male;
2381 pplayer->style = style_by_number(style);
2382 } else if (name[0] == '\0') {
2383 char message[1024];
2384
2386 message, sizeof(message));
2387 }
2388
2389 (void) player_set_nation(pplayer, new_nation);
2391}
2392
2393/**********************************************************************/
2397{
2398 if (pconn->access_level == ALLOW_HACK) {
2399 players_iterate(plr) {
2400 if (is_human(plr)) {
2401 return;
2402 }
2404
2406 }
2407}
2408
2409/**********************************************************************/
2413 int player_no,
2414 bool is_ready)
2415{
2416 struct player *pplayer = player_by_number(player_no);
2417
2418 if (NULL == pplayer || S_S_INITIAL != server_state()) {
2419 return;
2420 }
2421
2422 if (pplayer != requestor) {
2423 /* Currently you can only change your own readiness. */
2424 return;
2425 }
2426
2427 pplayer->is_ready = is_ready;
2428 send_player_info_c(pplayer, NULL);
2429
2430 /* Note this is called even if the player has pressed /start once
2431 * before. For instance, when a player leaves everyone remaining
2432 * might have pressed /start already but the start won't happen
2433 * until someone presses it again. Also you can press start more
2434 * than once to remind other people to start (which is a good thing
2435 * until somebody does it too much and it gets labeled as spam). */
2436 if (is_ready) {
2437 int num_ready = 0, num_unready = 0;
2438
2439 players_iterate_alive(other_player) {
2440 if (other_player->is_connected) {
2441 if (other_player->is_ready) {
2442 num_ready++;
2443 } else {
2444 num_unready++;
2445 }
2446 }
2448
2449 if (num_unready > 0) {
2451 _("Waiting to start game: %d out of %d alive players "
2452 "are ready to start."),
2454 } else {
2455 /* Check minplayers etc. and then start */
2457 }
2458 }
2459}
2460
2461/**********************************************************************/
2466const char *aifill(int amount)
2467{
2468 char *limitreason = NULL;
2469 int limit;
2470
2471 if (game_was_started()) {
2472 return NULL;
2473 }
2474
2476 if (limit < amount) {
2477 limitreason = _("requested more than 'maxplayers' setting");
2478 }
2479
2480 /* Limit to nations provided by ruleset */
2481 if (limit > server.playable_nations) {
2482 limit = server.playable_nations;
2483 if (nation_set_count() > 1) {
2484 limitreason = _("not enough playable nations in this nation set "
2485 "(see 'nationset' setting)");
2486 } else {
2487 limitreason = _("not enough playable nations");
2488 }
2489 }
2490
2491 if (limit < player_count()) {
2492 int removal = player_slot_count() - 1;
2493
2494 while (limit < player_count() && 0 <= removal) {
2495 struct player *pplayer = player_by_number(removal);
2496
2497 removal--;
2498 if (!pplayer) {
2499 continue;
2500 }
2501
2502 if (!pplayer->is_connected && !pplayer->was_created) {
2503 server_remove_player(pplayer);
2504 }
2505 }
2506
2507 /* 'limit' can be different from 'player_count()' at this point if
2508 * there are more human or created players than the 'limit'. */
2509 return limitreason;
2510 }
2511
2512 while (limit > player_count()) {
2514 int filled = 1;
2515 struct player *pplayer;
2516
2518 NULL, FALSE);
2519 /* !game_was_started() so no need to assign_player_colors() */
2520 if (!pplayer) {
2521 break;
2522 }
2523 server_player_init(pplayer, FALSE, TRUE);
2524
2525 player_set_nation(pplayer, NULL);
2526
2527 do {
2528 fc_snprintf(leader_name, sizeof(leader_name), "AI*%d", filled++);
2529 } while (player_by_name(leader_name));
2531 pplayer->random_name = TRUE;
2532 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
2533 pplayer->unassigned_user = TRUE;
2534
2536 set_as_ai(pplayer);
2538
2539 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
2540
2541 log_normal(_("%s has been added as %s level AI-controlled player (%s)."),
2542 player_name(pplayer),
2544 ai_name(pplayer->ai));
2546 _("%s has been added as %s level AI-controlled player (%s)."),
2547 player_name(pplayer),
2549 ai_name(pplayer->ai));
2550
2551 send_player_info_c(pplayer, NULL);
2552 }
2553
2554 return limitreason;
2555}
2556
2557/**********************************************************************/
2560#define SPECHASH_TAG startpos
2561#define SPECHASH_IKEY_TYPE struct startpos *
2562#define SPECHASH_INT_DATA_TYPE
2563#include "spechash.h"
2564#define startpos_hash_iterate(hash, psp, c) \
2565 TYPED_HASH_ITERATE(struct startpos *, intptr_t, hash, psp, c)
2566#define startpos_hash_iterate_end HASH_ITERATE_END
2567
2568/**********************************************************************/
2571static void player_set_nation_full(struct player *pplayer,
2572 struct nation_type *pnation)
2573{
2574 /* Don't change the name of a created player. */
2575 player_nation_defaults(pplayer, pnation, pplayer->random_name);
2576}
2577
2578/**********************************************************************/
2581void player_nation_defaults(struct player *pplayer, struct nation_type *pnation,
2582 bool set_name)
2583{
2584 struct nation_leader *pleader;
2585
2586 fc_assert(NO_NATION_SELECTED != pnation);
2587 player_set_nation(pplayer, pnation);
2588 fc_assert(pnation == pplayer->nation);
2589
2590 pplayer->style = style_of_nation(pnation);
2591
2592 if (set_name) {
2594 }
2595
2596 if ((pleader = nation_leader_by_name(pnation, player_name(pplayer)))) {
2598 } else {
2599 pplayer->is_male = (fc_rand(2) == 1);
2600 }
2601
2602 ai_traits_init(pplayer);
2603}
2604
2605/**********************************************************************/
2632static void generate_players(void)
2633{
2634 int nations_to_assign = 0;
2635
2636 /* Announce players who already have nations, and select nations based
2637 * on player names. */
2638 players_iterate(pplayer) {
2639 if (pplayer->nation != NO_NATION_SELECTED) {
2640 /* Traits are initialized here, and not already when nation gets
2641 * picked, as player may change their mind after picking one nation,
2642 * and picks another and we want to init traits only once, for the
2643 * correct nation. */
2644 ai_traits_init(pplayer);
2645 announce_player(pplayer);
2646 continue;
2647 }
2648
2649 /* See if the player name matches a known leader name.
2650 * If more than one nation has this leader name, pick one at random.
2651 * No attempt is made to avoid clashes to maximise the number of
2652 * nations that can be assigned in this way. */
2653 {
2655 int n = 0;
2656
2657 allowed_nations_iterate(pnation) {
2658 if (is_nation_playable(pnation)
2659 && client_can_pick_nation(pnation)
2660 && NULL == pnation->player
2661 && (nation_leader_by_name(pnation, player_name(pplayer)))) {
2663 n++;
2664 }
2666 if (n > 0) {
2667 player_set_nation_full(pplayer,
2669 }
2671 }
2672 if (pplayer->nation != NO_NATION_SELECTED) {
2673 announce_player(pplayer);
2674 } else {
2676 }
2678
2679 if (0 < nations_to_assign && 0 < map_startpos_count()) {
2680 /* We're running a scenario game with specified start positions.
2681 * Prefer nations assigned to those positions (but we can fall back
2682 * to others, even if game.scenario.startpos_nations is set). */
2684 struct nation_type *picked;
2685 int c, max = -1;
2686 int i, min;
2687
2688 /* Initialization. */
2690 if (startpos_allows_all(psp)) {
2691 continue;
2692 }
2693
2694 /* Count the already-assigned players whose nations can use this
2695 * start position. */
2696 c = 0;
2697 players_iterate(pplayer) {
2698 if (NO_NATION_SELECTED != pplayer->nation
2699 && startpos_nation_allowed(psp, pplayer->nation)) {
2700 c++;
2701 }
2703
2704 startpos_hash_insert(hash, psp, c);
2705 if (c > max) {
2706 max = c;
2707 }
2709
2710 /* Try to assign nations with start positions to the unassigned
2711 * players, preferring nations whose start positions aren't usable
2712 * by already-assigned players. */
2713 players_iterate(pplayer) {
2714 if (NO_NATION_SELECTED != pplayer->nation) {
2715 continue;
2716 }
2717
2719 min = max;
2720 i = 0;
2721
2722 allowed_nations_iterate(pnation) {
2723 if (!is_nation_playable(pnation)
2724 || NULL != pnation->player) {
2725 /* Not available. */
2726 continue;
2727 }
2728
2729 startpos_hash_iterate(hash, psp, val) {
2730 if (!startpos_nation_allowed(psp, pnation)) {
2731 continue;
2732 }
2733
2734 if (val < min) {
2735 /* Pick this nation, as fewer nations already in the game
2736 * can use this start position. */
2737 picked = pnation;
2738 min = val;
2739 i = 1;
2740 } else if (val == min && 0 == fc_rand(++i)) {
2741 /* More than one nation is equally desirable. Pick one at
2742 * random. */
2743 picked = pnation;
2744 }
2747
2748 if (NO_NATION_SELECTED != picked) {
2751 announce_player(pplayer);
2752 /* Update the counts for the newly assigned nation. */
2753 startpos_hash_iterate(hash, psp, val) {
2754 if (startpos_nation_allowed(psp, picked)) {
2755 startpos_hash_replace(hash, psp, val + 1);
2756 }
2758 } else {
2759 /* No need to continue; we failed to pick a nation this time,
2760 * so we're not going to succeed next time. Fall back to
2761 * standard nation selection. */
2762 break;
2763 }
2765
2767 }
2768
2769 if (0 < nations_to_assign) {
2770 /* Pick random races. Try to select from the set permitted by
2771 * starting positions -- if we fell through here after failing to
2772 * match start positions, this will at least keep the picked
2773 * nations vaguely in keeping with the scenario.
2774 * However, even this may fail (if there are start positions that
2775 * can only be filled by nations outside the current nationset),
2776 * in which case we fall back to completely random nations. */
2777 bool needs_startpos = TRUE;
2778 players_iterate(pplayer) {
2779 if (NO_NATION_SELECTED == pplayer->nation) {
2782 if (pnation == NO_NATION_SELECTED && needs_startpos) {
2785 }
2786 fc_assert(pnation != NO_NATION_SELECTED);
2787 player_set_nation_full(pplayer, pnation);
2789 announce_player(pplayer);
2790 }
2792 }
2793
2795
2797}
2798
2799/**********************************************************************/
2804const char *pick_random_player_name(const struct nation_type *pnation)
2805{
2806 const char *choice = NULL;
2808 int n;
2809
2811 const char *name = nation_leader_name(pleader);
2812
2813 if (NULL == player_by_name(name)
2814 && NULL == player_by_user(name)) {
2816 }
2818
2820 if (n > 0) {
2822 fc_rand(n)));
2823 }
2825
2826 return choice;
2827}
2828
2829/**********************************************************************/
2832static void announce_player(struct player *pplayer)
2833{
2834 log_normal(_("%s rules the %s."),
2835 player_name(pplayer), nation_plural_for_player(pplayer));
2836
2838 ftc_server, _("%s rules the %s."),
2839 player_name(pplayer), nation_plural_for_player(pplayer));
2840
2841 /* Let the clients knows the nation of the players as soon as possible.
2842 * When a player's nation is server assigned its client will think of it
2843 * as NULL until informed about the assigned nation. */
2844 send_player_info_c(pplayer, NULL);
2845}
2846
2847/**********************************************************************/
2850static void srv_running(void)
2851{
2852 int i;
2854 bool skip_mapimg = !game.info.is_new_game; /* Do not overwrite start-of-turn image */
2856 int save_counter = game.info.is_new_game ? 1 : 0;
2857
2858 /* We may as well reset is_new_game now. */
2860
2861 log_verbose("srv_running() mostly redundant send_server_settings()");
2863
2865
2866 if (game.server.autosaves & (1 << AS_TIMER)) {
2870 ? NULL : "save interval");
2872 }
2873
2874 /*
2875 * This will freeze the reports and agents at the client.
2876 *
2877 * Do this before the body so that the PACKET_THAW_CLIENT packet is
2878 * balanced.
2879 */
2881
2883 while (S_S_RUNNING == server_state()) {
2884 /* The beginning of a turn.
2885 *
2886 * We have to initialize data as well as do some actions. However when
2887 * loading a game we don't want to do these actions (like AI unit
2888 * movement and AI diplomacy). */
2890
2891 if (game.server.num_phases != 1) {
2892 /* We allow everyone to begin adjusting cities and such
2893 * from the beginning of the turn.
2894 * With simultaneous movement we send begin_turn packet in
2895 * begin_phase() only after AI players have finished their actions. */
2897 }
2898
2900 log_debug("Starting phase %d/%d.", game.info.phase,
2904 /* When loading a savegame, we need to send loaded events, after
2905 * the clients switched to the game page (after the first
2906 * packet_start_phase is received). */
2911 }
2912
2913 is_new_turn = TRUE;
2914
2916
2917 /*
2918 * This will thaw the reports and agents at the client.
2919 */
2921
2922#ifdef LOG_TIMERS
2923 /* Before sniff (human player activites), report time to now: */
2924 log_verbose("End/start-turn server/ai activities: %g seconds",
2926#endif
2927
2928 /* Do auto-saves just before starting server_sniff_all_input(), so that
2929 * autosave happens effectively "at the same time" as manual
2930 * saves, from the point of view of restarting and AI players.
2931 * Post-increment so we don't count the first loop. */
2932 if (game.info.phase == 0) {
2933 /* Create autosaves if requested. */
2935 && game.server.save_nturns > 0) {
2936 save_counter = 0;
2937 save_game_auto("Autosave", AS_TURN);
2938 }
2939 save_counter++;
2940
2941 if (!skip_mapimg) {
2942 /* Save map image(s). */
2943 for (i = 0; i < mapimg_count(); i++) {
2944 struct mapdef *pmapdef = mapimg_isvalid(i);
2945 if (pmapdef != NULL) {
2948 } else {
2949 log_error("%s", mapimg_error());
2950 }
2951 }
2952 } else {
2954 }
2955 }
2956
2957 log_debug("sniffingpackets");
2958 check_for_full_turn_done(); /* HACK: don't wait during AI phases */
2959
2960 if (between_turns != NULL) {
2962 log_debug("Unresponsive between turns %g seconds", game.server.turn_change_time);
2963 }
2964
2966 /* nothing */
2967 }
2968
2970 between_turns != NULL ? NULL : "between turns");
2972
2973 /* After sniff, re-zero the timer: (read-out above on next loop) */
2976
2978
2979 sanity_check();
2980
2981 /*
2982 * This will freeze the reports and agents at the client.
2983 */
2985
2986 end_phase();
2987
2989
2990 if (S_S_OVER == server_state()) {
2991 break;
2992 }
2994 }
2995
2996 /* Make sure is_new_turn is reset before next turn even if
2997 * we did zero rounds in the loop (i.e. if current phase from
2998 * the savegame was >= num phases). Without this begin_turn()
2999 * would not reset phase, so there would be infinite loop
3000 * where phase is too high for is_new_turn to get set. */
3001 is_new_turn = TRUE;
3002
3003 end_turn();
3004 log_debug("Sendinfotometaserver");
3006
3009 if (game.info.turn > game.server.end_turn) {
3010 /* endturn was reached - rank users based on team scores */
3012 } else {
3013 /* game ended for victory conditions - rank users based on survival */
3015 }
3016 } else if (S_S_OVER == server_state()) {
3017 /* game terminated by /endgame command - calculate team scores */
3019 }
3020 }
3021
3022 /* This will thaw the reports and agents at the client. */
3024
3025 if (game.server.save_timer != NULL) {
3028 }
3029 if (between_turns != NULL) {
3032 }
3034}
3035
3036/**********************************************************************/
3039static void srv_prepare(void)
3040{
3041#ifdef HAVE_FCDB
3042 if (!srvarg.auth_enabled) {
3043 con_write(C_COMMENT, _("This freeciv-server program has player "
3044 "authentication support, but it's currently not "
3045 "in use."));
3046 }
3047#endif /* HAVE_FCDB */
3048
3049 /* make sure it's initialized */
3050 if (!has_been_srv_init) {
3051 srv_init();
3052 }
3053
3055
3056 /* must be before con_log_init() */
3060 /* logging available after this point */
3061
3063
3064#if IS_BETA_VERSION || IS_DEVEL_VERSION
3065 con_puts(C_COMMENT, "");
3067 con_puts(C_COMMENT, "");
3068#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
3069
3070 con_flush();
3071
3074 edithand_init();
3075 voting_init();
3076 voting_init();
3077 ai_timer_init();
3078
3084
3085#ifdef HAVE_FCDB
3086 if (srvarg.fcdb_enabled) {
3087 bool success;
3088
3090 free(srvarg.fcdb_conf); /* Never needed again */
3092 if (!success) {
3094 }
3095 }
3096#endif /* HAVE_FCDB */
3097
3098 if (srvarg.ruleset != NULL) {
3099 const char *testfilename;
3100
3102 if (testfilename == NULL) {
3103 log_fatal(_("Ruleset directory \"%s\" not found"), srvarg.ruleset);
3105 }
3107 }
3108
3109 /* Try to load a saved game */
3110 if ('\0' == srvarg.load_filename[0]
3112 /* Savegame not loaded */
3114
3115 /* Rulesets are loaded on game initialization, but may be changed later
3116 * if /load or /rulesetdir is done. */
3118 }
3119
3121
3122 if (!(srvarg.metaserver_no_send)) {
3123 log_normal(_("Sending info to metaserver <%s>."), meta_addr_port());
3124 /* Open socket for meta server */
3127 con_write(C_FAIL, _("Not starting without explicitly requested metaserver connection."));
3129 }
3130 }
3131
3132 eot_timer = timer_new(TIMER_CPU, TIMER_ACTIVE, "end-of-turn");
3133}
3134
3135/**********************************************************************/
3138static void srv_scores(void)
3139{
3140 /* Recalculate the scores in case of a spaceship victory */
3141 players_iterate(pplayer) {
3142 calc_civ_score(pplayer);
3144
3146
3150 _("The game is over..."));
3152
3153 if (game.server.save_nturns > 0
3155 || !srvarg.quitidle)) {
3156 /* Save game on game_over, but not when the gameover was caused by
3157 * the -q parameter. Be sure that it's the -q, and not an autogame
3158 * with no human players. */
3159 save_game_auto("Game over", AS_GAME_OVER);
3160 }
3161}
3162
3163/**********************************************************************/
3169{
3170 players_iterate(pplayer) {
3171 struct nation_type *pnation = nation_of_player(pplayer);
3172
3173 pplayer->government = init_government_of_nation(pnation);
3174
3176 /* If we do not do this, an assertion will trigger. This enables us to
3177 * select a valid government on game start. */
3178 pplayer->revolution_finishes = 0;
3179 }
3180
3181 multipliers_iterate(pmul) {
3182 int midx = multiplier_index(pmul);
3183
3184 pplayer->multipliers[midx].value
3185 = pplayer->multipliers[midx].target
3186 = pmul->def;
3189}
3190
3191/**********************************************************************/
3194static void srv_ready(void)
3195{
3197
3199 players_iterate(pplayer) {
3200 if (!pplayer->is_connected && is_human(pplayer)) {
3201 toggle_ai_player_direct(NULL, pplayer);
3202 }
3204 }
3205
3207
3208#ifdef TEST_RANDOM /* not defined anywhere, set it if you want it */
3209 test_random1(200);
3210 test_random1(2000);
3211 test_random1(20000);
3212 test_random1(200000);
3213#endif
3214
3215 if (game.info.is_new_game) {
3216 /* Must come before assign_player_colors() */
3219
3220 game.info.turn++; /* Pregame T0 -> game T1 */
3221 fc_assert(game.info.turn == 1);
3223 }
3224
3225 /* If we have a tile map, and MAPGEN_SCENARIO == map.server.generator,
3226 * call map_fractal_generate() anyway to make the specials, huts and
3227 * continent numbers. */
3228 if (map_is_empty()
3230 && game.info.is_new_game)) {
3231 struct {
3232 const char *name;
3233 char value[MAX_LEN_NAME * 2];
3234 char pretty[MAX_LEN_NAME * 2];
3235 } mapgen_settings[] = {
3236 { "generator", },
3237 { "startpos", },
3238 { "teamplacement", }
3239 };
3240 int i;
3241 /* If a specific seed has been requested, there's no point retrying,
3242 * as the map will be the same every time. */
3243 bool retry_ok = (wld.map.server.seed_setting == 0
3245 int max = retry_ok ? 3 : 1;
3246 bool created = FALSE;
3247 struct unit_type *utype = NULL;
3249
3250 if (sucount > 0) {
3251 for (i = 0; utype == NULL && i < sucount; i++) {
3253 }
3254 } else {
3255 /* First unit the initial city might build. */
3256 utype = get_role_unit(L_FIRSTBUILD, 0);
3257 }
3258 fc_assert(utype != NULL);
3259
3260 /* Register map generator setting main values. */
3261 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3263
3264 fc_assert_action(pset != NULL, continue);
3267 sizeof(mapgen_settings[i].value));
3269 mapgen_settings[i].pretty,
3270 sizeof(mapgen_settings[i].pretty));
3271 }
3272
3273 for (i = 0; !created && i < max ; i++) {
3275 if (!created && max > 1) {
3276 int set;
3277
3278 /* If we're retrying, seed_setting == 0, which will yield a new map
3279 * next time */
3281 if (i == 0) {
3282 /* We will retry only if max attempts allow it */
3283 log_normal(_("Failed to create suitable map, retrying with another mapseed."));
3284 } else {
3285 /* +1 - start human readable count from 1 and not from 0
3286 * +1 - refers to next round, not to one we just did
3287 * ==
3288 * +2 */
3289 log_normal(_("Attempt %d/%d"), i + 2, max);
3290 }
3292
3293 /* Remove old information already present in tiles */
3294 main_map_free();
3296 /* Restore the settings. */
3297 for (set = 0; set < ARRAY_SIZE(mapgen_settings); set++) {
3299#ifdef FREECIV_NDEBUG
3301#else /* FREECIV_NDEBUG */
3302 char error[128];
3303 bool success;
3304
3305 fc_assert_action(pset != NULL, continue);
3307 NULL, error, sizeof(error));
3309 "Failed to restore '%s': %s",
3310 mapgen_settings[set].name,
3311 error);
3312#endif /* FREECIV_NDEBUG */
3313 }
3314 main_map_allocate(); /* NOT map_init() as that would overwrite settings */
3315 }
3316 }
3317 if (!created) {
3318 bugreport_request(_("Cannot create suitable map with given settings."));
3319
3321 }
3322
3324 script_server_signal_emit("map_generated");
3325 }
3326
3327 game_map_init();
3328
3329 /* Test if main map generator settings have changed. */
3330 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3332 char pretty[sizeof(mapgen_settings[i].pretty)];
3333
3334 fc_assert_action(pset != NULL, continue);
3335 if (0 == strcmp(setting_value_name(pset, TRUE, pretty,
3336 sizeof(pretty)),
3337 mapgen_settings[i].pretty)) {
3338 continue; /* Setting didn't change. */
3339 }
3341 _("Setting '%s' has been adjusted from %s to %s."),
3343 mapgen_settings[i].pretty,
3344 pretty);
3345 log_normal(_("Setting '%s' has been adjusted from %s to %s."),
3347 mapgen_settings[i].pretty,
3348 pretty);
3349 }
3350 }
3351
3352 CALL_FUNC_EACH_AI(map_ready);
3353
3354 /* start the game */
3357
3358 if (game.info.is_new_game) {
3360
3361 /* If we're starting a new game, reset the max_players to be at
3362 * least the number of players currently in the game. */
3364
3365 /* Before the player map is allocated (and initialized)! */
3367
3368 players_iterate(pplayer) {
3369 player_map_init(pplayer);
3371 pplayer->economic.gold = game.info.gold;
3372 pplayer->economic.infra_points = game.info.infrapoints;
3374
3375 /* Give initial technologies, as specified in the ruleset and the
3376 * settings. */
3381
3382 /* Set up alliances based on team selections */
3383 players_iterate(pplayer) {
3385 if (players_on_same_team(pplayer, pdest)
3386 && player_number(pplayer) != player_number(pdest)) {
3388 player_diplstate_get(pdest, pplayer),
3389 DS_TEAM);
3390 give_shared_vision(pplayer, pdest);
3391 BV_SET(pplayer->real_embassy, player_index(pdest));
3392 }
3395
3396 /* Assign colors from the ruleset for any players who weren't
3397 * explicitly assigned colors during the pregame.
3398 * This must come after generate_players() since it can depend on
3399 * assigned nations. */
3401
3402 /* Save all settings for the 'reset game' command. */
3404 }
3405
3406 /* FIXME: can this be moved? */
3407 players_iterate(pplayer) {
3410
3411 if (!game.info.is_new_game) {
3412 players_iterate(pplayer) {
3413 if (is_ai(pplayer)) {
3414 set_ai_level_direct(pplayer, pplayer->ai_common.skill_level);
3415 }
3417 } else {
3418 players_iterate(pplayer) {
3419 /* Initialize this again to be sure */
3420 adv_data_default(pplayer);
3422 }
3423
3427
3428 if (game.info.is_new_game) {
3429 /* Place players' initial units, etc */
3430 init_new_game();
3432
3434 players_iterate(pplayer) {
3435 map_show_all(pplayer);
3437 }
3438 }
3439
3441 /* This is a heavy scenario. It may include research. The sciencebox
3442 * setting may have been changed. A change to the sciencebox setting
3443 * may have caused the stored amount of bulbs to be enough to finish
3444 * the current research. */
3445
3446 players_iterate(pplayer) {
3447 /* Check for finished research. */
3448 update_bulbs(pplayer, 0, TRUE, FALSE);
3450 }
3451
3452 if (srvarg.fcdb_enabled) {
3454 &game.server.dbid);
3455 log_debug("dbid: %d", game.server.dbid);
3456 }
3457
3458 CALL_FUNC_EACH_AI(game_start);
3459}
3460
3461/**********************************************************************/
3465{
3466 /* was redundantly in game_load() */
3467 server.playable_nations = 0;
3468 server.nbarbarians = 0;
3469 server.identity_number = IDENTITY_NUMBER_SKIP;
3470
3473
3476 /* game_init() set game.server.plr_colors to NULL. So we need to
3477 * initialize the colors after. */
3479
3481}
3482
3483/**********************************************************************/
3489{
3491
3492 /* Free all the treaties that were left open when game finished. */
3493 free_treaties();
3494
3495 /* Free the vision data, without sending updates. */
3496 players_iterate(pplayer) {
3497 unit_list_iterate(pplayer->units, punit) {
3498 /* don't bother using vision_clear_sight() */
3500 punit->server.vision->radius_sq[v] = -1;
3505
3506 city_list_iterate(pplayer->cities, pcity) {
3507 /* don't bother using vision_clear_sight() */
3509 pcity->server.vision->radius_sq[v] = -1;
3511 vision_free(pcity->server.vision);
3512 pcity->server.vision = NULL;
3513 adv_city_free(pcity);
3516
3517 /* Destroy all players; with must be separate as the player information is
3518 * needed above. This also sends the information to the clients. */
3519 players_iterate(pplayer) {
3520 server_remove_player(pplayer);
3522
3526 citymap_free();
3527 game_free();
3528}
3529
3530/**********************************************************************/
3534{
3535 srv_prepare();
3536
3537 /* Run server loop */
3538 do {
3540
3541 /* Load a script file. */
3542 if (NULL != srvarg.script_filename) {
3543 /* Adding an error message more here will duplicate them. */
3545 }
3546
3548 if (!game_was_started()) {
3550 }
3551
3552 log_normal(_("Now accepting new client connections on port %d."),
3553 srvarg.port);
3554 /* Remain in S_S_INITIAL until all players are ready. */
3556 /* When force_end_of_sniff is used in pregame, it means that the server
3557 * is ready to start (usually set within start_game()). */
3558 }
3559
3560 if (S_S_RUNNING > server_state()) {
3561 /* If restarting for lack of players, the state is S_S_OVER,
3562 * so don't try to start the game. */
3563 srv_ready(); /* srv_ready() sets server state to S_S_RUNNING. */
3564 srv_running();
3565 srv_scores();
3566 }
3567
3568 /* Remain in S_S_OVER until players log out */
3569 while (conn_list_size(game.est_connections) > 0) {
3571 }
3572
3573 if (game.info.timeout == -1 || srvarg.exit_on_end) {
3574 /* For autogames or if the -e option is specified, exit the server. */
3575 server_quit();
3576 }
3577
3578 /* Close it even between games. */
3580
3581 /* Reset server */
3585 mapimg_reset();
3589 } while (TRUE);
3590
3591 /* Technically, we won't ever get here. We exit via server_quit(). */
3593}
3594
3595/**********************************************************************/
3598struct color;
3599static inline void server_gui_color_free(struct color *pcolor)
3600{
3602
3603 return;
3604}
3605
3606/**********************************************************************/
3610static int server_plr_tile_city_id_get(const struct tile *ptile,
3611 const struct player *pplayer)
3612{
3613 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3614
3615 return plrtile && plrtile->site ? plrtile->site->identity
3617}
3618
3619/**********************************************************************/
3623{
3624 struct setting *pset = setting_by_name(name);
3625
3626 if (pset) {
3627 return setting_number(pset);
3628 } else {
3629 log_error("No server setting named %s exists.", name);
3630 return SERVER_SETTING_NONE;
3631 }
3632}
3633
3634/**********************************************************************/
3638{
3639 struct setting *pset = setting_by_number(id);
3640
3641 if (pset) {
3642 return setting_name(pset);
3643 } else {
3644 log_error("No server setting with the id %d exists.", id);
3645 return NULL;
3646 }
3647}
3648
3649/**********************************************************************/
3653{
3654 struct setting *pset = setting_by_number(id);
3655
3656 if (pset) {
3657 return setting_type(pset);
3658 } else {
3659 log_error("No server setting with the id %d exists.", id);
3660 return sset_type_invalid();
3661 }
3662}
3663
3664/**********************************************************************/
3668{
3669 struct setting *pset = setting_by_number(id);
3670
3671 if (pset) {
3672 return setting_bool_get(pset);
3673 } else {
3674 log_error("No server setting with the id %d exists.", id);
3675 return FALSE;
3676 }
3677}
3678
3679/**********************************************************************/
3683{
3684 struct setting *pset = setting_by_number(id);
3685
3686 if (pset) {
3687 return setting_int_get(pset);
3688 } else {
3689 log_error("No server setting with the id %d exists.", id);
3690 return 0;
3691 }
3692}
3693
3694/**********************************************************************/
3698{
3699 struct setting *pset = setting_by_number(id);
3700
3701 if (pset) {
3702 return setting_bitwise_get(pset);
3703 } else {
3704 log_error("No server setting with the id %d exists.", id);
3705 return FALSE;
3706 }
3707}
3708
3709/**********************************************************************/
3713{
3715
3716 funcs->server_setting_by_name = server_ss_by_name;
3717 funcs->server_setting_name_get = server_ss_name_get;
3718 funcs->server_setting_type_get = server_ss_type_get;
3719 funcs->server_setting_val_bool_get = server_ss_val_bool_get;
3720 funcs->server_setting_val_int_get = server_ss_val_int_get;
3721 funcs->server_setting_val_bitwise_get = server_ss_val_bitwise_get;
3722 funcs->create_extra = create_extra;
3723 funcs->destroy_extra = destroy_extra;
3724 funcs->destroy_city = remove_city;
3725 funcs->player_tile_vision_get = map_is_known_and_seen;
3726 funcs->player_tile_city_id_get = server_plr_tile_city_id_get;
3727 funcs->gui_color_free = server_gui_color_free;
3728
3729 /* Keep this function call at the end. It checks if all required functions
3730 are defined. */
3732}
3733
3734/**********************************************************************/
3737static enum known_type mapimg_server_tile_known(const struct tile *ptile,
3738 const struct player *pplayer,
3739 bool knowledge)
3740{
3741 if (knowledge && pplayer) {
3742 return tile_get_known(ptile, pplayer);
3743 }
3744
3745 return TILE_KNOWN_SEEN;
3746}
3747
3748/**********************************************************************/
3751static struct terrain
3752 *mapimg_server_tile_terrain(const struct tile *ptile,
3753 const struct player *pplayer, bool knowledge)
3754{
3755 if (knowledge && pplayer) {
3756 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3757 return plrtile->terrain;
3758 }
3759
3760 return tile_terrain(ptile);
3761}
3762
3763/**********************************************************************/
3766static struct player *mapimg_server_tile_owner(const struct tile *ptile,
3767 const struct player *pplayer,
3768 bool knowledge)
3769{
3770 if (knowledge && pplayer
3771 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3772 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3773 return plrtile->owner;
3774 }
3775
3776 return tile_owner(ptile);
3777}
3778
3779/**********************************************************************/
3782static struct player *mapimg_server_tile_city(const struct tile *ptile,
3783 const struct player *pplayer,
3784 bool knowledge)
3785{
3786 struct city *pcity = tile_city(ptile);
3787
3788 if (!pcity) {
3789 return NULL;
3790 }
3791
3792 if (knowledge && pplayer) {
3793 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
3794
3795 if (pdcity) {
3796 return pdcity->owner;
3797 } else {
3798 return NULL;
3799 }
3800 }
3801
3802 return city_owner(tile_city(ptile));
3803}
3804
3805/**********************************************************************/
3808static struct player *mapimg_server_tile_unit(const struct tile *ptile,
3809 const struct player *pplayer,
3810 bool knowledge)
3811{
3812 int unit_count = unit_list_size(ptile->units);
3813
3814 if (unit_count == 0) {
3815 return NULL;
3816 }
3817
3818 if (knowledge && pplayer
3819 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3820 return NULL;
3821 }
3822
3823 return unit_owner(unit_list_get(ptile->units, 0));
3824}
3825
3826/**********************************************************************/
3830{
3831 return playercolor_count();
3832}
3833
3834/**********************************************************************/
3838{
3839 return playercolor_get(i);
3840}
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:565
void adv_data_default(struct player *pplayer)
Definition advdata.c:730
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:129
const char * default_ai_type_name(void)
Definition aiiface.c:251
void ai_traits_init(struct player *pplayer)
Definition aitraits.c:33
void create_animals(void)
Definition animals.c:95
void astr_free(struct astring *astr)
Definition astring.c:153
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
void astr_init(struct astring *astr)
Definition astring.c:144
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:287
#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 auto_settlers_player(struct player *pplayer)
void adv_settlers_free(void)
void summon_barbarians(void)
Definition barbarian.c:738
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
void bugreport_request(const char *reason_format,...)
Definition bugs.c:31
void game_advance_year(void)
Definition calendar.c:91
void game_next_year(struct packet_game_info *info)
Definition calendar.c:30
#define FIRST_TURN
Definition calendar.h:20
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
void free_city_map_index(void)
Definition city.c:609
#define cities_iterate_end
Definition city.h:517
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define cities_iterate(pcity)
Definition city.h:512
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
void citymap_free(void)
Definition citymap.c:110
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3615
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2363
bool send_city_suppression(bool now)
Definition citytools.c:2166
void sync_cities(void)
Definition citytools.c:3342
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3457
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3376
void remove_city(struct city *pcity)
Definition citytools.c:1708
void city_thaw_workers_queue(void)
Definition citytools.c:198
void send_player_cities(struct player *pplayer)
Definition citytools.c:2343
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2320
bool check_city_migrations(void)
Definition cityturn.c:4226
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4592
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:577
void update_city_activities(struct player *pplayer)
Definition cityturn.c:603
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4613
void check_disasters(void)
Definition cityturn.c:4387
void city_refresh_queue_processing(void)
Definition cityturn.c:214
char * incite_cost
Definition comments.c:75
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
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:888
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:125
void free_treaties(void)
Definition diptreaty.c:332
void edithand_free(void)
Definition edithand.c:97
void edithand_init(void)
Definition edithand.c:79
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1070
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Definition extras.c:1016
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1122
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:1136
#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:1277
@ EUT_NUCLEAR_WINTER
Definition fc_types.h:1279
@ EUT_GLOBAL_WARMING
Definition fc_types.h:1278
int server_setting_id
Definition fc_types.h:1070
int Tech_type_id
Definition fc_types.h:377
int Nation_type_id
Definition fc_types.h:380
#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:1273
@ VC_ALLIED
Definition fc_types.h:1272
@ 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:1038
@ BORDERS_DISABLED
Definition fc_types.h:1037
#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:62
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:707
int current_turn_timeout(void)
Definition game.c:848
void game_init(bool keep_ruleset_value)
Definition game.c:438
struct world wld
Definition game.c:63
void game_free(void)
Definition game.c:470
void game_map_init(void)
Definition game.c:457
int generate_save_name(const char *format, char *buf, int buflen, const char *reason)
Definition game.c:791
#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:881
int update_timeout(void)
Definition gamehand.c:985
void send_game_info(struct conn_list *dest)
Definition gamehand.c:907
void init_new_game(void)
Definition gamehand.c:451
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:1445
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:501
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert_exit_msg(condition, message,...)
Definition log.h:211
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_action_msg(condition, action, message,...)
Definition log.h:201
#define log_fatal(message,...)
Definition log.h:100
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
#define log_testmatic(message,...)
Definition log.h:123
void main_map_free(void)
Definition map.c:554
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
Definition map.c:1685
int map_num_tiles(void)
Definition map.c:1014
bool startpos_allows_all(const struct startpos *psp)
Definition map.c:1696
void main_map_allocate(void)
Definition map.c:519
int map_startpos_count(void)
Definition map.c:1853
bool map_is_empty(void)
Definition map.c:149
#define map_startpos_iterate(NAME_psp)
Definition map.h:130
#define map_startpos_iterate_end
Definition map.h:133
#define whole_map_iterate(_map, _tile)
Definition map.h:545
#define whole_map_iterate_end
Definition map.h:554
@ MAPGEN_SCENARIO
Definition map_types.h:47
bool map_fractal_generate(bool autosize, struct unit_type *initial_unit)
Definition mapgen.c:1261
void generator_free(void)
void player_map_init(struct player *pplayer)
Definition maphand.c:1221
void map_set_border_vision(struct player *pplayer, const bool is_enabled)
Definition maphand.c:740
void send_map_info(struct conn_list *dest)
Definition maphand.c:649
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2621
void disable_fog_of_war(void)
Definition maphand.c:1789
void show_map_to_all(void)
Definition maphand.c:1210
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:444
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1367
void enable_fog_of_war(void)
Definition maphand.c:1763
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2556
void map_show_all(struct player *pplayer)
Definition maphand.c:879
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:768
void nuclear_winter(int effect)
Definition maphand.c:119
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2724
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
void map_calculate_borders(void)
Definition maphand.c:2373
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1439
void give_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1632
void global_warming(int effect)
Definition maphand.c:106
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1382
void mapimg_free(void)
Definition mapimg.c:558
struct mapdef * mapimg_isvalid(int id)
Definition mapimg.c:1121
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:1332
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
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:48
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:1476
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:1405
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
#define player_list_iterate(playerlist, pplayer)
Definition player.h:555
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
#define is_ai(plr)
Definition player.h:230
#define player_list_iterate_end
Definition player.h:557
#define players_iterate_alive_end
Definition player.h:547
#define set_as_ai(plr)
Definition player.h:232
#define ANON_PLAYER_NAME
Definition player.h:43
#define is_human(plr)
Definition player.h:229
#define players_iterate_alive(_pplayer)
Definition player.h:542
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2268
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1129
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1894
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3213
int normal_player_count(void)
Definition plrhand.c:3205
void playercolor_free(void)
Definition plrhand.c:3342
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:2057
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:2168
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:2453
void playercolor_init(void)
Definition plrhand.c:3333
void kill_player(struct player *pplayer)
Definition plrhand.c:126
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
void update_national_activities(struct player *pplayer, int old_gold)
Definition plrhand.c:3472
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3221
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3371
int playercolor_count(void)
Definition plrhand.c:3381
void shuffle_players(void)
Definition plrhand.c:2378
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1943
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Definition plrhand.c:337
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1619
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2303
void update_capital(struct player *pplayer)
Definition plrhand.c:731
void assign_player_colors(void)
Definition plrhand.c:1734
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2614
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2590
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:30
void registry_module_close(void)
Definition registry.c:40
void report_final_scores(struct conn_list *dest)
Definition report.c:1689
void report_wonders_of_the_world(struct conn_list *dest)
Definition report.c:525
void report_demographics(struct connection *pconn)
Definition report.c:1125
void report_wonders_of_the_world_long(struct conn_list *dest)
Definition report.c:414
void make_history_report(void)
Definition report.c:1667
void log_civ_score_free(void)
Definition report.c:1434
void report_top_cities(struct conn_list *dest)
Definition report.c:331
void report_achievements(struct connection *pconn)
Definition report.c:1189
void log_civ_score_now(void)
Definition report.c:1464
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 ruleset.c:9442
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 ruleset.c:9362
#define sanity_check()
Definition sanitycheck.h:43
void save_system_close(void)
Definition savemain.c:338
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:152
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:1137
void flush_packets(void)
Definition sernet.c:381
void init_connections(void)
Definition sernet.c:1366
enum server_events server_sniff_all_input(void)
Definition sernet.c:527
void readline_atexit(void)
Definition sernet.c:209
void close_connections_and_socket(void)
Definition sernet.c:260
@ 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:5245
int setting_int_get(struct setting *pset)
Definition settings.c:3785
struct setting * setting_by_name(const char *name)
Definition settings.c:3306
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4264
int setting_number(const struct setting *pset)
Definition settings.c:3321
struct setting * setting_by_number(int id)
Definition settings.c:3298
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3359
void settings_free(void)
Definition settings.c:5287
void settings_turn(void)
Definition settings.c:5279
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
void settings_game_start(void)
Definition settings.c:4845
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4019
const char * setting_name(const struct setting *pset)
Definition settings.c:3330
int setting_bitwise_get(struct setting *pset)
Definition settings.c:4254
bool setting_bool_get(struct setting *pset)
Definition settings.c:3673
void send_server_settings(struct conn_list *dest)
Definition settings.c:5427
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1101
const struct strvec * get_data_dirs(void)
Definition shared.c:893
#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:3039
static struct player * mapimg_server_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3766
static void server_gui_color_free(struct color *pcolor)
Definition srv_main.c:3599
void server_game_init(bool keep_ruleset_value)
Definition srv_main.c:3464
static struct terrain * mapimg_server_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3752
static struct player * mapimg_server_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3782
static void update_diplomatics(void)
Definition srv_main.c:912
static struct player * mapimg_server_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3808
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:2330
static void do_have_contacts_effect(void)
Definition srv_main.c:747
static void ai_start_phase(void)
Definition srv_main.c:1100
static struct timer * eot_timer
Definition srv_main.c:196
const char * pick_random_player_name(const struct nation_type *pnation)
Definition srv_main.c:2804
void identity_number_release(int id)
Definition srv_main.c:1986
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2581
static void handle_observer_ready(struct connection *pconn)
Definition srv_main.c:2396
bv_id identity_numbers_used
Definition srv_main.c:190
void handle_report_req(struct connection *pconn, enum report_type type)
Definition srv_main.c:1947
static void generate_players(void)
Definition srv_main.c:2632
bool force_end_of_sniff
Definition srv_main.c:188
static void do_reveal_effects(void)
Definition srv_main.c:724
static int mapimg_server_plrcolor_count(void)
Definition srv_main.c:3829
void start_game(void)
Definition srv_main.c:1838
void handle_client_info(struct connection *pc, enum gui_type gui, int emerg_version, const char *distribution)
Definition srv_main.c:310
void handle_player_ready(struct player *requestor, int player_no, bool is_ready)
Definition srv_main.c:2412
const char * aifill(int amount)
Definition srv_main.c:2466
static bool identity_number_is_used(int id)
Definition srv_main.c:2002
static void end_phase(void)
Definition srv_main.c:1400
static enum server_states civserver_state
Definition srv_main.c:182
static void begin_turn(bool is_new_turn)
Definition srv_main.c:1115
static void end_turn(void)
Definition srv_main.c:1566
void save_game_auto(const char *save_reason, enum autosave_type type)
Definition srv_main.c:1797
static struct rgbcolor * mapimg_server_plrcolor_get(int i)
Definition srv_main.c:3837
void set_server_state(enum server_states newstate)
Definition srv_main.c:341
static int increment_identity_number(void)
Definition srv_main.c:2010
const char * server_ss_name_get(server_setting_id id)
Definition srv_main.c:3637
static void begin_phase(bool is_new_phase)
Definition srv_main.c:1222
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:791
static void kill_dying_players(void)
Definition srv_main.c:1074
bool game_was_started(void)
Definition srv_main.c:349
static void srv_scores(void)
Definition srv_main.c:3138
#define startpos_hash_iterate(hash, psp, c)
Definition srv_main.c:2564
void identity_number_reserve(int id)
Definition srv_main.c:1994
struct server_arguments srvarg
Definition srv_main.c:176
static void srv_ready(void)
Definition srv_main.c:3194
static void srv_running(void)
Definition srv_main.c:2850
static void final_ruleset_adjustments(void)
Definition srv_main.c:3168
#define startpos_hash_iterate_end
Definition srv_main.c:2566
static int server_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Definition srv_main.c:3610
static bool is_client_edit_packet(int type)
Definition srv_main.c:2042
void fc__noreturn srv_main(void)
Definition srv_main.c:3533
static void notify_illegal_armistice_units(struct player *phost, struct player *pguest, int turns_left)
Definition srv_main.c:829
bool server_ss_val_bool_get(server_setting_id id)
Definition srv_main.c:3667
static void remove_illegal_armistice_units(struct player *plr1, struct player *plr2)
Definition srv_main.c:873
int identity_number(void)
Definition srv_main.c:2020
server_setting_id server_ss_by_name(const char *name)
Definition srv_main.c:3622
void check_for_full_turn_done(void)
Definition srv_main.c:2216
static void player_set_nation_full(struct player *pplayer, struct nation_type *pnation)
Definition srv_main.c:2571
static void announce_player(struct player *pplayer)
Definition srv_main.c:2832
void srv_init(void)
Definition srv_main.c:227
bool server_packet_input(struct connection *pconn, void *packet, int type)
Definition srv_main.c:2051
static void fc_interface_init_server(void)
Definition srv_main.c:3712
int server_ss_val_int_get(server_setting_id id)
Definition srv_main.c:3682
static struct timer * between_turns
Definition srv_main.c:198
unsigned int server_ss_val_bitwise_get(server_setting_id id)
Definition srv_main.c:3697
static bool has_been_srv_init
Definition srv_main.c:193
void send_all_info(struct conn_list *dest)
Definition srv_main.c:692
void init_game_seed(void)
Definition srv_main.c:203
void fc__noreturn server_quit(void)
Definition srv_main.c:1875
void update_nations_with_startpos(void)
Definition srv_main.c:2271
enum sset_type server_ss_type_get(server_setting_id id)
Definition srv_main.c:3652
bool check_for_game_over(void)
Definition srv_main.c:363
static enum known_type mapimg_server_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3737
static void do_border_vision_effect(void)
Definition srv_main.c:764
enum server_states server_state(void)
Definition srv_main.c:333
void server_game_free(void)
Definition srv_main.c:3488
#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:1632
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:2002
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:3788
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6112
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:706
Definition city.h:320
int num_phases
Definition game.h:173
struct civ_game::@31::@35::@39 mutexes
void(* unit_deallocate)(int unit_id)
Definition game.h:304
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:193
int save_nturns
Definition game.h:187
float turn_change_time
Definition game.h:222
bool fixedlength
Definition game.h:150
struct packet_ruleset_control control
Definition game.h:83
bool fogofwar_old
Definition game.h:238
int end_turn
Definition game.h:148
fc_mutex city_list
Definition game.h:274
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
unsigned autosaves
Definition game.h:189
struct timer * save_timer
Definition game.h:221
bool endspaceship
Definition game.h:149
char rulesetdir[MAX_LEN_NAME]
Definition game.h:242
int start_year
Definition game.h:195
bool migration
Definition game.h:168
int additional_phase_seconds
Definition game.h:216
randseed seed
Definition game.h:231
int dbid
Definition game.h:251
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:230
struct timer * phase_timer
Definition game.h:215
int nuclear_winter_percent
Definition game.h:236
unsigned revealmap
Definition game.h:181
char orig_game_version[MAX_LEN_NAME]
Definition game.h:225
struct civ_game::@33 callbacks
char save_name[MAX_LEN_NAME]
Definition game.h:224
struct civ_game::@31::@35 server
struct packet_timeout_info tinfo
Definition game.h:91
int phase_mode_stored
Definition game.h:220
int max_players
Definition game.h:160
bool auto_ai_toggle
Definition game.h:134
int global_warming_percent
Definition game.h:234
struct government * government_during_revolution
Definition game.h:94
bool turnblock
Definition game.h:201
int xsize
Definition map_types.h:78
int ysize
Definition map_types.h:78
bool have_resources
Definition map_types.h:108
struct civ_map::@42::@44 server
randseed seed_setting
Definition map_types.h:91
enum map_generator generator
Definition map_types.h:98
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:114
char contact_turns_left
Definition player.h:202
int auto_cancel_turn
Definition player.h:204
int first_contact_turn
Definition player.h:199
enum diplstate_type type
Definition player.h:197
char has_reason_to_cancel
Definition player.h:201
int culture
Definition player.h:107
bool random_name
Definition player.h:293
struct player_ai ai_common
Definition player.h:286
bool is_male
Definition player.h:255
char username[MAX_LEN_NAME]
Definition player.h:250
bool is_winner
Definition player.h:267
bool is_connected
Definition player.h:294
int nturns_idle
Definition player.h:263
struct connection * current_conn
Definition player.h:295
struct team * team
Definition player.h:259
bool was_created
Definition player.h:292
const struct ai_type * ai
Definition player.h:287
struct unit_list * units
Definition player.h:280
bool is_alive
Definition player.h:266
struct player_score score
Definition player.h:281
struct nation_type * nation
Definition player.h:258
struct nation_style * style
Definition player.h:277
bool is_ready
Definition player.h:260
bool unassigned_user
Definition player.h:251
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:138
enum unit_activity activity
Definition unit.h:157
struct vision * vision
Definition unit.h:244
struct unit::@81::@84 server
struct tile * tile
Definition unit.h:140
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:974
#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:283
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:118
known_type
Definition tile.h:35
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:114
#define tile_has_extra(ptile, pextra)
Definition tile.h:151
#define tile_owner(_tile)
Definition tile.h:96
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:264
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:384
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:2649
bool is_enter_borders_unit(const struct unit *punit)
Definition unit.c:340
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
#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:667
void random_movements(struct player *pplayer)
Definition unittools.c:4934
void finalize_unit_phase_beginning(struct player *pplayer)
Definition unittools.c:699
void execute_unit_orders(struct player *pplayer)
Definition unittools.c:677
void do_explore(struct unit *punit)
Definition unittools.c:2945
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2132
void unit_tc_effect_refresh(struct player *pplayer)
Definition unittools.c:689
void player_restore_units(struct player *pplayer)
Definition unittools.c:478
bool unit_can_be_retired(struct unit *punit)
Definition unittools.c:4917
void send_all_known_units(struct conn_list *dest)
Definition unittools.c:2767
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2253
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