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/advisors */
84#include "advdata.h"
85
86/* server/savegame */
87#include "savemain.h"
88
89/* server/scripting */
90#include "script_server.h"
91#include "script_fcdb.h"
92
93/* ai */
94#include "difficulty.h"
95#include "handicaps.h"
96
97#include "stdinhand.h"
98
99#define OPTION_NAME_SPACE 25
100
103
104static time_t *time_duplicate(const time_t *t);
105
106/* 'struct kick_hash' and related functions. */
107#define SPECHASH_TAG kick
108#define SPECHASH_ASTR_KEY_TYPE
109#define SPECHASH_IDATA_TYPE time_t *
110#define SPECHASH_UDATA_TYPE time_t
111#define SPECHASH_IDATA_COPY time_duplicate
112#define SPECHASH_IDATA_FREE (kick_hash_data_free_fn_t) free
113#define SPECHASH_UDATA_TO_IDATA(t) (&(t))
114#define SPECHASH_IDATA_TO_UDATA(p) (NULL != p ? *p : 0)
115#include "spechash.h"
116
117const char *script_extension = ".serv";
118
121
122
123static bool cut_client_connection(struct connection *caller, char *name,
124 bool check);
125static bool show_help(struct connection *caller, char *arg);
126static bool show_list(struct connection *caller, char *arg);
127static void show_ais(struct connection *caller);
128static void show_colors(struct connection *caller);
129static bool set_ai_level_named(struct connection *caller, const char *name,
130 const char *level_name, bool check);
131static bool set_ai_level(struct connection *caller, const char *name,
132 enum ai_level level, bool check);
133static bool away_command(struct connection *caller, bool check);
134static bool show_command(struct connection *caller, char *str, bool check);
135static bool show_settings(struct connection *caller,
137 char *str, bool check);
138static void show_settings_one(struct connection *caller, enum command_id cmd,
139 struct setting *pset);
140static void show_ruleset_info(struct connection *caller, enum command_id cmd,
141 bool check, int read_recursion);
142static void show_mapimg(struct connection *caller, enum command_id cmd);
143static bool set_command(struct connection *caller, char *str, bool check);
144static bool lock_command(struct connection *caller, char *str, bool check);
145static bool unlock_command(struct connection *caller, char *str, bool check);
146
147static bool create_command(struct connection *caller, const char *str,
148 bool check);
149static bool end_command(struct connection *caller, char *str, bool check);
150static bool surrender_command(struct connection *caller, char *str, bool check);
151static bool handle_stdin_input_real(struct connection *caller, char *str,
152 bool check, int read_recursion);
153static bool read_init_script_real(struct connection *caller,
154 const char *script_filename, bool from_cmdline,
155 bool check, int read_recursion);
156static bool reset_command(struct connection *caller, char *arg, bool check,
157 int read_recursion);
158static bool default_command(struct connection *caller, char *arg, bool check);
159static bool lua_command(struct connection *caller, char *arg, bool check,
160 int read_recursion);
161static bool kick_command(struct connection *caller, char *name, bool check);
162static bool delegate_command(struct connection *caller, char *arg,
163 bool check);
164static const char *delegate_player_str(struct player *pplayer, bool observer);
165static bool aicmd_command(struct connection *caller, char *arg, bool check);
166static bool fcdb_command(struct connection *caller, char *arg, bool check);
167static const char *fcdb_accessor(int i);
168static char setting_status(struct connection *caller,
169 const struct setting *pset);
170static bool player_name_check(const char *name, char *buf, size_t buflen);
171static bool playercolor_command(struct connection *caller,
172 char *str, bool check);
173static bool playernation_command(struct connection *caller,
174 char *str, bool check);
175static bool mapimg_command(struct connection *caller, char *arg, bool check);
176static const char *mapimg_accessor(int i);
177
178static void show_delegations(struct connection *caller);
179
180static const char horiz_line[] =
181"------------------------------------------------------------------------------";
182
183/**********************************************************************/
187static bool is_restricted(struct connection *caller)
188{
189 return (caller && caller->access_level != ALLOW_HACK);
190}
191
192/**********************************************************************/
196static bool player_name_check(const char *name, char *buf, size_t buflen)
197{
198 size_t len = strlen(name);
199
200 if (len == 0) {
201 fc_snprintf(buf, buflen, _("Can't use an empty name."));
202 return FALSE;
203 } else if (len > MAX_LEN_NAME-1) {
204 fc_snprintf(buf, buflen, _("That name exceeds the maximum of %d chars."),
205 MAX_LEN_NAME-1);
206 return FALSE;
207 } else if (fc_strcasecmp(name, ANON_PLAYER_NAME) == 0
208 || fc_strcasecmp(name, "Observer") == 0) {
209 fc_snprintf(buf, buflen, _("That name is not allowed."));
210 /* "Observer" used to be illegal and we keep it that way for now. */
211 /* FIXME: This disallows anonymous player name as it appears in English,
212 * but not one in any other language that the user may see. */
213 return FALSE;
214 }
215
216 return TRUE;
217}
218
219/**********************************************************************/
226static enum command_id command_named(const char *token, bool accept_ambiguity)
227{
228 enum m_pre_result result;
229 int ind;
230
232 fc_strncasecmp, NULL, token, &ind);
233
234 if (result < M_PRE_AMBIGUOUS) {
235 return ind;
236 } else if (result == M_PRE_AMBIGUOUS) {
238 } else {
239 return CMD_UNRECOGNIZED;
240 }
241}
242
243/**********************************************************************/
254
255/**********************************************************************/
272
273/**********************************************************************/
277static bool may_use(struct connection *caller, enum command_id cmd)
278{
279 if (!caller) {
280 return TRUE; /* on the console, everything is allowed */
281 }
282 return (caller->access_level >= command_level(command_by_number(cmd)));
283}
284
285/**********************************************************************/
289static bool may_use_nothing(struct connection *caller)
290{
291 if (!caller) {
292 return FALSE; /* on the console, everything is allowed */
293 }
294 return (ALLOW_NONE == conn_get_access(caller));
295}
296
297/**********************************************************************/
301static char setting_status(struct connection *caller,
302 const struct setting *pset)
303{
304 /* First check for a ruleset lock as this is included in
305 * setting_is_changeable() */
306 if (setting_locked(pset)) {
307 /* Setting is locked */
308 return '!';
309 }
310
311 if (setting_is_changeable(pset, caller, NULL, 0)) {
312 /* setting can be changed */
313 return '+';
314 }
315
316 /* setting is fixed */
317 return ' ';
318}
319
320/**********************************************************************/
327static void cmd_reply_line(enum command_id cmd, struct connection *caller,
328 enum rfc_status rfc_status, const char *prefix,
329 const char *line)
330{
331 const char *cmdname = cmd < CMD_NUM
333 : cmd == CMD_AMBIGUOUS
334 /* TRANS: ambiguous command */
335 ? _("(ambiguous)")
336 : cmd == CMD_UNRECOGNIZED
337 /* TRANS: unrecognized command */
338 ? _("(unknown)")
339 : "(?!?)"; /* this case is a bug! */
340
341 if (caller) {
343 "/%s: %s%s", cmdname, prefix, line);
344 /* cc: to the console - testing has proved it's too verbose - rp
345 con_write(rfc_status, "%s/%s: %s%s", caller->name, cmdname, prefix, line);
346 */
347 } else {
348 con_write(rfc_status, "%s%s", prefix, line);
349 }
350
351 if (rfc_status == C_OK) {
352 struct packet_chat_msg packet;
353
354 package_event(&packet, NULL, E_SETTING, ftc_server, "%s", line);
356 /* Do not tell caller, since they were told above! */
357 if (caller != pconn) {
358 send_packet_chat_msg(pconn, &packet);
359 }
362
363 if (NULL != caller) {
364 /* Echo to the console. */
365 log_normal("%s", line);
366 }
367 }
368}
369
370/**********************************************************************/
374static void vcmd_reply_prefix(enum command_id cmd, struct connection *caller,
375 enum rfc_status rfc_status, const char *prefix,
376 const char *format, va_list ap)
377{
378 char buf[4096];
379 char *c0, *c1;
380
381 fc_vsnprintf(buf, sizeof(buf), format, ap);
382
383 c0 = buf;
384 while ((c1 = strstr(c0, "\n"))) {
385 *c1 = '\0';
386 cmd_reply_line(cmd, caller, rfc_status, (c0 == buf ? "" : prefix), c0);
387 c0 = c1 + 1;
388 }
389
390 cmd_reply_line(cmd, caller, rfc_status, (c0 == buf ? "" : prefix), c0);
391}
392
393/**********************************************************************/
397static void cmd_reply_prefix(enum command_id cmd, struct connection *caller,
398 enum rfc_status rfc_status, const char *prefix,
399 const char *format, ...)
402 enum rfc_status rfc_status, const char *prefix,
403 const char *format, ...)
404{
405 va_list ap;
406 va_start(ap, format);
407 vcmd_reply_prefix(cmd, caller, rfc_status, prefix, format, ap);
408 va_end(ap);
409}
410
411/**********************************************************************/
414void cmd_reply(enum command_id cmd, struct connection *caller,
415 enum rfc_status rfc_status, const char *format, ...)
416{
417 va_list ap;
418 va_start(ap, format);
419 vcmd_reply_prefix(cmd, caller, rfc_status, "", format, ap);
420 va_end(ap);
421}
422
423/**********************************************************************/
428 struct connection *caller,
429 const char *name,
431{
432 switch (match_result) {
433 case M_PRE_EMPTY:
434 cmd_reply(cmd, caller, C_SYNTAX,
435 _("Name is empty, so cannot be a player."));
436 break;
437 case M_PRE_LONG:
438 cmd_reply(cmd, caller, C_SYNTAX,
439 _("Name is too long, so cannot be a player."));
440 break;
441 case M_PRE_AMBIGUOUS:
442 cmd_reply(cmd, caller, C_FAIL,
443 _("Player name prefix '%s' is ambiguous."), name);
444 break;
445 case M_PRE_FAIL:
446 cmd_reply(cmd, caller, C_FAIL,
447 _("No player by the name of '%s'."), name);
448 break;
449 default:
450 cmd_reply(cmd, caller, C_FAIL,
451 _("Unexpected match_result %d (%s) for '%s'."),
453 log_error("Unexpected match_result %d (%s) for '%s'.",
455 }
456}
457
458/**********************************************************************/
463 struct connection *caller,
464 const char *name,
466{
467 switch (match_result) {
468 case M_PRE_EMPTY:
469 cmd_reply(cmd, caller, C_SYNTAX,
470 _("Name is empty, so cannot be a connection."));
471 break;
472 case M_PRE_LONG:
473 cmd_reply(cmd, caller, C_SYNTAX,
474 _("Name is too long, so cannot be a connection."));
475 break;
476 case M_PRE_AMBIGUOUS:
477 cmd_reply(cmd, caller, C_FAIL,
478 _("Connection name prefix '%s' is ambiguous."), name);
479 break;
480 case M_PRE_FAIL:
481 cmd_reply(cmd, caller, C_FAIL,
482 _("No connection by the name of '%s'."), name);
483 break;
484 default:
485 cmd_reply(cmd, caller, C_FAIL,
486 _("Unexpected match_result %d (%s) for '%s'."),
488 log_error("Unexpected match_result %d (%s) for '%s'.",
490 }
491}
492
493/**********************************************************************/
496static void open_metaserver_connection(struct connection *caller,
497 bool persistent)
498{
501 cmd_reply(CMD_METACONN, caller, C_OK,
502 _("Open metaserver connection to [%s]."),
504 }
505}
506
507/**********************************************************************/
510static void close_metaserver_connection(struct connection *caller)
511{
514 cmd_reply(CMD_METACONN, caller, C_OK,
515 _("Close metaserver connection to [%s]."),
517 }
518}
519
520/**********************************************************************/
523static bool metaconnection_command(struct connection *caller, char *arg,
524 bool check)
525{
526 bool persistent = FALSE;
527
528 if ((*arg == '\0')
529 || (!strcmp(arg, "?"))) {
530 if (is_metaserver_open()) {
532 _("Metaserver connection is open."));
533 } else {
535 _("Metaserver connection is closed."));
536 }
537 return TRUE;
538 }
539
540 if (!fc_strcasecmp(arg, "p")
541 || !fc_strcasecmp(arg, "persistent")) {
543 }
544
545 if (persistent
546 || !fc_strcasecmp(arg, "u")
547 || !fc_strcasecmp(arg, "up")) {
548 if (!is_metaserver_open()) {
549 if (!check) {
551 }
552 } else {
554 _("Metaserver connection is already open."));
555 return FALSE;
556 }
557 } else if (!fc_strcasecmp(arg, "d")
558 || !fc_strcasecmp(arg, "down")) {
559 if (is_metaserver_open()) {
560 if (!check) {
562 }
563 } else {
565 _("Metaserver connection is already closed."));
566 return FALSE;
567 }
568 } else {
570 _("Argument must be 'u', 'up', 'd', 'down', 'p', 'persistent', or '?'."));
571 return FALSE;
572 }
573 return TRUE;
574}
575
576/**********************************************************************/
579static bool metapatches_command(struct connection *caller,
580 char *arg, bool check)
581{
582 if (check) {
583 return TRUE;
584 }
585
587
588 if (is_metaserver_open()) {
591 _("Metaserver patches string set to '%s'."), arg);
592 } else {
594 _("Metaserver patches string set to '%s', "
595 "not reporting to metaserver."), arg);
596 }
597
598 return TRUE;
599}
600
601/**********************************************************************/
604static bool metamessage_command(struct connection *caller,
605 char *arg, bool check)
606{
607 struct setting *pset;
608
609 log_deprecation(_("/metamessage command is deprecated. "
610 "Set metamessage setting instead."));
611
612 if (check) {
613 return TRUE;
614 }
615
617 if (is_metaserver_open()) {
620 _("Metaserver message string set to '%s'."), arg);
621 } else {
623 _("Metaserver message string set to '%s', "
624 "not reporting to metaserver."), arg);
625 }
626
627 /* Metamessage is also a setting. */
628 pset = setting_by_name("metamessage");
631
632 return TRUE;
633}
634
635/**********************************************************************/
638static bool metaserver_command(struct connection *caller, char *arg,
639 bool check)
640{
641 if (check) {
642 return TRUE;
643 }
645
647
649 _("Metaserver is now [%s]."), meta_addr_port());
650 return TRUE;
651}
652
653/**********************************************************************/
656static bool show_serverid(struct connection *caller, char *arg)
657{
658 cmd_reply(CMD_SRVID, caller, C_COMMENT, _("Server id: %s"), srvarg.serverid);
659
660 return TRUE;
661}
662
663/**********************************************************************/
667static bool save_command(struct connection *caller, char *arg, bool check)
668{
669 if (is_restricted(caller)) {
670 cmd_reply(CMD_SAVE, caller, C_FAIL,
671 _("You cannot save games manually on this server."));
672 return FALSE;
673 }
674 if (!check) {
675 save_game(arg, "User request", FALSE);
676 }
677 return TRUE;
678}
679
680/**********************************************************************/
684static bool scensave_command(struct connection *caller, char *arg, bool check)
685{
686 if (is_restricted(caller)) {
687 cmd_reply(CMD_SAVE, caller, C_FAIL,
688 _("You cannot save games manually on this server."));
689 return FALSE;
690 }
691 if (!check) {
692 save_game(arg, "Scenario", TRUE);
693 }
694 return TRUE;
695}
696
697/**********************************************************************/
700void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
701{
702 fc_assert_ret(pplayer != NULL);
703
704 if (is_human(pplayer)) {
705 cmd_reply(CMD_AITOGGLE, caller, C_OK,
706 _("%s is now under AI control."),
707 player_name(pplayer));
708 player_set_to_ai_mode(pplayer,
711 : pplayer->ai_common.skill_level);
712 fc_assert(is_ai(pplayer));
713 } else {
714 cmd_reply(CMD_AITOGGLE, caller, C_OK,
715 _("%s is now under human control."),
716 player_name(pplayer));
718 fc_assert(is_human(pplayer));
719 }
720}
721
722/**********************************************************************/
725static bool toggle_ai_command(struct connection *caller, char *arg, bool check)
726{
728 struct player *pplayer;
729
730 pplayer = player_by_name_prefix(arg, &match_result);
731
732 if (!pplayer) {
734 return FALSE;
735 } else if (!check) {
736 toggle_ai_player_direct(caller, pplayer);
738 }
739 return TRUE;
740}
741
742/**********************************************************************/
748static bool create_command(struct connection *caller, const char *str,
749 bool check)
750{
751 enum rfc_status status;
753
754 /* 2 legal arguments, and extra space for stuffing illegal part */
755 char *arg[3];
756 int ntokens;
757 const char *ai_type_name;
758
761
762 if (ntokens == 1) {
764 } else if (ntokens == 2) {
765 ai_type_name = arg[1];
766 } else {
768 _("Wrong number of arguments to create command."));
769 free_tokens(arg, ntokens);
770 return FALSE;
771 }
772
773 if (game_was_started()) {
775 NULL, NULL, buf, sizeof(buf));
776 } else {
778 NULL, buf, sizeof(buf));
779 }
780
781 free_tokens(arg, ntokens);
782
783 if (status != C_OK) {
784 /* No player created. */
785 cmd_reply(CMD_CREATE, caller, status, "%s", buf);
786 return FALSE;
787 }
788
789 if (strlen(buf) > 0) {
790 /* Send a notification. */
791 cmd_reply(CMD_CREATE, caller, C_OK, "%s", buf);
792 }
793
794 return TRUE;
795}
796
797/**********************************************************************/
807 const char *ai,
808 bool check,
809 struct nation_type *pnation,
810 struct player **newplayer,
811 char *buf, size_t buflen)
812{
813 struct player *pplayer = NULL;
814 struct research *presearch;
815 bool new_slot = FALSE;
816
817 /* Check player name. */
819 return C_SYNTAX;
820 }
821
822 /* Check first if we can replace a player with
823 * [1a] - the same username. */
824 pplayer = player_by_user(name);
825 if (pplayer && pplayer->is_alive) {
827 _("A living user already exists by that name."));
828 return C_BOUNCE;
829 }
830
831 /* [1b] - the same player name. */
832 pplayer = player_by_name(name);
833 if (pplayer && pplayer->is_alive) {
835 _("A living player already exists by that name."));
836 return C_BOUNCE;
837 }
838
839 if (pnation) {
840 if (!nation_is_in_current_set(pnation)) {
842 _("Can't create player, requested nation %s not in "
843 "current nation set."),
845 return C_FAIL;
846 }
848 if (0 > nations_match(pnation, nation_of_player(aplayer), FALSE)) {
850 _("Can't create players, nation %s conflicts with %s."),
852 nation_plural_for_player(pplayer));
853 return C_FAIL;
854 }
856 } else {
857 /* Try to find a nation. */
859 if (pnation == NO_NATION_SELECTED) {
861 _("Can't create players, no nations available."));
862 return C_FAIL;
863 }
864 }
865
866 if (pplayer == NULL) {
867 if (player_count() == player_slot_count()) {
868 bool dead_found = FALSE;
869
871 if (!aplayer->is_alive) {
873 break;
874 }
876
877 if (!dead_found) {
879 _("Can't create players, no slots available."));
880 return C_FAIL;
881 }
882 } else if (normal_player_count() == game.server.max_players) {
884 _("Maxplayers setting prevents creation of more players."));
885 return C_FAIL;
886 }
887 }
888
889 if (check) {
890 /* All code below will change the game state. */
891
892 /* Return an empty string. */
893 buf[0] = '\0';
894
895 return C_OK;
896 }
897
898 if (pplayer) {
899 /* [1] Replace a player. 'pplayer' was set above. */
901 _("%s is replacing dead player %s as an AI-controlled "
902 "player."), name, player_name(pplayer));
903 /* remove player and thus free a player slot */
904 server_remove_player(pplayer);
905 pplayer = NULL;
906 } else if (player_count() == player_slot_count()) {
907 /* [2] All player slots are used; try to remove a dead player. */
908 bool dead_found = FALSE;
909
911 if (!aplayer->is_alive) {
912 if (!dead_found) {
913 /* Fill the buffer with the name of the first found dead player */
915 _("%s is replacing dead player %s as an AI-controlled "
916 "player."), name, player_name(aplayer));
918 }
919
920 /* Remove player and thus free a player slot */
922 }
923
926 } else {
927 /* [3] An empty player slot must be used for the new player. */
928 new_slot = TRUE;
929 }
930
931 /* Create the new player. */
932 pplayer = server_create_player(-1, ai, NULL, FALSE);
933 if (!pplayer) {
934 fc_snprintf(buf, buflen, _("Failed to create new player %s."), name);
935 return C_FAIL;
936 }
937
938 if (new_slot) {
939 /* 'buf' must be set if a new player slot is used. */
940 fc_snprintf(buf, buflen, _("New player %s created."), name);
941 }
942
943 /* We have a player; now initialise all needed data. */
945
946 /* Initialise player. */
947 server_player_init(pplayer, TRUE, TRUE);
948
949 player_nation_defaults(pplayer, pnation, FALSE);
950 pplayer->government = pplayer->target_government
951 = init_government_of_nation(pnation);
952 /* Find a color for the new player. */
954
955 /* TRANS: keep one space at the beginning of the string. */
956 cat_snprintf(buf, buflen, _(" Nation of the new player: %s."),
957 nation_rule_name(pnation));
958
959 presearch = research_get(pplayer);
962
965 pplayer->unassigned_user = TRUE;
966
967 pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
968 set_as_ai(pplayer);
970
971 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
972
973 send_player_info_c(pplayer, NULL);
974 /* Send updated diplstate information to all players. */
976 /* Send research info after player info, else the client will complain
977 * about invalid team. */
980
981 if (newplayer != NULL) {
982 *newplayer = pplayer;
983 }
984
985 adv_data_phase_init(pplayer, TRUE);
986 CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, TRUE);
987
988 return C_OK;
989}
990
991/**********************************************************************/
995 const char *ai,
996 bool check,
997 struct player **newplayer,
998 char *buf, size_t buflen)
999{
1000 char leader_name[MAX_LEN_NAME]; /* Must be in whole function scope */
1001 struct player *pplayer = NULL;
1002 bool rand_name = FALSE;
1003
1004 if (name[0] == '\0') {
1005 int filled = 1;
1006
1007 do {
1008 fc_snprintf(leader_name, sizeof(leader_name), "%s*%d", ai, filled++);
1009 } while (player_by_name(leader_name));
1010
1011 name = leader_name;
1012 rand_name = TRUE;
1013 }
1014
1015 if (!player_name_check(name, buf, buflen)) {
1016 return C_SYNTAX;
1017 }
1018
1019 if (NULL != player_by_name(name)) {
1021 _("A player already exists by that name."));
1022 return C_BOUNCE;
1023 }
1024 if (NULL != player_by_user(name)) {
1026 _("A user already exists by that name."));
1027 return C_BOUNCE;
1028 }
1029
1030 /* Search for first uncontrolled player */
1031 pplayer = find_uncontrolled_player();
1032
1033 if (NULL == pplayer) {
1034 /* Check that we are not going over max players setting */
1037 _("Can't add more players, server is full."));
1038 return C_FAIL;
1039 }
1040 /* Check that we have nations available */
1041 if (normal_player_count() >= server.playable_nations) {
1042 if (nation_set_count() > 1) {
1044 _("Can't add more players, not enough playable nations "
1045 "in current nation set (see 'nationset' setting)."));
1046 } else {
1048 _("Can't add more players, not enough playable nations."));
1049 }
1050 return C_FAIL;
1051 }
1052 }
1053
1054 if (pplayer) {
1055 struct ai_type *ait = ai_type_by_name(ai);
1056
1057 if (ait == NULL) {
1059 _("There is no AI type %s."), ai);
1060 return C_FAIL;
1061 }
1062 }
1063
1064 if (check) {
1065 /* All code below will change the game state. */
1066
1067 /* Return an empty string. */
1068 buf[0] = '\0';
1069
1070 return C_OK;
1071 }
1072
1073 if (pplayer) {
1075 /* TRANS: <name> replacing <name> ... */
1076 _("%s replacing %s as an AI-controlled player."),
1077 name, player_name(pplayer));
1078
1079 team_remove_player(pplayer);
1080 pplayer->ai = ai_type_by_name(ai);
1081 } else {
1082 /* add new player */
1083 pplayer = server_create_player(-1, ai, NULL, FALSE);
1084 /* pregame so no need to assign_player_colors() */
1085 if (!pplayer) {
1087 _("Failed to create new player %s."), name);
1088 return C_GENFAIL;
1089 }
1090
1092 _("%s has been added as an AI-controlled player (%s)."),
1093 name, ai_name(pplayer->ai));
1094 }
1095 server_player_init(pplayer, FALSE, TRUE);
1096
1097 server_player_set_name(pplayer, name);
1098 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
1099 pplayer->unassigned_user = TRUE;
1100
1101 pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
1102 pplayer->random_name = rand_name;
1103 set_as_ai(pplayer);
1105 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
1107
1111
1112 if (newplayer != NULL) {
1113 *newplayer = pplayer;
1114 }
1115 return C_OK;
1116}
1117
1118/**********************************************************************/
1121static bool remove_player_command(struct connection *caller, char *arg,
1122 bool check)
1123{
1125 struct player *pplayer;
1126 char name[MAX_LEN_NAME];
1127
1128 pplayer = player_by_name_prefix(arg, &match_result);
1129
1130 if (NULL == pplayer) {
1132 return FALSE;
1133 }
1134
1135 if (game_was_started() && caller && caller->access_level < ALLOW_ADMIN) {
1136 cmd_reply(CMD_REMOVE, caller, C_FAIL,
1137 _("Command level '%s' or greater needed to remove a player "
1138 "once the game has started."), cmdlevel_name(ALLOW_ADMIN));
1139 return FALSE;
1140 }
1141 if (check) {
1142 return TRUE;
1143 }
1144
1145 sz_strlcpy(name, player_name(pplayer));
1146 server_remove_player(pplayer);
1147 if (!caller || caller->used) { /* may have removed self */
1148 cmd_reply(CMD_REMOVE, caller, C_OK,
1149 _("Removed player %s from the game."), name);
1150 }
1152 return TRUE;
1153}
1154
1155/**********************************************************************/
1158static bool read_command(struct connection *caller, char *arg, bool check,
1159 int read_recursion)
1160{
1161 return read_init_script_real(caller, arg, FALSE, check, read_recursion);
1162}
1163
1164/**********************************************************************/
1167bool read_init_script(struct connection *caller, const char *script_filename,
1168 bool from_cmdline, bool check)
1169{
1170 return read_init_script_real(caller, script_filename, from_cmdline,
1171 check, 0);
1172}
1173
1174/**********************************************************************/
1185static bool read_init_script_real(struct connection *caller,
1186 const char *script_filename, bool from_cmdline,
1187 bool check, int read_recursion)
1188{
1190 char serv_filename[strlen(script_extension) + strlen(script_filename) + 2];
1191 char tilde_filename[4096];
1192 const char *real_filename;
1193 size_t fnlen;
1194
1195 /* check recursion depth */
1197 log_error("Error: recursive calls to read!");
1198 return FALSE;
1199 }
1200
1201 /* abuse real_filename to find if we already have a .serv extension */
1202 fnlen = strlen(script_filename);
1203 real_filename = script_filename + fnlen
1206 fc_snprintf(serv_filename, sizeof(serv_filename), "%s%s",
1207 script_filename, script_extension);
1208 } else {
1209 sz_strlcpy(serv_filename, script_filename);
1210 }
1211
1212 if (is_restricted(caller) && !from_cmdline) {
1215 _("Name \"%s\" disallowed for security reasons."),
1217 return FALSE;
1218 }
1220 } else {
1222 }
1223
1225 if (!real_filename) {
1226 if (is_restricted(caller) && !from_cmdline) {
1228 _("No command script found by the name \"%s\"."),
1230 return FALSE;
1231 }
1232 /* File is outside data directories */
1234 }
1235
1236 log_testmatic_alt(LOG_NORMAL, _("Loading script file '%s'."), real_filename);
1237
1239 && (script_file = fc_fopen(real_filename, "r"))) {
1240 char buffer[MAX_LEN_CONSOLE_LINE];
1241
1242 /* The size is set as to not overflow buffer in handle_stdin_input */
1243 while (fgets(buffer, MAX_LEN_CONSOLE_LINE - 1, script_file)) {
1244 /* Execute script contents with same permissions as caller */
1245 handle_stdin_input_real(caller, buffer, check, read_recursion + 1);
1246 }
1248
1250
1251 return TRUE;
1252 } else {
1254 _("Cannot read command line scriptfile '%s'."), real_filename);
1255 if (NULL != caller) {
1256 log_error(_("Could not read script file '%s'."), real_filename);
1257 }
1258 return FALSE;
1259 }
1260}
1261
1262/**********************************************************************/
1272
1273/**********************************************************************/
1278static bool write_init_script(char *script_filename)
1279{
1280 char real_filename[1024], buf[256];
1282
1283 interpret_tilde(real_filename, sizeof(real_filename), script_filename);
1284
1286 && (script_file = fc_fopen(real_filename, "w"))) {
1288 "#FREECIV SERVER COMMAND FILE, version %s\n", VERSION_STRING);
1289 fputs("# These are server options saved from a running freeciv-server.\n",
1290 script_file);
1291
1292 /* First rulesetdir. Setting rulesetdir resets the settings to their
1293 * default value, so they would be lost if placed before this. */
1294 fprintf(script_file, "rulesetdir %s\n", game.server.rulesetdir);
1295
1296 /* Some state info from commands (we can't save everything) */
1297
1298 fprintf(script_file, "cmdlevel %s new\n",
1300
1301 fprintf(script_file, "cmdlevel %s first\n",
1303
1304 fprintf(script_file, "%s\n",
1306
1307 if (*srvarg.metaserver_addr != '\0'
1309 fprintf(script_file, "metaserver %s\n", meta_addr_port());
1310 }
1311
1313 fprintf(script_file, "metapatches %s\n", get_meta_patches_string());
1314 }
1315
1316 /* Then, the 'set' option settings */
1317
1319 fprintf(script_file, "set %s \"%s\"\n", setting_name(pset),
1320 setting_value_name(pset, FALSE, buf, sizeof(buf)));
1322
1324
1325 return TRUE;
1326 } else {
1327 log_error(_("Could not write script file '%s'."), real_filename);
1328
1329 return FALSE;
1330 }
1331}
1332
1333/**********************************************************************/
1336static bool write_command(struct connection *caller, char *arg, bool check)
1337{
1338 if (is_restricted(caller)) {
1340 _("You cannot use the write command on this server"
1341 " for security reasons."));
1342 return FALSE;
1343 } else if (!check) {
1344 char serv_filename[strlen(script_extension) + strlen(arg) + 2];
1345 const char *real_filename;
1346 size_t arglen = strlen(arg);
1347
1348 /* abuse real_filename to find if we already have a .serv extension */
1351 fc_snprintf(serv_filename, sizeof(serv_filename), "%s%s",
1352 arg, script_extension);
1353 } else {
1355 }
1356
1359 /* TRANS: Failed to write server script, e.g., 'example.serv' */
1360 _("Failed to write %s."), serv_filename);
1361 return FALSE;
1362 }
1363
1365 /* TRANS: Wrote server script, e.g., 'example.serv' */
1366 _("Wrote %s."), serv_filename);
1367 }
1368
1369 return TRUE;
1370}
1371
1372/**********************************************************************/
1375static bool set_cmdlevel(struct connection *caller,
1376 struct connection *ptarget,
1377 enum cmdlevel level)
1378{
1379 /* Only ever call me for specific connection. */
1381
1382 if (caller && ptarget->access_level > caller->access_level) {
1383 /*
1384 * This command is intended to be used at ctrl access level
1385 * and thus this if clause is needed.
1386 * (Imagine a ctrl level access player that wants to change
1387 * access level of a hack level access player)
1388 * At the moment it can be used only by hack access level
1389 * and thus this clause is never used.
1390 */
1391 cmd_reply(CMD_CMDLEVEL, caller, C_FAIL,
1392 _("Cannot decrease command access level '%s' "
1393 "for connection '%s'; you only have '%s'."),
1394 cmdlevel_name(ptarget->access_level),
1396 cmdlevel_name(caller->access_level));
1397 return FALSE;
1398 } else {
1400 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1401 _("Command access level set to '%s' for connection %s."),
1403 return TRUE;
1404 }
1405}
1406
1407/**********************************************************************/
1410static bool a_connection_exists(void)
1411{
1413}
1414
1415/**********************************************************************/
1419{
1421 if (pconn->access_level >= first_access_level) {
1422 return TRUE;
1423 }
1424 }
1426 return FALSE;
1427}
1428
1429/**********************************************************************/
1433{
1435 && !a_connection_exists()) {
1436 return first_access_level;
1437 } else {
1438 return default_access_level;
1439 }
1440}
1441
1442/**********************************************************************/
1447{
1451 _("Anyone can now become game organizer "
1452 "'%s' by issuing the 'first' command."),
1454 }
1455}
1456
1457/**********************************************************************/
1460static bool cmdlevel_command(struct connection *caller, char *str, bool check)
1461{
1462 char *arg[2];
1463 int ntokens;
1464 bool ret = FALSE;
1466 enum cmdlevel level;
1467 struct connection *ptarget;
1468
1470
1471 if (ntokens == 0) {
1472 /* No argument supplied; list the levels */
1475 _("Command access levels in effect:"));
1479
1480 if (lvl_name != NULL) {
1481 cmd_reply(CMD_CMDLEVEL, caller, C_COMMENT, "cmdlevel %s %s",
1483 } else {
1484 fc_assert(lvl_name != NULL); /* Always fails when reached. */
1485 }
1488 _("Command access level for new connections: %s"),
1491 _("Command access level for first player to take it: %s"),
1494 return TRUE;
1495 }
1496
1497 /* A level name was supplied; set the level. */
1499 if (!cmdlevel_is_valid(level)) {
1500 const char *cmdlevel_names[CMDLEVEL_COUNT];
1501 struct astring astr = ASTRING_INIT;
1502 int i = 0;
1503
1504 for (level = cmdlevel_begin(); level != cmdlevel_end();
1507 }
1509 /* TRANS: comma and 'or' separated list of access levels */
1510 _("Command access level must be one of %s."),
1512 astr_free(&astr);
1513 goto CLEAN_UP;
1514 } else if (caller && level > conn_get_access(caller)) {
1515 cmd_reply(CMD_CMDLEVEL, caller, C_FAIL,
1516 _("Cannot increase command access level to '%s';"
1517 " you only have '%s' yourself."),
1518 arg[0], cmdlevel_name(conn_get_access(caller)));
1519 goto CLEAN_UP;
1520 }
1521
1522 if (check) {
1523 return TRUE; /* looks good */
1524 }
1525
1526 if (ntokens == 1) {
1527 /* No playername supplied: set for all connections */
1529 if (pconn != caller) {
1530 (void) set_cmdlevel(caller, pconn, level);
1531 }
1533
1534 /* Set the caller access level at last, because it could make the
1535 * previous operations impossible if set before. */
1536 if (caller) {
1537 (void) set_cmdlevel(caller, caller, level);
1538 }
1539
1540 /* Set default access for new connections. */
1542 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1543 _("Command access level set to '%s' for new players."),
1545 /* Set default access for first connection. */
1547 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1548 _("Command access level set to '%s' "
1549 "for first player to grab it."),
1551
1552 ret = TRUE;
1553
1554 } else if (fc_strcasecmp(arg[1], "new") == 0) {
1556 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1557 _("Command access level set to '%s' for new players."),
1559 if (level > first_access_level) {
1561 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1562 _("Command access level set to '%s' "
1563 "for first player to grab it."),
1565 }
1566
1567 ret = TRUE;
1568
1569 } else if (fc_strcasecmp(arg[1], "first") == 0) {
1571 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1572 _("Command access level set to '%s' "
1573 "for first player to grab it."),
1577 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1578 _("Command access level set to '%s' for new players."),
1580 }
1581
1582 ret = TRUE;
1583
1584 } else if ((ptarget = conn_by_user_prefix(arg[1], &match_result))) {
1585 if (set_cmdlevel(caller, ptarget, level)) {
1586 ret = TRUE;
1587 }
1588 } else {
1590 }
1591
1592CLEAN_UP:
1593 free_tokens(arg, ntokens);
1594 return ret;
1595}
1596
1597/**********************************************************************/
1603static bool firstlevel_command(struct connection *caller, bool check)
1604{
1605 if (!caller) {
1607 _("The 'first' command makes no sense from the server command line."));
1608 return FALSE;
1609 } else if (caller->access_level >= first_access_level) {
1611 _("You already have command access level '%s' or better."),
1613 return FALSE;
1614 } else if (is_first_access_level_taken()) {
1616 _("Someone else is already game organizer."));
1617 return FALSE;
1618 } else if (!check) {
1620 cmd_reply(CMD_FIRSTLEVEL, caller, C_OK,
1621 _("Connection %s has opted to become the game organizer."),
1622 caller->username);
1623 }
1624 return TRUE;
1625}
1626
1627/**********************************************************************/
1631{
1634 _("Default cmdlevel lowered to 'basic' on game start."));
1636 }
1637}
1638
1639/**********************************************************************/
1643static const char *optname_accessor(int i)
1644{
1646}
1647
1648#ifdef FREECIV_HAVE_LIBREADLINE
1649/**********************************************************************/
1652static const char *olvlname_accessor(int i)
1653{
1654 if (i == 0) {
1655 return "rulesetdir";
1656 } else if (i < OLEVELS_NUM+1) {
1657 return sset_level_name(i-1);
1658 } else {
1659 return optname_accessor(i-OLEVELS_NUM-1);
1660 }
1661}
1662#endif /* FREECIV_HAVE_LIBREADLINE */
1663
1664/**********************************************************************/
1667static bool timeout_command(struct connection *caller, char *str, bool check)
1668{
1670 char *arg[4];
1671 int i = 0, ntokens;
1672 int *timeouts[4];
1673
1678
1679 sz_strlcpy(buf, str);
1681
1682 for (i = 0; i < ntokens; i++) {
1683 if (!str_to_int(arg[i], timeouts[i])) {
1684 cmd_reply(CMD_TIMEOUT, caller, C_FAIL, _("Invalid argument %d."),
1685 i + 1);
1686 }
1687 free(arg[i]);
1688 }
1689
1690 if (ntokens == 0) {
1691 cmd_reply(CMD_TIMEOUT, caller, C_SYNTAX, _("Usage:\n%s"),
1693 return FALSE;
1694 } else if (check) {
1695 return TRUE;
1696 }
1697
1698 cmd_reply(CMD_TIMEOUT, caller, C_OK, _("Dynamic timeout set to "
1699 "%d %d %d %d"),
1702
1703 /* if we set anything here, reset the counter */
1705 return TRUE;
1706}
1707
1708/**********************************************************************/
1711static enum sset_level lookup_option_level(const char *name)
1712{
1713 enum sset_level i;
1714
1715 for (i = SSET_ALL; i < OLEVELS_NUM; i++) {
1716 if (0 == fc_strcasecmp(name, sset_level_name(i))) {
1717 return i;
1718 }
1719 }
1720
1721 return SSET_NONE;
1722}
1723
1724/* Special return values of lookup options */
1725#define LOOKUP_OPTION_NO_RESULT (-1)
1726#define LOOKUP_OPTION_AMBIGUOUS (-2)
1727#define LOOKUP_OPTION_LEVEL_NAME (-3)
1728#define LOOKUP_OPTION_RULESETDIR (-4)
1729
1730/**********************************************************************/
1737static int lookup_option(const char *name)
1738{
1739 enum m_pre_result result;
1740 int ind;
1741
1742 /* Check for option levels, first off */
1745 }
1746
1748 0, fc_strncasecmp, NULL, name, &ind);
1749 if (M_PRE_AMBIGUOUS > result) {
1750 return ind;
1751 } else if (M_PRE_AMBIGUOUS == result) {
1753 } else if ('\0' != name[0]
1754 && 0 == fc_strncasecmp("rulesetdir", name, strlen(name))) {
1756 } else {
1758 }
1759}
1760
1761/**********************************************************************/
1766static void show_help_option(struct connection *caller,
1767 enum command_id help_cmd, int id)
1768{
1769 char val_buf[256], def_buf[256];
1770 struct setting *pset = setting_by_number(id);
1771 const char *sethelp;
1772
1773 if (setting_short_help(pset)) {
1774 cmd_reply(help_cmd, caller, C_COMMENT,
1775 /* TRANS: <untranslated name> - translated short help */
1776 _("Option: %s - %s"), setting_name(pset),
1778 } else {
1779 cmd_reply(help_cmd, caller, C_COMMENT,
1780 /* TRANS: <untranslated name> */
1781 _("Option: %s"), setting_name(pset));
1782 }
1783
1785 if (strlen(sethelp) > 0) {
1786 char *help = fc_strdup(sethelp);
1787
1789 cmd_reply(help_cmd, caller, C_COMMENT, _("Description:"));
1790 cmd_reply_prefix(help_cmd, caller, C_COMMENT, " ", " %s", help);
1791 FC_FREE(help);
1792 }
1793 cmd_reply(help_cmd, caller, C_COMMENT,
1794 _("Status: %s"), (setting_is_changeable(pset, NULL, NULL, 0)
1795 ? _("changeable") : _("fixed")));
1796
1797 if (setting_is_visible(pset, caller)) {
1800
1801 switch (setting_type(pset)) {
1802 case SST_INT:
1803 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s, %s %d, %s %s, %s %d",
1804 _("Value:"), val_buf,
1805 _("Minimum:"), setting_int_min(pset),
1806 _("Default:"), def_buf,
1807 _("Maximum:"), setting_int_max(pset));
1808 break;
1809 case SST_ENUM:
1810 {
1811 int i;
1812 const char *value;
1813
1814 cmd_reply(help_cmd, caller, C_COMMENT, _("Possible values:"));
1815 for (i = 0; (value = setting_enum_val(pset, i, FALSE)); i++) {
1816 cmd_reply(help_cmd, caller, C_COMMENT, "- %s: \"%s\"",
1818 }
1819 }
1820
1822 case SST_BOOL:
1823 case SST_STRING:
1824 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s, %s %s",
1825 _("Value:"), val_buf, _("Default:"), def_buf);
1826 break;
1827 case SST_BITWISE:
1828 {
1829 int i;
1830 const char *value;
1831
1832 cmd_reply(help_cmd, caller, C_COMMENT,
1833 _("Possible values (option can take any number of these):"));
1834 for (i = 0; (value = setting_bitwise_bit(pset, i, FALSE)); i++) {
1835 cmd_reply(help_cmd, caller, C_COMMENT, "- %s: \"%s\"",
1837 }
1838 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s",
1839 _("Value:"), val_buf);
1840 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s",
1841 _("Default:"), def_buf);
1842 }
1843 break;
1844 case SST_COUNT:
1846 break;
1847 }
1848 }
1849}
1850
1851/**********************************************************************/
1856static void show_help_option_list(struct connection *caller,
1857 enum command_id help_cmd)
1858{
1859 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1860 cmd_reply(help_cmd, caller, C_COMMENT,
1861 _("Explanations are available for the following server options:"));
1862 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1863 if (!caller && con_get_style()) {
1865 cmd_reply(help_cmd, caller, C_COMMENT, "%s", setting_name(pset));
1867 } else {
1869 int j = 0;
1870 buf[0] = '\0';
1871
1873 if (setting_is_visible(pset, caller)) {
1874 cat_snprintf(buf, sizeof(buf), "%-19s", setting_name(pset));
1875 if ((++j % 4) == 0) {
1876 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
1877 buf[0] = '\0';
1878 }
1879 }
1881
1882 if (buf[0] != '\0') {
1883 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
1884 }
1885 }
1886 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1887}
1888
1889/**********************************************************************/
1892static bool explain_option(struct connection *caller, char *str, bool check)
1893{
1894 int cmd;
1895
1897
1898 if (*str != '\0') {
1899 cmd = lookup_option(str);
1900 if (cmd >= 0 && cmd < settings_number()) {
1901 show_help_option(caller, CMD_EXPLAIN, cmd);
1902 } else if (cmd == LOOKUP_OPTION_NO_RESULT
1903 || cmd == LOOKUP_OPTION_LEVEL_NAME
1904 || cmd == LOOKUP_OPTION_RULESETDIR) {
1905 cmd_reply(CMD_EXPLAIN, caller, C_FAIL,
1906 _("No explanation for that yet."));
1907 return FALSE;
1908 } else if (cmd == LOOKUP_OPTION_AMBIGUOUS) {
1909 cmd_reply(CMD_EXPLAIN, caller, C_FAIL, _("Ambiguous option name."));
1910 return FALSE;
1911 } else {
1912 log_error("Unexpected case %d in %s line %d", cmd, __FILE__,
1913 __FC_LINE__);
1914 return FALSE;
1915 }
1916 } else {
1918 }
1919 return TRUE;
1920}
1921
1922/**********************************************************************/
1925static bool wall(char *str, bool check)
1926{
1927 if (!check) {
1929 _("Server Operator: %s"), str);
1930 }
1931 return TRUE;
1932}
1933
1934/**********************************************************************/
1937static bool connectmsg_command(struct connection *caller, char *str,
1938 bool check)
1939{
1940 unsigned int bufsize = sizeof(game.server.connectmsg);
1941
1942 if (is_restricted(caller)) {
1943 return FALSE;
1944 }
1945 if (!check) {
1946 int i;
1947 int c = 0;
1948
1949 for (i = 0; c < bufsize -1 && str[i] != '\0'; i++) {
1950 if (str[i] == '\\') {
1951 i++;
1952
1953 if (str[i] == 'n') {
1954 game.server.connectmsg[c++] = '\n';
1955 } else {
1956 game.server.connectmsg[c++] = str[i];
1957 }
1958 } else {
1959 game.server.connectmsg[c++] = str[i];
1960 }
1961 }
1962
1963 game.server.connectmsg[c++] = '\0';
1964
1965 if (c == bufsize) {
1966 /* Truncated */
1968 _("Connectmsg truncated to %u bytes."), bufsize);
1969 }
1970 }
1971 return TRUE;
1972}
1973
1974/**********************************************************************/
1978static enum command_id cmd_of_level(enum ai_level level)
1979{
1980 switch (level) {
1981 case AI_LEVEL_AWAY : return CMD_AWAY;
1982 case AI_LEVEL_RESTRICTED : return CMD_RESTRICTED;
1983 case AI_LEVEL_NOVICE : return CMD_NOVICE;
1984 case AI_LEVEL_EASY : return CMD_EASY;
1985 case AI_LEVEL_NORMAL : return CMD_NORMAL;
1986 case AI_LEVEL_HARD : return CMD_HARD;
1987 case AI_LEVEL_CHEATING : return CMD_CHEATING;
1988#ifdef FREECIV_DEBUG
1990#endif /* FREECIV_DEBUG */
1991 case AI_LEVEL_COUNT : return CMD_NORMAL;
1992 }
1993 log_error("Unknown AI level variant: %d.", level);
1994 return CMD_NORMAL;
1995}
1996
1997/**********************************************************************/
2000void set_ai_level_direct(struct player *pplayer, enum ai_level level)
2001{
2002 set_ai_level_directer(pplayer, level);
2003 send_player_info_c(pplayer, NULL);
2005 _("Player '%s' now has AI skill level '%s'."),
2006 player_name(pplayer),
2008
2009}
2010
2011/**********************************************************************/
2014static bool set_ai_level_named(struct connection *caller, const char *name,
2015 const char *level_name, bool check)
2016{
2018
2019 return set_ai_level(caller, name, level, check);
2020}
2021
2022/**********************************************************************/
2025static bool set_ai_level(struct connection *caller, const char *name,
2026 enum ai_level level, bool check)
2027{
2029 struct player *pplayer;
2030
2032
2034
2035 if (pplayer) {
2036 if (is_ai(pplayer)) {
2037 if (check) {
2038 return TRUE;
2039 }
2040 set_ai_level_directer(pplayer, level);
2041 send_player_info_c(pplayer, NULL);
2042 cmd_reply(cmd_of_level(level), caller, C_OK,
2043 _("Player '%s' now has AI skill level '%s'."),
2044 player_name(pplayer),
2046 } else {
2048 _("%s is not controlled by the AI."),
2049 player_name(pplayer));
2050 return FALSE;
2051 }
2052 } else if (match_result == M_PRE_EMPTY) {
2053 if (check) {
2054 return TRUE;
2055 }
2057 if (is_ai(cplayer)) {
2060 cmd_reply(cmd_of_level(level), caller, C_OK,
2061 _("Player '%s' now has AI skill level '%s'."),
2064 }
2068 cmd_reply(cmd_of_level(level), caller, C_OK,
2069 _("Default AI skill level set to '%s'."),
2071 } else {
2073 return FALSE;
2074 }
2075 return TRUE;
2076}
2077
2078/**********************************************************************/
2081static bool away_command(struct connection *caller, bool check)
2082{
2083 struct player *pplayer;
2084
2085 if (caller == NULL) {
2086 cmd_reply(CMD_AWAY, caller, C_FAIL, _("This command is client only."));
2087 return FALSE;
2088 }
2089
2090 if (!conn_controls_player(caller)) {
2091 /* This happens for detached or observer connections. */
2092 cmd_reply(CMD_AWAY, caller, C_FAIL,
2093 _("Only players may use the away command."));
2094 return FALSE;
2095 }
2096
2097 if (check) {
2098 return TRUE;
2099 }
2100
2101 pplayer = conn_get_player(caller);
2102 if (is_human(pplayer)) {
2103 cmd_reply(CMD_AWAY, caller, C_OK,
2104 _("%s set to away mode."), player_name(pplayer));
2106 fc_assert(!is_human(pplayer));
2107 } else {
2108 cmd_reply(CMD_AWAY, caller, C_OK,
2109 _("%s returned to game."), player_name(pplayer));
2111 fc_assert(is_human(pplayer));
2112 }
2113
2115
2116 return TRUE;
2117}
2118
2119/**********************************************************************/
2122static void show_ruleset_info(struct connection *caller, enum command_id cmd,
2123 bool check, int read_recursion)
2124{
2125 char *show_arg = "changed";
2126
2127 /* show changed settings only at the top level of recursion */
2128 if (read_recursion != 0) {
2129 return;
2130 }
2131
2132 show_settings(caller, cmd, show_arg, check);
2133
2134 if (game.ruleset_summary != NULL) {
2136
2138 cmd_reply(cmd, caller, C_COMMENT, "%s", translated);
2139 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
2141 }
2142}
2143
2144/**********************************************************************/
2147static bool show_command(struct connection *caller, char *str, bool check)
2148{
2149 return show_settings(caller, CMD_SHOW, str, check);
2150}
2151
2152/**********************************************************************/
2157static bool show_settings(struct connection *caller,
2158 enum command_id called_as,
2159 char *str, bool check)
2160{
2161 int cmd;
2162 enum sset_level level = SSET_ALL;
2163 size_t clen = 0;
2164
2166 if (str[0] != '\0') {
2167 /* In "/show forests", figure out that it's the forests option we're
2168 * looking at. */
2169 cmd = lookup_option(str);
2170 if (cmd >= 0) {
2171 /* Ignore levels when a particular option is specified. */
2172 level = SSET_NONE;
2173
2174 if (!setting_is_visible(setting_by_number(cmd), caller)) {
2175 cmd_reply(called_as, caller, C_FAIL,
2176 _("Sorry, you do not have access to view option '%s'."),
2177 str);
2178 return FALSE;
2179 }
2180 }
2181
2182 /* Valid negative values for 'cmd' are defined as LOOKUP_OPTION_*. */
2183 switch (cmd) {
2185 cmd_reply(called_as, caller, C_FAIL, _("Unknown option '%s'."), str);
2186 return FALSE;
2188 /* Allow ambiguous: show all matching. */
2189 clen = strlen(str);
2190 break;
2192 /* Option level. */
2194 break;
2196 /* Ruleset. */
2197 cmd_reply(called_as, caller, C_COMMENT,
2198 _("Current ruleset directory is \"%s\""),
2200 return TRUE;
2201 }
2202 } else {
2203 /* to indicate that no command was specified */
2205 /* Use vital level by default. */
2206 level = SSET_VITAL;
2207 }
2208
2210 || cmd == LOOKUP_OPTION_LEVEL_NAME
2211 || cmd == LOOKUP_OPTION_NO_RESULT, FALSE);
2212
2213#define cmd_reply_show(string) \
2214 cmd_reply(called_as, caller, C_COMMENT, "%s", string)
2215
2216 {
2217 const char *heading = NULL;
2218 switch (level) {
2219 case SSET_NONE:
2220 break;
2221 case SSET_CHANGED:
2222 heading = _("All options with non-default values");
2223 break;
2224 case SSET_ALL:
2225 heading = _("All options");
2226 break;
2227 case SSET_VITAL:
2228 heading = _("Vital options");
2229 break;
2230 case SSET_SITUATIONAL:
2231 heading = _("Situational options");
2232 break;
2233 case SSET_RARE:
2234 heading = _("Rarely used options");
2235 break;
2236 case SSET_LOCKED:
2237 heading = _("Options locked by the ruleset");
2238 break;
2239 case OLEVELS_NUM:
2240 /* nothing */
2241 break;
2242 }
2243 if (heading) {
2246 }
2247 }
2249 cmd_reply_show(_("In the column '##' the status of the option is shown:"));
2250 cmd_reply_show(_(" - a '!' means the option is locked by the ruleset."));
2251 cmd_reply_show(_(" - a '+' means you may change the option."));
2252 cmd_reply_show(_(" - a '~' means that option follows default value."));
2253 cmd_reply_show(_(" - a '=' means the value is same as default."));
2255 cmd_reply(called_as, caller, C_COMMENT, _("%-*s ## value (min, max)"),
2256 OPTION_NAME_SPACE, _("Option"));
2258
2259 /* Update changed and locked levels. */
2261
2262 switch (level) {
2263 case SSET_NONE:
2264 /* Show _one_ setting. */
2265 fc_assert_ret_val(0 <= cmd, FALSE);
2266 {
2267 struct setting *pset = setting_by_number(cmd);
2268
2270 }
2271 break;
2272 case SSET_CHANGED:
2273 case SSET_ALL:
2274 case SSET_VITAL:
2275 case SSET_SITUATIONAL:
2276 case SSET_RARE:
2277 case SSET_LOCKED:
2279 if (!setting_is_visible(pset, caller)) {
2280 continue;
2281 }
2282
2283 if (LOOKUP_OPTION_AMBIGUOUS == cmd
2284 && 0 != fc_strncasecmp(setting_name(pset), str, clen)) {
2285 continue;
2286 }
2287
2290 break;
2291 case OLEVELS_NUM:
2292 /* nothing */
2293 break;
2294 }
2295
2297 /* Only emit this additional help for bona fide 'show' command */
2298 if (called_as == CMD_SHOW) {
2299 cmd_reply_show(_("A help text for each option is available via 'help "
2300 "<option>'."));
2302 if (level == SSET_VITAL) {
2303 cmd_reply_show(_("Try 'show situational' or 'show rare' to show "
2304 "more options.\n"
2305 "Try 'show changed' to show settings with "
2306 "non-default values.\n"
2307 "Try 'show locked' to show settings locked "
2308 "by the ruleset."));
2310 }
2311 }
2312 return TRUE;
2313#undef cmd_reply_show
2314}
2315
2316/**********************************************************************/
2329static void show_settings_one(struct connection *caller, enum command_id cmd,
2330 struct setting *pset)
2331{
2333 bool is_changed;
2334 static char prefix[OPTION_NAME_SPACE + 4 + 1] = "";
2335 char defaultness;
2336
2338
2341
2342 /* Wrap long option values, such as bitwise options */
2343 fc_break_lines(value, LINE_BREAK - (sizeof(prefix)-1));
2344
2345 if (prefix[0] == '\0') {
2346 memset(prefix, ' ', sizeof(prefix)-1);
2347 }
2348
2349 if (is_changed) {
2350 /* Emphasizes the changed option. */
2351 /* Apply tags to each line fragment. */
2352 size_t startpos = 0;
2353 char *nl;
2354
2355 do {
2356 nl = strchr(value + startpos, '\n');
2359 ftc_changed);
2361 if (nl) {
2362 char *p = strchr(nl, '\n');
2363
2364 fc_assert_action(p != NULL, break);
2365 startpos = p + 1 - value;
2366 }
2367 } while (nl);
2368 }
2369
2370 if (SST_INT == setting_type(pset)) {
2371 /* Add the range. */
2372 cat_snprintf(value, sizeof(value), " (%d, %d)",
2374 }
2375
2377 defaultness = '~';
2378 } else if (is_changed) {
2379 defaultness = ' ';
2380 } else {
2381 defaultness = '=';
2382 }
2383
2384 cmd_reply_prefix(cmd, caller, C_COMMENT, prefix, "%-*s %c%c %s",
2387 value);
2388}
2389
2390/**********************************************************************/
2393static bool team_command(struct connection *caller, char *str, bool check)
2394{
2395 struct player *pplayer;
2398 char *arg[2];
2399 int ntokens = 0, i;
2400 bool res = FALSE;
2401 struct team_slot *tslot;
2402
2403 if (game_was_started()) {
2404 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2405 _("Cannot change teams once game has begun."));
2406 return FALSE;
2407 }
2408
2409 if (str != NULL || strlen(str) > 0) {
2410 sz_strlcpy(buf, str);
2412 }
2413 if (ntokens != 2) {
2414 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2415 _("Undefined argument. Usage:\n%s"),
2417 goto cleanup;
2418 }
2419
2420 pplayer = player_by_name_prefix(arg[0], &match_result);
2421 if (pplayer == NULL) {
2423 goto cleanup;
2424 }
2425
2426 tslot = team_slot_by_rule_name(arg[1]);
2427 if (NULL == tslot) {
2428 int teamno;
2429
2430 if (str_to_int(arg[1], &teamno)) {
2432 }
2433 }
2434
2435 if (NULL == tslot) {
2436 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2437 _("No such team %s. Please give a "
2438 "valid team name or number."), arg[1]);
2439 goto cleanup;
2440 }
2441
2442 if (is_barbarian(pplayer)) {
2443 /* This can happen if we change team settings on a loaded game. */
2444 cmd_reply(CMD_TEAM, caller, C_SYNTAX, _("Cannot team a barbarian."));
2445 goto cleanup;
2446 }
2447
2448 if (!check) {
2449 /* Should never fail when slot given is not nullptr */
2450 team_add_player(pplayer, team_new(tslot));
2451 send_player_info_c(pplayer, NULL);
2452 cmd_reply(CMD_TEAM, caller, C_OK, _("Player %s set to team %s."),
2453 player_name(pplayer),
2455 }
2456
2457 res = TRUE;
2458
2459 cleanup:
2460 for (i = 0; i < ntokens; i++) {
2461 free(arg[i]);
2462 }
2463
2464 return res;
2465}
2466
2467/**********************************************************************/
2470static void show_votes(struct connection *caller)
2471{
2472 int count = 0;
2473 const char *title;
2474
2475 if (vote_list != NULL) {
2477 if (NULL != caller && !conn_can_see_vote(caller, pvote)) {
2478 continue;
2479 }
2480 /* TRANS: "Vote" or "Teamvote" is voting-as-a-process. Used as
2481 * part of a sentence. */
2482 title = vote_is_team_only(pvote) ? _("Teamvote") : _("Vote");
2483 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2484 /* TRANS: "[Vote|Teamvote] 3 \"proposed change\" (needs ..." */
2485 _("%s %d \"%s\" (needs %0.0f%%%s): %d for, "
2486 "%d against, and %d abstained out of %d players."),
2487 title, pvote->vote_no, pvote->cmdline,
2488 MIN(100, pvote->need_pc * 100 + 1),
2489 /* TRANS: preserve leading space */
2490 pvote->flags & VCF_NODISSENT ? _(" no dissent") : "",
2491 pvote->yes, pvote->no, pvote->abstain, count_voters(pvote));
2492 count++;
2494 }
2495
2496 if (count == 0) {
2497 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2498 _("There are no votes going on."));
2499 }
2500}
2501
2502/**********************************************************************/
2505static const char *const vote_args[] = {
2506 "yes",
2507 "no",
2508 "abstain",
2509 NULL
2510};
2511static const char *vote_arg_accessor(int i)
2512{
2513 return vote_args[i];
2514}
2515
2516/**********************************************************************/
2519static bool vote_command(struct connection *caller, char *str,
2520 bool check)
2521{
2523 char *arg[2];
2524 int ntokens = 0, i = 0, which = -1;
2526 struct vote *pvote = NULL;
2527 bool res = FALSE;
2528
2529 if (check) {
2530 /* This should never happen, since /vote must always be
2531 * set to ALLOW_BASIC or less. But just in case... */
2532 return FALSE;
2533 }
2534
2535 sz_strlcpy(buf, str);
2537
2538 if (ntokens == 0) {
2539 show_votes(caller);
2540 goto CLEANUP;
2541 } else if (!conn_can_vote(caller, NULL)) {
2542 cmd_reply(CMD_VOTE, caller, C_FAIL,
2543 _("You are not allowed to use this command."));
2544 goto CLEANUP;
2545 }
2546
2548 fc_strncasecmp, NULL, arg[0], &i);
2549
2551 cmd_reply(CMD_VOTE, caller, C_SYNTAX,
2552 _("The argument \"%s\" is ambiguous."), arg[0]);
2553 goto CLEANUP;
2554 } else if (match_result > M_PRE_AMBIGUOUS) {
2555 /* Failed */
2556 cmd_reply(CMD_VOTE, caller, C_SYNTAX,
2557 _("Undefined argument. Usage:\n%s"),
2559 goto CLEANUP;
2560 }
2561
2562 if (ntokens == 1) {
2563 /* Applies to last vote */
2566 } else {
2568 if (num_votes == 0) {
2569 cmd_reply(CMD_VOTE, caller, C_FAIL, _("There are no votes running."));
2570 } else {
2571 /* TRANS: "vote" as a process */
2572 cmd_reply(CMD_VOTE, caller, C_FAIL, _("No legal last vote (%d %s)."),
2573 num_votes, PL_("other vote running", "other votes running",
2574 num_votes));
2575 }
2576 goto CLEANUP;
2577 }
2578 } else {
2579 if (!str_to_int(arg[1], &which)) {
2580 cmd_reply(CMD_VOTE, caller, C_SYNTAX, _("Value must be an integer."));
2581 goto CLEANUP;
2582 }
2583 }
2584
2585 if (!(pvote = get_vote_by_no(which))) {
2586 /* TRANS: "vote" as a process */
2587 cmd_reply(CMD_VOTE, caller, C_FAIL, _("No such vote (%d)."), which);
2588 goto CLEANUP;
2589 }
2590
2591 if (!conn_can_vote(caller, pvote)) {
2592 cmd_reply(CMD_VOTE, caller, C_FAIL,
2593 _("You are not allowed to vote on that."));
2594 goto CLEANUP;
2595 }
2596
2597 if (i == VOTE_YES) {
2598 cmd_reply(CMD_VOTE, caller, C_COMMENT, _("You voted for \"%s\""),
2599 pvote->cmdline);
2600 connection_vote(caller, pvote, VOTE_YES);
2601 } else if (i == VOTE_NO) {
2602 cmd_reply(CMD_VOTE, caller, C_COMMENT, _("You voted against \"%s\""),
2603 pvote->cmdline);
2604 connection_vote(caller, pvote, VOTE_NO);
2605 } else if (i == VOTE_ABSTAIN) {
2606 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2607 _("You abstained from voting on \"%s\""), pvote->cmdline);
2609 } else {
2610 /* Must never happen. */
2612 }
2613
2614 res = TRUE;
2615
2616CLEANUP:
2617 free_tokens(arg, ntokens);
2618 return res;
2619}
2620
2621/**********************************************************************/
2624static bool cancelvote_command(struct connection *caller,
2625 char *arg, bool check)
2626{
2627 struct vote *pvote = NULL;
2628 int vote_no;
2629
2630 if (check) {
2631 /* This should never happen anyway, since /cancelvote
2632 * is set to ALLOW_BASIC in both pregame and while the
2633 * game is running. */
2634 return FALSE;
2635 }
2636
2638
2639 if (arg[0] == '\0') {
2640 if (caller == NULL) {
2641 /* Server prompt */
2643 /* TRANS: "vote" as a process */
2644 _("Missing argument <vote number> or "
2645 "the string \"all\"."));
2646 return FALSE;
2647 }
2648 /* The caller is canceling their own vote. */
2649 if (!(pvote = get_vote_by_caller(caller))) {
2651 _("You don't have any vote going on."));
2652 return FALSE;
2653 }
2654 } else if (fc_strcasecmp(arg, "all") == 0) {
2655 /* Cancel all votes (needs some privileges). */
2656 if (vote_list_size(vote_list) == 0) {
2658 _("There isn't any vote going on."));
2659 return FALSE;
2660 } else if (!caller || conn_get_access(caller) >= ALLOW_ADMIN) {
2663 /* TRANS: "votes" as a process */
2664 _("All votes have been removed."));
2665 return TRUE;
2666 } else {
2668 _("You are not allowed to use this command."));
2669 return FALSE;
2670 }
2671 } else if (str_to_int(arg, &vote_no)) {
2672 /* Cancel one particular vote (needs some privileges if the vote
2673 * is not owned). */
2674 if (!(pvote = get_vote_by_no(vote_no))) {
2676 /* TRANS: "vote" as a process */
2677 _("No such vote (%d)."), vote_no);
2678 return FALSE;
2679 } else if (caller && conn_get_access(caller) < ALLOW_ADMIN
2680 && caller->id != pvote->caller_id) {
2682 /* TRANS: "vote" as a process */
2683 _("You are not allowed to cancel this vote (%d)."),
2684 vote_no);
2685 return FALSE;
2686 }
2687 } else {
2689 /* TRANS: "vote" as a process */
2690 _("Usage: /cancelvote [<vote number>|all]"));
2691 return FALSE;
2692 }
2693
2695
2696 if (caller) {
2699 /* TRANS: "vote" as a process */
2700 _("%s has canceled the vote \"%s\" (number %d)."),
2701 caller->username, pvote->cmdline, pvote->vote_no);
2702 } else {
2703 /* Server prompt */
2706 /* TRANS: "vote" as a process */
2707 _("The vote \"%s\" (number %d) has been canceled."),
2708 pvote->cmdline, pvote->vote_no);
2709 }
2710 /* Make it after, prevent crashs about a free pointer (pvote). */
2712
2713 return TRUE;
2714}
2715
2716/**********************************************************************/
2719static bool debug_command(struct connection *caller, char *str,
2720 bool check)
2721{
2723 char *arg[3];
2724 int ntokens = 0, i;
2725
2726 if (game.info.is_new_game) {
2727 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2728 _("Can only use this command once game has begun."));
2729 return FALSE;
2730 }
2731 if (check) {
2732 return TRUE; /* whatever! */
2733 }
2734
2735 if (str != NULL && strlen(str) > 0) {
2736 sz_strlcpy(buf, str);
2738 } else {
2739 ntokens = 0;
2740 }
2741
2742 if (ntokens > 0 && strcmp(arg[0], "diplomacy") == 0) {
2743 struct player *pplayer;
2745
2746 if (ntokens != 2) {
2747 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2748 _("Undefined argument. Usage:\n%s"),
2750 goto cleanup;
2751 }
2752 pplayer = player_by_name_prefix(arg[1], &match_result);
2753 if (pplayer == NULL) {
2755 goto cleanup;
2756 }
2759 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s diplomacy no longer debugged"),
2760 player_name(pplayer));
2761 } else {
2763 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s diplomacy debugged"),
2764 player_name(pplayer));
2765 /* TODO: print some info about the player here */
2766 }
2767 } else if (ntokens > 0 && strcmp(arg[0], "tech") == 0) {
2768 struct player *pplayer;
2770
2771 if (ntokens != 2) {
2772 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2773 _("Undefined argument. Usage:\n%s"),
2775 goto cleanup;
2776 }
2777 pplayer = player_by_name_prefix(arg[1], &match_result);
2778 if (pplayer == NULL) {
2780 goto cleanup;
2781 }
2782 if (BV_ISSET(pplayer->server.debug, PLAYER_DEBUG_TECH)) {
2784 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s tech no longer debugged"),
2785 player_name(pplayer));
2786 } else {
2788 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s tech debugged"),
2789 player_name(pplayer));
2790 /* TODO: print some info about the player here */
2791 }
2792 } else if (ntokens > 0 && strcmp(arg[0], "info") == 0) {
2793 int cities = 0, players = 0, units = 0, citizen_count = 0;
2794
2795 players_iterate(plr) {
2796 players++;
2797 city_list_iterate(plr->cities, pcity) {
2798 cities++;
2801 units += unit_list_size(plr->units);
2803 log_normal(_("players=%d cities=%d citizens=%d units=%d"),
2804 players, cities, citizen_count, units);
2806 _("players=%d cities=%d citizens=%d units=%d"),
2807 players, cities, citizen_count, units);
2808 } else if (ntokens > 0 && strcmp(arg[0], "city") == 0) {
2809 int x, y;
2810 struct tile *ptile;
2811 struct city *pcity;
2812
2813 if (ntokens != 3) {
2814 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2815 _("Undefined argument. Usage:\n%s"),
2817 goto cleanup;
2818 }
2819 if (!str_to_int(arg[1], &x) || !str_to_int(arg[2], &y)) {
2820 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be integer."));
2821 goto cleanup;
2822 }
2823 if (!(ptile = map_pos_to_tile(&(wld.map), x, y))) {
2824 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
2825 goto cleanup;
2826 }
2827 pcity = tile_city(ptile);
2828 if (!pcity) {
2829 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("No city at this coordinate."));
2830 goto cleanup;
2831 }
2832 if (pcity->server.debug) {
2834 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s no longer debugged"),
2836 } else {
2838 CITY_LOG(LOG_NORMAL, pcity, "debugged");
2839 }
2840 } else if (ntokens > 0 && strcmp(arg[0], "units") == 0) {
2841 int x, y;
2842 struct tile *ptile;
2843
2844 if (ntokens != 3) {
2845 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2846 _("Undefined argument. Usage:\n%s"),
2848 goto cleanup;
2849 }
2850 if (!str_to_int(arg[1], &x) || !str_to_int(arg[2], &y)) {
2851 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be integer."));
2852 goto cleanup;
2853 }
2854 if (!(ptile = map_pos_to_tile(&(wld.map), x, y))) {
2855 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
2856 goto cleanup;
2857 }
2858 unit_list_iterate(ptile->units, punit) {
2859 if (punit->server.debug) {
2861 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s %s no longer debugged."),
2864 } else {
2866 UNIT_LOG(LOG_NORMAL, punit, "%s %s debugged.",
2869 }
2871 } else if (ntokens > 0 && strcmp(arg[0], "timing") == 0) {
2873 } else if (ntokens > 0 && strcmp(arg[0], "ferries") == 0) {
2876 cmd_reply(CMD_DEBUG, caller, C_OK, _("Ferry system is no longer "
2877 "in debug mode."));
2878 } else {
2880 cmd_reply(CMD_DEBUG, caller, C_OK, _("Ferry system in debug mode."));
2881 }
2882 } else if (ntokens > 0 && strcmp(arg[0], "unit") == 0) {
2883 int id;
2884 struct unit *punit;
2885
2886 if (ntokens != 2) {
2887 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2888 _("Undefined argument. Usage:\n%s"),
2890 goto cleanup;
2891 }
2892 if (!str_to_int(arg[1], &id)) {
2893 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 must be integer."));
2894 goto cleanup;
2895 }
2896 if (!(punit = game_unit_by_number(id))) {
2897 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Unit %d does not exist."), id);
2898 goto cleanup;
2899 }
2900 if (punit->server.debug) {
2902 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s %s no longer debugged."),
2905 } else {
2907 UNIT_LOG(LOG_NORMAL, punit, "%s %s debugged.",
2910 }
2911 } else {
2912 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2913 _("Undefined argument. Usage:\n%s"),
2915 }
2916 cleanup:
2917 for (i = 0; i < ntokens; i++) {
2918 free(arg[i]);
2919 }
2920 return TRUE;
2921}
2922
2923/**********************************************************************/
2928 struct connection *caller,
2929 char *arg)
2930{
2931 int opt = lookup_option(arg);
2932
2933 if (opt < 0) {
2934 switch (opt) {
2937 cmd_reply(cmd, caller, C_SYNTAX, _("Option '%s' not recognized."), arg);
2938 break;
2940 cmd_reply(cmd, caller, C_SYNTAX, _("Ambiguous option name."));
2941 break;
2943 cmd_reply(cmd, caller, C_SYNTAX,
2944 /* TRANS: 'rulesetdir' is the command. Do not translate. */
2945 _("Use the '%srulesetdir' command to change the ruleset "
2946 "directory."), caller ? "/" : "");
2947 break;
2948 default:
2950 break;
2951 }
2952 return NULL;
2953 }
2954
2955 return setting_by_number(opt);
2956}
2957
2958/**********************************************************************/
2961static bool set_command(struct connection *caller, char *str, bool check)
2962{
2963 char *args[2];
2964 int val, nargs;
2965 struct setting *pset;
2966 bool do_update;
2967 char reject_msg[256] = "";
2968 bool ret = FALSE;
2969
2970 /* '=' is also a valid delimiter for this function. */
2971 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS "=");
2972
2973 if (nargs < 2) {
2974 cmd_reply(CMD_SET, caller, C_SYNTAX,
2975 _("Undefined argument. Usage:\n%s"),
2977 goto cleanup;
2978 }
2979
2980 pset = validate_setting_arg(CMD_SET, caller, args[0]);
2981
2982 if (!pset) {
2983 /* Reason already reported. */
2984 goto cleanup;
2985 }
2986
2987 if (!setting_is_changeable(pset, caller, reject_msg, sizeof(reject_msg))
2988 && !check) {
2989 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
2990 goto cleanup;
2991 }
2992
2993 do_update = FALSE;
2994
2995 switch (setting_type(pset)) {
2996 case SST_BOOL:
2997 if (check) {
2999 sizeof(reject_msg))
3000 || (!setting_bool_validate(pset, args[1], caller,
3001 reject_msg, sizeof(reject_msg)))) {
3002 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3003 goto cleanup;
3004 }
3005 } else if (setting_bool_set(pset, args[1], caller,
3006 reject_msg, sizeof(reject_msg))) {
3007 do_update = TRUE;
3008 } else {
3009 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3010 goto cleanup;
3011 }
3012 break;
3013
3014 case SST_INT:
3015 if (!str_to_int(args[1], &val)) {
3016 cmd_reply(CMD_SET, caller, C_SYNTAX,
3017 _("The parameter %s should only contain +- and 0-9."),
3019 goto cleanup;
3020 }
3021 if (check) {
3023 sizeof(reject_msg))
3024 || !setting_int_validate(pset, val, caller, reject_msg,
3025 sizeof(reject_msg))) {
3026 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3027 goto cleanup;
3028 }
3029 } else {
3030 if (setting_int_set(pset, val, caller, reject_msg,
3031 sizeof(reject_msg))) {
3032 do_update = TRUE;
3033 } else {
3034 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3035 goto cleanup;
3036 }
3037 }
3038 break;
3039
3040 case SST_STRING:
3041 if (check) {
3043 sizeof(reject_msg))
3044 || !setting_str_validate(pset, args[1], caller, reject_msg,
3045 sizeof(reject_msg))) {
3046 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3047 goto cleanup;
3048 }
3049 } else {
3050 if (setting_str_set(pset, args[1], caller, reject_msg,
3051 sizeof(reject_msg))) {
3052 do_update = TRUE;
3053 } else {
3054 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3055 goto cleanup;
3056 }
3057 }
3058 break;
3059
3060 case SST_ENUM:
3061 if (check) {
3063 sizeof(reject_msg))
3064 || (!setting_enum_validate(pset, args[1], caller,
3065 reject_msg, sizeof(reject_msg)))) {
3066 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3067 goto cleanup;
3068 }
3069 } else if (setting_enum_set(pset, args[1], caller,
3070 reject_msg, sizeof(reject_msg))) {
3071 do_update = TRUE;
3072 } else {
3073 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3074 goto cleanup;
3075 }
3076 break;
3077
3078 case SST_BITWISE:
3079 if (check) {
3081 sizeof(reject_msg))
3082 || (!setting_bitwise_validate(pset, args[1], caller,
3083 reject_msg, sizeof(reject_msg)))) {
3084 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3085 goto cleanup;
3086 }
3087 } else if (setting_bitwise_set(pset, args[1], caller,
3088 reject_msg, sizeof(reject_msg))) {
3089 do_update = TRUE;
3090 } else {
3091 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3092 goto cleanup;
3093 }
3094 break;
3095
3096 case SST_COUNT:
3098 goto cleanup;
3099 break;
3100 }
3101
3102 ret = TRUE; /* Looks like a success. */
3103
3104 if (!check && do_update) {
3105 /* Send only to connections able to see that. */
3106 char buf[256];
3107 struct packet_chat_msg packet;
3108
3110 _("Console: '%s' has been set to %s."), setting_name(pset),
3111 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3114 send_packet_chat_msg(pconn, &packet);
3115 }
3117 /* Notify the console. */
3118 con_write(C_OK, "%s", packet.message);
3119
3123 /*
3124 * send any modified game parameters to the clients -- if sent
3125 * before S_S_RUNNING, triggers a popdown_races_dialog() call
3126 * in client/packhand.c#handle_game_info()
3127 */
3131 }
3132
3133 cleanup:
3134 free_tokens(args, nargs);
3135 return ret;
3136}
3137
3138/**********************************************************************/
3141static bool lock_command(struct connection *caller, char *str, bool check)
3142{
3143 char *args[1];
3144 int nargs;
3145
3146 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS);
3147
3148 if (nargs < 1) {
3149 cmd_reply(CMD_LOCK, caller, C_SYNTAX,
3150 _("Undefined argument. Usage:\n%s"),
3152 } else {
3153 struct setting *pset;
3154
3155 pset = validate_setting_arg(CMD_SET, caller, args[0]);
3156
3157 if (pset != NULL) {
3159 return TRUE;
3160 }
3161 }
3162
3163 return FALSE;
3164}
3165
3166/**********************************************************************/
3169static bool unlock_command(struct connection *caller, char *str, bool check)
3170{
3171 char *args[1];
3172 int nargs;
3173
3174 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS);
3175
3176 if (nargs < 1) {
3177 cmd_reply(CMD_LOCK, caller, C_SYNTAX,
3178 _("Undefined argument. Usage:\n%s"),
3180 } else {
3181 struct setting *pset;
3182
3183 pset = validate_setting_arg(CMD_SET, caller, args[0]);
3184
3185 if (pset != NULL) {
3187 return TRUE;
3188 }
3189 }
3190
3191 return FALSE;
3192}
3193
3194/**********************************************************************/
3202 struct connection *taker,
3203 struct player *pplayer, bool will_obs,
3204 char *msg, size_t msg_len)
3205{
3206 const char *allow;
3207
3208 if (!pplayer && !will_obs) {
3209 /* Auto-taking a new player */
3210
3211 if (game_was_started()) {
3212 fc_strlcpy(msg, _("You cannot take a new player at this time."),
3213 msg_len);
3214 return FALSE;
3215 }
3216
3218 fc_snprintf(msg, msg_len,
3219 /* TRANS: Do not translate "maxplayers". */
3220 PL_("You cannot take a new player because "
3221 "the maximum of %d player has already "
3222 "been reached (maxplayers setting).",
3223 "You cannot take a new player because "
3224 "the maximum of %d players has already "
3225 "been reached (maxplayers setting).",
3228 return FALSE;
3229 }
3230
3231 if (player_count() >= player_slot_count()) {
3232 fc_strlcpy(msg, _("You cannot take a new player because there "
3233 "are no free player slots."),
3234 msg_len);
3235 return FALSE;
3236 }
3237
3238 return TRUE;
3239
3240 }
3241
3242#ifdef HAVE_FCDB
3243 if (srvarg.fcdb_enabled) {
3244 bool ok = FALSE;
3245
3246 if (script_fcdb_call("user_take", requester, taker, pplayer, will_obs,
3247 &ok) && ok) {
3248 return TRUE;
3249 }
3250 }
3251#endif
3252
3253 if (!pplayer && will_obs) {
3254 /* Global observer. */
3256 (game.info.is_new_game ? 'O' : 'o')))) {
3257 fc_strlcpy(msg, _("Sorry, one can't observe globally in this game."),
3258 msg_len);
3259 return FALSE;
3260 }
3261 } else if (is_barbarian(pplayer)) {
3262 if (!(allow = strchr(game.server.allow_take, 'b'))) {
3263 if (will_obs) {
3264 fc_strlcpy(msg,
3265 _("Sorry, one can't observe barbarians in this game."),
3266 msg_len);
3267 } else {
3268 fc_strlcpy(msg, _("Sorry, one can't take barbarians in this game."),
3269 msg_len);
3270 }
3271 return FALSE;
3272 }
3273 } else if (!pplayer->is_alive) {
3274 if (!(allow = strchr(game.server.allow_take, 'd'))) {
3275 if (will_obs) {
3276 fc_strlcpy(msg,
3277 _("Sorry, one can't observe dead players in this game."),
3278 msg_len);
3279 } else {
3280 fc_strlcpy(msg,
3281 _("Sorry, one can't take dead players in this game."),
3282 msg_len);
3283 }
3284 return FALSE;
3285 }
3286 } else if (is_ai(pplayer)) {
3288 (game.info.is_new_game ? 'A' : 'a')))) {
3289 if (will_obs) {
3290 fc_strlcpy(msg,
3291 _("Sorry, one can't observe AI players in this game."),
3292 msg_len);
3293 } else {
3294 fc_strlcpy(msg, _("Sorry, one can't take AI players in this game."),
3295 msg_len);
3296 }
3297 return FALSE;
3298 }
3299 } else {
3301 (game.info.is_new_game ? 'H' : 'h')))) {
3302 if (will_obs) {
3303 fc_strlcpy(msg,
3304 _("Sorry, one can't observe human players in this game."),
3305 msg_len);
3306 } else {
3307 fc_strlcpy(msg,
3308 _("Sorry, one can't take human players in this game."),
3309 msg_len);
3310 }
3311 return FALSE;
3312 }
3313 }
3314
3315 allow++;
3316
3317 if (will_obs && (*allow == '2' || *allow == '3')) {
3318 fc_strlcpy(msg, _("Sorry, one can't observe in this game."), msg_len);
3319 return FALSE;
3320 }
3321
3322 if (!will_obs && *allow == '4') {
3323 fc_strlcpy(msg, _("Sorry, one can't take players in this game."),
3324 MAX_LEN_MSG);
3325 return FALSE;
3326 }
3327
3328 if (!will_obs && pplayer->is_connected
3329 && (*allow == '1' || *allow == '3')) {
3330 fc_strlcpy(msg, _("Sorry, one can't take players already "
3331 "connected in this game."), msg_len);
3332 return FALSE;
3333 }
3334
3335 return TRUE;
3336}
3337
3338/**********************************************************************/
3343static bool observe_command(struct connection *caller, char *str, bool check)
3344{
3345 int i = 0, ntokens = 0;
3346 char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
3347 bool is_newgame = !game_was_started();
3348 enum m_pre_result result;
3349 struct connection *pconn = NULL;
3350 struct player *pplayer = NULL;
3351 bool res = FALSE;
3352
3353 /******** PART I: fill pconn and pplayer ********/
3354
3355 sz_strlcpy(buf, str);
3357
3358 /* check syntax, only certain syntax if allowed depending on the caller */
3359 if (!caller && ntokens < 1) {
3360 cmd_reply(CMD_OBSERVE, caller, C_SYNTAX, _("Usage:\n%s"),
3362 goto end;
3363 }
3364
3365 if (ntokens == 2 && (caller && caller->access_level != ALLOW_HACK)) {
3367 _("Only the player name form is allowed."));
3368 goto end;
3369 }
3370
3371 /* match connection if we're console, match a player if we're not */
3372 if (ntokens == 1) {
3373 if (!caller && !(pconn = conn_by_user_prefix(arg[0], &result))) {
3374 cmd_reply_no_such_conn(CMD_OBSERVE, caller, arg[0], result);
3375 goto end;
3376 } else if (caller
3377 && !(pplayer = player_by_name_prefix(arg[0], &result))) {
3378 cmd_reply_no_such_player(CMD_OBSERVE, caller, arg[0], result);
3379 goto end;
3380 }
3381 }
3382
3383 /* get connection name then player name */
3384 if (ntokens == 2) {
3385 if (!(pconn = conn_by_user_prefix(arg[0], &result))) {
3386 cmd_reply_no_such_conn(CMD_OBSERVE, caller, arg[0], result);
3387 goto end;
3388 }
3389 if (!(pplayer = player_by_name_prefix(arg[1], &result))) {
3390 cmd_reply_no_such_player(CMD_OBSERVE, caller, arg[1], result);
3391 goto end;
3392 }
3393 }
3394
3395 /* if we can't force other connections to observe, assign us to be pconn. */
3396 if (!pconn) {
3397 pconn = caller;
3398 }
3399
3400 /* if we have no pplayer, it means that we want to be a global observer */
3401
3402 /******** PART II: do the observing ********/
3403
3404 /* check allowtake for permission */
3405 if (!is_allowed_to_take(caller, pconn, pplayer, TRUE, msg, sizeof(msg))) {
3406 cmd_reply(CMD_OBSERVE, caller, C_FAIL, "%s", msg);
3407 goto end;
3408 }
3409
3410 /* observing your own player (during pregame) makes no sense. */
3411 if (NULL != pplayer
3412 && pplayer == pconn->playing
3413 && !pconn->observer
3414 && is_newgame
3415 && !pplayer->was_created) {
3416 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3417 _("%s already controls %s. Using 'observe' would remove %s"),
3418 pconn->username,
3419 player_name(pplayer),
3420 player_name(pplayer));
3421 goto end;
3422 }
3423
3424 /* attempting to observe a player you're already observing should fail. */
3425 if (pplayer == pconn->playing && pconn->observer) {
3426 if (pplayer) {
3427 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3428 _("%s is already observing %s."),
3429 pconn->username,
3430 player_name(pplayer));
3431 } else {
3432 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3433 _("%s is already observing."),
3434 pconn->username);
3435 }
3436 goto end;
3437 }
3438
3439 res = TRUE; /* all tests passed */
3440 if (check) {
3441 goto end;
3442 }
3443
3444 /* if the connection is already attached to a player,
3445 * unattach and cleanup old player (rename, remove, etc) */
3446 if (TRUE) {
3447 char name[MAX_LEN_NAME];
3448
3449 if (pplayer) {
3450 /* if pconn->playing is removed, we'll lose pplayer */
3451 sz_strlcpy(name, player_name(pplayer));
3452 }
3453
3455
3456 if (pplayer) {
3457 /* find pplayer again, the pointer might have been changed */
3458 pplayer = player_by_name(name);
3459 }
3460 }
3461
3462 /* attach pconn to new player as an observer or as global observer */
3463 if ((res = connection_attach(pconn, pplayer, TRUE))) {
3464 if (pplayer) {
3465 cmd_reply(CMD_OBSERVE, caller, C_OK, _("%s now observes %s"),
3466 pconn->username,
3467 player_name(pplayer));
3468 } else {
3469 cmd_reply(CMD_OBSERVE, caller, C_OK, _("%s now observes"),
3470 pconn->username);
3471 }
3472 }
3473
3474 end:;
3475 /* free our args */
3476 for (i = 0; i < ntokens; i++) {
3477 free(arg[i]);
3478 }
3479 return res;
3480}
3481
3482/**********************************************************************/
3491static bool take_command(struct connection *caller, char *str, bool check)
3492{
3493 int i = 0, ntokens = 0;
3494 char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
3495 bool is_newgame = !game_was_started();
3497 struct connection *pconn = caller;
3498 struct player *pplayer = NULL;
3499 bool res = FALSE;
3500
3501 /******** PART I: fill pconn and pplayer ********/
3502
3503 sz_strlcpy(buf, str);
3505
3506 /* check syntax */
3507 if (!caller && ntokens != 2) {
3508 cmd_reply(CMD_TAKE, caller, C_SYNTAX, _("Usage:\n%s"),
3510 goto end;
3511 }
3512
3513 if (caller && caller->access_level != ALLOW_HACK && ntokens != 1) {
3514 cmd_reply(CMD_TAKE, caller, C_SYNTAX,
3515 _("Only the player name form is allowed."));
3516 goto end;
3517 }
3518
3519 if (ntokens == 0) {
3520 cmd_reply(CMD_TAKE, caller, C_SYNTAX, _("Usage:\n%s"),
3522 goto end;
3523 }
3524
3525 if (ntokens == 2) {
3526 if (!(pconn = conn_by_user_prefix(arg[i], &match_result))) {
3528 goto end;
3529 }
3530 i++; /* found a conn, now reference the second argument */
3531 }
3532
3533 if (strcmp(arg[i], "-") == 0) {
3534 if (!is_newgame) {
3535 cmd_reply(CMD_TAKE, caller, C_FAIL,
3536 _("You cannot issue \"/take -\" when "
3537 "the game has already started."));
3538 goto end;
3539 }
3540
3541 /* Find first uncontrolled player. This will return NULL if there is
3542 * no free players at the moment. Later call to
3543 * connection_attach() will create new player for such NULL
3544 * cases. */
3545 pplayer = find_uncontrolled_player();
3546 if (pplayer) {
3547 /* Make it human! */
3548 set_as_human(pplayer);
3549 }
3550 } else if (!(pplayer = player_by_name_prefix(arg[i], &match_result))) {
3552 goto end;
3553 }
3554
3555 /******** PART II: do the attaching ********/
3556
3557 /* Take not possible if the player is involved in a delegation (either
3558 * it's being controlled, or it's been put aside by the delegate). */
3559 if (player_delegation_active(pplayer)) {
3560 cmd_reply(CMD_TAKE, caller, C_FAIL, _("A delegation is active for player "
3561 "'%s'. /take not possible."),
3562 player_name(pplayer));
3563 goto end;
3564 }
3565
3566 /* check allowtake for permission */
3567 if (!is_allowed_to_take(caller, pconn, pplayer, FALSE, msg, sizeof(msg))) {
3568 cmd_reply(CMD_TAKE, caller, C_FAIL, "%s", msg);
3569 goto end;
3570 }
3571
3572 /* taking your own player makes no sense. */
3573 if ((NULL != pplayer && !pconn->observer && pplayer == pconn->playing)
3574 || (NULL == pplayer && !pconn->observer && NULL != pconn->playing)) {
3575 cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s already controls %s."),
3576 pconn->username,
3577 player_name(pconn->playing));
3578 goto end;
3579 }
3580
3581 /* Make sure there is free player slot if there is need to
3582 * create new player. This is necessary for previously
3583 * detached connections only. Others can reuse the slot
3584 * they first release. */
3585 if (!pplayer && !pconn->playing
3587 || normal_player_count() >= server.playable_nations)) {
3588 cmd_reply(CMD_TAKE, caller, C_FAIL,
3589 _("There is no free player slot for %s."),
3590 pconn->username);
3591 goto end;
3592 }
3594
3595 res = TRUE;
3596 if (check) {
3597 goto end;
3598 }
3599
3600 /* If the player is controlled by another user, forcibly detach
3601 * the user. */
3602 if (pplayer && pplayer->is_connected) {
3603 if (NULL == caller) {
3605 _("Reassigned nation to %s by server console."),
3606 pconn->username);
3607 } else {
3609 _("Reassigned nation to %s by %s."),
3610 pconn->username,
3611 caller->username);
3612 }
3613
3614 /* We are reassigning this nation, so we need to detach the current
3615 * user to set a new one. */
3617 if (!aconn->observer) {
3619 }
3621 }
3622
3623 /* if the connection is already attached to another player,
3624 * unattach and cleanup old player (rename, remove, etc)
3625 * We may have been observing the player we now want to take */
3626 if (NULL != pconn->playing || pconn->observer) {
3627 char name[MAX_LEN_NAME];
3628
3629 if (pplayer) {
3630 /* if pconn->playing is removed, we'll lose pplayer */
3631 sz_strlcpy(name, player_name(pplayer));
3632 }
3633
3635
3636 if (pplayer) {
3637 /* find pplayer again; the pointer might have been changed */
3638 pplayer = player_by_name(name);
3639 }
3640 }
3641
3642 /* Now attach to new player */
3643 if ((res = connection_attach(pconn, pplayer, FALSE))) {
3644 /* Successfully attached */
3645 pplayer = pconn->playing; /* In case pplayer was NULL. */
3646
3647 /* inform about the status before changes */
3648 cmd_reply(CMD_TAKE, caller, C_OK, _("%s now controls %s (%s, %s)."),
3649 pconn->username,
3650 player_name(pplayer),
3651 is_barbarian(pplayer)
3652 ? _("Barbarian")
3653 : is_ai(pplayer)
3654 ? _("AI")
3655 : _("Human"),
3656 pplayer->is_alive
3657 ? _("Alive")
3658 : _("Dead"));
3659 } else {
3660 cmd_reply(CMD_TAKE, caller, C_FAIL,
3661 _("%s failed to attach to any player."),
3662 pconn->username);
3663 }
3664
3665 end:;
3666 /* free our args */
3667 for (i = 0; i < ntokens; i++) {
3668 free(arg[i]);
3669 }
3670 return res;
3671}
3672
3673/**********************************************************************/
3680static bool detach_command(struct connection *caller, char *str, bool check)
3681{
3682 int i = 0, ntokens = 0;
3683 char buf[MAX_LEN_CONSOLE_LINE], *arg[1];
3685 struct connection *pconn = NULL;
3686 struct player *pplayer = NULL;
3687 bool res = FALSE;
3688
3689 sz_strlcpy(buf, str);
3691
3692 if (!caller && ntokens == 0) {
3693 cmd_reply(CMD_DETACH, caller, C_SYNTAX, _("Usage:\n%s"),
3695 goto end;
3696 }
3697
3698 /* match the connection if the argument was given */
3699 if (ntokens == 1
3700 && !(pconn = conn_by_user_prefix(arg[0], &match_result))) {
3702 goto end;
3703 }
3704
3705 /* if no argument is given, the caller wants to detach themself */
3706 if (!pconn) {
3707 pconn = caller;
3708 }
3709
3710 /* if pconn and caller are not the same, only continue
3711 * if we're console, or we have ALLOW_HACK */
3712 if (pconn != caller && caller && caller->access_level != ALLOW_HACK) {
3713 cmd_reply(CMD_DETACH, caller, C_FAIL,
3714 _("You can not detach other users."));
3715 goto end;
3716 }
3717
3718 pplayer = pconn->playing;
3719
3720 /* must have someone to detach from... */
3721 if (!pplayer && !pconn->observer) {
3722 cmd_reply(CMD_DETACH, caller, C_FAIL,
3723 _("%s is not attached to any player."), pconn->username);
3724 goto end;
3725 }
3726
3727 res = TRUE;
3728 if (check) {
3729 goto end;
3730 }
3731
3732 if (pplayer) {
3733 cmd_reply(CMD_DETACH, caller, C_OK, _("%s detaching from %s"),
3734 pconn->username, player_name(pplayer));
3735 } else {
3736 cmd_reply(CMD_DETACH, caller, C_OK, _("%s no longer observing."),
3737 pconn->username);
3738 }
3739
3740 /* Actually do the detaching. */
3742
3743 /* The user explicitly wanted to detach, so if a player is marked for
3744 * them, reset its username. */
3746 if (!fc_strncmp(aplayer->username, pconn->username, MAX_LEN_NAME)) {
3747 sz_strlcpy(aplayer->username, _(ANON_USER_NAME));
3748 aplayer->unassigned_user = TRUE;
3750 }
3752
3754
3755 end:
3757
3758 /* free our args */
3759 for (i = 0; i < ntokens; i++) {
3760 free(arg[i]);
3761 }
3762 return res;
3763}
3764
3765/**********************************************************************/
3786bool load_command(struct connection *caller, const char *filename, bool check,
3787 bool cmdline_load)
3788{
3789 struct timer *loadtimer, *uloadtimer;
3790 struct section_file *file;
3791 char arg[MAX_LEN_PATH];
3793
3794 if (!filename || filename[0] == '\0') {
3795 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Usage:\n%s"),
3797 return FALSE;
3798 }
3799 if (S_S_INITIAL != server_state()) {
3800 cmd_reply(CMD_LOAD, caller, C_FAIL,
3801 _("Cannot load a game while another is running."));
3802 return FALSE;
3803 }
3804 if (!is_safe_filename(filename) && is_restricted(caller)) {
3805 cmd_reply(CMD_LOAD, caller, C_FAIL,
3806 _("Name \"%s\" disallowed for security reasons."),
3807 filename);
3808 return FALSE;
3809 }
3810
3811 {
3812 /* It is a normal savegame or maybe a scenario */
3813 char testfile[MAX_LEN_PATH];
3814 const struct strvec *paths[] = {
3816 };
3817 const char *exts[] = {
3818 "sav", "gz", "bz2", "xz", "sav.gz", "sav.bz2", "sav.xz", "sav.zst", NULL
3819 };
3820 const char **ext, *found = NULL;
3821 const struct strvec **path;
3822
3823 if (cmdline_load) {
3824 /* Allow plain names being loaded with '--file' option, but not otherwise
3825 * (no loading of arbitrary files by unauthorized users)
3826 * Iterate through ALL paths to check for file with plain name before
3827 * looking any path with an extension, i.e., prefer plain name file
3828 * in later directory over file with extension in name in earlier
3829 * directory. */
3830 for (path = paths; !found && *path; path++) {
3831 found = fileinfoname(*path, filename);
3832 if (found != NULL) {
3833 sz_strlcpy(arg, found);
3834 }
3835 }
3836 }
3837
3838 for (path = paths; !found && *path; path++) {
3839 for (ext = exts; !found && *ext; ext++) {
3840 fc_snprintf(testfile, sizeof(testfile), "%s.%s", filename, *ext);
3841 found = fileinfoname(*path, testfile);
3842 if (found != NULL) {
3843 sz_strlcpy(arg, found);
3844 }
3845 }
3846 }
3847
3848 if (is_restricted(caller) && !found) {
3849 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Cannot find savegame or "
3850 "scenario with the name \"%s\"."), filename);
3851 return FALSE;
3852 }
3853
3854 if (!found) {
3855 sz_strlcpy(arg, filename);
3856 }
3857 }
3858
3859 /* attempt to parse the file */
3860
3861 if (!(file = secfile_load(arg, FALSE))) {
3862 log_error("Error loading savefile '%s': %s", arg, secfile_error());
3863 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Could not load savefile: %s"),
3864 arg);
3866 return FALSE;
3867 }
3868
3869 if (check) {
3870 return TRUE;
3871 }
3872
3873 /* Detach current players, before we blow them away. */
3876 if (pconn->playing != NULL) {
3878 } else if (pconn->observer) {
3881 }
3883
3885
3886 /* Now free all game data. */
3888
3889 /* Keep old ruleset value. Scenario file will either use the old value,
3890 * or to initialize new value itself. */
3892
3893 loadtimer = timer_new(TIMER_CPU, TIMER_ACTIVE, "load cpu");
3897
3899
3900 savegame_load(file);
3902 secfile_destroy(file);
3903
3904 log_verbose("Load time: %g seconds (%g apparent)",
3908
3909 sanity_check();
3910
3911 log_verbose("load_command() does send_rulesets()");
3919
3920 /* Send information about the new players. */
3923
3924 /* Everything seemed to load ok; spread the good news. */
3926
3927 /* Attach connections to players. Currently, this applies only
3928 * to connections that have the same username as a player. */
3930 players_iterate(pplayer) {
3931 if (strcmp(pconn->username, pplayer->username) == 0) {
3932 connection_attach(pconn, pplayer, FALSE);
3933 break;
3934 }
3937
3938 /* Reattach global observers. */
3940 if (NULL == pconn->playing) {
3941 /* May have been assigned to a player before. */
3943 }
3946
3948
3950 players_iterate(pplayer) {
3952
3954 pack.gained = achievement_player_has(pach, pplayer);
3955 pack.first = (pach->first == pplayer);
3956
3957 lsend_packet_achievement_info(pplayer->connections, &pack);
3960
3961 return TRUE;
3962}
3963
3964/**********************************************************************/
3973bool set_rulesetdir(struct connection *caller, const char *str, bool check,
3974 int read_recursion)
3975{
3976 char filename[512];
3977 const char *pfilename;
3978
3979 if (NULL == str || '\0' == str[0]) {
3981 _("You must provide a ruleset name. Use \"/show ruleset\" to "
3982 "see what is the current ruleset."));
3983 return FALSE;
3984 }
3985
3986 if (srvarg.ruleset != NULL && is_restricted(caller)) {
3988 _("Changing ruleset not allowed. It was locked from the commandline."));
3989
3990 return FALSE;
3991 }
3992
3993 if (game_was_started() || !map_is_empty()) {
3995 _("This setting can't be modified after the game has started."));
3997 && !game_was_started()) {
3999 /* TRANS: scenario name */
4000 _("The ruleset of \"%s\" can be changed by switching to a"
4001 " compatible ruleset before loading it."),
4003 }
4004 return FALSE;
4005 }
4006
4007 if (strcmp(str, game.server.rulesetdir) == 0) {
4009 _("Ruleset directory is already \"%s\""), str);
4010 return FALSE;
4011 }
4012
4013 if (is_restricted(caller)
4014 && (!is_safe_filename(str) || strchr(str, '.'))) {
4016 _("Name \"%s\" disallowed for security reasons."),
4017 str);
4018 return FALSE;
4019 }
4020
4021 fc_snprintf(filename, sizeof(filename), "%s", str);
4022 pfilename = fileinfoname(get_data_dirs(), filename);
4023 if (!pfilename) {
4025 _("Ruleset directory \"%s\" not found"), str);
4026 return FALSE;
4027 }
4028
4029 if (!check) {
4030 bool success = TRUE;
4031 char old[512];
4032
4034 log_verbose("set_rulesetdir() does load_rulesets() with \"%s\"", str);
4036
4037 /* load the ruleset (and game settings defined in the ruleset) */
4039 if (!load_rulesets(old, NULL, FALSE, NULL, TRUE, FALSE, TRUE)) {
4040 success = FALSE;
4041
4042 /* While loading of the requested ruleset failed, we might
4043 * have changed ruleset from third one to default. Handle
4044 * rest of the ruleset changing accordingly. */
4045 }
4046
4047 if (game.est_connections) {
4048 /* Now that the rulesets are loaded we immediately send updates to any
4049 * connected clients. */
4051 }
4052 /* show ruleset summary and list changed values */
4055
4056 if (success) {
4057 cmd_reply(CMD_RULESETDIR, caller, C_OK,
4058 _("Ruleset directory set to \"%s\""), str);
4059 } else {
4061 _("Failed loading rulesets from directory \"%s\", using \"%s\""),
4063 }
4064
4065 return success;
4066 }
4067
4068 return TRUE;
4069}
4070
4071/**********************************************************************/
4074static bool ignore_command(struct connection *caller, char *str, bool check)
4075{
4076 char buf[128];
4077 struct conn_pattern *ppattern;
4078
4079 if (NULL == caller) {
4080 cmd_reply(CMD_IGNORE, caller, C_FAIL,
4081 _("That would be rather silly, since you are not a player."));
4082 return FALSE;
4083 }
4084
4086 if (NULL == ppattern) {
4087 cmd_reply(CMD_IGNORE, caller, C_SYNTAX,
4088 _("%s. Try /help ignore"), buf);
4089 return FALSE;
4090 }
4091
4092 if (check) {
4094 return TRUE;
4095 }
4096
4100 _("Added pattern %s as entry %d to your ignore list."),
4102
4103 return TRUE;
4104}
4105
4106/**********************************************************************/
4109static bool unignore_command(struct connection *caller,
4110 char *str, bool check)
4111{
4112 char buf[128], *c;
4113 int first, last, n;
4114
4115 if (!caller) {
4116 cmd_reply(CMD_IGNORE, caller, C_FAIL,
4117 _("That would be rather silly, since you are not a player."));
4118 return FALSE;
4119 }
4120
4121 sz_strlcpy(buf, str);
4123
4125 if (n == 0) {
4126 cmd_reply(CMD_UNIGNORE, caller, C_FAIL, _("Your ignore list is empty."));
4127 return FALSE;
4128 }
4129
4130 /* Parse the range. */
4131 if ('\0' == buf[0]) {
4133 _("Missing range. Try /help unignore."));
4134 return FALSE;
4135 } else if ((c = strchr(buf, '-'))) {
4136 *c++ = '\0';
4137 if ('\0' == buf[0]) {
4138 first = 1;
4139 } else if (!str_to_int(buf, &first)) {
4140 *--c = '-';
4142 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4143 return FALSE;
4144 }
4145 if ('\0' == *c) {
4146 last = n;
4147 } else if (!str_to_int(c, &last)) {
4148 *--c = '-';
4150 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4151 return FALSE;
4152 }
4153 } else {
4154 if (!str_to_int(buf, &first)) {
4156 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4157 return FALSE;
4158 }
4159 last = first;
4160 }
4161
4162 if (!(1 <= first && first <= last && last <= n)) {
4163 if (first == last) {
4164 cmd_reply(CMD_UNIGNORE, caller, C_FAIL,
4165 _("Invalid entry number: %d."), first);
4166 } else {
4167 cmd_reply(CMD_UNIGNORE, caller, C_FAIL,
4168 _("Invalid range: %d to %d."), first, last);
4169 }
4170 return FALSE;
4171 }
4172
4173 if (check) {
4174 return TRUE;
4175 }
4176
4177 n = 1;
4179 if (first <= n) {
4182 _("Removed pattern %s (entry %d) from your ignore list."),
4183 buf, n);
4185 }
4186 n++;
4187 if (n > last) {
4188 break;
4189 }
4191
4192 return TRUE;
4193}
4194
4195/**********************************************************************/
4198static bool playercolor_command(struct connection *caller,
4199 char *str, bool check)
4200{
4202 struct player *pplayer;
4203 struct rgbcolor *prgbcolor = NULL;
4204 int ntokens = 0;
4205 char *token[2];
4206 bool ret = TRUE;
4207
4208 ntokens = get_tokens(str, token, 2, TOKEN_DELIMITERS);
4209
4210 if (ntokens != 2) {
4212 _("Two arguments needed. See '/help playercolor'."));
4213 ret = FALSE;
4214 goto cleanup;
4215 }
4216
4217 pplayer = player_by_name_prefix(token[0], &match_result);
4218
4219 if (!pplayer) {
4221 ret = FALSE;
4222 goto cleanup;
4223 }
4224
4225 {
4226 const char *reason;
4227 if (!player_color_changeable(pplayer, &reason)) {
4228 cmd_reply(CMD_PLAYERCOLOR, caller, C_FAIL, "%s", reason);
4229 ret = FALSE;
4230 goto cleanup;
4231 }
4232 }
4233
4234 if (0 == fc_strcasecmp(token[1], "reset")) {
4235 if (!game_was_started()) {
4236 prgbcolor = NULL;
4237 } else {
4239 _("Can only unset player color before game starts."));
4240 ret = FALSE;
4241 goto cleanup;
4242 }
4243 } else if (!rgbcolor_from_hex(&prgbcolor, token[1])) {
4245 _("Invalid player color definition. See '/help playercolor'."));
4246 ret = FALSE;
4247 goto cleanup;
4248 }
4249
4250 if (prgbcolor != NULL) {
4252 if (pother != pplayer && pother->rgb != NULL
4255 /* TRANS: "... [c0ffee] for Caesar ... to Hammurabi." */
4256 _("Warning: new color [%s] for %s is identical to %s."),
4259 }
4261 }
4262
4263 if (check) {
4264 goto cleanup;
4265 }
4266
4269 _("Color of player %s set to [%s]."), player_name(pplayer),
4270 player_color_ftstr(pplayer));
4271
4272 cleanup:
4273
4275 free_tokens(token, ntokens);
4276
4277 return ret;
4278}
4279
4280/**********************************************************************/
4283static bool playernation_command(struct connection *caller,
4284 char *str, bool check)
4285{
4287 struct player *pplayer;
4288 struct nation_type *pnation;
4289 struct nation_style *pstyle;
4290 bool is_male = FALSE;
4291 int ntokens = 0;
4292 char *token[5];
4293
4294 ntokens = get_tokens(str, token, 5, TOKEN_DELIMITERS);
4295
4296 if (ntokens == 0) {
4298 _("At least one argument needed. See '/help playernation'."));
4299 free_tokens(token, ntokens);
4300 return FALSE;
4301 }
4302
4303 if (game_was_started()) {
4305 _("Can only set player nation before game starts."));
4306 free_tokens(token, ntokens);
4307 return FALSE;
4308 }
4309
4310 pplayer = player_by_name_prefix(token[0], &match_result);
4311 if (!pplayer) {
4313 free_tokens(token, ntokens);
4314 return FALSE;
4315 }
4316
4317 if (ntokens == 1) {
4318 if (!check) {
4320
4322 _("Nation of player %s reset."), player_name(pplayer));
4324 }
4325 } else {
4326 pnation = nation_by_rule_name(token[1]);
4327 if (pnation == NO_NATION_SELECTED) {
4329 _("Unrecognized nation: %s."), token[1]);
4330 free_tokens(token, ntokens);
4331 return FALSE;
4332 }
4333
4334 if (!client_can_pick_nation(pnation)) {
4336 _("%s nation is not available for user selection."),
4337 token[1]);
4338 free_tokens(token, ntokens);
4339 return FALSE;
4340 }
4341
4342 if (pnation->player && pnation->player != pplayer) {
4344 _("%s nation is already in use."), token[1]);
4345 free_tokens(token, ntokens);
4346 return FALSE;
4347 }
4348
4349 if (ntokens < 3) {
4351 /* TRANS: Nation resetting form of /playernation does not require sex */
4352 _("Leader sex must be given when setting nation."));
4353 free_tokens(token, ntokens);
4354 return FALSE;
4355 }
4356
4357 if (!strcmp(token[2], "0")) {
4358 is_male = FALSE;
4359 } else if (!strcmp(token[2], "1")) {
4360 is_male = TRUE;
4361 } else {
4363 _("Unrecognized gender: %s, expecting 1 or 0."), token[2]);
4364 free_tokens(token, ntokens);
4365 return FALSE;
4366 }
4367
4368 if (ntokens > 4) {
4369 pstyle = style_by_rule_name(token[4]);
4370 if (!pstyle) {
4372 _("Unrecognized style: %s."), token[4]);
4373 free_tokens(token, ntokens);
4374 return FALSE;
4375 }
4376 } else {
4377 pstyle = style_of_nation(pnation);
4378 }
4379
4380 if (!check) {
4381 char error_buf[256];
4382
4383 player_set_nation(pplayer, pnation);
4384 pplayer->style = pstyle;
4385 pplayer->is_male = is_male;
4386
4387 if (ntokens > 3) {
4388 if (!server_player_set_name_full(caller, pplayer, pnation, token[3],
4389 error_buf, sizeof(error_buf))) {
4391 }
4392 } else {
4393 server_player_set_name(pplayer, token[0]);
4394 }
4396 _("Nation of player %s set to [%s]."), player_name(pplayer),
4397 nation_rule_name(pnation));
4399 }
4400 }
4401
4402 free_tokens(token, ntokens);
4403
4404 return TRUE;
4405}
4406
4407/**************************************************************************
4408 Handle quit command
4409**************************************************************************/
4410static bool quit_game(struct connection *caller, bool check)
4411{
4412 if (!check) {
4413 cmd_reply(CMD_QUIT, caller, C_OK, _("Goodbye."));
4414 server_quit();
4415 }
4416
4417 return TRUE;
4418}
4419
4420/**********************************************************************/
4424bool handle_stdin_input(struct connection *caller, char *str)
4425{
4426 return handle_stdin_input_real(caller, str, FALSE, 0);
4427}
4428
4429/**********************************************************************/
4432bool handle_stdin_input_free(struct connection *caller, char *str)
4433{
4434 bool ret = handle_stdin_input_real(caller, str, FALSE, 0);
4435
4436 /* Since handle_stdin_input_real() returned,
4437 * we can be sure this was not freed in atexit(). */
4438 free(str);
4439
4440 return ret;
4441}
4442
4443/**********************************************************************/
4451static bool handle_stdin_input_real(struct connection *caller, char *str,
4452 bool check, int read_recursion)
4453{
4456 char *cptr_s, *cptr_d;
4457 enum command_id cmd;
4458 enum cmdlevel level;
4459
4460 /* Remove leading and trailing spaces, and server command prefix. */
4462 if ('\0' == *cptr_s || '#' == *cptr_s) {
4463 /* This appear to be a comment or blank line. */
4464 return FALSE;
4465 }
4466
4467 if (SERVER_COMMAND_PREFIX == *cptr_s) {
4468 /* Commands may be prefixed with SERVER_COMMAND_PREFIX, even when
4469 * given on the server command line. */
4470 cptr_s++;
4472 if ('\0' == *cptr_s) {
4473 /* This appear to be a blank line. */
4474 return FALSE;
4475 }
4476 }
4478
4479 /* notify to the server console */
4480 if (!check && caller) {
4481 con_write(C_COMMENT, "%s: '%s'", caller->username, str);
4482 }
4483
4484 /* if the caller may not use any commands at all, don't waste any time */
4485 if (may_use_nothing(caller)) {
4486 cmd_reply(CMD_HELP, caller, C_FAIL,
4487 _("Sorry, you are not allowed to use server commands."));
4488 return FALSE;
4489 }
4490
4491 /* copy the full command, in case we need it for voting purposes. */
4493
4494 /*
4495 * cptr_s points now to the beginning of the real command. It has
4496 * skipped leading whitespace, the SERVER_COMMAND_PREFIX and any
4497 * other non-alphanumeric characters.
4498 */
4499 for (cptr_d = command; *cptr_s != '\0' && fc_isalnum(*cptr_s)
4500 && cptr_d < command + sizeof(command) - 1; cptr_s++, cptr_d++) {
4501 *cptr_d = *cptr_s;
4502 }
4503 *cptr_d = '\0';
4504
4505 /* cptr_s now contains the arguments. */
4507
4508 cmd = command_named(command, FALSE);
4509 if (cmd == CMD_AMBIGUOUS) {
4510 cmd = command_named(command, TRUE);
4511 cmd_reply(cmd, caller, C_SYNTAX,
4512 _("Warning: '%s' interpreted as '%s', but it is ambiguous."
4513 " Try '%shelp'."),
4514 command, command_name_by_number(cmd), caller?"/":"");
4515 } else if (cmd == CMD_UNRECOGNIZED) {
4516 cmd_reply(cmd, caller, C_SYNTAX, _("Unknown command '%s%s'. "
4517 " Try '%shelp'."),
4518 caller ? "/" : "", command, caller ? "/" : "");
4519 return FALSE;
4520 }
4521
4523
4524 if (conn_can_vote(caller, NULL) && level == ALLOW_CTRL
4525 && conn_get_access(caller) == ALLOW_BASIC && !check
4526 && !vote_would_pass_immediately(caller, cmd)) {
4527 struct vote *vote;
4528 bool caller_had_vote = (NULL != get_vote_by_caller(caller));
4529
4530 /* Check if the vote command would succeed. If we already have a vote
4531 * going, cancel it in favour of the new vote command. You can only
4532 * have one vote at a time. This is done by vote_new(). */
4534 read_recursion + 1)
4535 && (vote = vote_new(caller, arg, cmd))) {
4537 const struct player *teamplr;
4538 const char *what;
4539 struct ft_color color;
4540
4541 if (caller_had_vote) {
4542 cmd_reply(CMD_VOTE, caller, C_COMMENT,
4543 /* TRANS: "vote" as a process */
4544 _("Your new vote canceled your previous vote."));
4545 }
4546
4548
4549 if (vote_is_team_only(vote)) {
4550 /* TRANS: "vote" as a process */
4551 what = _("New teamvote");
4552 teamplr = conn_get_player(caller);
4554 } else {
4555 /* TRANS: "vote" as a process */
4556 what = _("New vote");
4557 teamplr = NULL;
4559 }
4561 /* TRANS: "[New vote|New teamvote] (number 3)
4562 * by fred: proposed change" */
4563 _("%s (number %d) by %s: %s"), what,
4564 vote->vote_no, caller->username, votedesc);
4565
4566 /* Vote on your own suggestion. */
4567 connection_vote(caller, vote, VOTE_YES);
4568 return TRUE;
4569
4570 } else {
4571 cmd_reply(CMD_VOTE, caller, C_FAIL,
4572 /* TRANS: "vote" as a process */
4573 _("Your new vote (\"%s\") was not "
4574 "legal or was not recognized."), full_command);
4575 return FALSE;
4576 }
4577 }
4578
4579 if (caller
4580 && !((check || vote_would_pass_immediately(caller, cmd))
4581 && conn_get_access(caller) >= ALLOW_BASIC
4582 && level == ALLOW_CTRL)
4583 && conn_get_access(caller) < level) {
4584 cmd_reply(cmd, caller, C_FAIL,
4585 _("You are not allowed to use this command."));
4586 return FALSE;
4587 }
4588
4589 if (!check) {
4590 struct conn_list *echo_list = NULL;
4592
4593 switch (command_echo(command_by_number(cmd))) {
4594 case CMD_ECHO_NONE:
4595 break;
4596 case CMD_ECHO_ADMINS:
4599 if (NULL == echo_list) {
4602 }
4604 }
4606 break;
4607 case CMD_ECHO_ALL:
4609 break;
4610 }
4611
4612 if (NULL != echo_list) {
4613 if (caller) {
4615 "%s: '%s %s'", caller->username, command, arg);
4616 } else {
4618 "%s: '%s %s'", _("(server prompt)"), command, arg);
4619 }
4620 if (echo_list_allocated) {
4622 }
4623 }
4624 }
4625
4626 switch (cmd) {
4627 case CMD_REMOVE:
4628 return remove_player_command(caller, arg, check);
4629 case CMD_SAVE:
4630 return save_command(caller, arg, check);
4631 case CMD_SCENSAVE:
4632 return scensave_command(caller, arg, check);
4633 case CMD_LOAD:
4634 return load_command(caller, arg, check, FALSE);
4635 case CMD_METAPATCHES:
4636 return metapatches_command(caller, arg, check);
4637 case CMD_METAMESSAGE:
4638 return metamessage_command(caller, arg, check);
4639 case CMD_METACONN:
4640 return metaconnection_command(caller, arg, check);
4641 case CMD_METASERVER:
4642 return metaserver_command(caller, arg, check);
4643 case CMD_HELP:
4644 return show_help(caller, arg);
4645 case CMD_SRVID:
4646 return show_serverid(caller, arg);
4647 case CMD_LIST:
4648 return show_list(caller, arg);
4649 case CMD_AITOGGLE:
4650 return toggle_ai_command(caller, arg, check);
4651 case CMD_TAKE:
4652 return take_command(caller, arg, check);
4653 case CMD_OBSERVE:
4654 return observe_command(caller, arg, check);
4655 case CMD_DETACH:
4656 return detach_command(caller, arg, check);
4657 case CMD_CREATE:
4658 return create_command(caller, arg, check);
4659 case CMD_AWAY:
4660 return away_command(caller, check);
4661 case CMD_RESTRICTED:
4662 case CMD_NOVICE:
4663 case CMD_EASY:
4664 case CMD_NORMAL:
4665 case CMD_HARD:
4666 case CMD_CHEATING:
4667#ifdef FREECIV_DEBUG
4668 case CMD_EXPERIMENTAL:
4669#endif
4670 return set_ai_level_named(caller, arg, command_name_by_number(cmd), check);
4671 case CMD_QUIT:
4672 return quit_game(caller, check);
4673 case CMD_CUT:
4674 return cut_client_connection(caller, arg, check);
4675 case CMD_SHOW:
4676 return show_command(caller, arg, check);
4677 case CMD_EXPLAIN:
4678 return explain_option(caller, arg, check);
4679 case CMD_DEBUG:
4680 return debug_command(caller, arg, check);
4681 case CMD_SET:
4682 return set_command(caller, arg, check);
4683 case CMD_TEAM:
4684 return team_command(caller, arg, check);
4685 case CMD_RULESETDIR:
4686 return set_rulesetdir(caller, arg, check, read_recursion);
4687 case CMD_WALL:
4688 return wall(arg, check);
4689 case CMD_CONNECTMSG:
4690 return connectmsg_command(caller, arg, check);
4691 case CMD_VOTE:
4692 return vote_command(caller, arg, check);
4693 case CMD_CANCELVOTE:
4694 return cancelvote_command(caller, arg, check);
4695 case CMD_READ_SCRIPT:
4696 return read_command(caller, arg, check, read_recursion);
4697 case CMD_WRITE_SCRIPT:
4698 return write_command(caller, arg, check);
4699 case CMD_RESET:
4700 return reset_command(caller, arg, check, read_recursion);
4701 case CMD_DEFAULT:
4702 return default_command(caller, arg, check);
4703 case CMD_LUA:
4704 return lua_command(caller, arg, check, read_recursion);
4705 case CMD_KICK:
4706 return kick_command(caller, arg, check);
4707 case CMD_DELEGATE:
4708 return delegate_command(caller, arg, check);
4709 case CMD_AICMD:
4710 return aicmd_command(caller, arg, check);
4711 case CMD_FCDB:
4712 return fcdb_command(caller, arg, check);
4713 case CMD_MAPIMG:
4714 return mapimg_command(caller, arg, check);
4715 case CMD_LOCK:
4716 return lock_command(caller, arg, check);
4717 case CMD_UNLOCK:
4718 return unlock_command(caller, arg, check);
4719 case CMD_RFCSTYLE: /* see console.h for an explanation */
4720 if (!check) {
4722 }
4723 return TRUE;
4724 case CMD_CMDLEVEL:
4725 return cmdlevel_command(caller, arg, check);
4726 case CMD_FIRSTLEVEL:
4727 return firstlevel_command(caller, check);
4728 case CMD_TIMEOUT:
4729 return timeout_command(caller, arg, check);
4730 case CMD_START_GAME:
4731 return start_command(caller, check, FALSE);
4732 case CMD_END_GAME:
4733 return end_command(caller, arg, check);
4734 case CMD_SURRENDER:
4735 return surrender_command(caller, arg, check);
4736 case CMD_IGNORE:
4737 return ignore_command(caller, arg, check);
4738 case CMD_UNIGNORE:
4739 return unignore_command(caller, arg, check);
4740 case CMD_PLAYERCOLOR:
4741 return playercolor_command(caller, arg, check);
4742 case CMD_PLAYERNATION:
4743 return playernation_command(caller, arg, check);
4744 case CMD_NUM:
4745 case CMD_UNRECOGNIZED:
4746 case CMD_AMBIGUOUS:
4747 break;
4748 }
4749 /* should NEVER happen! */
4750 log_error("Unknown command variant: %d.", cmd);
4751 return FALSE;
4752}
4753
4754/**********************************************************************/
4757static bool end_command(struct connection *caller, char *str, bool check)
4758{
4759 if (S_S_RUNNING == server_state()) {
4760 if (check) {
4761 return TRUE;
4762 }
4764 _("Game is over."));
4767 cmd_reply(CMD_END_GAME, caller, C_OK,
4768 _("Ending the game. The server will restart once all clients "
4769 "have disconnected."));
4770 return TRUE;
4771 } else {
4772 cmd_reply(CMD_END_GAME, caller, C_FAIL,
4773 _("Cannot end the game: no game running."));
4774 return FALSE;
4775 }
4776}
4777
4778/**********************************************************************/
4782static bool surrender_command(struct connection *caller, char *str, bool check)
4783{
4784 struct player *pplayer;
4785
4786 if (caller == NULL || !conn_controls_player(caller)) {
4788 _("You are not allowed to use this command."));
4789 return FALSE;
4790 }
4791
4792 if (S_S_RUNNING != server_state()) {
4793 cmd_reply(CMD_SURRENDER, caller, C_FAIL, _("You cannot surrender now."));
4794 return FALSE;
4795 }
4796
4797 pplayer = conn_get_player(caller);
4798 if (player_status_check(pplayer, PSTATUS_SURRENDER)) {
4800 _("You have already conceded the game."));
4801 return FALSE;
4802 }
4803
4804 if (check) {
4805 return TRUE;
4806 }
4807
4809 _("%s has conceded the game and can no longer win."),
4810 player_name(pplayer));
4812 return TRUE;
4813}
4814
4815/* Define the possible arguments to the reset command */
4816#define SPECENUM_NAME reset_args
4817#define SPECENUM_VALUE0 RESET_GAME
4818#define SPECENUM_VALUE0NAME "game"
4819#define SPECENUM_VALUE1 RESET_RULESET
4820#define SPECENUM_VALUE1NAME "ruleset"
4821#define SPECENUM_VALUE2 RESET_SCRIPT
4822#define SPECENUM_VALUE2NAME "script"
4823#define SPECENUM_VALUE3 RESET_DEFAULT
4824#define SPECENUM_VALUE3NAME "default"
4825#include "specenum_gen.h"
4826
4827/**********************************************************************/
4830static const char *reset_accessor(int i)
4831{
4832 i = CLIP(0, i, reset_args_max());
4833 return reset_args_name((enum reset_args) i);
4834}
4835
4836/**********************************************************************/
4840static bool reset_command(struct connection *caller, char *arg, bool check,
4841 int read_recursion)
4842{
4843 enum m_pre_result result;
4844 int ind;
4845
4846 /* match the argument */
4847 result = match_prefix(reset_accessor, reset_args_max() + 1, 0,
4848 fc_strncasecmp, NULL, arg, &ind);
4849
4850 switch (result) {
4851 case M_PRE_EXACT:
4852 case M_PRE_ONLY:
4853 /* we have a match */
4854 break;
4855 case M_PRE_AMBIGUOUS:
4856 case M_PRE_EMPTY:
4857 /* use 'ruleset' [1] if the game was not started; else use 'game' [2] */
4859 cmd_reply(CMD_RESET, caller, C_WARNING,
4860 _("Guessing argument 'ruleset'."));
4862 } else {
4863 cmd_reply(CMD_RESET, caller, C_WARNING,
4864 _("Guessing argument 'game'."));
4865 ind = RESET_GAME;
4866 }
4867 break;
4868 case M_PRE_LONG:
4869 case M_PRE_FAIL:
4870 case M_PRE_LAST:
4871 cmd_reply(CMD_RESET, caller, C_FAIL,
4872 _("The valid arguments are: 'game', 'ruleset', 'script' "
4873 "or 'default'."));
4874 return FALSE;
4875 break;
4876 }
4877
4878 if (check) {
4879 return TRUE;
4880 }
4881
4882 switch (ind) {
4883 case RESET_GAME:
4884 if (!game.info.is_new_game) {
4885 if (settings_game_reset()) {
4886 cmd_reply(CMD_RESET, caller, C_OK,
4887 _("Reset all settings to the values at the game start."));
4888 } else {
4889 cmd_reply(CMD_RESET, caller, C_FAIL,
4890 _("No saved settings from the game start available."));
4891 return FALSE;
4892 }
4893 } else {
4894 cmd_reply(CMD_RESET, caller, C_FAIL, _("No game started..."));
4895 return FALSE;
4896 }
4897 break;
4898
4899 case RESET_RULESET:
4900 /* Restore game settings saved in game.ruleset. */
4902 cmd_reply(CMD_RESET, caller, C_OK,
4903 _("Reset all settings to ruleset values."));
4904 } else {
4905 cmd_reply(CMD_RESET, caller, C_FAIL,
4906 _("Failed to reset settings to ruleset values."));
4907 }
4908 break;
4909
4910 case RESET_SCRIPT:
4911 cmd_reply(CMD_RESET, caller, C_OK,
4912 _("Reset all settings and rereading the server start "
4913 "script."));
4915 /* Load initial script */
4918 read_recursion + 1)) {
4919 if (NULL != caller) {
4920 cmd_reply(CMD_RESET, caller, C_FAIL,
4921 _("Could not read script file '%s'."),
4923 }
4924 return FALSE;
4925 }
4926 break;
4927
4928 case RESET_DEFAULT:
4929 cmd_reply(CMD_RESET, caller, C_OK,
4930 _("Reset all settings to default values."));
4932 break;
4933 }
4934
4936 cmd_reply(CMD_RESET, caller, C_OK, _("Settings re-initialized."));
4937
4938 /* show ruleset summary and list changed values */
4940
4941 return TRUE;
4942}
4943
4944/**********************************************************************/
4947static bool default_command(struct connection *caller, char *arg, bool check)
4948{
4949 struct setting *pset;
4950 char reject_msg[256] = "";
4951
4952 pset = validate_setting_arg(CMD_DEFAULT, caller, arg);
4953
4954 if (!pset) {
4955 /* Reason already reported. */
4956 return FALSE;
4957 }
4958
4959 if (!setting_is_changeable(pset, caller, reject_msg, sizeof(reject_msg))) {
4960 cmd_reply(CMD_DEFAULT, caller, C_FAIL, "%s", reject_msg);
4961
4962 return FALSE;
4963 }
4964
4965 if (!check) {
4967 cmd_reply(CMD_DEFAULT, caller, C_OK,
4968 _("Option '%s' reset to default value, and will track any "
4969 "default changes."), arg);
4970 }
4971
4972 return TRUE;
4973}
4974
4975/* Define the possible arguments to the delegation command */
4976#define SPECENUM_NAME lua_args
4977#define SPECENUM_VALUE0 LUA_CMD
4978#define SPECENUM_VALUE0NAME "cmd"
4979#define SPECENUM_VALUE1 LUA_FILE
4980#define SPECENUM_VALUE1NAME "file"
4981#define SPECENUM_VALUE2 LUA_UNSAFE_CMD
4982#define SPECENUM_VALUE2NAME "unsafe-cmd"
4983#define SPECENUM_VALUE3 LUA_UNSAFE_FILE
4984#define SPECENUM_VALUE3NAME "unsafe-file"
4985#include "specenum_gen.h"
4986
4987/**********************************************************************/
4990static const char *lua_accessor(int i)
4991{
4992 i = CLIP(0, i, lua_args_max());
4993 return lua_args_name((enum lua_args) i);
4994}
4995
4996/**********************************************************************/
4999static bool lua_command(struct connection *caller, char *arg, bool check,
5000 int read_recursion)
5001{
5002 struct stat statbuf;
5003 const char extension[] = ".lua", *real_filename = NULL;
5004 char luafile[4096], tilde_filename[4096];
5005 char *tokens[1], *luaarg = NULL;
5006 int ntokens, ind;
5007 enum m_pre_result result;
5008 bool ret = FALSE;
5009
5011
5012 if (ntokens > 0) {
5013 /* match the argument */
5014 result = match_prefix(lua_accessor, lua_args_max() + 1, 0,
5015 fc_strncasecmp, NULL, tokens[0], &ind);
5016
5017 switch (result) {
5018 case M_PRE_EXACT:
5019 case M_PRE_ONLY:
5020 /* We have a match */
5021 luaarg = arg + strlen(lua_args_name(ind));
5023 break;
5024 case M_PRE_EMPTY:
5025 /* Nothing. */
5026 break;
5027 case M_PRE_AMBIGUOUS:
5028 case M_PRE_LONG:
5029 case M_PRE_FAIL:
5030 case M_PRE_LAST:
5031 /* Fall back to depreciated 'lua <script command>' syntax. */
5032 cmd_reply(CMD_LUA, caller, C_SYNTAX,
5033 _("Fall back to old syntax '%slua <script command>'."),
5034 caller ? "/" : "");
5035 ind = LUA_CMD;
5036 luaarg = arg;
5037 break;
5038 }
5039 }
5040
5041 if (luaarg == NULL) {
5042 cmd_reply(CMD_LUA, caller, C_FAIL,
5043 _("No lua command or lua script file. See '%shelp lua'."),
5044 caller ? "/" : "");
5045 ret = TRUE;
5046 goto cleanup;
5047 }
5048
5049 switch (ind) {
5050 case LUA_CMD:
5051 /* Nothing to check. */
5052 break;
5053 case LUA_UNSAFE_CMD:
5054 if (read_recursion > 0) {
5055 cmd_reply(CMD_LUA, caller, C_FAIL,
5056 _("Unsafe Lua code can only be run by explicit command."));
5057 ret = FALSE;
5058 goto cleanup;
5059 } else if (is_restricted(caller)) {
5060 cmd_reply(CMD_LUA, caller, C_FAIL,
5061 _("You aren't allowed to run unsafe Lua code."));
5062 ret = FALSE;
5063 goto cleanup;
5064 }
5065 break;
5066 case LUA_UNSAFE_FILE:
5067 if (read_recursion > 0) {
5068 cmd_reply(CMD_LUA, caller, C_FAIL,
5069 _("Unsafe Lua code can only be run by explicit command."));
5070 ret = FALSE;
5071 goto cleanup;
5072 } else if (is_restricted(caller)) {
5073 cmd_reply(CMD_LUA, caller, C_FAIL,
5074 _("You aren't allowed to run unsafe Lua code."));
5075 ret = FALSE;
5076 goto cleanup;
5077 }
5078
5080 case LUA_FILE:
5081 /* Abuse real_filename to find if we already have a .lua extension. */
5083 strlen(luaarg));
5084 if (strcmp(real_filename, extension) != 0) {
5085 fc_snprintf(luafile, sizeof(luafile), "%s%s", luaarg, extension);
5086 } else {
5088 }
5089
5090 if (is_restricted(caller)) {
5091 if (!is_safe_filename(luafile)) {
5092 cmd_reply(CMD_LUA, caller, C_FAIL,
5093 _("Freeciv script '%s' disallowed for security reasons."),
5094 luafile);
5095 ret = FALSE;
5096 goto cleanup;
5097 }
5099 } else {
5101 }
5102
5104 if (!real_filename) {
5105 if (is_restricted(caller)) {
5106 cmd_reply(CMD_LUA, caller, C_FAIL,
5107 _("No Freeciv script found by the name '%s'."),
5109 ret = FALSE;
5110 goto cleanup;
5111 }
5112 /* File is outside data directories */
5114 }
5115 break;
5116 }
5117
5118 if (check) {
5119 ret = TRUE;
5120 goto cleanup;
5121 }
5122
5123 switch (ind) {
5124 case LUA_CMD:
5126 break;
5127 case LUA_UNSAFE_CMD:
5129 break;
5130 case LUA_FILE:
5131 cmd_reply(CMD_LUA, caller, C_COMMENT,
5132 _("Loading Freeciv script file '%s'."), real_filename);
5133
5135 && !fc_stat(real_filename, &statbuf)) {
5137 } else {
5138 cmd_reply(CMD_LUA, caller, C_FAIL,
5139 _("Cannot read Freeciv script '%s'."), real_filename);
5140 ret = FALSE;
5141 }
5142 break;
5143 case LUA_UNSAFE_FILE:
5144 cmd_reply(CMD_LUA, caller, C_COMMENT,
5145 _("Loading Freeciv script file '%s'."), real_filename);
5146
5148 && !fc_stat(real_filename, &statbuf)) {
5150 } else {
5151 cmd_reply(CMD_LUA, caller, C_FAIL,
5152 _("Cannot read Freeciv script '%s'."), real_filename);
5153 ret = FALSE;
5154 }
5155 break;
5156 }
5157
5158 cleanup:
5160 return ret;
5161}
5162
5163/* Define the possible arguments to the delegation command */
5164#define SPECENUM_NAME delegate_args
5165#define SPECENUM_VALUE0 DELEGATE_CANCEL
5166#define SPECENUM_VALUE0NAME "cancel"
5167#define SPECENUM_VALUE1 DELEGATE_RESTORE
5168#define SPECENUM_VALUE1NAME "restore"
5169#define SPECENUM_VALUE2 DELEGATE_SHOW
5170#define SPECENUM_VALUE2NAME "show"
5171#define SPECENUM_VALUE3 DELEGATE_TAKE
5172#define SPECENUM_VALUE3NAME "take"
5173#define SPECENUM_VALUE4 DELEGATE_TO
5174#define SPECENUM_VALUE4NAME "to"
5175#include "specenum_gen.h"
5176
5177/**********************************************************************/
5180static const char *delegate_accessor(int i)
5181{
5182 i = CLIP(0, i, delegate_args_max());
5183 return delegate_args_name((enum delegate_args) i);
5184}
5185
5186/**********************************************************************/
5189static bool delegate_command(struct connection *caller, char *arg,
5190 bool check)
5191{
5192 char *tokens[3];
5194 enum m_pre_result result;
5195 bool player_specified = FALSE; /* affects messages only */
5196 bool ret = FALSE;
5197 const char *username = NULL;
5198 struct player *dplayer = NULL;
5199
5200 if (!game_was_started()) {
5201 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Game not started - "
5202 "cannot delegate yet."));
5203 return FALSE;
5204 }
5205
5207
5208 if (ntokens > 0) {
5209 /* match the argument */
5211 fc_strncasecmp, NULL, tokens[0], &ind);
5212
5213 switch (result) {
5214 case M_PRE_EXACT:
5215 case M_PRE_ONLY:
5216 /* we have a match */
5217 break;
5218 case M_PRE_EMPTY:
5219 if (caller) {
5220 /* Use 'delegate show' as default. */
5222 }
5223 break;
5224 case M_PRE_AMBIGUOUS:
5225 case M_PRE_LONG:
5226 case M_PRE_FAIL:
5227 case M_PRE_LAST:
5229 break;
5230 }
5231 } else {
5232 if (caller) {
5233 /* Use 'delegate show' as default. */
5235 }
5236 }
5237
5239 char buf[256] = "";
5241
5245 const char *name = delegate_args_name(valid_args);
5246
5247 if (name != NULL) {
5248 cat_snprintf(buf, sizeof(buf), "'%s'", name);
5249 if (valid_args != delegate_args_max()) {
5250 cat_snprintf(buf, sizeof(buf), ", ");
5251 }
5252 }
5253 }
5254
5256 /* TRANS: do not translate the command 'delegate'. */
5257 _("Valid arguments for 'delegate' are: %s."), buf);
5258 ret = FALSE;
5259 goto cleanup;
5260 }
5261
5262 /* Get the data (player, username for delegation) and validate it. */
5263 switch (ind) {
5264 case DELEGATE_CANCEL:
5265 /* delegate cancel [player] */
5266 if (ntokens > 1) {
5267 if (!caller || conn_get_access(caller) >= ALLOW_ADMIN) {
5269 dplayer = player_by_name_prefix(tokens[1], &result);
5270 if (!dplayer) {
5271 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5272 ret = FALSE;
5273 goto cleanup;
5274 }
5275 } else {
5277 _("Command level '%s' or greater needed to modify "
5278 "others' delegations."), cmdlevel_name(ALLOW_ADMIN));
5279 ret = FALSE;
5280 goto cleanup;
5281 }
5282 } else {
5283 dplayer = conn_get_player(caller);
5284 if (!dplayer) {
5286 _("Please specify a player for whom delegation should "
5287 "be canceled."));
5288 ret = FALSE;
5289 goto cleanup;
5290 }
5291 }
5292 break;
5293 case DELEGATE_RESTORE:
5294 /* delegate restore */
5295 if (!caller) {
5296 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5297 _("You can't switch players from the console."));
5298 ret = FALSE;
5299 goto cleanup;
5300 }
5301 break;
5302 case DELEGATE_SHOW:
5303 /* delegate show [player] */
5304 if (ntokens > 1) {
5306 dplayer = player_by_name_prefix(tokens[1], &result);
5307 if (!dplayer) {
5308 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5309 ret = FALSE;
5310 goto cleanup;
5311 }
5312 } else {
5313 dplayer = conn_get_player(caller);
5314 if (!dplayer) {
5316 _("Please specify a player for whom the delegation should "
5317 "be shown."));
5318 ret = FALSE;
5319 goto cleanup;
5320 }
5321 }
5322 break;
5323 case DELEGATE_TAKE:
5324 /* delegate take <player> */
5325 if (!caller) {
5326 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5327 _("You can't switch players from the console."));
5328 ret = FALSE;
5329 goto cleanup;
5330 }
5331 if (ntokens > 1) {
5333 dplayer = player_by_name_prefix(tokens[1], &result);
5334 if (!dplayer) {
5335 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5336 ret = FALSE;
5337 goto cleanup;
5338 }
5339 } else {
5341 _("Please specify a player to take control of."));
5342 ret = FALSE;
5343 goto cleanup;
5344 }
5345 break;
5346 case DELEGATE_TO:
5347 break;
5348 }
5349 /* All checks done to this point will give pretty much the same result at
5350 * any time. Checks after this point are more likely to vary over time. */
5351 if (check) {
5352 ret = TRUE;
5353 goto cleanup;
5354 }
5355
5356 switch (ind) {
5357 case DELEGATE_TO:
5358 /* delegate to <username> [player] */
5359 if (ntokens > 1) {
5360 username = tokens[1];
5361 } else {
5363 _("Please specify a user to whom control is to be delegated."));
5364 ret = FALSE;
5365 break;
5366 }
5367 if (ntokens > 2) {
5369 dplayer = player_by_name_prefix(tokens[2], &result);
5370 if (!dplayer) {
5371 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[2], result);
5372 ret = FALSE;
5373 break;
5374 }
5375#ifndef HAVE_FCDB
5376 if (caller && conn_get_access(caller) < ALLOW_ADMIN) {
5377#else
5378 if (caller && conn_get_access(caller) < ALLOW_ADMIN
5379 && !(srvarg.fcdb_enabled
5380 && script_fcdb_call("user_delegate_to", caller, dplayer,
5381 username, &ret) && ret)) {
5382#endif
5384 _("Command level '%s' or greater or special permission "
5385 "needed to modify others' delegations."),
5387 ret = FALSE;
5388 break;
5389 }
5390 } else {
5391 dplayer = conn_controls_player(caller) ? conn_get_player(caller) : NULL;
5392 if (!dplayer) {
5393 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5394 _("You do not control a player."));
5395 ret = FALSE;
5396 break;
5397 }
5398 }
5399
5400 /* Delegate control of player to another user. */
5403
5404 /* Forbid delegation of players already controlled by a delegate, and
5405 * those 'put aside' by a delegate.
5406 * For the former, if player is already under active delegate control,
5407 * we wouldn't handle the revocation that would be necessary if their
5408 * delegation changed; and the authority granted to delegates does not
5409 * include the ability to sub-delegate.
5410 * For the latter, allowing control of the 'put aside' player to be
5411 * delegated would break the invariant that whenever a user is connected,
5412 * they are attached to 'their' player. */
5415 /* Attempting to change a 'put aside' player. Must be admin
5416 * or console. */
5418 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5419 _("Can't delegate control of '%s' belonging to %s while "
5420 "they are controlling another player."),
5422 } else if (player_specified) {
5423 /* Admin or console attempting to change a controlled player. */
5424 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5425 _("Can't change delegation of '%s' while controlled by "
5426 "delegate %s."), player_name(dplayer), dplayer->username);
5427 } else {
5428 /* Caller must be the delegate. Give more specific message.
5429 * (We don't know if they thought they were delegating their
5430 * original or delegated player, but we don't allow either.) */
5431 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5432 _("You can't delegate control while you are controlling "
5433 "a delegated player yourself."));
5434 }
5435 ret = FALSE;
5436 break;
5437 }
5438
5439 /* Forbid delegation to player's original owner
5440 * (from above test we know that dplayer->username is the original now) */
5441 if (fc_strcasecmp(dplayer->username, username) == 0) {
5442 if (player_specified) {
5443 /* Probably admin or console. */
5444 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5445 /* TRANS: don't translate 'delegate cancel' */
5446 _("%s already owns '%s', so cannot also be delegate. "
5447 "Use '%sdelegate cancel' to cancel an existing "
5448 "delegation."),
5449 username, player_name(dplayer), caller?"/":"");
5450 } else {
5451 /* Player not specified on command line, so they must have been trying
5452 * to delegate control to themself. Give more specific message. */
5453 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5454 /* TRANS: don't translate '/delegate cancel' */
5455 _("You can't delegate control to yourself. "
5456 "Use '/delegate cancel' to cancel an existing "
5457 "delegation."));
5458 }
5459 ret = FALSE;
5460 break;
5461 }
5462
5463 /* FIXME: if control was already delegated to someone else, that
5464 * delegation is implicitly canceled. Perhaps we should tell someone. */
5465
5467 cmd_reply(CMD_DELEGATE, caller, C_OK,
5468 _("Control of player '%s' delegated to user %s."),
5470 ret = TRUE;
5471 break;
5472
5473 case DELEGATE_SHOW:
5474 /* Show delegations. */
5476
5478 /* No delegation set. */
5480 _("No delegation defined for '%s'."),
5482 } else {
5484 _("Control of player '%s' delegated to user %s."),
5486 }
5487 ret = TRUE;
5488 break;
5489
5490 case DELEGATE_CANCEL:
5492 /* No delegation set. */
5493 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5494 _("No delegation defined for '%s'."),
5496 ret = FALSE;
5497 break;
5498 }
5499
5501 /* Delegation is currently in use. Forcibly break connection. */
5502 struct connection *pdelegate;
5503 /* (Can only happen if admin/console issues this command, as owner
5504 * will end use by their mere presence.) */
5509 /* Should never happen. Generic failure message. */
5510 log_error("Failed to restore %s's connection as %s during "
5511 "'delegate cancel'.", pdelegate->username,
5512 delegate_player_str(pdelegate->server.delegation.playing,
5513 pdelegate->server.delegation.observer));
5514 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5515 ret = FALSE;
5516 break;
5517 }
5519 _("Your delegated control of player '%s' was canceled."),
5521 }
5522
5524 cmd_reply(CMD_DELEGATE, caller, C_OK, _("Delegation of '%s' canceled."),
5526 ret = TRUE;
5527 break;
5528
5529 case DELEGATE_TAKE:
5530 /* Try to take another player. */
5532 fc_assert_ret_val(caller, FALSE);
5533
5534 if (caller->server.delegation.status) {
5535 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5536 /* TRANS: don't translate '/delegate restore'. */
5537 _("You are already controlling a delegated player. "
5538 "Use '/delegate restore' to relinquish control of your "
5539 "current player first."));
5540 ret = FALSE;
5541 break;
5542 }
5543
5544 /* Don't allow 'put aside' players to be delegated; the invariant is
5545 * that while the owning user is connected to the server, they are
5546 * in sole control of 'their' player. */
5547 if (conn_controls_player(caller)
5549 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5550 /* TRANS: don't translate '/delegate cancel'. */
5551 _("Can't take player while you have delegated control "
5552 "yourself. Use '/delegate cancel' to cancel your own "
5553 "delegation first."));
5554 ret = FALSE;
5555 break;
5556 }
5557
5558 /* Taking your own player makes no sense. */
5559 if (conn_controls_player(caller)
5560 && dplayer == conn_get_player(caller)) {
5561 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("You already control '%s'."),
5562 player_name(conn_get_player(caller)));
5563 ret = FALSE;
5564 break;
5565 }
5566
5569 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5570 _("Control of player '%s' has not been delegated to you."),
5572 ret = FALSE;
5573 break;
5574 }
5575
5576 /* If the player is controlled by another user, fail. */
5577 if (dplayer->is_connected) {
5578 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5579 _("Another user already controls player '%s'."),
5581 ret = FALSE;
5582 break;
5583 }
5584
5585 if (!connection_delegate_take(caller, dplayer)) {
5586 /* Should never happen. Generic failure message. */
5587 log_error("%s failed to take control of '%s' during 'delegate take'.",
5588 caller->username, player_name(dplayer));
5589 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5590 ret = FALSE;
5591 break;
5592 }
5593
5594 cmd_reply(CMD_DELEGATE, caller, C_OK,
5595 _("%s is now controlling player '%s'."), caller->username,
5596 player_name(conn_get_player(caller)));
5597 ret = TRUE;
5598 break;
5599
5600 case DELEGATE_RESTORE:
5601 /* Delegate user relinquishes control of delegated player, returning to
5602 * previous view (e.g. observer) if any. */
5603 fc_assert_ret_val(caller, FALSE);
5604
5605 if (!caller->server.delegation.status) {
5606 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5607 _("You are not currently controlling a delegated player."));
5608 ret = FALSE;
5609 break;
5610 }
5611
5612 if (!connection_delegate_restore(caller)) {
5613 /* Should never happen. Generic failure message. */
5614 log_error("Failed to restore %s's connection as %s during "
5615 "'delegate restore'.", caller->username,
5617 caller->server.delegation.observer));
5618 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5619 ret = FALSE;
5620 break;
5621 }
5622
5623 cmd_reply(CMD_DELEGATE, caller, C_OK,
5624 /* TRANS: "<user> is now connected to <player>" where <player>
5625 * can also be "global observer" or "nothing" */
5626 _("%s is now connected as %s."), caller->username,
5627 delegate_player_str(conn_get_player(caller), caller->observer));
5628 ret = TRUE;
5629 break;
5630 }
5631
5632 cleanup:
5634 return ret;
5635}
5636
5637/**********************************************************************/
5640static const char *delegate_player_str(struct player *pplayer, bool observer)
5641{
5642 static struct astring buf;
5643
5644 if (pplayer) {
5645 if (observer) {
5646 astr_set(&buf, _("%s (observer)"), player_name(pplayer));
5647 } else {
5648 astr_set(&buf, "%s", player_name(pplayer));
5649 }
5650 } else if (observer) {
5651 astr_set(&buf, "%s", _("global observer"));
5652 } else {
5653 /* TRANS: in place of player name or "global observer" */
5654 astr_set(&buf, "%s", _("nothing"));
5655 }
5656
5657 return astr_str(&buf);
5658}
5659
5660/* Define the possible arguments to the mapimg command */
5661/* map image layers */
5662#define SPECENUM_NAME mapimg_args
5663#define SPECENUM_VALUE0 MAPIMG_COLORTEST
5664#define SPECENUM_VALUE0NAME "colortest"
5665#define SPECENUM_VALUE1 MAPIMG_CREATE
5666#define SPECENUM_VALUE1NAME "create"
5667#define SPECENUM_VALUE2 MAPIMG_DEFINE
5668#define SPECENUM_VALUE2NAME "define"
5669#define SPECENUM_VALUE3 MAPIMG_DELETE
5670#define SPECENUM_VALUE3NAME "delete"
5671#define SPECENUM_VALUE4 MAPIMG_SHOW
5672#define SPECENUM_VALUE4NAME "show"
5673#define SPECENUM_COUNT MAPIMG_COUNT
5674#include "specenum_gen.h"
5675
5676/**********************************************************************/
5679static const char *mapimg_accessor(int i)
5680{
5681 i = CLIP(0, i, mapimg_args_max());
5682 return mapimg_args_name((enum mapimg_args) i);
5683}
5684
5685/**********************************************************************/
5688static bool mapimg_command(struct connection *caller, char *arg, bool check)
5689{
5690 enum m_pre_result result;
5691 int ind, ntokens, id;
5692 char *token[2];
5693 bool ret = TRUE;
5694
5695 ntokens = get_tokens(arg, token, 2, TOKEN_DELIMITERS);
5696
5697 if (ntokens > 0) {
5698 /* match the argument */
5700 fc_strncasecmp, NULL, token[0], &ind);
5701
5702 switch (result) {
5703 case M_PRE_EXACT:
5704 case M_PRE_ONLY:
5705 /* we have a match */
5706 break;
5707 case M_PRE_AMBIGUOUS:
5708 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5709 _("Ambiguous 'mapimg' command."));
5710 ret = FALSE;
5711 goto cleanup;
5712 break;
5713 case M_PRE_EMPTY:
5714 /* use 'show' as default */
5715 ind = MAPIMG_SHOW;
5716 break;
5717 case M_PRE_LONG:
5718 case M_PRE_FAIL:
5719 case M_PRE_LAST:
5720 {
5721 char buf[256] = "";
5723
5727 cat_snprintf(buf, sizeof(buf), "'%s'",
5729 if (valid_args != mapimg_args_max()) {
5730 cat_snprintf(buf, sizeof(buf), ", ");
5731 }
5732 }
5733
5734 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5735 _("The valid arguments are: %s."), buf);
5736 ret = FALSE;
5737 goto cleanup;
5738 }
5739 break;
5740 }
5741 } else {
5742 /* use 'show' as default */
5743 ind = MAPIMG_SHOW;
5744 }
5745
5746 switch (ind) {
5747 case MAPIMG_DEFINE:
5748 if (ntokens == 1) {
5749 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5750 _("Missing argument for 'mapimg define'."));
5751 ret = FALSE;
5752 } else {
5753 /* 'mapimg define <mapstr>' */
5754 if (!mapimg_define(token[1], check)) {
5755 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5756 _("Can't use definition: %s."), mapimg_error());
5757 ret = FALSE;
5758 } else if (check) {
5759 /* Validated OK, bail out now */
5760 goto cleanup;
5761 } else if (game_was_started()
5762 && mapimg_isvalid(mapimg_count() - 1) == NULL) {
5763 /* game was started - error in map image definition check */
5764 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5765 _("Can't use definition: %s."), mapimg_error());
5766 ret = FALSE;
5767 } else {
5768 char str[MAX_LEN_MAPDEF];
5769
5770 id = mapimg_count() - 1;
5771
5772 mapimg_id2str(id, str, sizeof(str));
5773 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Defined as map image "
5774 "definition %d: '%s'."),
5775 id, str);
5776 }
5777 }
5778 break;
5779
5780 case MAPIMG_DELETE:
5781 if (ntokens == 1) {
5782 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5783 _("Missing argument for 'mapimg delete'."));
5784 ret = FALSE;
5785 } else if (ntokens == 2 && strcmp(token[1], "all") == 0) {
5786 /* 'mapimg delete all' */
5787 if (check) {
5788 goto cleanup;
5789 }
5790
5791 while (mapimg_count() > 0) {
5792 mapimg_delete(0);
5793 }
5794 cmd_reply(CMD_MAPIMG, caller, C_OK, _("All map image definitions "
5795 "deleted."));
5796 } else if (ntokens == 2 && sscanf(token[1], "%d", &id) != 0) {
5797 /* 'mapimg delete <id>' */
5798 if (check) {
5799 goto cleanup;
5800 }
5801
5802 if (!mapimg_delete(id)) {
5803 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5804 _("Couldn't delete definition: %s."), mapimg_error());
5805 ret = FALSE;
5806 } else {
5807 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Map image definition %d "
5808 "deleted."), id);
5809 }
5810 } else {
5811 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5812 _("Bad argument for 'mapimg delete': '%s'."), token[1]);
5813 ret = FALSE;
5814 }
5815 break;
5816
5817 case MAPIMG_SHOW:
5818 if (ntokens < 2 || (ntokens == 2 && strcmp(token[1], "all") == 0)) {
5819 /* 'mapimg show' or 'mapimg show all' */
5820 if (check) {
5821 goto cleanup;
5822 }
5823 show_mapimg(caller, CMD_MAPIMG);
5824 } else if (ntokens == 2 && sscanf(token[1], "%d", &id) != 0) {
5825 char str[2048];
5826 /* 'mapimg show <id>' */
5827 if (check) {
5828 goto cleanup;
5829 }
5830
5831 if (mapimg_show(id, str, sizeof(str), TRUE)) {
5832 cmd_reply(CMD_MAPIMG, caller, C_OK, "%s", str);
5833 } else {
5834 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5835 _("Couldn't show definition: %s."), mapimg_error());
5836 ret = FALSE;
5837 }
5838 } else {
5839 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5840 _("Bad argument for 'mapimg show': '%s'."), token[1]);
5841 ret = FALSE;
5842 }
5843 break;
5844
5845 case MAPIMG_COLORTEST:
5846 if (check) {
5847 goto cleanup;
5848 }
5849
5851 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Map color test images saved."));
5852 break;
5853
5854 case MAPIMG_CREATE:
5855 if (ntokens < 2) {
5856 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5857 _("Missing argument for 'mapimg create'."));
5858 ret = FALSE;
5859 goto cleanup;
5860 }
5861
5862 if (strcmp(token[1], "all") == 0) {
5863 int count;
5864
5865 /* 'mapimg create all' */
5866 if (check) {
5867 goto cleanup;
5868 }
5869
5870 count = mapimg_count();
5871 for (id = 0; id < count; id++) {
5872 struct mapdef *pmapdef = mapimg_isvalid(id);
5873
5874 if (pmapdef == NULL
5877 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5878 _("Error saving map image %d: %s."), id, mapimg_error());
5879 ret = FALSE;
5880 }
5881 }
5882 } else if (sscanf(token[1], "%d", &id) != 0) {
5883 struct mapdef *pmapdef;
5884
5885 /* 'mapimg create <id>' */
5886 if (check) {
5887 goto cleanup;
5888 }
5889
5890 pmapdef = mapimg_isvalid(id);
5891 if (pmapdef == NULL
5894 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5895 _("Error saving map image %d: %s."), id, mapimg_error());
5896 ret = FALSE;
5897 }
5898 } else {
5899 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5900 _("Bad argument for 'mapimg create': '%s'."), token[1]);
5901 ret = FALSE;
5902 }
5903 break;
5904 }
5905
5906 cleanup:
5907
5908 free_tokens(token, ntokens);
5909
5910 return ret;
5911}
5912
5913/**********************************************************************/
5916static bool aicmd_command(struct connection *caller, char *arg, bool check)
5917{
5919 struct player *pplayer;
5920 char *tokens[1], *cmd = NULL;
5921 int ntokens;
5922 bool ret = FALSE;
5923
5925
5926 if (ntokens < 1) {
5927 cmd_reply(CMD_AICMD, caller, C_FAIL,
5928 _("No player given for aicmd."));
5929 goto cleanup;
5930 }
5931
5933
5934 if (NULL == pplayer) {
5936 goto cleanup;
5937 }
5938
5939 /* We have a player - extract the command. */
5940 cmd = arg + strlen(tokens[0]);
5941 cmd = skip_leading_spaces(cmd);
5942
5943 if (strlen(cmd) == 0) {
5944 cmd_reply(CMD_AICMD, caller, C_FAIL,
5945 _("No command for the AI console defined."));
5946 goto cleanup;
5947 }
5948
5949 if (check) {
5950 ret = TRUE;
5951 goto cleanup;
5952 }
5953
5954 /* This check is needed to return a message if the function is not defined
5955 * for the AI of the player. */
5956 if (pplayer && pplayer->ai) {
5957 if (pplayer->ai->funcs.player_console) {
5958 cmd_reply(CMD_AICMD, caller, C_OK,
5959 _("AI console for player %s. Command: '%s'."),
5960 player_name(pplayer), cmd);
5961 CALL_PLR_AI_FUNC(player_console, pplayer, pplayer, cmd);
5962 ret = TRUE;
5963 } else {
5964 cmd_reply(CMD_AICMD, caller, C_FAIL,
5965 _("No AI console defined for the AI '%s' of player %s."),
5966 ai_name(pplayer->ai), player_name(pplayer));
5967 }
5968 } else {
5969 cmd_reply(CMD_AICMD, caller, C_FAIL, _("No AI defined for player %s."),
5970 player_name(pplayer));
5971 }
5972
5973 cleanup:
5975 return ret;
5976}
5977
5978/* Define the possible arguments to the fcdb command */
5979#define SPECENUM_NAME fcdb_args
5980#define SPECENUM_VALUE0 FCDB_RELOAD
5981#define SPECENUM_VALUE0NAME "reload"
5982#define SPECENUM_VALUE1 FCDB_LUA
5983#define SPECENUM_VALUE1NAME "lua"
5984#define SPECENUM_COUNT FCDB_COUNT
5985#include "specenum_gen.h"
5986
5987/**********************************************************************/
5990static const char *fcdb_accessor(int i)
5991{
5992 i = CLIP(0, i, fcdb_args_max());
5993 return fcdb_args_name((enum fcdb_args) i);
5994}
5995
5996/**********************************************************************/
5999static bool fcdb_command(struct connection *caller, char *arg, bool check)
6000{
6001 enum m_pre_result result;
6002 int ind, ntokens;
6003 char *token[1];
6004 bool ret = TRUE;
6005 bool usage = FALSE;
6006
6007#ifndef HAVE_FCDB
6008 cmd_reply(CMD_FCDB, caller, C_FAIL,
6009 _("Freeciv database script deactivated at compile time."));
6010 return FALSE;
6011#endif
6012
6013 if (!srvarg.fcdb_enabled) {
6014 /* Not supposed to be used. It isn't initialized. */
6015 cmd_reply(CMD_FCDB, caller, C_FAIL,
6016 _("Freeciv database script not activated at server start. "
6017 "See the Freeciv server's --auth command line option."));
6018 return FALSE;
6019 }
6020
6021 ntokens = get_tokens(arg, token, 1, TOKEN_DELIMITERS);
6022
6023 if (ntokens > 0) {
6024 /* match the argument */
6026 fc_strncasecmp, NULL, token[0], &ind);
6027
6028 switch (result) {
6029 case M_PRE_EXACT:
6030 case M_PRE_ONLY:
6031 /* we have a match */
6032 break;
6033 case M_PRE_AMBIGUOUS:
6034 cmd_reply(CMD_FCDB, caller, C_FAIL,
6035 _("Ambiguous fcdb command."));
6036 ret = FALSE;
6037 goto cleanup;
6038 break;
6039 case M_PRE_EMPTY:
6040 case M_PRE_LONG:
6041 case M_PRE_FAIL:
6042 case M_PRE_LAST:
6043 usage = TRUE;
6044 break;
6045 }
6046 } else {
6047 usage = TRUE;
6048 }
6049
6050 if (usage) {
6051 char buf[256] = "";
6052 enum fcdb_args valid_args;
6053
6054 for (valid_args = fcdb_args_begin();
6057 cat_snprintf(buf, sizeof(buf), "'%s'",
6059 if (valid_args != fcdb_args_max()) {
6060 cat_snprintf(buf, sizeof(buf), ", ");
6061 }
6062 }
6063
6064 cmd_reply(CMD_FCDB, caller, C_FAIL,
6065 _("The valid arguments are: %s."), buf);
6066 ret = FALSE;
6067 goto cleanup;
6068 }
6069
6070 if (check) {
6071 ret = TRUE;
6072 goto cleanup;
6073 }
6074
6075 switch (ind) {
6076 case FCDB_RELOAD:
6077 /* Reload database lua script. */
6080 break;
6081
6082 case FCDB_LUA:
6083 /* Skip whitespaces. */
6084 arg = skip_leading_spaces(arg);
6085 /* Skip the base argument 'lua'. */
6086 arg += 3;
6087 /* Now execute the scriptlet. */
6088 ret = script_fcdb_do_string(caller, arg);
6089 break;
6090 }
6091
6092 cleanup:
6093
6094 free_tokens(token, ntokens);
6095
6096 return ret;
6097}
6098
6099/**********************************************************************/
6102static void start_cmd_reply(struct connection *caller, bool notify, char *msg)
6103{
6104 cmd_reply(CMD_START_GAME, caller, C_FAIL, "%s", msg);
6105 if (notify) {
6106 notify_conn(NULL, NULL, E_SETTING, ftc_server, "%s", msg);
6107 }
6108}
6109
6110/**********************************************************************/
6113bool start_command(struct connection *caller, bool check, bool notify)
6114{
6115 int human_players;
6116
6117 switch (server_state()) {
6118 case S_S_INITIAL:
6119 /* Sanity check scenario */
6120 if (game.info.is_new_game && !check) {
6121 if (0 < map_startpos_count()
6123 /* If we load a pre-generated map (i.e., a scenario) it is possible
6124 * to increase the number of players beyond the number supported by
6125 * the scenario. The solution is a hack: cut the extra players
6126 * when the game starts. */
6127 log_verbose("Reduced maxplayers from %d to %d to fit "
6128 "to the number of start positions.",
6131 }
6132
6134 int i;
6135 struct player *pplayer;
6136
6137 for (i = player_slot_count() - 1; i >= 0; i--) {
6138 pplayer = player_by_number(i);
6139 if (pplayer) {
6140 server_remove_player(pplayer);
6141 }
6143 break;
6144 }
6145 }
6146
6147 log_verbose("Had to cut down the number of players to the "
6148 "number of map start positions, there must be "
6149 "something wrong with the savegame or you "
6150 "adjusted the maxplayers value.");
6151 }
6152 }
6153
6154 human_players = 0;
6155 players_iterate(plr) {
6156 if (is_human(plr)) {
6157 human_players++;
6158 }
6160
6161 /* check min_players.
6162 * Allow continuing of savegames where some of the original
6163 * players have died */
6166 char buf[512] = "";
6167
6168 fc_snprintf(buf, sizeof(buf),
6169 _("Not enough human players ('minplayers' server setting has value %d); game will not start."),
6171 start_cmd_reply(caller, notify, buf);
6172 return FALSE;
6173 } else if (player_count() < 1) {
6174 /* At least one player required */
6175 start_cmd_reply(caller, notify,
6176 _("No players; game will not start."));
6177 return FALSE;
6178 } else if (normal_player_count() > server.playable_nations) {
6179 if (nation_set_count() > 1) {
6180 start_cmd_reply(caller, notify,
6181 _("Not enough nations in the current nation set "
6182 "for all players; game will not start. "
6183 "(See 'nationset' setting.)"));
6184 } else {
6185 start_cmd_reply(caller, notify,
6186 _("Not enough nations for all players; game will "
6187 "not start."));
6188 }
6189 return FALSE;
6190 } else if (strlen(game.server.start_units) == 0 && !game.server.start_city) {
6191 start_cmd_reply(caller, notify,
6192 _("Neither 'startcity' nor 'startunits' setting gives "
6193 "players anything to start game with; game will "
6194 "not start."));
6195 return FALSE;
6196 } else if (check) {
6197 return TRUE;
6198 } else if (!caller) {
6199 if (notify) {
6200 /* Called from handle_player_ready()
6201 * Last player just toggled ready-status. */
6203 _("All players are ready; starting game."));
6204 }
6205 start_game();
6206 return TRUE;
6207 } else if (NULL == caller->playing || caller->observer) {
6208 /* A detached or observer player can't do /start. */
6209 return TRUE;
6210 } else {
6211 /* This might trigger recursive call to start_command() if this is
6212 * last player who gets ready. In that case caller is NULL. */
6214 return TRUE;
6215 }
6216 case S_S_OVER:
6217 start_cmd_reply(caller, notify,
6218 /* TRANS: given when /start is invoked during gameover. */
6219 _("Cannot start the game: the game is waiting for all clients "
6220 "to disconnect."));
6221 return FALSE;
6222 case S_S_RUNNING:
6223 start_cmd_reply(caller, notify,
6224 /* TRANS: given when /start is invoked while the game
6225 * is running. */
6226 _("Cannot start the game: it is already running."));
6227 return FALSE;
6228 }
6229 log_error("Unknown server state variant: %d.", server_state());
6230 return FALSE;
6231}
6232
6233/**********************************************************************/
6236static bool cut_client_connection(struct connection *caller, char *name,
6237 bool check)
6238{
6240 struct connection *ptarget;
6241
6243
6244 if (!ptarget) {
6246 return FALSE;
6247 } else if (check) {
6248 return TRUE;
6249 }
6250
6252 /* If we cut the connection, unassign the login name.*/
6253 sz_strlcpy(ptarget->playing->username, _(ANON_USER_NAME));
6254 ptarget->playing->unassigned_user = TRUE;
6255 }
6256
6258 _("Cutting connection %s."), ptarget->username);
6259 connection_close_server(ptarget, _("connection cut"));
6260
6261 return TRUE;
6262}
6263
6264
6265/**********************************************************************/
6269{
6270 time_t *d = fc_malloc(sizeof(*d));
6271 *d = *t;
6272 return d;
6273}
6274
6275/**********************************************************************/
6280{
6282 time_t now, time_of_kick = 0;
6283
6284 if (NULL != time_remaining) {
6285 *time_remaining = 0;
6286 }
6287
6291
6292 if (kick_hash_lookup(kick_table_by_addr, pconn->server.ipaddr,
6295 }
6300 }
6301
6302 if (0 == time_of_kick) {
6303 return FALSE; /* Not found. */
6304 }
6305
6306 now = time(NULL);
6308 /* Kick timeout expired. */
6309 if (0 != time_of_addr_kick) {
6310 kick_hash_remove(kick_table_by_addr, pconn->server.ipaddr);
6311 }
6312 if (0 != time_of_user_kick) {
6314 }
6315 return FALSE;
6316 }
6317
6318 if (NULL != time_remaining) {
6320 }
6321 return TRUE;
6322}
6323
6324/**********************************************************************/
6327static bool kick_command(struct connection *caller, char *name, bool check)
6328{
6329 char ipaddr[FC_MEMBER_SIZEOF(struct connection, server.ipaddr)];
6330 struct connection *pconn;
6332 time_t now;
6333
6336 if (NULL == pconn) {
6338 return FALSE;
6339 }
6340
6341 if (NULL != caller && ALLOW_ADMIN > conn_get_access(caller)) {
6342 const int MIN_UNIQUE_CONNS = 3;
6343 const char *unique_ipaddr[MIN_UNIQUE_CONNS];
6344 int i, num_unique_connections = 0;
6345
6346 if (pconn == caller) {
6347 cmd_reply(CMD_KICK, caller, C_FAIL, _("You may not kick yourself."));
6348 return FALSE;
6349 }
6350
6352 for (i = 0; i < num_unique_connections; i++) {
6353 if (0 == strcmp(unique_ipaddr[i], aconn->server.ipaddr)) {
6354 /* Already listed. */
6355 break;
6356 }
6357 }
6358 if (i >= num_unique_connections) {
6361 /* We have enough already. */
6362 break;
6363 }
6364 unique_ipaddr[num_unique_connections - 1] = aconn->server.ipaddr;
6365 }
6367
6369 cmd_reply(CMD_KICK, caller, C_FAIL,
6370 _("There must be at least %d unique connections to the "
6371 "server for this command to be valid."), MIN_UNIQUE_CONNS);
6372 return FALSE;
6373 }
6374 }
6375
6376 if (check) {
6377 return TRUE;
6378 }
6379
6380 sz_strlcpy(ipaddr, pconn->server.ipaddr);
6381 now = time(NULL);
6383
6385 if (0 != strcmp(ipaddr, aconn->server.ipaddr)) {
6386 continue;
6387 }
6388
6390 /* Unassign the username. */
6391 sz_strlcpy(aconn->playing->username, _(ANON_USER_NAME));
6392 aconn->playing->unassigned_user = TRUE;
6393 }
6394
6396
6397 connection_close_server(aconn, _("kicked"));
6399
6400 return TRUE;
6401}
6402
6403
6404/**********************************************************************/
6408static void show_help_intro(struct connection *caller,
6409 enum command_id help_cmd)
6410{
6411 /* This is formatted like extra_help entries for settings and commands: */
6412 char *help = fc_strdup(
6413 _("Welcome - this is the introductory help text for the Freeciv "
6414 "server.\n"
6415 "\n"
6416 "Two important server concepts are Commands and Options. Commands, "
6417 "such as 'help', are used to interact with the server. Some commands "
6418 "take one or more arguments, separated by spaces. In many cases "
6419 "commands and command arguments may be abbreviated. Options are "
6420 "settings which control the server as it is running.\n"
6421 "\n"
6422 "To find out how to get more information about commands and options, "
6423 "use 'help help'.\n"
6424 "\n"
6425 "For the impatient, the main commands to get going are:\n"
6426 " show - to see current options\n"
6427 " set - to set options\n"
6428 " start - to start the game once players have connected\n"
6429 " save - to save the current game\n"
6430 " quit - to exit"));
6431
6433 cmd_reply(help_cmd, caller, C_COMMENT, "%s", help);
6434 FC_FREE(help);
6435}
6436
6437/**********************************************************************/
6441static void show_help_command(struct connection *caller,
6442 enum command_id help_cmd,
6443 enum command_id id)
6444{
6445 const struct command *cmd = command_by_number(id);
6446
6447 if (command_short_help(cmd)) {
6448 cmd_reply(help_cmd, caller, C_COMMENT,
6449 /* TRANS: <untranslated name> - translated short help */
6450 _("Command: %s - %s"),
6451 command_name(cmd),
6452 command_short_help(cmd));
6453 } else {
6454 cmd_reply(help_cmd, caller, C_COMMENT,
6455 /* TRANS: <untranslated name> */
6456 _("Command: %s"),
6457 command_name(cmd));
6458 }
6459 if (command_synopsis(cmd)) {
6460 /* line up the synopsis lines: */
6461 const char *syn = _("Synopsis: ");
6462 size_t synlen = strlen(syn);
6463 char prefix[40];
6464
6465 fc_snprintf(prefix, sizeof(prefix), "%*s", (int) synlen, " ");
6466 cmd_reply_prefix(help_cmd, caller, C_COMMENT, prefix,
6467 "%s%s", syn, command_synopsis(cmd));
6468 }
6469 cmd_reply(help_cmd, caller, C_COMMENT,
6470 _("Level: %s"), cmdlevel_name(command_level(cmd)));
6471 {
6472 char *help = command_extra_help(cmd);
6473
6474 if (help) {
6476 cmd_reply(help_cmd, caller, C_COMMENT, _("Description:"));
6477 cmd_reply_prefix(help_cmd, caller, C_COMMENT, " ", " %s", help);
6478 FC_FREE(help);
6479 }
6480 }
6481}
6482
6483/**********************************************************************/
6487static void show_help_command_list(struct connection *caller,
6488 enum command_id help_cmd)
6489{
6490 enum command_id i;
6491
6492 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6493 cmd_reply(help_cmd, caller, C_COMMENT,
6494 _("The following server commands are available:"));
6495 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6496 if (!caller && con_get_style()) {
6497 for (i = 0; i < CMD_NUM; i++) {
6498 cmd_reply(help_cmd, caller, C_COMMENT, "%s", command_name_by_number(i));
6499 }
6500 } else {
6502 int j;
6503
6504 buf[0] = '\0';
6505 for (i = 0, j = 0; i < CMD_NUM; i++) {
6506 if (may_use(caller, i)) {
6507 cat_snprintf(buf, sizeof(buf), "%-19s", command_name_by_number(i));
6508 if ((++j % 4) == 0) {
6509 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
6510 buf[0] = '\0';
6511 }
6512 }
6513 }
6514 if (buf[0] != '\0') {
6515 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
6516 }
6517 }
6518 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6519}
6520
6521/**********************************************************************/
6525static void cmd_reply_matches(enum command_id cmd,
6526 struct connection *caller,
6528 int *matches, int num_matches)
6529{
6530 char buf[MAX_LEN_MSG];
6531 const char *src, *end;
6532 char *dest;
6533 int i;
6534
6535 if (accessor_fn == NULL || matches == NULL || num_matches < 1) {
6536 return;
6537 }
6538
6539 dest = buf;
6540 end = buf + sizeof(buf) - 1;
6541
6542 for (i = 0; i < num_matches && dest < end; i++) {
6543 src = accessor_fn(matches[i]);
6544 if (!src) {
6545 continue;
6546 }
6547 if (dest != buf) {
6548 *dest++ = ' ';
6549 }
6550 while (*src != '\0' && dest < end) {
6551 *dest++ = *src++;
6552 }
6553 }
6554 *dest = '\0';
6555
6556 cmd_reply(cmd, caller, C_COMMENT, _("Possible matches: %s"), buf);
6557}
6558
6559/**************************************************************************
6560 Additional 'help' arguments
6561**************************************************************************/
6562#define SPECENUM_NAME help_general_args
6563#define SPECENUM_VALUE0 HELP_GENERAL_COMMANDS
6564#define SPECENUM_VALUE0NAME "commands"
6565#define SPECENUM_VALUE1 HELP_GENERAL_OPTIONS
6566#define SPECENUM_VALUE1NAME "options"
6567#define SPECENUM_COUNT HELP_GENERAL_COUNT
6568#include "specenum_gen.h"
6569
6570/**************************************************************************
6571 Unified indices for help arguments:
6572 CMD_NUM - Server commands
6573 HELP_GENERAL_NUM - General help arguments, above
6574 settings_number() - Server options
6575**************************************************************************/
6576#define HELP_ARG_NUM (CMD_NUM + HELP_GENERAL_COUNT + settings_number())
6577
6578/**********************************************************************/
6581static const char *helparg_accessor(int i)
6582{
6583 if (i < CMD_NUM) {
6584 return command_name_by_number(i);
6585 }
6586
6587 i -= CMD_NUM;
6588 if (i < HELP_GENERAL_COUNT) {
6590 }
6591
6593 return optname_accessor(i);
6594}
6595
6596/**********************************************************************/
6599static bool show_help(struct connection *caller, char *arg)
6600{
6601 int matches[64], num_matches = 0;
6603 int ind;
6604
6606 /* no commands means no help, either */
6607
6609 fc_strncasecmp, NULL, arg, &ind, matches,
6611
6612 if (match_result == M_PRE_EMPTY) {
6613 show_help_intro(caller, CMD_HELP);
6614 return FALSE;
6615 }
6617 cmd_reply(CMD_HELP, caller, C_FAIL,
6618 _("Help argument '%s' is ambiguous."), arg);
6621 return FALSE;
6622 }
6623 if (match_result == M_PRE_FAIL) {
6624 cmd_reply(CMD_HELP, caller, C_FAIL,
6625 _("No match for help argument '%s'."), arg);
6626 return FALSE;
6627 }
6628
6629 /* other cases should be above */
6631
6632 if (ind < CMD_NUM) {
6633 show_help_command(caller, CMD_HELP, ind);
6634 return TRUE;
6635 }
6636 ind -= CMD_NUM;
6637
6638 if (ind == HELP_GENERAL_OPTIONS) {
6640 return TRUE;
6641 }
6642 if (ind == HELP_GENERAL_COMMANDS) {
6644 return TRUE;
6645 }
6647
6648 if (ind < settings_number()) {
6649 show_help_option(caller, CMD_HELP, ind);
6650 return TRUE;
6651 }
6652
6653 /* should have finished by now */
6654 log_error("Bug in show_help!");
6655 return FALSE;
6656}
6657
6658/**********************************************************************/
6661static void show_connections(struct connection *caller)
6662{
6664
6665 cmd_reply(CMD_LIST, caller, C_COMMENT,
6666 _("List of connections to server:"));
6668
6670 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no connections>"));
6671 } else {
6674 if (pconn->established) {
6675 cat_snprintf(buf, sizeof(buf), " command access level %s",
6676 cmdlevel_name(pconn->access_level));
6677 }
6678 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6680 }
6682}
6683
6684/**********************************************************************/
6687static void show_delegations(struct connection *caller)
6688{
6689 bool empty = TRUE;
6690
6691 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of all delegations:"));
6693
6694 players_iterate(pplayer) {
6695 const char *delegate_to = player_delegation_get(pplayer);
6696 if (delegate_to != NULL) {
6697 const char *owner =
6698 player_delegation_active(pplayer) ? pplayer->server.orig_username
6699 : pplayer->username;
6701 cmd_reply(CMD_LIST, caller, C_COMMENT,
6702 /* TRANS: last %s is either " (active)" or empty string */
6703 _("%s delegates control over player '%s' to user %s%s."),
6704 owner, player_name(pplayer), delegate_to,
6705 /* TRANS: preserve leading space */
6706 player_delegation_active(pplayer) ? _(" (active)") : "");
6707 empty = FALSE;
6708 }
6710
6711 if (empty) {
6712 cmd_reply(CMD_LIST, caller, C_COMMENT, _("No delegations defined."));
6713 }
6714
6716}
6717
6718/**********************************************************************/
6721static bool show_ignore(struct connection *caller)
6722{
6723 char buf[128];
6724 int n = 1;
6725
6726 if (NULL == caller) {
6727 cmd_reply(CMD_IGNORE, caller, C_FAIL,
6728 _("That would be rather silly, since you are not a player."));
6729 return FALSE;
6730 }
6731
6732 if (0 == conn_pattern_list_size(caller->server.ignore_list)) {
6733 cmd_reply(CMD_LIST, caller, C_COMMENT, _("Your ignore list is empty."));
6734 return TRUE;
6735 }
6736
6737 cmd_reply(CMD_LIST, caller, C_COMMENT, _("Your ignore list:"));
6741 cmd_reply(CMD_LIST, caller, C_COMMENT, "%d: %s", n++, buf);
6744
6745 return TRUE;
6746}
6747
6748/**********************************************************************/
6751void show_players(struct connection *caller)
6752{
6753 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of players:"));
6755
6756 if (player_count() == 0) {
6757 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no players>"));
6758 } else {
6759 players_iterate(pplayer) {
6761 int n;
6762
6763 /* Low access level callers don't get to see barbarians in list: */
6764 if (is_barbarian(pplayer) && caller
6765 && (caller->access_level < ALLOW_CTRL)) {
6766 continue;
6767 }
6768
6769 /* The output for each player looks like:
6770 *
6771 * <Player name> [color]: Team[, Nation][, Username][, Status]
6772 * AI/Barbarian/Human[, AI type, skill level][, Connections]
6773 * [Details for each connection]
6774 */
6775
6776 /* '<Player name> [color]: [Nation][, Username][, Status]' */
6777 buf[0] = '\0';
6778 cat_snprintf(buf, sizeof(buf), "%s [%s]: %s", player_name(pplayer),
6779 player_color_ftstr(pplayer),
6780 team_name_translation(pplayer->team));
6781 if (!game.info.is_new_game) {
6782 cat_snprintf(buf, sizeof(buf), ", %s",
6784 }
6785 if (strlen(pplayer->username) > 0
6786 && strcmp(pplayer->username, "nouser") != 0) {
6787 cat_snprintf(buf, sizeof(buf), _(", user %s"), pplayer->username);
6788 }
6789 if (S_S_INITIAL == server_state() && pplayer->is_connected) {
6790 if (pplayer->is_ready) {
6791 sz_strlcat(buf, _(", ready"));
6792 } else {
6793 /* Emphasizes this */
6794 n = strlen(buf);
6795 featured_text_apply_tag(_(", not ready"),
6796 buf + n, sizeof(buf) - n,
6798 ftc_changed);
6799 }
6800 } else if (!pplayer->is_alive) {
6801 sz_strlcat(buf, _(", Dead"));
6802 }
6803 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6804
6805 /* ' AI/Barbarian/Human[, skill level][, Connections]' */
6806 buf[0] = '\0';
6807 if (is_barbarian(pplayer)) {
6808 sz_strlcat(buf, _("Barbarian"));
6809 } else if (is_ai(pplayer)) {
6810 sz_strlcat(buf, _("AI"));
6811 } else {
6812 sz_strlcat(buf, _("Human"));
6813 }
6814 if (is_ai(pplayer)) {
6815 cat_snprintf(buf, sizeof(buf), _(", %s"), ai_name(pplayer->ai));
6816 cat_snprintf(buf, sizeof(buf), _(", difficulty level %s"),
6817 ai_level_translated_name(pplayer->ai_common.skill_level));
6818 }
6819 n = conn_list_size(pplayer->connections);
6820 if (n > 0) {
6821 cat_snprintf(buf, sizeof(buf),
6822 PL_(", %d connection:", ", %d connections:", n), n);
6823 }
6824 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", buf);
6825
6826 /* ' [Details for each connection]' */
6827 conn_list_iterate(pplayer->connections, pconn) {
6828 fc_snprintf(buf, sizeof(buf),
6829 _("%s from %s (command access level %s), "
6830 "bufsize=%dkb"), pconn->username, pconn->addr,
6831 cmdlevel_name(pconn->access_level),
6832 (pconn->send_buffer->nsize >> 10));
6833 if (pconn->observer) {
6834 /* TRANS: preserve leading space */
6835 sz_strlcat(buf, _(" (observer mode)"));
6836 }
6837 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", buf);
6840 }
6842}
6843
6846};
6847
6848/************************************************************************/
6851static void ruleset_cache_listcmd_cb(const char *mp_name,
6852 const char *filename, void *data_in)
6853{
6854 struct mrc_listcmd_data *data = (struct mrc_listcmd_data *)data_in;
6855 struct section_file *sf;
6856 const char *name;
6857 const char *serv;
6858 const char *rsdir;
6859
6861
6862 if (name == NULL) {
6863 log_error("Modpack \"%s\" not in ruleset cache", mp_name);
6864 return;
6865 }
6866
6867 sf = secfile_load(name, FALSE);
6868
6869 if (sf == NULL) {
6870 log_error("Failed to load modpack file \"%s\"", name);
6871 return;
6872 }
6873
6874 serv = modpack_serv_file(sf);
6876
6877 if (serv != NULL || rsdir != NULL) {
6878 /* Modpack has ruleset component */
6879 cmd_reply(CMD_LIST, data->caller, C_COMMENT, "%s : %s : %s", mp_name,
6880 rsdir != NULL ? rsdir : "-",
6881 serv != NULL ? serv : "-");
6882 }
6883
6884 secfile_destroy(sf);
6885}
6886
6887/**********************************************************************/
6890static void show_rulesets(struct connection *caller)
6891{
6892 struct mrc_listcmd_data data;
6893
6895 /* TRANS: don't translate text between '' */
6896 _("List of available rulesets, and how to load them:"));
6899 _("Ruleset : /rulesetdir <dir> : /read <script>"));
6901
6903
6904 data.caller = caller;
6906
6908}
6909
6910/**********************************************************************/
6914{
6916 struct fileinfo_list *files;
6917
6918 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of scenarios available:"));
6920
6921 files = fileinfolist_infix(get_scenario_dirs(), ".sav", TRUE);
6922
6924 struct section_file *sf = secfile_load_section(pfile->fullname, "scenario", TRUE);
6925
6926 if (secfile_lookup_bool_default(sf, TRUE, "scenario.is_scenario")) {
6927 fc_snprintf(buf, sizeof(buf), "%s", pfile->name);
6928 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6929 }
6931 fileinfo_list_destroy(files);
6932
6934}
6935
6936/**********************************************************************/
6939static void show_nationsets(struct connection *caller)
6940{
6941 cmd_reply(CMD_LIST, caller, C_COMMENT,
6942 /* TRANS: don't translate text between '' */
6943 _("List of nation sets available for 'nationset' option:"));
6945
6947 const char *description = nation_set_description(pset);
6948 int num_nations = 0;
6949 nations_iterate(pnation) {
6950 if (is_nation_playable(pnation) && nation_is_in_set(pnation, pset)) {
6951 num_nations++;
6952 }
6954 cmd_reply(CMD_LIST, caller, C_COMMENT,
6955 /* TRANS: nation set description; %d refers to number of playable
6956 * nations in set */
6957 PL_(" %-10s %s (%d playable)",
6958 " %-10s %s (%d playable)", num_nations),
6960 num_nations);
6961 if (strlen(description) > 0) {
6962 static const char prefix[] = " ";
6963 char *translated = fc_strdup(_(description));
6965 cmd_reply_prefix(CMD_LIST, caller, C_COMMENT, prefix, "%s%s",
6966 prefix, translated);
6967 }
6969
6971}
6972
6973/**********************************************************************/
6976static void show_teams(struct connection *caller)
6977{
6978 /* Currently this just lists all teams (typically 32 of them) with their
6979 * names and # of players on the team. This could probably be improved. */
6980 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of teams:"));
6982
6984 const struct player_list *members = team_members(pteam);
6985
6986 /* PL_() is needed here because some languages may differentiate
6987 * between 2 and 3 (although English does not). */
6988 cmd_reply(CMD_LIST, caller, C_COMMENT,
6989 /* TRANS: There will always be at least 2 players here. */
6990 PL_("%2d : '%s' : %d player :",
6991 "%2d : '%s' : %d players :",
6995 player_list_iterate(members, pplayer) {
6996 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", player_name(pplayer));
6999
7001}
7002
7003/**********************************************************************/
7006static void show_mapimg(struct connection *caller, enum command_id cmd)
7007{
7008 int id;
7009
7010 if (mapimg_count() == 0) {
7011 cmd_reply(cmd, caller, C_OK, _("No map image definitions."));
7012 } else {
7013 cmd_reply(cmd, caller, C_COMMENT, _("List of map image definitions:"));
7014 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
7015 for (id = 0; id < mapimg_count(); id++) {
7016 char str[MAX_LEN_MAPDEF] = "";
7017 mapimg_show(id, str, sizeof(str), FALSE);
7018 cmd_reply(cmd, caller, C_COMMENT, _("[%2d] %s"), id, str);
7019 }
7020 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
7021 }
7022}
7023
7024/**********************************************************************/
7027static void show_ais(struct connection *caller)
7028{
7029 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of AI types:"));
7031
7032 ai_type_iterate(ai) {
7033 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", ai->name);
7035
7037}
7038
7039/**********************************************************************/
7042static void show_colors(struct connection *caller)
7043{
7044 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of player colors:"));
7046 if (player_count() == 0) {
7047 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no players>"));
7048 } else {
7049 players_iterate(pplayer) {
7050 cmd_reply(CMD_LIST, caller, C_COMMENT, _("%s (user %s): [%s]"),
7051 player_name(pplayer), pplayer->username,
7052 player_color_ftstr(pplayer));
7054 }
7056}
7057
7058/**************************************************************************
7059 '/list' arguments
7060**************************************************************************/
7061#define SPECENUM_NAME list_args
7062#define SPECENUM_VALUE0 LIST_AIS
7063#define SPECENUM_VALUE0NAME "ais"
7064#define SPECENUM_VALUE1 LIST_COLORS
7065#define SPECENUM_VALUE1NAME "colors"
7066#define SPECENUM_VALUE2 LIST_CONNECTIONS
7067#define SPECENUM_VALUE2NAME "connections"
7068#define SPECENUM_VALUE3 LIST_DELEGATIONS
7069#define SPECENUM_VALUE3NAME "delegations"
7070#define SPECENUM_VALUE4 LIST_IGNORE
7071#define SPECENUM_VALUE4NAME "ignored users"
7072#define SPECENUM_VALUE5 LIST_MAPIMG
7073#define SPECENUM_VALUE5NAME "map image definitions"
7074#define SPECENUM_VALUE6 LIST_PLAYERS
7075#define SPECENUM_VALUE6NAME "players"
7076#define SPECENUM_VALUE7 LIST_RULESETS
7077#define SPECENUM_VALUE7NAME "rulesets"
7078#define SPECENUM_VALUE8 LIST_SCENARIOS
7079#define SPECENUM_VALUE8NAME "scenarios"
7080#define SPECENUM_VALUE9 LIST_NATIONSETS
7081#define SPECENUM_VALUE9NAME "nationsets"
7082#define SPECENUM_VALUE10 LIST_TEAMS
7083#define SPECENUM_VALUE10NAME "teams"
7084#define SPECENUM_VALUE11 LIST_VOTES
7085#define SPECENUM_VALUE11NAME "votes"
7086#include "specenum_gen.h"
7087
7088/**********************************************************************/
7091static const char *list_accessor(int i)
7092{
7093 i = CLIP(0, i, list_args_max());
7094 return list_args_name((enum list_args) i);
7095}
7096
7097/**********************************************************************/
7100static bool show_list(struct connection *caller, char *arg)
7101{
7103 int ind_int;
7104 enum list_args ind;
7105
7108 fc_strncasecmp, NULL, arg, &ind_int);
7109 ind = ind_int;
7110
7111 if (match_result > M_PRE_EMPTY) {
7112 cmd_reply(CMD_LIST, caller, C_SYNTAX,
7113 _("Bad list argument: '%s'. Try '%shelp list'."),
7114 arg, (caller ? "/" : ""));
7115 return FALSE;
7116 }
7117
7118 if (match_result == M_PRE_EMPTY) {
7119 ind = LIST_PLAYERS;
7120 }
7121
7122 switch (ind) {
7123 case LIST_AIS:
7124 show_ais(caller);
7125 return TRUE;
7126 case LIST_COLORS:
7127 show_colors(caller);
7128 return TRUE;
7129 case LIST_CONNECTIONS:
7130 show_connections(caller);
7131 return TRUE;
7132 case LIST_DELEGATIONS:
7133 show_delegations(caller);
7134 return TRUE;
7135 case LIST_IGNORE:
7136 return show_ignore(caller);
7137 case LIST_MAPIMG:
7138 show_mapimg(caller, CMD_LIST);
7139 return TRUE;
7140 case LIST_PLAYERS:
7141 show_players(caller);
7142 return TRUE;
7143 case LIST_RULESETS:
7144 show_rulesets(caller);
7145 return TRUE;
7146 case LIST_SCENARIOS:
7147 show_scenarios(caller);
7148 return TRUE;
7149 case LIST_NATIONSETS:
7150 show_nationsets(caller);
7151 return TRUE;
7152 case LIST_TEAMS:
7153 show_teams(caller);
7154 return TRUE;
7155 case LIST_VOTES:
7156 show_votes(caller);
7157 return TRUE;
7158 }
7159
7160 cmd_reply(CMD_LIST, caller, C_FAIL,
7161 "Internal error: ind %d in show_list", ind);
7162 log_error("Internal error: ind %d in show_list", ind);
7163 return FALSE;
7164}
7165
7166#ifdef FREECIV_HAVE_LIBREADLINE
7167/********************* RL completion functions ***************************/
7168/* To properly complete both commands, player names, options and filenames
7169 there is one array per type of completion with the commands that
7170 the type is relevant for.
7171*/
7172
7173/**********************************************************************/
7181static char *generic_generator(const char *text, int state, int num,
7182 const char*(*index2str)(int))
7183{
7184 static int list_index, len;
7185 const char *name = ""; /* dummy non-NULL string */
7187
7188 /* This function takes a string (text) in the local format and must return
7189 * a string in the local format. However comparisons are done against
7190 * names that are in the internal format (UTF-8). Thus we have to convert
7191 * the text function from the local to the internal format before doing
7192 * the comparison, and convert the string we return *back* to the
7193 * local format when returning it. */
7194
7195 /* If this is a new word to complete, initialize now. This includes
7196 saving the length of TEXT for efficiency, and initializing the index
7197 variable to 0. */
7198 if (state == 0) {
7199 list_index = 0;
7200 len = strlen(mytext);
7201 }
7202
7203 /* Return the next name which partially matches: */
7204 while ((num < 0 && name) || (list_index < num)) {
7206 list_index++;
7207
7208 if (name != NULL && fc_strncasecmp(name, mytext, len) == 0) {
7209 free(mytext);
7211 }
7212 }
7213 free(mytext);
7214
7215 /* If no names matched, then return NULL. */
7216 return ((char *)NULL);
7217}
7218
7219/**********************************************************************/
7222static char *command_generator(const char *text, int state)
7223{
7224 return generic_generator(text, state, CMD_NUM, command_name_by_number);
7225}
7226
7227/**********************************************************************/
7230static char *option_generator(const char *text, int state)
7231{
7232 return generic_generator(text, state, settings_number(), optname_accessor);
7233}
7234
7235/**********************************************************************/
7238static char *olevel_generator(const char *text, int state)
7239{
7240 return generic_generator(text, state, settings_number() + OLEVELS_NUM + 1,
7242}
7243
7244/**********************************************************************/
7248static int completion_option;
7249static const char *option_value_accessor(int idx) {
7251
7252 switch (setting_type(pset)) {
7253 case SST_ENUM:
7254 return setting_enum_val(pset, idx, FALSE);
7255 case SST_BITWISE:
7256 return setting_bitwise_bit(pset, idx, FALSE);
7257 default:
7259 }
7260
7261 return NULL;
7262}
7263
7264/**********************************************************************/
7268static char *option_value_generator(const char *text, int state)
7269{
7270 return generic_generator(text, state, -1, option_value_accessor);
7271}
7272
7273/**********************************************************************/
7276static const char *playername_accessor(int idx)
7277{
7278 const struct player_slot *pslot = player_slot_by_number(idx);
7279
7280 if (!player_slot_is_used(pslot)) {
7281 return NULL;
7282 }
7283
7284 return player_name(player_slot_get_player(pslot));
7285}
7286
7287/**********************************************************************/
7290static char *player_generator(const char *text, int state)
7291{
7292 return generic_generator(text, state, player_slot_count(),
7294}
7295
7296/**********************************************************************/
7299static const char *connection_name_accessor(int idx)
7300{
7301 return conn_list_get(game.all_connections, idx)->username;
7302}
7303
7304/**********************************************************************/
7307static char *connection_generator(const char *text, int state)
7308{
7311}
7312
7313/**********************************************************************/
7316static const char *cmdlevel_arg1_accessor(int idx)
7317{
7318 return cmdlevel_name(idx);
7319}
7320
7321/**********************************************************************/
7324static char *cmdlevel_arg1_generator(const char *text, int state)
7325{
7326 return generic_generator(text, state, cmdlevel_max()+1,
7328}
7329
7330/**********************************************************************/
7334static const char *cmdlevel_arg2_accessor(int idx)
7335{
7336 return ((idx == 0) ? "first" :
7337 (idx == 1) ? "new" :
7338 connection_name_accessor(idx - 2));
7339}
7340
7341/**********************************************************************/
7344static char *cmdlevel_arg2_generator(const char *text, int state)
7345{
7346 return generic_generator(text, state,
7347 /* "first", "new", connection names */
7350}
7351
7352/**********************************************************************/
7355static const char *aitype_accessor(int idx)
7356{
7357 return get_ai_type(idx)->name;
7358}
7359
7360/**********************************************************************/
7363static char *aitype_generator(const char *text, int state)
7364{
7365 return generic_generator(text, state, ai_type_get_count(),
7367}
7368
7369/**********************************************************************/
7372static char *reset_generator(const char *text, int state)
7373{
7374 return generic_generator(text, state, reset_args_max() + 1, reset_accessor);
7375}
7376
7377/**********************************************************************/
7380static char *vote_generator(const char *text, int state)
7381{
7382 return generic_generator(text, state, -1, vote_arg_accessor);
7383}
7384
7385/**********************************************************************/
7388static char *delegate_generator(const char *text, int state)
7389{
7390 return generic_generator(text, state, delegate_args_max() + 1,
7392}
7393
7394/**********************************************************************/
7397static char *mapimg_generator(const char *text, int state)
7398{
7399 return generic_generator(text, state, mapimg_args_max() + 1,
7401}
7402
7403/**********************************************************************/
7406static char *fcdb_generator(const char *text, int state)
7407{
7408 return generic_generator(text, state, FCDB_COUNT, fcdb_accessor);
7409}
7410
7411/**********************************************************************/
7414static char *lua_generator(const char *text, int state)
7415{
7416 return generic_generator(text, state, lua_args_max() + 1, lua_accessor);
7417}
7418
7419/**********************************************************************/
7422static char *help_generator(const char *text, int state)
7423{
7424 return generic_generator(text, state, HELP_ARG_NUM, helparg_accessor);
7425}
7426
7427/**********************************************************************/
7430static char *list_generator(const char *text, int state)
7431{
7432 return generic_generator(text, state, list_args_max() + 1, list_accessor);
7433}
7434
7435/**********************************************************************/
7439static bool contains_token_before_start(int start, int token, const char *arg,
7440 bool allow_fluff)
7441{
7442 char *str_itr = rl_line_buffer;
7443 int arg_len = strlen(arg);
7444
7445 /* Swallow unwanted tokens and their preceding delimiters */
7446 while (token--) {
7447 while (str_itr < rl_line_buffer + start && !fc_isalnum(*str_itr)) {
7448 str_itr++;
7449 }
7450 while (str_itr < rl_line_buffer + start && fc_isalnum(*str_itr)) {
7451 str_itr++;
7452 }
7453 }
7454
7455 /* Swallow any delimiters before the token we're interested in */
7456 while (str_itr < rl_line_buffer + start && !fc_isalnum(*str_itr)) {
7457 str_itr++;
7458 }
7459
7460 if (fc_strncasecmp(str_itr, arg, arg_len) != 0) {
7461 return FALSE;
7462 }
7463 str_itr += arg_len;
7464
7465 if (fc_isalnum(*str_itr)) {
7466 /* Not a distinct word. */
7467 return FALSE;
7468 }
7469
7470 if (!allow_fluff) {
7471 for (; str_itr < rl_line_buffer + start; str_itr++) {
7472 if (fc_isalnum(*str_itr)) {
7473 return FALSE;
7474 }
7475 }
7476 }
7477
7478 return TRUE;
7479}
7480
7481/**********************************************************************/
7486static bool contains_str_before_start(int start, const char *cmd,
7487 bool allow_fluff)
7488{
7489 return contains_token_before_start(start, 0, cmd, allow_fluff);
7490}
7491
7492/**********************************************************************/
7496static bool is_command(int start)
7497{
7498 char *str_itr;
7499
7501 return TRUE;
7502
7503 /* if there is only it is also OK */
7505 while (str_itr - rl_line_buffer < start) {
7506 if (fc_isalnum(*str_itr)) {
7507 return FALSE;
7508 }
7509 str_itr++;
7510 }
7511 return TRUE;
7512}
7513
7514/**********************************************************************/
7517static int num_tokens(int start)
7518{
7519 int res = 0;
7520 bool alnum = FALSE;
7521 char *chptr = rl_line_buffer;
7522
7523 while (chptr - rl_line_buffer < start) {
7524 if (fc_isalnum(*chptr)) {
7525 if (!alnum) {
7526 alnum = TRUE;
7527 res++;
7528 }
7529 } else {
7530 alnum = FALSE;
7531 }
7532 chptr++;
7533 }
7534
7535 return res;
7536}
7537
7538/**************************************************************************
7539 Commands that may be followed by a player name
7540**************************************************************************/
7541static const int player_cmd[] = {
7544 CMD_NOVICE,
7545 CMD_EASY,
7546 CMD_NORMAL,
7547 CMD_HARD,
7549#ifdef FREECIV_DEBUG
7551#endif
7552 CMD_REMOVE,
7553 CMD_TEAM,
7555 -1
7556};
7557
7558/**********************************************************************/
7561static bool is_player(int start)
7562{
7563 int i = 0;
7564
7565 while (player_cmd[i] != -1) {
7567 return TRUE;
7568 }
7569 i++;
7570 }
7571
7572 return FALSE;
7573}
7574
7575/**************************************************************************
7576 Commands that may be followed by a connection name
7577**************************************************************************/
7578static const int connection_cmd[] = {
7579 CMD_CUT,
7580 CMD_KICK,
7581 -1
7582};
7583
7584/**********************************************************************/
7587static bool is_connection(int start)
7588{
7589 int i = 0;
7590
7591 while (connection_cmd[i] != -1) {
7592 if (contains_str_before_start(start,
7594 FALSE)) {
7595 return TRUE;
7596 }
7597 i++;
7598 }
7599
7600 return FALSE;
7601}
7602
7603/**********************************************************************/
7606static bool is_cmdlevel_arg2(int start)
7607{
7609 && num_tokens(start) == 2);
7610}
7611
7612/**********************************************************************/
7615static bool is_cmdlevel_arg1(int start)
7616{
7618}
7619
7620/**************************************************************************
7621 Commands that may be followed by a server option name
7622
7623 CMD_SHOW is handled by option_level_cmd, which is for both option levels
7624 and server options
7625**************************************************************************/
7626static const int server_option_cmd[] = {
7628 CMD_SET,
7630 -1
7631};
7632
7633/**********************************************************************/
7637static bool is_server_option(int start)
7638{
7639 int i = 0;
7640
7641 while (server_option_cmd[i] != -1) {
7643 FALSE)) {
7644 return TRUE;
7645 }
7646 i++;
7647 }
7648
7649 return FALSE;
7650}
7651
7652/**************************************************************************
7653 Commands that may be followed by an option level or server option
7654**************************************************************************/
7655static const int option_level_cmd[] = {
7656 CMD_SHOW,
7657 -1
7658};
7659
7660/**********************************************************************/
7664static bool is_option_level(int start)
7665{
7666 int i = 0;
7667
7668 while (option_level_cmd[i] != -1) {
7670 FALSE)) {
7671 return TRUE;
7672 }
7673 i++;
7674 }
7675
7676 return FALSE;
7677}
7678
7679/**********************************************************************/
7684static bool is_enum_option_value(int start, int *opt_p)
7685{
7687 TRUE)) {
7689 if (setting_type(pset) != SST_ENUM
7690 && setting_type(pset) != SST_BITWISE) {
7691 continue;
7692 }
7693 /* Allow a single token for enum options, multiple for bitwise
7694 * (the separator | will separate tokens for these purposes) */
7698 /* Suppress appended space for bitwise options (user may want |) */
7700 return TRUE;
7701 }
7703 }
7704 return FALSE;
7705}
7706
7707/**************************************************************************
7708 Commands that may be followed by a filename
7709**************************************************************************/
7710static const int filename_cmd[] = {
7711 CMD_LOAD,
7712 CMD_SAVE,
7715 -1
7716};
7717
7718/**********************************************************************/
7721static bool is_filename(int start)
7722{
7723 int i = 0;
7724
7725 while (filename_cmd[i] != -1) {
7727 return TRUE;
7728 }
7729 i++;
7730 }
7731
7732 return FALSE;
7733}
7734
7735/**********************************************************************/
7738static bool is_create_arg2(int start)
7739{
7741 && num_tokens(start) == 2);
7742}
7743
7744/**********************************************************************/
7747static bool is_reset(int start)
7748{
7749 return contains_str_before_start(start,
7751 FALSE);
7752}
7753
7754/**********************************************************************/
7757static bool is_vote(int start)
7758{
7759 return contains_str_before_start(start,
7761 FALSE);
7762}
7763
7764/**********************************************************************/
7767static bool is_delegate_arg1(int start)
7768{
7769 return contains_str_before_start(start,
7771 FALSE);
7772}
7773
7774/**********************************************************************/
7777static bool is_mapimg(int start)
7778{
7779 return contains_str_before_start(start,
7781 FALSE);
7782}
7783
7784/**********************************************************************/
7787static bool is_fcdb(int start)
7788{
7789 return contains_str_before_start(start,
7791 FALSE);
7792}
7793
7794/**********************************************************************/
7797static bool is_lua(int start)
7798{
7799 return contains_str_before_start(start,
7801 FALSE);
7802}
7803
7804/**********************************************************************/
7807static bool is_help(int start)
7808{
7810}
7811
7812/**********************************************************************/
7815static bool is_list(int start)
7816{
7818}
7819
7820/**********************************************************************/
7827char **freeciv_completion(const char *text, int start, int end)
7828{
7829 char **matches = (char **)NULL;
7830
7831 if (is_help(start)) {
7833 } else if (is_command(start)) {
7835 } else if (is_list(start)) {
7837 } else if (is_cmdlevel_arg2(start)) {
7839 } else if (is_cmdlevel_arg1(start)) {
7841 } else if (is_connection(start)) {
7843 } else if (is_player(start)) {
7845 } else if (is_server_option(start)) {
7847 } else if (is_option_level(start)) {
7849 } else if (is_enum_option_value(start, &completion_option)) {
7851 } else if (is_filename(start)) {
7852 /* This function we get from readline */
7854 } else if (is_create_arg2(start)) {
7856 } else if (is_reset(start)) {
7858 } else if (is_vote(start)) {
7860 } else if (is_delegate_arg1(start)) {
7862 } else if (is_mapimg(start)) {
7864 } else if (is_fcdb(start)) {
7866 } else if (is_lua(start)) {
7868 } else {
7869 /* We have no idea what to do */
7870 matches = NULL;
7871 }
7872
7873 /* Don't automatically try to complete with filenames */
7875
7876 return (matches);
7877}
7878
7879#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_)
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:263
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:272
#define MAX_LEN_NAME
Definition fc_types.h:67
#define LINE_BREAK
Definition fc_types.h:78
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:2451
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:9243
bool reload_rulesets_settings(void)
Definition ruleload.c:9571
void send_rulesets(struct conn_list *dest)
Definition ruleload.c:9594
#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:5257
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:5595
enum setting_default_level setting_get_setdef(const struct setting *pset)
Definition settings.c:5603
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:5524
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:5266
void send_server_settings(struct conn_list *dest)
Definition settings.c:5385
#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:3496
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2620
bool force_end_of_sniff
Definition srv_main.c:193
void start_game(void)
Definition srv_main.c:1876
const char * aifill(int amount)
Definition srv_main.c:2505
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:2255
void fc__noreturn server_quit(void)
Definition srv_main.c:1913
enum server_states server_state(void)
Definition srv_main.c:338
void server_game_free(void)
Definition srv_main.c:3520
#define TOKEN_DELIMITERS
Definition srvdefs.h:20
static bool write_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:1336
static const char * reset_accessor(int i)
Definition stdinhand.c:4830
static bool set_cmdlevel(struct connection *caller, struct connection *ptarget, enum cmdlevel level)
Definition stdinhand.c:1375
static struct setting * validate_setting_arg(enum command_id cmd, struct connection *caller, char *arg)
Definition stdinhand.c:2927
#define LOOKUP_OPTION_AMBIGUOUS
Definition stdinhand.c:1726
static const char * mapimg_accessor(int i)
Definition stdinhand.c:5679
void cmd_reply(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *format,...)
Definition stdinhand.c:414
static bool set_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2961
static enum command_id cmd_of_level(enum ai_level level)
Definition stdinhand.c:1978
static void show_delegations(struct connection *caller)
Definition stdinhand.c:6687
static char setting_status(struct connection *caller, const struct setting *pset)
Definition stdinhand.c:301
static void show_scenarios(struct connection *caller)
Definition stdinhand.c:6913
static bool delegate_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5189
static bool ignore_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4074
static void show_help_command(struct connection *caller, enum command_id help_cmd, enum command_id id)
Definition stdinhand.c:6441
void set_running_game_access_level(void)
Definition stdinhand.c:1630
void notify_if_first_access_level_is_available(void)
Definition stdinhand.c:1446
static const char * lua_accessor(int i)
Definition stdinhand.c:4990
static const char * fcdb_accessor(int i)
Definition stdinhand.c:5990
static void show_help_command_list(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:6487
static void show_connections(struct connection *caller)
Definition stdinhand.c:6661
static bool explain_option(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1892
static struct kick_hash * kick_table_by_user
Definition stdinhand.c:120
static void show_ais(struct connection *caller)
Definition stdinhand.c:7027
bool conn_is_kicked(struct connection *pconn, int *time_remaining)
Definition stdinhand.c:6279
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:806
static void show_colors(struct connection *caller)
Definition stdinhand.c:7042
static bool set_ai_level(struct connection *caller, const char *name, enum ai_level level, bool check)
Definition stdinhand.c:2025
static struct kick_hash * kick_table_by_addr
Definition stdinhand.c:119
static void show_help_option_list(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:1856
static bool lock_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3141
void stdinhand_init(void)
Definition stdinhand.c:246
static bool take_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3491
static bool wall(char *str, bool check)
Definition stdinhand.c:1925
static enum cmdlevel default_access_level
Definition stdinhand.c:101
static void show_ruleset_info(struct connection *caller, enum command_id cmd, bool check, int read_recursion)
Definition stdinhand.c:2122
void show_players(struct connection *caller)
Definition stdinhand.c:6751
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:6525
#define LOOKUP_OPTION_NO_RESULT
Definition stdinhand.c:1725
static const char * list_accessor(int i)
Definition stdinhand.c:7091
static int lookup_option(const char *name)
Definition stdinhand.c:1737
static bool reset_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:4840
static void show_teams(struct connection *caller)
Definition stdinhand.c:6976
static bool handle_stdin_input_real(struct connection *caller, char *str, bool check, int read_recursion)
Definition stdinhand.c:4451
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:994
static bool metaconnection_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:523
static bool show_serverid(struct connection *caller, char *arg)
Definition stdinhand.c:656
static void show_nationsets(struct connection *caller)
Definition stdinhand.c:6939
static const char * helparg_accessor(int i)
Definition stdinhand.c:6581
static bool metamessage_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:604
static bool away_command(struct connection *caller, bool check)
Definition stdinhand.c:2081
enum cmdlevel access_level_for_next_connection(void)
Definition stdinhand.c:1432
static bool playercolor_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4198
bool handle_stdin_input_free(struct connection *caller, char *str)
Definition stdinhand.c:4432
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2000
static bool player_name_check(const char *name, char *buf, size_t buflen)
Definition stdinhand.c:196
static bool default_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:4947
static bool create_command(struct connection *caller, const char *str, bool check)
Definition stdinhand.c:748
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:374
static const char * delegate_accessor(int i)
Definition stdinhand.c:5180
static void show_rulesets(struct connection *caller)
Definition stdinhand.c:6890
static bool surrender_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4782
static bool end_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4757
static const char * delegate_player_str(struct player *pplayer, bool observer)
Definition stdinhand.c:5640
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:1728
static bool timeout_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1667
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:427
static bool metaserver_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:638
bool handle_stdin_input(struct connection *caller, char *str)
Definition stdinhand.c:4424
static bool cut_client_connection(struct connection *caller, char *name, bool check)
Definition stdinhand.c:6236
static void open_metaserver_connection(struct connection *caller, bool persistent)
Definition stdinhand.c:496
#define HELP_ARG_NUM
Definition stdinhand.c:6576
static time_t * time_duplicate(const time_t *t)
Definition stdinhand.c:6268
static void show_mapimg(struct connection *caller, enum command_id cmd)
Definition stdinhand.c:7006
static bool may_use_nothing(struct connection *caller)
Definition stdinhand.c:289
static void show_votes(struct connection *caller)
Definition stdinhand.c:2470
static const char *const vote_args[]
Definition stdinhand.c:2505
static bool show_settings(struct connection *caller, enum command_id called_as, char *str, bool check)
Definition stdinhand.c:2157
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
Definition stdinhand.c:1167
static bool unlock_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3169
static bool a_connection_exists(void)
Definition stdinhand.c:1410
void stdinhand_free(void)
Definition stdinhand.c:258
static bool cmdlevel_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1460
static bool is_first_access_level_taken(void)
Definition stdinhand.c:1418
#define LOOKUP_OPTION_LEVEL_NAME
Definition stdinhand.c:1727
static bool firstlevel_command(struct connection *caller, bool check)
Definition stdinhand.c:1603
static void start_cmd_reply(struct connection *caller, bool notify, char *msg)
Definition stdinhand.c:6102
static bool connectmsg_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1937
static const char horiz_line[]
Definition stdinhand.c:180
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:462
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:327
static void show_help_intro(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:6408
static bool cancelvote_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:2624
bool set_rulesetdir(struct connection *caller, const char *str, bool check, int read_recursion)
Definition stdinhand.c:3973
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Definition stdinhand.c:3786
static bool read_init_script_real(struct connection *caller, const char *script_filename, bool from_cmdline, bool check, int read_recursion)
Definition stdinhand.c:1185
static void show_settings_one(struct connection *caller, enum command_id cmd, struct setting *pset)
Definition stdinhand.c:2329
static bool toggle_ai_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:725
static bool playernation_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4283
static bool team_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2393
static bool quit_game(struct connection *caller, bool check)
Definition stdinhand.c:4410
static bool vote_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2519
#define cmd_reply_show(string)
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6113
static const char * optname_accessor(int i)
Definition stdinhand.c:1643
static bool show_help(struct connection *caller, char *arg)
Definition stdinhand.c:6599
#define OPTION_NAME_SPACE
Definition stdinhand.c:99
struct strvec * get_init_script_choices(void)
Definition stdinhand.c:1268
static bool remove_player_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:1121
static void ruleset_cache_listcmd_cb(const char *mp_name, const char *filename, void *data_in)
Definition stdinhand.c:6851
static bool debug_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2719
static enum command_id command_named(const char *token, bool accept_ambiguity)
Definition stdinhand.c:226
static bool fcdb_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5999
static bool mapimg_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5688
static bool unignore_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4109
static bool observe_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3343
static bool show_list(struct connection *caller, char *arg)
Definition stdinhand.c:7100
static bool scensave_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:684
static enum sset_level lookup_option_level(const char *name)
Definition stdinhand.c:1711
static bool may_use(struct connection *caller, enum command_id cmd)
Definition stdinhand.c:277
static bool kick_command(struct connection *caller, char *name, bool check)
Definition stdinhand.c:6327
static const char * vote_arg_accessor(int i)
Definition stdinhand.c:2511
static bool is_restricted(struct connection *caller)
Definition stdinhand.c:187
const char * script_extension
Definition stdinhand.c:117
static bool show_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2147
static bool lua_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:4999
static bool write_init_script(char *script_filename)
Definition stdinhand.c:1278
static enum cmdlevel first_access_level
Definition stdinhand.c:102
static bool detach_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3680
static bool aicmd_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5916
static void close_metaserver_connection(struct connection *caller)
Definition stdinhand.c:510
static bool save_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:667
static bool set_ai_level_named(struct connection *caller, const char *name, const char *level_name, bool check)
Definition stdinhand.c:2014
static bool metapatches_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:579
static bool show_ignore(struct connection *caller)
Definition stdinhand.c:6721
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:3201
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:700
static void show_help_option(struct connection *caller, enum command_id help_cmd, int id)
Definition stdinhand.c:1766
static bool read_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:1158
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:6845
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