Freeciv-3.3
Loading...
Searching...
No Matches
stdinhand.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 <stdarg.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#ifdef FREECIV_HAVE_LIBREADLINE
26#include <readline/readline.h>
27#endif
28
29/* utility */
30#include "astring.h"
31#include "bitvector.h"
32#include "deprecations.h"
33#include "fc_cmdline.h"
34#include "fciconv.h"
35#include "fcintl.h"
36#include "log.h"
37#include "mem.h"
38#include "rand.h"
39#include "registry.h"
40#include "support.h" /* fc__attribute, bool type, etc. */
41#include "timing.h"
42#include "section_file.h"
43
44/* common */
45#include "capability.h"
46#include "events.h"
47#include "fc_types.h" /* LINE_BREAK */
48#include "featured_text.h"
49#include "game.h"
50#include "map.h"
51#include "mapimg.h"
52#include "modpack.h"
53#include "packets.h"
54#include "player.h"
55#include "research.h"
56#include "rgbcolor.h"
57#include "srvdefs.h"
58#include "unitlist.h"
59#include "version.h"
60
61/* server */
62#include "aiiface.h"
63#include "citytools.h"
64#include "connecthand.h"
65#include "diplhand.h"
66#include "gamehand.h"
67#include "mapgen.h"
68#include "maphand.h"
69#include "meta.h"
70#include "notify.h"
71#include "plrhand.h"
72#include "report.h"
73#include "ruleload.h"
74#include "sanitycheck.h"
75#include "score.h"
76#include "sernet.h"
77#include "settings.h"
78#include "srv_log.h"
79#include "srv_main.h"
80#include "techtools.h"
81#include "voting.h"
82
83/* server/savegame */
84#include "savemain.h"
85
86/* server/scripting */
87#include "script_server.h"
88#include "script_fcdb.h"
89
90/* ai */
91#include "difficulty.h"
92#include "handicaps.h"
93
94#include "stdinhand.h"
95
96#define OPTION_NAME_SPACE 25
97
100
101static time_t *time_duplicate(const time_t *t);
102
103/* 'struct kick_hash' and related functions. */
104#define SPECHASH_TAG kick
105#define SPECHASH_ASTR_KEY_TYPE
106#define SPECHASH_IDATA_TYPE time_t *
107#define SPECHASH_UDATA_TYPE time_t
108#define SPECHASH_IDATA_COPY time_duplicate
109#define SPECHASH_IDATA_FREE (kick_hash_data_free_fn_t) free
110#define SPECHASH_UDATA_TO_IDATA(t) (&(t))
111#define SPECHASH_IDATA_TO_UDATA(p) (NULL != p ? *p : 0)
112#include "spechash.h"
113
114const char *script_extension = ".serv";
115
118
119
120static bool cut_client_connection(struct connection *caller, char *name,
121 bool check);
122static bool show_help(struct connection *caller, char *arg);
123static bool show_list(struct connection *caller, char *arg);
124static void show_ais(struct connection *caller);
125static void show_colors(struct connection *caller);
126static bool set_ai_level_named(struct connection *caller, const char *name,
127 const char *level_name, bool check);
128static bool set_ai_level(struct connection *caller, const char *name,
129 enum ai_level level, bool check);
130static bool away_command(struct connection *caller, bool check);
131static bool show_command(struct connection *caller, char *str, bool check);
132static bool show_settings(struct connection *caller,
134 char *str, bool check);
135static void show_settings_one(struct connection *caller, enum command_id cmd,
136 struct setting *pset);
137static void show_ruleset_info(struct connection *caller, enum command_id cmd,
138 bool check, int read_recursion);
139static void show_mapimg(struct connection *caller, enum command_id cmd);
140static bool set_command(struct connection *caller, char *str, bool check);
141static bool lock_command(struct connection *caller, char *str, bool check);
142static bool unlock_command(struct connection *caller, char *str, bool check);
143
144static bool create_command(struct connection *caller, const char *str,
145 bool check);
146static bool end_command(struct connection *caller, char *str, bool check);
147static bool surrender_command(struct connection *caller, char *str, bool check);
148static bool handle_stdin_input_real(struct connection *caller, char *str,
149 bool check, int read_recursion);
150static bool read_init_script_real(struct connection *caller,
151 const char *script_filename, bool from_cmdline,
152 bool check, int read_recursion);
153static bool reset_command(struct connection *caller, char *arg, bool check,
154 int read_recursion);
155static bool default_command(struct connection *caller, char *arg, bool check);
156static bool lua_command(struct connection *caller, char *arg, bool check,
157 int read_recursion);
158static bool kick_command(struct connection *caller, char *name, bool check);
159static bool delegate_command(struct connection *caller, char *arg,
160 bool check);
161static const char *delegate_player_str(struct player *pplayer, bool observer);
162static bool aicmd_command(struct connection *caller, char *arg, bool check);
163static bool fcdb_command(struct connection *caller, char *arg, bool check);
164static const char *fcdb_accessor(int i);
165static char setting_status(struct connection *caller,
166 const struct setting *pset);
167static bool player_name_check(const char *name, char *buf, size_t buflen);
168static bool playercolor_command(struct connection *caller,
169 char *str, bool check);
170static bool playernation_command(struct connection *caller,
171 char *str, bool check);
172static bool mapimg_command(struct connection *caller, char *arg, bool check);
173static const char *mapimg_accessor(int i);
174
175static void show_delegations(struct connection *caller);
176
177static const char horiz_line[] =
178"------------------------------------------------------------------------------";
179
180/**********************************************************************/
184static bool is_restricted(struct connection *caller)
185{
186 return (caller && caller->access_level != ALLOW_HACK);
187}
188
189/**********************************************************************/
193static bool player_name_check(const char *name, char *buf, size_t buflen)
194{
195 size_t len = strlen(name);
196
197 if (len == 0) {
198 fc_snprintf(buf, buflen, _("Can't use an empty name."));
199 return FALSE;
200 } else if (len > MAX_LEN_NAME-1) {
201 fc_snprintf(buf, buflen, _("That name exceeds the maximum of %d chars."),
202 MAX_LEN_NAME-1);
203 return FALSE;
204 } else if (fc_strcasecmp(name, ANON_PLAYER_NAME) == 0
205 || fc_strcasecmp(name, "Observer") == 0) {
206 fc_snprintf(buf, buflen, _("That name is not allowed."));
207 /* "Observer" used to be illegal and we keep it that way for now. */
208 /* FIXME: This disallows anonymous player name as it appears in English,
209 * but not one in any other language that the user may see. */
210 return FALSE;
211 }
212
213 return TRUE;
214}
215
216/**********************************************************************/
223static enum command_id command_named(const char *token, bool accept_ambiguity)
224{
225 enum m_pre_result result;
226 int ind;
227
229 fc_strncasecmp, NULL, token, &ind);
230
231 if (result < M_PRE_AMBIGUOUS) {
232 return ind;
233 } else if (result == M_PRE_AMBIGUOUS) {
235 } else {
236 return CMD_UNRECOGNIZED;
237 }
238}
239
240/**********************************************************************/
251
252/**********************************************************************/
257{
258 /* Nothing at the moment. */
259}
260
261/**********************************************************************/
278
279/**********************************************************************/
283static bool may_use(struct connection *caller, enum command_id cmd)
284{
285 if (!caller) {
286 return TRUE; /* on the console, everything is allowed */
287 }
288 return (caller->access_level >= command_level(command_by_number(cmd)));
289}
290
291/**********************************************************************/
295static bool may_use_nothing(struct connection *caller)
296{
297 if (!caller) {
298 return FALSE; /* on the console, everything is allowed */
299 }
300 return (ALLOW_NONE == conn_get_access(caller));
301}
302
303/**********************************************************************/
307static char setting_status(struct connection *caller,
308 const struct setting *pset)
309{
310 /* First check for a ruleset lock as this is included in
311 * setting_is_changeable() */
312 if (setting_locked(pset)) {
313 /* Setting is locked */
314 return '!';
315 }
316
317 if (setting_is_changeable(pset, caller, NULL, 0)) {
318 /* setting can be changed */
319 return '+';
320 }
321
322 /* setting is fixed */
323 return ' ';
324}
325
326/**********************************************************************/
333static void cmd_reply_line(enum command_id cmd, struct connection *caller,
334 enum rfc_status rfc_status, const char *prefix,
335 const char *line)
336{
337 const char *cmdname = cmd < CMD_NUM
339 : cmd == CMD_AMBIGUOUS
340 /* TRANS: ambiguous command */
341 ? _("(ambiguous)")
342 : cmd == CMD_UNRECOGNIZED
343 /* TRANS: unrecognized command */
344 ? _("(unknown)")
345 : "(?!?)"; /* this case is a bug! */
346
347 if (caller) {
349 "/%s: %s%s", cmdname, prefix, line);
350 /* cc: to the console - testing has proved it's too verbose - rp
351 con_write(rfc_status, "%s/%s: %s%s", caller->name, cmdname, prefix, line);
352 */
353 } else {
354 con_write(rfc_status, "%s%s", prefix, line);
355 }
356
357 if (rfc_status == C_OK) {
358 struct packet_chat_msg packet;
359
360 package_event(&packet, NULL, E_SETTING, ftc_server, "%s", line);
362 /* Do not tell caller, since they were told above! */
363 if (caller != pconn) {
364 send_packet_chat_msg(pconn, &packet);
365 }
368
369 if (NULL != caller) {
370 /* Echo to the console. */
371 log_normal("%s", line);
372 }
373 }
374}
375
376/**********************************************************************/
380static void vcmd_reply_prefix(enum command_id cmd, struct connection *caller,
381 enum rfc_status rfc_status, const char *prefix,
382 const char *format, va_list ap)
383{
384 char buf[4096];
385 char *c0, *c1;
386
387 fc_vsnprintf(buf, sizeof(buf), format, ap);
388
389 c0 = buf;
390 while ((c1 = strstr(c0, "\n"))) {
391 *c1 = '\0';
392 cmd_reply_line(cmd, caller, rfc_status, (c0 == buf ? "" : prefix), c0);
393 c0 = c1 + 1;
394 }
395
396 cmd_reply_line(cmd, caller, rfc_status, (c0 == buf ? "" : prefix), c0);
397}
398
399/**********************************************************************/
403static void cmd_reply_prefix(enum command_id cmd, struct connection *caller,
404 enum rfc_status rfc_status, const char *prefix,
405 const char *format, ...)
408 enum rfc_status rfc_status, const char *prefix,
409 const char *format, ...)
410{
411 va_list ap;
412 va_start(ap, format);
413 vcmd_reply_prefix(cmd, caller, rfc_status, prefix, format, ap);
414 va_end(ap);
415}
416
417/**********************************************************************/
420void cmd_reply(enum command_id cmd, struct connection *caller,
421 enum rfc_status rfc_status, const char *format, ...)
422{
423 va_list ap;
424 va_start(ap, format);
425 vcmd_reply_prefix(cmd, caller, rfc_status, "", format, ap);
426 va_end(ap);
427}
428
429/**********************************************************************/
434 struct connection *caller,
435 const char *name,
437{
438 switch (match_result) {
439 case M_PRE_EMPTY:
440 cmd_reply(cmd, caller, C_SYNTAX,
441 _("Name is empty, so cannot be a player."));
442 break;
443 case M_PRE_LONG:
444 cmd_reply(cmd, caller, C_SYNTAX,
445 _("Name is too long, so cannot be a player."));
446 break;
447 case M_PRE_AMBIGUOUS:
448 cmd_reply(cmd, caller, C_FAIL,
449 _("Player name prefix '%s' is ambiguous."), name);
450 break;
451 case M_PRE_FAIL:
452 cmd_reply(cmd, caller, C_FAIL,
453 _("No player by the name of '%s'."), name);
454 break;
455 default:
456 cmd_reply(cmd, caller, C_FAIL,
457 _("Unexpected match_result %d (%s) for '%s'."),
459 log_error("Unexpected match_result %d (%s) for '%s'.",
461 }
462}
463
464/**********************************************************************/
469 struct connection *caller,
470 const char *name,
472{
473 switch (match_result) {
474 case M_PRE_EMPTY:
475 cmd_reply(cmd, caller, C_SYNTAX,
476 _("Name is empty, so cannot be a connection."));
477 break;
478 case M_PRE_LONG:
479 cmd_reply(cmd, caller, C_SYNTAX,
480 _("Name is too long, so cannot be a connection."));
481 break;
482 case M_PRE_AMBIGUOUS:
483 cmd_reply(cmd, caller, C_FAIL,
484 _("Connection name prefix '%s' is ambiguous."), name);
485 break;
486 case M_PRE_FAIL:
487 cmd_reply(cmd, caller, C_FAIL,
488 _("No connection by the name of '%s'."), name);
489 break;
490 default:
491 cmd_reply(cmd, caller, C_FAIL,
492 _("Unexpected match_result %d (%s) for '%s'."),
494 log_error("Unexpected match_result %d (%s) for '%s'.",
496 }
497}
498
499/**********************************************************************/
502static void open_metaserver_connection(struct connection *caller,
503 bool persistent)
504{
507 cmd_reply(CMD_METACONN, caller, C_OK,
508 _("Open metaserver connection to [%s]."),
510 }
511}
512
513/**********************************************************************/
516static void close_metaserver_connection(struct connection *caller)
517{
520 cmd_reply(CMD_METACONN, caller, C_OK,
521 _("Close metaserver connection to [%s]."),
523 }
524}
525
526/**********************************************************************/
529static bool metaconnection_command(struct connection *caller, char *arg,
530 bool check)
531{
532 bool persistent = FALSE;
533
534 if ((*arg == '\0')
535 || (!strcmp(arg, "?"))) {
536 if (is_metaserver_open()) {
538 _("Metaserver connection is open."));
539 } else {
541 _("Metaserver connection is closed."));
542 }
543 return TRUE;
544 }
545
546 if (!fc_strcasecmp(arg, "p")
547 || !fc_strcasecmp(arg, "persistent")) {
549 }
550
551 if (persistent
552 || !fc_strcasecmp(arg, "u")
553 || !fc_strcasecmp(arg, "up")) {
554 if (!is_metaserver_open()) {
555 if (!check) {
557 }
558 } else {
560 _("Metaserver connection is already open."));
561 return FALSE;
562 }
563 } else if (!fc_strcasecmp(arg, "d")
564 || !fc_strcasecmp(arg, "down")) {
565 if (is_metaserver_open()) {
566 if (!check) {
568 }
569 } else {
571 _("Metaserver connection is already closed."));
572 return FALSE;
573 }
574 } else {
576 _("Argument must be 'u', 'up', 'd', 'down', 'p', 'persistent', or '?'."));
577 return FALSE;
578 }
579 return TRUE;
580}
581
582/**********************************************************************/
585static bool metapatches_command(struct connection *caller,
586 char *arg, bool check)
587{
588 if (check) {
589 return TRUE;
590 }
591
593
594 if (is_metaserver_open()) {
597 _("Metaserver patches string set to '%s'."), arg);
598 } else {
600 _("Metaserver patches string set to '%s', "
601 "not reporting to metaserver."), arg);
602 }
603
604 return TRUE;
605}
606
607/**********************************************************************/
610static bool metamessage_command(struct connection *caller,
611 char *arg, bool check)
612{
613 struct setting *pset;
614
615 log_deprecation(_("/metamessage command is deprecated. "
616 "Set metamessage setting instead."));
617
618 if (check) {
619 return TRUE;
620 }
621
623 if (is_metaserver_open()) {
626 _("Metaserver message string set to '%s'."), arg);
627 } else {
629 _("Metaserver message string set to '%s', "
630 "not reporting to metaserver."), arg);
631 }
632
633 /* Metamessage is also a setting. */
634 pset = setting_by_name("metamessage");
637
638 return TRUE;
639}
640
641/**********************************************************************/
644static bool metaserver_command(struct connection *caller, char *arg,
645 bool check)
646{
647 if (check) {
648 return TRUE;
649 }
651
653
655 _("Metaserver is now [%s]."), meta_addr_port());
656 return TRUE;
657}
658
659/**********************************************************************/
662static bool show_serverid(struct connection *caller, char *arg)
663{
664 cmd_reply(CMD_SRVID, caller, C_COMMENT, _("Server id: %s"), srvarg.serverid);
665
666 return TRUE;
667}
668
669/**********************************************************************/
673static bool save_command(struct connection *caller, char *arg, bool check)
674{
675 if (is_restricted(caller)) {
676 cmd_reply(CMD_SAVE, caller, C_FAIL,
677 _("You cannot save games manually on this server."));
678 return FALSE;
679 }
680 if (!check) {
681 save_game(arg, "User request", FALSE);
682 }
683 return TRUE;
684}
685
686/**********************************************************************/
690static bool scensave_command(struct connection *caller, char *arg, bool check)
691{
692 if (is_restricted(caller)) {
693 cmd_reply(CMD_SAVE, caller, C_FAIL,
694 _("You cannot save games manually on this server."));
695 return FALSE;
696 }
697 if (!check) {
698 save_game(arg, "Scenario", TRUE);
699 }
700 return TRUE;
701}
702
703/**********************************************************************/
706void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
707{
708 fc_assert_ret(pplayer != NULL);
709
710 if (is_human(pplayer)) {
711 cmd_reply(CMD_AITOGGLE, caller, C_OK,
712 _("%s is now under AI control."),
713 player_name(pplayer));
714 player_set_to_ai_mode(pplayer,
717 : pplayer->ai_common.skill_level);
718 fc_assert(is_ai(pplayer));
719 } else {
720 cmd_reply(CMD_AITOGGLE, caller, C_OK,
721 _("%s is now under human control."),
722 player_name(pplayer));
724 fc_assert(is_human(pplayer));
725 }
726}
727
728/**********************************************************************/
731static bool toggle_ai_command(struct connection *caller, char *arg, bool check)
732{
734 struct player *pplayer;
735
736 pplayer = player_by_name_prefix(arg, &match_result);
737
738 if (!pplayer) {
740 return FALSE;
741 } else if (!check) {
742 toggle_ai_player_direct(caller, pplayer);
744 }
745 return TRUE;
746}
747
748/**********************************************************************/
754static bool create_command(struct connection *caller, const char *str,
755 bool check)
756{
757 enum rfc_status status;
759
760 /* 2 legal arguments, and extra space for stuffing illegal part */
761 char *arg[3];
762 int ntokens;
763 const char *ai_type_name;
764
767
768 if (ntokens == 1) {
770 } else if (ntokens == 2) {
771 ai_type_name = arg[1];
772 } else {
774 _("Wrong number of arguments to create command."));
775 free_tokens(arg, ntokens);
776 return FALSE;
777 }
778
779 if (game_was_started()) {
781 NULL, NULL, buf, sizeof(buf));
782 } else {
784 NULL, buf, sizeof(buf));
785 }
786
787 free_tokens(arg, ntokens);
788
789 if (status != C_OK) {
790 /* No player created. */
791 cmd_reply(CMD_CREATE, caller, status, "%s", buf);
792 return FALSE;
793 }
794
795 if (strlen(buf) > 0) {
796 /* Send a notification. */
797 cmd_reply(CMD_CREATE, caller, C_OK, "%s", buf);
798 }
799
800 return TRUE;
801}
802
803/**********************************************************************/
813 const char *ai,
814 bool check,
815 struct nation_type *pnation,
816 struct player **newplayer,
817 char *buf, size_t buflen)
818{
819 struct player *pplayer = NULL;
820 struct research *presearch;
821 bool new_slot = FALSE;
822
823 /* Check player name. */
825 return C_SYNTAX;
826 }
827
828 /* Check first if we can replace a player with
829 * [1a] - the same username. */
830 pplayer = player_by_user(name);
831 if (pplayer && pplayer->is_alive) {
833 _("A living user already exists by that name."));
834 return C_BOUNCE;
835 }
836
837 /* [1b] - the same player name. */
838 pplayer = player_by_name(name);
839 if (pplayer && pplayer->is_alive) {
841 _("A living player already exists by that name."));
842 return C_BOUNCE;
843 }
844
845 if (pnation) {
846 if (!nation_is_in_current_set(pnation)) {
848 _("Can't create player, requested nation %s not in "
849 "current nation set."),
851 return C_FAIL;
852 }
854 if (0 > nations_match(pnation, nation_of_player(aplayer), FALSE)) {
856 _("Can't create players, nation %s conflicts with %s."),
858 nation_plural_for_player(pplayer));
859 return C_FAIL;
860 }
862 } else {
863 /* Try to find a nation. */
865 if (pnation == NO_NATION_SELECTED) {
867 _("Can't create players, no nations available."));
868 return C_FAIL;
869 }
870 }
871
872 if (pplayer == NULL) {
873 if (player_count() == player_slot_count()) {
874 bool dead_found = FALSE;
875
877 if (!aplayer->is_alive) {
879 break;
880 }
882
883 if (!dead_found) {
885 _("Can't create players, no slots available."));
886 return C_FAIL;
887 }
888 } else if (normal_player_count() == game.server.max_players) {
890 _("Maxplayers setting prevents creation of more players."));
891 return C_FAIL;
892 }
893 }
894
895 if (check) {
896 /* All code below will change the game state. */
897
898 /* Return an empty string. */
899 buf[0] = '\0';
900
901 return C_OK;
902 }
903
904 if (pplayer) {
905 /* [1] Replace a player. 'pplayer' was set above. */
907 _("%s is replacing dead player %s as an AI-controlled "
908 "player."), name, player_name(pplayer));
909 /* remove player and thus free a player slot */
910 server_remove_player(pplayer);
911 pplayer = NULL;
912 } else if (player_count() == player_slot_count()) {
913 /* [2] All player slots are used; try to remove a dead player. */
914 bool dead_found = FALSE;
915
917 if (!aplayer->is_alive) {
918 if (!dead_found) {
919 /* Fill the buffer with the name of the first found dead player */
921 _("%s is replacing dead player %s as an AI-controlled "
922 "player."), name, player_name(aplayer));
924 }
925
926 /* Remove player and thus free a player slot */
928 }
929
932 } else {
933 /* [3] An empty player slot must be used for the new player. */
934 new_slot = TRUE;
935 }
936
937 /* Create the new player. */
938 pplayer = server_create_player(-1, ai, NULL, FALSE);
939 if (!pplayer) {
940 fc_snprintf(buf, buflen, _("Failed to create new player %s."), name);
941 return C_FAIL;
942 }
943
944 if (new_slot) {
945 /* 'buf' must be set if a new player slot is used. */
946 fc_snprintf(buf, buflen, _("New player %s created."), name);
947 }
948
949 /* We have a player; now initialise all needed data. */
951
952 /* Initialise player. */
953 server_player_init(pplayer, TRUE, TRUE);
954
955 player_nation_defaults(pplayer, pnation, FALSE);
956 pplayer->government = pplayer->target_government =
958 /* Find a color for the new player. */
960
961 /* TRANS: keep one space at the beginning of the string. */
962 cat_snprintf(buf, buflen, _(" Nation of the new player: %s."),
963 nation_rule_name(pnation));
964
965 presearch = research_get(pplayer);
968
971 pplayer->unassigned_user = TRUE;
972
973 pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
974 set_as_ai(pplayer);
976
977 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
978
979 send_player_info_c(pplayer, NULL);
980 /* Send updated diplstate information to all players. */
982 /* Send research info after player info, else the client will complain
983 * about invalid team. */
986
987 if (newplayer != NULL) {
988 *newplayer = pplayer;
989 }
990 return C_OK;
991}
992
993/**********************************************************************/
997 const char *ai,
998 bool check,
999 struct player **newplayer,
1000 char *buf, size_t buflen)
1001{
1002 char leader_name[MAX_LEN_NAME]; /* Must be in whole function scope */
1003 struct player *pplayer = NULL;
1004 bool rand_name = FALSE;
1005
1006 if (name[0] == '\0') {
1007 int filled = 1;
1008
1009 do {
1010 fc_snprintf(leader_name, sizeof(leader_name), "%s*%d", ai, filled++);
1011 } while (player_by_name(leader_name));
1012
1013 name = leader_name;
1014 rand_name = TRUE;
1015 }
1016
1017 if (!player_name_check(name, buf, buflen)) {
1018 return C_SYNTAX;
1019 }
1020
1021 if (NULL != player_by_name(name)) {
1023 _("A player already exists by that name."));
1024 return C_BOUNCE;
1025 }
1026 if (NULL != player_by_user(name)) {
1028 _("A user already exists by that name."));
1029 return C_BOUNCE;
1030 }
1031
1032 /* Search for first uncontrolled player */
1033 pplayer = find_uncontrolled_player();
1034
1035 if (NULL == pplayer) {
1036 /* Check that we are not going over max players setting */
1039 _("Can't add more players, server is full."));
1040 return C_FAIL;
1041 }
1042 /* Check that we have nations available */
1043 if (normal_player_count() >= server.playable_nations) {
1044 if (nation_set_count() > 1) {
1046 _("Can't add more players, not enough playable nations "
1047 "in current nation set (see 'nationset' setting)."));
1048 } else {
1050 _("Can't add more players, not enough playable nations."));
1051 }
1052 return C_FAIL;
1053 }
1054 }
1055
1056 if (pplayer) {
1057 struct ai_type *ait = ai_type_by_name(ai);
1058
1059 if (ait == NULL) {
1061 _("There is no AI type %s."), ai);
1062 return C_FAIL;
1063 }
1064 }
1065
1066 if (check) {
1067 /* All code below will change the game state. */
1068
1069 /* Return an empty string. */
1070 buf[0] = '\0';
1071
1072 return C_OK;
1073 }
1074
1075 if (pplayer) {
1077 /* TRANS: <name> replacing <name> ... */
1078 _("%s replacing %s as an AI-controlled player."),
1079 name, player_name(pplayer));
1080
1081 team_remove_player(pplayer);
1082 pplayer->ai = ai_type_by_name(ai);
1083 } else {
1084 /* add new player */
1085 pplayer = server_create_player(-1, ai, NULL, FALSE);
1086 /* pregame so no need to assign_player_colors() */
1087 if (!pplayer) {
1089 _("Failed to create new player %s."), name);
1090 return C_GENFAIL;
1091 }
1092
1094 _("%s has been added as an AI-controlled player (%s)."),
1095 name, ai_name(pplayer->ai));
1096 }
1097 server_player_init(pplayer, FALSE, TRUE);
1098
1099 server_player_set_name(pplayer, name);
1100 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
1101 pplayer->unassigned_user = TRUE;
1102
1103 pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
1104 pplayer->random_name = rand_name;
1105 set_as_ai(pplayer);
1107 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
1109
1113
1114 if (newplayer != NULL) {
1115 *newplayer = pplayer;
1116 }
1117 return C_OK;
1118}
1119
1120/**********************************************************************/
1123static bool remove_player_command(struct connection *caller, char *arg,
1124 bool check)
1125{
1127 struct player *pplayer;
1128 char name[MAX_LEN_NAME];
1129
1130 pplayer = player_by_name_prefix(arg, &match_result);
1131
1132 if (NULL == pplayer) {
1134 return FALSE;
1135 }
1136
1137 if (game_was_started() && caller && caller->access_level < ALLOW_ADMIN) {
1138 cmd_reply(CMD_REMOVE, caller, C_FAIL,
1139 _("Command level '%s' or greater needed to remove a player "
1140 "once the game has started."), cmdlevel_name(ALLOW_ADMIN));
1141 return FALSE;
1142 }
1143 if (check) {
1144 return TRUE;
1145 }
1146
1147 sz_strlcpy(name, player_name(pplayer));
1148 server_remove_player(pplayer);
1149 if (!caller || caller->used) { /* may have removed self */
1150 cmd_reply(CMD_REMOVE, caller, C_OK,
1151 _("Removed player %s from the game."), name);
1152 }
1154 return TRUE;
1155}
1156
1157/**********************************************************************/
1160static bool read_command(struct connection *caller, char *arg, bool check,
1161 int read_recursion)
1162{
1163 return read_init_script_real(caller, arg, FALSE, check, read_recursion);
1164}
1165
1166/**********************************************************************/
1169bool read_init_script(struct connection *caller, const char *script_filename,
1170 bool from_cmdline, bool check)
1171{
1172 return read_init_script_real(caller, script_filename, from_cmdline,
1173 check, 0);
1174}
1175
1176/**********************************************************************/
1187static bool read_init_script_real(struct connection *caller,
1188 const char *script_filename, bool from_cmdline,
1189 bool check, int read_recursion)
1190{
1192 char serv_filename[strlen(script_extension) + strlen(script_filename) + 2];
1193 char tilde_filename[4096];
1194 const char *real_filename;
1195 size_t fnlen;
1196
1197 /* check recursion depth */
1199 log_error("Error: recursive calls to read!");
1200 return FALSE;
1201 }
1202
1203 /* abuse real_filename to find if we already have a .serv extension */
1204 fnlen = strlen(script_filename);
1205 real_filename = script_filename + fnlen
1208 fc_snprintf(serv_filename, sizeof(serv_filename), "%s%s",
1209 script_filename, script_extension);
1210 } else {
1211 sz_strlcpy(serv_filename, script_filename);
1212 }
1213
1214 if (is_restricted(caller) && !from_cmdline) {
1217 _("Name \"%s\" disallowed for security reasons."),
1219 return FALSE;
1220 }
1222 } else {
1224 }
1225
1227 if (!real_filename) {
1228 if (is_restricted(caller) && !from_cmdline) {
1230 _("No command script found by the name \"%s\"."),
1232 return FALSE;
1233 }
1234 /* File is outside data directories */
1236 }
1237
1238 log_testmatic_alt(LOG_NORMAL, _("Loading script file '%s'."), real_filename);
1239
1241 && (script_file = fc_fopen(real_filename, "r"))) {
1242 char buffer[MAX_LEN_CONSOLE_LINE];
1243
1244 /* The size is set as to not overflow buffer in handle_stdin_input */
1245 while (fgets(buffer, MAX_LEN_CONSOLE_LINE - 1, script_file)) {
1246 /* Execute script contents with same permissions as caller */
1247 handle_stdin_input_real(caller, buffer, check, read_recursion + 1);
1248 }
1250
1252
1253 return TRUE;
1254 } else {
1256 _("Cannot read command line scriptfile '%s'."), real_filename);
1257 if (NULL != caller) {
1258 log_error(_("Could not read script file '%s'."), real_filename);
1259 }
1260 return FALSE;
1261 }
1262}
1263
1264/**********************************************************************/
1274
1275/**********************************************************************/
1280static bool write_init_script(char *script_filename)
1281{
1282 char real_filename[1024], buf[256];
1284
1285 interpret_tilde(real_filename, sizeof(real_filename), script_filename);
1286
1288 && (script_file = fc_fopen(real_filename, "w"))) {
1290 "#FREECIV SERVER COMMAND FILE, version %s\n", VERSION_STRING);
1291 fputs("# These are server options saved from a running freeciv-server.\n",
1292 script_file);
1293
1294 /* First rulesetdir. Setting rulesetdir resets the settings to their
1295 * default value, so they would be lost if placed before this. */
1296 fprintf(script_file, "rulesetdir %s\n", game.server.rulesetdir);
1297
1298 /* Some state info from commands (we can't save everything) */
1299
1300 fprintf(script_file, "cmdlevel %s new\n",
1302
1303 fprintf(script_file, "cmdlevel %s first\n",
1305
1306 fprintf(script_file, "%s\n",
1308
1309 if (*srvarg.metaserver_addr != '\0'
1311 fprintf(script_file, "metaserver %s\n", meta_addr_port());
1312 }
1313
1315 fprintf(script_file, "metapatches %s\n", get_meta_patches_string());
1316 }
1317
1318 /* Then, the 'set' option settings */
1319
1321 fprintf(script_file, "set %s \"%s\"\n", setting_name(pset),
1322 setting_value_name(pset, FALSE, buf, sizeof(buf)));
1324
1326
1327 return TRUE;
1328 } else {
1329 log_error(_("Could not write script file '%s'."), real_filename);
1330
1331 return FALSE;
1332 }
1333}
1334
1335/**********************************************************************/
1338static bool write_command(struct connection *caller, char *arg, bool check)
1339{
1340 if (is_restricted(caller)) {
1342 _("You cannot use the write command on this server"
1343 " for security reasons."));
1344 return FALSE;
1345 } else if (!check) {
1346 char serv_filename[strlen(script_extension) + strlen(arg) + 2];
1347 const char *real_filename;
1348 size_t arglen = strlen(arg);
1349
1350 /* abuse real_filename to find if we already have a .serv extension */
1353 fc_snprintf(serv_filename, sizeof(serv_filename), "%s%s",
1354 arg, script_extension);
1355 } else {
1357 }
1358
1361 /* TRANS: Failed to write server script, e.g., 'example.serv' */
1362 _("Failed to write %s."), serv_filename);
1363 return FALSE;
1364 }
1365
1367 /* TRANS: Wrote server script, e.g., 'example.serv' */
1368 _("Wrote %s."), serv_filename);
1369 }
1370
1371 return TRUE;
1372}
1373
1374/**********************************************************************/
1377static bool set_cmdlevel(struct connection *caller,
1378 struct connection *ptarget,
1379 enum cmdlevel level)
1380{
1381 /* Only ever call me for specific connection. */
1383
1384 if (caller && ptarget->access_level > caller->access_level) {
1385 /*
1386 * This command is intended to be used at ctrl access level
1387 * and thus this if clause is needed.
1388 * (Imagine a ctrl level access player that wants to change
1389 * access level of a hack level access player)
1390 * At the moment it can be used only by hack access level
1391 * and thus this clause is never used.
1392 */
1393 cmd_reply(CMD_CMDLEVEL, caller, C_FAIL,
1394 _("Cannot decrease command access level '%s' "
1395 "for connection '%s'; you only have '%s'."),
1396 cmdlevel_name(ptarget->access_level),
1398 cmdlevel_name(caller->access_level));
1399 return FALSE;
1400 } else {
1402 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1403 _("Command access level set to '%s' for connection %s."),
1405 return TRUE;
1406 }
1407}
1408
1409/**********************************************************************/
1412static bool a_connection_exists(void)
1413{
1415}
1416
1417/**********************************************************************/
1421{
1423 if (pconn->access_level >= first_access_level) {
1424 return TRUE;
1425 }
1426 }
1428 return FALSE;
1429}
1430
1431/**********************************************************************/
1435{
1437 && !a_connection_exists()) {
1438 return first_access_level;
1439 } else {
1440 return default_access_level;
1441 }
1442}
1443
1444/**********************************************************************/
1449{
1453 _("Anyone can now become game organizer "
1454 "'%s' by issuing the 'first' command."),
1456 }
1457}
1458
1459/**********************************************************************/
1462static bool cmdlevel_command(struct connection *caller, char *str, bool check)
1463{
1464 char *arg[2];
1465 int ntokens;
1466 bool ret = FALSE;
1468 enum cmdlevel level;
1469 struct connection *ptarget;
1470
1472
1473 if (ntokens == 0) {
1474 /* No argument supplied; list the levels */
1477 _("Command access levels in effect:"));
1481
1482 if (lvl_name != NULL) {
1483 cmd_reply(CMD_CMDLEVEL, caller, C_COMMENT, "cmdlevel %s %s",
1485 } else {
1486 fc_assert(lvl_name != NULL); /* Always fails when reached. */
1487 }
1490 _("Command access level for new connections: %s"),
1493 _("Command access level for first player to take it: %s"),
1496 return TRUE;
1497 }
1498
1499 /* A level name was supplied; set the level. */
1501 if (!cmdlevel_is_valid(level)) {
1502 const char *cmdlevel_names[CMDLEVEL_COUNT];
1503 struct astring astr = ASTRING_INIT;
1504 int i = 0;
1505
1506 for (level = cmdlevel_begin(); level != cmdlevel_end();
1509 }
1511 /* TRANS: comma and 'or' separated list of access levels */
1512 _("Command access level must be one of %s."),
1514 astr_free(&astr);
1515 goto CLEAN_UP;
1516 } else if (caller && level > conn_get_access(caller)) {
1517 cmd_reply(CMD_CMDLEVEL, caller, C_FAIL,
1518 _("Cannot increase command access level to '%s';"
1519 " you only have '%s' yourself."),
1520 arg[0], cmdlevel_name(conn_get_access(caller)));
1521 goto CLEAN_UP;
1522 }
1523
1524 if (check) {
1525 return TRUE; /* looks good */
1526 }
1527
1528 if (ntokens == 1) {
1529 /* No playername supplied: set for all connections */
1531 if (pconn != caller) {
1532 (void) set_cmdlevel(caller, pconn, level);
1533 }
1535
1536 /* Set the caller access level at last, because it could make the
1537 * previous operations impossible if set before. */
1538 if (caller) {
1539 (void) set_cmdlevel(caller, caller, level);
1540 }
1541
1542 /* Set default access for new connections. */
1544 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1545 _("Command access level set to '%s' for new players."),
1547 /* Set default access for first connection. */
1549 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1550 _("Command access level set to '%s' "
1551 "for first player to grab it."),
1553
1554 ret = TRUE;
1555
1556 } else if (fc_strcasecmp(arg[1], "new") == 0) {
1558 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1559 _("Command access level set to '%s' for new players."),
1561 if (level > first_access_level) {
1563 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1564 _("Command access level set to '%s' "
1565 "for first player to grab it."),
1567 }
1568
1569 ret = TRUE;
1570
1571 } else if (fc_strcasecmp(arg[1], "first") == 0) {
1573 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1574 _("Command access level set to '%s' "
1575 "for first player to grab it."),
1579 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1580 _("Command access level set to '%s' for new players."),
1582 }
1583
1584 ret = TRUE;
1585
1586 } else if ((ptarget = conn_by_user_prefix(arg[1], &match_result))) {
1587 if (set_cmdlevel(caller, ptarget, level)) {
1588 ret = TRUE;
1589 }
1590 } else {
1592 }
1593
1594CLEAN_UP:
1595 free_tokens(arg, ntokens);
1596 return ret;
1597}
1598
1599/**********************************************************************/
1605static bool firstlevel_command(struct connection *caller, bool check)
1606{
1607 if (!caller) {
1609 _("The 'first' command makes no sense from the server command line."));
1610 return FALSE;
1611 } else if (caller->access_level >= first_access_level) {
1613 _("You already have command access level '%s' or better."),
1615 return FALSE;
1616 } else if (is_first_access_level_taken()) {
1618 _("Someone else is already game organizer."));
1619 return FALSE;
1620 } else if (!check) {
1622 cmd_reply(CMD_FIRSTLEVEL, caller, C_OK,
1623 _("Connection %s has opted to become the game organizer."),
1624 caller->username);
1625 }
1626 return TRUE;
1627}
1628
1629/**********************************************************************/
1633{
1636 _("Default cmdlevel lowered to 'basic' on game start."));
1638 }
1639}
1640
1641/**********************************************************************/
1645static const char *optname_accessor(int i)
1646{
1648}
1649
1650#ifdef FREECIV_HAVE_LIBREADLINE
1651/**********************************************************************/
1654static const char *olvlname_accessor(int i)
1655{
1656 if (i == 0) {
1657 return "rulesetdir";
1658 } else if (i < OLEVELS_NUM+1) {
1659 return sset_level_name(i-1);
1660 } else {
1661 return optname_accessor(i-OLEVELS_NUM-1);
1662 }
1663}
1664#endif /* FREECIV_HAVE_LIBREADLINE */
1665
1666/**********************************************************************/
1669static bool timeout_command(struct connection *caller, char *str, bool check)
1670{
1672 char *arg[4];
1673 int i = 0, ntokens;
1674 int *timeouts[4];
1675
1680
1681 sz_strlcpy(buf, str);
1683
1684 for (i = 0; i < ntokens; i++) {
1685 if (!str_to_int(arg[i], timeouts[i])) {
1686 cmd_reply(CMD_TIMEOUT, caller, C_FAIL, _("Invalid argument %d."),
1687 i + 1);
1688 }
1689 free(arg[i]);
1690 }
1691
1692 if (ntokens == 0) {
1693 cmd_reply(CMD_TIMEOUT, caller, C_SYNTAX, _("Usage:\n%s"),
1695 return FALSE;
1696 } else if (check) {
1697 return TRUE;
1698 }
1699
1700 cmd_reply(CMD_TIMEOUT, caller, C_OK, _("Dynamic timeout set to "
1701 "%d %d %d %d"),
1704
1705 /* if we set anything here, reset the counter */
1707 return TRUE;
1708}
1709
1710/**********************************************************************/
1713static enum sset_level lookup_option_level(const char *name)
1714{
1715 enum sset_level i;
1716
1717 for (i = SSET_ALL; i < OLEVELS_NUM; i++) {
1718 if (0 == fc_strcasecmp(name, sset_level_name(i))) {
1719 return i;
1720 }
1721 }
1722
1723 return SSET_NONE;
1724}
1725
1726/* Special return values of lookup options */
1727#define LOOKUP_OPTION_NO_RESULT (-1)
1728#define LOOKUP_OPTION_AMBIGUOUS (-2)
1729#define LOOKUP_OPTION_LEVEL_NAME (-3)
1730#define LOOKUP_OPTION_RULESETDIR (-4)
1731
1732/**********************************************************************/
1739static int lookup_option(const char *name)
1740{
1741 enum m_pre_result result;
1742 int ind;
1743
1744 /* Check for option levels, first off */
1747 }
1748
1750 0, fc_strncasecmp, NULL, name, &ind);
1751 if (M_PRE_AMBIGUOUS > result) {
1752 return ind;
1753 } else if (M_PRE_AMBIGUOUS == result) {
1755 } else if ('\0' != name[0]
1756 && 0 == fc_strncasecmp("rulesetdir", name, strlen(name))) {
1758 } else {
1760 }
1761}
1762
1763/**********************************************************************/
1768static void show_help_option(struct connection *caller,
1769 enum command_id help_cmd, int id)
1770{
1771 char val_buf[256], def_buf[256];
1772 struct setting *pset = setting_by_number(id);
1773 const char *sethelp;
1774
1775 if (setting_short_help(pset)) {
1776 cmd_reply(help_cmd, caller, C_COMMENT,
1777 /* TRANS: <untranslated name> - translated short help */
1778 _("Option: %s - %s"), setting_name(pset),
1780 } else {
1781 cmd_reply(help_cmd, caller, C_COMMENT,
1782 /* TRANS: <untranslated name> */
1783 _("Option: %s"), setting_name(pset));
1784 }
1785
1787 if (strlen(sethelp) > 0) {
1788 char *help = fc_strdup(sethelp);
1789
1791 cmd_reply(help_cmd, caller, C_COMMENT, _("Description:"));
1792 cmd_reply_prefix(help_cmd, caller, C_COMMENT, " ", " %s", help);
1793 FC_FREE(help);
1794 }
1795 cmd_reply(help_cmd, caller, C_COMMENT,
1796 _("Status: %s"), (setting_is_changeable(pset, NULL, NULL, 0)
1797 ? _("changeable") : _("fixed")));
1798
1799 if (setting_is_visible(pset, caller)) {
1802
1803 switch (setting_type(pset)) {
1804 case SST_INT:
1805 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s, %s %d, %s %s, %s %d",
1806 _("Value:"), val_buf,
1807 _("Minimum:"), setting_int_min(pset),
1808 _("Default:"), def_buf,
1809 _("Maximum:"), setting_int_max(pset));
1810 break;
1811 case SST_ENUM:
1812 {
1813 int i;
1814 const char *value;
1815
1816 cmd_reply(help_cmd, caller, C_COMMENT, _("Possible values:"));
1817 for (i = 0; (value = setting_enum_val(pset, i, FALSE)); i++) {
1818 cmd_reply(help_cmd, caller, C_COMMENT, "- %s: \"%s\"",
1820 }
1821 }
1822
1824 case SST_BOOL:
1825 case SST_STRING:
1826 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s, %s %s",
1827 _("Value:"), val_buf, _("Default:"), def_buf);
1828 break;
1829 case SST_BITWISE:
1830 {
1831 int i;
1832 const char *value;
1833
1834 cmd_reply(help_cmd, caller, C_COMMENT,
1835 _("Possible values (option can take any number of these):"));
1836 for (i = 0; (value = setting_bitwise_bit(pset, i, FALSE)); i++) {
1837 cmd_reply(help_cmd, caller, C_COMMENT, "- %s: \"%s\"",
1839 }
1840 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s",
1841 _("Value:"), val_buf);
1842 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s",
1843 _("Default:"), def_buf);
1844 }
1845 break;
1846 case SST_COUNT:
1848 break;
1849 }
1850 }
1851}
1852
1853/**********************************************************************/
1858static void show_help_option_list(struct connection *caller,
1859 enum command_id help_cmd)
1860{
1861 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1862 cmd_reply(help_cmd, caller, C_COMMENT,
1863 _("Explanations are available for the following server options:"));
1864 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1865 if (!caller && con_get_style()) {
1867 cmd_reply(help_cmd, caller, C_COMMENT, "%s", setting_name(pset));
1869 } else {
1871 int j = 0;
1872 buf[0] = '\0';
1873
1875 if (setting_is_visible(pset, caller)) {
1876 cat_snprintf(buf, sizeof(buf), "%-19s", setting_name(pset));
1877 if ((++j % 4) == 0) {
1878 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
1879 buf[0] = '\0';
1880 }
1881 }
1883
1884 if (buf[0] != '\0') {
1885 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
1886 }
1887 }
1888 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1889}
1890
1891/**********************************************************************/
1894static bool explain_option(struct connection *caller, char *str, bool check)
1895{
1896 int cmd;
1897
1899
1900 if (*str != '\0') {
1901 cmd = lookup_option(str);
1902 if (cmd >= 0 && cmd < settings_number()) {
1903 show_help_option(caller, CMD_EXPLAIN, cmd);
1904 } else if (cmd == LOOKUP_OPTION_NO_RESULT
1905 || cmd == LOOKUP_OPTION_LEVEL_NAME
1906 || cmd == LOOKUP_OPTION_RULESETDIR) {
1907 cmd_reply(CMD_EXPLAIN, caller, C_FAIL,
1908 _("No explanation for that yet."));
1909 return FALSE;
1910 } else if (cmd == LOOKUP_OPTION_AMBIGUOUS) {
1911 cmd_reply(CMD_EXPLAIN, caller, C_FAIL, _("Ambiguous option name."));
1912 return FALSE;
1913 } else {
1914 log_error("Unexpected case %d in %s line %d", cmd, __FILE__,
1915 __FC_LINE__);
1916 return FALSE;
1917 }
1918 } else {
1920 }
1921 return TRUE;
1922}
1923
1924/**********************************************************************/
1927static bool wall(char *str, bool check)
1928{
1929 if (!check) {
1931 _("Server Operator: %s"), str);
1932 }
1933 return TRUE;
1934}
1935
1936/**********************************************************************/
1939static bool connectmsg_command(struct connection *caller, char *str,
1940 bool check)
1941{
1942 unsigned int bufsize = sizeof(game.server.connectmsg);
1943
1944 if (is_restricted(caller)) {
1945 return FALSE;
1946 }
1947 if (!check) {
1948 int i;
1949 int c = 0;
1950
1951 for (i = 0; c < bufsize -1 && str[i] != '\0'; i++) {
1952 if (str[i] == '\\') {
1953 i++;
1954
1955 if (str[i] == 'n') {
1956 game.server.connectmsg[c++] = '\n';
1957 } else {
1958 game.server.connectmsg[c++] = str[i];
1959 }
1960 } else {
1961 game.server.connectmsg[c++] = str[i];
1962 }
1963 }
1964
1965 game.server.connectmsg[c++] = '\0';
1966
1967 if (c == bufsize) {
1968 /* Truncated */
1970 _("Connectmsg truncated to %u bytes."), bufsize);
1971 }
1972 }
1973 return TRUE;
1974}
1975
1976/**********************************************************************/
1980static enum command_id cmd_of_level(enum ai_level level)
1981{
1982 switch (level) {
1983 case AI_LEVEL_AWAY : return CMD_AWAY;
1984 case AI_LEVEL_RESTRICTED : return CMD_RESTRICTED;
1985 case AI_LEVEL_NOVICE : return CMD_NOVICE;
1986 case AI_LEVEL_EASY : return CMD_EASY;
1987 case AI_LEVEL_NORMAL : return CMD_NORMAL;
1988 case AI_LEVEL_HARD : return CMD_HARD;
1989 case AI_LEVEL_CHEATING : return CMD_CHEATING;
1990#ifdef FREECIV_DEBUG
1992#endif /* FREECIV_DEBUG */
1993 case AI_LEVEL_COUNT : return CMD_NORMAL;
1994 }
1995 log_error("Unknown AI level variant: %d.", level);
1996 return CMD_NORMAL;
1997}
1998
1999/**********************************************************************/
2002void set_ai_level_direct(struct player *pplayer, enum ai_level level)
2003{
2004 set_ai_level_directer(pplayer, level);
2005 send_player_info_c(pplayer, NULL);
2007 _("Player '%s' now has AI skill level '%s'."),
2008 player_name(pplayer),
2010
2011}
2012
2013/**********************************************************************/
2016static bool set_ai_level_named(struct connection *caller, const char *name,
2017 const char *level_name, bool check)
2018{
2020
2021 return set_ai_level(caller, name, level, check);
2022}
2023
2024/**********************************************************************/
2027static bool set_ai_level(struct connection *caller, const char *name,
2028 enum ai_level level, bool check)
2029{
2031 struct player *pplayer;
2032
2034
2036
2037 if (pplayer) {
2038 if (is_ai(pplayer)) {
2039 if (check) {
2040 return TRUE;
2041 }
2042 set_ai_level_directer(pplayer, level);
2043 send_player_info_c(pplayer, NULL);
2044 cmd_reply(cmd_of_level(level), caller, C_OK,
2045 _("Player '%s' now has AI skill level '%s'."),
2046 player_name(pplayer),
2048 } else {
2050 _("%s is not controlled by the AI."),
2051 player_name(pplayer));
2052 return FALSE;
2053 }
2054 } else if (match_result == M_PRE_EMPTY) {
2055 if (check) {
2056 return TRUE;
2057 }
2059 if (is_ai(cplayer)) {
2062 cmd_reply(cmd_of_level(level), caller, C_OK,
2063 _("Player '%s' now has AI skill level '%s'."),
2066 }
2070 cmd_reply(cmd_of_level(level), caller, C_OK,
2071 _("Default AI skill level set to '%s'."),
2073 } else {
2075 return FALSE;
2076 }
2077 return TRUE;
2078}
2079
2080/**********************************************************************/
2083static bool away_command(struct connection *caller, bool check)
2084{
2085 struct player *pplayer;
2086
2087 if (caller == NULL) {
2088 cmd_reply(CMD_AWAY, caller, C_FAIL, _("This command is client only."));
2089 return FALSE;
2090 }
2091
2092 if (!conn_controls_player(caller)) {
2093 /* This happens for detached or observer connections. */
2094 cmd_reply(CMD_AWAY, caller, C_FAIL,
2095 _("Only players may use the away command."));
2096 return FALSE;
2097 }
2098
2099 if (check) {
2100 return TRUE;
2101 }
2102
2103 pplayer = conn_get_player(caller);
2104 if (is_human(pplayer)) {
2105 cmd_reply(CMD_AWAY, caller, C_OK,
2106 _("%s set to away mode."), player_name(pplayer));
2108 fc_assert(!is_human(pplayer));
2109 } else {
2110 cmd_reply(CMD_AWAY, caller, C_OK,
2111 _("%s returned to game."), player_name(pplayer));
2113 fc_assert(is_human(pplayer));
2114 }
2115
2117
2118 return TRUE;
2119}
2120
2121/**********************************************************************/
2124static void show_ruleset_info(struct connection *caller, enum command_id cmd,
2125 bool check, int read_recursion)
2126{
2127 char *show_arg = "changed";
2128
2129 /* show changed settings only at the top level of recursion */
2130 if (read_recursion != 0) {
2131 return;
2132 }
2133
2134 show_settings(caller, cmd, show_arg, check);
2135
2136 if (game.ruleset_summary != NULL) {
2138
2140 cmd_reply(cmd, caller, C_COMMENT, "%s", translated);
2141 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
2143 }
2144}
2145
2146/**********************************************************************/
2149static bool show_command(struct connection *caller, char *str, bool check)
2150{
2151 return show_settings(caller, CMD_SHOW, str, check);
2152}
2153
2154/**********************************************************************/
2159static bool show_settings(struct connection *caller,
2160 enum command_id called_as,
2161 char *str, bool check)
2162{
2163 int cmd;
2164 enum sset_level level = SSET_ALL;
2165 size_t clen = 0;
2166
2168 if (str[0] != '\0') {
2169 /* In "/show forests", figure out that it's the forests option we're
2170 * looking at. */
2171 cmd = lookup_option(str);
2172 if (cmd >= 0) {
2173 /* Ignore levels when a particular option is specified. */
2174 level = SSET_NONE;
2175
2176 if (!setting_is_visible(setting_by_number(cmd), caller)) {
2177 cmd_reply(called_as, caller, C_FAIL,
2178 _("Sorry, you do not have access to view option '%s'."),
2179 str);
2180 return FALSE;
2181 }
2182 }
2183
2184 /* Valid negative values for 'cmd' are defined as LOOKUP_OPTION_*. */
2185 switch (cmd) {
2187 cmd_reply(called_as, caller, C_FAIL, _("Unknown option '%s'."), str);
2188 return FALSE;
2190 /* Allow ambiguous: show all matching. */
2191 clen = strlen(str);
2192 break;
2194 /* Option level. */
2196 break;
2198 /* Ruleset. */
2199 cmd_reply(called_as, caller, C_COMMENT,
2200 _("Current ruleset directory is \"%s\""),
2202 return TRUE;
2203 }
2204 } else {
2205 /* to indicate that no command was specified */
2207 /* Use vital level by default. */
2208 level = SSET_VITAL;
2209 }
2210
2212 || cmd == LOOKUP_OPTION_LEVEL_NAME
2213 || cmd == LOOKUP_OPTION_NO_RESULT, FALSE);
2214
2215#define cmd_reply_show(string) \
2216 cmd_reply(called_as, caller, C_COMMENT, "%s", string)
2217
2218 {
2219 const char *heading = NULL;
2220 switch (level) {
2221 case SSET_NONE:
2222 break;
2223 case SSET_CHANGED:
2224 heading = _("All options with non-default values");
2225 break;
2226 case SSET_ALL:
2227 heading = _("All options");
2228 break;
2229 case SSET_VITAL:
2230 heading = _("Vital options");
2231 break;
2232 case SSET_SITUATIONAL:
2233 heading = _("Situational options");
2234 break;
2235 case SSET_RARE:
2236 heading = _("Rarely used options");
2237 break;
2238 case SSET_LOCKED:
2239 heading = _("Options locked by the ruleset");
2240 break;
2241 case OLEVELS_NUM:
2242 /* nothing */
2243 break;
2244 }
2245 if (heading) {
2248 }
2249 }
2251 cmd_reply_show(_("In the column '##' the status of the option is shown:"));
2252 cmd_reply_show(_(" - a '!' means the option is locked by the ruleset."));
2253 cmd_reply_show(_(" - a '+' means you may change the option."));
2254 cmd_reply_show(_(" - a '~' means that option follows default value."));
2255 cmd_reply_show(_(" - a '=' means the value is same as default."));
2257 cmd_reply(called_as, caller, C_COMMENT, _("%-*s ## value (min, max)"),
2258 OPTION_NAME_SPACE, _("Option"));
2260
2261 /* Update changed and locked levels. */
2263
2264 switch (level) {
2265 case SSET_NONE:
2266 /* Show _one_ setting. */
2267 fc_assert_ret_val(0 <= cmd, FALSE);
2268 {
2269 struct setting *pset = setting_by_number(cmd);
2270
2272 }
2273 break;
2274 case SSET_CHANGED:
2275 case SSET_ALL:
2276 case SSET_VITAL:
2277 case SSET_SITUATIONAL:
2278 case SSET_RARE:
2279 case SSET_LOCKED:
2281 if (!setting_is_visible(pset, caller)) {
2282 continue;
2283 }
2284
2285 if (LOOKUP_OPTION_AMBIGUOUS == cmd
2286 && 0 != fc_strncasecmp(setting_name(pset), str, clen)) {
2287 continue;
2288 }
2289
2292 break;
2293 case OLEVELS_NUM:
2294 /* nothing */
2295 break;
2296 }
2297
2299 /* Only emit this additional help for bona fide 'show' command */
2300 if (called_as == CMD_SHOW) {
2301 cmd_reply_show(_("A help text for each option is available via 'help "
2302 "<option>'."));
2304 if (level == SSET_VITAL) {
2305 cmd_reply_show(_("Try 'show situational' or 'show rare' to show "
2306 "more options.\n"
2307 "Try 'show changed' to show settings with "
2308 "non-default values.\n"
2309 "Try 'show locked' to show settings locked "
2310 "by the ruleset."));
2312 }
2313 }
2314 return TRUE;
2315#undef cmd_reply_show
2316}
2317
2318/**********************************************************************/
2331static void show_settings_one(struct connection *caller, enum command_id cmd,
2332 struct setting *pset)
2333{
2335 bool is_changed;
2336 static char prefix[OPTION_NAME_SPACE + 4 + 1] = "";
2337 char defaultness;
2338
2340
2343
2344 /* Wrap long option values, such as bitwise options */
2345 fc_break_lines(value, LINE_BREAK - (sizeof(prefix)-1));
2346
2347 if (prefix[0] == '\0') {
2348 memset(prefix, ' ', sizeof(prefix)-1);
2349 }
2350
2351 if (is_changed) {
2352 /* Emphasizes the changed option. */
2353 /* Apply tags to each line fragment. */
2354 size_t startpos = 0;
2355 char *nl;
2356
2357 do {
2358 nl = strchr(value + startpos, '\n');
2361 ftc_changed);
2363 if (nl) {
2364 char *p = strchr(nl, '\n');
2365
2366 fc_assert_action(p != NULL, break);
2367 startpos = p + 1 - value;
2368 }
2369 } while (nl);
2370 }
2371
2372 if (SST_INT == setting_type(pset)) {
2373 /* Add the range. */
2374 cat_snprintf(value, sizeof(value), " (%d, %d)",
2376 }
2377
2379 defaultness = '~';
2380 } else if (is_changed) {
2381 defaultness = ' ';
2382 } else {
2383 defaultness = '=';
2384 }
2385
2386 cmd_reply_prefix(cmd, caller, C_COMMENT, prefix, "%-*s %c%c %s",
2389 value);
2390}
2391
2392/**********************************************************************/
2395static bool team_command(struct connection *caller, char *str, bool check)
2396{
2397 struct player *pplayer;
2400 char *arg[2];
2401 int ntokens = 0, i;
2402 bool res = FALSE;
2403 struct team_slot *tslot;
2404
2405 if (game_was_started()) {
2406 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2407 _("Cannot change teams once game has begun."));
2408 return FALSE;
2409 }
2410
2411 if (str != NULL || strlen(str) > 0) {
2412 sz_strlcpy(buf, str);
2414 }
2415 if (ntokens != 2) {
2416 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2417 _("Undefined argument. Usage:\n%s"),
2419 goto cleanup;
2420 }
2421
2422 pplayer = player_by_name_prefix(arg[0], &match_result);
2423 if (pplayer == NULL) {
2425 goto cleanup;
2426 }
2427
2428 tslot = team_slot_by_rule_name(arg[1]);
2429 if (NULL == tslot) {
2430 int teamno;
2431
2432 if (str_to_int(arg[1], &teamno)) {
2434 }
2435 }
2436
2437 if (NULL == tslot) {
2438 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2439 _("No such team %s. Please give a "
2440 "valid team name or number."), arg[1]);
2441 goto cleanup;
2442 }
2443
2444 if (is_barbarian(pplayer)) {
2445 /* This can happen if we change team settings on a loaded game. */
2446 cmd_reply(CMD_TEAM, caller, C_SYNTAX, _("Cannot team a barbarian."));
2447 goto cleanup;
2448 }
2449
2450 if (!check) {
2451 /* Should never fail when slot given is not nullptr */
2452 team_add_player(pplayer, team_new(tslot));
2453 send_player_info_c(pplayer, NULL);
2454 cmd_reply(CMD_TEAM, caller, C_OK, _("Player %s set to team %s."),
2455 player_name(pplayer),
2457 }
2458
2459 res = TRUE;
2460
2461 cleanup:
2462 for (i = 0; i < ntokens; i++) {
2463 free(arg[i]);
2464 }
2465
2466 return res;
2467}
2468
2469/**********************************************************************/
2472static void show_votes(struct connection *caller)
2473{
2474 int count = 0;
2475 const char *title;
2476
2477 if (vote_list != NULL) {
2479 if (NULL != caller && !conn_can_see_vote(caller, pvote)) {
2480 continue;
2481 }
2482 /* TRANS: "Vote" or "Teamvote" is voting-as-a-process. Used as
2483 * part of a sentence. */
2484 title = vote_is_team_only(pvote) ? _("Teamvote") : _("Vote");
2485 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2486 /* TRANS: "[Vote|Teamvote] 3 \"proposed change\" (needs ..." */
2487 _("%s %d \"%s\" (needs %0.0f%%%s): %d for, "
2488 "%d against, and %d abstained out of %d players."),
2489 title, pvote->vote_no, pvote->cmdline,
2490 MIN(100, pvote->need_pc * 100 + 1),
2491 /* TRANS: preserve leading space */
2492 pvote->flags & VCF_NODISSENT ? _(" no dissent") : "",
2493 pvote->yes, pvote->no, pvote->abstain, count_voters(pvote));
2494 count++;
2496 }
2497
2498 if (count == 0) {
2499 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2500 _("There are no votes going on."));
2501 }
2502}
2503
2504/**********************************************************************/
2507static const char *const vote_args[] = {
2508 "yes",
2509 "no",
2510 "abstain",
2511 NULL
2512};
2513static const char *vote_arg_accessor(int i)
2514{
2515 return vote_args[i];
2516}
2517
2518/**********************************************************************/
2521static bool vote_command(struct connection *caller, char *str,
2522 bool check)
2523{
2525 char *arg[2];
2526 int ntokens = 0, i = 0, which = -1;
2528 struct vote *pvote = NULL;
2529 bool res = FALSE;
2530
2531 if (check) {
2532 /* This should never happen, since /vote must always be
2533 * set to ALLOW_BASIC or less. But just in case... */
2534 return FALSE;
2535 }
2536
2537 sz_strlcpy(buf, str);
2539
2540 if (ntokens == 0) {
2541 show_votes(caller);
2542 goto CLEANUP;
2543 } else if (!conn_can_vote(caller, NULL)) {
2544 cmd_reply(CMD_VOTE, caller, C_FAIL,
2545 _("You are not allowed to use this command."));
2546 goto CLEANUP;
2547 }
2548
2550 fc_strncasecmp, NULL, arg[0], &i);
2551
2553 cmd_reply(CMD_VOTE, caller, C_SYNTAX,
2554 _("The argument \"%s\" is ambiguous."), arg[0]);
2555 goto CLEANUP;
2556 } else if (match_result > M_PRE_AMBIGUOUS) {
2557 /* Failed */
2558 cmd_reply(CMD_VOTE, caller, C_SYNTAX,
2559 _("Undefined argument. Usage:\n%s"),
2561 goto CLEANUP;
2562 }
2563
2564 if (ntokens == 1) {
2565 /* Applies to last vote */
2568 } else {
2570 if (num_votes == 0) {
2571 cmd_reply(CMD_VOTE, caller, C_FAIL, _("There are no votes running."));
2572 } else {
2573 /* TRANS: "vote" as a process */
2574 cmd_reply(CMD_VOTE, caller, C_FAIL, _("No legal last vote (%d %s)."),
2575 num_votes, PL_("other vote running", "other votes running",
2576 num_votes));
2577 }
2578 goto CLEANUP;
2579 }
2580 } else {
2581 if (!str_to_int(arg[1], &which)) {
2582 cmd_reply(CMD_VOTE, caller, C_SYNTAX, _("Value must be an integer."));
2583 goto CLEANUP;
2584 }
2585 }
2586
2587 if (!(pvote = get_vote_by_no(which))) {
2588 /* TRANS: "vote" as a process */
2589 cmd_reply(CMD_VOTE, caller, C_FAIL, _("No such vote (%d)."), which);
2590 goto CLEANUP;
2591 }
2592
2593 if (!conn_can_vote(caller, pvote)) {
2594 cmd_reply(CMD_VOTE, caller, C_FAIL,
2595 _("You are not allowed to vote on that."));
2596 goto CLEANUP;
2597 }
2598
2599 if (i == VOTE_YES) {
2600 cmd_reply(CMD_VOTE, caller, C_COMMENT, _("You voted for \"%s\""),
2601 pvote->cmdline);
2602 connection_vote(caller, pvote, VOTE_YES);
2603 } else if (i == VOTE_NO) {
2604 cmd_reply(CMD_VOTE, caller, C_COMMENT, _("You voted against \"%s\""),
2605 pvote->cmdline);
2606 connection_vote(caller, pvote, VOTE_NO);
2607 } else if (i == VOTE_ABSTAIN) {
2608 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2609 _("You abstained from voting on \"%s\""), pvote->cmdline);
2611 } else {
2612 /* Must never happen. */
2614 }
2615
2616 res = TRUE;
2617
2618CLEANUP:
2619 free_tokens(arg, ntokens);
2620 return res;
2621}
2622
2623/**********************************************************************/
2626static bool cancelvote_command(struct connection *caller,
2627 char *arg, bool check)
2628{
2629 struct vote *pvote = NULL;
2630 int vote_no;
2631
2632 if (check) {
2633 /* This should never happen anyway, since /cancelvote
2634 * is set to ALLOW_BASIC in both pregame and while the
2635 * game is running. */
2636 return FALSE;
2637 }
2638
2640
2641 if (arg[0] == '\0') {
2642 if (caller == NULL) {
2643 /* Server prompt */
2645 /* TRANS: "vote" as a process */
2646 _("Missing argument <vote number> or "
2647 "the string \"all\"."));
2648 return FALSE;
2649 }
2650 /* The caller is canceling their own vote. */
2651 if (!(pvote = get_vote_by_caller(caller))) {
2653 _("You don't have any vote going on."));
2654 return FALSE;
2655 }
2656 } else if (fc_strcasecmp(arg, "all") == 0) {
2657 /* Cancel all votes (needs some privileges). */
2658 if (vote_list_size(vote_list) == 0) {
2660 _("There isn't any vote going on."));
2661 return FALSE;
2662 } else if (!caller || conn_get_access(caller) >= ALLOW_ADMIN) {
2665 /* TRANS: "votes" as a process */
2666 _("All votes have been removed."));
2667 return TRUE;
2668 } else {
2670 _("You are not allowed to use this command."));
2671 return FALSE;
2672 }
2673 } else if (str_to_int(arg, &vote_no)) {
2674 /* Cancel one particular vote (needs some privileges if the vote
2675 * is not owned). */
2676 if (!(pvote = get_vote_by_no(vote_no))) {
2678 /* TRANS: "vote" as a process */
2679 _("No such vote (%d)."), vote_no);
2680 return FALSE;
2681 } else if (caller && conn_get_access(caller) < ALLOW_ADMIN
2682 && caller->id != pvote->caller_id) {
2684 /* TRANS: "vote" as a process */
2685 _("You are not allowed to cancel this vote (%d)."),
2686 vote_no);
2687 return FALSE;
2688 }
2689 } else {
2691 /* TRANS: "vote" as a process */
2692 _("Usage: /cancelvote [<vote number>|all]"));
2693 return FALSE;
2694 }
2695
2697
2698 if (caller) {
2701 /* TRANS: "vote" as a process */
2702 _("%s has canceled the vote \"%s\" (number %d)."),
2703 caller->username, pvote->cmdline, pvote->vote_no);
2704 } else {
2705 /* Server prompt */
2708 /* TRANS: "vote" as a process */
2709 _("The vote \"%s\" (number %d) has been canceled."),
2710 pvote->cmdline, pvote->vote_no);
2711 }
2712 /* Make it after, prevent crashs about a free pointer (pvote). */
2714
2715 return TRUE;
2716}
2717
2718/**********************************************************************/
2721static bool debug_command(struct connection *caller, char *str,
2722 bool check)
2723{
2725 char *arg[3];
2726 int ntokens = 0, i;
2727
2728 if (game.info.is_new_game) {
2729 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2730 _("Can only use this command once game has begun."));
2731 return FALSE;
2732 }
2733 if (check) {
2734 return TRUE; /* whatever! */
2735 }
2736
2737 if (str != NULL && strlen(str) > 0) {
2738 sz_strlcpy(buf, str);
2740 } else {
2741 ntokens = 0;
2742 }
2743
2744 if (ntokens > 0 && strcmp(arg[0], "diplomacy") == 0) {
2745 struct player *pplayer;
2747
2748 if (ntokens != 2) {
2749 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2750 _("Undefined argument. Usage:\n%s"),
2752 goto cleanup;
2753 }
2754 pplayer = player_by_name_prefix(arg[1], &match_result);
2755 if (pplayer == NULL) {
2757 goto cleanup;
2758 }
2761 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s diplomacy no longer debugged"),
2762 player_name(pplayer));
2763 } else {
2765 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s diplomacy debugged"),
2766 player_name(pplayer));
2767 /* TODO: print some info about the player here */
2768 }
2769 } else if (ntokens > 0 && strcmp(arg[0], "tech") == 0) {
2770 struct player *pplayer;
2772
2773 if (ntokens != 2) {
2774 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2775 _("Undefined argument. Usage:\n%s"),
2777 goto cleanup;
2778 }
2779 pplayer = player_by_name_prefix(arg[1], &match_result);
2780 if (pplayer == NULL) {
2782 goto cleanup;
2783 }
2784 if (BV_ISSET(pplayer->server.debug, PLAYER_DEBUG_TECH)) {
2786 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s tech no longer debugged"),
2787 player_name(pplayer));
2788 } else {
2790 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s tech debugged"),
2791 player_name(pplayer));
2792 /* TODO: print some info about the player here */
2793 }
2794 } else if (ntokens > 0 && strcmp(arg[0], "info") == 0) {
2795 int cities = 0, players = 0, units = 0, citizen_count = 0;
2796
2797 players_iterate(plr) {
2798 players++;
2799 city_list_iterate(plr->cities, pcity) {
2800 cities++;
2803 units += unit_list_size(plr->units);
2805 log_normal(_("players=%d cities=%d citizens=%d units=%d"),
2806 players, cities, citizen_count, units);
2808 _("players=%d cities=%d citizens=%d units=%d"),
2809 players, cities, citizen_count, units);
2810 } else if (ntokens > 0 && strcmp(arg[0], "city") == 0) {
2811 int x, y;
2812 struct tile *ptile;
2813 struct city *pcity;
2814
2815 if (ntokens != 3) {
2816 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2817 _("Undefined argument. Usage:\n%s"),
2819 goto cleanup;
2820 }
2821 if (!str_to_int(arg[1], &x) || !str_to_int(arg[2], &y)) {
2822 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be integer."));
2823 goto cleanup;
2824 }
2825 if (!(ptile = map_pos_to_tile(&(wld.map), x, y))) {
2826 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
2827 goto cleanup;
2828 }
2829 pcity = tile_city(ptile);
2830 if (!pcity) {
2831 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("No city at this coordinate."));
2832 goto cleanup;
2833 }
2834 if (pcity->server.debug) {
2836 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s no longer debugged"),
2838 } else {
2840 CITY_LOG(LOG_NORMAL, pcity, "debugged");
2841 }
2842 } else if (ntokens > 0 && strcmp(arg[0], "units") == 0) {
2843 int x, y;
2844 struct tile *ptile;
2845
2846 if (ntokens != 3) {
2847 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2848 _("Undefined argument. Usage:\n%s"),
2850 goto cleanup;
2851 }
2852 if (!str_to_int(arg[1], &x) || !str_to_int(arg[2], &y)) {
2853 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be integer."));
2854 goto cleanup;
2855 }
2856 if (!(ptile = map_pos_to_tile(&(wld.map), x, y))) {
2857 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
2858 goto cleanup;
2859 }
2860 unit_list_iterate(ptile->units, punit) {
2861 if (punit->server.debug) {
2863 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s %s no longer debugged."),
2866 } else {
2868 UNIT_LOG(LOG_NORMAL, punit, "%s %s debugged.",
2871 }
2873 } else if (ntokens > 0 && strcmp(arg[0], "timing") == 0) {
2875 } else if (ntokens > 0 && strcmp(arg[0], "ferries") == 0) {
2878 cmd_reply(CMD_DEBUG, caller, C_OK, _("Ferry system is no longer "
2879 "in debug mode."));
2880 } else {
2882 cmd_reply(CMD_DEBUG, caller, C_OK, _("Ferry system in debug mode."));
2883 }
2884 } else if (ntokens > 0 && strcmp(arg[0], "unit") == 0) {
2885 int id;
2886 struct unit *punit;
2887
2888 if (ntokens != 2) {
2889 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2890 _("Undefined argument. Usage:\n%s"),
2892 goto cleanup;
2893 }
2894 if (!str_to_int(arg[1], &id)) {
2895 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 must be integer."));
2896 goto cleanup;
2897 }
2898 if (!(punit = game_unit_by_number(id))) {
2899 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Unit %d does not exist."), id);
2900 goto cleanup;
2901 }
2902 if (punit->server.debug) {
2904 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s %s no longer debugged."),
2907 } else {
2909 UNIT_LOG(LOG_NORMAL, punit, "%s %s debugged.",
2912 }
2913 } else {
2914 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2915 _("Undefined argument. Usage:\n%s"),
2917 }
2918 cleanup:
2919 for (i = 0; i < ntokens; i++) {
2920 free(arg[i]);
2921 }
2922 return TRUE;
2923}
2924
2925/**********************************************************************/
2930 struct connection *caller,
2931 char *arg)
2932{
2933 int opt = lookup_option(arg);
2934
2935 if (opt < 0) {
2936 switch (opt) {
2939 cmd_reply(cmd, caller, C_SYNTAX, _("Option '%s' not recognized."), arg);
2940 break;
2942 cmd_reply(cmd, caller, C_SYNTAX, _("Ambiguous option name."));
2943 break;
2945 cmd_reply(cmd, caller, C_SYNTAX,
2946 /* TRANS: 'rulesetdir' is the command. Do not translate. */
2947 _("Use the '%srulesetdir' command to change the ruleset "
2948 "directory."), caller ? "/" : "");
2949 break;
2950 default:
2952 break;
2953 }
2954 return NULL;
2955 }
2956
2957 return setting_by_number(opt);
2958}
2959
2960/**********************************************************************/
2963static bool set_command(struct connection *caller, char *str, bool check)
2964{
2965 char *args[2];
2966 int val, nargs;
2967 struct setting *pset;
2968 bool do_update;
2969 char reject_msg[256] = "";
2970 bool ret = FALSE;
2971
2972 /* '=' is also a valid delimiter for this function. */
2973 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS "=");
2974
2975 if (nargs < 2) {
2976 cmd_reply(CMD_SET, caller, C_SYNTAX,
2977 _("Undefined argument. Usage:\n%s"),
2979 goto cleanup;
2980 }
2981
2982 pset = validate_setting_arg(CMD_SET, caller, args[0]);
2983
2984 if (!pset) {
2985 /* Reason already reported. */
2986 goto cleanup;
2987 }
2988
2989 if (!setting_is_changeable(pset, caller, reject_msg, sizeof(reject_msg))
2990 && !check) {
2991 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
2992 goto cleanup;
2993 }
2994
2995 do_update = FALSE;
2996
2997 switch (setting_type(pset)) {
2998 case SST_BOOL:
2999 if (check) {
3001 sizeof(reject_msg))
3002 || (!setting_bool_validate(pset, args[1], caller,
3003 reject_msg, sizeof(reject_msg)))) {
3004 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3005 goto cleanup;
3006 }
3007 } else if (setting_bool_set(pset, args[1], caller,
3008 reject_msg, sizeof(reject_msg))) {
3009 do_update = TRUE;
3010 } else {
3011 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3012 goto cleanup;
3013 }
3014 break;
3015
3016 case SST_INT:
3017 if (!str_to_int(args[1], &val)) {
3018 cmd_reply(CMD_SET, caller, C_SYNTAX,
3019 _("The parameter %s should only contain +- and 0-9."),
3021 goto cleanup;
3022 }
3023 if (check) {
3025 sizeof(reject_msg))
3026 || !setting_int_validate(pset, val, caller, reject_msg,
3027 sizeof(reject_msg))) {
3028 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3029 goto cleanup;
3030 }
3031 } else {
3032 if (setting_int_set(pset, val, caller, reject_msg,
3033 sizeof(reject_msg))) {
3034 do_update = TRUE;
3035 } else {
3036 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3037 goto cleanup;
3038 }
3039 }
3040 break;
3041
3042 case SST_STRING:
3043 if (check) {
3045 sizeof(reject_msg))
3046 || !setting_str_validate(pset, args[1], caller, reject_msg,
3047 sizeof(reject_msg))) {
3048 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3049 goto cleanup;
3050 }
3051 } else {
3052 if (setting_str_set(pset, args[1], caller, reject_msg,
3053 sizeof(reject_msg))) {
3054 do_update = TRUE;
3055 } else {
3056 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3057 goto cleanup;
3058 }
3059 }
3060 break;
3061
3062 case SST_ENUM:
3063 if (check) {
3065 sizeof(reject_msg))
3066 || (!setting_enum_validate(pset, args[1], caller,
3067 reject_msg, sizeof(reject_msg)))) {
3068 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3069 goto cleanup;
3070 }
3071 } else if (setting_enum_set(pset, args[1], caller,
3072 reject_msg, sizeof(reject_msg))) {
3073 do_update = TRUE;
3074 } else {
3075 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3076 goto cleanup;
3077 }
3078 break;
3079
3080 case SST_BITWISE:
3081 if (check) {
3083 sizeof(reject_msg))
3084 || (!setting_bitwise_validate(pset, args[1], caller,
3085 reject_msg, sizeof(reject_msg)))) {
3086 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3087 goto cleanup;
3088 }
3089 } else if (setting_bitwise_set(pset, args[1], caller,
3090 reject_msg, sizeof(reject_msg))) {
3091 do_update = TRUE;
3092 } else {
3093 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3094 goto cleanup;
3095 }
3096 break;
3097
3098 case SST_COUNT:
3100 goto cleanup;
3101 break;
3102 }
3103
3104 ret = TRUE; /* Looks like a success. */
3105
3106 if (!check && do_update) {
3107 /* Send only to connections able to see that. */
3108 char buf[256];
3109 struct packet_chat_msg packet;
3110
3112 _("Console: '%s' has been set to %s."), setting_name(pset),
3113 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3116 send_packet_chat_msg(pconn, &packet);
3117 }
3119 /* Notify the console. */
3120 con_write(C_OK, "%s", packet.message);
3121
3125 /*
3126 * send any modified game parameters to the clients -- if sent
3127 * before S_S_RUNNING, triggers a popdown_races_dialog() call
3128 * in client/packhand.c#handle_game_info()
3129 */
3133 }
3134
3135 cleanup:
3136 free_tokens(args, nargs);
3137 return ret;
3138}
3139
3140/**********************************************************************/
3143static bool lock_command(struct connection *caller, char *str, bool check)
3144{
3145 char *args[1];
3146 int nargs;
3147
3148 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS);
3149
3150 if (nargs < 1) {
3151 cmd_reply(CMD_LOCK, caller, C_SYNTAX,
3152 _("Undefined argument. Usage:\n%s"),
3154 } else {
3155 struct setting *pset;
3156
3157 pset = validate_setting_arg(CMD_SET, caller, args[0]);
3158
3159 if (pset != NULL) {
3161 return TRUE;
3162 }
3163 }
3164
3165 return FALSE;
3166}
3167
3168/**********************************************************************/
3171static bool unlock_command(struct connection *caller, char *str, bool check)
3172{
3173 char *args[1];
3174 int nargs;
3175
3176 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS);
3177
3178 if (nargs < 1) {
3179 cmd_reply(CMD_LOCK, caller, C_SYNTAX,
3180 _("Undefined argument. Usage:\n%s"),
3182 } else {
3183 struct setting *pset;
3184
3185 pset = validate_setting_arg(CMD_SET, caller, args[0]);
3186
3187 if (pset != NULL) {
3189 return TRUE;
3190 }
3191 }
3192
3193 return FALSE;
3194}
3195
3196/**********************************************************************/
3204 struct connection *taker,
3205 struct player *pplayer, bool will_obs,
3206 char *msg, size_t msg_len)
3207{
3208 const char *allow;
3209
3210 if (!pplayer && !will_obs) {
3211 /* Auto-taking a new player */
3212
3213 if (game_was_started()) {
3214 fc_strlcpy(msg, _("You cannot take a new player at this time."),
3215 msg_len);
3216 return FALSE;
3217 }
3218
3220 fc_snprintf(msg, msg_len,
3221 /* TRANS: Do not translate "maxplayers". */
3222 PL_("You cannot take a new player because "
3223 "the maximum of %d player has already "
3224 "been reached (maxplayers setting).",
3225 "You cannot take a new player because "
3226 "the maximum of %d players has already "
3227 "been reached (maxplayers setting).",
3230 return FALSE;
3231 }
3232
3233 if (player_count() >= player_slot_count()) {
3234 fc_strlcpy(msg, _("You cannot take a new player because there "
3235 "are no free player slots."),
3236 msg_len);
3237 return FALSE;
3238 }
3239
3240 return TRUE;
3241
3242 }
3243
3244#ifdef HAVE_FCDB
3245 if (srvarg.fcdb_enabled) {
3246 bool ok = FALSE;
3247
3248 if (script_fcdb_call("user_take", requester, taker, pplayer, will_obs,
3249 &ok) && ok) {
3250 return TRUE;
3251 }
3252 }
3253#endif
3254
3255 if (!pplayer && will_obs) {
3256 /* Global observer. */
3258 (game.info.is_new_game ? 'O' : 'o')))) {
3259 fc_strlcpy(msg, _("Sorry, one can't observe globally in this game."),
3260 msg_len);
3261 return FALSE;
3262 }
3263 } else if (is_barbarian(pplayer)) {
3264 if (!(allow = strchr(game.server.allow_take, 'b'))) {
3265 if (will_obs) {
3266 fc_strlcpy(msg,
3267 _("Sorry, one can't observe barbarians in this game."),
3268 msg_len);
3269 } else {
3270 fc_strlcpy(msg, _("Sorry, one can't take barbarians in this game."),
3271 msg_len);
3272 }
3273 return FALSE;
3274 }
3275 } else if (!pplayer->is_alive) {
3276 if (!(allow = strchr(game.server.allow_take, 'd'))) {
3277 if (will_obs) {
3278 fc_strlcpy(msg,
3279 _("Sorry, one can't observe dead players in this game."),
3280 msg_len);
3281 } else {
3282 fc_strlcpy(msg,
3283 _("Sorry, one can't take dead players in this game."),
3284 msg_len);
3285 }
3286 return FALSE;
3287 }
3288 } else if (is_ai(pplayer)) {
3290 (game.info.is_new_game ? 'A' : 'a')))) {
3291 if (will_obs) {
3292 fc_strlcpy(msg,
3293 _("Sorry, one can't observe AI players in this game."),
3294 msg_len);
3295 } else {
3296 fc_strlcpy(msg, _("Sorry, one can't take AI players in this game."),
3297 msg_len);
3298 }
3299 return FALSE;
3300 }
3301 } else {
3303 (game.info.is_new_game ? 'H' : 'h')))) {
3304 if (will_obs) {
3305 fc_strlcpy(msg,
3306 _("Sorry, one can't observe human players in this game."),
3307 msg_len);
3308 } else {
3309 fc_strlcpy(msg,
3310 _("Sorry, one can't take human players in this game."),
3311 msg_len);
3312 }
3313 return FALSE;
3314 }
3315 }
3316
3317 allow++;
3318
3319 if (will_obs && (*allow == '2' || *allow == '3')) {
3320 fc_strlcpy(msg, _("Sorry, one can't observe in this game."), msg_len);
3321 return FALSE;
3322 }
3323
3324 if (!will_obs && *allow == '4') {
3325 fc_strlcpy(msg, _("Sorry, one can't take players in this game."),
3326 MAX_LEN_MSG);
3327 return FALSE;
3328 }
3329
3330 if (!will_obs && pplayer->is_connected
3331 && (*allow == '1' || *allow == '3')) {
3332 fc_strlcpy(msg, _("Sorry, one can't take players already "
3333 "connected in this game."), msg_len);
3334 return FALSE;
3335 }
3336
3337 return TRUE;
3338}
3339
3340/**********************************************************************/
3345static bool observe_command(struct connection *caller, char *str, bool check)
3346{
3347 int i = 0, ntokens = 0;
3348 char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
3349 bool is_newgame = !game_was_started();
3350 enum m_pre_result result;
3351 struct connection *pconn = NULL;
3352 struct player *pplayer = NULL;
3353 bool res = FALSE;
3354
3355 /******** PART I: fill pconn and pplayer ********/
3356
3357 sz_strlcpy(buf, str);
3359
3360 /* check syntax, only certain syntax if allowed depending on the caller */
3361 if (!caller && ntokens < 1) {
3362 cmd_reply(CMD_OBSERVE, caller, C_SYNTAX, _("Usage:\n%s"),
3364 goto end;
3365 }
3366
3367 if (ntokens == 2 && (caller && caller->access_level != ALLOW_HACK)) {
3369 _("Only the player name form is allowed."));
3370 goto end;
3371 }
3372
3373 /* match connection if we're console, match a player if we're not */
3374 if (ntokens == 1) {
3375 if (!caller && !(pconn = conn_by_user_prefix(arg[0], &result))) {
3376 cmd_reply_no_such_conn(CMD_OBSERVE, caller, arg[0], result);
3377 goto end;
3378 } else if (caller
3379 && !(pplayer = player_by_name_prefix(arg[0], &result))) {
3380 cmd_reply_no_such_player(CMD_OBSERVE, caller, arg[0], result);
3381 goto end;
3382 }
3383 }
3384
3385 /* get connection name then player name */
3386 if (ntokens == 2) {
3387 if (!(pconn = conn_by_user_prefix(arg[0], &result))) {
3388 cmd_reply_no_such_conn(CMD_OBSERVE, caller, arg[0], result);
3389 goto end;
3390 }
3391 if (!(pplayer = player_by_name_prefix(arg[1], &result))) {
3392 cmd_reply_no_such_player(CMD_OBSERVE, caller, arg[1], result);
3393 goto end;
3394 }
3395 }
3396
3397 /* if we can't force other connections to observe, assign us to be pconn. */
3398 if (!pconn) {
3399 pconn = caller;
3400 }
3401
3402 /* if we have no pplayer, it means that we want to be a global observer */
3403
3404 /******** PART II: do the observing ********/
3405
3406 /* check allowtake for permission */
3407 if (!is_allowed_to_take(caller, pconn, pplayer, TRUE, msg, sizeof(msg))) {
3408 cmd_reply(CMD_OBSERVE, caller, C_FAIL, "%s", msg);
3409 goto end;
3410 }
3411
3412 /* observing your own player (during pregame) makes no sense. */
3413 if (NULL != pplayer
3414 && pplayer == pconn->playing
3415 && !pconn->observer
3416 && is_newgame
3417 && !pplayer->was_created) {
3418 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3419 _("%s already controls %s. Using 'observe' would remove %s"),
3420 pconn->username,
3421 player_name(pplayer),
3422 player_name(pplayer));
3423 goto end;
3424 }
3425
3426 /* attempting to observe a player you're already observing should fail. */
3427 if (pplayer == pconn->playing && pconn->observer) {
3428 if (pplayer) {
3429 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3430 _("%s is already observing %s."),
3431 pconn->username,
3432 player_name(pplayer));
3433 } else {
3434 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3435 _("%s is already observing."),
3436 pconn->username);
3437 }
3438 goto end;
3439 }
3440
3441 res = TRUE; /* all tests passed */
3442 if (check) {
3443 goto end;
3444 }
3445
3446 /* if the connection is already attached to a player,
3447 * unattach and cleanup old player (rename, remove, etc) */
3448 if (TRUE) {
3449 char name[MAX_LEN_NAME];
3450
3451 if (pplayer) {
3452 /* if pconn->playing is removed, we'll lose pplayer */
3453 sz_strlcpy(name, player_name(pplayer));
3454 }
3455
3457
3458 if (pplayer) {
3459 /* find pplayer again, the pointer might have been changed */
3460 pplayer = player_by_name(name);
3461 }
3462 }
3463
3464 /* attach pconn to new player as an observer or as global observer */
3465 if ((res = connection_attach(pconn, pplayer, TRUE))) {
3466 if (pplayer) {
3467 cmd_reply(CMD_OBSERVE, caller, C_OK, _("%s now observes %s"),
3468 pconn->username,
3469 player_name(pplayer));
3470 } else {
3471 cmd_reply(CMD_OBSERVE, caller, C_OK, _("%s now observes"),
3472 pconn->username);
3473 }
3474 }
3475
3476 end:;
3477 /* free our args */
3478 for (i = 0; i < ntokens; i++) {
3479 free(arg[i]);
3480 }
3481 return res;
3482}
3483
3484/**********************************************************************/
3493static bool take_command(struct connection *caller, char *str, bool check)
3494{
3495 int i = 0, ntokens = 0;
3496 char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
3497 bool is_newgame = !game_was_started();
3499 struct connection *pconn = caller;
3500 struct player *pplayer = NULL;
3501 bool res = FALSE;
3502
3503 /******** PART I: fill pconn and pplayer ********/
3504
3505 sz_strlcpy(buf, str);
3507
3508 /* check syntax */
3509 if (!caller && ntokens != 2) {
3510 cmd_reply(CMD_TAKE, caller, C_SYNTAX, _("Usage:\n%s"),
3512 goto end;
3513 }
3514
3515 if (caller && caller->access_level != ALLOW_HACK && ntokens != 1) {
3516 cmd_reply(CMD_TAKE, caller, C_SYNTAX,
3517 _("Only the player name form is allowed."));
3518 goto end;
3519 }
3520
3521 if (ntokens == 0) {
3522 cmd_reply(CMD_TAKE, caller, C_SYNTAX, _("Usage:\n%s"),
3524 goto end;
3525 }
3526
3527 if (ntokens == 2) {
3528 if (!(pconn = conn_by_user_prefix(arg[i], &match_result))) {
3530 goto end;
3531 }
3532 i++; /* found a conn, now reference the second argument */
3533 }
3534
3535 if (strcmp(arg[i], "-") == 0) {
3536 if (!is_newgame) {
3537 cmd_reply(CMD_TAKE, caller, C_FAIL,
3538 _("You cannot issue \"/take -\" when "
3539 "the game has already started."));
3540 goto end;
3541 }
3542
3543 /* Find first uncontrolled player. This will return NULL if there is
3544 * no free players at the moment. Later call to
3545 * connection_attach() will create new player for such NULL
3546 * cases. */
3547 pplayer = find_uncontrolled_player();
3548 if (pplayer) {
3549 /* Make it human! */
3550 set_as_human(pplayer);
3551 }
3552 } else if (!(pplayer = player_by_name_prefix(arg[i], &match_result))) {
3554 goto end;
3555 }
3556
3557 /******** PART II: do the attaching ********/
3558
3559 /* Take not possible if the player is involved in a delegation (either
3560 * it's being controlled, or it's been put aside by the delegate). */
3561 if (player_delegation_active(pplayer)) {
3562 cmd_reply(CMD_TAKE, caller, C_FAIL, _("A delegation is active for player "
3563 "'%s'. /take not possible."),
3564 player_name(pplayer));
3565 goto end;
3566 }
3567
3568 /* check allowtake for permission */
3569 if (!is_allowed_to_take(caller, pconn, pplayer, FALSE, msg, sizeof(msg))) {
3570 cmd_reply(CMD_TAKE, caller, C_FAIL, "%s", msg);
3571 goto end;
3572 }
3573
3574 /* taking your own player makes no sense. */
3575 if ((NULL != pplayer && !pconn->observer && pplayer == pconn->playing)
3576 || (NULL == pplayer && !pconn->observer && NULL != pconn->playing)) {
3577 cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s already controls %s."),
3578 pconn->username,
3579 player_name(pconn->playing));
3580 goto end;
3581 }
3582
3583 /* Make sure there is free player slot if there is need to
3584 * create new player. This is necessary for previously
3585 * detached connections only. Others can reuse the slot
3586 * they first release. */
3587 if (!pplayer && !pconn->playing
3589 || normal_player_count() >= server.playable_nations)) {
3590 cmd_reply(CMD_TAKE, caller, C_FAIL,
3591 _("There is no free player slot for %s."),
3592 pconn->username);
3593 goto end;
3594 }
3596
3597 res = TRUE;
3598 if (check) {
3599 goto end;
3600 }
3601
3602 /* If the player is controlled by another user, forcibly detach
3603 * the user. */
3604 if (pplayer && pplayer->is_connected) {
3605 if (NULL == caller) {
3607 _("Reassigned nation to %s by server console."),
3608 pconn->username);
3609 } else {
3611 _("Reassigned nation to %s by %s."),
3612 pconn->username,
3613 caller->username);
3614 }
3615
3616 /* We are reassigning this nation, so we need to detach the current
3617 * user to set a new one. */
3619 if (!aconn->observer) {
3621 }
3623 }
3624
3625 /* if the connection is already attached to another player,
3626 * unattach and cleanup old player (rename, remove, etc)
3627 * We may have been observing the player we now want to take */
3628 if (NULL != pconn->playing || pconn->observer) {
3629 char name[MAX_LEN_NAME];
3630
3631 if (pplayer) {
3632 /* if pconn->playing is removed, we'll lose pplayer */
3633 sz_strlcpy(name, player_name(pplayer));
3634 }
3635
3637
3638 if (pplayer) {
3639 /* find pplayer again; the pointer might have been changed */
3640 pplayer = player_by_name(name);
3641 }
3642 }
3643
3644 /* Now attach to new player */
3645 if ((res = connection_attach(pconn, pplayer, FALSE))) {
3646 /* Successfully attached */
3647 pplayer = pconn->playing; /* In case pplayer was NULL. */
3648
3649 /* inform about the status before changes */
3650 cmd_reply(CMD_TAKE, caller, C_OK, _("%s now controls %s (%s, %s)."),
3651 pconn->username,
3652 player_name(pplayer),
3653 is_barbarian(pplayer)
3654 ? _("Barbarian")
3655 : is_ai(pplayer)
3656 ? _("AI")
3657 : _("Human"),
3658 pplayer->is_alive
3659 ? _("Alive")
3660 : _("Dead"));
3661 } else {
3662 cmd_reply(CMD_TAKE, caller, C_FAIL,
3663 _("%s failed to attach to any player."),
3664 pconn->username);
3665 }
3666
3667 end:;
3668 /* free our args */
3669 for (i = 0; i < ntokens; i++) {
3670 free(arg[i]);
3671 }
3672 return res;
3673}
3674
3675/**********************************************************************/
3682static bool detach_command(struct connection *caller, char *str, bool check)
3683{
3684 int i = 0, ntokens = 0;
3685 char buf[MAX_LEN_CONSOLE_LINE], *arg[1];
3687 struct connection *pconn = NULL;
3688 struct player *pplayer = NULL;
3689 bool res = FALSE;
3690
3691 sz_strlcpy(buf, str);
3693
3694 if (!caller && ntokens == 0) {
3695 cmd_reply(CMD_DETACH, caller, C_SYNTAX, _("Usage:\n%s"),
3697 goto end;
3698 }
3699
3700 /* match the connection if the argument was given */
3701 if (ntokens == 1
3702 && !(pconn = conn_by_user_prefix(arg[0], &match_result))) {
3704 goto end;
3705 }
3706
3707 /* if no argument is given, the caller wants to detach themself */
3708 if (!pconn) {
3709 pconn = caller;
3710 }
3711
3712 /* if pconn and caller are not the same, only continue
3713 * if we're console, or we have ALLOW_HACK */
3714 if (pconn != caller && caller && caller->access_level != ALLOW_HACK) {
3715 cmd_reply(CMD_DETACH, caller, C_FAIL,
3716 _("You can not detach other users."));
3717 goto end;
3718 }
3719
3720 pplayer = pconn->playing;
3721
3722 /* must have someone to detach from... */
3723 if (!pplayer && !pconn->observer) {
3724 cmd_reply(CMD_DETACH, caller, C_FAIL,
3725 _("%s is not attached to any player."), pconn->username);
3726 goto end;
3727 }
3728
3729 res = TRUE;
3730 if (check) {
3731 goto end;
3732 }
3733
3734 if (pplayer) {
3735 cmd_reply(CMD_DETACH, caller, C_OK, _("%s detaching from %s"),
3736 pconn->username, player_name(pplayer));
3737 } else {
3738 cmd_reply(CMD_DETACH, caller, C_OK, _("%s no longer observing."),
3739 pconn->username);
3740 }
3741
3742 /* Actually do the detaching. */
3744
3745 /* The user explicitly wanted to detach, so if a player is marked for
3746 * them, reset its username. */
3748 if (!fc_strncmp(aplayer->username, pconn->username, MAX_LEN_NAME)) {
3749 sz_strlcpy(aplayer->username, _(ANON_USER_NAME));
3750 aplayer->unassigned_user = TRUE;
3752 }
3754
3756
3757 end:
3759
3760 /* free our args */
3761 for (i = 0; i < ntokens; i++) {
3762 free(arg[i]);
3763 }
3764 return res;
3765}
3766
3767/**********************************************************************/
3788bool load_command(struct connection *caller, const char *filename, bool check,
3789 bool cmdline_load)
3790{
3791 struct timer *loadtimer, *uloadtimer;
3792 struct section_file *file;
3793 char arg[MAX_LEN_PATH];
3795
3796 if (!filename || filename[0] == '\0') {
3797 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Usage:\n%s"),
3799 return FALSE;
3800 }
3801 if (S_S_INITIAL != server_state()) {
3802 cmd_reply(CMD_LOAD, caller, C_FAIL,
3803 _("Cannot load a game while another is running."));
3804 return FALSE;
3805 }
3806 if (!is_safe_filename(filename) && is_restricted(caller)) {
3807 cmd_reply(CMD_LOAD, caller, C_FAIL,
3808 _("Name \"%s\" disallowed for security reasons."),
3809 filename);
3810 return FALSE;
3811 }
3812
3813 {
3814 /* It is a normal savegame or maybe a scenario */
3815 char testfile[MAX_LEN_PATH];
3816 const struct strvec *paths[] = {
3818 };
3819 const char *exts[] = {
3820 "sav", "gz", "bz2", "xz", "sav.gz", "sav.bz2", "sav.xz", "sav.zst", NULL
3821 };
3822 const char **ext, *found = NULL;
3823 const struct strvec **path;
3824
3825 if (cmdline_load) {
3826 /* Allow plain names being loaded with '--file' option, but not otherwise
3827 * (no loading of arbitrary files by unauthorized users)
3828 * Iterate through ALL paths to check for file with plain name before
3829 * looking any path with an extension, i.e., prefer plain name file
3830 * in later directory over file with extension in name in earlier
3831 * directory. */
3832 for (path = paths; !found && *path; path++) {
3833 found = fileinfoname(*path, filename);
3834 if (found != NULL) {
3835 sz_strlcpy(arg, found);
3836 }
3837 }
3838 }
3839
3840 for (path = paths; !found && *path; path++) {
3841 for (ext = exts; !found && *ext; ext++) {
3842 fc_snprintf(testfile, sizeof(testfile), "%s.%s", filename, *ext);
3843 found = fileinfoname(*path, testfile);
3844 if (found != NULL) {
3845 sz_strlcpy(arg, found);
3846 }
3847 }
3848 }
3849
3850 if (is_restricted(caller) && !found) {
3851 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Cannot find savegame or "
3852 "scenario with the name \"%s\"."), filename);
3853 return FALSE;
3854 }
3855
3856 if (!found) {
3857 sz_strlcpy(arg, filename);
3858 }
3859 }
3860
3861 /* attempt to parse the file */
3862
3863 if (!(file = secfile_load(arg, FALSE))) {
3864 log_error("Error loading savefile '%s': %s", arg, secfile_error());
3865 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Could not load savefile: %s"),
3866 arg);
3868 return FALSE;
3869 }
3870
3871 if (check) {
3872 return TRUE;
3873 }
3874
3875 /* Detach current players, before we blow them away. */
3878 if (pconn->playing != NULL) {
3880 } else if (pconn->observer) {
3883 }
3885
3887
3888 /* Now free all game data. */
3890
3891 /* Keep old ruleset value. Scenario file will either use the old value,
3892 * or to initialize new value itself. */
3894
3895 loadtimer = timer_new(TIMER_CPU, TIMER_ACTIVE, "load cpu");
3899
3901
3902 savegame_load(file);
3904 secfile_destroy(file);
3905
3906 log_verbose("Load time: %g seconds (%g apparent)",
3910
3911 sanity_check();
3912
3913 log_verbose("load_command() does send_rulesets()");
3921
3922 /* Send information about the new players. */
3925
3926 /* Everything seemed to load ok; spread the good news. */
3928
3929 /* Attach connections to players. Currently, this applies only
3930 * to connections that have the same username as a player. */
3932 players_iterate(pplayer) {
3933 if (strcmp(pconn->username, pplayer->username) == 0) {
3934 connection_attach(pconn, pplayer, FALSE);
3935 break;
3936 }
3939
3940 /* Reattach global observers. */
3942 if (NULL == pconn->playing) {
3943 /* May have been assigned to a player before. */
3945 }
3948
3950
3952 players_iterate(pplayer) {
3954
3956 pack.gained = achievement_player_has(pach, pplayer);
3957 pack.first = (pach->first == pplayer);
3958
3959 lsend_packet_achievement_info(pplayer->connections, &pack);
3962
3963 return TRUE;
3964}
3965
3966/**********************************************************************/
3975bool set_rulesetdir(struct connection *caller, const char *str, bool check,
3976 int read_recursion)
3977{
3978 char filename[512];
3979 const char *pfilename;
3980
3981 if (NULL == str || '\0' == str[0]) {
3983 _("You must provide a ruleset name. Use \"/show ruleset\" to "
3984 "see what is the current ruleset."));
3985 return FALSE;
3986 }
3987
3988 if (srvarg.ruleset != NULL && is_restricted(caller)) {
3990 _("Changing ruleset not allowed. It was locked from the commandline."));
3991
3992 return FALSE;
3993 }
3994
3995 if (game_was_started() || !map_is_empty()) {
3997 _("This setting can't be modified after the game has started."));
3999 && !game_was_started()) {
4001 /* TRANS: scenario name */
4002 _("The ruleset of \"%s\" can be changed by switching to a"
4003 " compatible ruleset before loading it."),
4005 }
4006 return FALSE;
4007 }
4008
4009 if (strcmp(str, game.server.rulesetdir) == 0) {
4011 _("Ruleset directory is already \"%s\""), str);
4012 return FALSE;
4013 }
4014
4015 if (is_restricted(caller)
4016 && (!is_safe_filename(str) || strchr(str, '.'))) {
4018 _("Name \"%s\" disallowed for security reasons."),
4019 str);
4020 return FALSE;
4021 }
4022
4023 fc_snprintf(filename, sizeof(filename), "%s", str);
4024 pfilename = fileinfoname(get_data_dirs(), filename);
4025 if (!pfilename) {
4027 _("Ruleset directory \"%s\" not found"), str);
4028 return FALSE;
4029 }
4030
4031 if (!check) {
4032 bool success = TRUE;
4033 char old[512];
4034
4036 log_verbose("set_rulesetdir() does load_rulesets() with \"%s\"", str);
4038
4039 /* load the ruleset (and game settings defined in the ruleset) */
4041 if (!load_rulesets(old, NULL, FALSE, NULL, TRUE, FALSE, TRUE)) {
4042 success = FALSE;
4043
4044 /* While loading of the requested ruleset failed, we might
4045 * have changed ruleset from third one to default. Handle
4046 * rest of the ruleset changing accordingly. */
4047 }
4048
4049 if (game.est_connections) {
4050 /* Now that the rulesets are loaded we immediately send updates to any
4051 * connected clients. */
4053 }
4054 /* show ruleset summary and list changed values */
4057
4058 if (success) {
4059 cmd_reply(CMD_RULESETDIR, caller, C_OK,
4060 _("Ruleset directory set to \"%s\""), str);
4061 } else {
4063 _("Failed loading rulesets from directory \"%s\", using \"%s\""),
4065 }
4066
4067 return success;
4068 }
4069
4070 return TRUE;
4071}
4072
4073/**********************************************************************/
4076static bool ignore_command(struct connection *caller, char *str, bool check)
4077{
4078 char buf[128];
4079 struct conn_pattern *ppattern;
4080
4081 if (NULL == caller) {
4082 cmd_reply(CMD_IGNORE, caller, C_FAIL,
4083 _("That would be rather silly, since you are not a player."));
4084 return FALSE;
4085 }
4086
4088 if (NULL == ppattern) {
4089 cmd_reply(CMD_IGNORE, caller, C_SYNTAX,
4090 _("%s. Try /help ignore"), buf);
4091 return FALSE;
4092 }
4093
4094 if (check) {
4096 return TRUE;
4097 }
4098
4102 _("Added pattern %s as entry %d to your ignore list."),
4104
4105 return TRUE;
4106}
4107
4108/**********************************************************************/
4111static bool unignore_command(struct connection *caller,
4112 char *str, bool check)
4113{
4114 char buf[128], *c;
4115 int first, last, n;
4116
4117 if (!caller) {
4118 cmd_reply(CMD_IGNORE, caller, C_FAIL,
4119 _("That would be rather silly, since you are not a player."));
4120 return FALSE;
4121 }
4122
4123 sz_strlcpy(buf, str);
4125
4127 if (n == 0) {
4128 cmd_reply(CMD_UNIGNORE, caller, C_FAIL, _("Your ignore list is empty."));
4129 return FALSE;
4130 }
4131
4132 /* Parse the range. */
4133 if ('\0' == buf[0]) {
4135 _("Missing range. Try /help unignore."));
4136 return FALSE;
4137 } else if ((c = strchr(buf, '-'))) {
4138 *c++ = '\0';
4139 if ('\0' == buf[0]) {
4140 first = 1;
4141 } else if (!str_to_int(buf, &first)) {
4142 *--c = '-';
4144 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4145 return FALSE;
4146 }
4147 if ('\0' == *c) {
4148 last = n;
4149 } else if (!str_to_int(c, &last)) {
4150 *--c = '-';
4152 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4153 return FALSE;
4154 }
4155 } else {
4156 if (!str_to_int(buf, &first)) {
4158 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4159 return FALSE;
4160 }
4161 last = first;
4162 }
4163
4164 if (!(1 <= first && first <= last && last <= n)) {
4165 if (first == last) {
4166 cmd_reply(CMD_UNIGNORE, caller, C_FAIL,
4167 _("Invalid entry number: %d."), first);
4168 } else {
4169 cmd_reply(CMD_UNIGNORE, caller, C_FAIL,
4170 _("Invalid range: %d to %d."), first, last);
4171 }
4172 return FALSE;
4173 }
4174
4175 if (check) {
4176 return TRUE;
4177 }
4178
4179 n = 1;
4181 if (first <= n) {
4184 _("Removed pattern %s (entry %d) from your ignore list."),
4185 buf, n);
4187 }
4188 n++;
4189 if (n > last) {
4190 break;
4191 }
4193
4194 return TRUE;
4195}
4196
4197/**********************************************************************/
4200static bool playercolor_command(struct connection *caller,
4201 char *str, bool check)
4202{
4204 struct player *pplayer;
4205 struct rgbcolor *prgbcolor = NULL;
4206 int ntokens = 0;
4207 char *token[2];
4208 bool ret = TRUE;
4209
4210 ntokens = get_tokens(str, token, 2, TOKEN_DELIMITERS);
4211
4212 if (ntokens != 2) {
4214 _("Two arguments needed. See '/help playercolor'."));
4215 ret = FALSE;
4216 goto cleanup;
4217 }
4218
4219 pplayer = player_by_name_prefix(token[0], &match_result);
4220
4221 if (!pplayer) {
4223 ret = FALSE;
4224 goto cleanup;
4225 }
4226
4227 {
4228 const char *reason;
4229 if (!player_color_changeable(pplayer, &reason)) {
4230 cmd_reply(CMD_PLAYERCOLOR, caller, C_FAIL, "%s", reason);
4231 ret = FALSE;
4232 goto cleanup;
4233 }
4234 }
4235
4236 if (0 == fc_strcasecmp(token[1], "reset")) {
4237 if (!game_was_started()) {
4238 prgbcolor = NULL;
4239 } else {
4241 _("Can only unset player color before game starts."));
4242 ret = FALSE;
4243 goto cleanup;
4244 }
4245 } else if (!rgbcolor_from_hex(&prgbcolor, token[1])) {
4247 _("Invalid player color definition. See '/help playercolor'."));
4248 ret = FALSE;
4249 goto cleanup;
4250 }
4251
4252 if (prgbcolor != NULL) {
4254 if (pother != pplayer && pother->rgb != NULL
4257 /* TRANS: "... [c0ffee] for Caesar ... to Hammurabi." */
4258 _("Warning: new color [%s] for %s is identical to %s."),
4261 }
4263 }
4264
4265 if (check) {
4266 goto cleanup;
4267 }
4268
4271 _("Color of player %s set to [%s]."), player_name(pplayer),
4272 player_color_ftstr(pplayer));
4273
4274 cleanup:
4275
4277 free_tokens(token, ntokens);
4278
4279 return ret;
4280}
4281
4282/**********************************************************************/
4285static bool playernation_command(struct connection *caller,
4286 char *str, bool check)
4287{
4289 struct player *pplayer;
4290 struct nation_type *pnation;
4291 struct nation_style *pstyle;
4292 bool is_male = FALSE;
4293 int ntokens = 0;
4294 char *token[5];
4295
4296 ntokens = get_tokens(str, token, 5, TOKEN_DELIMITERS);
4297
4298 if (ntokens == 0) {
4300 _("At least one argument needed. See '/help playernation'."));
4301 free_tokens(token, ntokens);
4302 return FALSE;
4303 }
4304
4305 if (game_was_started()) {
4307 _("Can only set player nation before game starts."));
4308 free_tokens(token, ntokens);
4309 return FALSE;
4310 }
4311
4312 pplayer = player_by_name_prefix(token[0], &match_result);
4313 if (!pplayer) {
4315 free_tokens(token, ntokens);
4316 return FALSE;
4317 }
4318
4319 if (ntokens == 1) {
4320 if (!check) {
4322
4324 _("Nation of player %s reset."), player_name(pplayer));
4326 }
4327 } else {
4328 pnation = nation_by_rule_name(token[1]);
4329 if (pnation == NO_NATION_SELECTED) {
4331 _("Unrecognized nation: %s."), token[1]);
4332 free_tokens(token, ntokens);
4333 return FALSE;
4334 }
4335
4336 if (!client_can_pick_nation(pnation)) {
4338 _("%s nation is not available for user selection."),
4339 token[1]);
4340 free_tokens(token, ntokens);
4341 return FALSE;
4342 }
4343
4344 if (pnation->player && pnation->player != pplayer) {
4346 _("%s nation is already in use."), token[1]);
4347 free_tokens(token, ntokens);
4348 return FALSE;
4349 }
4350
4351 if (ntokens < 3) {
4353 /* TRANS: Nation resetting form of /playernation does not require sex */
4354 _("Leader sex must be given when setting nation."));
4355 free_tokens(token, ntokens);
4356 return FALSE;
4357 }
4358
4359 if (!strcmp(token[2], "0")) {
4360 is_male = FALSE;
4361 } else if (!strcmp(token[2], "1")) {
4362 is_male = TRUE;
4363 } else {
4365 _("Unrecognized gender: %s, expecting 1 or 0."), token[2]);
4366 free_tokens(token, ntokens);
4367 return FALSE;
4368 }
4369
4370 if (ntokens > 4) {
4371 pstyle = style_by_rule_name(token[4]);
4372 if (!pstyle) {
4374 _("Unrecognized style: %s."), token[4]);
4375 free_tokens(token, ntokens);
4376 return FALSE;
4377 }
4378 } else {
4379 pstyle = style_of_nation(pnation);
4380 }
4381
4382 if (!check) {
4383 char error_buf[256];
4384
4385 player_set_nation(pplayer, pnation);
4386 pplayer->style = pstyle;
4387 pplayer->is_male = is_male;
4388
4389 if (ntokens > 3) {
4390 if (!server_player_set_name_full(caller, pplayer, pnation, token[3],
4391 error_buf, sizeof(error_buf))) {
4393 }
4394 } else {
4395 server_player_set_name(pplayer, token[0]);
4396 }
4398 _("Nation of player %s set to [%s]."), player_name(pplayer),
4399 nation_rule_name(pnation));
4401 }
4402 }
4403
4404 free_tokens(token, ntokens);
4405
4406 return TRUE;
4407}
4408
4409/**************************************************************************
4410 Handle quit command
4411**************************************************************************/
4412static bool quit_game(struct connection *caller, bool check)
4413{
4414 if (!check) {
4415 cmd_reply(CMD_QUIT, caller, C_OK, _("Goodbye."));
4416 server_quit();
4417 }
4418
4419 return TRUE;
4420}
4421
4422/**********************************************************************/
4426bool handle_stdin_input(struct connection *caller, char *str)
4427{
4428 return handle_stdin_input_real(caller, str, FALSE, 0);
4429}
4430
4431/**********************************************************************/
4434bool handle_stdin_input_free(struct connection *caller, char *str)
4435{
4436 bool ret = handle_stdin_input_real(caller, str, FALSE, 0);
4437
4438 /* Since handle_stdin_input_real() returned,
4439 * we can be sure this was not freed in atexit(). */
4440 free(str);
4441
4442 return ret;
4443}
4444
4445/**********************************************************************/
4453static bool handle_stdin_input_real(struct connection *caller, char *str,
4454 bool check, int read_recursion)
4455{
4458 char *cptr_s, *cptr_d;
4459 enum command_id cmd;
4460 enum cmdlevel level;
4461
4462 /* Remove leading and trailing spaces, and server command prefix. */
4464 if ('\0' == *cptr_s || '#' == *cptr_s) {
4465 /* This appear to be a comment or blank line. */
4466 return FALSE;
4467 }
4468
4469 if (SERVER_COMMAND_PREFIX == *cptr_s) {
4470 /* Commands may be prefixed with SERVER_COMMAND_PREFIX, even when
4471 * given on the server command line. */
4472 cptr_s++;
4474 if ('\0' == *cptr_s) {
4475 /* This appear to be a blank line. */
4476 return FALSE;
4477 }
4478 }
4480
4481 /* notify to the server console */
4482 if (!check && caller) {
4483 con_write(C_COMMENT, "%s: '%s'", caller->username, str);
4484 }
4485
4486 /* if the caller may not use any commands at all, don't waste any time */
4487 if (may_use_nothing(caller)) {
4488 cmd_reply(CMD_HELP, caller, C_FAIL,
4489 _("Sorry, you are not allowed to use server commands."));
4490 return FALSE;
4491 }
4492
4493 /* copy the full command, in case we need it for voting purposes. */
4495
4496 /*
4497 * cptr_s points now to the beginning of the real command. It has
4498 * skipped leading whitespace, the SERVER_COMMAND_PREFIX and any
4499 * other non-alphanumeric characters.
4500 */
4501 for (cptr_d = command; *cptr_s != '\0' && fc_isalnum(*cptr_s)
4502 && cptr_d < command + sizeof(command) - 1; cptr_s++, cptr_d++) {
4503 *cptr_d = *cptr_s;
4504 }
4505 *cptr_d = '\0';
4506
4507 /* cptr_s now contains the arguments. */
4509
4510 cmd = command_named(command, FALSE);
4511 if (cmd == CMD_AMBIGUOUS) {
4512 cmd = command_named(command, TRUE);
4513 cmd_reply(cmd, caller, C_SYNTAX,
4514 _("Warning: '%s' interpreted as '%s', but it is ambiguous."
4515 " Try '%shelp'."),
4516 command, command_name_by_number(cmd), caller?"/":"");
4517 } else if (cmd == CMD_UNRECOGNIZED) {
4518 cmd_reply(cmd, caller, C_SYNTAX, _("Unknown command '%s%s'. "
4519 " Try '%shelp'."),
4520 caller ? "/" : "", command, caller ? "/" : "");
4521 return FALSE;
4522 }
4523
4525
4526 if (conn_can_vote(caller, NULL) && level == ALLOW_CTRL
4527 && conn_get_access(caller) == ALLOW_BASIC && !check
4528 && !vote_would_pass_immediately(caller, cmd)) {
4529 struct vote *vote;
4530 bool caller_had_vote = (NULL != get_vote_by_caller(caller));
4531
4532 /* Check if the vote command would succeed. If we already have a vote
4533 * going, cancel it in favour of the new vote command. You can only
4534 * have one vote at a time. This is done by vote_new(). */
4536 read_recursion + 1)
4537 && (vote = vote_new(caller, arg, cmd))) {
4539 const struct player *teamplr;
4540 const char *what;
4541 struct ft_color color;
4542
4543 if (caller_had_vote) {
4544 cmd_reply(CMD_VOTE, caller, C_COMMENT,
4545 /* TRANS: "vote" as a process */
4546 _("Your new vote canceled your previous vote."));
4547 }
4548
4550
4551 if (vote_is_team_only(vote)) {
4552 /* TRANS: "vote" as a process */
4553 what = _("New teamvote");
4554 teamplr = conn_get_player(caller);
4556 } else {
4557 /* TRANS: "vote" as a process */
4558 what = _("New vote");
4559 teamplr = NULL;
4561 }
4563 /* TRANS: "[New vote|New teamvote] (number 3)
4564 * by fred: proposed change" */
4565 _("%s (number %d) by %s: %s"), what,
4566 vote->vote_no, caller->username, votedesc);
4567
4568 /* Vote on your own suggestion. */
4569 connection_vote(caller, vote, VOTE_YES);
4570 return TRUE;
4571
4572 } else {
4573 cmd_reply(CMD_VOTE, caller, C_FAIL,
4574 /* TRANS: "vote" as a process */
4575 _("Your new vote (\"%s\") was not "
4576 "legal or was not recognized."), full_command);
4577 return FALSE;
4578 }
4579 }
4580
4581 if (caller
4582 && !((check || vote_would_pass_immediately(caller, cmd))
4583 && conn_get_access(caller) >= ALLOW_BASIC
4584 && level == ALLOW_CTRL)
4585 && conn_get_access(caller) < level) {
4586 cmd_reply(cmd, caller, C_FAIL,
4587 _("You are not allowed to use this command."));
4588 return FALSE;
4589 }
4590
4591 if (!check) {
4592 struct conn_list *echo_list = NULL;
4594
4595 switch (command_echo(command_by_number(cmd))) {
4596 case CMD_ECHO_NONE:
4597 break;
4598 case CMD_ECHO_ADMINS:
4601 if (NULL == echo_list) {
4604 }
4606 }
4608 break;
4609 case CMD_ECHO_ALL:
4611 break;
4612 }
4613
4614 if (NULL != echo_list) {
4615 if (caller) {
4617 "%s: '%s %s'", caller->username, command, arg);
4618 } else {
4620 "%s: '%s %s'", _("(server prompt)"), command, arg);
4621 }
4622 if (echo_list_allocated) {
4624 }
4625 }
4626 }
4627
4628 switch (cmd) {
4629 case CMD_REMOVE:
4630 return remove_player_command(caller, arg, check);
4631 case CMD_SAVE:
4632 return save_command(caller, arg, check);
4633 case CMD_SCENSAVE:
4634 return scensave_command(caller, arg, check);
4635 case CMD_LOAD:
4636 return load_command(caller, arg, check, FALSE);
4637 case CMD_METAPATCHES:
4638 return metapatches_command(caller, arg, check);
4639 case CMD_METAMESSAGE:
4640 return metamessage_command(caller, arg, check);
4641 case CMD_METACONN:
4642 return metaconnection_command(caller, arg, check);
4643 case CMD_METASERVER:
4644 return metaserver_command(caller, arg, check);
4645 case CMD_HELP:
4646 return show_help(caller, arg);
4647 case CMD_SRVID:
4648 return show_serverid(caller, arg);
4649 case CMD_LIST:
4650 return show_list(caller, arg);
4651 case CMD_AITOGGLE:
4652 return toggle_ai_command(caller, arg, check);
4653 case CMD_TAKE:
4654 return take_command(caller, arg, check);
4655 case CMD_OBSERVE:
4656 return observe_command(caller, arg, check);
4657 case CMD_DETACH:
4658 return detach_command(caller, arg, check);
4659 case CMD_CREATE:
4660 return create_command(caller, arg, check);
4661 case CMD_AWAY:
4662 return away_command(caller, check);
4663 case CMD_RESTRICTED:
4664 case CMD_NOVICE:
4665 case CMD_EASY:
4666 case CMD_NORMAL:
4667 case CMD_HARD:
4668 case CMD_CHEATING:
4669#ifdef FREECIV_DEBUG
4670 case CMD_EXPERIMENTAL:
4671#endif
4672 return set_ai_level_named(caller, arg, command_name_by_number(cmd), check);
4673 case CMD_QUIT:
4674 return quit_game(caller, check);
4675 case CMD_CUT:
4676 return cut_client_connection(caller, arg, check);
4677 case CMD_SHOW:
4678 return show_command(caller, arg, check);
4679 case CMD_EXPLAIN:
4680 return explain_option(caller, arg, check);
4681 case CMD_DEBUG:
4682 return debug_command(caller, arg, check);
4683 case CMD_SET:
4684 return set_command(caller, arg, check);
4685 case CMD_TEAM:
4686 return team_command(caller, arg, check);
4687 case CMD_RULESETDIR:
4688 return set_rulesetdir(caller, arg, check, read_recursion);
4689 case CMD_WALL:
4690 return wall(arg, check);
4691 case CMD_CONNECTMSG:
4692 return connectmsg_command(caller, arg, check);
4693 case CMD_VOTE:
4694 return vote_command(caller, arg, check);
4695 case CMD_CANCELVOTE:
4696 return cancelvote_command(caller, arg, check);
4697 case CMD_READ_SCRIPT:
4698 return read_command(caller, arg, check, read_recursion);
4699 case CMD_WRITE_SCRIPT:
4700 return write_command(caller, arg, check);
4701 case CMD_RESET:
4702 return reset_command(caller, arg, check, read_recursion);
4703 case CMD_DEFAULT:
4704 return default_command(caller, arg, check);
4705 case CMD_LUA:
4706 return lua_command(caller, arg, check, read_recursion);
4707 case CMD_KICK:
4708 return kick_command(caller, arg, check);
4709 case CMD_DELEGATE:
4710 return delegate_command(caller, arg, check);
4711 case CMD_AICMD:
4712 return aicmd_command(caller, arg, check);
4713 case CMD_FCDB:
4714 return fcdb_command(caller, arg, check);
4715 case CMD_MAPIMG:
4716 return mapimg_command(caller, arg, check);
4717 case CMD_LOCK:
4718 return lock_command(caller, arg, check);
4719 case CMD_UNLOCK:
4720 return unlock_command(caller, arg, check);
4721 case CMD_RFCSTYLE: /* see console.h for an explanation */
4722 if (!check) {
4724 }
4725 return TRUE;
4726 case CMD_CMDLEVEL:
4727 return cmdlevel_command(caller, arg, check);
4728 case CMD_FIRSTLEVEL:
4729 return firstlevel_command(caller, check);
4730 case CMD_TIMEOUT:
4731 return timeout_command(caller, arg, check);
4732 case CMD_START_GAME:
4733 return start_command(caller, check, FALSE);
4734 case CMD_END_GAME:
4735 return end_command(caller, arg, check);
4736 case CMD_SURRENDER:
4737 return surrender_command(caller, arg, check);
4738 case CMD_IGNORE:
4739 return ignore_command(caller, arg, check);
4740 case CMD_UNIGNORE:
4741 return unignore_command(caller, arg, check);
4742 case CMD_PLAYERCOLOR:
4743 return playercolor_command(caller, arg, check);
4744 case CMD_PLAYERNATION:
4745 return playernation_command(caller, arg, check);
4746 case CMD_NUM:
4747 case CMD_UNRECOGNIZED:
4748 case CMD_AMBIGUOUS:
4749 break;
4750 }
4751 /* should NEVER happen! */
4752 log_error("Unknown command variant: %d.", cmd);
4753 return FALSE;
4754}
4755
4756/**********************************************************************/
4759static bool end_command(struct connection *caller, char *str, bool check)
4760{
4761 if (S_S_RUNNING == server_state()) {
4762 if (check) {
4763 return TRUE;
4764 }
4766 _("Game is over."));
4769 cmd_reply(CMD_END_GAME, caller, C_OK,
4770 _("Ending the game. The server will restart once all clients "
4771 "have disconnected."));
4772 return TRUE;
4773 } else {
4774 cmd_reply(CMD_END_GAME, caller, C_FAIL,
4775 _("Cannot end the game: no game running."));
4776 return FALSE;
4777 }
4778}
4779
4780/**********************************************************************/
4784static bool surrender_command(struct connection *caller, char *str, bool check)
4785{
4786 struct player *pplayer;
4787
4788 if (caller == NULL || !conn_controls_player(caller)) {
4790 _("You are not allowed to use this command."));
4791 return FALSE;
4792 }
4793
4794 if (S_S_RUNNING != server_state()) {
4795 cmd_reply(CMD_SURRENDER, caller, C_FAIL, _("You cannot surrender now."));
4796 return FALSE;
4797 }
4798
4799 pplayer = conn_get_player(caller);
4800 if (player_status_check(pplayer, PSTATUS_SURRENDER)) {
4802 _("You have already conceded the game."));
4803 return FALSE;
4804 }
4805
4806 if (check) {
4807 return TRUE;
4808 }
4809
4811 _("%s has conceded the game and can no longer win."),
4812 player_name(pplayer));
4814 return TRUE;
4815}
4816
4817/* Define the possible arguments to the reset command */
4818#define SPECENUM_NAME reset_args
4819#define SPECENUM_VALUE0 RESET_GAME
4820#define SPECENUM_VALUE0NAME "game"
4821#define SPECENUM_VALUE1 RESET_RULESET
4822#define SPECENUM_VALUE1NAME "ruleset"
4823#define SPECENUM_VALUE2 RESET_SCRIPT
4824#define SPECENUM_VALUE2NAME "script"
4825#define SPECENUM_VALUE3 RESET_DEFAULT
4826#define SPECENUM_VALUE3NAME "default"
4827#include "specenum_gen.h"
4828
4829/**********************************************************************/
4832static const char *reset_accessor(int i)
4833{
4834 i = CLIP(0, i, reset_args_max());
4835 return reset_args_name((enum reset_args) i);
4836}
4837
4838/**********************************************************************/
4842static bool reset_command(struct connection *caller, char *arg, bool check,
4843 int read_recursion)
4844{
4845 enum m_pre_result result;
4846 int ind;
4847
4848 /* match the argument */
4849 result = match_prefix(reset_accessor, reset_args_max() + 1, 0,
4850 fc_strncasecmp, NULL, arg, &ind);
4851
4852 switch (result) {
4853 case M_PRE_EXACT:
4854 case M_PRE_ONLY:
4855 /* we have a match */
4856 break;
4857 case M_PRE_AMBIGUOUS:
4858 case M_PRE_EMPTY:
4859 /* use 'ruleset' [1] if the game was not started; else use 'game' [2] */
4861 cmd_reply(CMD_RESET, caller, C_WARNING,
4862 _("Guessing argument 'ruleset'."));
4864 } else {
4865 cmd_reply(CMD_RESET, caller, C_WARNING,
4866 _("Guessing argument 'game'."));
4867 ind = RESET_GAME;
4868 }
4869 break;
4870 case M_PRE_LONG:
4871 case M_PRE_FAIL:
4872 case M_PRE_LAST:
4873 cmd_reply(CMD_RESET, caller, C_FAIL,
4874 _("The valid arguments are: 'game', 'ruleset', 'script' "
4875 "or 'default'."));
4876 return FALSE;
4877 break;
4878 }
4879
4880 if (check) {
4881 return TRUE;
4882 }
4883
4884 switch (ind) {
4885 case RESET_GAME:
4886 if (!game.info.is_new_game) {
4887 if (settings_game_reset()) {
4888 cmd_reply(CMD_RESET, caller, C_OK,
4889 _("Reset all settings to the values at the game start."));
4890 } else {
4891 cmd_reply(CMD_RESET, caller, C_FAIL,
4892 _("No saved settings from the game start available."));
4893 return FALSE;
4894 }
4895 } else {
4896 cmd_reply(CMD_RESET, caller, C_FAIL, _("No game started..."));
4897 return FALSE;
4898 }
4899 break;
4900
4901 case RESET_RULESET:
4902 /* Restore game settings saved in game.ruleset. */
4904 cmd_reply(CMD_RESET, caller, C_OK,
4905 _("Reset all settings to ruleset values."));
4906 } else {
4907 cmd_reply(CMD_RESET, caller, C_FAIL,
4908 _("Failed to reset settings to ruleset values."));
4909 }
4910 break;
4911
4912 case RESET_SCRIPT:
4913 cmd_reply(CMD_RESET, caller, C_OK,
4914 _("Reset all settings and rereading the server start "
4915 "script."));
4917 /* Load initial script */
4920 read_recursion + 1)) {
4921 if (NULL != caller) {
4922 cmd_reply(CMD_RESET, caller, C_FAIL,
4923 _("Could not read script file '%s'."),
4925 }
4926 return FALSE;
4927 }
4928 break;
4929
4930 case RESET_DEFAULT:
4931 cmd_reply(CMD_RESET, caller, C_OK,
4932 _("Reset all settings to default values."));
4934 break;
4935 }
4936
4938 cmd_reply(CMD_RESET, caller, C_OK, _("Settings re-initialized."));
4939
4940 /* show ruleset summary and list changed values */
4942
4943 return TRUE;
4944}
4945
4946/**********************************************************************/
4949static bool default_command(struct connection *caller, char *arg, bool check)
4950{
4951 struct setting *pset;
4952 char reject_msg[256] = "";
4953
4954 pset = validate_setting_arg(CMD_DEFAULT, caller, arg);
4955
4956 if (!pset) {
4957 /* Reason already reported. */
4958 return FALSE;
4959 }
4960
4961 if (!setting_is_changeable(pset, caller, reject_msg, sizeof(reject_msg))) {
4962 cmd_reply(CMD_DEFAULT, caller, C_FAIL, "%s", reject_msg);
4963
4964 return FALSE;
4965 }
4966
4967 if (!check) {
4969 cmd_reply(CMD_DEFAULT, caller, C_OK,
4970 _("Option '%s' reset to default value, and will track any "
4971 "default changes."), arg);
4972 }
4973
4974 return TRUE;
4975}
4976
4977/* Define the possible arguments to the delegation command */
4978#define SPECENUM_NAME lua_args
4979#define SPECENUM_VALUE0 LUA_CMD
4980#define SPECENUM_VALUE0NAME "cmd"
4981#define SPECENUM_VALUE1 LUA_FILE
4982#define SPECENUM_VALUE1NAME "file"
4983#define SPECENUM_VALUE2 LUA_UNSAFE_CMD
4984#define SPECENUM_VALUE2NAME "unsafe-cmd"
4985#define SPECENUM_VALUE3 LUA_UNSAFE_FILE
4986#define SPECENUM_VALUE3NAME "unsafe-file"
4987#include "specenum_gen.h"
4988
4989/**********************************************************************/
4992static const char *lua_accessor(int i)
4993{
4994 i = CLIP(0, i, lua_args_max());
4995 return lua_args_name((enum lua_args) i);
4996}
4997
4998/**********************************************************************/
5001static bool lua_command(struct connection *caller, char *arg, bool check,
5002 int read_recursion)
5003{
5004 struct stat statbuf;
5005 const char extension[] = ".lua", *real_filename = NULL;
5006 char luafile[4096], tilde_filename[4096];
5007 char *tokens[1], *luaarg = NULL;
5008 int ntokens, ind;
5009 enum m_pre_result result;
5010 bool ret = FALSE;
5011
5013
5014 if (ntokens > 0) {
5015 /* match the argument */
5016 result = match_prefix(lua_accessor, lua_args_max() + 1, 0,
5017 fc_strncasecmp, NULL, tokens[0], &ind);
5018
5019 switch (result) {
5020 case M_PRE_EXACT:
5021 case M_PRE_ONLY:
5022 /* We have a match */
5023 luaarg = arg + strlen(lua_args_name(ind));
5025 break;
5026 case M_PRE_EMPTY:
5027 /* Nothing. */
5028 break;
5029 case M_PRE_AMBIGUOUS:
5030 case M_PRE_LONG:
5031 case M_PRE_FAIL:
5032 case M_PRE_LAST:
5033 /* Fall back to depreciated 'lua <script command>' syntax. */
5034 cmd_reply(CMD_LUA, caller, C_SYNTAX,
5035 _("Fall back to old syntax '%slua <script command>'."),
5036 caller ? "/" : "");
5037 ind = LUA_CMD;
5038 luaarg = arg;
5039 break;
5040 }
5041 }
5042
5043 if (luaarg == NULL) {
5044 cmd_reply(CMD_LUA, caller, C_FAIL,
5045 _("No lua command or lua script file. See '%shelp lua'."),
5046 caller ? "/" : "");
5047 ret = TRUE;
5048 goto cleanup;
5049 }
5050
5051 switch (ind) {
5052 case LUA_CMD:
5053 /* Nothing to check. */
5054 break;
5055 case LUA_UNSAFE_CMD:
5056 if (read_recursion > 0) {
5057 cmd_reply(CMD_LUA, caller, C_FAIL,
5058 _("Unsafe Lua code can only be run by explicit command."));
5059 ret = FALSE;
5060 goto cleanup;
5061 } else if (is_restricted(caller)) {
5062 cmd_reply(CMD_LUA, caller, C_FAIL,
5063 _("You aren't allowed to run unsafe Lua code."));
5064 ret = FALSE;
5065 goto cleanup;
5066 }
5067 break;
5068 case LUA_UNSAFE_FILE:
5069 if (read_recursion > 0) {
5070 cmd_reply(CMD_LUA, caller, C_FAIL,
5071 _("Unsafe Lua code can only be run by explicit command."));
5072 ret = FALSE;
5073 goto cleanup;
5074 } else if (is_restricted(caller)) {
5075 cmd_reply(CMD_LUA, caller, C_FAIL,
5076 _("You aren't allowed to run unsafe Lua code."));
5077 ret = FALSE;
5078 goto cleanup;
5079 }
5080
5082 case LUA_FILE:
5083 /* Abuse real_filename to find if we already have a .lua extension. */
5085 strlen(luaarg));
5086 if (strcmp(real_filename, extension) != 0) {
5087 fc_snprintf(luafile, sizeof(luafile), "%s%s", luaarg, extension);
5088 } else {
5090 }
5091
5092 if (is_restricted(caller)) {
5093 if (!is_safe_filename(luafile)) {
5094 cmd_reply(CMD_LUA, caller, C_FAIL,
5095 _("Freeciv script '%s' disallowed for security reasons."),
5096 luafile);
5097 ret = FALSE;
5098 goto cleanup;
5099 }
5101 } else {
5103 }
5104
5106 if (!real_filename) {
5107 if (is_restricted(caller)) {
5108 cmd_reply(CMD_LUA, caller, C_FAIL,
5109 _("No Freeciv script found by the name '%s'."),
5111 ret = FALSE;
5112 goto cleanup;
5113 }
5114 /* File is outside data directories */
5116 }
5117 break;
5118 }
5119
5120 if (check) {
5121 ret = TRUE;
5122 goto cleanup;
5123 }
5124
5125 switch (ind) {
5126 case LUA_CMD:
5128 break;
5129 case LUA_UNSAFE_CMD:
5131 break;
5132 case LUA_FILE:
5133 cmd_reply(CMD_LUA, caller, C_COMMENT,
5134 _("Loading Freeciv script file '%s'."), real_filename);
5135
5137 && !fc_stat(real_filename, &statbuf)) {
5139 } else {
5140 cmd_reply(CMD_LUA, caller, C_FAIL,
5141 _("Cannot read Freeciv script '%s'."), real_filename);
5142 ret = FALSE;
5143 }
5144 break;
5145 case LUA_UNSAFE_FILE:
5146 cmd_reply(CMD_LUA, caller, C_COMMENT,
5147 _("Loading Freeciv script file '%s'."), real_filename);
5148
5150 && !fc_stat(real_filename, &statbuf)) {
5152 } else {
5153 cmd_reply(CMD_LUA, caller, C_FAIL,
5154 _("Cannot read Freeciv script '%s'."), real_filename);
5155 ret = FALSE;
5156 }
5157 break;
5158 }
5159
5160 cleanup:
5162 return ret;
5163}
5164
5165/* Define the possible arguments to the delegation command */
5166#define SPECENUM_NAME delegate_args
5167#define SPECENUM_VALUE0 DELEGATE_CANCEL
5168#define SPECENUM_VALUE0NAME "cancel"
5169#define SPECENUM_VALUE1 DELEGATE_RESTORE
5170#define SPECENUM_VALUE1NAME "restore"
5171#define SPECENUM_VALUE2 DELEGATE_SHOW
5172#define SPECENUM_VALUE2NAME "show"
5173#define SPECENUM_VALUE3 DELEGATE_TAKE
5174#define SPECENUM_VALUE3NAME "take"
5175#define SPECENUM_VALUE4 DELEGATE_TO
5176#define SPECENUM_VALUE4NAME "to"
5177#include "specenum_gen.h"
5178
5179/**********************************************************************/
5182static const char *delegate_accessor(int i)
5183{
5184 i = CLIP(0, i, delegate_args_max());
5185 return delegate_args_name((enum delegate_args) i);
5186}
5187
5188/**********************************************************************/
5191static bool delegate_command(struct connection *caller, char *arg,
5192 bool check)
5193{
5194 char *tokens[3];
5196 enum m_pre_result result;
5197 bool player_specified = FALSE; /* affects messages only */
5198 bool ret = FALSE;
5199 const char *username = NULL;
5200 struct player *dplayer = NULL;
5201
5202 if (!game_was_started()) {
5203 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Game not started - "
5204 "cannot delegate yet."));
5205 return FALSE;
5206 }
5207
5209
5210 if (ntokens > 0) {
5211 /* match the argument */
5213 fc_strncasecmp, NULL, tokens[0], &ind);
5214
5215 switch (result) {
5216 case M_PRE_EXACT:
5217 case M_PRE_ONLY:
5218 /* we have a match */
5219 break;
5220 case M_PRE_EMPTY:
5221 if (caller) {
5222 /* Use 'delegate show' as default. */
5224 }
5225 break;
5226 case M_PRE_AMBIGUOUS:
5227 case M_PRE_LONG:
5228 case M_PRE_FAIL:
5229 case M_PRE_LAST:
5231 break;
5232 }
5233 } else {
5234 if (caller) {
5235 /* Use 'delegate show' as default. */
5237 }
5238 }
5239
5241 char buf[256] = "";
5243
5247 const char *name = delegate_args_name(valid_args);
5248
5249 if (name != NULL) {
5250 cat_snprintf(buf, sizeof(buf), "'%s'", name);
5251 if (valid_args != delegate_args_max()) {
5252 cat_snprintf(buf, sizeof(buf), ", ");
5253 }
5254 }
5255 }
5256
5258 /* TRANS: do not translate the command 'delegate'. */
5259 _("Valid arguments for 'delegate' are: %s."), buf);
5260 ret = FALSE;
5261 goto cleanup;
5262 }
5263
5264 /* Get the data (player, username for delegation) and validate it. */
5265 switch (ind) {
5266 case DELEGATE_CANCEL:
5267 /* delegate cancel [player] */
5268 if (ntokens > 1) {
5269 if (!caller || conn_get_access(caller) >= ALLOW_ADMIN) {
5271 dplayer = player_by_name_prefix(tokens[1], &result);
5272 if (!dplayer) {
5273 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5274 ret = FALSE;
5275 goto cleanup;
5276 }
5277 } else {
5279 _("Command level '%s' or greater needed to modify "
5280 "others' delegations."), cmdlevel_name(ALLOW_ADMIN));
5281 ret = FALSE;
5282 goto cleanup;
5283 }
5284 } else {
5285 dplayer = conn_get_player(caller);
5286 if (!dplayer) {
5288 _("Please specify a player for whom delegation should "
5289 "be canceled."));
5290 ret = FALSE;
5291 goto cleanup;
5292 }
5293 }
5294 break;
5295 case DELEGATE_RESTORE:
5296 /* delegate restore */
5297 if (!caller) {
5298 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5299 _("You can't switch players from the console."));
5300 ret = FALSE;
5301 goto cleanup;
5302 }
5303 break;
5304 case DELEGATE_SHOW:
5305 /* delegate show [player] */
5306 if (ntokens > 1) {
5308 dplayer = player_by_name_prefix(tokens[1], &result);
5309 if (!dplayer) {
5310 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5311 ret = FALSE;
5312 goto cleanup;
5313 }
5314 } else {
5315 dplayer = conn_get_player(caller);
5316 if (!dplayer) {
5318 _("Please specify a player for whom the delegation should "
5319 "be shown."));
5320 ret = FALSE;
5321 goto cleanup;
5322 }
5323 }
5324 break;
5325 case DELEGATE_TAKE:
5326 /* delegate take <player> */
5327 if (!caller) {
5328 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5329 _("You can't switch players from the console."));
5330 ret = FALSE;
5331 goto cleanup;
5332 }
5333 if (ntokens > 1) {
5335 dplayer = player_by_name_prefix(tokens[1], &result);
5336 if (!dplayer) {
5337 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5338 ret = FALSE;
5339 goto cleanup;
5340 }
5341 } else {
5343 _("Please specify a player to take control of."));
5344 ret = FALSE;
5345 goto cleanup;
5346 }
5347 break;
5348 case DELEGATE_TO:
5349 break;
5350 }
5351 /* All checks done to this point will give pretty much the same result at
5352 * any time. Checks after this point are more likely to vary over time. */
5353 if (check) {
5354 ret = TRUE;
5355 goto cleanup;
5356 }
5357
5358 switch (ind) {
5359 case DELEGATE_TO:
5360 /* delegate to <username> [player] */
5361 if (ntokens > 1) {
5362 username = tokens[1];
5363 } else {
5365 _("Please specify a user to whom control is to be delegated."));
5366 ret = FALSE;
5367 break;
5368 }
5369 if (ntokens > 2) {
5371 dplayer = player_by_name_prefix(tokens[2], &result);
5372 if (!dplayer) {
5373 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[2], result);
5374 ret = FALSE;
5375 break;
5376 }
5377#ifndef HAVE_FCDB
5378 if (caller && conn_get_access(caller) < ALLOW_ADMIN) {
5379#else
5380 if (caller && conn_get_access(caller) < ALLOW_ADMIN
5381 && !(srvarg.fcdb_enabled
5382 && script_fcdb_call("user_delegate_to", caller, dplayer,
5383 username, &ret) && ret)) {
5384#endif
5386 _("Command level '%s' or greater or special permission "
5387 "needed to modify others' delegations."),
5389 ret = FALSE;
5390 break;
5391 }
5392 } else {
5393 dplayer = conn_controls_player(caller) ? conn_get_player(caller) : NULL;
5394 if (!dplayer) {
5395 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5396 _("You do not control a player."));
5397 ret = FALSE;
5398 break;
5399 }
5400 }
5401
5402 /* Delegate control of player to another user. */
5405
5406 /* Forbid delegation of players already controlled by a delegate, and
5407 * those 'put aside' by a delegate.
5408 * For the former, if player is already under active delegate control,
5409 * we wouldn't handle the revocation that would be necessary if their
5410 * delegation changed; and the authority granted to delegates does not
5411 * include the ability to sub-delegate.
5412 * For the latter, allowing control of the 'put aside' player to be
5413 * delegated would break the invariant that whenever a user is connected,
5414 * they are attached to 'their' player. */
5417 /* Attempting to change a 'put aside' player. Must be admin
5418 * or console. */
5420 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5421 _("Can't delegate control of '%s' belonging to %s while "
5422 "they are controlling another player."),
5424 } else if (player_specified) {
5425 /* Admin or console attempting to change a controlled player. */
5426 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5427 _("Can't change delegation of '%s' while controlled by "
5428 "delegate %s."), player_name(dplayer), dplayer->username);
5429 } else {
5430 /* Caller must be the delegate. Give more specific message.
5431 * (We don't know if they thought they were delegating their
5432 * original or delegated player, but we don't allow either.) */
5433 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5434 _("You can't delegate control while you are controlling "
5435 "a delegated player yourself."));
5436 }
5437 ret = FALSE;
5438 break;
5439 }
5440
5441 /* Forbid delegation to player's original owner
5442 * (from above test we know that dplayer->username is the original now) */
5443 if (fc_strcasecmp(dplayer->username, username) == 0) {
5444 if (player_specified) {
5445 /* Probably admin or console. */
5446 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5447 /* TRANS: don't translate 'delegate cancel' */
5448 _("%s already owns '%s', so cannot also be delegate. "
5449 "Use '%sdelegate cancel' to cancel an existing "
5450 "delegation."),
5451 username, player_name(dplayer), caller?"/":"");
5452 } else {
5453 /* Player not specified on command line, so they must have been trying
5454 * to delegate control to themself. Give more specific message. */
5455 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5456 /* TRANS: don't translate '/delegate cancel' */
5457 _("You can't delegate control to yourself. "
5458 "Use '/delegate cancel' to cancel an existing "
5459 "delegation."));
5460 }
5461 ret = FALSE;
5462 break;
5463 }
5464
5465 /* FIXME: if control was already delegated to someone else, that
5466 * delegation is implicitly canceled. Perhaps we should tell someone. */
5467
5469 cmd_reply(CMD_DELEGATE, caller, C_OK,
5470 _("Control of player '%s' delegated to user %s."),
5472 ret = TRUE;
5473 break;
5474
5475 case DELEGATE_SHOW:
5476 /* Show delegations. */
5478
5480 /* No delegation set. */
5482 _("No delegation defined for '%s'."),
5484 } else {
5486 _("Control of player '%s' delegated to user %s."),
5488 }
5489 ret = TRUE;
5490 break;
5491
5492 case DELEGATE_CANCEL:
5494 /* No delegation set. */
5495 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5496 _("No delegation defined for '%s'."),
5498 ret = FALSE;
5499 break;
5500 }
5501
5503 /* Delegation is currently in use. Forcibly break connection. */
5504 struct connection *pdelegate;
5505 /* (Can only happen if admin/console issues this command, as owner
5506 * will end use by their mere presence.) */
5511 /* Should never happen. Generic failure message. */
5512 log_error("Failed to restore %s's connection as %s during "
5513 "'delegate cancel'.", pdelegate->username,
5514 delegate_player_str(pdelegate->server.delegation.playing,
5515 pdelegate->server.delegation.observer));
5516 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5517 ret = FALSE;
5518 break;
5519 }
5521 _("Your delegated control of player '%s' was canceled."),
5523 }
5524
5526 cmd_reply(CMD_DELEGATE, caller, C_OK, _("Delegation of '%s' canceled."),
5528 ret = TRUE;
5529 break;
5530
5531 case DELEGATE_TAKE:
5532 /* Try to take another player. */
5534 fc_assert_ret_val(caller, FALSE);
5535
5536 if (caller->server.delegation.status) {
5537 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5538 /* TRANS: don't translate '/delegate restore'. */
5539 _("You are already controlling a delegated player. "
5540 "Use '/delegate restore' to relinquish control of your "
5541 "current player first."));
5542 ret = FALSE;
5543 break;
5544 }
5545
5546 /* Don't allow 'put aside' players to be delegated; the invariant is
5547 * that while the owning user is connected to the server, they are
5548 * in sole control of 'their' player. */
5549 if (conn_controls_player(caller)
5551 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5552 /* TRANS: don't translate '/delegate cancel'. */
5553 _("Can't take player while you have delegated control "
5554 "yourself. Use '/delegate cancel' to cancel your own "
5555 "delegation first."));
5556 ret = FALSE;
5557 break;
5558 }
5559
5560 /* Taking your own player makes no sense. */
5561 if (conn_controls_player(caller)
5562 && dplayer == conn_get_player(caller)) {
5563 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("You already control '%s'."),
5564 player_name(conn_get_player(caller)));
5565 ret = FALSE;
5566 break;
5567 }
5568
5571 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5572 _("Control of player '%s' has not been delegated to you."),
5574 ret = FALSE;
5575 break;
5576 }
5577
5578 /* If the player is controlled by another user, fail. */
5579 if (dplayer->is_connected) {
5580 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5581 _("Another user already controls player '%s'."),
5583 ret = FALSE;
5584 break;
5585 }
5586
5587 if (!connection_delegate_take(caller, dplayer)) {
5588 /* Should never happen. Generic failure message. */
5589 log_error("%s failed to take control of '%s' during 'delegate take'.",
5590 caller->username, player_name(dplayer));
5591 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5592 ret = FALSE;
5593 break;
5594 }
5595
5596 cmd_reply(CMD_DELEGATE, caller, C_OK,
5597 _("%s is now controlling player '%s'."), caller->username,
5598 player_name(conn_get_player(caller)));
5599 ret = TRUE;
5600 break;
5601
5602 case DELEGATE_RESTORE:
5603 /* Delegate user relinquishes control of delegated player, returning to
5604 * previous view (e.g. observer) if any. */
5605 fc_assert_ret_val(caller, FALSE);
5606
5607 if (!caller->server.delegation.status) {
5608 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5609 _("You are not currently controlling a delegated player."));
5610 ret = FALSE;
5611 break;
5612 }
5613
5614 if (!connection_delegate_restore(caller)) {
5615 /* Should never happen. Generic failure message. */
5616 log_error("Failed to restore %s's connection as %s during "
5617 "'delegate restore'.", caller->username,
5619 caller->server.delegation.observer));
5620 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5621 ret = FALSE;
5622 break;
5623 }
5624
5625 cmd_reply(CMD_DELEGATE, caller, C_OK,
5626 /* TRANS: "<user> is now connected to <player>" where <player>
5627 * can also be "global observer" or "nothing" */
5628 _("%s is now connected as %s."), caller->username,
5629 delegate_player_str(conn_get_player(caller), caller->observer));
5630 ret = TRUE;
5631 break;
5632 }
5633
5634 cleanup:
5636 return ret;
5637}
5638
5639/**********************************************************************/
5642static const char *delegate_player_str(struct player *pplayer, bool observer)
5643{
5644 static struct astring buf;
5645
5646 if (pplayer) {
5647 if (observer) {
5648 astr_set(&buf, _("%s (observer)"), player_name(pplayer));
5649 } else {
5650 astr_set(&buf, "%s", player_name(pplayer));
5651 }
5652 } else if (observer) {
5653 astr_set(&buf, "%s", _("global observer"));
5654 } else {
5655 /* TRANS: in place of player name or "global observer" */
5656 astr_set(&buf, "%s", _("nothing"));
5657 }
5658
5659 return astr_str(&buf);
5660}
5661
5662/* Define the possible arguments to the mapimg command */
5663/* map image layers */
5664#define SPECENUM_NAME mapimg_args
5665#define SPECENUM_VALUE0 MAPIMG_COLORTEST
5666#define SPECENUM_VALUE0NAME "colortest"
5667#define SPECENUM_VALUE1 MAPIMG_CREATE
5668#define SPECENUM_VALUE1NAME "create"
5669#define SPECENUM_VALUE2 MAPIMG_DEFINE
5670#define SPECENUM_VALUE2NAME "define"
5671#define SPECENUM_VALUE3 MAPIMG_DELETE
5672#define SPECENUM_VALUE3NAME "delete"
5673#define SPECENUM_VALUE4 MAPIMG_SHOW
5674#define SPECENUM_VALUE4NAME "show"
5675#define SPECENUM_COUNT MAPIMG_COUNT
5676#include "specenum_gen.h"
5677
5678/**********************************************************************/
5681static const char *mapimg_accessor(int i)
5682{
5683 i = CLIP(0, i, mapimg_args_max());
5684 return mapimg_args_name((enum mapimg_args) i);
5685}
5686
5687/**********************************************************************/
5690static bool mapimg_command(struct connection *caller, char *arg, bool check)
5691{
5692 enum m_pre_result result;
5693 int ind, ntokens, id;
5694 char *token[2];
5695 bool ret = TRUE;
5696
5697 ntokens = get_tokens(arg, token, 2, TOKEN_DELIMITERS);
5698
5699 if (ntokens > 0) {
5700 /* match the argument */
5702 fc_strncasecmp, NULL, token[0], &ind);
5703
5704 switch (result) {
5705 case M_PRE_EXACT:
5706 case M_PRE_ONLY:
5707 /* we have a match */
5708 break;
5709 case M_PRE_AMBIGUOUS:
5710 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5711 _("Ambiguous 'mapimg' command."));
5712 ret = FALSE;
5713 goto cleanup;
5714 break;
5715 case M_PRE_EMPTY:
5716 /* use 'show' as default */
5717 ind = MAPIMG_SHOW;
5718 break;
5719 case M_PRE_LONG:
5720 case M_PRE_FAIL:
5721 case M_PRE_LAST:
5722 {
5723 char buf[256] = "";
5725
5729 cat_snprintf(buf, sizeof(buf), "'%s'",
5731 if (valid_args != mapimg_args_max()) {
5732 cat_snprintf(buf, sizeof(buf), ", ");
5733 }
5734 }
5735
5736 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5737 _("The valid arguments are: %s."), buf);
5738 ret = FALSE;
5739 goto cleanup;
5740 }
5741 break;
5742 }
5743 } else {
5744 /* use 'show' as default */
5745 ind = MAPIMG_SHOW;
5746 }
5747
5748 switch (ind) {
5749 case MAPIMG_DEFINE:
5750 if (ntokens == 1) {
5751 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5752 _("Missing argument for 'mapimg define'."));
5753 ret = FALSE;
5754 } else {
5755 /* 'mapimg define <mapstr>' */
5756 if (!mapimg_define(token[1], check)) {
5757 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5758 _("Can't use definition: %s."), mapimg_error());
5759 ret = FALSE;
5760 } else if (check) {
5761 /* Validated OK, bail out now */
5762 goto cleanup;
5763 } else if (game_was_started()
5764 && mapimg_isvalid(mapimg_count() - 1) == NULL) {
5765 /* game was started - error in map image definition check */
5766 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5767 _("Can't use definition: %s."), mapimg_error());
5768 ret = FALSE;
5769 } else {
5770 char str[MAX_LEN_MAPDEF];
5771
5772 id = mapimg_count() - 1;
5773
5774 mapimg_id2str(id, str, sizeof(str));
5775 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Defined as map image "
5776 "definition %d: '%s'."),
5777 id, str);
5778 }
5779 }
5780 break;
5781
5782 case MAPIMG_DELETE:
5783 if (ntokens == 1) {
5784 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5785 _("Missing argument for 'mapimg delete'."));
5786 ret = FALSE;
5787 } else if (ntokens == 2 && strcmp(token[1], "all") == 0) {
5788 /* 'mapimg delete all' */
5789 if (check) {
5790 goto cleanup;
5791 }
5792
5793 while (mapimg_count() > 0) {
5794 mapimg_delete(0);
5795 }
5796 cmd_reply(CMD_MAPIMG, caller, C_OK, _("All map image definitions "
5797 "deleted."));
5798 } else if (ntokens == 2 && sscanf(token[1], "%d", &id) != 0) {
5799 /* 'mapimg delete <id>' */
5800 if (check) {
5801 goto cleanup;
5802 }
5803
5804 if (!mapimg_delete(id)) {
5805 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5806 _("Couldn't delete definition: %s."), mapimg_error());
5807 ret = FALSE;
5808 } else {
5809 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Map image definition %d "
5810 "deleted."), id);
5811 }
5812 } else {
5813 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5814 _("Bad argument for 'mapimg delete': '%s'."), token[1]);
5815 ret = FALSE;
5816 }
5817 break;
5818
5819 case MAPIMG_SHOW:
5820 if (ntokens < 2 || (ntokens == 2 && strcmp(token[1], "all") == 0)) {
5821 /* 'mapimg show' or 'mapimg show all' */
5822 if (check) {
5823 goto cleanup;
5824 }
5825 show_mapimg(caller, CMD_MAPIMG);
5826 } else if (ntokens == 2 && sscanf(token[1], "%d", &id) != 0) {
5827 char str[2048];
5828 /* 'mapimg show <id>' */
5829 if (check) {
5830 goto cleanup;
5831 }
5832
5833 if (mapimg_show(id, str, sizeof(str), TRUE)) {
5834 cmd_reply(CMD_MAPIMG, caller, C_OK, "%s", str);
5835 } else {
5836 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5837 _("Couldn't show definition: %s."), mapimg_error());
5838 ret = FALSE;
5839 }
5840 } else {
5841 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5842 _("Bad argument for 'mapimg show': '%s'."), token[1]);
5843 ret = FALSE;
5844 }
5845 break;
5846
5847 case MAPIMG_COLORTEST:
5848 if (check) {
5849 goto cleanup;
5850 }
5851
5853 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Map color test images saved."));
5854 break;
5855
5856 case MAPIMG_CREATE:
5857 if (ntokens < 2) {
5858 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5859 _("Missing argument for 'mapimg create'."));
5860 ret = FALSE;
5861 goto cleanup;
5862 }
5863
5864 if (strcmp(token[1], "all") == 0) {
5865 int count;
5866
5867 /* 'mapimg create all' */
5868 if (check) {
5869 goto cleanup;
5870 }
5871
5872 count = mapimg_count();
5873 for (id = 0; id < count; id++) {
5874 struct mapdef *pmapdef = mapimg_isvalid(id);
5875
5876 if (pmapdef == NULL
5879 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5880 _("Error saving map image %d: %s."), id, mapimg_error());
5881 ret = FALSE;
5882 }
5883 }
5884 } else if (sscanf(token[1], "%d", &id) != 0) {
5885 struct mapdef *pmapdef;
5886
5887 /* 'mapimg create <id>' */
5888 if (check) {
5889 goto cleanup;
5890 }
5891
5892 pmapdef = mapimg_isvalid(id);
5893 if (pmapdef == NULL
5896 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5897 _("Error saving map image %d: %s."), id, mapimg_error());
5898 ret = FALSE;
5899 }
5900 } else {
5901 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5902 _("Bad argument for 'mapimg create': '%s'."), token[1]);
5903 ret = FALSE;
5904 }
5905 break;
5906 }
5907
5908 cleanup:
5909
5910 free_tokens(token, ntokens);
5911
5912 return ret;
5913}
5914
5915/**********************************************************************/
5918static bool aicmd_command(struct connection *caller, char *arg, bool check)
5919{
5921 struct player *pplayer;
5922 char *tokens[1], *cmd = NULL;
5923 int ntokens;
5924 bool ret = FALSE;
5925
5927
5928 if (ntokens < 1) {
5929 cmd_reply(CMD_AICMD, caller, C_FAIL,
5930 _("No player given for aicmd."));
5931 goto cleanup;
5932 }
5933
5935
5936 if (NULL == pplayer) {
5938 goto cleanup;
5939 }
5940
5941 /* We have a player - extract the command. */
5942 cmd = arg + strlen(tokens[0]);
5943 cmd = skip_leading_spaces(cmd);
5944
5945 if (strlen(cmd) == 0) {
5946 cmd_reply(CMD_AICMD, caller, C_FAIL,
5947 _("No command for the AI console defined."));
5948 goto cleanup;
5949 }
5950
5951 if (check) {
5952 ret = TRUE;
5953 goto cleanup;
5954 }
5955
5956 /* This check is needed to return a message if the function is not defined
5957 * for the AI of the player. */
5958 if (pplayer && pplayer->ai) {
5959 if (pplayer->ai->funcs.player_console) {
5960 cmd_reply(CMD_AICMD, caller, C_OK,
5961 _("AI console for player %s. Command: '%s'."),
5962 player_name(pplayer), cmd);
5963 CALL_PLR_AI_FUNC(player_console, pplayer, pplayer, cmd);
5964 ret = TRUE;
5965 } else {
5966 cmd_reply(CMD_AICMD, caller, C_FAIL,
5967 _("No AI console defined for the AI '%s' of player %s."),
5968 ai_name(pplayer->ai), player_name(pplayer));
5969 }
5970 } else {
5971 cmd_reply(CMD_AICMD, caller, C_FAIL, _("No AI defined for player %s."),
5972 player_name(pplayer));
5973 }
5974
5975 cleanup:
5977 return ret;
5978}
5979
5980/* Define the possible arguments to the fcdb command */
5981#define SPECENUM_NAME fcdb_args
5982#define SPECENUM_VALUE0 FCDB_RELOAD
5983#define SPECENUM_VALUE0NAME "reload"
5984#define SPECENUM_VALUE1 FCDB_LUA
5985#define SPECENUM_VALUE1NAME "lua"
5986#define SPECENUM_COUNT FCDB_COUNT
5987#include "specenum_gen.h"
5988
5989/**********************************************************************/
5992static const char *fcdb_accessor(int i)
5993{
5994 i = CLIP(0, i, fcdb_args_max());
5995 return fcdb_args_name((enum fcdb_args) i);
5996}
5997
5998/**********************************************************************/
6001static bool fcdb_command(struct connection *caller, char *arg, bool check)
6002{
6003 enum m_pre_result result;
6004 int ind, ntokens;
6005 char *token[1];
6006 bool ret = TRUE;
6007 bool usage = FALSE;
6008
6009#ifndef HAVE_FCDB
6010 cmd_reply(CMD_FCDB, caller, C_FAIL,
6011 _("Freeciv database script deactivated at compile time."));
6012 return FALSE;
6013#endif
6014
6015 if (!srvarg.fcdb_enabled) {
6016 /* Not supposed to be used. It isn't initialized. */
6017 cmd_reply(CMD_FCDB, caller, C_FAIL,
6018 _("Freeciv database script not activated at server start. "
6019 "See the Freeciv server's --auth command line option."));
6020 return FALSE;
6021 }
6022
6023 ntokens = get_tokens(arg, token, 1, TOKEN_DELIMITERS);
6024
6025 if (ntokens > 0) {
6026 /* match the argument */
6028 fc_strncasecmp, NULL, token[0], &ind);
6029
6030 switch (result) {
6031 case M_PRE_EXACT:
6032 case M_PRE_ONLY:
6033 /* we have a match */
6034 break;
6035 case M_PRE_AMBIGUOUS:
6036 cmd_reply(CMD_FCDB, caller, C_FAIL,
6037 _("Ambiguous fcdb command."));
6038 ret = FALSE;
6039 goto cleanup;
6040 break;
6041 case M_PRE_EMPTY:
6042 case M_PRE_LONG:
6043 case M_PRE_FAIL:
6044 case M_PRE_LAST:
6045 usage = TRUE;
6046 break;
6047 }
6048 } else {
6049 usage = TRUE;
6050 }
6051
6052 if (usage) {
6053 char buf[256] = "";
6054 enum fcdb_args valid_args;
6055
6056 for (valid_args = fcdb_args_begin();
6059 cat_snprintf(buf, sizeof(buf), "'%s'",
6061 if (valid_args != fcdb_args_max()) {
6062 cat_snprintf(buf, sizeof(buf), ", ");
6063 }
6064 }
6065
6066 cmd_reply(CMD_FCDB, caller, C_FAIL,
6067 _("The valid arguments are: %s."), buf);
6068 ret = FALSE;
6069 goto cleanup;
6070 }
6071
6072 if (check) {
6073 ret = TRUE;
6074 goto cleanup;
6075 }
6076
6077 switch (ind) {
6078 case FCDB_RELOAD:
6079 /* Reload database lua script. */
6082 break;
6083
6084 case FCDB_LUA:
6085 /* Skip whitespaces. */
6086 arg = skip_leading_spaces(arg);
6087 /* Skip the base argument 'lua'. */
6088 arg += 3;
6089 /* Now execute the scriptlet. */
6090 ret = script_fcdb_do_string(caller, arg);
6091 break;
6092 }
6093
6094 cleanup:
6095
6096 free_tokens(token, ntokens);
6097
6098 return ret;
6099}
6100
6101/**********************************************************************/
6104static void start_cmd_reply(struct connection *caller, bool notify, char *msg)
6105{
6106 cmd_reply(CMD_START_GAME, caller, C_FAIL, "%s", msg);
6107 if (notify) {
6108 notify_conn(NULL, NULL, E_SETTING, ftc_server, "%s", msg);
6109 }
6110}
6111
6112/**********************************************************************/
6115bool start_command(struct connection *caller, bool check, bool notify)
6116{
6117 int human_players;
6118
6119 switch (server_state()) {
6120 case S_S_INITIAL:
6121 /* Sanity check scenario */
6122 if (game.info.is_new_game && !check) {
6123 if (0 < map_startpos_count()
6125 /* If we load a pre-generated map (i.e., a scenario) it is possible
6126 * to increase the number of players beyond the number supported by
6127 * the scenario. The solution is a hack: cut the extra players
6128 * when the game starts. */
6129 log_verbose("Reduced maxplayers from %d to %d to fit "
6130 "to the number of start positions.",
6133 }
6134
6136 int i;
6137 struct player *pplayer;
6138
6139 for (i = player_slot_count() - 1; i >= 0; i--) {
6140 pplayer = player_by_number(i);
6141 if (pplayer) {
6142 server_remove_player(pplayer);
6143 }
6145 break;
6146 }
6147 }
6148
6149 log_verbose("Had to cut down the number of players to the "
6150 "number of map start positions, there must be "
6151 "something wrong with the savegame or you "
6152 "adjusted the maxplayers value.");
6153 }
6154 }
6155
6156 human_players = 0;
6157 players_iterate(plr) {
6158 if (is_human(plr)) {
6159 human_players++;
6160 }
6162
6163 /* check min_players.
6164 * Allow continuing of savegames where some of the original
6165 * players have died */
6168 char buf[512] = "";
6169
6170 fc_snprintf(buf, sizeof(buf),
6171 _("Not enough human players ('minplayers' server setting has value %d); game will not start."),
6173 start_cmd_reply(caller, notify, buf);
6174 return FALSE;
6175 } else if (player_count() < 1) {
6176 /* At least one player required */
6177 start_cmd_reply(caller, notify,
6178 _("No players; game will not start."));
6179 return FALSE;
6180 } else if (normal_player_count() > server.playable_nations) {
6181 if (nation_set_count() > 1) {
6182 start_cmd_reply(caller, notify,
6183 _("Not enough nations in the current nation set "
6184 "for all players; game will not start. "
6185 "(See 'nationset' setting.)"));
6186 } else {
6187 start_cmd_reply(caller, notify,
6188 _("Not enough nations for all players; game will "
6189 "not start."));
6190 }
6191 return FALSE;
6192 } else if (strlen(game.server.start_units) == 0 && !game.server.start_city) {
6193 start_cmd_reply(caller, notify,
6194 _("Neither 'startcity' nor 'startunits' setting gives "
6195 "players anything to start game with; game will "
6196 "not start."));
6197 return FALSE;
6198 } else if (check) {
6199 return TRUE;
6200 } else if (!caller) {
6201 if (notify) {
6202 /* Called from handle_player_ready()
6203 * Last player just toggled ready-status. */
6205 _("All players are ready; starting game."));
6206 }
6207 start_game();
6208 return TRUE;
6209 } else if (NULL == caller->playing || caller->observer) {
6210 /* A detached or observer player can't do /start. */
6211 return TRUE;
6212 } else {
6213 /* This might trigger recursive call to start_command() if this is
6214 * last player who gets ready. In that case caller is NULL. */
6216 return TRUE;
6217 }
6218 case S_S_OVER:
6219 start_cmd_reply(caller, notify,
6220 /* TRANS: given when /start is invoked during gameover. */
6221 _("Cannot start the game: the game is waiting for all clients "
6222 "to disconnect."));
6223 return FALSE;
6224 case S_S_RUNNING:
6225 start_cmd_reply(caller, notify,
6226 /* TRANS: given when /start is invoked while the game
6227 * is running. */
6228 _("Cannot start the game: it is already running."));
6229 return FALSE;
6230 }
6231 log_error("Unknown server state variant: %d.", server_state());
6232 return FALSE;
6233}
6234
6235/**********************************************************************/
6238static bool cut_client_connection(struct connection *caller, char *name,
6239 bool check)
6240{
6242 struct connection *ptarget;
6243
6245
6246 if (!ptarget) {
6248 return FALSE;
6249 } else if (check) {
6250 return TRUE;
6251 }
6252
6254 /* If we cut the connection, unassign the login name.*/
6255 sz_strlcpy(ptarget->playing->username, _(ANON_USER_NAME));
6256 ptarget->playing->unassigned_user = TRUE;
6257 }
6258
6260 _("Cutting connection %s."), ptarget->username);
6261 connection_close_server(ptarget, _("connection cut"));
6262
6263 return TRUE;
6264}
6265
6266
6267/**********************************************************************/
6271{
6272 time_t *d = fc_malloc(sizeof(*d));
6273 *d = *t;
6274 return d;
6275}
6276
6277/**********************************************************************/
6282{
6284 time_t now, time_of_kick = 0;
6285
6286 if (NULL != time_remaining) {
6287 *time_remaining = 0;
6288 }
6289
6293
6294 if (kick_hash_lookup(kick_table_by_addr, pconn->server.ipaddr,
6297 }
6302 }
6303
6304 if (0 == time_of_kick) {
6305 return FALSE; /* Not found. */
6306 }
6307
6308 now = time(NULL);
6310 /* Kick timeout expired. */
6311 if (0 != time_of_addr_kick) {
6312 kick_hash_remove(kick_table_by_addr, pconn->server.ipaddr);
6313 }
6314 if (0 != time_of_user_kick) {
6316 }
6317 return FALSE;
6318 }
6319
6320 if (NULL != time_remaining) {
6322 }
6323 return TRUE;
6324}
6325
6326/**********************************************************************/
6329static bool kick_command(struct connection *caller, char *name, bool check)
6330{
6331 char ipaddr[FC_MEMBER_SIZEOF(struct connection, server.ipaddr)];
6332 struct connection *pconn;
6334 time_t now;
6335
6338 if (NULL == pconn) {
6340 return FALSE;
6341 }
6342
6343 if (NULL != caller && ALLOW_ADMIN > conn_get_access(caller)) {
6344 const int MIN_UNIQUE_CONNS = 3;
6345 const char *unique_ipaddr[MIN_UNIQUE_CONNS];
6346 int i, num_unique_connections = 0;
6347
6348 if (pconn == caller) {
6349 cmd_reply(CMD_KICK, caller, C_FAIL, _("You may not kick yourself."));
6350 return FALSE;
6351 }
6352
6354 for (i = 0; i < num_unique_connections; i++) {
6355 if (0 == strcmp(unique_ipaddr[i], aconn->server.ipaddr)) {
6356 /* Already listed. */
6357 break;
6358 }
6359 }
6360 if (i >= num_unique_connections) {
6363 /* We have enough already. */
6364 break;
6365 }
6366 unique_ipaddr[num_unique_connections - 1] = aconn->server.ipaddr;
6367 }
6369
6371 cmd_reply(CMD_KICK, caller, C_FAIL,
6372 _("There must be at least %d unique connections to the "
6373 "server for this command to be valid."), MIN_UNIQUE_CONNS);
6374 return FALSE;
6375 }
6376 }
6377
6378 if (check) {
6379 return TRUE;
6380 }
6381
6382 sz_strlcpy(ipaddr, pconn->server.ipaddr);
6383 now = time(NULL);
6385
6387 if (0 != strcmp(ipaddr, aconn->server.ipaddr)) {
6388 continue;
6389 }
6390
6392 /* Unassign the username. */
6393 sz_strlcpy(aconn->playing->username, _(ANON_USER_NAME));
6394 aconn->playing->unassigned_user = TRUE;
6395 }
6396
6398
6399 connection_close_server(aconn, _("kicked"));
6401
6402 return TRUE;
6403}
6404
6405
6406/**********************************************************************/
6410static void show_help_intro(struct connection *caller,
6411 enum command_id help_cmd)
6412{
6413 /* This is formatted like extra_help entries for settings and commands: */
6414 char *help = fc_strdup(
6415 _("Welcome - this is the introductory help text for the Freeciv "
6416 "server.\n"
6417 "\n"
6418 "Two important server concepts are Commands and Options. Commands, "
6419 "such as 'help', are used to interact with the server. Some commands "
6420 "take one or more arguments, separated by spaces. In many cases "
6421 "commands and command arguments may be abbreviated. Options are "
6422 "settings which control the server as it is running.\n"
6423 "\n"
6424 "To find out how to get more information about commands and options, "
6425 "use 'help help'.\n"
6426 "\n"
6427 "For the impatient, the main commands to get going are:\n"
6428 " show - to see current options\n"
6429 " set - to set options\n"
6430 " start - to start the game once players have connected\n"
6431 " save - to save the current game\n"
6432 " quit - to exit"));
6433
6435 cmd_reply(help_cmd, caller, C_COMMENT, "%s", help);
6436 FC_FREE(help);
6437}
6438
6439/**********************************************************************/
6443static void show_help_command(struct connection *caller,
6444 enum command_id help_cmd,
6445 enum command_id id)
6446{
6447 const struct command *cmd = command_by_number(id);
6448
6449 if (command_short_help(cmd)) {
6450 cmd_reply(help_cmd, caller, C_COMMENT,
6451 /* TRANS: <untranslated name> - translated short help */
6452 _("Command: %s - %s"),
6453 command_name(cmd),
6454 command_short_help(cmd));
6455 } else {
6456 cmd_reply(help_cmd, caller, C_COMMENT,
6457 /* TRANS: <untranslated name> */
6458 _("Command: %s"),
6459 command_name(cmd));
6460 }
6461 if (command_synopsis(cmd)) {
6462 /* line up the synopsis lines: */
6463 const char *syn = _("Synopsis: ");
6464 size_t synlen = strlen(syn);
6465 char prefix[40];
6466
6467 fc_snprintf(prefix, sizeof(prefix), "%*s", (int) synlen, " ");
6468 cmd_reply_prefix(help_cmd, caller, C_COMMENT, prefix,
6469 "%s%s", syn, command_synopsis(cmd));
6470 }
6471 cmd_reply(help_cmd, caller, C_COMMENT,
6472 _("Level: %s"), cmdlevel_name(command_level(cmd)));
6473 {
6474 char *help = command_extra_help(cmd);
6475
6476 if (help) {
6478 cmd_reply(help_cmd, caller, C_COMMENT, _("Description:"));
6479 cmd_reply_prefix(help_cmd, caller, C_COMMENT, " ", " %s", help);
6480 FC_FREE(help);
6481 }
6482 }
6483}
6484
6485/**********************************************************************/
6489static void show_help_command_list(struct connection *caller,
6490 enum command_id help_cmd)
6491{
6492 enum command_id i;
6493
6494 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6495 cmd_reply(help_cmd, caller, C_COMMENT,
6496 _("The following server commands are available:"));
6497 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6498 if (!caller && con_get_style()) {
6499 for (i = 0; i < CMD_NUM; i++) {
6500 cmd_reply(help_cmd, caller, C_COMMENT, "%s", command_name_by_number(i));
6501 }
6502 } else {
6504 int j;
6505
6506 buf[0] = '\0';
6507 for (i = 0, j = 0; i < CMD_NUM; i++) {
6508 if (may_use(caller, i)) {
6509 cat_snprintf(buf, sizeof(buf), "%-19s", command_name_by_number(i));
6510 if ((++j % 4) == 0) {
6511 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
6512 buf[0] = '\0';
6513 }
6514 }
6515 }
6516 if (buf[0] != '\0') {
6517 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
6518 }
6519 }
6520 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6521}
6522
6523/**********************************************************************/
6527static void cmd_reply_matches(enum command_id cmd,
6528 struct connection *caller,
6530 int *matches, int num_matches)
6531{
6532 char buf[MAX_LEN_MSG];
6533 const char *src, *end;
6534 char *dest;
6535 int i;
6536
6537 if (accessor_fn == NULL || matches == NULL || num_matches < 1) {
6538 return;
6539 }
6540
6541 dest = buf;
6542 end = buf + sizeof(buf) - 1;
6543
6544 for (i = 0; i < num_matches && dest < end; i++) {
6545 src = accessor_fn(matches[i]);
6546 if (!src) {
6547 continue;
6548 }
6549 if (dest != buf) {
6550 *dest++ = ' ';
6551 }
6552 while (*src != '\0' && dest < end) {
6553 *dest++ = *src++;
6554 }
6555 }
6556 *dest = '\0';
6557
6558 cmd_reply(cmd, caller, C_COMMENT, _("Possible matches: %s"), buf);
6559}
6560
6561/**************************************************************************
6562 Additional 'help' arguments
6563**************************************************************************/
6564#define SPECENUM_NAME help_general_args
6565#define SPECENUM_VALUE0 HELP_GENERAL_COMMANDS
6566#define SPECENUM_VALUE0NAME "commands"
6567#define SPECENUM_VALUE1 HELP_GENERAL_OPTIONS
6568#define SPECENUM_VALUE1NAME "options"
6569#define SPECENUM_COUNT HELP_GENERAL_COUNT
6570#include "specenum_gen.h"
6571
6572/**************************************************************************
6573 Unified indices for help arguments:
6574 CMD_NUM - Server commands
6575 HELP_GENERAL_NUM - General help arguments, above
6576 settings_number() - Server options
6577**************************************************************************/
6578#define HELP_ARG_NUM (CMD_NUM + HELP_GENERAL_COUNT + settings_number())
6579
6580/**********************************************************************/
6583static const char *helparg_accessor(int i)
6584{
6585 if (i < CMD_NUM) {
6586 return command_name_by_number(i);
6587 }
6588
6589 i -= CMD_NUM;
6590 if (i < HELP_GENERAL_COUNT) {
6592 }
6593
6595 return optname_accessor(i);
6596}
6597
6598/**********************************************************************/
6601static bool show_help(struct connection *caller, char *arg)
6602{
6603 int matches[64], num_matches = 0;
6605 int ind;
6606
6608 /* no commands means no help, either */
6609
6611 fc_strncasecmp, NULL, arg, &ind, matches,
6613
6614 if (match_result == M_PRE_EMPTY) {
6615 show_help_intro(caller, CMD_HELP);
6616 return FALSE;
6617 }
6619 cmd_reply(CMD_HELP, caller, C_FAIL,
6620 _("Help argument '%s' is ambiguous."), arg);
6623 return FALSE;
6624 }
6625 if (match_result == M_PRE_FAIL) {
6626 cmd_reply(CMD_HELP, caller, C_FAIL,
6627 _("No match for help argument '%s'."), arg);
6628 return FALSE;
6629 }
6630
6631 /* other cases should be above */
6633
6634 if (ind < CMD_NUM) {
6635 show_help_command(caller, CMD_HELP, ind);
6636 return TRUE;
6637 }
6638 ind -= CMD_NUM;
6639
6640 if (ind == HELP_GENERAL_OPTIONS) {
6642 return TRUE;
6643 }
6644 if (ind == HELP_GENERAL_COMMANDS) {
6646 return TRUE;
6647 }
6649
6650 if (ind < settings_number()) {
6651 show_help_option(caller, CMD_HELP, ind);
6652 return TRUE;
6653 }
6654
6655 /* should have finished by now */
6656 log_error("Bug in show_help!");
6657 return FALSE;
6658}
6659
6660/**********************************************************************/
6663static void show_connections(struct connection *caller)
6664{
6666
6667 cmd_reply(CMD_LIST, caller, C_COMMENT,
6668 _("List of connections to server:"));
6670
6672 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no connections>"));
6673 } else {
6676 if (pconn->established) {
6677 cat_snprintf(buf, sizeof(buf), " command access level %s",
6678 cmdlevel_name(pconn->access_level));
6679 }
6680 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6682 }
6684}
6685
6686/**********************************************************************/
6689static void show_delegations(struct connection *caller)
6690{
6691 bool empty = TRUE;
6692
6693 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of all delegations:"));
6695
6696 players_iterate(pplayer) {
6697 const char *delegate_to = player_delegation_get(pplayer);
6698 if (delegate_to != NULL) {
6699 const char *owner =
6700 player_delegation_active(pplayer) ? pplayer->server.orig_username
6701 : pplayer->username;
6703 cmd_reply(CMD_LIST, caller, C_COMMENT,
6704 /* TRANS: last %s is either " (active)" or empty string */
6705 _("%s delegates control over player '%s' to user %s%s."),
6706 owner, player_name(pplayer), delegate_to,
6707 /* TRANS: preserve leading space */
6708 player_delegation_active(pplayer) ? _(" (active)") : "");
6709 empty = FALSE;
6710 }
6712
6713 if (empty) {
6714 cmd_reply(CMD_LIST, caller, C_COMMENT, _("No delegations defined."));
6715 }
6716
6718}
6719
6720/**********************************************************************/
6723static bool show_ignore(struct connection *caller)
6724{
6725 char buf[128];
6726 int n = 1;
6727
6728 if (NULL == caller) {
6729 cmd_reply(CMD_IGNORE, caller, C_FAIL,
6730 _("That would be rather silly, since you are not a player."));
6731 return FALSE;
6732 }
6733
6734 if (0 == conn_pattern_list_size(caller->server.ignore_list)) {
6735 cmd_reply(CMD_LIST, caller, C_COMMENT, _("Your ignore list is empty."));
6736 return TRUE;
6737 }
6738
6739 cmd_reply(CMD_LIST, caller, C_COMMENT, _("Your ignore list:"));
6743 cmd_reply(CMD_LIST, caller, C_COMMENT, "%d: %s", n++, buf);
6746
6747 return TRUE;
6748}
6749
6750/**********************************************************************/
6753void show_players(struct connection *caller)
6754{
6755 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of players:"));
6757
6758 if (player_count() == 0) {
6759 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no players>"));
6760 } else {
6761 players_iterate(pplayer) {
6763 int n;
6764
6765 /* Low access level callers don't get to see barbarians in list: */
6766 if (is_barbarian(pplayer) && caller
6767 && (caller->access_level < ALLOW_CTRL)) {
6768 continue;
6769 }
6770
6771 /* The output for each player looks like:
6772 *
6773 * <Player name> [color]: Team[, Nation][, Username][, Status]
6774 * AI/Barbarian/Human[, AI type, skill level][, Connections]
6775 * [Details for each connection]
6776 */
6777
6778 /* '<Player name> [color]: [Nation][, Username][, Status]' */
6779 buf[0] = '\0';
6780 cat_snprintf(buf, sizeof(buf), "%s [%s]: %s", player_name(pplayer),
6781 player_color_ftstr(pplayer),
6782 team_name_translation(pplayer->team));
6783 if (!game.info.is_new_game) {
6784 cat_snprintf(buf, sizeof(buf), ", %s",
6786 }
6787 if (strlen(pplayer->username) > 0
6788 && strcmp(pplayer->username, "nouser") != 0) {
6789 cat_snprintf(buf, sizeof(buf), _(", user %s"), pplayer->username);
6790 }
6791 if (S_S_INITIAL == server_state() && pplayer->is_connected) {
6792 if (pplayer->is_ready) {
6793 sz_strlcat(buf, _(", ready"));
6794 } else {
6795 /* Emphasizes this */
6796 n = strlen(buf);
6797 featured_text_apply_tag(_(", not ready"),
6798 buf + n, sizeof(buf) - n,
6800 ftc_changed);
6801 }
6802 } else if (!pplayer->is_alive) {
6803 sz_strlcat(buf, _(", Dead"));
6804 }
6805 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6806
6807 /* ' AI/Barbarian/Human[, skill level][, Connections]' */
6808 buf[0] = '\0';
6809 if (is_barbarian(pplayer)) {
6810 sz_strlcat(buf, _("Barbarian"));
6811 } else if (is_ai(pplayer)) {
6812 sz_strlcat(buf, _("AI"));
6813 } else {
6814 sz_strlcat(buf, _("Human"));
6815 }
6816 if (is_ai(pplayer)) {
6817 cat_snprintf(buf, sizeof(buf), _(", %s"), ai_name(pplayer->ai));
6818 cat_snprintf(buf, sizeof(buf), _(", difficulty level %s"),
6819 ai_level_translated_name(pplayer->ai_common.skill_level));
6820 }
6821 n = conn_list_size(pplayer->connections);
6822 if (n > 0) {
6823 cat_snprintf(buf, sizeof(buf),
6824 PL_(", %d connection:", ", %d connections:", n), n);
6825 }
6826 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", buf);
6827
6828 /* ' [Details for each connection]' */
6829 conn_list_iterate(pplayer->connections, pconn) {
6830 fc_snprintf(buf, sizeof(buf),
6831 _("%s from %s (command access level %s), "
6832 "bufsize=%dkb"), pconn->username, pconn->addr,
6833 cmdlevel_name(pconn->access_level),
6834 (pconn->send_buffer->nsize >> 10));
6835 if (pconn->observer) {
6836 /* TRANS: preserve leading space */
6837 sz_strlcat(buf, _(" (observer mode)"));
6838 }
6839 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", buf);
6842 }
6844}
6845
6848};
6849
6850/************************************************************************/
6853static void ruleset_cache_listcmd_cb(const char *mp_name,
6854 const char *filename, void *data_in)
6855{
6856 struct mrc_listcmd_data *data = (struct mrc_listcmd_data *)data_in;
6857 struct section_file *sf;
6858 const char *name;
6859 const char *serv;
6860 const char *rsdir;
6861
6863
6864 if (name == NULL) {
6865 log_error("Modpack \"%s\" not in ruleset cache", mp_name);
6866 return;
6867 }
6868
6869 sf = secfile_load(name, FALSE);
6870
6871 if (sf == NULL) {
6872 log_error("Failed to load modpack file \"%s\"", name);
6873 return;
6874 }
6875
6876 serv = modpack_serv_file(sf);
6878
6879 if (serv != NULL || rsdir != NULL) {
6880 /* Modpack has ruleset component */
6881 cmd_reply(CMD_LIST, data->caller, C_COMMENT, "%s : %s : %s", mp_name,
6882 rsdir != NULL ? rsdir : "-",
6883 serv != NULL ? serv : "-");
6884 }
6885
6886 secfile_destroy(sf);
6887}
6888
6889/**********************************************************************/
6892static void show_rulesets(struct connection *caller)
6893{
6894 struct mrc_listcmd_data data;
6895
6897 /* TRANS: don't translate text between '' */
6898 _("List of available rulesets, and how to load them:"));
6901 _("Ruleset : /rulesetdir <dir> : /read <script>"));
6903
6905
6906 data.caller = caller;
6908
6910}
6911
6912/**********************************************************************/
6916{
6918 struct fileinfo_list *files;
6919
6920 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of scenarios available:"));
6922
6923 files = fileinfolist_infix(get_scenario_dirs(), ".sav", TRUE);
6924
6926 struct section_file *sf = secfile_load_section(pfile->fullname, "scenario", TRUE);
6927
6928 if (secfile_lookup_bool_default(sf, TRUE, "scenario.is_scenario")) {
6929 fc_snprintf(buf, sizeof(buf), "%s", pfile->name);
6930 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6931 }
6933 fileinfo_list_destroy(files);
6934
6936}
6937
6938/**********************************************************************/
6941static void show_nationsets(struct connection *caller)
6942{
6943 cmd_reply(CMD_LIST, caller, C_COMMENT,
6944 /* TRANS: don't translate text between '' */
6945 _("List of nation sets available for 'nationset' option:"));
6947
6949 const char *description = nation_set_description(pset);
6950 int num_nations = 0;
6951 nations_iterate(pnation) {
6952 if (is_nation_playable(pnation) && nation_is_in_set(pnation, pset)) {
6953 num_nations++;
6954 }
6956 cmd_reply(CMD_LIST, caller, C_COMMENT,
6957 /* TRANS: nation set description; %d refers to number of playable
6958 * nations in set */
6959 PL_(" %-10s %s (%d playable)",
6960 " %-10s %s (%d playable)", num_nations),
6962 num_nations);
6963 if (strlen(description) > 0) {
6964 static const char prefix[] = " ";
6965 char *translated = fc_strdup(_(description));
6967 cmd_reply_prefix(CMD_LIST, caller, C_COMMENT, prefix, "%s%s",
6968 prefix, translated);
6969 }
6971
6973}
6974
6975/**********************************************************************/
6978static void show_teams(struct connection *caller)
6979{
6980 /* Currently this just lists all teams (typically 32 of them) with their
6981 * names and # of players on the team. This could probably be improved. */
6982 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of teams:"));
6984
6986 const struct player_list *members = team_members(pteam);
6987
6988 /* PL_() is needed here because some languages may differentiate
6989 * between 2 and 3 (although English does not). */
6990 cmd_reply(CMD_LIST, caller, C_COMMENT,
6991 /* TRANS: There will always be at least 2 players here. */
6992 PL_("%2d : '%s' : %d player :",
6993 "%2d : '%s' : %d players :",
6997 player_list_iterate(members, pplayer) {
6998 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", player_name(pplayer));
7001
7003}
7004
7005/**********************************************************************/
7008static void show_mapimg(struct connection *caller, enum command_id cmd)
7009{
7010 int id;
7011
7012 if (mapimg_count() == 0) {
7013 cmd_reply(cmd, caller, C_OK, _("No map image definitions."));
7014 } else {
7015 cmd_reply(cmd, caller, C_COMMENT, _("List of map image definitions:"));
7016 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
7017 for (id = 0; id < mapimg_count(); id++) {
7018 char str[MAX_LEN_MAPDEF] = "";
7019 mapimg_show(id, str, sizeof(str), FALSE);
7020 cmd_reply(cmd, caller, C_COMMENT, _("[%2d] %s"), id, str);
7021 }
7022 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
7023 }
7024}
7025
7026/**********************************************************************/
7029static void show_ais(struct connection *caller)
7030{
7031 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of AI types:"));
7033
7034 ai_type_iterate(ai) {
7035 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", ai->name);
7037
7039}
7040
7041/**********************************************************************/
7044static void show_colors(struct connection *caller)
7045{
7046 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of player colors:"));
7048 if (player_count() == 0) {
7049 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no players>"));
7050 } else {
7051 players_iterate(pplayer) {
7052 cmd_reply(CMD_LIST, caller, C_COMMENT, _("%s (user %s): [%s]"),
7053 player_name(pplayer), pplayer->username,
7054 player_color_ftstr(pplayer));
7056 }
7058}
7059
7060/**************************************************************************
7061 '/list' arguments
7062**************************************************************************/
7063#define SPECENUM_NAME list_args
7064#define SPECENUM_VALUE0 LIST_AIS
7065#define SPECENUM_VALUE0NAME "ais"
7066#define SPECENUM_VALUE1 LIST_COLORS
7067#define SPECENUM_VALUE1NAME "colors"
7068#define SPECENUM_VALUE2 LIST_CONNECTIONS
7069#define SPECENUM_VALUE2NAME "connections"
7070#define SPECENUM_VALUE3 LIST_DELEGATIONS
7071#define SPECENUM_VALUE3NAME "delegations"
7072#define SPECENUM_VALUE4 LIST_IGNORE
7073#define SPECENUM_VALUE4NAME "ignored users"
7074#define SPECENUM_VALUE5 LIST_MAPIMG
7075#define SPECENUM_VALUE5NAME "map image definitions"
7076#define SPECENUM_VALUE6 LIST_PLAYERS
7077#define SPECENUM_VALUE6NAME "players"
7078#define SPECENUM_VALUE7 LIST_RULESETS
7079#define SPECENUM_VALUE7NAME "rulesets"
7080#define SPECENUM_VALUE8 LIST_SCENARIOS
7081#define SPECENUM_VALUE8NAME "scenarios"
7082#define SPECENUM_VALUE9 LIST_NATIONSETS
7083#define SPECENUM_VALUE9NAME "nationsets"
7084#define SPECENUM_VALUE10 LIST_TEAMS
7085#define SPECENUM_VALUE10NAME "teams"
7086#define SPECENUM_VALUE11 LIST_VOTES
7087#define SPECENUM_VALUE11NAME "votes"
7088#include "specenum_gen.h"
7089
7090/**********************************************************************/
7093static const char *list_accessor(int i)
7094{
7095 i = CLIP(0, i, list_args_max());
7096 return list_args_name((enum list_args) i);
7097}
7098
7099/**********************************************************************/
7102static bool show_list(struct connection *caller, char *arg)
7103{
7105 int ind_int;
7106 enum list_args ind;
7107
7110 fc_strncasecmp, NULL, arg, &ind_int);
7111 ind = ind_int;
7112
7113 if (match_result > M_PRE_EMPTY) {
7114 cmd_reply(CMD_LIST, caller, C_SYNTAX,
7115 _("Bad list argument: '%s'. Try '%shelp list'."),
7116 arg, (caller ? "/" : ""));
7117 return FALSE;
7118 }
7119
7120 if (match_result == M_PRE_EMPTY) {
7121 ind = LIST_PLAYERS;
7122 }
7123
7124 switch (ind) {
7125 case LIST_AIS:
7126 show_ais(caller);
7127 return TRUE;
7128 case LIST_COLORS:
7129 show_colors(caller);
7130 return TRUE;
7131 case LIST_CONNECTIONS:
7132 show_connections(caller);
7133 return TRUE;
7134 case LIST_DELEGATIONS:
7135 show_delegations(caller);
7136 return TRUE;
7137 case LIST_IGNORE:
7138 return show_ignore(caller);
7139 case LIST_MAPIMG:
7140 show_mapimg(caller, CMD_LIST);
7141 return TRUE;
7142 case LIST_PLAYERS:
7143 show_players(caller);
7144 return TRUE;
7145 case LIST_RULESETS:
7146 show_rulesets(caller);
7147 return TRUE;
7148 case LIST_SCENARIOS:
7149 show_scenarios(caller);
7150 return TRUE;
7151 case LIST_NATIONSETS:
7152 show_nationsets(caller);
7153 return TRUE;
7154 case LIST_TEAMS:
7155 show_teams(caller);
7156 return TRUE;
7157 case LIST_VOTES:
7158 show_votes(caller);
7159 return TRUE;
7160 }
7161
7162 cmd_reply(CMD_LIST, caller, C_FAIL,
7163 "Internal error: ind %d in show_list", ind);
7164 log_error("Internal error: ind %d in show_list", ind);
7165 return FALSE;
7166}
7167
7168#ifdef FREECIV_HAVE_LIBREADLINE
7169/********************* RL completion functions ***************************/
7170/* To properly complete both commands, player names, options and filenames
7171 there is one array per type of completion with the commands that
7172 the type is relevant for.
7173*/
7174
7175/**********************************************************************/
7183static char *generic_generator(const char *text, int state, int num,
7184 const char*(*index2str)(int))
7185{
7186 static int list_index, len;
7187 const char *name = ""; /* dummy non-NULL string */
7189
7190 /* This function takes a string (text) in the local format and must return
7191 * a string in the local format. However comparisons are done against
7192 * names that are in the internal format (UTF-8). Thus we have to convert
7193 * the text function from the local to the internal format before doing
7194 * the comparison, and convert the string we return *back* to the
7195 * local format when returning it. */
7196
7197 /* If this is a new word to complete, initialize now. This includes
7198 saving the length of TEXT for efficiency, and initializing the index
7199 variable to 0. */
7200 if (state == 0) {
7201 list_index = 0;
7202 len = strlen(mytext);
7203 }
7204
7205 /* Return the next name which partially matches: */
7206 while ((num < 0 && name) || (list_index < num)) {
7208 list_index++;
7209
7210 if (name != NULL && fc_strncasecmp(name, mytext, len) == 0) {
7211 free(mytext);
7213 }
7214 }
7215 free(mytext);
7216
7217 /* If no names matched, then return NULL. */
7218 return ((char *)NULL);
7219}
7220
7221/**********************************************************************/
7224static char *command_generator(const char *text, int state)
7225{
7226 return generic_generator(text, state, CMD_NUM, command_name_by_number);
7227}
7228
7229/**********************************************************************/
7232static char *option_generator(const char *text, int state)
7233{
7234 return generic_generator(text, state, settings_number(), optname_accessor);
7235}
7236
7237/**********************************************************************/
7240static char *olevel_generator(const char *text, int state)
7241{
7242 return generic_generator(text, state, settings_number() + OLEVELS_NUM + 1,
7244}
7245
7246/**********************************************************************/
7250static int completion_option;
7251static const char *option_value_accessor(int idx) {
7253
7254 switch (setting_type(pset)) {
7255 case SST_ENUM:
7256 return setting_enum_val(pset, idx, FALSE);
7257 case SST_BITWISE:
7258 return setting_bitwise_bit(pset, idx, FALSE);
7259 default:
7261 }
7262
7263 return NULL;
7264}
7265
7266/**********************************************************************/
7270static char *option_value_generator(const char *text, int state)
7271{
7272 return generic_generator(text, state, -1, option_value_accessor);
7273}
7274
7275/**********************************************************************/
7278static const char *playername_accessor(int idx)
7279{
7280 const struct player_slot *pslot = player_slot_by_number(idx);
7281
7282 if (!player_slot_is_used(pslot)) {
7283 return NULL;
7284 }
7285
7286 return player_name(player_slot_get_player(pslot));
7287}
7288
7289/**********************************************************************/
7292static char *player_generator(const char *text, int state)
7293{
7294 return generic_generator(text, state, player_slot_count(),
7296}
7297
7298/**********************************************************************/
7301static const char *connection_name_accessor(int idx)
7302{
7303 return conn_list_get(game.all_connections, idx)->username;
7304}
7305
7306/**********************************************************************/
7309static char *connection_generator(const char *text, int state)
7310{
7313}
7314
7315/**********************************************************************/
7318static const char *cmdlevel_arg1_accessor(int idx)
7319{
7320 return cmdlevel_name(idx);
7321}
7322
7323/**********************************************************************/
7326static char *cmdlevel_arg1_generator(const char *text, int state)
7327{
7328 return generic_generator(text, state, cmdlevel_max()+1,
7330}
7331
7332/**********************************************************************/
7336static const char *cmdlevel_arg2_accessor(int idx)
7337{
7338 return ((idx == 0) ? "first" :
7339 (idx == 1) ? "new" :
7340 connection_name_accessor(idx - 2));
7341}
7342
7343/**********************************************************************/
7346static char *cmdlevel_arg2_generator(const char *text, int state)
7347{
7348 return generic_generator(text, state,
7349 /* "first", "new", connection names */
7352}
7353
7354/**********************************************************************/
7357static const char *aitype_accessor(int idx)
7358{
7359 return get_ai_type(idx)->name;
7360}
7361
7362/**********************************************************************/
7365static char *aitype_generator(const char *text, int state)
7366{
7367 return generic_generator(text, state, ai_type_get_count(),
7369}
7370
7371/**********************************************************************/
7374static char *reset_generator(const char *text, int state)
7375{
7376 return generic_generator(text, state, reset_args_max() + 1, reset_accessor);
7377}
7378
7379/**********************************************************************/
7382static char *vote_generator(const char *text, int state)
7383{
7384 return generic_generator(text, state, -1, vote_arg_accessor);
7385}
7386
7387/**********************************************************************/
7390static char *delegate_generator(const char *text, int state)
7391{
7392 return generic_generator(text, state, delegate_args_max() + 1,
7394}
7395
7396/**********************************************************************/
7399static char *mapimg_generator(const char *text, int state)
7400{
7401 return generic_generator(text, state, mapimg_args_max() + 1,
7403}
7404
7405/**********************************************************************/
7408static char *fcdb_generator(const char *text, int state)
7409{
7410 return generic_generator(text, state, FCDB_COUNT, fcdb_accessor);
7411}
7412
7413/**********************************************************************/
7416static char *lua_generator(const char *text, int state)
7417{
7418 return generic_generator(text, state, lua_args_max() + 1, lua_accessor);
7419}
7420
7421/**********************************************************************/
7424static char *help_generator(const char *text, int state)
7425{
7426 return generic_generator(text, state, HELP_ARG_NUM, helparg_accessor);
7427}
7428
7429/**********************************************************************/
7432static char *list_generator(const char *text, int state)
7433{
7434 return generic_generator(text, state, list_args_max() + 1, list_accessor);
7435}
7436
7437/**********************************************************************/
7441static bool contains_token_before_start(int start, int token, const char *arg,
7442 bool allow_fluff)
7443{
7444 char *str_itr = rl_line_buffer;
7445 int arg_len = strlen(arg);
7446
7447 /* Swallow unwanted tokens and their preceding delimiters */
7448 while (token--) {
7449 while (str_itr < rl_line_buffer + start && !fc_isalnum(*str_itr)) {
7450 str_itr++;
7451 }
7452 while (str_itr < rl_line_buffer + start && fc_isalnum(*str_itr)) {
7453 str_itr++;
7454 }
7455 }
7456
7457 /* Swallow any delimiters before the token we're interested in */
7458 while (str_itr < rl_line_buffer + start && !fc_isalnum(*str_itr)) {
7459 str_itr++;
7460 }
7461
7462 if (fc_strncasecmp(str_itr, arg, arg_len) != 0) {
7463 return FALSE;
7464 }
7465 str_itr += arg_len;
7466
7467 if (fc_isalnum(*str_itr)) {
7468 /* Not a distinct word. */
7469 return FALSE;
7470 }
7471
7472 if (!allow_fluff) {
7473 for (; str_itr < rl_line_buffer + start; str_itr++) {
7474 if (fc_isalnum(*str_itr)) {
7475 return FALSE;
7476 }
7477 }
7478 }
7479
7480 return TRUE;
7481}
7482
7483/**********************************************************************/
7488static bool contains_str_before_start(int start, const char *cmd,
7489 bool allow_fluff)
7490{
7491 return contains_token_before_start(start, 0, cmd, allow_fluff);
7492}
7493
7494/**********************************************************************/
7498static bool is_command(int start)
7499{
7500 char *str_itr;
7501
7503 return TRUE;
7504
7505 /* if there is only it is also OK */
7507 while (str_itr - rl_line_buffer < start) {
7508 if (fc_isalnum(*str_itr)) {
7509 return FALSE;
7510 }
7511 str_itr++;
7512 }
7513 return TRUE;
7514}
7515
7516/**********************************************************************/
7519static int num_tokens(int start)
7520{
7521 int res = 0;
7522 bool alnum = FALSE;
7523 char *chptr = rl_line_buffer;
7524
7525 while (chptr - rl_line_buffer < start) {
7526 if (fc_isalnum(*chptr)) {
7527 if (!alnum) {
7528 alnum = TRUE;
7529 res++;
7530 }
7531 } else {
7532 alnum = FALSE;
7533 }
7534 chptr++;
7535 }
7536
7537 return res;
7538}
7539
7540/**************************************************************************
7541 Commands that may be followed by a player name
7542**************************************************************************/
7543static const int player_cmd[] = {
7546 CMD_NOVICE,
7547 CMD_EASY,
7548 CMD_NORMAL,
7549 CMD_HARD,
7551#ifdef FREECIV_DEBUG
7553#endif
7554 CMD_REMOVE,
7555 CMD_TEAM,
7557 -1
7558};
7559
7560/**********************************************************************/
7563static bool is_player(int start)
7564{
7565 int i = 0;
7566
7567 while (player_cmd[i] != -1) {
7569 return TRUE;
7570 }
7571 i++;
7572 }
7573
7574 return FALSE;
7575}
7576
7577/**************************************************************************
7578 Commands that may be followed by a connection name
7579**************************************************************************/
7580static const int connection_cmd[] = {
7581 CMD_CUT,
7582 CMD_KICK,
7583 -1
7584};
7585
7586/**********************************************************************/
7589static bool is_connection(int start)
7590{
7591 int i = 0;
7592
7593 while (connection_cmd[i] != -1) {
7594 if (contains_str_before_start(start,
7596 FALSE)) {
7597 return TRUE;
7598 }
7599 i++;
7600 }
7601
7602 return FALSE;
7603}
7604
7605/**********************************************************************/
7608static bool is_cmdlevel_arg2(int start)
7609{
7611 && num_tokens(start) == 2);
7612}
7613
7614/**********************************************************************/
7617static bool is_cmdlevel_arg1(int start)
7618{
7620}
7621
7622/**************************************************************************
7623 Commands that may be followed by a server option name
7624
7625 CMD_SHOW is handled by option_level_cmd, which is for both option levels
7626 and server options
7627**************************************************************************/
7628static const int server_option_cmd[] = {
7630 CMD_SET,
7632 -1
7633};
7634
7635/**********************************************************************/
7639static bool is_server_option(int start)
7640{
7641 int i = 0;
7642
7643 while (server_option_cmd[i] != -1) {
7645 FALSE)) {
7646 return TRUE;
7647 }
7648 i++;
7649 }
7650
7651 return FALSE;
7652}
7653
7654/**************************************************************************
7655 Commands that may be followed by an option level or server option
7656**************************************************************************/
7657static const int option_level_cmd[] = {
7658 CMD_SHOW,
7659 -1
7660};
7661
7662/**********************************************************************/
7666static bool is_option_level(int start)
7667{
7668 int i = 0;
7669
7670 while (option_level_cmd[i] != -1) {
7672 FALSE)) {
7673 return TRUE;
7674 }
7675 i++;
7676 }
7677
7678 return FALSE;
7679}
7680
7681/**********************************************************************/
7686static bool is_enum_option_value(int start, int *opt_p)
7687{
7689 TRUE)) {
7691 if (setting_type(pset) != SST_ENUM
7692 && setting_type(pset) != SST_BITWISE) {
7693 continue;
7694 }
7695 /* Allow a single token for enum options, multiple for bitwise
7696 * (the separator | will separate tokens for these purposes) */
7700 /* Suppress appended space for bitwise options (user may want |) */
7702 return TRUE;
7703 }
7705 }
7706 return FALSE;
7707}
7708
7709/**************************************************************************
7710 Commands that may be followed by a filename
7711**************************************************************************/
7712static const int filename_cmd[] = {
7713 CMD_LOAD,
7714 CMD_SAVE,
7717 -1
7718};
7719
7720/**********************************************************************/
7723static bool is_filename(int start)
7724{
7725 int i = 0;
7726
7727 while (filename_cmd[i] != -1) {
7729 return TRUE;
7730 }
7731 i++;
7732 }
7733
7734 return FALSE;
7735}
7736
7737/**********************************************************************/
7740static bool is_create_arg2(int start)
7741{
7743 && num_tokens(start) == 2);
7744}
7745
7746/**********************************************************************/
7749static bool is_reset(int start)
7750{
7751 return contains_str_before_start(start,
7753 FALSE);
7754}
7755
7756/**********************************************************************/
7759static bool is_vote(int start)
7760{
7761 return contains_str_before_start(start,
7763 FALSE);
7764}
7765
7766/**********************************************************************/
7769static bool is_delegate_arg1(int start)
7770{
7771 return contains_str_before_start(start,
7773 FALSE);
7774}
7775
7776/**********************************************************************/
7779static bool is_mapimg(int start)
7780{
7781 return contains_str_before_start(start,
7783 FALSE);
7784}
7785
7786/**********************************************************************/
7789static bool is_fcdb(int start)
7790{
7791 return contains_str_before_start(start,
7793 FALSE);
7794}
7795
7796/**********************************************************************/
7799static bool is_lua(int start)
7800{
7801 return contains_str_before_start(start,
7803 FALSE);
7804}
7805
7806/**********************************************************************/
7809static bool is_help(int start)
7810{
7812}
7813
7814/**********************************************************************/
7817static bool is_list(int start)
7818{
7820}
7821
7822/**********************************************************************/
7829char **freeciv_completion(const char *text, int start, int end)
7830{
7831 char **matches = (char **)NULL;
7832
7833 if (is_help(start)) {
7835 } else if (is_command(start)) {
7837 } else if (is_list(start)) {
7839 } else if (is_cmdlevel_arg2(start)) {
7841 } else if (is_cmdlevel_arg1(start)) {
7843 } else if (is_connection(start)) {
7845 } else if (is_player(start)) {
7847 } else if (is_server_option(start)) {
7849 } else if (is_option_level(start)) {
7851 } else if (is_enum_option_value(start, &completion_option)) {
7853 } else if (is_filename(start)) {
7854 /* This function we get from readline */
7856 } else if (is_create_arg2(start)) {
7858 } else if (is_reset(start)) {
7860 } else if (is_vote(start)) {
7862 } else if (is_delegate_arg1(start)) {
7864 } else if (is_mapimg(start)) {
7866 } else if (is_fcdb(start)) {
7868 } else if (is_lua(start)) {
7870 } else {
7871 /* We have no idea what to do */
7872 matches = NULL;
7873 }
7874
7875 /* Don't automatically try to complete with filenames */
7877
7878 return (matches);
7879}
7880
7881#endif /* FREECIV_HAVE_LIBREADLINE */
bool achievement_player_has(const struct achievement *pach, const struct player *pplayer)
int achievement_index(const struct achievement *pach)
#define achievements_iterate_end
#define achievements_iterate(_ach_)
const char * ai_name(const struct ai_type *ai)
Definition ai.c:335
struct ai_type * ai_type_by_name(const char *search)
Definition ai.c:290
int ai_type_get_count(void)
Definition ai.c:327
struct ai_type * get_ai_type(int id)
Definition ai.c:260
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
#define ai_type_iterate_end
Definition ai.h:372
#define ai_type_iterate(NAME_ai)
Definition ai.h:365
const char * default_ai_type_name(void)
Definition aiiface.c:249
void astr_free(struct astring *astr)
Definition astring.c:148
const char * astr_build_or_list(struct astring *astr, const char *const *items, size_t number)
Definition astring.c:313
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:251
#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
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_CLR(bv, bit)
Definition bitvector.h:94
#define SERVER_COMMAND_PREFIX
Definition chat.h:28
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define city_list_iterate(citylist, pcity)
Definition city.h:505
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
#define city_list_iterate_end
Definition city.h:507
enum cmd_echo command_echo(const struct command *pcommand)
Definition commands.c:802
const char * command_name_by_number(int i)
Definition commands.c:754
const char * command_name(const struct command *pcommand)
Definition commands.c:746
const struct command * command_by_number(int i)
Definition commands.c:737
const char * command_short_help(const struct command *pcommand)
Definition commands.c:770
char * command_extra_help(const struct command *pcommand)
Definition commands.c:779
enum cmdlevel command_level(const struct command *pcommand)
Definition commands.c:794
const char * command_synopsis(const struct command *pcommand)
Definition commands.c:762
command_id
Definition commands.h:35
@ CMD_NUM
Definition commands.h:109
@ CMD_UNLOCK
Definition commands.h:102
@ CMD_IGNORE
Definition commands.h:78
@ CMD_LOCK
Definition commands.h:101
@ CMD_METASERVER
Definition commands.h:58
@ CMD_END_GAME
Definition commands.h:84
@ CMD_DEFAULT
Definition commands.h:93
@ CMD_METAPATCHES
Definition commands.h:56
@ CMD_TEAM
Definition commands.h:53
@ CMD_DELEGATE
Definition commands.h:96
@ CMD_CHEATING
Definition commands.h:70
@ CMD_PLAYERCOLOR
Definition commands.h:80
@ CMD_LIST
Definition commands.h:39
@ CMD_AITOGGLE
Definition commands.h:59
@ CMD_CUT
Definition commands.h:41
@ CMD_EXPLAIN
Definition commands.h:44
@ CMD_SHOW
Definition commands.h:45
@ CMD_METAMESSAGE
Definition commands.h:55
@ CMD_RULESETDIR
Definition commands.h:54
@ CMD_HARD
Definition commands.h:69
@ CMD_RFCSTYLE
Definition commands.h:105
@ CMD_DETACH
Definition commands.h:62
@ CMD_NORMAL
Definition commands.h:68
@ CMD_RESTRICTED
Definition commands.h:65
@ CMD_VOTE
Definition commands.h:48
@ CMD_NOVICE
Definition commands.h:66
@ CMD_UNRECOGNIZED
Definition commands.h:110
@ CMD_TIMEOUT
Definition commands.h:76
@ CMD_CREATE
Definition commands.h:63
@ CMD_LOAD
Definition commands.h:89
@ CMD_AICMD
Definition commands.h:97
@ CMD_AMBIGUOUS
Definition commands.h:111
@ CMD_LUA
Definition commands.h:94
@ CMD_FCDB
Definition commands.h:98
@ CMD_CANCELVOTE
Definition commands.h:77
@ CMD_SAVE
Definition commands.h:87
@ CMD_SRVID
Definition commands.h:106
@ CMD_SCENSAVE
Definition commands.h:88
@ CMD_START_GAME
Definition commands.h:37
@ CMD_UNIGNORE
Definition commands.h:79
@ CMD_FIRSTLEVEL
Definition commands.h:75
@ CMD_WALL
Definition commands.h:46
@ CMD_EASY
Definition commands.h:67
@ CMD_KICK
Definition commands.h:95
@ CMD_WRITE_SCRIPT
Definition commands.h:91
@ CMD_CONNECTMSG
Definition commands.h:47
@ CMD_TAKE
Definition commands.h:60
@ CMD_HELP
Definition commands.h:38
@ CMD_REMOVE
Definition commands.h:86
@ CMD_OBSERVE
Definition commands.h:61
@ CMD_RESET
Definition commands.h:92
@ CMD_SURRENDER
Definition commands.h:85
@ CMD_METACONN
Definition commands.h:57
@ CMD_READ_SCRIPT
Definition commands.h:90
@ CMD_CMDLEVEL
Definition commands.h:74
@ CMD_SET
Definition commands.h:52
@ CMD_AWAY
Definition commands.h:64
@ CMD_QUIT
Definition commands.h:40
@ CMD_DEBUG
Definition commands.h:51
@ CMD_PLAYERNATION
Definition commands.h:81
@ CMD_MAPIMG
Definition commands.h:99
@ CMD_ECHO_ADMINS
Definition commands.h:22
@ CMD_ECHO_NONE
Definition commands.h:21
@ CMD_ECHO_ALL
Definition commands.h:23
char * incite_cost
Definition comments.c:76
#define MAX_LEN_MSG
Definition conn_types.h:37
bool connection_attach(struct connection *pconn, struct player *pplayer, bool observing)
bool connection_delegate_take(struct connection *pconn, struct player *dplayer)
struct player * find_uncontrolled_player(void)
void connection_close_server(struct connection *pconn, const char *reason)
void connection_detach(struct connection *pconn, bool remove_unused_player)
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
Definition connecthand.c:72
bool connection_delegate_restore(struct connection *pconn)
size_t conn_pattern_to_string(const struct conn_pattern *ppattern, char *buf, size_t buf_len)
Definition connection.c:865
struct player * conn_get_player(const struct connection *pconn)
Definition connection.c:763
struct connection * conn_by_user_prefix(const char *user_name, enum m_pre_result *result)
Definition connection.c:398
struct connection * conn_by_user(const char *user_name)
Definition connection.c:377
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:732
void conn_pattern_destroy(struct conn_pattern *ppattern)
Definition connection.c:809
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
struct conn_pattern * conn_pattern_from_string(const char *pattern, enum conn_pattern_type prefer, char *error_buf, size_t error_buf_len)
Definition connection.c:878
enum cmdlevel conn_get_access(const struct connection *pconn)
Definition connection.c:775
#define conn_pattern_list_iterate_end
Definition connection.h:338
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_pattern_list_iterate(plist, ppatern)
Definition connection.h:336
#define conn_list_iterate_end
Definition connection.h:110
bool con_get_style(void)
Definition console.c:264
void con_set_style(bool i)
Definition console.c:251
void con_write(enum rfc_status rfc_status, const char *message,...)
Definition console.c:203
rfc_status
Definition console.h:35
@ C_DISCONNECTED
Definition console.h:43
@ C_BOUNCE
Definition console.h:48
@ C_FAIL
Definition console.h:45
@ C_SYNTAX
Definition console.h:47
@ C_OK
Definition console.h:41
@ C_METAERROR
Definition console.h:46
@ C_GENFAIL
Definition console.h:49
@ C_COMMENT
Definition console.h:37
@ C_WARNING
Definition console.h:50
#define MAX_LEN_CONSOLE_LINE
Definition console.h:19
#define log_deprecation(message,...)
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
int int id
Definition editgui_g.h:28
void free_tokens(char **tokens, size_t ntokens)
Definition fc_cmdline.c:203
int get_tokens(const char *str, char **tokens, size_t num_tokens, const char *delimiterset)
Definition fc_cmdline.c:166
#define RULESET_SUFFIX
Definition fc_types.h:271
#define MAX_LEN_NAME
Definition fc_types.h:66
#define LINE_BREAK
Definition fc_types.h:77
char * internal_to_local_string_malloc(const char *text)
char * local_to_internal_string_malloc(const char *text)
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
const struct ft_color ftc_log
const struct ft_color ftc_command
const struct ft_color ftc_server
const struct ft_color ftc_any
VAR_ARG_CONST struct ft_color ftc_changed
const struct ft_color ftc_vote_team
const struct ft_color ftc_game_start
const struct ft_color ftc_server_prompt
const struct ft_color ftc_vote_public
#define FT_OFFSET_UNSET
@ TTT_COLOR
struct civ_game game
Definition game.c:61
struct world wld
Definition game.c:62
struct unit * game_unit_by_number(int id)
Definition game.c:115
@ DEBUG_FERRIES
Definition game.h:40
#define GAME_MAX_READ_RECURSION
Definition game.h:753
void send_scenario_description(struct conn_list *dest)
Definition gamehand.c:967
void send_scenario_info(struct conn_list *dest)
Definition gamehand.c:953
void send_game_info(struct conn_list *dest)
Definition gamehand.c:910
void cache_rulesets(void)
Definition gamehand.c:1136
struct city * owner
Definition citydlg.c:226
static GtkWidget * persistent
const char * title
Definition repodlgs.c:1314
static char * leader_name
Definition dialogs.c:97
void handle_player_ready(struct player *pplayer, int player_no, bool is_ready)
Definition srv_main.c:2453
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define __FC_LINE__
Definition log.h:41
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define log_testmatic_alt(altlvl, message,...)
Definition log.h:125
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_normal(message,...)
Definition log.h:108
@ LOG_NORMAL
Definition log.h:33
#define log_error(message,...)
Definition log.h:104
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:434
int map_startpos_count(void)
Definition map.c:2008
bool map_is_empty(void)
Definition map.c:148
bool mapimg_id2str(int id, char *str, size_t str_len)
Definition mapimg.c:1314
bool mapimg_colortest(const char *savename, const char *path)
Definition mapimg.c:1441
struct mapdef * mapimg_isvalid(int id)
Definition mapimg.c:1124
bool mapimg_define(const char *maparg, bool check)
Definition mapimg.c:769
bool mapimg_delete(int id)
Definition mapimg.c:1207
int mapimg_count(void)
Definition mapimg.c:573
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
Definition mapimg.c:1335
const char * mapimg_error(void)
Definition mapimg.c:759
bool mapimg_show(int id, char *str, size_t str_len, bool detail)
Definition mapimg.c:1226
#define MAX_LEN_MAPDEF
Definition mapimg.h:65
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
void set_meta_patches_string(const char *string)
Definition meta.c:172
bool is_metaserver_open(void)
Definition meta.c:483
char * meta_addr_port(void)
Definition meta.c:203
void server_close_meta(void)
Definition meta.c:455
const char * default_meta_patches_string(void)
Definition meta.c:83
bool send_server_info_to_metaserver(enum meta_flag flag)
Definition meta.c:491
bool server_open_meta(bool persistent)
Definition meta.c:464
const char * get_meta_patches_string(void)
Definition meta.c:107
void set_user_meta_message_string(const char *string)
Definition meta.c:188
#define DEFAULT_META_SERVER_ADDR
Definition meta.h:21
@ META_GOODBYE
Definition meta.h:28
@ META_INFO
Definition meta.h:26
void modpack_ruleset_cache_iterate(mrc_cb cb, void *data)
Definition modpack.c:346
const char * modpack_file_from_ruleset_cache(const char *name)
Definition modpack.c:295
const char * modpack_serv_file(struct section_file *sf)
Definition modpack.c:189
const char * modpack_rulesetdir(struct section_file *sf)
Definition modpack.c:204
#define translated
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Definition nation.c:1206
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
const char * nation_set_name_translation(const struct nation_set *pset)
Definition nation.c:818
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
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:837
const char * nation_set_description(const struct nation_set *pset)
Definition nation.c:828
int nation_set_count(void)
Definition nation.c:691
struct nation_type * nation_by_rule_name(const char *name)
Definition nation.c:121
const char * nation_plural_translation(const struct nation_type *pnation)
Definition nation.c:159
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:807
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_sets_iterate_end
Definition nation.h:305
#define nation_sets_iterate(NAME_pset)
Definition nation.h:301
#define nations_iterate_end
Definition nation.h:336
#define nations_iterate(NAME_pnation)
Definition nation.h:333
#define NO_NATION_SELECTED
Definition nation.h:30
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 notify_team(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:345
void package_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:168
void event_cache_add_for_all(const struct packet_chat_msg *packet)
Definition notify.c:619
int send_packet_chat_msg(struct connection *pc, const struct packet_chat_msg *packet)
void dlsend_packet_game_load(struct conn_list *dest, bool load_successful, const char *load_filename)
void lsend_packet_achievement_info(struct conn_list *dest, const struct packet_achievement_info *packet)
struct city_list * cities
Definition packhand.c:119
int len
Definition packhand.c:127
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:448
struct player * player_by_name_prefix(const char *name, enum m_pre_result *result)
Definition player.c:920
struct player * player_by_number(const int player_id)
Definition player.c:849
int player_count(void)
Definition player.c:817
int player_slot_count(void)
Definition player.c:418
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:463
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
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 * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
#define ai_level_cmd(_level_)
Definition player.h:572
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
#define player_list_iterate(playerlist, pplayer)
Definition player.h:560
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define is_ai(plr)
Definition player.h:232
#define player_list_iterate_end
Definition player.h:562
#define set_as_human(plr)
Definition player.h:233
#define set_as_ai(plr)
Definition player.h:234
#define ANON_PLAYER_NAME
Definition player.h:43
@ PLAYER_DEBUG_DIPLOMACY
Definition player.h:215
@ PLAYER_DEBUG_TECH
Definition player.h:215
#define is_human(plr)
Definition player.h:231
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2270
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1896
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3217
int normal_player_count(void)
Definition plrhand.c:3209
void player_set_under_human_control(struct player *pplayer)
Definition plrhand.c:3458
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition plrhand.c:1825
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Definition plrhand.c:3436
bool server_player_set_name_full(const struct connection *caller, struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Definition plrhand.c:2170
bool player_delegation_active(const struct player *pplayer)
Definition plrhand.c:3271
void player_info_thaw(void)
Definition plrhand.c:1110
void player_info_freeze(void)
Definition plrhand.c:1101
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2458
const char * player_color_ftstr(struct player *pplayer)
Definition plrhand.c:1845
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1148
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3225
void player_delegation_set(struct player *pplayer, const char *username)
Definition plrhand.c:3255
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1945
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1620
bool player_color_changeable(const struct player *pplayer, const char **reason)
Definition plrhand.c:1718
void assign_player_colors(void)
Definition plrhand.c:1736
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2619
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1214
const char * player_delegation_get(const struct player *pplayer)
Definition plrhand.c:3242
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2595
void reset_all_start_commands(bool plrchange)
Definition plrhand.c:2729
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:51
const char * secfile_error(void)
void secfile_destroy(struct section_file *secfile)
void secfile_check_unused(const struct section_file *secfile)
struct section_file * secfile_load_section(const char *filename, const char *section, bool allow_duplicates)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
struct research * research_get(const struct player *pplayer)
Definition research.c:128
bool rgbcolor_from_hex(struct rgbcolor **prgbcolor, const char *hex)
Definition rgbcolor.c:162
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
bool rgbcolors_are_equal(const struct rgbcolor *c1, const struct rgbcolor *c2)
Definition rgbcolor.c:62
bool load_rulesets(const char *restore, const char *alt, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleload.c:9201
bool reload_rulesets_settings(void)
Definition ruleload.c:9529
void send_rulesets(struct conn_list *dest)
Definition ruleload.c:9552
#define sanity_check()
Definition sanitycheck.h:43
void savegame_load(struct section_file *sfile)
Definition savemain.c:43
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:143
void script_fcdb_free(void)
bool script_fcdb_do_string(struct connection *caller, const char *str)
bool script_fcdb_call(const char *func_name,...)
bool script_fcdb_init(const char *fcdb_luafile)
bool script_server_unsafe_do_string(struct connection *caller, const char *str)
bool script_server_do_string(struct connection *caller, const char *str)
bool script_server_unsafe_do_file(struct connection *caller, const char *filename)
bool script_server_do_file(struct connection *caller, const char *filename)
bool setting_int_validate(const struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3763
void setting_action(const struct setting *pset)
Definition settings.c:4369
void setting_admin_lock_clear(struct setting *pset)
Definition settings.c:4688
const char * setting_default_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4303
bool setting_enum_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4051
struct setting * setting_by_name(const char *name)
Definition settings.c:3309
void setting_set_to_default(struct setting *pset)
Definition settings.c:4339
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4267
const char * setting_extra_help(const struct setting *pset, bool constant)
Definition settings.c:3350
int setting_number(const struct setting *pset)
Definition settings.c:3324
struct setting * setting_by_number(int id)
Definition settings.c:3301
bool setting_int_set(struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3743
bool setting_is_visible(const struct setting *pset, struct connection *caller)
Definition settings.c:3506
bool setting_locked(const struct setting *pset)
Definition settings.c:4640
bool setting_non_default(const struct setting *pset)
Definition settings.c:4614
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3362
void setting_admin_lock_set(struct setting *pset)
Definition settings.c:4668
bool setting_str_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3814
int setting_int_max(const struct setting *pset)
Definition settings.c:3733
bool setting_bitwise_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4223
int settings_number(void)
Definition settings.c:5266
bool setting_str_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3834
const char * setting_enum_val(const struct setting *pset, int val, bool pretty)
Definition settings.c:3893
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
void setting_changed(struct setting *pset)
Definition settings.c:5604
enum setting_default_level setting_get_setdef(const struct setting *pset)
Definition settings.c:5612
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4022
const char * setting_short_help(const struct setting *pset)
Definition settings.c:3341
const char * setting_bitwise_bit(const struct setting *pset, int bit, bool pretty)
Definition settings.c:4088
int setting_int_min(const struct setting *pset)
Definition settings.c:3724
bool setting_bitwise_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4244
bool setting_bool_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3688
bool setting_is_changeable(const struct setting *pset, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3460
void settings_reset(void)
Definition settings.c:5232
const char * setting_name(const struct setting *pset)
Definition settings.c:3333
bool settings_game_reset(void)
Definition settings.c:5195
void settings_list_update(void)
Definition settings.c:5533
bool setting_bool_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3657
void send_server_setting(struct conn_list *dest, const struct setting *pset)
Definition settings.c:5275
void send_server_settings(struct conn_list *dest)
Definition settings.c:5394
#define settings_iterate(_level, _pset)
Definition settings.h:188
#define settings_iterate_end
Definition settings.h:194
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
void remove_trailing_spaces(char *s)
Definition shared.c:422
bool str_to_int(const char *str, int *pint)
Definition shared.c:515
const char * m_pre_description(enum m_pre_result result)
Definition shared.c:1564
struct strvec * fileinfolist(const struct strvec *dirs, const char *suffix)
Definition shared.c:1020
char * skip_leading_spaces(char *s)
Definition shared.c:392
enum m_pre_result match_prefix_full(m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result, int *matches, int max_matches, int *pnum_matches)
Definition shared.c:1606
const struct strvec * get_scenario_dirs(void)
Definition shared.c:971
void interpret_tilde(char *buf, size_t buf_size, const char *filename)
Definition shared.c:1713
const struct strvec * get_save_dirs(void)
Definition shared.c:934
void remove_leading_spaces(char *s)
Definition shared.c:405
enum m_pre_result match_prefix(m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result)
Definition shared.c:1583
bool is_safe_filename(const char *name)
Definition shared.c:256
void remove_leading_trailing_spaces(char *s)
Definition shared.c:444
const struct strvec * get_data_dirs(void)
Definition shared.c:886
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)
Definition shared.c:1204
#define CLIP(lower, current, upper)
Definition shared.h:57
#define FC_MEMBER_SIZEOF(type, member)
Definition shared.h:90
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MIN(x, y)
Definition shared.h:55
#define fileinfo_list_iterate(list, pnode)
Definition shared.h:182
#define MAX_LEN_PATH
Definition shared.h:32
m_pre_result
Definition shared.h:213
@ M_PRE_EXACT
Definition shared.h:214
@ M_PRE_ONLY
Definition shared.h:215
@ M_PRE_LAST
Definition shared.h:220
@ M_PRE_LONG
Definition shared.h:218
@ M_PRE_AMBIGUOUS
Definition shared.h:216
@ M_PRE_EMPTY
Definition shared.h:217
@ M_PRE_FAIL
Definition shared.h:219
#define fileinfo_list_iterate_end
Definition shared.h:184
const char *(* m_pre_accessor_fn_t)(int)
Definition shared.h:226
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
#define UNIT_LOG(loglevel, punit, msg,...)
Definition srv_log.h:98
#define TIMING_RESULTS()
Definition srv_log.h:126
void server_game_init(bool keep_ruleset_value)
Definition srv_main.c:3498
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2622
bool force_end_of_sniff
Definition srv_main.c:193
void start_game(void)
Definition srv_main.c:1878
const char * aifill(int amount)
Definition srv_main.c:2507
void set_server_state(enum server_states newstate)
Definition srv_main.c:346
bool game_was_started(void)
Definition srv_main.c:354
struct server_arguments srvarg
Definition srv_main.c:181
void check_for_full_turn_done(void)
Definition srv_main.c:2257
void fc__noreturn server_quit(void)
Definition srv_main.c:1915
enum server_states server_state(void)
Definition srv_main.c:338
void server_game_free(void)
Definition srv_main.c:3522
#define TOKEN_DELIMITERS
Definition srvdefs.h:20
static bool write_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:1338
static const char * reset_accessor(int i)
Definition stdinhand.c:4832
static bool set_cmdlevel(struct connection *caller, struct connection *ptarget, enum cmdlevel level)
Definition stdinhand.c:1377
static struct setting * validate_setting_arg(enum command_id cmd, struct connection *caller, char *arg)
Definition stdinhand.c:2929
#define LOOKUP_OPTION_AMBIGUOUS
Definition stdinhand.c:1728
static const char * mapimg_accessor(int i)
Definition stdinhand.c:5681
void cmd_reply(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *format,...)
Definition stdinhand.c:420
static bool set_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2963
static enum command_id cmd_of_level(enum ai_level level)
Definition stdinhand.c:1980
static void show_delegations(struct connection *caller)
Definition stdinhand.c:6689
static char setting_status(struct connection *caller, const struct setting *pset)
Definition stdinhand.c:307
static void show_scenarios(struct connection *caller)
Definition stdinhand.c:6915
static bool delegate_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5191
static bool ignore_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4076
static void show_help_command(struct connection *caller, enum command_id help_cmd, enum command_id id)
Definition stdinhand.c:6443
void set_running_game_access_level(void)
Definition stdinhand.c:1632
void notify_if_first_access_level_is_available(void)
Definition stdinhand.c:1448
static const char * lua_accessor(int i)
Definition stdinhand.c:4992
static const char * fcdb_accessor(int i)
Definition stdinhand.c:5992
static void show_help_command_list(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:6489
void stdinhand_turn(void)
Definition stdinhand.c:256
static void show_connections(struct connection *caller)
Definition stdinhand.c:6663
static bool explain_option(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1894
static struct kick_hash * kick_table_by_user
Definition stdinhand.c:117
static void show_ais(struct connection *caller)
Definition stdinhand.c:7029
bool conn_is_kicked(struct connection *pconn, int *time_remaining)
Definition stdinhand.c:6281
enum rfc_status create_command_newcomer(const char *name, const char *ai, bool check, struct nation_type *pnation, struct player **newplayer, char *buf, size_t buflen)
Definition stdinhand.c:812
static void show_colors(struct connection *caller)
Definition stdinhand.c:7044
static bool set_ai_level(struct connection *caller, const char *name, enum ai_level level, bool check)
Definition stdinhand.c:2027
static struct kick_hash * kick_table_by_addr
Definition stdinhand.c:116
static void show_help_option_list(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:1858
static bool lock_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3143
void stdinhand_init(void)
Definition stdinhand.c:243
static bool take_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3493
static bool wall(char *str, bool check)
Definition stdinhand.c:1927
static enum cmdlevel default_access_level
Definition stdinhand.c:98
static void show_ruleset_info(struct connection *caller, enum command_id cmd, bool check, int read_recursion)
Definition stdinhand.c:2124
void show_players(struct connection *caller)
Definition stdinhand.c:6753
static void cmd_reply_matches(enum command_id cmd, struct connection *caller, m_pre_accessor_fn_t accessor_fn, int *matches, int num_matches)
Definition stdinhand.c:6527
#define LOOKUP_OPTION_NO_RESULT
Definition stdinhand.c:1727
static const char * list_accessor(int i)
Definition stdinhand.c:7093
static int lookup_option(const char *name)
Definition stdinhand.c:1739
static bool reset_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:4842
static void show_teams(struct connection *caller)
Definition stdinhand.c:6978
static bool handle_stdin_input_real(struct connection *caller, char *str, bool check, int read_recursion)
Definition stdinhand.c:4453
enum rfc_status create_command_pregame(const char *name, const char *ai, bool check, struct player **newplayer, char *buf, size_t buflen)
Definition stdinhand.c:996
static bool metaconnection_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:529
static bool show_serverid(struct connection *caller, char *arg)
Definition stdinhand.c:662
static void show_nationsets(struct connection *caller)
Definition stdinhand.c:6941
static const char * helparg_accessor(int i)
Definition stdinhand.c:6583
static bool metamessage_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:610
static bool away_command(struct connection *caller, bool check)
Definition stdinhand.c:2083
enum cmdlevel access_level_for_next_connection(void)
Definition stdinhand.c:1434
static bool playercolor_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4200
bool handle_stdin_input_free(struct connection *caller, char *str)
Definition stdinhand.c:4434
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2002
static bool player_name_check(const char *name, char *buf, size_t buflen)
Definition stdinhand.c:193
static bool default_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:4949
static bool create_command(struct connection *caller, const char *str, bool check)
Definition stdinhand.c:754
static void vcmd_reply_prefix(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *prefix, const char *format, va_list ap)
Definition stdinhand.c:380
static const char * delegate_accessor(int i)
Definition stdinhand.c:5182
static void show_rulesets(struct connection *caller)
Definition stdinhand.c:6892
static bool surrender_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4784
static bool end_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4759
static const char * delegate_player_str(struct player *pplayer, bool observer)
Definition stdinhand.c:5642
static void cmd_reply_prefix(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *prefix, const char *format,...) fc__attribute((__format__(__printf__
#define LOOKUP_OPTION_RULESETDIR
Definition stdinhand.c:1730
static bool timeout_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1669
static void cmd_reply_no_such_player(enum command_id cmd, struct connection *caller, const char *name, enum m_pre_result match_result)
Definition stdinhand.c:433
static bool metaserver_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:644
bool handle_stdin_input(struct connection *caller, char *str)
Definition stdinhand.c:4426
static bool cut_client_connection(struct connection *caller, char *name, bool check)
Definition stdinhand.c:6238
static void open_metaserver_connection(struct connection *caller, bool persistent)
Definition stdinhand.c:502
#define HELP_ARG_NUM
Definition stdinhand.c:6578
static time_t * time_duplicate(const time_t *t)
Definition stdinhand.c:6270
static void show_mapimg(struct connection *caller, enum command_id cmd)
Definition stdinhand.c:7008
static bool may_use_nothing(struct connection *caller)
Definition stdinhand.c:295
static void show_votes(struct connection *caller)
Definition stdinhand.c:2472
static const char *const vote_args[]
Definition stdinhand.c:2507
static bool show_settings(struct connection *caller, enum command_id called_as, char *str, bool check)
Definition stdinhand.c:2159
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
Definition stdinhand.c:1169
static bool unlock_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3171
static bool a_connection_exists(void)
Definition stdinhand.c:1412
void stdinhand_free(void)
Definition stdinhand.c:264
static bool cmdlevel_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1462
static bool is_first_access_level_taken(void)
Definition stdinhand.c:1420
#define LOOKUP_OPTION_LEVEL_NAME
Definition stdinhand.c:1729
static bool firstlevel_command(struct connection *caller, bool check)
Definition stdinhand.c:1605
static void start_cmd_reply(struct connection *caller, bool notify, char *msg)
Definition stdinhand.c:6104
static bool connectmsg_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1939
static const char horiz_line[]
Definition stdinhand.c:177
static void cmd_reply_no_such_conn(enum command_id cmd, struct connection *caller, const char *name, enum m_pre_result match_result)
Definition stdinhand.c:468
static void cmd_reply_line(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *prefix, const char *line)
Definition stdinhand.c:333
static void show_help_intro(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:6410
static bool cancelvote_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:2626
bool set_rulesetdir(struct connection *caller, const char *str, bool check, int read_recursion)
Definition stdinhand.c:3975
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Definition stdinhand.c:3788
static bool read_init_script_real(struct connection *caller, const char *script_filename, bool from_cmdline, bool check, int read_recursion)
Definition stdinhand.c:1187
static void show_settings_one(struct connection *caller, enum command_id cmd, struct setting *pset)
Definition stdinhand.c:2331
static bool toggle_ai_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:731
static bool playernation_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4285
static bool team_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2395
static bool quit_game(struct connection *caller, bool check)
Definition stdinhand.c:4412
static bool vote_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2521
#define cmd_reply_show(string)
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6115
static const char * optname_accessor(int i)
Definition stdinhand.c:1645
static bool show_help(struct connection *caller, char *arg)
Definition stdinhand.c:6601
#define OPTION_NAME_SPACE
Definition stdinhand.c:96
struct strvec * get_init_script_choices(void)
Definition stdinhand.c:1270
static bool remove_player_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:1123
static void ruleset_cache_listcmd_cb(const char *mp_name, const char *filename, void *data_in)
Definition stdinhand.c:6853
static bool debug_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2721
static enum command_id command_named(const char *token, bool accept_ambiguity)
Definition stdinhand.c:223
static bool fcdb_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:6001
static bool mapimg_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5690
static bool unignore_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4111
static bool observe_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3345
static bool show_list(struct connection *caller, char *arg)
Definition stdinhand.c:7102
static bool scensave_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:690
static enum sset_level lookup_option_level(const char *name)
Definition stdinhand.c:1713
static bool may_use(struct connection *caller, enum command_id cmd)
Definition stdinhand.c:283
static bool kick_command(struct connection *caller, char *name, bool check)
Definition stdinhand.c:6329
static const char * vote_arg_accessor(int i)
Definition stdinhand.c:2513
static bool is_restricted(struct connection *caller)
Definition stdinhand.c:184
const char * script_extension
Definition stdinhand.c:114
static bool show_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2149
static bool lua_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:5001
static bool write_init_script(char *script_filename)
Definition stdinhand.c:1280
static enum cmdlevel first_access_level
Definition stdinhand.c:99
static bool detach_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3682
static bool aicmd_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5918
static void close_metaserver_connection(struct connection *caller)
Definition stdinhand.c:516
static bool save_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:673
static bool set_ai_level_named(struct connection *caller, const char *name, const char *level_name, bool check)
Definition stdinhand.c:2016
static bool metapatches_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:585
static bool show_ignore(struct connection *caller)
Definition stdinhand.c:6723
static bool is_allowed_to_take(struct connection *requester, struct connection *taker, struct player *pplayer, bool will_obs, char *msg, size_t msg_len)
Definition stdinhand.c:3203
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:706
static void show_help_option(struct connection *caller, enum command_id help_cmd, int id)
Definition stdinhand.c:1768
static bool read_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:1160
Definition ai.h:50
struct ai_type::@15 funcs
void(* gained_control)(struct player *pplayer)
Definition ai.h:108
char name[MAX_LEN_NAME]
Definition ai.h:51
void(* player_console)(struct player *pplayer, const char *cmd)
Definition ai.h:105
Definition city.h:317
struct city::@18::@20 server
int kick_time
Definition game.h:160
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:196
bool debug[DEBUG_LAST]
Definition game.h:209
char connectmsg[MAX_LEN_MSG]
Definition game.h:226
char * ruleset_summary
Definition game.h:84
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
int min_players
Definition game.h:173
int timeoutcounter
Definition game.h:214
char rulesetdir[MAX_LEN_NAME]
Definition game.h:246
struct packet_scenario_info scenario
Definition game.h:87
int timeoutint
Definition game.h:210
struct conn_list * all_connections
Definition game.h:96
char save_name[MAX_LEN_NAME]
Definition game.h:227
int timeoutincmult
Definition game.h:212
struct civ_game::@32::@36 server
int timeoutinc
Definition game.h:211
char allow_take[MAX_LEN_ALLOW_TAKE]
Definition game.h:248
bool start_city
Definition game.h:197
int max_players
Definition game.h:163
int timeoutintinc
Definition game.h:213
Definition colors.h:21
struct player * playing
Definition connection.h:151
struct connection::@61::@67 server
enum cmdlevel access_level
Definition connection.h:177
struct conn_list * self
Definition connection.h:163
bool observer
Definition connection.h:147
char username[MAX_LEN_NAME]
Definition connection.h:164
enum auth_status status
Definition connection.h:217
char ipaddr[MAX_LEN_ADDR]
Definition connection.h:221
struct connection::@61::@67::@68 delegation
struct conn_pattern_list * ignore_list
Definition connection.h:230
struct connection * caller
Definition stdinhand.c:6847
struct player * player
Definition nation.h:118
char message[MAX_LEN_MSG]
enum ai_level skill_level
enum ai_level skill_level
Definition player.h:116
bool random_name
Definition player.h:295
struct player_ai ai_common
Definition player.h:288
bv_pstatus status
Definition player.h:322
bool is_male
Definition player.h:257
struct government * target_government
Definition player.h:259
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_connected
Definition player.h:296
struct government * government
Definition player.h:258
bool was_created
Definition player.h:294
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
struct player::@73::@75 server
struct nation_style * style
Definition player.h:279
bv_debug debug
Definition player.h:332
struct rgbcolor * rgb
Definition player.h:312
bool unassigned_user
Definition player.h:253
char metaserver_addr[256]
Definition srv_main.h:29
char load_filename[512]
Definition srv_main.h:44
char * saves_pathname
Definition srv_main.h:46
char * script_filename
Definition srv_main.h:45
char serverid[256]
Definition srv_main.h:49
char *const value
Definition settings.c:147
Definition map.c:40
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition timing.c:81
Definition unit.h:140
bool debug
Definition unit.h:237
struct unit::@84::@87 server
Definition voting.h:46
int vote_no
Definition voting.h:52
struct civ_map map
struct nation_style * style_by_rule_name(const char *name)
Definition style.c:117
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:886
FILE * fc_fopen(const char *filename, const char *opentype)
Definition support.c:505
int fc_break_lines(char *str, size_t desired_len)
Definition support.c:1135
int fc_stat(const char *filename, struct stat *buf)
Definition support.c:574
bool is_reg_file_for_access(const char *name, bool write_access)
Definition support.c:1120
bool fc_isalnum(char c)
Definition support.c:1196
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Definition support.c:235
#define sz_strlcpy(dest, src)
Definition support.h:195
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
#define fc_strncmp(_s1_, _s2_, _len_)
Definition support.h:160
#define fc__fallthrough
Definition support.h:119
int team_index(const struct team *pteam)
Definition team.c:383
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
struct team_slot * team_slot_by_number(int team_id)
Definition team.c:175
const char * team_slot_name_translation(const struct team_slot *tslot)
Definition team.c:253
bool team_add_player(struct player *pplayer, struct team *pteam)
Definition team.c:467
struct team * team_new(struct team_slot *tslot)
Definition team.c:317
struct team_slot * team_slot_by_rule_name(const char *team_name)
Definition team.c:189
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
void team_remove_player(struct player *pplayer)
Definition team.c:502
#define teams_iterate_end
Definition team.h:87
#define teams_iterate(_pteam)
Definition team.h:82
void init_tech(struct research *research, bool update)
Definition techtools.c:1094
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1188
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
void timer_destroy(struct timer *t)
Definition timing.c:208
void timer_start(struct timer *t)
Definition timing.c:263
struct timer * timer_new(enum timer_timetype type, enum timer_use use, const char *name)
Definition timing.c:160
double timer_read_seconds(struct timer *t)
Definition timing.c:379
@ TIMER_ACTIVE
Definition timing.h:46
@ TIMER_CPU
Definition timing.h:41
@ TIMER_USER
Definition timing.h:42
#define unit_owner(_pu)
Definition unit.h:406
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1573
int describe_vote(struct vote *pvote, char *buf, int buflen)
Definition voting.c:748
bool conn_can_vote(const struct connection *pconn, const struct vote *pvote)
Definition voting.c:248
struct vote * vote_new(struct connection *caller, const char *allargs, int command_id)
Definition voting.c:338
bool vote_is_team_only(const struct vote *pvote)
Definition voting.c:235
struct vote * get_vote_by_no(int vote_no)
Definition voting.c:301
int vote_number_sequence
Definition voting.c:42
bool vote_would_pass_immediately(const struct connection *caller, int command_id)
Definition voting.c:391
void clear_all_votes(void)
Definition voting.c:219
struct vote * get_vote_by_caller(const struct connection *caller)
Definition voting.c:319
void connection_vote(struct connection *pconn, struct vote *pvote, enum vote_type type)
Definition voting.c:663
struct vote_list * vote_list
Definition voting.c:41
const struct connection * vote_get_caller(const struct vote *pvote)
Definition voting.c:891
int count_voters(const struct vote *pvote)
Definition voting.c:48
void remove_vote(struct vote *pvote)
Definition voting.c:205
bool conn_can_see_vote(const struct connection *pconn, const struct vote *pvote)
Definition voting.c:272
@ VOTE_ABSTAIN
Definition voting.h:27
@ VOTE_YES
Definition voting.h:27
@ VOTE_NUM
Definition voting.h:27
@ VOTE_NO
Definition voting.h:27
#define vote_list_iterate_end
Definition voting.h:65
@ VCF_NODISSENT
Definition voting.h:20
#define vote_list_iterate(alist, pvote)
Definition voting.h:63