Freeciv21
Develop your civilization from humble roots to a global empire
client_main.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2023 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include <fc_config.h>
15 
16 #ifdef FREECIV_MSWINDOWS
17 #include <windows.h> // LoadLibrary()
18 #endif
19 
20 #include <cmath>
21 #include <csignal>
22 
23 // Qt
24 #include <QApplication>
25 #include <QBitArray>
26 #include <QCommandLineParser>
27 #include <QElapsedTimer>
28 #include <QGlobalStatic>
29 #include <QTimer>
30 #include <QUrl>
31 
32 // utility
33 #include "capstr.h"
34 #include "dataio.h"
35 #include "deprecations.h"
36 #include "fcbacktrace.h"
37 #include "fciconv.h"
38 #include "fcintl.h"
39 #include "log.h"
40 #include "rand.h"
41 
42 // common
43 #include "ai.h"
44 #include "diptreaty.h"
45 #include "fc_interface.h"
46 #include "game.h"
47 #include "helpdata.h" // boot_help_texts()
48 #include "net_types.h"
49 #include "packets.h"
50 #include "player.h"
51 #include "research.h"
52 #include "server_settings.h"
53 #include "version.h"
54 
55 /* client/include */
56 #include "dialogs_g.h"
57 #include "diplodlg_g.h"
58 #include "gui_main_g.h"
59 #include "mapctrl_g.h"
60 #include "mapview_g.h"
61 #include "menu_g.h"
62 #include "pages_g.h"
63 #include "voteinfo_bar_g.h"
64 
65 // client
66 #include "attribute.h"
67 #include "audio/audio.h"
68 #include "chatline_common.h"
69 #include "climisc.h"
70 #include "clinet.h"
71 #include "connectdlg_common.h" // client_kill_server()
72 #include "control.h"
73 #include "editor.h"
74 #include "fonts.h"
75 #include "global_worklist.h"
76 #include "governor.h"
77 #include "helpdlg.h"
78 #include "messagewin_common.h"
79 #include "minimap_panel.h"
80 #include "music.h"
81 #include "options.h"
82 #include "overview_common.h"
83 #include "packhand.h"
84 #include "qtg_cxxside.h"
85 #include "themes_common.h"
86 #include "tileset/tilespec.h"
87 #include "update_queue.h"
88 #include "views/view_cities_data.h"
89 #include "views/view_map_common.h"
91 #include "voteinfo.h"
92 
93 /* client/luascript */
94 #include "script_client.h"
95 
96 #include "client_main.h"
97 
98 #include "packhand_gen.h"
99 
100 static enum known_type mapimg_client_tile_known(const struct tile *ptile,
101  const struct player *pplayer,
102  bool knowledge);
103 static struct terrain *
104 mapimg_client_tile_terrain(const struct tile *ptile,
105  const struct player *pplayer, bool knowledge);
106 static struct player *mapimg_client_tile_owner(const struct tile *ptile,
107  const struct player *pplayer,
108  bool knowledge);
109 static struct player *mapimg_client_tile_city(const struct tile *ptile,
110  const struct player *pplayer,
111  bool knowledge);
112 static struct player *mapimg_client_tile_unit(const struct tile *ptile,
113  const struct player *pplayer,
114  bool knowledge);
115 static int mapimg_client_plrcolor_count();
116 static struct rgbcolor *mapimg_client_plrcolor_get(int i);
117 
118 static void fc_interface_init_client();
119 
120 namespace /* anonymous */ {
121 QUrl url;
122 }
123 
124 QString logfile;
125 QString scriptfile;
126 QString savefile;
133  false; // TRUE = skip "Connect to Freeciv21 Server" dialog
134 bool auto_spawn = false; // TRUE = skip main menu, start local server
136 
137 struct civclient client;
138 
140 
141 // TRUE if an end turn request is blocked by busy agents
142 bool waiting_for_end_turn = false;
143 
144 /*
145  * TRUE between receiving PACKET_END_TURN and PACKET_BEGIN_TURN
146  */
147 static bool server_busy = false;
148 
149 #ifdef FREECIV_DEBUG
150 bool hackless = false;
151 #endif
152 
153 static bool client_quitting = false;
154 
159 static char *put_conv(const char *src, size_t *length)
160 {
161  char *out = internal_to_data_string_malloc(src);
162 
163  if (out) {
164  *length = qstrlen(out);
165  return out;
166  } else {
167  *length = 0;
168  return nullptr;
169  }
170 }
171 
177 static bool get_conv(char *dst, size_t ndst, const char *src, size_t nsrc)
178 {
179  Q_UNUSED(nsrc)
180 
181  char *out = data_to_internal_string_malloc(src);
182  bool ret = true;
183  size_t len;
184 
185  if (!out) {
186  dst[0] = '\0';
187  return false;
188  }
189 
190  len = qstrlen(out);
191  if (ndst > 0 && len >= ndst) {
192  ret = false;
193  len = ndst - 1;
194  }
195 
196  memcpy(dst, out, len);
197  dst[len] = '\0';
198  delete[] out;
199 
200  return ret;
201 }
202 
206 static void charsets_init()
207 {
210 }
211 
216 static void emergency_exit() { client_kill_server(true); }
217 
221 static void at_exit()
222 {
223  emergency_exit();
224  packets_deinit();
225  update_queue::uq()->drop();
227 }
228 
232 static void client_game_init()
233 {
234  client.conn.playing = nullptr;
235  client.conn.observer = false;
236 
237  game_init(false);
238  attribute_init();
239  control_init();
240  link_marks_init();
247 }
248 
252 static void client_game_free()
253 {
255 
256  mapimg_free();
257  packhand_free();
260  link_marks_free();
261  control_free();
262  free_help_texts();
263  attribute_free();
264  governor::i()->drop();
265  game.client.ruleset_init = false;
266  game.client.ruleset_ready = false;
267  game_free();
268  /* update_queue_init() is correct at this point. The queue is reset to
269  a clean state which is also needed if the client is not connected to
270  the server! */
271  update_queue::uq()->init();
272 
273  client.conn.playing = nullptr;
274  client.conn.observer = false;
275 }
276 
281 static void client_game_reset()
282 {
284 
285  packhand_free();
286  link_marks_free();
287  control_free();
288  attribute_free();
289  governor::i()->drop();
290 
291  game_reset();
292  mapimg_reset();
293 
294  attribute_init();
295  control_init();
296  link_marks_init();
297 }
298 
302 int client_main(int argc, char *argv[])
303 {
304  QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
305  QApplication::setHighDpiScaleFactorRoundingPolicy(
306  Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
307  QApplication app(argc, argv);
308  QCoreApplication::setApplicationVersion(freeciv21_version());
309  app.setDesktopFileName(QStringLiteral("net.longturn.freeciv21"));
310 
311  i_am_client(); // Tell to libfreeciv that we are client
312 
314 
315  game.client.ruleset_init = false;
316 
317  /* Ensure that all AIs are initialized to unused state
318  * Not using ai_type_iterate as it would stop at
319  * current ai type count, ai_type_get_count(), i.e., 0 */
320  for (int aii = 0; aii < FREECIV_AI_MOD_LAST; aii++) {
321  struct ai_type *ai = get_ai_type(aii);
322 
323  init_ai(ai);
324  }
325 
326  init_nls();
327 #ifdef ENABLE_NLS
328  (void) bindtextdomain("freeciv21-nations", get_locale_dir());
329 #endif
331 #ifdef ENABLE_NLS
332  bind_textdomain_codeset("freeciv21-nations", get_internal_encoding());
333 #endif
334 
335  QCommandLineParser parser;
336  parser.addHelpOption();
337  parser.addVersionOption();
338 
339  // List of all the supported options
340  bool ok = parser.addOptions(
341  {{{"A", _("Announce")},
342  // TRANS: Do not translate IPv4, IPv6 and none
343  _("Announce game in LAN using protocol PROTO (IPv4/IPv6/none)."),
344  _("PROTO"),
345  "IPv4"},
346  {{"a", "autoconnect"}, _("Skip connect dialog.")},
347  {{"d", _("debug")},
348  // TRANS: Do not translate "fatal", "critical", "warning", "info" or
349  // "debug". It's exactly what the user must type.
350  _("Set debug log level (fatal/critical/warning/info/debug)."),
351  _("LEVEL"),
352  QStringLiteral("info")},
353  {{"F", _("Fatal")}, _("Raise a signal on failed assertion.")},
354  {{"f", "file"}, _("Load saved game FILE."), "FILE"},
355 #ifdef FREECIV_DEBUG
356  {{"H", "Hackless"},
357  _("Do not request hack access to local, but not spawned, server.")},
358 #endif // FREECIV_DEBUG
359  {{"l", "log"},
360  _("Use FILE as logfile (spawned server also uses this)."),
361  "FILE"},
362  {{"M", "Meta"}, _("Connect to the metaserver at HOST."), "HOST"},
363  {{"n", "name"}, _("Use NAME as username on server."), "NAME"},
364  {{"p", "port"},
365  _("Connect to server port PORT (usually with -a)."),
366  "PORT"},
367  {{"P", _("Plugin")}, _("Use PLUGIN for sound output."), "PLUGIN"},
368  {{"r", "read"},
369  _("Read startup script FILE (for spawned server only)."),
370  "FILE"},
371  {{"s", "server"},
372  _("Connect to the server at HOST (usually with -a)."),
373  "HOST"},
374  {{"S", "Sound"}, _("Read sound tags from FILE."), "FILE"},
375  {{"m", "music"}, _("Read music tags from FILE."), "FILE"},
376  {{"t", "tiles"}, _("Use data file FILE.tilespec for tiles."), "FILE"},
377  {{"w", "warnings"}, _("Warn about deprecated modpack constructs.")},
378  {"debug-tileset", _("Prints tileset debugging information.")}});
379 
380  parser.addPositionalArgument(
381  _("url"), _("Server information in URL format."), _("[url]"));
382  if (!ok) {
383  qFatal("Adding command line arguments failed.");
384  exit(EXIT_FAILURE);
385  }
386  parser.process(app);
387 
388  // Process the parsed options
389 
390  // Init log level
391  {
392  QStringList extra;
393  if (!parser.isSet(QStringLiteral("debug-tileset"))) {
394  extra.push_back(QStringLiteral("freeciv.tileset.info = false"));
395  }
396  if (!log_init(parser.value(QStringLiteral("debug")), extra)) {
397  exit(EXIT_FAILURE);
398  }
399  }
400  if (parser.isSet(QStringLiteral("version"))) {
401  fc_fprintf(stderr, "%s %s\n", freeciv_name_version(), client_string);
402  exit(EXIT_SUCCESS);
403  }
404 #ifdef FREECIV_DEBUG
405  if (parser.isSet(QStringLiteral("Hackless"))) {
406  hackless = true;
407  }
408 #endif
409  if (parser.isSet(QStringLiteral("log"))) {
410  logfile = parser.value(QStringLiteral("log"));
411  }
412  fc_assert_set_fatal(parser.isSet(QStringLiteral("Fatal")));
413  if (parser.isSet(QStringLiteral("read"))) {
414  scriptfile = parser.value(QStringLiteral("read"));
415  }
416  if (parser.isSet(QStringLiteral("file"))) {
417  savefile = parser.value(QStringLiteral("file"));
418  auto_spawn = true;
419  }
420  if (parser.isSet(QStringLiteral("name"))) {
421  url.setUserName(parser.value(QStringLiteral("name")));
422  }
423  if (parser.isSet(QStringLiteral("Meta"))) {
424  cmd_metaserver = parser.value(QStringLiteral("Meta"));
425  }
426  if (parser.isSet(QStringLiteral("Sound"))) {
427  sound_set_name = parser.value(QStringLiteral("Sound"));
428  }
429  if (parser.isSet(QStringLiteral("music"))) {
430  music_set_name = parser.value(QStringLiteral("music"));
431  }
432  if (parser.isSet(QStringLiteral("Plugin"))) {
433  sound_plugin_name = parser.value(QStringLiteral("Plugin"));
434  }
435  if (parser.isSet(QStringLiteral("port"))) {
436  bool conversion_ok;
437  url.setPort(parser.value(QStringLiteral("port")).toUInt(&conversion_ok));
438  if (!conversion_ok) {
439  qFatal(_("Invalid port number %s"),
440  qUtf8Printable(parser.value("port")));
441  exit(EXIT_FAILURE);
442  }
443  }
444  if (parser.isSet(QStringLiteral("server"))) {
445  url.setHost(parser.value(QStringLiteral("server")));
446  }
447  if (parser.isSet(QStringLiteral("autoconnect"))) {
448  auto_connect = true;
449  }
450  if (parser.isSet(QStringLiteral("tiles"))) {
451  forced_tileset_name = parser.value(QStringLiteral("tiles"));
452  }
454  if (parser.isSet(QStringLiteral("Announce"))) {
455  auto value = parser.value(QStringLiteral("Announce")).toLower();
456  if (value == QLatin1String("ipv4")) {
458  } else if (value == QLatin1String("ipv6")) {
460  } else if (value == QLatin1String("none")) {
462  } else {
463  qCritical(_("Illegal value \"%s\" for --Announce"),
464  qUtf8Printable(parser.value("Announce")));
465  }
466  }
467  if (parser.isSet(QStringLiteral("warnings"))) {
468  qCWarning(deprecations_category,
469  // TRANS: Do not translate --warnings
470  _("The --warnings option is deprecated."));
471  }
472 
473  // Server URL as positional argument
474  auto positional = parser.positionalArguments();
475  if (positional.size() == 1) {
476  url = QUrl(positional.constFirst());
477  // Supported schemes: fc21://, fc21+local://
478  if (!url.isValid() || (!url.scheme().startsWith("fc21"))) {
479  // Try with the default protocol
480  url = QUrl(QStringLiteral("fc21://") + positional.constFirst());
481  // Still no luck
482  if (!url.isValid()) {
483  qFatal("%s", qPrintable(url.errorString()));
484  }
485  }
486  auto_connect = true;
487  } else if (!positional.isEmpty()) {
488  qFatal(_("Too many positional arguments."));
489  } else {
490  // Unset by default
491  url.setScheme(QStringLiteral("fc21"));
492  }
493 
494  if (auto_spawn && auto_connect) {
495  // TRANS: don't translate option names
496  fc_fprintf(stderr, _("-f/--file and -a/--autoconnect options are "
497  "incompatible\n"));
498  exit(EXIT_FAILURE);
499  }
500 
501  // disallow running as root -- too dangerous
502  dont_run_as_root(argv[0], "freeciv21-client");
503 
505  backtrace_init();
506 
507  // after log_init:
508 
510 
511  audio_init();
512  options_init();
513  configure_fonts();
514  init_themes();
515 
516  options_load();
517 
518  // Set default username
521  }
523  char buf[sizeof(gui_options->default_user_name)];
524 
525  fc_snprintf(buf, sizeof(buf), "_%s", gui_options->default_user_name);
526  if (is_valid_username(buf)) {
528  } else {
530  sizeof(gui_options->default_user_name), "player%d",
531  (int) fc_rand(10000));
532  }
533  }
534 
535  // initialization
536  game.all_connections = conn_list_new();
537  game.est_connections = conn_list_new();
538 
539  charsets_init();
540  update_queue::uq()->init();
541 
543 
544  // register exit handler
545  atexit(at_exit);
547 
550 
551  if (sound_set_name.isEmpty()) {
553  }
554  if (music_set_name.isEmpty()) {
556  }
557  if (sound_plugin_name.isEmpty()) {
559  }
560  if (url.host().isEmpty()) {
561  url.setHost(gui_options->default_server_host);
562  } else if (gui_options->use_prev_server) {
563  sz_strlcpy(gui_options->default_server_host, qUtf8Printable(url.host()));
564  }
565  if (url.userName().isEmpty()) {
566  url.setUserName(gui_options->default_user_name);
567  }
568  if (cmd_metaserver.isEmpty()) {
569  // FIXME: Find a cleaner way to achieve this.
570  /* www.cazfi.net/freeciv/metaserver/ was default metaserver
571  * over one release when meta.freeciv.org was unavailable. */
572  const char *oldaddr = "http://www.cazfi.net/freeciv/metaserver/";
573 
574  if (0 == strcmp(gui_options->default_metaserver, oldaddr)) {
575  qInfo(_("Updating old metaserver address \"%s\"."), oldaddr);
577  qInfo(_("Default metaserver has been set to value \"%s\"."),
579  }
580  if (0
581  == strcmp(gui_options->default_metaserver,
583  cmd_metaserver = FREECIV_META_URL;
584  } else {
586  }
587  }
588  if (url.port() <= 0) {
589  url.setPort(gui_options->default_server_port);
590  } else if (gui_options->use_prev_server) {
591  gui_options->default_server_port = url.port();
592  }
593 
594  /* This seed is not saved anywhere; randoms in the client should
595  have cosmetic effects only (eg city name suggestions). --dwp */
596  fc_srand(time(nullptr));
598 
600  if (!forced_tileset_name.isEmpty()) {
601  if (!tilespec_try_read(forced_tileset_name, true, -1)) {
602  qCritical(_("Can't load requested tileset %s!"),
603  qUtf8Printable(forced_tileset_name));
604  client_exit();
605  return EXIT_FAILURE;
606  }
607  } else {
608  tilespec_try_read(QString(), false, -1);
609  }
610 
612  if (!auto_connect) {
613  // People autoconnecting won't stay in the menus for long. Avoid starting
614  // music that will be stopped immediately.
615  start_menu_music(QStringLiteral("music_menu"), nullptr);
616  }
617 
618  editor_init();
619 
620  // run gui-specific client
621  ui_main();
622 
623  // termination
624  client_exit();
625 
626  // not reached
627  return EXIT_SUCCESS;
628 }
629 
633 static void log_option_save_msg(QtMsgType lvl, const QString &msg)
634 {
635  switch (lvl) {
636  case QtDebugMsg:
637  qDebug("%s", qUtf8Printable(msg));
638  break;
639  case QtInfoMsg:
640  qInfo("%s", qUtf8Printable(msg));
641  break;
642  case QtWarningMsg:
643  qWarning("%s", qUtf8Printable(msg));
644  break;
645  case QtCriticalMsg:
646  qCritical("%s", qUtf8Printable(msg));
647  break;
648  case QtFatalMsg:
649  qFatal("%s", qUtf8Printable(msg));
650  break;
651  }
652 }
653 
659 {
660  if (client_state() >= C_S_PREPARING) {
661  attribute_flush();
663  }
664 
667  }
668 
669  audio_shutdown();
670 
671  overview_free();
673 
674  ui_exit();
675 
677 
678  editor_free();
679  options_free();
680  if (client_state() >= C_S_PREPARING) {
682  }
683 
684  conn_list_destroy(game.all_connections);
685  conn_list_destroy(game.est_connections);
686 
687  free_libfreeciv();
688  free_nls();
689 
691  log_close();
692 
693  exit(EXIT_SUCCESS);
694 }
695 
699 void client_packet_input(void *packet, int type)
700 {
701  if (!client.conn.established && PACKET_CONN_PING != type
702  && PACKET_PROCESSING_STARTED != type
703  && PACKET_PROCESSING_FINISHED != type
704  && PACKET_SERVER_JOIN_REPLY != type
705  && PACKET_AUTHENTICATION_REQ != type && PACKET_SERVER_SHUTDOWN != type
706  && PACKET_CONNECT_MSG != type && PACKET_EARLY_CHAT_MSG != type
707  && PACKET_SERVER_INFO != type) {
708  qCritical("Received packet %s (%d) before establishing connection!",
709  packet_name(static_cast<packet_type>(type)), type);
711  } else if (!client_handle_packet(static_cast<packet_type>(type), packet)) {
712  qCritical("Received unknown packet (type %d) from server!", type);
714  }
715 }
716 
721 
726 {
727  log_debug("send_turn_done() can_end_turn=%d", can_end_turn());
728 
729  if (!can_end_turn()) {
730  /*
731  * The turn done button is disabled but the user may have pressed
732  * the return key.
733  */
734 
735  if (!governor::i()->hot()) {
736  waiting_for_end_turn = true;
737  }
738 
739  return;
740  }
741 
742  waiting_for_end_turn = false;
743 
744  attribute_flush();
745 
746  dsend_packet_player_phase_done(&client.conn, game.info.turn);
747 
749 }
750 
755 {
756  dsend_packet_report_req(&client.conn, type);
757 }
758 
762 void set_client_state(enum client_states newstate)
763 {
764  enum client_states oldstate = civclient_state;
765  struct player *pplayer = client_player();
766 
767  if (auto_spawn) {
769  auto_spawn = false;
770  if (!client_start_server(url.userName())) {
771  qFatal(_("Failed to start local server; aborting."));
772  exit(EXIT_FAILURE);
773  }
774  }
775 
776  if (auto_connect && newstate == C_S_DISCONNECTED) {
777  if (oldstate == C_S_DISCONNECTED) {
778  qFatal(_("There was an error while auto connecting; aborting."));
779  exit(EXIT_FAILURE);
780  } else {
782  auto_connect = false; // Don't try this again.
783  }
784  }
785 
786  if (C_S_PREPARING == newstate
788  // Reset the delta-state.
790  }
791 
792  if (oldstate == newstate) {
793  return;
794  }
795 
796  if (oldstate == C_S_RUNNING && newstate != C_S_PREPARING) {
798 
799  if (!is_client_quitting()) {
800  // Back to menu
801  start_menu_music(QStringLiteral("music_menu"), nullptr);
802  }
803  }
804 
805  civclient_state = newstate;
806 
807  switch (newstate) {
808  case C_S_INITIAL:
809  qCritical("%d is not a valid client state to set.", C_S_INITIAL);
810  break;
811 
812  case C_S_DISCONNECTED:
817 
818  if (oldstate > C_S_DISCONNECTED) {
819  unit_focus_set(nullptr);
820  editor_clear();
824  if (oldstate > C_S_PREPARING) {
826  }
827  }
828 
829  set_client_page(PAGE_MAIN);
830  break;
831 
832  case C_S_PREPARING:
837 
838  if (oldstate < C_S_PREPARING) {
840  } else {
841  /* From an upper state means that we didn't quit the server,
842  * so a lot of informations are still in effect. */
845  }
846 
847  unit_focus_set(nullptr);
848 
849  if (get_client_page() != PAGE_SCENARIO
850  && get_client_page() != PAGE_LOAD) {
851  set_client_page(PAGE_START);
852  }
853  break;
854 
855  case C_S_RUNNING:
856  if (oldstate == C_S_PREPARING) {
858  stop_menu_music(); // stop intro sound loop.
859  }
860 
863  create_event(nullptr, E_GAME_START, ftc_client, _("Game started."));
864  if (pplayer) {
865  research_update(research_get(pplayer));
866  }
868 
869  // reboot with player
872 
875  set_client_page(PAGE_GAME);
876  // Find something sensible to display instead of the intro gfx.
880 
882 
883  update_info_label(); // get initial population right
886 
889  }
891  break;
892 
893  case C_S_OVER:
894  if (C_S_RUNNING == oldstate) {
895  // Extra kludge for end-game handling of the CMA.
896  if (pplayer && pplayer->cities) {
897  city_list_iterate(pplayer->cities, pcity)
898  {
899  if (cma_is_city_under_agent(pcity, nullptr)) {
900  cma_release_city(pcity);
901  }
902  }
904  }
908  unit_focus_set(nullptr);
909  } else {
910  // From C_S_PREPARING.
913  if (pplayer) {
914  research_update(research_get(pplayer));
915  }
917 
918  // reboot
921 
923  unit_focus_set(nullptr);
924  set_client_page(PAGE_GAME);
926  }
928 
932 
933  break;
934  }
935 
936  menus_init();
939  if (can_client_change_view()) {
941  }
942 
943  // If turn was going to change, that is now aborted.
944  set_server_busy(false);
945 }
946 
950 enum client_states client_state() { return civclient_state; }
951 
956 {
957  fc_assert_msg(pconn != nullptr,
958  "Trying to remove a non existing connection");
959 
960  if (nullptr != pconn->playing) {
961  conn_list_remove(pconn->playing->connections, pconn);
962  }
963  conn_list_remove(game.all_connections, pconn);
964  conn_list_remove(game.est_connections, pconn);
965  fc_assert_ret(pconn != &client.conn);
966  delete pconn;
967 }
968 
974 {
975  fc_assert_msg(game.all_connections != nullptr, "Connection list missing");
976 
977  while (conn_list_size(game.all_connections) > 0) {
978  struct connection *pconn = conn_list_get(game.all_connections, 0);
979  client_remove_cli_conn(pconn);
980  }
981 }
982 
986 QUrl &client_url() { return url; }
987 
992 {
993  send_packet_player_attribute_block(&client.conn);
994 }
995 
1000 {
1002 }
1003 
1004 Q_GLOBAL_STATIC(QTimer, turndone_timer)
1005 
1006 /* The timer tells how long since server informed us about starting
1007  * turn-change activities. */
1008 Q_GLOBAL_STATIC(QElapsedTimer, between_turns)
1009 static bool waiting_turn_change = false;
1010 
1011 /* This value shows what value the timeout label is currently showing for
1012  * the seconds-to-turndone. */
1015 
1022 void set_miliseconds_to_turndone(int miliseconds)
1023 {
1024  if (current_turn_timeout() > 0) {
1025  turndone_timer->setSingleShot(true);
1026  turndone_timer->start(miliseconds);
1027 
1028  /* Maybe we should do an update_timeout_label here, but it doesn't
1029  * seem to be necessary. */
1030  seconds_shown_to_turndone = miliseconds / 1000;
1031  }
1032 }
1033 
1038 
1043 {
1044  seconds_shown_to_new_turn = ceil(game.tinfo.last_turn_change_time) + 0.1;
1045  between_turns->start();
1046 
1047  waiting_turn_change = true;
1048 }
1049 
1054 {
1055  waiting_turn_change = false;
1057 }
1058 
1064 {
1065  if (current_turn_timeout() > 0) {
1067  } else {
1068  // This shouldn't happen.
1069  return FC_INFINITY;
1070  }
1071 }
1072 
1078 
1085 {
1086  double time_until_next_call = 1.0;
1087 
1089 
1090  {
1091  double autoconnect_time = try_to_autoconnect(url);
1092  time_until_next_call = MIN(time_until_next_call, autoconnect_time);
1093  }
1094 
1095  if (C_S_RUNNING != client_state()) {
1096  return time_until_next_call;
1097  }
1098 
1099  {
1100  double blink_time = blink_turn_done_button();
1101  time_until_next_call = std::min(time_until_next_call, blink_time / 1000);
1102  }
1103 
1104  if (get_num_units_in_focus() > 0) {
1105  double blink_time = blink_active_unit();
1106  time_until_next_call = std::min(time_until_next_call, blink_time / 1000);
1107  }
1108 
1109  /* It is possible to have current_turn_timeout() > 0 but !turndone_timer,
1110  * in the first moments after the timeout is set. */
1111  if (current_turn_timeout() > 0 && turndone_timer) {
1112  if (turndone_timer->remainingTime() / 1000 < seconds_shown_to_turndone) {
1113  seconds_shown_to_turndone = turndone_timer->remainingTime() / 1000;
1115  }
1116 
1117  time_until_next_call = std::min(time_until_next_call, 1.0);
1118  }
1119  if (waiting_turn_change) {
1120  double seconds =
1121  game.tinfo.last_turn_change_time - between_turns->elapsed() / 1000;
1122  int iseconds = ceil(seconds) + 0.1; // Turn should end right on 0.
1123 
1124  if (iseconds < game.tinfo.last_turn_change_time) {
1125  seconds_shown_to_new_turn = iseconds;
1127  }
1128  }
1129 
1130  {
1131  static long counter = 0;
1132 
1133  counter++;
1134 
1135  if (gui_options->heartbeat_enabled && (counter % (20 * 10) == 0)) {
1136  send_packet_client_heartbeat(&client.conn);
1137  }
1138  }
1139 
1140  return std::max(time_until_next_call, 0.0);
1141 }
1142 
1147 {
1148  return (nullptr != client.conn.playing && !client_is_observer());
1149 }
1150 
1157 {
1158  return (can_client_control() && C_S_RUNNING == client_state());
1159 }
1160 
1165 bool can_meet_with_player(const struct player *pplayer)
1166 {
1167  return (can_client_issue_orders()
1168  // && nullptr != client.conn.playing (above)
1169  && could_meet_with_player(client.conn.playing, pplayer));
1170 }
1171 
1178 {
1179  return ((nullptr != client.conn.playing || client_is_observer())
1180  && (C_S_RUNNING == client_state() || C_S_OVER == client_state()));
1181 }
1182 
1187 void set_server_busy(bool busy)
1188 {
1189  if (busy != server_busy) {
1190  // server_busy value will change
1191  server_busy = busy;
1192 
1193  // This may mean that we have to change from or to wait cursor
1194  control_mouse_cursor(nullptr);
1195  }
1196 }
1197 
1201 bool is_server_busy() { return server_busy; }
1202 
1207 {
1208  return client.conn.playing == nullptr && client.conn.observer;
1209 }
1210 
1215 {
1216  if (client.conn.playing == nullptr) {
1217  return -1;
1218  }
1219  return player_number(client.conn.playing);
1220 }
1221 
1225 bool client_has_player() { return client.conn.playing != nullptr; }
1226 
1230 struct player *client_player() { return client.conn.playing; }
1231 
1236 bool client_map_is_known_and_seen(const struct tile *ptile,
1237  const struct player *pplayer,
1238  enum vision_layer vlayer)
1239 {
1240  return pplayer->client.tile_vision[vlayer]->at(tile_index(ptile));
1241 }
1242 
1246 static int client_plr_tile_city_id_get(const struct tile *ptile,
1247  const struct player *pplayer)
1248 {
1249  struct city *pcity = tile_city(ptile);
1250 
1251  // Can't look up what other players think.
1252  fc_assert(pplayer == client_player());
1253 
1254  return pcity ? pcity->id : IDENTITY_NUMBER_ZERO;
1255 }
1256 
1261 {
1263 
1264  if (pset) {
1265  return option_number(pset);
1266  } else {
1267  qCritical("No server setting named %s exists.", name);
1268  return SERVER_SETTING_NONE;
1269  }
1270 }
1271 
1276 {
1277  struct option *pset = optset_option_by_number(server_optset, id);
1278 
1279  if (pset) {
1280  return option_name(pset);
1281  } else {
1282  qCritical("No server setting with the id %d exists.", id);
1283  return nullptr;
1284  }
1285 }
1286 
1290 static enum sset_type client_ss_type_get(server_setting_id id)
1291 {
1292  enum option_type opt_type;
1293  struct option *pset = optset_option_by_number(server_optset, id);
1294 
1295  if (!pset) {
1296  qCritical("No server setting with the id %d exists.", id);
1297  return sset_type_invalid();
1298  }
1299 
1300  opt_type = option_type(pset);
1301 
1302  // The option type isn't client only.
1303  fc_assert_ret_val_msg((opt_type != OT_FONT && opt_type != OT_COLOR),
1304  sset_type_invalid(),
1305  "%s is a client option type but not a server "
1306  "setting type",
1307  option_type_name(option_type(pset)));
1308 
1309  // The option type is valid.
1310  fc_assert_ret_val(sset_type_is_valid((enum sset_type) opt_type),
1311  sset_type_invalid());
1312 
1313  /* Each server setting type value equals the client option type value with
1314  * the same meaning. */
1315  FC_STATIC_ASSERT((enum sset_type) OT_BOOLEAN == SST_BOOL
1316  && (enum sset_type) OT_INTEGER == SST_INT
1317  && (enum sset_type) OT_STRING == SST_STRING
1318  && (enum sset_type) OT_ENUM == SST_ENUM
1319  && (enum sset_type) OT_BITWISE == SST_BITWISE
1320  && SST_COUNT == (enum sset_type) 5,
1321  server_setting_type_not_equal_to_client_option_type);
1322 
1323  /* Exploit the fact that each server setting type value corresponds to the
1324  * client option type value with the same meaning. */
1325  return static_cast<enum sset_type>(opt_type);
1326 }
1327 
1332 {
1333  struct option *pset = optset_option_by_number(server_optset, id);
1334 
1335  if (pset) {
1336  return option_bool_get(pset);
1337  } else {
1338  qCritical("No server setting with the id %d exists.", id);
1339  return false;
1340  }
1341 }
1342 
1347 {
1348  struct option *pset = optset_option_by_number(server_optset, id);
1349 
1350  if (pset) {
1351  return option_int_get(pset);
1352  } else {
1353  qCritical("No server setting with the id %d exists.", id);
1354  return 0;
1355  }
1356 }
1357 
1362 {
1363  struct option *pset = optset_option_by_number(server_optset, id);
1364 
1365  if (pset) {
1366  return option_bitwise_get(pset);
1367  } else {
1368  qCritical("No server setting with the id %d exists.", id);
1369  return false;
1370  }
1371 }
1372 
1377 {
1378  struct functions *funcs = fc_interface_funcs();
1379 
1386  funcs->create_extra = nullptr;
1387  funcs->destroy_extra = nullptr;
1390 
1391  /* Keep this function call at the end. It checks if all required functions
1392  are defined. */
1394 }
1395 
1399 static enum known_type mapimg_client_tile_known(const struct tile *ptile,
1400  const struct player *pplayer,
1401  bool knowledge)
1402 {
1403  Q_UNUSED(knowledge)
1404  if (client_is_global_observer()) {
1405  return TILE_KNOWN_SEEN;
1406  }
1407 
1408  return tile_get_known(ptile, pplayer);
1409 }
1410 
1414 static struct terrain *
1415 mapimg_client_tile_terrain(const struct tile *ptile,
1416  const struct player *pplayer, bool knowledge)
1417 {
1418  Q_UNUSED(pplayer)
1419  Q_UNUSED(knowledge)
1420  return tile_terrain(ptile);
1421 }
1422 
1426 static struct player *mapimg_client_tile_owner(const struct tile *ptile,
1427  const struct player *pplayer,
1428  bool knowledge)
1429 {
1430  Q_UNUSED(pplayer)
1431  Q_UNUSED(knowledge)
1432  return tile_owner(ptile);
1433 }
1434 
1438 static struct player *mapimg_client_tile_city(const struct tile *ptile,
1439  const struct player *pplayer,
1440  bool knowledge)
1441 {
1442  Q_UNUSED(pplayer)
1443  Q_UNUSED(knowledge)
1444  struct city *pcity = tile_city(ptile);
1445 
1446  if (!pcity) {
1447  return nullptr;
1448  }
1449 
1450  return city_owner(tile_city(ptile));
1451 }
1452 
1456 static struct player *mapimg_client_tile_unit(const struct tile *ptile,
1457  const struct player *pplayer,
1458  bool knowledge)
1459 {
1460  Q_UNUSED(pplayer)
1461  Q_UNUSED(knowledge)
1462  int unit_count = unit_list_size(ptile->units);
1463 
1464  if (unit_count == 0) {
1465  return nullptr;
1466  }
1467 
1468  return unit_owner(unit_list_get(ptile->units, 0));
1469 }
1470 
1474 static int mapimg_client_plrcolor_count() { return player_count(); }
1475 
1481 {
1482  int count = 0;
1483 
1484  if (0 > i || i > player_count()) {
1485  return nullptr;
1486  }
1487 
1488  players_iterate(pplayer)
1489  {
1490  if (count == i) {
1491  return pplayer->rgb;
1492  }
1493  count++;
1494  }
1496 
1497  return nullptr;
1498 }
1499 
1504 
void init_ai(struct ai_type *ai)
Initializes AI structure.
Definition: ai.cpp:42
struct ai_type * get_ai_type(int id)
Returns ai_type of given id.
Definition: ai.cpp:32
void attribute_init()
Initializes the attribute module.
Definition: attribute.cpp:66
void attribute_flush()
Send current state to the server.
Definition: attribute.cpp:284
void attribute_free()
Frees the attribute module.
Definition: attribute.cpp:71
void audio_init()
Initialize base audio system.
Definition: audio.cpp:173
void audio_real_init(const QString &soundset_name, const QString &musicset_name, const QString &preferred_plugin_name)
Initialize audio system and autoselect a plugin.
Definition: audio.cpp:253
void audio_shutdown()
Call this at end of program only.
Definition: audio.cpp:599
void init_our_capability()
Setup our internal network capability string.
Definition: capstr.cpp:83
void fc_destroy_ow_mutex()
Destroy output window mutex.
void fc_init_ow_mutex()
Initialize output window mutex.
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
#define city_list_iterate(citylist, pcity)
Definition: city.h:482
#define city_list_iterate_end
Definition: city.h:484
void popdown_city_dialog()
Closes the city overlay.
Definition: citydlg.cpp:2264
static void drop()
Definition: governor.cpp:98
static governor * i()
Definition: governor.cpp:107
static update_queue * uq()
static void drop()
static void client_game_free()
Called by set_client_state() and client_exit() below.
static struct player * mapimg_client_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - city owner.
QString savefile
static enum client_states civclient_state
int get_seconds_to_new_turn()
Return the number of seconds until turn-done.
static server_setting_id client_ss_by_name(const char *name)
Returns the id of the server setting with the specified name.
enum client_states client_state()
Return current client state.
static struct player * mapimg_client_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - unit owner.
void start_turn_change_wait()
Start waiting of the server turn change activities.
QString logfile
void client_remove_cli_conn(struct connection *pconn)
Remove pconn from all connection lists in client, then free it.
QString cmd_metaserver
static bool waiting_turn_change
QUrl & client_url()
Returns the URL that this client connects to.
static int client_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Returns the id of the city the player believes exists at 'ptile'.
static struct rgbcolor * mapimg_client_plrcolor_get(int i)
Helper function for the mapimg module - one player color.
bool can_meet_with_player(const struct player *pplayer)
Returns TRUE iff the client can do diplomatic meetings with another given player.
void client_packet_input(void *packet, int type)
Handle packet received from server.
int client_player_number()
Returns number of player attached to client.
bool client_map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Return the vision of the player on a tile.
bool waiting_for_end_turn
static enum sset_type client_ss_type_get(server_setting_id id)
Returns the type of the server setting with the specified id.
bool is_server_busy()
Returns if server is considered busy at the moment.
static struct terrain * mapimg_client_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile terrain.
int client_main(int argc, char *argv[])
Entry point for common client code.
enum announce_type announce
QString sound_plugin_name
bool client_has_player()
Either controlling or observing.
void set_miliseconds_to_turndone(int miliseconds)
Reset the number of seconds to turndone from an "authentic" source.
static char * put_conv(const char *src, size_t *length)
Convert a text string from the internal to the data encoding, when it is written to the network.
void client_remove_all_cli_conn()
Remove (and free) all connections from all connection lists in client.
bool client_is_global_observer()
Returns whether client is global observer.
static enum known_type mapimg_client_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile knowledge.
double real_timer_callback()
This function should be called at least once per second.
void start_quitting()
Mark client as one going to quit as soon as possible,.
static bool client_quitting
void set_server_busy(bool busy)
Sets if server is considered busy.
static bool client_ss_val_bool_get(server_setting_id id)
Returns the value of the boolean server setting with the specified id.
struct player * client_player()
Either controlling or observing.
static bool get_conv(char *dst, size_t ndst, const char *src, size_t nsrc)
Convert a text string from the data to the internal encoding when it is first read from the network.
static int client_ss_val_int_get(server_setting_id id)
Returns the value of the integer server setting with the specified id.
static void at_exit()
This is called at program exit.
int get_seconds_to_turndone()
Return the number of seconds until turn-done.
struct civclient client
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
bool auto_connect
static unsigned int client_ss_val_bitwise_get(server_setting_id id)
Returns the value of the bitwise server setting with the specified id.
static int seconds_shown_to_new_turn
void user_ended_turn()
Handle user ending his/her turn.
bool client_is_observer()
Returns whether client is observer.
void send_attribute_block_request()
Send attribute block.
QString scriptfile
bool auto_spawn
QString music_set_name
static int seconds_shown_to_turndone
void send_report_request(enum report_type type)
Send request for some report to server.
bool is_client_quitting()
Is the client marked as one going down?
static void log_option_save_msg(QtMsgType lvl, const QString &msg)
Write messages from option saving to the log.
static void client_game_reset()
Called only by set_client_state() below.
static void charsets_init()
Set up charsets for the client.
void send_turn_done()
Send information about player having finished his/her turn to server.
bool can_client_control()
Returns TRUE iff the client can control player.
bool is_waiting_turn_change()
Are we in turn-change wait state?
static struct player * mapimg_client_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile owner.
bool can_client_change_view()
Return TRUE if the client can change the view; i.e.
QString forced_tileset_name
static void fc_interface_init_client()
Initialize client specific functions.
void stop_turn_change_wait()
Server is responsive again.
QString sound_set_name
void client_exit()
Main client execution stop function.
static void emergency_exit()
This is called at program exit in any emergency.
static const char * client_ss_name_get(server_setting_id id)
Returns the name of the server setting with the specified id.
static int mapimg_client_plrcolor_count()
Helper function for the mapimg module - number of player colors.
static bool server_busy
static void client_game_init()
Called only by set_client_state() below.
void set_client_state(enum client_states newstate)
Change client state.
client_states
Definition: client_main.h:39
@ C_S_PREPARING
Definition: client_main.h:42
@ C_S_DISCONNECTED
Definition: client_main.h:41
@ C_S_INITIAL
Definition: client_main.h:40
@ C_S_RUNNING
Definition: client_main.h:43
@ C_S_OVER
Definition: client_main.h:44
const char *const gui_character_encoding
Definition: gui_main.cpp:47
const bool gui_use_transliteration
Definition: gui_main.cpp:46
void create_event(struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Creates a struct packet_generic_message packet and injects it via handle_chat_msg.
Definition: climisc.cpp:952
struct nation_set * client_current_nation_set()
Returns the nation set in use.
Definition: climisc.cpp:1190
void center_on_something()
Find something sensible to display.
Definition: climisc.cpp:392
double try_to_autoconnect(const QUrl &url)
Make an attempt to autoconnect to the server.
Definition: clinet.cpp:339
void start_autoconnecting_to_server(const QUrl &url)
Start trying to autoconnect to freeciv21-server.
Definition: clinet.cpp:377
void disconnect_from_server()
Get rid of server connection.
Definition: clinet.cpp:219
bool client_start_server(const QString &user_name)
Forks a server if it can.
void client_kill_server(bool force)
Kills the server if the client has started it.
void conn_reset_delta_state(struct connection *pc)
Remove all is-game-info cached packets from the connection.
Definition: connection.cpp:615
std::vector< unit * > & get_units_in_focus()
Returns list of units currently in focus.
Definition: control.cpp:169
void unit_focus_update()
If there is no unit currently in focus, or if the current unit in focus should not be in focus,...
Definition: control.cpp:718
void control_init()
Called only by client_game_init() in client/client_main.c.
Definition: control.cpp:131
void unit_focus_set(struct unit *punit)
Sets the focus unit directly.
Definition: control.cpp:479
void control_free()
Called only by client_game_free() in client/client_main.c.
Definition: control.cpp:147
int get_num_units_in_focus()
Return the number of units currently in focus (0 or more).
Definition: control.cpp:174
int blink_turn_done_button()
Blink the turn done button (if necessary).
Definition: control.cpp:857
void control_mouse_cursor(struct tile *ptile)
Determines which mouse cursor should be used, according to hover_state, and the information gathered ...
Definition: control.cpp:1067
int blink_active_unit()
Blink the active unit (if necessary).
Definition: control.cpp:827
void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun)
Sets string conversion callback to use when getting text.
Definition: dataio_raw.cpp:104
void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun)
Sets string conversion callback to be used when putting text.
Definition: dataio_raw.cpp:76
void popdown_races_dialog(void)
Close the nation selection dialog.
Definition: dialogs.cpp:1011
void popdown_all_game_dialogs(void)
This function is called when the client disconnects or the game is over.
Definition: dialogs.cpp:3496
void close_all_diplomacy_dialogs()
Close all open diplomacy dialogs.
Definition: diplodlg.cpp:970
bool could_meet_with_player(const struct player *pplayer, const struct player *aplayer)
Returns TRUE iff pplayer could do diplomatic meetings with aplayer.
Definition: diptreaty.cpp:56
void editor_free()
Free the client's editor.
Definition: editor.cpp:247
void editor_init()
Initialize the client's editor state information to some suitable default values.
Definition: editor.cpp:184
void editor_clear()
Clear the editor data which is game dependent.
Definition: editor.cpp:236
void free_libfreeciv()
Free misc resources allocated for libfreeciv.
struct functions * fc_interface_funcs()
Return the function pointer.
void fc_interface_init()
Test and initialize the functions.
int server_setting_id
Definition: fc_types.h:893
#define MAX_LEN_NAME
Definition: fc_types.h:61
#define IDENTITY_NUMBER_ZERO
Definition: fc_types.h:76
void backtrace_init()
Take backtrace log callback to use.
Definition: fcbacktrace.cpp:48
void backtrace_deinit()
Remove backtrace log callback from use.
Definition: fcbacktrace.cpp:58
char * internal_to_data_string_malloc(const char *text)
Definition: fciconv.cpp:99
void fc_fprintf(FILE *stream, const char *format,...)
Do a fprintf from the internal charset into the local charset.
Definition: fciconv.cpp:132
void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Must be called during the initialization phase of server and client to initialize the character encod...
Definition: fciconv.cpp:39
const char * get_internal_encoding()
Return the internal encoding.
Definition: fciconv.cpp:90
char * data_to_internal_string_malloc(const char *text)
Definition: fciconv.cpp:92
const char * get_locale_dir()
Return directory containing locales.
Definition: fcintl.cpp:94
#define _(String)
Definition: fcintl.h:50
const struct ft_color ftc_client
void configure_fonts()
Tries to choose good fonts for Freeciv21.
Definition: fonts.cpp:160
void i_am_client()
Set program type to client.
Definition: game.cpp:67
void game_reset()
Do all changes to change view, and not full game_free()/game_init().
Definition: game.cpp:466
struct civ_game game
Definition: game.cpp:47
void game_init(bool keep_ruleset_value)
Initialise all game settings.
Definition: game.cpp:420
int current_turn_timeout()
Return timeout value for the current turn.
Definition: game.cpp:808
void game_free()
Frees all memory of the game.
Definition: game.cpp:450
void global_worklists_build()
Check if the global worklists are valid or not for the ruleset.
void global_worklists_unbuild()
Convert the universal pointers to strings to work out-ruleset.
bool cma_is_city_under_agent(const struct city *pcity, struct cm_parameter *parameter)
Check whether city is under governor control, and fill parameter if it is.
Definition: governor.cpp:632
void cma_release_city(struct city *pcity)
Release city from governor control.
Definition: governor.cpp:627
const char * client_string
Definition: gui_main.cpp:48
void editgui_tileset_changed()
Stub for editor function.
Definition: gui_main.cpp:245
void ui_exit()
Do any necessary UI-specific cleanup.
Definition: gui_main.cpp:116
void editgui_popdown_all()
Stub for editor function.
Definition: gui_main.cpp:260
void ui_main()
The main loop for the UI.
Definition: gui_main.cpp:69
void conn_list_dialog_update()
void free_help_texts()
Free all allocations associated with help_nodes.
Definition: helpdata.cpp:73
void boot_help_texts(const nation_set *nations_to_show, help_item *tileset_help)
pplayer may be nullptr.
Definition: helpdata.cpp:682
void popdown_help_dialog(void)
Close the help dialog.
Definition: helpdlg.cpp:75
const char * name
Definition: inputfile.cpp:118
bool log_init(const QString &level_str, const QStringList &extra_rules)
Parses a log level string as provided by the user on the command line, and installs the corresponding...
Definition: log.cpp:55
void fc_assert_set_fatal(bool fatal)
Set what signal the assert* macros should raise on failed assertion (-1 to disable).
Definition: log.cpp:226
void log_set_file(const QString &path)
Redirects the log to a file.
Definition: log.cpp:177
void log_close()
Deinitialize logging module.
Definition: log.cpp:212
#define fc_assert_msg(condition, message,...)
Definition: log.h:96
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
#define log_debug(message,...)
Definition: log.h:65
#define FC_STATIC_ASSERT(cond, tag)
Definition: log.h:158
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition: log.h:132
void update_turn_done_button_state()
Update the turn done button state.
bool can_end_turn()
Return TRUE iff client can end turn.
void mapimg_reset()
Reset the map image subsystem.
Definition: mapimg.cpp:386
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)
Initialisation of the map image subsystem.
Definition: mapimg.cpp:351
void mapimg_free()
Free all memory allocated by the map image subsystem.
Definition: mapimg.cpp:405
void update_info_label(void)
Typically an info box is provided to tell the player about the state of their civilization.
Definition: page_game.cpp:750
void update_unit_info_label(const std::vector< unit * > &unit_list)
Update the information label which gives info on the current unit and the tile under the current unit...
Definition: view_map.cpp:446
void menus_init()
void meswin_clear_older(int turn, int phase)
Clear all messages.
#define MESWIN_CLEAR_ALL
void update_timeout_label()
Update the timeout display.
void start_style_music()
Start music suitable for current game situation.
Definition: music.cpp:27
void start_menu_music(const QString &tag, const QString &alt_tag)
Start menu music.
Definition: music.cpp:78
void stop_menu_music()
Stop menu music completely.
Definition: music.cpp:88
void stop_style_music()
Stop style music completely.
Definition: music.cpp:73
announce_type
Definition: net_types.h:19
@ ANNOUNCE_IPV6
Definition: net_types.h:19
@ ANNOUNCE_IPV4
Definition: net_types.h:19
@ ANNOUNCE_NONE
Definition: net_types.h:19
#define ANNOUNCE_DEFAULT
Definition: net_types.h:21
void options_free()
Free the option module.
Definition: options.cpp:4677
void options_init()
Initialize the option module.
Definition: options.cpp:4582
const char * option_name(const struct option *poption)
Returns the name of the option.
Definition: options.cpp:300
const struct option_set * server_optset
Definition: options.cpp:2430
void options_dialogs_set()
This set the city and player report dialog options.
Definition: options.cpp:4332
client_options * gui_options
Definition: options.cpp:74
void options_dialogs_update()
This set the city and player report dialog options to the current ones.
Definition: options.cpp:4306
int option_number(const struct option *poption)
Returns the number of the option.
Definition: options.cpp:290
void server_options_free()
Free the server options, if already received.
Definition: options.cpp:2619
int option_int_get(const struct option *poption)
Returns the current value of this integer option.
Definition: options.cpp:494
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Returns the option corresponding of the name in this option set.
Definition: options.cpp:110
bool option_bool_get(const struct option *poption)
Returns the current value of this boolean option.
Definition: options.cpp:457
enum option_type option_type(const struct option *poption)
Returns the type of the option.
Definition: options.cpp:330
struct option * optset_option_by_number(const struct option_set *poptset, int id)
Returns the option corresponding of the number in this option set.
Definition: options.cpp:99
void fill_topo_ts_default()
Fill default tilesets for topology-specific settings.
Definition: options.cpp:4906
void options_save(option_save_log_callback log_cb)
Save all options.
Definition: options.cpp:4496
void options_load()
Load from the rc file any options that are not ruleset specific.
Definition: options.cpp:4362
unsigned option_bitwise_get(const struct option *poption)
Returns the current value of this bitwise option.
Definition: options.cpp:682
void server_options_init()
Initialize the server options (not received yet).
Definition: options.cpp:2566
#define DEFAULT_METASERVER_OPTION
Definition: options.h:20
void refresh_overview_canvas()
Redraw the entire backing store for the overview minimap.
void overview_free()
Free overview resources.
void packets_deinit()
Call when there is no longer a requirement for protocol processing.
Definition: packets.cpp:804
const char * packet_name(enum packet_type type)
report_type
Definition: packets.h:52
void packhand_free()
Called below, and by client/client_main.c client_game_free()
Definition: packhand.cpp:142
int len
Definition: packhand.cpp:127
void set_client_page(enum client_pages page)
enum client_pages get_client_page()
bool is_valid_username(const char *name)
Returns whether this is a valid username.
Definition: player.cpp:1793
int player_number(const struct player *pplayer)
Return the player index/number/id.
Definition: player.cpp:756
int player_count()
Return the number of players.
Definition: player.cpp:739
#define players_iterate_end
Definition: player.h:520
#define players_iterate(_pplayer)
Definition: player.h:514
void fc_srand(std::uint_fast32_t seed)
Initialize the generator; see comment at top of file.
Definition: rand.cpp:69
#define fc_rand(_size)
Definition: rand.h:16
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
Q_GLOBAL_STATIC(QVector< QString >, future_name_translation)
void research_update(struct research *presearch)
Mark as TECH_PREREQS_KNOWN each tech which is available, not known and which has all requirements ful...
Definition: research.cpp:486
bool script_client_init()
Initialize the scripting state.
void script_client_free()
Free the scripting data.
#define SERVER_SETTING_NONE
void dont_run_as_root(const char *argv0, const char *fallback)
If we have root privileges, die with an error.
Definition: shared.cpp:948
void free_nls()
Free memory allocated by Native Language Support.
Definition: shared.cpp:931
void init_nls()
Setup for Native Language Support, if configured to use it.
Definition: shared.cpp:871
char * user_username(char *buf, size_t bufsz)
Returns string which gives user's username, as specified by $USER or as given in password file for th...
Definition: shared.cpp:443
#define MIN(x, y)
Definition: shared.h:49
#define FC_INFINITY
Definition: shared.h:32
static civtimer * between_turns
Definition: srv_main.cpp:142
Definition: ai.h:42
Definition: city.h:291
int id
Definition: city.h:296
struct civ_game::@28::@31 client
struct conn_list * est_connections
Definition: game.h:88
struct packet_game_info info
Definition: game.h:80
struct conn_list * all_connections
Definition: game.h:87
struct packet_timeout_info tinfo
Definition: game.h:82
struct connection conn
Definition: client_main.h:89
int default_server_port
Definition: options.h:51
char default_sound_set_name[512]
Definition: options.h:59
bool use_prev_server
Definition: options.h:52
char default_metaserver[512]
Definition: options.h:54
bool auto_center_each_turn
Definition: options.h:88
char default_server_host[512]
Definition: options.h:50
bool heartbeat_enabled
Definition: options.h:53
bool save_options_on_exit
Definition: options.h:64
char default_music_set_name[512]
Definition: options.h:60
char default_sound_plugin_name[512]
Definition: options.h:61
char default_user_name[512]
Definition: options.h:49
bool established
Definition: connection.h:131
struct player * playing
Definition: connection.h:142
bool observer
Definition: connection.h:138
int(* player_tile_city_id_get)(const struct tile *ptile, const struct player *pplayer)
Definition: fc_interface.h:42
int(* server_setting_val_int_get)(server_setting_id id)
Definition: fc_interface.h:29
void(* create_extra)(struct tile *ptile, const extra_type *pextra, struct player *pplayer)
Definition: fc_interface.h:31
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
Definition: fc_interface.h:36
const char *(* server_setting_name_get)(server_setting_id id)
Definition: fc_interface.h:26
bool(* server_setting_val_bool_get)(server_setting_id id)
Definition: fc_interface.h:28
void(* destroy_extra)(struct tile *ptile, struct extra_type *pextra)
Definition: fc_interface.h:33
server_setting_id(* server_setting_by_name)(const char *name)
Definition: fc_interface.h:25
unsigned int(* server_setting_val_bitwise_get)(server_setting_id id)
Definition: fc_interface.h:30
enum sset_type(* server_setting_type_get)(server_setting_id id)
Definition: fc_interface.h:27
The base class for options.
Definition: options.cpp:209
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
struct player::@65::@68 client
struct conn_list * connections
Definition: player.h:280
struct rgbcolor * rgb
Definition: player.h:293
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
Definition: support.cpp:537
int fc_at_quick_exit(void(*func)())
Set quick_exit() callback if possible.
Definition: support.cpp:657
#define sz_strlcpy(dest, src)
Definition: support.h:140
void init_themes()
Initialized themes data.
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Return a known_type enumeration value for the tile.
Definition: tile.cpp:398
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
#define tile_index(_pt_)
Definition: tile.h:70
known_type
Definition: tile.h:28
@ TILE_KNOWN_SEEN
Definition: tile.h:31
#define tile_terrain(_tile)
Definition: tile.h:93
#define tile_owner(_tile)
Definition: tile.h:78
void tileset_free(struct tileset *t)
Clean up.
Definition: tilespec.cpp:840
help_item * tileset_help(const struct tileset *t)
Creates the help item for the given tileset.
Definition: tilespec.cpp:3859
bool tilespec_try_read(const QString &tileset_name, bool verbose, int topo_id)
Read a new tilespec in when first starting the game.
Definition: tilespec.cpp:860
#define unit_owner(_pu)
Definition: unit.h:370
void role_unit_precalcs()
Initialize; it is safe to call this multiple times (e.g., if units have changed due to rulesets in cl...
Definition: unittype.cpp:1838
const char * freeciv21_version()
Returns the raw version string.
Definition: version.cpp:29
const char * freeciv_name_version()
Return string containing both name of Freeciv21 and version.
Definition: version.cpp:34
void init_city_report_game_data()
Initialize city report data.
void link_marks_free()
Free the link marks.
void link_marks_init()
Initialize the link marks.
void update_map_canvas_visible()
Schedules an update of (only) the visible part of the map at the next unqueue_mapview_update().
void init_player_dlg_common()
Translate all titles.
void voteinfo_queue_init()
Initialize data structures used by this module.
Definition: voteinfo.cpp:163
void voteinfo_queue_free()
Free memory allocated by this module.
Definition: voteinfo.cpp:175
void voteinfo_queue_check_removed()
Check for old votes that should be removed from the queue.
Definition: voteinfo.cpp:65
void voteinfo_gui_update(void)
Refresh all vote related GUI widgets.