Freeciv-3.2
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 "ruleset.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/**********************************************************************/
260{
261 /* Nothing at the moment. */
262}
263
264/**********************************************************************/
281
282/**********************************************************************/
286static bool may_use(struct connection *caller, enum command_id cmd)
287{
288 if (!caller) {
289 return TRUE; /* on the console, everything is allowed */
290 }
291 return (caller->access_level >= command_level(command_by_number(cmd)));
292}
293
294/**********************************************************************/
298static bool may_use_nothing(struct connection *caller)
299{
300 if (!caller) {
301 return FALSE; /* on the console, everything is allowed */
302 }
303 return (ALLOW_NONE == conn_get_access(caller));
304}
305
306/**********************************************************************/
310static char setting_status(struct connection *caller,
311 const struct setting *pset)
312{
313 /* First check for a ruleset lock as this is included in
314 * setting_is_changeable() */
315 if (setting_locked(pset)) {
316 /* Setting is locked */
317 return '!';
318 }
319
320 if (setting_is_changeable(pset, caller, NULL, 0)) {
321 /* setting can be changed */
322 return '+';
323 }
324
325 /* setting is fixed */
326 return ' ';
327}
328
329/**********************************************************************/
336static void cmd_reply_line(enum command_id cmd, struct connection *caller,
337 enum rfc_status rfc_status, const char *prefix,
338 const char *line)
339{
340 const char *cmdname = cmd < CMD_NUM
342 : cmd == CMD_AMBIGUOUS
343 /* TRANS: ambiguous command */
344 ? _("(ambiguous)")
345 : cmd == CMD_UNRECOGNIZED
346 /* TRANS: unrecognized command */
347 ? _("(unknown)")
348 : "(?!?)"; /* this case is a bug! */
349
350 if (caller) {
352 "/%s: %s%s", cmdname, prefix, line);
353 /* cc: to the console - testing has proved it's too verbose - rp
354 con_write(rfc_status, "%s/%s: %s%s", caller->name, cmdname, prefix, line);
355 */
356 } else {
357 con_write(rfc_status, "%s%s", prefix, line);
358 }
359
360 if (rfc_status == C_OK) {
361 struct packet_chat_msg packet;
362
363 package_event(&packet, NULL, E_SETTING, ftc_server, "%s", line);
365 /* Do not tell caller, since they were told above! */
366 if (caller != pconn) {
367 send_packet_chat_msg(pconn, &packet);
368 }
371
372 if (NULL != caller) {
373 /* Echo to the console. */
374 log_normal("%s", line);
375 }
376 }
377}
378
379/**********************************************************************/
383static void vcmd_reply_prefix(enum command_id cmd, struct connection *caller,
384 enum rfc_status rfc_status, const char *prefix,
385 const char *format, va_list ap)
386{
387 char buf[4096];
388 char *c0, *c1;
389
390 fc_vsnprintf(buf, sizeof(buf), format, ap);
391
392 c0 = buf;
393 while ((c1 = strstr(c0, "\n"))) {
394 *c1 = '\0';
395 cmd_reply_line(cmd, caller, rfc_status, (c0 == buf ? "" : prefix), c0);
396 c0 = c1 + 1;
397 }
398
399 cmd_reply_line(cmd, caller, rfc_status, (c0 == buf ? "" : prefix), c0);
400}
401
402/**********************************************************************/
406static void cmd_reply_prefix(enum command_id cmd, struct connection *caller,
407 enum rfc_status rfc_status, const char *prefix,
408 const char *format, ...)
411 enum rfc_status rfc_status, const char *prefix,
412 const char *format, ...)
413{
414 va_list ap;
415 va_start(ap, format);
416 vcmd_reply_prefix(cmd, caller, rfc_status, prefix, format, ap);
417 va_end(ap);
418}
419
420/**********************************************************************/
423void cmd_reply(enum command_id cmd, struct connection *caller,
424 enum rfc_status rfc_status, const char *format, ...)
425{
426 va_list ap;
427 va_start(ap, format);
428 vcmd_reply_prefix(cmd, caller, rfc_status, "", format, ap);
429 va_end(ap);
430}
431
432/**********************************************************************/
437 struct connection *caller,
438 const char *name,
440{
441 switch (match_result) {
442 case M_PRE_EMPTY:
443 cmd_reply(cmd, caller, C_SYNTAX,
444 _("Name is empty, so cannot be a player."));
445 break;
446 case M_PRE_LONG:
447 cmd_reply(cmd, caller, C_SYNTAX,
448 _("Name is too long, so cannot be a player."));
449 break;
450 case M_PRE_AMBIGUOUS:
451 cmd_reply(cmd, caller, C_FAIL,
452 _("Player name prefix '%s' is ambiguous."), name);
453 break;
454 case M_PRE_FAIL:
455 cmd_reply(cmd, caller, C_FAIL,
456 _("No player by the name of '%s'."), name);
457 break;
458 default:
459 cmd_reply(cmd, caller, C_FAIL,
460 _("Unexpected match_result %d (%s) for '%s'."),
462 log_error("Unexpected match_result %d (%s) for '%s'.",
464 }
465}
466
467/**********************************************************************/
472 struct connection *caller,
473 const char *name,
475{
476 switch (match_result) {
477 case M_PRE_EMPTY:
478 cmd_reply(cmd, caller, C_SYNTAX,
479 _("Name is empty, so cannot be a connection."));
480 break;
481 case M_PRE_LONG:
482 cmd_reply(cmd, caller, C_SYNTAX,
483 _("Name is too long, so cannot be a connection."));
484 break;
485 case M_PRE_AMBIGUOUS:
486 cmd_reply(cmd, caller, C_FAIL,
487 _("Connection name prefix '%s' is ambiguous."), name);
488 break;
489 case M_PRE_FAIL:
490 cmd_reply(cmd, caller, C_FAIL,
491 _("No connection by the name of '%s'."), name);
492 break;
493 default:
494 cmd_reply(cmd, caller, C_FAIL,
495 _("Unexpected match_result %d (%s) for '%s'."),
497 log_error("Unexpected match_result %d (%s) for '%s'.",
499 }
500}
501
502/**********************************************************************/
505static void open_metaserver_connection(struct connection *caller,
506 bool persistent)
507{
510 cmd_reply(CMD_METACONN, caller, C_OK,
511 _("Open metaserver connection to [%s]."),
513 }
514}
515
516/**********************************************************************/
519static void close_metaserver_connection(struct connection *caller)
520{
523 cmd_reply(CMD_METACONN, caller, C_OK,
524 _("Close metaserver connection to [%s]."),
526 }
527}
528
529/**********************************************************************/
532static bool metaconnection_command(struct connection *caller, char *arg,
533 bool check)
534{
535 bool persistent = FALSE;
536
537 if ((*arg == '\0')
538 || (!strcmp(arg, "?"))) {
539 if (is_metaserver_open()) {
541 _("Metaserver connection is open."));
542 } else {
544 _("Metaserver connection is closed."));
545 }
546 return TRUE;
547 }
548
549 if (!fc_strcasecmp(arg, "p")
550 || !fc_strcasecmp(arg, "persistent")) {
552 }
553
554 if (persistent
555 || !fc_strcasecmp(arg, "u")
556 || !fc_strcasecmp(arg, "up")) {
557 if (!is_metaserver_open()) {
558 if (!check) {
560 }
561 } else {
563 _("Metaserver connection is already open."));
564 return FALSE;
565 }
566 } else if (!fc_strcasecmp(arg, "d")
567 || !fc_strcasecmp(arg, "down")) {
568 if (is_metaserver_open()) {
569 if (!check) {
571 }
572 } else {
574 _("Metaserver connection is already closed."));
575 return FALSE;
576 }
577 } else {
579 _("Argument must be 'u', 'up', 'd', 'down', 'p', 'persistent', or '?'."));
580 return FALSE;
581 }
582 return TRUE;
583}
584
585/**********************************************************************/
588static bool metapatches_command(struct connection *caller,
589 char *arg, bool check)
590{
591 if (check) {
592 return TRUE;
593 }
594
596
597 if (is_metaserver_open()) {
600 _("Metaserver patches string set to '%s'."), arg);
601 } else {
603 _("Metaserver patches string set to '%s', "
604 "not reporting to metaserver."), arg);
605 }
606
607 return TRUE;
608}
609
610/**********************************************************************/
613static bool metamessage_command(struct connection *caller,
614 char *arg, bool check)
615{
616 struct setting *pset;
617
618 log_deprecation(_("/metamessage command is deprecated. "
619 "Set metamessage setting instead."));
620
621 if (check) {
622 return TRUE;
623 }
624
626 if (is_metaserver_open()) {
629 _("Metaserver message string set to '%s'."), arg);
630 } else {
632 _("Metaserver message string set to '%s', "
633 "not reporting to metaserver."), arg);
634 }
635
636 /* Metamessage is also a setting. */
637 pset = setting_by_name("metamessage");
640
641 return TRUE;
642}
643
644/**********************************************************************/
647static bool metaserver_command(struct connection *caller, char *arg,
648 bool check)
649{
650 if (check) {
651 return TRUE;
652 }
654
656
658 _("Metaserver is now [%s]."), meta_addr_port());
659 return TRUE;
660}
661
662/**********************************************************************/
665static bool show_serverid(struct connection *caller, char *arg)
666{
667 cmd_reply(CMD_SRVID, caller, C_COMMENT, _("Server id: %s"), srvarg.serverid);
668
669 return TRUE;
670}
671
672/**********************************************************************/
676static bool save_command(struct connection *caller, char *arg, bool check)
677{
678 if (is_restricted(caller)) {
679 cmd_reply(CMD_SAVE, caller, C_FAIL,
680 _("You cannot save games manually on this server."));
681 return FALSE;
682 }
683 if (!check) {
684 save_game(arg, "User request", FALSE);
685 }
686 return TRUE;
687}
688
689/**********************************************************************/
693static bool scensave_command(struct connection *caller, char *arg, bool check)
694{
695 if (is_restricted(caller)) {
696 cmd_reply(CMD_SAVE, caller, C_FAIL,
697 _("You cannot save games manually on this server."));
698 return FALSE;
699 }
700 if (!check) {
701 save_game(arg, "Scenario", TRUE);
702 }
703 return TRUE;
704}
705
706/**********************************************************************/
709void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
710{
711 fc_assert_ret(pplayer != NULL);
712
713 if (is_human(pplayer)) {
714 cmd_reply(CMD_AITOGGLE, caller, C_OK,
715 _("%s is now under AI control."),
716 player_name(pplayer));
717 player_set_to_ai_mode(pplayer,
720 : pplayer->ai_common.skill_level);
721 fc_assert(is_ai(pplayer));
722 } else {
723 cmd_reply(CMD_AITOGGLE, caller, C_OK,
724 _("%s is now under human control."),
725 player_name(pplayer));
727 fc_assert(is_human(pplayer));
728 }
729}
730
731/**********************************************************************/
734static bool toggle_ai_command(struct connection *caller, char *arg, bool check)
735{
737 struct player *pplayer;
738
739 pplayer = player_by_name_prefix(arg, &match_result);
740
741 if (!pplayer) {
743 return FALSE;
744 } else if (!check) {
745 toggle_ai_player_direct(caller, pplayer);
747 }
748 return TRUE;
749}
750
751/**********************************************************************/
757static bool create_command(struct connection *caller, const char *str,
758 bool check)
759{
760 enum rfc_status status;
762
763 /* 2 legal arguments, and extra space for stuffing illegal part */
764 char *arg[3];
765 int ntokens;
766 const char *ai_type_name;
767
770
771 if (ntokens == 1) {
773 } else if (ntokens == 2) {
774 ai_type_name = arg[1];
775 } else {
777 _("Wrong number of arguments to create command."));
778 free_tokens(arg, ntokens);
779 return FALSE;
780 }
781
782 if (game_was_started()) {
784 NULL, NULL, buf, sizeof(buf));
785 } else {
787 NULL, buf, sizeof(buf));
788 }
789
790 free_tokens(arg, ntokens);
791
792 if (status != C_OK) {
793 /* No player created. */
794 cmd_reply(CMD_CREATE, caller, status, "%s", buf);
795 return FALSE;
796 }
797
798 if (strlen(buf) > 0) {
799 /* Send a notification. */
800 cmd_reply(CMD_CREATE, caller, C_OK, "%s", buf);
801 }
802
803 return TRUE;
804}
805
806/**********************************************************************/
816 const char *ai,
817 bool check,
818 struct nation_type *pnation,
819 struct player **newplayer,
820 char *buf, size_t buflen)
821{
822 struct player *pplayer = NULL;
823 struct research *presearch;
824 bool new_slot = FALSE;
825
826 /* Check player name. */
828 return C_SYNTAX;
829 }
830
831 /* Check first if we can replace a player with
832 * [1a] - the same username. */
833 pplayer = player_by_user(name);
834 if (pplayer && pplayer->is_alive) {
836 _("A living user already exists by that name."));
837 return C_BOUNCE;
838 }
839
840 /* [1b] - the same player name. */
841 pplayer = player_by_name(name);
842 if (pplayer && pplayer->is_alive) {
844 _("A living player already exists by that name."));
845 return C_BOUNCE;
846 }
847
848 if (pnation) {
849 if (!nation_is_in_current_set(pnation)) {
851 _("Can't create player, requested nation %s not in "
852 "current nation set."),
854 return C_FAIL;
855 }
857 if (0 > nations_match(pnation, nation_of_player(aplayer), FALSE)) {
859 _("Can't create players, nation %s conflicts with %s."),
861 nation_plural_for_player(pplayer));
862 return C_FAIL;
863 }
865 } else {
866 /* Try to find a nation. */
868 if (pnation == NO_NATION_SELECTED) {
870 _("Can't create players, no nations available."));
871 return C_FAIL;
872 }
873 }
874
875 if (pplayer == NULL) {
876 if (player_count() == player_slot_count()) {
877 bool dead_found = FALSE;
878
880 if (!aplayer->is_alive) {
882 break;
883 }
885
886 if (!dead_found) {
888 _("Can't create players, no slots available."));
889 return C_FAIL;
890 }
891 } else if (normal_player_count() == game.server.max_players) {
893 _("Maxplayers setting prevents creation of more players."));
894 return C_FAIL;
895 }
896 }
897
898 if (check) {
899 /* All code below will change the game state. */
900
901 /* Return an empty string. */
902 buf[0] = '\0';
903
904 return C_OK;
905 }
906
907 if (pplayer) {
908 /* [1] Replace a player. 'pplayer' was set above. */
910 _("%s is replacing dead player %s as an AI-controlled "
911 "player."), name, player_name(pplayer));
912 /* remove player and thus free a player slot */
913 server_remove_player(pplayer);
914 pplayer = NULL;
915 } else if (player_count() == player_slot_count()) {
916 /* [2] All player slots are used; try to remove a dead player. */
917 bool dead_found = FALSE;
918
920 if (!aplayer->is_alive) {
921 if (!dead_found) {
922 /* Fill the buffer with the name of the first found dead player */
924 _("%s is replacing dead player %s as an AI-controlled "
925 "player."), name, player_name(aplayer));
927 }
928
929 /* Remove player and thus free a player slot */
931 }
932
935 } else {
936 /* [3] An empty player slot must be used for the new player. */
937 new_slot = TRUE;
938 }
939
940 /* Create the new player. */
941 pplayer = server_create_player(-1, ai, NULL, FALSE);
942 if (!pplayer) {
943 fc_snprintf(buf, buflen, _("Failed to create new player %s."), name);
944 return C_FAIL;
945 }
946
947 if (new_slot) {
948 /* 'buf' must be set if a new player slot is used. */
949 fc_snprintf(buf, buflen, _("New player %s created."), name);
950 }
951
952 /* We have a player; now initialise all needed data. */
954
955 /* Initialise player. */
956 server_player_init(pplayer, TRUE, TRUE);
957
958 player_nation_defaults(pplayer, pnation, FALSE);
959 pplayer->government = pplayer->target_government
960 = init_government_of_nation(pnation);
961 /* Find a color for the new player. */
963
964 /* TRANS: keep one space at the beginning of the string. */
965 cat_snprintf(buf, buflen, _(" Nation of the new player: %s."),
966 nation_rule_name(pnation));
967
968 presearch = research_get(pplayer);
971
974 pplayer->unassigned_user = TRUE;
975
976 pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
977 set_as_ai(pplayer);
979
980 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
981
982 send_player_info_c(pplayer, NULL);
983 /* Send updated diplstate information to all players. */
985 /* Send research info after player info, else the client will complain
986 * about invalid team. */
989
990 if (newplayer != NULL) {
991 *newplayer = pplayer;
992 }
993
994 adv_data_phase_init(pplayer, TRUE);
995 CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, TRUE);
996
997 return C_OK;
998}
999
1000/**********************************************************************/
1004 const char *ai,
1005 bool check,
1006 struct player **newplayer,
1007 char *buf, size_t buflen)
1008{
1009 char leader_name[MAX_LEN_NAME]; /* Must be in whole function scope */
1010 struct player *pplayer = NULL;
1011 bool rand_name = FALSE;
1012
1013 if (name[0] == '\0') {
1014 int filled = 1;
1015
1016 do {
1017 fc_snprintf(leader_name, sizeof(leader_name), "%s*%d", ai, filled++);
1018 } while (player_by_name(leader_name));
1019
1020 name = leader_name;
1021 rand_name = TRUE;
1022 }
1023
1024 if (!player_name_check(name, buf, buflen)) {
1025 return C_SYNTAX;
1026 }
1027
1028 if (NULL != player_by_name(name)) {
1030 _("A player already exists by that name."));
1031 return C_BOUNCE;
1032 }
1033 if (NULL != player_by_user(name)) {
1035 _("A user already exists by that name."));
1036 return C_BOUNCE;
1037 }
1038
1039 /* Search for first uncontrolled player */
1040 pplayer = find_uncontrolled_player();
1041
1042 if (NULL == pplayer) {
1043 /* Check that we are not going over max players setting */
1046 _("Can't add more players, server is full."));
1047 return C_FAIL;
1048 }
1049 /* Check that we have nations available */
1050 if (normal_player_count() >= server.playable_nations) {
1051 if (nation_set_count() > 1) {
1053 _("Can't add more players, not enough playable nations "
1054 "in current nation set (see 'nationset' setting)."));
1055 } else {
1057 _("Can't add more players, not enough playable nations."));
1058 }
1059 return C_FAIL;
1060 }
1061 }
1062
1063 if (pplayer) {
1064 struct ai_type *ait = ai_type_by_name(ai);
1065
1066 if (ait == NULL) {
1068 _("There is no AI type %s."), ai);
1069 return C_FAIL;
1070 }
1071 }
1072
1073 if (check) {
1074 /* All code below will change the game state. */
1075
1076 /* Return an empty string. */
1077 buf[0] = '\0';
1078
1079 return C_OK;
1080 }
1081
1082 if (pplayer) {
1084 /* TRANS: <name> replacing <name> ... */
1085 _("%s replacing %s as an AI-controlled player."),
1086 name, player_name(pplayer));
1087
1088 team_remove_player(pplayer);
1089 pplayer->ai = ai_type_by_name(ai);
1090 } else {
1091 /* add new player */
1092 pplayer = server_create_player(-1, ai, NULL, FALSE);
1093 /* pregame so no need to assign_player_colors() */
1094 if (!pplayer) {
1096 _("Failed to create new player %s."), name);
1097 return C_GENFAIL;
1098 }
1099
1101 _("%s has been added as an AI-controlled player (%s)."),
1102 name, ai_name(pplayer->ai));
1103 }
1104 server_player_init(pplayer, FALSE, TRUE);
1105
1106 server_player_set_name(pplayer, name);
1107 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
1108 pplayer->unassigned_user = TRUE;
1109
1110 pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
1111 pplayer->random_name = rand_name;
1112 set_as_ai(pplayer);
1114 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
1116
1120
1121 if (newplayer != NULL) {
1122 *newplayer = pplayer;
1123 }
1124 return C_OK;
1125}
1126
1127/**********************************************************************/
1130static bool remove_player_command(struct connection *caller, char *arg,
1131 bool check)
1132{
1134 struct player *pplayer;
1135 char name[MAX_LEN_NAME];
1136
1137 pplayer = player_by_name_prefix(arg, &match_result);
1138
1139 if (NULL == pplayer) {
1141 return FALSE;
1142 }
1143
1144 if (game_was_started() && caller && caller->access_level < ALLOW_ADMIN) {
1145 cmd_reply(CMD_REMOVE, caller, C_FAIL,
1146 _("Command level '%s' or greater needed to remove a player "
1147 "once the game has started."), cmdlevel_name(ALLOW_ADMIN));
1148 return FALSE;
1149 }
1150 if (check) {
1151 return TRUE;
1152 }
1153
1154 sz_strlcpy(name, player_name(pplayer));
1155 server_remove_player(pplayer);
1156 if (!caller || caller->used) { /* may have removed self */
1157 cmd_reply(CMD_REMOVE, caller, C_OK,
1158 _("Removed player %s from the game."), name);
1159 }
1161 return TRUE;
1162}
1163
1164/**********************************************************************/
1167static bool read_command(struct connection *caller, char *arg, bool check,
1168 int read_recursion)
1169{
1170 return read_init_script_real(caller, arg, FALSE, check, read_recursion);
1171}
1172
1173/**********************************************************************/
1176bool read_init_script(struct connection *caller, const char *script_filename,
1177 bool from_cmdline, bool check)
1178{
1179 return read_init_script_real(caller, script_filename, from_cmdline,
1180 check, 0);
1181}
1182
1183/**********************************************************************/
1194static bool read_init_script_real(struct connection *caller,
1195 const char *script_filename, bool from_cmdline,
1196 bool check, int read_recursion)
1197{
1199 char serv_filename[strlen(script_extension) + strlen(script_filename) + 2];
1200 char tilde_filename[4096];
1201 const char *real_filename;
1202 size_t fnlen;
1203
1204 /* check recursion depth */
1206 log_error("Error: recursive calls to read!");
1207 return FALSE;
1208 }
1209
1210 /* abuse real_filename to find if we already have a .serv extension */
1211 fnlen = strlen(script_filename);
1212 real_filename = script_filename + fnlen
1215 fc_snprintf(serv_filename, sizeof(serv_filename), "%s%s",
1216 script_filename, script_extension);
1217 } else {
1218 sz_strlcpy(serv_filename, script_filename);
1219 }
1220
1221 if (is_restricted(caller) && !from_cmdline) {
1224 _("Name \"%s\" disallowed for security reasons."),
1226 return FALSE;
1227 }
1229 } else {
1231 }
1232
1234 if (!real_filename) {
1235 if (is_restricted(caller) && !from_cmdline) {
1237 _("No command script found by the name \"%s\"."),
1239 return FALSE;
1240 }
1241 /* File is outside data directories */
1243 }
1244
1245 log_testmatic_alt(LOG_NORMAL, _("Loading script file '%s'."), real_filename);
1246
1248 && (script_file = fc_fopen(real_filename, "r"))) {
1249 char buffer[MAX_LEN_CONSOLE_LINE];
1250
1251 /* The size is set as to not overflow buffer in handle_stdin_input */
1252 while (fgets(buffer, MAX_LEN_CONSOLE_LINE - 1, script_file)) {
1253 /* Execute script contents with same permissions as caller */
1254 handle_stdin_input_real(caller, buffer, check, read_recursion + 1);
1255 }
1257
1259
1260 return TRUE;
1261 } else {
1263 _("Cannot read command line scriptfile '%s'."), real_filename);
1264 if (NULL != caller) {
1265 log_error(_("Could not read script file '%s'."), real_filename);
1266 }
1267 return FALSE;
1268 }
1269}
1270
1271/**********************************************************************/
1281
1282/**********************************************************************/
1287static bool write_init_script(char *script_filename)
1288{
1289 char real_filename[1024], buf[256];
1291
1292 interpret_tilde(real_filename, sizeof(real_filename), script_filename);
1293
1295 && (script_file = fc_fopen(real_filename, "w"))) {
1297 "#FREECIV SERVER COMMAND FILE, version %s\n", VERSION_STRING);
1298 fputs("# These are server options saved from a running freeciv-server.\n",
1299 script_file);
1300
1301 /* First rulesetdir. Setting rulesetdir resets the settings to their
1302 * default value, so they would be lost if placed before this. */
1303 fprintf(script_file, "rulesetdir %s\n", game.server.rulesetdir);
1304
1305 /* Some state info from commands (we can't save everything) */
1306
1307 fprintf(script_file, "cmdlevel %s new\n",
1309
1310 fprintf(script_file, "cmdlevel %s first\n",
1312
1313 fprintf(script_file, "%s\n",
1315
1316 if (*srvarg.metaserver_addr != '\0'
1318 fprintf(script_file, "metaserver %s\n", meta_addr_port());
1319 }
1320
1322 fprintf(script_file, "metapatches %s\n", get_meta_patches_string());
1323 }
1324
1325 /* Then, the 'set' option settings */
1326
1328 fprintf(script_file, "set %s \"%s\"\n", setting_name(pset),
1329 setting_value_name(pset, FALSE, buf, sizeof(buf)));
1331
1333
1334 return TRUE;
1335 } else {
1336 log_error(_("Could not write script file '%s'."), real_filename);
1337
1338 return FALSE;
1339 }
1340}
1341
1342/**********************************************************************/
1345static bool write_command(struct connection *caller, char *arg, bool check)
1346{
1347 if (is_restricted(caller)) {
1349 _("You cannot use the write command on this server"
1350 " for security reasons."));
1351 return FALSE;
1352 } else if (!check) {
1353 char serv_filename[strlen(script_extension) + strlen(arg) + 2];
1354 const char *real_filename;
1355 size_t arglen = strlen(arg);
1356
1357 /* abuse real_filename to find if we already have a .serv extension */
1360 fc_snprintf(serv_filename, sizeof(serv_filename), "%s%s",
1361 arg, script_extension);
1362 } else {
1364 }
1365
1368 /* TRANS: Failed to write server script, e.g., 'example.serv' */
1369 _("Failed to write %s."), serv_filename);
1370 return FALSE;
1371 }
1372
1374 /* TRANS: Wrote server script, e.g., 'example.serv' */
1375 _("Wrote %s."), serv_filename);
1376 }
1377
1378 return TRUE;
1379}
1380
1381/**********************************************************************/
1384static bool set_cmdlevel(struct connection *caller,
1385 struct connection *ptarget,
1386 enum cmdlevel level)
1387{
1388 /* Only ever call me for specific connection. */
1390
1391 if (caller && ptarget->access_level > caller->access_level) {
1392 /*
1393 * This command is intended to be used at ctrl access level
1394 * and thus this if clause is needed.
1395 * (Imagine a ctrl level access player that wants to change
1396 * access level of a hack level access player)
1397 * At the moment it can be used only by hack access level
1398 * and thus this clause is never used.
1399 */
1400 cmd_reply(CMD_CMDLEVEL, caller, C_FAIL,
1401 _("Cannot decrease command access level '%s' "
1402 "for connection '%s'; you only have '%s'."),
1403 cmdlevel_name(ptarget->access_level),
1405 cmdlevel_name(caller->access_level));
1406 return FALSE;
1407 } else {
1409 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1410 _("Command access level set to '%s' for connection %s."),
1412 return TRUE;
1413 }
1414}
1415
1416/**********************************************************************/
1419static bool a_connection_exists(void)
1420{
1422}
1423
1424/**********************************************************************/
1428{
1430 if (pconn->access_level >= first_access_level) {
1431 return TRUE;
1432 }
1433 }
1435 return FALSE;
1436}
1437
1438/**********************************************************************/
1442{
1444 && !a_connection_exists()) {
1445 return first_access_level;
1446 } else {
1447 return default_access_level;
1448 }
1449}
1450
1451/**********************************************************************/
1456{
1460 _("Anyone can now become game organizer "
1461 "'%s' by issuing the 'first' command."),
1463 }
1464}
1465
1466/**********************************************************************/
1469static bool cmdlevel_command(struct connection *caller, char *str, bool check)
1470{
1471 char *arg[2];
1472 int ntokens;
1473 bool ret = FALSE;
1475 enum cmdlevel level;
1476 struct connection *ptarget;
1477
1479
1480 if (ntokens == 0) {
1481 /* No argument supplied; list the levels */
1484 _("Command access levels in effect:"));
1488
1489 if (lvl_name != NULL) {
1490 cmd_reply(CMD_CMDLEVEL, caller, C_COMMENT, "cmdlevel %s %s",
1492 } else {
1493 fc_assert(lvl_name != NULL); /* Always fails when reached. */
1494 }
1497 _("Command access level for new connections: %s"),
1500 _("Command access level for first player to take it: %s"),
1503 return TRUE;
1504 }
1505
1506 /* A level name was supplied; set the level. */
1508 if (!cmdlevel_is_valid(level)) {
1509 const char *cmdlevel_names[CMDLEVEL_COUNT];
1510 struct astring astr = ASTRING_INIT;
1511 int i = 0;
1512
1513 for (level = cmdlevel_begin(); level != cmdlevel_end();
1516 }
1518 /* TRANS: comma and 'or' separated list of access levels */
1519 _("Command access level must be one of %s."),
1521 astr_free(&astr);
1522 goto CLEAN_UP;
1523 } else if (caller && level > conn_get_access(caller)) {
1524 cmd_reply(CMD_CMDLEVEL, caller, C_FAIL,
1525 _("Cannot increase command access level to '%s';"
1526 " you only have '%s' yourself."),
1527 arg[0], cmdlevel_name(conn_get_access(caller)));
1528 goto CLEAN_UP;
1529 }
1530
1531 if (check) {
1532 return TRUE; /* looks good */
1533 }
1534
1535 if (ntokens == 1) {
1536 /* No playername supplied: set for all connections */
1538 if (pconn != caller) {
1539 (void) set_cmdlevel(caller, pconn, level);
1540 }
1542
1543 /* Set the caller access level at last, because it could make the
1544 * previous operations impossible if set before. */
1545 if (caller) {
1546 (void) set_cmdlevel(caller, caller, level);
1547 }
1548
1549 /* Set default access for new connections. */
1551 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1552 _("Command access level set to '%s' for new players."),
1554 /* Set default access for first connection. */
1556 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1557 _("Command access level set to '%s' "
1558 "for first player to grab it."),
1560
1561 ret = TRUE;
1562
1563 } else if (fc_strcasecmp(arg[1], "new") == 0) {
1565 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1566 _("Command access level set to '%s' for new players."),
1568 if (level > first_access_level) {
1570 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1571 _("Command access level set to '%s' "
1572 "for first player to grab it."),
1574 }
1575
1576 ret = TRUE;
1577
1578 } else if (fc_strcasecmp(arg[1], "first") == 0) {
1580 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1581 _("Command access level set to '%s' "
1582 "for first player to grab it."),
1586 cmd_reply(CMD_CMDLEVEL, caller, C_OK,
1587 _("Command access level set to '%s' for new players."),
1589 }
1590
1591 ret = TRUE;
1592
1593 } else if ((ptarget = conn_by_user_prefix(arg[1], &match_result))) {
1594 if (set_cmdlevel(caller, ptarget, level)) {
1595 ret = TRUE;
1596 }
1597 } else {
1599 }
1600
1601CLEAN_UP:
1602 free_tokens(arg, ntokens);
1603 return ret;
1604}
1605
1606/**********************************************************************/
1612static bool firstlevel_command(struct connection *caller, bool check)
1613{
1614 if (!caller) {
1616 _("The 'first' command makes no sense from the server command line."));
1617 return FALSE;
1618 } else if (caller->access_level >= first_access_level) {
1620 _("You already have command access level '%s' or better."),
1622 return FALSE;
1623 } else if (is_first_access_level_taken()) {
1625 _("Someone else is already game organizer."));
1626 return FALSE;
1627 } else if (!check) {
1629 cmd_reply(CMD_FIRSTLEVEL, caller, C_OK,
1630 _("Connection %s has opted to become the game organizer."),
1631 caller->username);
1632 }
1633 return TRUE;
1634}
1635
1636/**********************************************************************/
1640{
1643 _("Default cmdlevel lowered to 'basic' on game start."));
1645 }
1646}
1647
1648/**********************************************************************/
1652static const char *optname_accessor(int i)
1653{
1655}
1656
1657#ifdef FREECIV_HAVE_LIBREADLINE
1658/**********************************************************************/
1661static const char *olvlname_accessor(int i)
1662{
1663 if (i == 0) {
1664 return "rulesetdir";
1665 } else if (i < OLEVELS_NUM+1) {
1666 return sset_level_name(i-1);
1667 } else {
1668 return optname_accessor(i-OLEVELS_NUM-1);
1669 }
1670}
1671#endif /* FREECIV_HAVE_LIBREADLINE */
1672
1673/**********************************************************************/
1676static bool timeout_command(struct connection *caller, char *str, bool check)
1677{
1679 char *arg[4];
1680 int i = 0, ntokens;
1681 int *timeouts[4];
1682
1687
1688 sz_strlcpy(buf, str);
1690
1691 for (i = 0; i < ntokens; i++) {
1692 if (!str_to_int(arg[i], timeouts[i])) {
1693 cmd_reply(CMD_TIMEOUT, caller, C_FAIL, _("Invalid argument %d."),
1694 i + 1);
1695 }
1696 free(arg[i]);
1697 }
1698
1699 if (ntokens == 0) {
1700 cmd_reply(CMD_TIMEOUT, caller, C_SYNTAX, _("Usage:\n%s"),
1702 return FALSE;
1703 } else if (check) {
1704 return TRUE;
1705 }
1706
1707 cmd_reply(CMD_TIMEOUT, caller, C_OK, _("Dynamic timeout set to "
1708 "%d %d %d %d"),
1711
1712 /* if we set anything here, reset the counter */
1714 return TRUE;
1715}
1716
1717/**********************************************************************/
1720static enum sset_level lookup_option_level(const char *name)
1721{
1722 enum sset_level i;
1723
1724 for (i = SSET_ALL; i < OLEVELS_NUM; i++) {
1725 if (0 == fc_strcasecmp(name, sset_level_name(i))) {
1726 return i;
1727 }
1728 }
1729
1730 return SSET_NONE;
1731}
1732
1733/* Special return values of lookup options */
1734#define LOOKUP_OPTION_NO_RESULT (-1)
1735#define LOOKUP_OPTION_AMBIGUOUS (-2)
1736#define LOOKUP_OPTION_LEVEL_NAME (-3)
1737#define LOOKUP_OPTION_RULESETDIR (-4)
1738
1739/**********************************************************************/
1746static int lookup_option(const char *name)
1747{
1748 enum m_pre_result result;
1749 int ind;
1750
1751 /* Check for option levels, first off */
1754 }
1755
1757 0, fc_strncasecmp, NULL, name, &ind);
1758 if (M_PRE_AMBIGUOUS > result) {
1759 return ind;
1760 } else if (M_PRE_AMBIGUOUS == result) {
1762 } else if ('\0' != name[0]
1763 && 0 == fc_strncasecmp("rulesetdir", name, strlen(name))) {
1765 } else {
1767 }
1768}
1769
1770/**********************************************************************/
1775static void show_help_option(struct connection *caller,
1776 enum command_id help_cmd, int id)
1777{
1778 char val_buf[256], def_buf[256];
1779 struct setting *pset = setting_by_number(id);
1780 const char *sethelp;
1781
1782 if (setting_short_help(pset)) {
1783 cmd_reply(help_cmd, caller, C_COMMENT,
1784 /* TRANS: <untranslated name> - translated short help */
1785 _("Option: %s - %s"), setting_name(pset),
1787 } else {
1788 cmd_reply(help_cmd, caller, C_COMMENT,
1789 /* TRANS: <untranslated name> */
1790 _("Option: %s"), setting_name(pset));
1791 }
1792
1794 if (strlen(sethelp) > 0) {
1795 char *help = fc_strdup(sethelp);
1796
1798 cmd_reply(help_cmd, caller, C_COMMENT, _("Description:"));
1799 cmd_reply_prefix(help_cmd, caller, C_COMMENT, " ", " %s", help);
1800 FC_FREE(help);
1801 }
1802 cmd_reply(help_cmd, caller, C_COMMENT,
1803 _("Status: %s"), (setting_is_changeable(pset, NULL, NULL, 0)
1804 ? _("changeable") : _("fixed")));
1805
1806 if (setting_is_visible(pset, caller)) {
1809
1810 switch (setting_type(pset)) {
1811 case SST_INT:
1812 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s, %s %d, %s %s, %s %d",
1813 _("Value:"), val_buf,
1814 _("Minimum:"), setting_int_min(pset),
1815 _("Default:"), def_buf,
1816 _("Maximum:"), setting_int_max(pset));
1817 break;
1818 case SST_ENUM:
1819 {
1820 int i;
1821 const char *value;
1822
1823 cmd_reply(help_cmd, caller, C_COMMENT, _("Possible values:"));
1824 for (i = 0; (value = setting_enum_val(pset, i, FALSE)); i++) {
1825 cmd_reply(help_cmd, caller, C_COMMENT, "- %s: \"%s\"",
1827 }
1828 }
1829
1831 case SST_BOOL:
1832 case SST_STRING:
1833 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s, %s %s",
1834 _("Value:"), val_buf, _("Default:"), def_buf);
1835 break;
1836 case SST_BITWISE:
1837 {
1838 int i;
1839 const char *value;
1840
1841 cmd_reply(help_cmd, caller, C_COMMENT,
1842 _("Possible values (option can take any number of these):"));
1843 for (i = 0; (value = setting_bitwise_bit(pset, i, FALSE)); i++) {
1844 cmd_reply(help_cmd, caller, C_COMMENT, "- %s: \"%s\"",
1846 }
1847 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s",
1848 _("Value:"), val_buf);
1849 cmd_reply(help_cmd, caller, C_COMMENT, "%s %s",
1850 _("Default:"), def_buf);
1851 }
1852 break;
1853 case SST_COUNT:
1855 break;
1856 }
1857 }
1858}
1859
1860/**********************************************************************/
1865static void show_help_option_list(struct connection *caller,
1866 enum command_id help_cmd)
1867{
1868 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1869 cmd_reply(help_cmd, caller, C_COMMENT,
1870 _("Explanations are available for the following server options:"));
1871 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1872 if (!caller && con_get_style()) {
1874 cmd_reply(help_cmd, caller, C_COMMENT, "%s", setting_name(pset));
1876 } else {
1878 int j = 0;
1879 buf[0] = '\0';
1880
1882 if (setting_is_visible(pset, caller)) {
1883 cat_snprintf(buf, sizeof(buf), "%-19s", setting_name(pset));
1884 if ((++j % 4) == 0) {
1885 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
1886 buf[0] = '\0';
1887 }
1888 }
1890
1891 if (buf[0] != '\0') {
1892 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
1893 }
1894 }
1895 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
1896}
1897
1898/**********************************************************************/
1901static bool explain_option(struct connection *caller, char *str, bool check)
1902{
1903 int cmd;
1904
1906
1907 if (*str != '\0') {
1908 cmd = lookup_option(str);
1909 if (cmd >= 0 && cmd < settings_number()) {
1910 show_help_option(caller, CMD_EXPLAIN, cmd);
1911 } else if (cmd == LOOKUP_OPTION_NO_RESULT
1912 || cmd == LOOKUP_OPTION_LEVEL_NAME
1913 || cmd == LOOKUP_OPTION_RULESETDIR) {
1914 cmd_reply(CMD_EXPLAIN, caller, C_FAIL,
1915 _("No explanation for that yet."));
1916 return FALSE;
1917 } else if (cmd == LOOKUP_OPTION_AMBIGUOUS) {
1918 cmd_reply(CMD_EXPLAIN, caller, C_FAIL, _("Ambiguous option name."));
1919 return FALSE;
1920 } else {
1921 log_error("Unexpected case %d in %s line %d", cmd, __FILE__,
1922 __FC_LINE__);
1923 return FALSE;
1924 }
1925 } else {
1927 }
1928 return TRUE;
1929}
1930
1931/**********************************************************************/
1934static bool wall(char *str, bool check)
1935{
1936 if (!check) {
1938 _("Server Operator: %s"), str);
1939 }
1940 return TRUE;
1941}
1942
1943/**********************************************************************/
1946static bool connectmsg_command(struct connection *caller, char *str,
1947 bool check)
1948{
1949 unsigned int bufsize = sizeof(game.server.connectmsg);
1950
1951 if (is_restricted(caller)) {
1952 return FALSE;
1953 }
1954 if (!check) {
1955 int i;
1956 int c = 0;
1957
1958 for (i = 0; c < bufsize -1 && str[i] != '\0'; i++) {
1959 if (str[i] == '\\') {
1960 i++;
1961
1962 if (str[i] == 'n') {
1963 game.server.connectmsg[c++] = '\n';
1964 } else {
1965 game.server.connectmsg[c++] = str[i];
1966 }
1967 } else {
1968 game.server.connectmsg[c++] = str[i];
1969 }
1970 }
1971
1972 game.server.connectmsg[c++] = '\0';
1973
1974 if (c == bufsize) {
1975 /* Truncated */
1977 _("Connectmsg truncated to %u bytes."), bufsize);
1978 }
1979 }
1980 return TRUE;
1981}
1982
1983/**********************************************************************/
1987static enum command_id cmd_of_level(enum ai_level level)
1988{
1989 switch (level) {
1990 case AI_LEVEL_AWAY : return CMD_AWAY;
1991 case AI_LEVEL_RESTRICTED : return CMD_RESTRICTED;
1992 case AI_LEVEL_NOVICE : return CMD_NOVICE;
1993 case AI_LEVEL_EASY : return CMD_EASY;
1994 case AI_LEVEL_NORMAL : return CMD_NORMAL;
1995 case AI_LEVEL_HARD : return CMD_HARD;
1996 case AI_LEVEL_CHEATING : return CMD_CHEATING;
1997#ifdef FREECIV_DEBUG
1999#endif /* FREECIV_DEBUG */
2000 case AI_LEVEL_COUNT : return CMD_NORMAL;
2001 }
2002 log_error("Unknown AI level variant: %d.", level);
2003 return CMD_NORMAL;
2004}
2005
2006/**********************************************************************/
2009void set_ai_level_direct(struct player *pplayer, enum ai_level level)
2010{
2011 set_ai_level_directer(pplayer, level);
2012 send_player_info_c(pplayer, NULL);
2014 _("Player '%s' now has AI skill level '%s'."),
2015 player_name(pplayer),
2017
2018}
2019
2020/**********************************************************************/
2023static bool set_ai_level_named(struct connection *caller, const char *name,
2024 const char *level_name, bool check)
2025{
2027
2028 return set_ai_level(caller, name, level, check);
2029}
2030
2031/**********************************************************************/
2034static bool set_ai_level(struct connection *caller, const char *name,
2035 enum ai_level level, bool check)
2036{
2038 struct player *pplayer;
2039
2041
2043
2044 if (pplayer) {
2045 if (is_ai(pplayer)) {
2046 if (check) {
2047 return TRUE;
2048 }
2049 set_ai_level_directer(pplayer, level);
2050 send_player_info_c(pplayer, NULL);
2051 cmd_reply(cmd_of_level(level), caller, C_OK,
2052 _("Player '%s' now has AI skill level '%s'."),
2053 player_name(pplayer),
2055 } else {
2057 _("%s is not controlled by the AI."),
2058 player_name(pplayer));
2059 return FALSE;
2060 }
2061 } else if (match_result == M_PRE_EMPTY) {
2062 if (check) {
2063 return TRUE;
2064 }
2066 if (is_ai(cplayer)) {
2069 cmd_reply(cmd_of_level(level), caller, C_OK,
2070 _("Player '%s' now has AI skill level '%s'."),
2073 }
2077 cmd_reply(cmd_of_level(level), caller, C_OK,
2078 _("Default AI skill level set to '%s'."),
2080 } else {
2082 return FALSE;
2083 }
2084 return TRUE;
2085}
2086
2087/**********************************************************************/
2090static bool away_command(struct connection *caller, bool check)
2091{
2092 struct player *pplayer;
2093
2094 if (caller == NULL) {
2095 cmd_reply(CMD_AWAY, caller, C_FAIL, _("This command is client only."));
2096 return FALSE;
2097 }
2098
2099 if (!conn_controls_player(caller)) {
2100 /* This happens for detached or observer connections. */
2101 cmd_reply(CMD_AWAY, caller, C_FAIL,
2102 _("Only players may use the away command."));
2103 return FALSE;
2104 }
2105
2106 if (check) {
2107 return TRUE;
2108 }
2109
2110 pplayer = conn_get_player(caller);
2111 if (is_human(pplayer)) {
2112 cmd_reply(CMD_AWAY, caller, C_OK,
2113 _("%s set to away mode."), player_name(pplayer));
2115 fc_assert(!is_human(pplayer));
2116 } else {
2117 cmd_reply(CMD_AWAY, caller, C_OK,
2118 _("%s returned to game."), player_name(pplayer));
2120 fc_assert(is_human(pplayer));
2121 }
2122
2124
2125 return TRUE;
2126}
2127
2128/**********************************************************************/
2131static void show_ruleset_info(struct connection *caller, enum command_id cmd,
2132 bool check, int read_recursion)
2133{
2134 char *show_arg = "changed";
2135
2136 /* show changed settings only at the top level of recursion */
2137 if (read_recursion != 0) {
2138 return;
2139 }
2140
2141 show_settings(caller, cmd, show_arg, check);
2142
2143 if (game.ruleset_summary != NULL) {
2145
2147 cmd_reply(cmd, caller, C_COMMENT, "%s", translated);
2148 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
2150 }
2151}
2152
2153/**********************************************************************/
2156static bool show_command(struct connection *caller, char *str, bool check)
2157{
2158 return show_settings(caller, CMD_SHOW, str, check);
2159}
2160
2161/**********************************************************************/
2166static bool show_settings(struct connection *caller,
2167 enum command_id called_as,
2168 char *str, bool check)
2169{
2170 int cmd;
2171 enum sset_level level = SSET_ALL;
2172 size_t clen = 0;
2173
2175 if (str[0] != '\0') {
2176 /* In "/show forests", figure out that it's the forests option we're
2177 * looking at. */
2178 cmd = lookup_option(str);
2179 if (cmd >= 0) {
2180 /* Ignore levels when a particular option is specified. */
2181 level = SSET_NONE;
2182
2183 if (!setting_is_visible(setting_by_number(cmd), caller)) {
2184 cmd_reply(called_as, caller, C_FAIL,
2185 _("Sorry, you do not have access to view option '%s'."),
2186 str);
2187 return FALSE;
2188 }
2189 }
2190
2191 /* Valid negative values for 'cmd' are defined as LOOKUP_OPTION_*. */
2192 switch (cmd) {
2194 cmd_reply(called_as, caller, C_FAIL, _("Unknown option '%s'."), str);
2195 return FALSE;
2197 /* Allow ambiguous: show all matching. */
2198 clen = strlen(str);
2199 break;
2201 /* Option level. */
2203 break;
2205 /* Ruleset. */
2206 cmd_reply(called_as, caller, C_COMMENT,
2207 _("Current ruleset directory is \"%s\""),
2209 return TRUE;
2210 }
2211 } else {
2212 /* to indicate that no command was specified */
2214 /* Use vital level by default. */
2215 level = SSET_VITAL;
2216 }
2217
2219 || cmd == LOOKUP_OPTION_LEVEL_NAME
2220 || cmd == LOOKUP_OPTION_NO_RESULT, FALSE);
2221
2222#define cmd_reply_show(string) \
2223 cmd_reply(called_as, caller, C_COMMENT, "%s", string)
2224
2225 {
2226 const char *heading = NULL;
2227 switch (level) {
2228 case SSET_NONE:
2229 break;
2230 case SSET_CHANGED:
2231 heading = _("All options with non-default values");
2232 break;
2233 case SSET_ALL:
2234 heading = _("All options");
2235 break;
2236 case SSET_VITAL:
2237 heading = _("Vital options");
2238 break;
2239 case SSET_SITUATIONAL:
2240 heading = _("Situational options");
2241 break;
2242 case SSET_RARE:
2243 heading = _("Rarely used options");
2244 break;
2245 case SSET_LOCKED:
2246 heading = _("Options locked by the ruleset");
2247 break;
2248 case OLEVELS_NUM:
2249 /* nothing */
2250 break;
2251 }
2252 if (heading) {
2255 }
2256 }
2258 cmd_reply_show(_("In the column '##' the status of the option is shown:"));
2259 cmd_reply_show(_(" - a '!' means the option is locked by the ruleset."));
2260 cmd_reply_show(_(" - a '+' means you may change the option."));
2261 cmd_reply_show(_(" - a '~' means that option follows default value."));
2262 cmd_reply_show(_(" - a '=' means the value is same as default."));
2264 cmd_reply(called_as, caller, C_COMMENT, _("%-*s ## value (min, max)"),
2265 OPTION_NAME_SPACE, _("Option"));
2267
2268 /* Update changed and locked levels. */
2270
2271 switch (level) {
2272 case SSET_NONE:
2273 /* Show _one_ setting. */
2274 fc_assert_ret_val(0 <= cmd, FALSE);
2275 {
2276 struct setting *pset = setting_by_number(cmd);
2277
2279 }
2280 break;
2281 case SSET_CHANGED:
2282 case SSET_ALL:
2283 case SSET_VITAL:
2284 case SSET_SITUATIONAL:
2285 case SSET_RARE:
2286 case SSET_LOCKED:
2288 if (!setting_is_visible(pset, caller)) {
2289 continue;
2290 }
2291
2292 if (LOOKUP_OPTION_AMBIGUOUS == cmd
2293 && 0 != fc_strncasecmp(setting_name(pset), str, clen)) {
2294 continue;
2295 }
2296
2299 break;
2300 case OLEVELS_NUM:
2301 /* nothing */
2302 break;
2303 }
2304
2306 /* Only emit this additional help for bona fide 'show' command */
2307 if (called_as == CMD_SHOW) {
2308 cmd_reply_show(_("A help text for each option is available via 'help "
2309 "<option>'."));
2311 if (level == SSET_VITAL) {
2312 cmd_reply_show(_("Try 'show situational' or 'show rare' to show "
2313 "more options.\n"
2314 "Try 'show changed' to show settings with "
2315 "non-default values.\n"
2316 "Try 'show locked' to show settings locked "
2317 "by the ruleset."));
2319 }
2320 }
2321 return TRUE;
2322#undef cmd_reply_show
2323}
2324
2325/**********************************************************************/
2338static void show_settings_one(struct connection *caller, enum command_id cmd,
2339 struct setting *pset)
2340{
2342 bool is_changed;
2343 static char prefix[OPTION_NAME_SPACE + 4 + 1] = "";
2344 char defaultness;
2345
2347
2350
2351 /* Wrap long option values, such as bitwise options */
2352 fc_break_lines(value, LINE_BREAK - (sizeof(prefix)-1));
2353
2354 if (prefix[0] == '\0') {
2355 memset(prefix, ' ', sizeof(prefix)-1);
2356 }
2357
2358 if (is_changed) {
2359 /* Emphasizes the changed option. */
2360 /* Apply tags to each line fragment. */
2361 size_t startpos = 0;
2362 char *nl;
2363
2364 do {
2365 nl = strchr(value + startpos, '\n');
2368 ftc_changed);
2370 if (nl) {
2371 char *p = strchr(nl, '\n');
2372
2373 fc_assert_action(p != NULL, break);
2374 startpos = p + 1 - value;
2375 }
2376 } while (nl);
2377 }
2378
2379 if (SST_INT == setting_type(pset)) {
2380 /* Add the range. */
2381 cat_snprintf(value, sizeof(value), " (%d, %d)",
2383 }
2384
2386 defaultness = '~';
2387 } else if (is_changed) {
2388 defaultness = ' ';
2389 } else {
2390 defaultness = '=';
2391 }
2392
2393 cmd_reply_prefix(cmd, caller, C_COMMENT, prefix, "%-*s %c%c %s",
2396 value);
2397}
2398
2399/**********************************************************************/
2402static bool team_command(struct connection *caller, char *str, bool check)
2403{
2404 struct player *pplayer;
2407 char *arg[2];
2408 int ntokens = 0, i;
2409 bool res = FALSE;
2410 struct team_slot *tslot;
2411
2412 if (game_was_started()) {
2413 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2414 _("Cannot change teams once game has begun."));
2415 return FALSE;
2416 }
2417
2418 if (str != NULL || strlen(str) > 0) {
2419 sz_strlcpy(buf, str);
2421 }
2422 if (ntokens != 2) {
2423 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2424 _("Undefined argument. Usage:\n%s"),
2426 goto cleanup;
2427 }
2428
2429 pplayer = player_by_name_prefix(arg[0], &match_result);
2430 if (pplayer == NULL) {
2432 goto cleanup;
2433 }
2434
2435 tslot = team_slot_by_rule_name(arg[1]);
2436 if (NULL == tslot) {
2437 int teamno;
2438
2439 if (str_to_int(arg[1], &teamno)) {
2441 }
2442 }
2443
2444 if (NULL == tslot) {
2445 cmd_reply(CMD_TEAM, caller, C_SYNTAX,
2446 _("No such team %s. Please give a "
2447 "valid team name or number."), arg[1]);
2448 goto cleanup;
2449 }
2450
2451 if (is_barbarian(pplayer)) {
2452 /* This can happen if we change team settings on a loaded game. */
2453 cmd_reply(CMD_TEAM, caller, C_SYNTAX, _("Cannot team a barbarian."));
2454 goto cleanup;
2455 }
2456
2457 if (!check) {
2458 /* Should never fail when slot given is not NULL */
2459 team_add_player(pplayer, team_new(tslot));
2460 send_player_info_c(pplayer, NULL);
2461 cmd_reply(CMD_TEAM, caller, C_OK, _("Player %s set to team %s."),
2462 player_name(pplayer),
2464 }
2465
2466 res = TRUE;
2467
2468 cleanup:
2469 for (i = 0; i < ntokens; i++) {
2470 free(arg[i]);
2471 }
2472
2473 return res;
2474}
2475
2476/**********************************************************************/
2479static void show_votes(struct connection *caller)
2480{
2481 int count = 0;
2482 const char *title;
2483
2484 if (vote_list != NULL) {
2486 if (NULL != caller && !conn_can_see_vote(caller, pvote)) {
2487 continue;
2488 }
2489 /* TRANS: "Vote" or "Teamvote" is voting-as-a-process. Used as
2490 * part of a sentence. */
2491 title = vote_is_team_only(pvote) ? _("Teamvote") : _("Vote");
2492 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2493 /* TRANS: "[Vote|Teamvote] 3 \"proposed change\" (needs ..." */
2494 _("%s %d \"%s\" (needs %0.0f%%%s): %d for, "
2495 "%d against, and %d abstained out of %d players."),
2496 title, pvote->vote_no, pvote->cmdline,
2497 MIN(100, pvote->need_pc * 100 + 1),
2498 /* TRANS: preserve leading space */
2499 pvote->flags & VCF_NODISSENT ? _(" no dissent") : "",
2500 pvote->yes, pvote->no, pvote->abstain, count_voters(pvote));
2501 count++;
2503 }
2504
2505 if (count == 0) {
2506 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2507 _("There are no votes going on."));
2508 }
2509}
2510
2511/**********************************************************************/
2514static const char *const vote_args[] = {
2515 "yes",
2516 "no",
2517 "abstain",
2518 NULL
2519};
2520static const char *vote_arg_accessor(int i)
2521{
2522 return vote_args[i];
2523}
2524
2525/**********************************************************************/
2528static bool vote_command(struct connection *caller, char *str,
2529 bool check)
2530{
2532 char *arg[2];
2533 int ntokens = 0, i = 0, which = -1;
2535 struct vote *pvote = NULL;
2536 bool res = FALSE;
2537
2538 if (check) {
2539 /* This should never happen, since /vote must always be
2540 * set to ALLOW_BASIC or less. But just in case... */
2541 return FALSE;
2542 }
2543
2544 sz_strlcpy(buf, str);
2546
2547 if (ntokens == 0) {
2548 show_votes(caller);
2549 goto CLEANUP;
2550 } else if (!conn_can_vote(caller, NULL)) {
2551 cmd_reply(CMD_VOTE, caller, C_FAIL,
2552 _("You are not allowed to use this command."));
2553 goto CLEANUP;
2554 }
2555
2557 fc_strncasecmp, NULL, arg[0], &i);
2558
2560 cmd_reply(CMD_VOTE, caller, C_SYNTAX,
2561 _("The argument \"%s\" is ambiguous."), arg[0]);
2562 goto CLEANUP;
2563 } else if (match_result > M_PRE_AMBIGUOUS) {
2564 /* Failed */
2565 cmd_reply(CMD_VOTE, caller, C_SYNTAX,
2566 _("Undefined argument. Usage:\n%s"),
2568 goto CLEANUP;
2569 }
2570
2571 if (ntokens == 1) {
2572 /* Applies to last vote */
2575 } else {
2577 if (num_votes == 0) {
2578 cmd_reply(CMD_VOTE, caller, C_FAIL, _("There are no votes running."));
2579 } else {
2580 /* TRANS: "vote" as a process */
2581 cmd_reply(CMD_VOTE, caller, C_FAIL, _("No legal last vote (%d %s)."),
2582 num_votes, PL_("other vote running", "other votes running",
2583 num_votes));
2584 }
2585 goto CLEANUP;
2586 }
2587 } else {
2588 if (!str_to_int(arg[1], &which)) {
2589 cmd_reply(CMD_VOTE, caller, C_SYNTAX, _("Value must be an integer."));
2590 goto CLEANUP;
2591 }
2592 }
2593
2594 if (!(pvote = get_vote_by_no(which))) {
2595 /* TRANS: "vote" as a process */
2596 cmd_reply(CMD_VOTE, caller, C_FAIL, _("No such vote (%d)."), which);
2597 goto CLEANUP;
2598 }
2599
2600 if (!conn_can_vote(caller, pvote)) {
2601 cmd_reply(CMD_VOTE, caller, C_FAIL,
2602 _("You are not allowed to vote on that."));
2603 goto CLEANUP;
2604 }
2605
2606 if (i == VOTE_YES) {
2607 cmd_reply(CMD_VOTE, caller, C_COMMENT, _("You voted for \"%s\""),
2608 pvote->cmdline);
2609 connection_vote(caller, pvote, VOTE_YES);
2610 } else if (i == VOTE_NO) {
2611 cmd_reply(CMD_VOTE, caller, C_COMMENT, _("You voted against \"%s\""),
2612 pvote->cmdline);
2613 connection_vote(caller, pvote, VOTE_NO);
2614 } else if (i == VOTE_ABSTAIN) {
2615 cmd_reply(CMD_VOTE, caller, C_COMMENT,
2616 _("You abstained from voting on \"%s\""), pvote->cmdline);
2618 } else {
2619 /* Must never happen. */
2621 }
2622
2623 res = TRUE;
2624
2625CLEANUP:
2626 free_tokens(arg, ntokens);
2627 return res;
2628}
2629
2630/**********************************************************************/
2633static bool cancelvote_command(struct connection *caller,
2634 char *arg, bool check)
2635{
2636 struct vote *pvote = NULL;
2637 int vote_no;
2638
2639 if (check) {
2640 /* This should never happen anyway, since /cancelvote
2641 * is set to ALLOW_BASIC in both pregame and while the
2642 * game is running. */
2643 return FALSE;
2644 }
2645
2647
2648 if (arg[0] == '\0') {
2649 if (caller == NULL) {
2650 /* Server prompt */
2652 /* TRANS: "vote" as a process */
2653 _("Missing argument <vote number> or "
2654 "the string \"all\"."));
2655 return FALSE;
2656 }
2657 /* The caller is canceling their own vote. */
2658 if (!(pvote = get_vote_by_caller(caller))) {
2660 _("You don't have any vote going on."));
2661 return FALSE;
2662 }
2663 } else if (fc_strcasecmp(arg, "all") == 0) {
2664 /* Cancel all votes (needs some privileges). */
2665 if (vote_list_size(vote_list) == 0) {
2667 _("There isn't any vote going on."));
2668 return FALSE;
2669 } else if (!caller || conn_get_access(caller) >= ALLOW_ADMIN) {
2672 /* TRANS: "votes" as a process */
2673 _("All votes have been removed."));
2674 return TRUE;
2675 } else {
2677 _("You are not allowed to use this command."));
2678 return FALSE;
2679 }
2680 } else if (str_to_int(arg, &vote_no)) {
2681 /* Cancel one particular vote (needs some privileges if the vote
2682 * is not owned). */
2683 if (!(pvote = get_vote_by_no(vote_no))) {
2685 /* TRANS: "vote" as a process */
2686 _("No such vote (%d)."), vote_no);
2687 return FALSE;
2688 } else if (caller && conn_get_access(caller) < ALLOW_ADMIN
2689 && caller->id != pvote->caller_id) {
2691 /* TRANS: "vote" as a process */
2692 _("You are not allowed to cancel this vote (%d)."),
2693 vote_no);
2694 return FALSE;
2695 }
2696 } else {
2698 /* TRANS: "vote" as a process */
2699 _("Usage: /cancelvote [<vote number>|all]"));
2700 return FALSE;
2701 }
2702
2704
2705 if (caller) {
2708 /* TRANS: "vote" as a process */
2709 _("%s has canceled the vote \"%s\" (number %d)."),
2710 caller->username, pvote->cmdline, pvote->vote_no);
2711 } else {
2712 /* Server prompt */
2715 /* TRANS: "vote" as a process */
2716 _("The vote \"%s\" (number %d) has been canceled."),
2717 pvote->cmdline, pvote->vote_no);
2718 }
2719 /* Make it after, prevent crashs about a free pointer (pvote). */
2721
2722 return TRUE;
2723}
2724
2725/**********************************************************************/
2728static bool debug_command(struct connection *caller, char *str,
2729 bool check)
2730{
2732 char *arg[3];
2733 int ntokens = 0, i;
2734
2735 if (game.info.is_new_game) {
2736 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2737 _("Can only use this command once game has begun."));
2738 return FALSE;
2739 }
2740 if (check) {
2741 return TRUE; /* whatever! */
2742 }
2743
2744 if (str != NULL && strlen(str) > 0) {
2745 sz_strlcpy(buf, str);
2747 } else {
2748 ntokens = 0;
2749 }
2750
2751 if (ntokens > 0 && strcmp(arg[0], "diplomacy") == 0) {
2752 struct player *pplayer;
2754
2755 if (ntokens != 2) {
2756 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2757 _("Undefined argument. Usage:\n%s"),
2759 goto cleanup;
2760 }
2761 pplayer = player_by_name_prefix(arg[1], &match_result);
2762 if (pplayer == NULL) {
2764 goto cleanup;
2765 }
2768 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s diplomacy no longer debugged"),
2769 player_name(pplayer));
2770 } else {
2772 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s diplomacy debugged"),
2773 player_name(pplayer));
2774 /* TODO: print some info about the player here */
2775 }
2776 } else if (ntokens > 0 && strcmp(arg[0], "tech") == 0) {
2777 struct player *pplayer;
2779
2780 if (ntokens != 2) {
2781 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2782 _("Undefined argument. Usage:\n%s"),
2784 goto cleanup;
2785 }
2786 pplayer = player_by_name_prefix(arg[1], &match_result);
2787 if (pplayer == NULL) {
2789 goto cleanup;
2790 }
2791 if (BV_ISSET(pplayer->server.debug, PLAYER_DEBUG_TECH)) {
2793 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s tech no longer debugged"),
2794 player_name(pplayer));
2795 } else {
2797 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s tech debugged"),
2798 player_name(pplayer));
2799 /* TODO: print some info about the player here */
2800 }
2801 } else if (ntokens > 0 && strcmp(arg[0], "info") == 0) {
2802 int cities = 0, players = 0, units = 0, citizen_count = 0;
2803
2804 players_iterate(plr) {
2805 players++;
2806 city_list_iterate(plr->cities, pcity) {
2807 cities++;
2808 citizen_count += city_size_get(pcity);
2810 units += unit_list_size(plr->units);
2812 log_normal(_("players=%d cities=%d citizens=%d units=%d"),
2813 players, cities, citizen_count, units);
2815 _("players=%d cities=%d citizens=%d units=%d"),
2816 players, cities, citizen_count, units);
2817 } else if (ntokens > 0 && strcmp(arg[0], "city") == 0) {
2818 int x, y;
2819 struct tile *ptile;
2820 struct city *pcity;
2821
2822 if (ntokens != 3) {
2823 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2824 _("Undefined argument. Usage:\n%s"),
2826 goto cleanup;
2827 }
2828 if (!str_to_int(arg[1], &x) || !str_to_int(arg[2], &y)) {
2829 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be integer."));
2830 goto cleanup;
2831 }
2832 if (!(ptile = map_pos_to_tile(&(wld.map), x, y))) {
2833 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
2834 goto cleanup;
2835 }
2836 pcity = tile_city(ptile);
2837 if (!pcity) {
2838 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("No city at this coordinate."));
2839 goto cleanup;
2840 }
2841 if (pcity->server.debug) {
2842 pcity->server.debug = FALSE;
2843 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s no longer debugged"),
2844 city_name_get(pcity));
2845 } else {
2846 pcity->server.debug = TRUE;
2847 CITY_LOG(LOG_NORMAL, pcity, "debugged");
2848 }
2849 } else if (ntokens > 0 && strcmp(arg[0], "units") == 0) {
2850 int x, y;
2851 struct tile *ptile;
2852
2853 if (ntokens != 3) {
2854 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2855 _("Undefined argument. Usage:\n%s"),
2857 goto cleanup;
2858 }
2859 if (!str_to_int(arg[1], &x) || !str_to_int(arg[2], &y)) {
2860 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be integer."));
2861 goto cleanup;
2862 }
2863 if (!(ptile = map_pos_to_tile(&(wld.map), x, y))) {
2864 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
2865 goto cleanup;
2866 }
2867 unit_list_iterate(ptile->units, punit) {
2868 if (punit->server.debug) {
2870 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s %s no longer debugged."),
2873 } else {
2875 UNIT_LOG(LOG_NORMAL, punit, "%s %s debugged.",
2878 }
2880 } else if (ntokens > 0 && strcmp(arg[0], "timing") == 0) {
2882 } else if (ntokens > 0 && strcmp(arg[0], "ferries") == 0) {
2885 cmd_reply(CMD_DEBUG, caller, C_OK, _("Ferry system is no longer "
2886 "in debug mode."));
2887 } else {
2889 cmd_reply(CMD_DEBUG, caller, C_OK, _("Ferry system in debug mode."));
2890 }
2891 } else if (ntokens > 0 && strcmp(arg[0], "unit") == 0) {
2892 int id;
2893 struct unit *punit;
2894
2895 if (ntokens != 2) {
2896 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2897 _("Undefined argument. Usage:\n%s"),
2899 goto cleanup;
2900 }
2901 if (!str_to_int(arg[1], &id)) {
2902 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 must be integer."));
2903 goto cleanup;
2904 }
2905 if (!(punit = game_unit_by_number(id))) {
2906 cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Unit %d does not exist."), id);
2907 goto cleanup;
2908 }
2909 if (punit->server.debug) {
2911 cmd_reply(CMD_DEBUG, caller, C_OK, _("%s %s no longer debugged."),
2914 } else {
2916 UNIT_LOG(LOG_NORMAL, punit, "%s %s debugged.",
2919 }
2920 } else {
2921 cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
2922 _("Undefined argument. Usage:\n%s"),
2924 }
2925 cleanup:
2926 for (i = 0; i < ntokens; i++) {
2927 free(arg[i]);
2928 }
2929 return TRUE;
2930}
2931
2932/**********************************************************************/
2937 struct connection *caller,
2938 char *arg)
2939{
2940 int opt = lookup_option(arg);
2941
2942 if (opt < 0) {
2943 switch (opt) {
2946 cmd_reply(cmd, caller, C_SYNTAX, _("Option '%s' not recognized."), arg);
2947 break;
2949 cmd_reply(cmd, caller, C_SYNTAX, _("Ambiguous option name."));
2950 break;
2952 cmd_reply(cmd, caller, C_SYNTAX,
2953 /* TRANS: 'rulesetdir' is the command. Do not translate. */
2954 _("Use the '%srulesetdir' command to change the ruleset "
2955 "directory."), caller ? "/" : "");
2956 break;
2957 default:
2959 break;
2960 }
2961 return NULL;
2962 }
2963
2964 return setting_by_number(opt);
2965}
2966
2967/**********************************************************************/
2970static bool set_command(struct connection *caller, char *str, bool check)
2971{
2972 char *args[2];
2973 int val, nargs;
2974 struct setting *pset;
2975 bool do_update;
2976 char reject_msg[256] = "";
2977 bool ret = FALSE;
2978
2979 /* '=' is also a valid delimiter for this function. */
2980 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS "=");
2981
2982 if (nargs < 2) {
2983 cmd_reply(CMD_SET, caller, C_SYNTAX,
2984 _("Undefined argument. Usage:\n%s"),
2986 goto cleanup;
2987 }
2988
2989 pset = validate_setting_arg(CMD_SET, caller, args[0]);
2990
2991 if (!pset) {
2992 /* Reason already reported. */
2993 goto cleanup;
2994 }
2995
2996 if (!setting_is_changeable(pset, caller, reject_msg, sizeof(reject_msg))
2997 && !check) {
2998 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
2999 goto cleanup;
3000 }
3001
3002 do_update = FALSE;
3003
3004 switch (setting_type(pset)) {
3005 case SST_BOOL:
3006 if (check) {
3008 sizeof(reject_msg))
3009 || (!setting_bool_validate(pset, args[1], caller,
3010 reject_msg, sizeof(reject_msg)))) {
3011 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3012 goto cleanup;
3013 }
3014 } else if (setting_bool_set(pset, args[1], caller,
3015 reject_msg, sizeof(reject_msg))) {
3016 do_update = TRUE;
3017 } else {
3018 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3019 goto cleanup;
3020 }
3021 break;
3022
3023 case SST_INT:
3024 if (!str_to_int(args[1], &val)) {
3025 cmd_reply(CMD_SET, caller, C_SYNTAX,
3026 _("The parameter %s should only contain +- and 0-9."),
3028 goto cleanup;
3029 }
3030 if (check) {
3032 sizeof(reject_msg))
3033 || !setting_int_validate(pset, val, caller, reject_msg,
3034 sizeof(reject_msg))) {
3035 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3036 goto cleanup;
3037 }
3038 } else {
3039 if (setting_int_set(pset, val, caller, reject_msg,
3040 sizeof(reject_msg))) {
3041 do_update = TRUE;
3042 } else {
3043 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3044 goto cleanup;
3045 }
3046 }
3047 break;
3048
3049 case SST_STRING:
3050 if (check) {
3052 sizeof(reject_msg))
3053 || !setting_str_validate(pset, args[1], caller, reject_msg,
3054 sizeof(reject_msg))) {
3055 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3056 goto cleanup;
3057 }
3058 } else {
3059 if (setting_str_set(pset, args[1], caller, reject_msg,
3060 sizeof(reject_msg))) {
3061 do_update = TRUE;
3062 } else {
3063 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3064 goto cleanup;
3065 }
3066 }
3067 break;
3068
3069 case SST_ENUM:
3070 if (check) {
3072 sizeof(reject_msg))
3073 || (!setting_enum_validate(pset, args[1], caller,
3074 reject_msg, sizeof(reject_msg)))) {
3075 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3076 goto cleanup;
3077 }
3078 } else if (setting_enum_set(pset, args[1], caller,
3079 reject_msg, sizeof(reject_msg))) {
3080 do_update = TRUE;
3081 } else {
3082 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3083 goto cleanup;
3084 }
3085 break;
3086
3087 case SST_BITWISE:
3088 if (check) {
3090 sizeof(reject_msg))
3091 || (!setting_bitwise_validate(pset, args[1], caller,
3092 reject_msg, sizeof(reject_msg)))) {
3093 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3094 goto cleanup;
3095 }
3096 } else if (setting_bitwise_set(pset, args[1], caller,
3097 reject_msg, sizeof(reject_msg))) {
3098 do_update = TRUE;
3099 } else {
3100 cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
3101 goto cleanup;
3102 }
3103 break;
3104
3105 case SST_COUNT:
3107 goto cleanup;
3108 break;
3109 }
3110
3111 ret = TRUE; /* Looks like a success. */
3112
3113 if (!check && do_update) {
3114 /* Send only to connections able to see that. */
3115 char buf[256];
3116 struct packet_chat_msg packet;
3117
3119 _("Console: '%s' has been set to %s."), setting_name(pset),
3120 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3123 send_packet_chat_msg(pconn, &packet);
3124 }
3126 /* Notify the console. */
3127 con_write(C_OK, "%s", packet.message);
3128
3132 /*
3133 * send any modified game parameters to the clients -- if sent
3134 * before S_S_RUNNING, triggers a popdown_races_dialog() call
3135 * in client/packhand.c#handle_game_info()
3136 */
3140 }
3141
3142 cleanup:
3143 free_tokens(args, nargs);
3144 return ret;
3145}
3146
3147/**********************************************************************/
3150static bool lock_command(struct connection *caller, char *str, bool check)
3151{
3152 char *args[1];
3153 int nargs;
3154
3155 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS);
3156
3157 if (nargs < 1) {
3158 cmd_reply(CMD_LOCK, caller, C_SYNTAX,
3159 _("Undefined argument. Usage:\n%s"),
3161 } else {
3162 struct setting *pset;
3163
3164 pset = validate_setting_arg(CMD_SET, caller, args[0]);
3165
3166 if (pset != NULL) {
3168 return TRUE;
3169 }
3170 }
3171
3172 return FALSE;
3173}
3174
3175/**********************************************************************/
3178static bool unlock_command(struct connection *caller, char *str, bool check)
3179{
3180 char *args[1];
3181 int nargs;
3182
3183 nargs = get_tokens(str, args, ARRAY_SIZE(args), TOKEN_DELIMITERS);
3184
3185 if (nargs < 1) {
3186 cmd_reply(CMD_LOCK, caller, C_SYNTAX,
3187 _("Undefined argument. Usage:\n%s"),
3189 } else {
3190 struct setting *pset;
3191
3192 pset = validate_setting_arg(CMD_SET, caller, args[0]);
3193
3194 if (pset != NULL) {
3196 return TRUE;
3197 }
3198 }
3199
3200 return FALSE;
3201}
3202
3203/**********************************************************************/
3211 struct connection *taker,
3212 struct player *pplayer, bool will_obs,
3213 char *msg, size_t msg_len)
3214{
3215 const char *allow;
3216
3217 if (!pplayer && !will_obs) {
3218 /* Auto-taking a new player */
3219
3220 if (game_was_started()) {
3221 fc_strlcpy(msg, _("You cannot take a new player at this time."),
3222 msg_len);
3223 return FALSE;
3224 }
3225
3227 fc_snprintf(msg, msg_len,
3228 /* TRANS: Do not translate "maxplayers". */
3229 PL_("You cannot take a new player because "
3230 "the maximum of %d player has already "
3231 "been reached (maxplayers setting).",
3232 "You cannot take a new player because "
3233 "the maximum of %d players has already "
3234 "been reached (maxplayers setting).",
3237 return FALSE;
3238 }
3239
3240 if (player_count() >= player_slot_count()) {
3241 fc_strlcpy(msg, _("You cannot take a new player because there "
3242 "are no free player slots."),
3243 msg_len);
3244 return FALSE;
3245 }
3246
3247 return TRUE;
3248
3249 }
3250
3251#ifdef HAVE_FCDB
3252 if (srvarg.fcdb_enabled) {
3253 bool ok = FALSE;
3254
3255 if (script_fcdb_call("user_take", requester, taker, pplayer, will_obs,
3256 &ok) && ok) {
3257 return TRUE;
3258 }
3259 }
3260#endif
3261
3262 if (!pplayer && will_obs) {
3263 /* Global observer. */
3265 (game.info.is_new_game ? 'O' : 'o')))) {
3266 fc_strlcpy(msg, _("Sorry, one can't observe globally in this game."),
3267 msg_len);
3268 return FALSE;
3269 }
3270 } else if (is_barbarian(pplayer)) {
3271 if (!(allow = strchr(game.server.allow_take, 'b'))) {
3272 if (will_obs) {
3273 fc_strlcpy(msg,
3274 _("Sorry, one can't observe barbarians in this game."),
3275 msg_len);
3276 } else {
3277 fc_strlcpy(msg, _("Sorry, one can't take barbarians in this game."),
3278 msg_len);
3279 }
3280 return FALSE;
3281 }
3282 } else if (!pplayer->is_alive) {
3283 if (!(allow = strchr(game.server.allow_take, 'd'))) {
3284 if (will_obs) {
3285 fc_strlcpy(msg,
3286 _("Sorry, one can't observe dead players in this game."),
3287 msg_len);
3288 } else {
3289 fc_strlcpy(msg,
3290 _("Sorry, one can't take dead players in this game."),
3291 msg_len);
3292 }
3293 return FALSE;
3294 }
3295 } else if (is_ai(pplayer)) {
3297 (game.info.is_new_game ? 'A' : 'a')))) {
3298 if (will_obs) {
3299 fc_strlcpy(msg,
3300 _("Sorry, one can't observe AI players in this game."),
3301 msg_len);
3302 } else {
3303 fc_strlcpy(msg, _("Sorry, one can't take AI players in this game."),
3304 msg_len);
3305 }
3306 return FALSE;
3307 }
3308 } else {
3310 (game.info.is_new_game ? 'H' : 'h')))) {
3311 if (will_obs) {
3312 fc_strlcpy(msg,
3313 _("Sorry, one can't observe human players in this game."),
3314 msg_len);
3315 } else {
3316 fc_strlcpy(msg,
3317 _("Sorry, one can't take human players in this game."),
3318 msg_len);
3319 }
3320 return FALSE;
3321 }
3322 }
3323
3324 allow++;
3325
3326 if (will_obs && (*allow == '2' || *allow == '3')) {
3327 fc_strlcpy(msg, _("Sorry, one can't observe in this game."), msg_len);
3328 return FALSE;
3329 }
3330
3331 if (!will_obs && *allow == '4') {
3332 fc_strlcpy(msg, _("Sorry, one can't take players in this game."),
3333 MAX_LEN_MSG);
3334 return FALSE;
3335 }
3336
3337 if (!will_obs && pplayer->is_connected
3338 && (*allow == '1' || *allow == '3')) {
3339 fc_strlcpy(msg, _("Sorry, one can't take players already "
3340 "connected in this game."), msg_len);
3341 return FALSE;
3342 }
3343
3344 return TRUE;
3345}
3346
3347/**********************************************************************/
3352static bool observe_command(struct connection *caller, char *str, bool check)
3353{
3354 int i = 0, ntokens = 0;
3355 char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
3356 bool is_newgame = !game_was_started();
3357 enum m_pre_result result;
3358 struct connection *pconn = NULL;
3359 struct player *pplayer = NULL;
3360 bool res = FALSE;
3361
3362 /******** PART I: fill pconn and pplayer ********/
3363
3364 sz_strlcpy(buf, str);
3366
3367 /* check syntax, only certain syntax if allowed depending on the caller */
3368 if (!caller && ntokens < 1) {
3369 cmd_reply(CMD_OBSERVE, caller, C_SYNTAX, _("Usage:\n%s"),
3371 goto end;
3372 }
3373
3374 if (ntokens == 2 && (caller && caller->access_level != ALLOW_HACK)) {
3376 _("Only the player name form is allowed."));
3377 goto end;
3378 }
3379
3380 /* match connection if we're console, match a player if we're not */
3381 if (ntokens == 1) {
3382 if (!caller && !(pconn = conn_by_user_prefix(arg[0], &result))) {
3383 cmd_reply_no_such_conn(CMD_OBSERVE, caller, arg[0], result);
3384 goto end;
3385 } else if (caller
3386 && !(pplayer = player_by_name_prefix(arg[0], &result))) {
3387 cmd_reply_no_such_player(CMD_OBSERVE, caller, arg[0], result);
3388 goto end;
3389 }
3390 }
3391
3392 /* get connection name then player name */
3393 if (ntokens == 2) {
3394 if (!(pconn = conn_by_user_prefix(arg[0], &result))) {
3395 cmd_reply_no_such_conn(CMD_OBSERVE, caller, arg[0], result);
3396 goto end;
3397 }
3398 if (!(pplayer = player_by_name_prefix(arg[1], &result))) {
3399 cmd_reply_no_such_player(CMD_OBSERVE, caller, arg[1], result);
3400 goto end;
3401 }
3402 }
3403
3404 /* if we can't force other connections to observe, assign us to be pconn. */
3405 if (!pconn) {
3406 pconn = caller;
3407 }
3408
3409 /* if we have no pplayer, it means that we want to be a global observer */
3410
3411 /******** PART II: do the observing ********/
3412
3413 /* check allowtake for permission */
3414 if (!is_allowed_to_take(caller, pconn, pplayer, TRUE, msg, sizeof(msg))) {
3415 cmd_reply(CMD_OBSERVE, caller, C_FAIL, "%s", msg);
3416 goto end;
3417 }
3418
3419 /* observing your own player (during pregame) makes no sense. */
3420 if (NULL != pplayer
3421 && pplayer == pconn->playing
3422 && !pconn->observer
3423 && is_newgame
3424 && !pplayer->was_created) {
3425 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3426 _("%s already controls %s. Using 'observe' would remove %s"),
3427 pconn->username,
3428 player_name(pplayer),
3429 player_name(pplayer));
3430 goto end;
3431 }
3432
3433 /* attempting to observe a player you're already observing should fail. */
3434 if (pplayer == pconn->playing && pconn->observer) {
3435 if (pplayer) {
3436 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3437 _("%s is already observing %s."),
3438 pconn->username,
3439 player_name(pplayer));
3440 } else {
3441 cmd_reply(CMD_OBSERVE, caller, C_FAIL,
3442 _("%s is already observing."),
3443 pconn->username);
3444 }
3445 goto end;
3446 }
3447
3448 res = TRUE; /* all tests passed */
3449 if (check) {
3450 goto end;
3451 }
3452
3453 /* if the connection is already attached to a player,
3454 * unattach and cleanup old player (rename, remove, etc) */
3455 if (TRUE) {
3456 char name[MAX_LEN_NAME];
3457
3458 if (pplayer) {
3459 /* if pconn->playing is removed, we'll lose pplayer */
3460 sz_strlcpy(name, player_name(pplayer));
3461 }
3462
3464
3465 if (pplayer) {
3466 /* find pplayer again, the pointer might have been changed */
3467 pplayer = player_by_name(name);
3468 }
3469 }
3470
3471 /* attach pconn to new player as an observer or as global observer */
3472 if ((res = connection_attach(pconn, pplayer, TRUE))) {
3473 if (pplayer) {
3474 cmd_reply(CMD_OBSERVE, caller, C_OK, _("%s now observes %s"),
3475 pconn->username,
3476 player_name(pplayer));
3477 } else {
3478 cmd_reply(CMD_OBSERVE, caller, C_OK, _("%s now observes"),
3479 pconn->username);
3480 }
3481 }
3482
3483 end:;
3484 /* free our args */
3485 for (i = 0; i < ntokens; i++) {
3486 free(arg[i]);
3487 }
3488 return res;
3489}
3490
3491/**********************************************************************/
3500static bool take_command(struct connection *caller, char *str, bool check)
3501{
3502 int i = 0, ntokens = 0;
3503 char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
3504 bool is_newgame = !game_was_started();
3506 struct connection *pconn = caller;
3507 struct player *pplayer = NULL;
3508 bool res = FALSE;
3509
3510 /******** PART I: fill pconn and pplayer ********/
3511
3512 sz_strlcpy(buf, str);
3514
3515 /* check syntax */
3516 if (!caller && ntokens != 2) {
3517 cmd_reply(CMD_TAKE, caller, C_SYNTAX, _("Usage:\n%s"),
3519 goto end;
3520 }
3521
3522 if (caller && caller->access_level != ALLOW_HACK && ntokens != 1) {
3523 cmd_reply(CMD_TAKE, caller, C_SYNTAX,
3524 _("Only the player name form is allowed."));
3525 goto end;
3526 }
3527
3528 if (ntokens == 0) {
3529 cmd_reply(CMD_TAKE, caller, C_SYNTAX, _("Usage:\n%s"),
3531 goto end;
3532 }
3533
3534 if (ntokens == 2) {
3535 if (!(pconn = conn_by_user_prefix(arg[i], &match_result))) {
3537 goto end;
3538 }
3539 i++; /* found a conn, now reference the second argument */
3540 }
3541
3542 if (strcmp(arg[i], "-") == 0) {
3543 if (!is_newgame) {
3544 cmd_reply(CMD_TAKE, caller, C_FAIL,
3545 _("You cannot issue \"/take -\" when "
3546 "the game has already started."));
3547 goto end;
3548 }
3549
3550 /* Find first uncontrolled player. This will return NULL if there is
3551 * no free players at the moment. Later call to
3552 * connection_attach() will create new player for such NULL
3553 * cases. */
3554 pplayer = find_uncontrolled_player();
3555 if (pplayer) {
3556 /* Make it human! */
3557 set_as_human(pplayer);
3558 }
3559 } else if (!(pplayer = player_by_name_prefix(arg[i], &match_result))) {
3561 goto end;
3562 }
3563
3564 /******** PART II: do the attaching ********/
3565
3566 /* Take not possible if the player is involved in a delegation (either
3567 * it's being controlled, or it's been put aside by the delegate). */
3568 if (player_delegation_active(pplayer)) {
3569 cmd_reply(CMD_TAKE, caller, C_FAIL, _("A delegation is active for player "
3570 "'%s'. /take not possible."),
3571 player_name(pplayer));
3572 goto end;
3573 }
3574
3575 /* check allowtake for permission */
3576 if (!is_allowed_to_take(caller, pconn, pplayer, FALSE, msg, sizeof(msg))) {
3577 cmd_reply(CMD_TAKE, caller, C_FAIL, "%s", msg);
3578 goto end;
3579 }
3580
3581 /* taking your own player makes no sense. */
3582 if ((NULL != pplayer && !pconn->observer && pplayer == pconn->playing)
3583 || (NULL == pplayer && !pconn->observer && NULL != pconn->playing)) {
3584 cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s already controls %s."),
3585 pconn->username,
3586 player_name(pconn->playing));
3587 goto end;
3588 }
3589
3590 /* Make sure there is free player slot if there is need to
3591 * create new player. This is necessary for previously
3592 * detached connections only. Others can reuse the slot
3593 * they first release. */
3594 if (!pplayer && !pconn->playing
3596 || normal_player_count() >= server.playable_nations)) {
3597 cmd_reply(CMD_TAKE, caller, C_FAIL,
3598 _("There is no free player slot for %s."),
3599 pconn->username);
3600 goto end;
3601 }
3603
3604 res = TRUE;
3605 if (check) {
3606 goto end;
3607 }
3608
3609 /* If the player is controlled by another user, forcibly detach
3610 * the user. */
3611 if (pplayer && pplayer->is_connected) {
3612 if (NULL == caller) {
3614 _("Reassigned nation to %s by server console."),
3615 pconn->username);
3616 } else {
3618 _("Reassigned nation to %s by %s."),
3619 pconn->username,
3620 caller->username);
3621 }
3622
3623 /* We are reassigning this nation, so we need to detach the current
3624 * user to set a new one. */
3626 if (!aconn->observer) {
3628 }
3630 }
3631
3632 /* if the connection is already attached to another player,
3633 * unattach and cleanup old player (rename, remove, etc)
3634 * We may have been observing the player we now want to take */
3635 if (NULL != pconn->playing || pconn->observer) {
3636 char name[MAX_LEN_NAME];
3637
3638 if (pplayer) {
3639 /* if pconn->playing is removed, we'll lose pplayer */
3640 sz_strlcpy(name, player_name(pplayer));
3641 }
3642
3644
3645 if (pplayer) {
3646 /* find pplayer again; the pointer might have been changed */
3647 pplayer = player_by_name(name);
3648 }
3649 }
3650
3651 /* Now attach to new player */
3652 if ((res = connection_attach(pconn, pplayer, FALSE))) {
3653 /* Successfully attached */
3654 pplayer = pconn->playing; /* In case pplayer was NULL. */
3655
3656 /* inform about the status before changes */
3657 cmd_reply(CMD_TAKE, caller, C_OK, _("%s now controls %s (%s, %s)."),
3658 pconn->username,
3659 player_name(pplayer),
3660 is_barbarian(pplayer)
3661 ? _("Barbarian")
3662 : is_ai(pplayer)
3663 ? _("AI")
3664 : _("Human"),
3665 pplayer->is_alive
3666 ? _("Alive")
3667 : _("Dead"));
3668 } else {
3669 cmd_reply(CMD_TAKE, caller, C_FAIL,
3670 _("%s failed to attach to any player."),
3671 pconn->username);
3672 }
3673
3674 end:;
3675 /* free our args */
3676 for (i = 0; i < ntokens; i++) {
3677 free(arg[i]);
3678 }
3679 return res;
3680}
3681
3682/**********************************************************************/
3689static bool detach_command(struct connection *caller, char *str, bool check)
3690{
3691 int i = 0, ntokens = 0;
3692 char buf[MAX_LEN_CONSOLE_LINE], *arg[1];
3694 struct connection *pconn = NULL;
3695 struct player *pplayer = NULL;
3696 bool res = FALSE;
3697
3698 sz_strlcpy(buf, str);
3700
3701 if (!caller && ntokens == 0) {
3702 cmd_reply(CMD_DETACH, caller, C_SYNTAX, _("Usage:\n%s"),
3704 goto end;
3705 }
3706
3707 /* match the connection if the argument was given */
3708 if (ntokens == 1
3709 && !(pconn = conn_by_user_prefix(arg[0], &match_result))) {
3711 goto end;
3712 }
3713
3714 /* if no argument is given, the caller wants to detach themself */
3715 if (!pconn) {
3716 pconn = caller;
3717 }
3718
3719 /* if pconn and caller are not the same, only continue
3720 * if we're console, or we have ALLOW_HACK */
3721 if (pconn != caller && caller && caller->access_level != ALLOW_HACK) {
3722 cmd_reply(CMD_DETACH, caller, C_FAIL,
3723 _("You can not detach other users."));
3724 goto end;
3725 }
3726
3727 pplayer = pconn->playing;
3728
3729 /* must have someone to detach from... */
3730 if (!pplayer && !pconn->observer) {
3731 cmd_reply(CMD_DETACH, caller, C_FAIL,
3732 _("%s is not attached to any player."), pconn->username);
3733 goto end;
3734 }
3735
3736 res = TRUE;
3737 if (check) {
3738 goto end;
3739 }
3740
3741 if (pplayer) {
3742 cmd_reply(CMD_DETACH, caller, C_OK, _("%s detaching from %s"),
3743 pconn->username, player_name(pplayer));
3744 } else {
3745 cmd_reply(CMD_DETACH, caller, C_OK, _("%s no longer observing."),
3746 pconn->username);
3747 }
3748
3749 /* Actually do the detaching. */
3751
3752 /* The user explicitly wanted to detach, so if a player is marked for
3753 * them, reset its username. */
3755 if (!fc_strncmp(aplayer->username, pconn->username, MAX_LEN_NAME)) {
3756 sz_strlcpy(aplayer->username, _(ANON_USER_NAME));
3757 aplayer->unassigned_user = TRUE;
3759 }
3761
3763
3764 end:
3766
3767 /* free our args */
3768 for (i = 0; i < ntokens; i++) {
3769 free(arg[i]);
3770 }
3771 return res;
3772}
3773
3774/**********************************************************************/
3795bool load_command(struct connection *caller, const char *filename, bool check,
3796 bool cmdline_load)
3797{
3798 struct timer *loadtimer, *uloadtimer;
3799 struct section_file *file;
3800 char arg[MAX_LEN_PATH];
3802
3803 if (!filename || filename[0] == '\0') {
3804 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Usage:\n%s"),
3806 return FALSE;
3807 }
3808 if (S_S_INITIAL != server_state()) {
3809 cmd_reply(CMD_LOAD, caller, C_FAIL,
3810 _("Cannot load a game while another is running."));
3811 return FALSE;
3812 }
3813 if (!is_safe_filename(filename) && is_restricted(caller)) {
3814 cmd_reply(CMD_LOAD, caller, C_FAIL,
3815 _("Name \"%s\" disallowed for security reasons."),
3816 filename);
3817 return FALSE;
3818 }
3819
3820 {
3821 /* It is a normal savegame or maybe a scenario */
3822 char testfile[MAX_LEN_PATH];
3823 const struct strvec *paths[] = {
3825 };
3826 const char *exts[] = {
3827 "sav", "gz", "bz2", "xz", "sav.gz", "sav.bz2", "sav.xz", "sav.zst", NULL
3828 };
3829 const char **ext, *found = NULL;
3830 const struct strvec **path;
3831
3832 if (cmdline_load) {
3833 /* Allow plain names being loaded with '--file' option, but not otherwise
3834 * (no loading of arbitrary files by unauthorized users)
3835 * Iterate through ALL paths to check for file with plain name before
3836 * looking any path with an extension, i.e., prefer plain name file
3837 * in later directory over file with extension in name in earlier
3838 * directory. */
3839 for (path = paths; !found && *path; path++) {
3840 found = fileinfoname(*path, filename);
3841 if (found != NULL) {
3842 sz_strlcpy(arg, found);
3843 }
3844 }
3845 }
3846
3847 for (path = paths; !found && *path; path++) {
3848 for (ext = exts; !found && *ext; ext++) {
3849 fc_snprintf(testfile, sizeof(testfile), "%s.%s", filename, *ext);
3850 found = fileinfoname(*path, testfile);
3851 if (found != NULL) {
3852 sz_strlcpy(arg, found);
3853 }
3854 }
3855 }
3856
3857 if (is_restricted(caller) && !found) {
3858 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Cannot find savegame or "
3859 "scenario with the name \"%s\"."), filename);
3860 return FALSE;
3861 }
3862
3863 if (!found) {
3864 sz_strlcpy(arg, filename);
3865 }
3866 }
3867
3868 /* attempt to parse the file */
3869
3870 if (!(file = secfile_load(arg, FALSE))) {
3871 log_error("Error loading savefile '%s': %s", arg, secfile_error());
3872 cmd_reply(CMD_LOAD, caller, C_FAIL, _("Could not load savefile: %s"),
3873 arg);
3875 return FALSE;
3876 }
3877
3878 if (check) {
3879 return TRUE;
3880 }
3881
3882 /* Detach current players, before we blow them away. */
3885 if (pconn->playing != NULL) {
3887 } else if (pconn->observer) {
3890 }
3892
3894
3895 /* Now free all game data. */
3897
3898 /* Keep old ruleset value. Scenario file will either use the old value,
3899 * or to initialize new value itself. */
3901
3902 loadtimer = timer_new(TIMER_CPU, TIMER_ACTIVE, "load cpu");
3906
3908
3909 savegame_load(file);
3911 secfile_destroy(file);
3912
3913 log_verbose("Load time: %g seconds (%g apparent)",
3917
3918 sanity_check();
3919
3920 log_verbose("load_command() does send_rulesets()");
3928
3929 /* Send information about the new players. */
3932
3933 /* Everything seemed to load ok; spread the good news. */
3935
3936 /* Attach connections to players. Currently, this applies only
3937 * to connections that have the same username as a player. */
3939 players_iterate(pplayer) {
3940 if (strcmp(pconn->username, pplayer->username) == 0) {
3941 connection_attach(pconn, pplayer, FALSE);
3942 break;
3943 }
3946
3947 /* Reattach global observers. */
3949 if (NULL == pconn->playing) {
3950 /* May have been assigned to a player before. */
3952 }
3955
3957
3959 players_iterate(pplayer) {
3961
3963 pack.gained = achievement_player_has(pach, pplayer);
3964 pack.first = (pach->first == pplayer);
3965
3966 lsend_packet_achievement_info(pplayer->connections, &pack);
3969
3970 return TRUE;
3971}
3972
3973/**********************************************************************/
3982bool set_rulesetdir(struct connection *caller, const char *str, bool check,
3983 int read_recursion)
3984{
3985 char filename[512];
3986 const char *pfilename;
3987
3988 if (NULL == str || '\0' == str[0]) {
3990 _("You must provide a ruleset name. Use \"/show ruleset\" to "
3991 "see what is the current ruleset."));
3992 return FALSE;
3993 }
3994
3995 if (srvarg.ruleset != NULL && is_restricted(caller)) {
3997 _("Changing ruleset not allowed. It was locked from the commandline."));
3998
3999 return FALSE;
4000 }
4001
4002 if (game_was_started() || !map_is_empty()) {
4004 _("This setting can't be modified after the game has started."));
4006 && !game_was_started()) {
4008 /* TRANS: scenario name */
4009 _("The ruleset of \"%s\" can be changed by switching to a"
4010 " compatible ruleset before loading it."),
4012 }
4013 return FALSE;
4014 }
4015
4016 if (strcmp(str, game.server.rulesetdir) == 0) {
4018 _("Ruleset directory is already \"%s\""), str);
4019 return FALSE;
4020 }
4021
4022 if (is_restricted(caller)
4023 && (!is_safe_filename(str) || strchr(str, '.'))) {
4025 _("Name \"%s\" disallowed for security reasons."),
4026 str);
4027 return FALSE;
4028 }
4029
4030 fc_snprintf(filename, sizeof(filename), "%s", str);
4031 pfilename = fileinfoname(get_data_dirs(), filename);
4032 if (!pfilename) {
4034 _("Ruleset directory \"%s\" not found"), str);
4035 return FALSE;
4036 }
4037
4038 if (!check) {
4039 bool success = TRUE;
4040 char old[512];
4041
4043 log_verbose("set_rulesetdir() does load_rulesets() with \"%s\"", str);
4045
4046 /* load the ruleset (and game settings defined in the ruleset) */
4048 if (!load_rulesets(old, NULL, FALSE, NULL, TRUE, FALSE, TRUE)) {
4049 success = FALSE;
4050
4051 /* While loading of the requested ruleset failed, we might
4052 * have changed ruleset from third one to default. Handle
4053 * rest of the ruleset changing accordingly. */
4054 }
4055
4056 if (game.est_connections) {
4057 /* Now that the rulesets are loaded we immediately send updates to any
4058 * connected clients. */
4060 }
4061 /* show ruleset summary and list changed values */
4064
4065 if (success) {
4066 cmd_reply(CMD_RULESETDIR, caller, C_OK,
4067 _("Ruleset directory set to \"%s\""), str);
4068 } else {
4070 _("Failed loading rulesets from directory \"%s\", using \"%s\""),
4072 }
4073
4074 return success;
4075 }
4076
4077 return TRUE;
4078}
4079
4080/**********************************************************************/
4083static bool ignore_command(struct connection *caller, char *str, bool check)
4084{
4085 char buf[128];
4086 struct conn_pattern *ppattern;
4087
4088 if (NULL == caller) {
4089 cmd_reply(CMD_IGNORE, caller, C_FAIL,
4090 _("That would be rather silly, since you are not a player."));
4091 return FALSE;
4092 }
4093
4095 if (NULL == ppattern) {
4096 cmd_reply(CMD_IGNORE, caller, C_SYNTAX,
4097 _("%s. Try /help ignore"), buf);
4098 return FALSE;
4099 }
4100
4101 if (check) {
4103 return TRUE;
4104 }
4105
4109 _("Added pattern %s as entry %d to your ignore list."),
4111
4112 return TRUE;
4113}
4114
4115/**********************************************************************/
4118static bool unignore_command(struct connection *caller,
4119 char *str, bool check)
4120{
4121 char buf[128], *c;
4122 int first, last, n;
4123
4124 if (!caller) {
4125 cmd_reply(CMD_IGNORE, caller, C_FAIL,
4126 _("That would be rather silly, since you are not a player."));
4127 return FALSE;
4128 }
4129
4130 sz_strlcpy(buf, str);
4132
4134 if (n == 0) {
4135 cmd_reply(CMD_UNIGNORE, caller, C_FAIL, _("Your ignore list is empty."));
4136 return FALSE;
4137 }
4138
4139 /* Parse the range. */
4140 if ('\0' == buf[0]) {
4142 _("Missing range. Try /help unignore."));
4143 return FALSE;
4144 } else if ((c = strchr(buf, '-'))) {
4145 *c++ = '\0';
4146 if ('\0' == buf[0]) {
4147 first = 1;
4148 } else if (!str_to_int(buf, &first)) {
4149 *--c = '-';
4151 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4152 return FALSE;
4153 }
4154 if ('\0' == *c) {
4155 last = n;
4156 } else if (!str_to_int(c, &last)) {
4157 *--c = '-';
4159 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4160 return FALSE;
4161 }
4162 } else {
4163 if (!str_to_int(buf, &first)) {
4165 _("\"%s\" is not a valid range. Try /help unignore."), buf);
4166 return FALSE;
4167 }
4168 last = first;
4169 }
4170
4171 if (!(1 <= first && first <= last && last <= n)) {
4172 if (first == last) {
4173 cmd_reply(CMD_UNIGNORE, caller, C_FAIL,
4174 _("Invalid entry number: %d."), first);
4175 } else {
4176 cmd_reply(CMD_UNIGNORE, caller, C_FAIL,
4177 _("Invalid range: %d to %d."), first, last);
4178 }
4179 return FALSE;
4180 }
4181
4182 if (check) {
4183 return TRUE;
4184 }
4185
4186 n = 1;
4188 if (first <= n) {
4191 _("Removed pattern %s (entry %d) from your ignore list."),
4192 buf, n);
4194 }
4195 n++;
4196 if (n > last) {
4197 break;
4198 }
4200
4201 return TRUE;
4202}
4203
4204/**********************************************************************/
4207static bool playercolor_command(struct connection *caller,
4208 char *str, bool check)
4209{
4211 struct player *pplayer;
4212 struct rgbcolor *prgbcolor = NULL;
4213 int ntokens = 0;
4214 char *token[2];
4215 bool ret = TRUE;
4216
4217 ntokens = get_tokens(str, token, 2, TOKEN_DELIMITERS);
4218
4219 if (ntokens != 2) {
4221 _("Two arguments needed. See '/help playercolor'."));
4222 ret = FALSE;
4223 goto cleanup;
4224 }
4225
4226 pplayer = player_by_name_prefix(token[0], &match_result);
4227
4228 if (!pplayer) {
4230 ret = FALSE;
4231 goto cleanup;
4232 }
4233
4234 {
4235 const char *reason;
4236 if (!player_color_changeable(pplayer, &reason)) {
4237 cmd_reply(CMD_PLAYERCOLOR, caller, C_FAIL, "%s", reason);
4238 ret = FALSE;
4239 goto cleanup;
4240 }
4241 }
4242
4243 if (0 == fc_strcasecmp(token[1], "reset")) {
4244 if (!game_was_started()) {
4245 prgbcolor = NULL;
4246 } else {
4248 _("Can only unset player color before game starts."));
4249 ret = FALSE;
4250 goto cleanup;
4251 }
4252 } else if (!rgbcolor_from_hex(&prgbcolor, token[1])) {
4254 _("Invalid player color definition. See '/help playercolor'."));
4255 ret = FALSE;
4256 goto cleanup;
4257 }
4258
4259 if (prgbcolor != NULL) {
4261 if (pother != pplayer && pother->rgb != NULL
4264 /* TRANS: "... [c0ffee] for Caesar ... to Hammurabi." */
4265 _("Warning: new color [%s] for %s is identical to %s."),
4268 }
4270 }
4271
4272 if (check) {
4273 goto cleanup;
4274 }
4275
4278 _("Color of player %s set to [%s]."), player_name(pplayer),
4279 player_color_ftstr(pplayer));
4280
4281 cleanup:
4282
4284 free_tokens(token, ntokens);
4285
4286 return ret;
4287}
4288
4289/**********************************************************************/
4292static bool playernation_command(struct connection *caller,
4293 char *str, bool check)
4294{
4296 struct player *pplayer;
4297 struct nation_type *pnation;
4298 struct nation_style *pstyle;
4299 bool is_male = FALSE;
4300 int ntokens = 0;
4301 char *token[5];
4302
4303 ntokens = get_tokens(str, token, 5, TOKEN_DELIMITERS);
4304
4305 if (ntokens == 0) {
4307 _("At least one argument needed. See '/help playernation'."));
4308 free_tokens(token, ntokens);
4309 return FALSE;
4310 }
4311
4312 if (game_was_started()) {
4314 _("Can only set player nation before game starts."));
4315 free_tokens(token, ntokens);
4316 return FALSE;
4317 }
4318
4319 pplayer = player_by_name_prefix(token[0], &match_result);
4320 if (!pplayer) {
4322 free_tokens(token, ntokens);
4323 return FALSE;
4324 }
4325
4326 if (ntokens == 1) {
4327 if (!check) {
4329
4331 _("Nation of player %s reset."), player_name(pplayer));
4333 }
4334 } else {
4335 pnation = nation_by_rule_name(token[1]);
4336 if (pnation == NO_NATION_SELECTED) {
4338 _("Unrecognized nation: %s."), token[1]);
4339 free_tokens(token, ntokens);
4340 return FALSE;
4341 }
4342
4343 if (!client_can_pick_nation(pnation)) {
4345 _("%s nation is not available for user selection."),
4346 token[1]);
4347 free_tokens(token, ntokens);
4348 return FALSE;
4349 }
4350
4351 if (pnation->player && pnation->player != pplayer) {
4353 _("%s nation is already in use."), token[1]);
4354 free_tokens(token, ntokens);
4355 return FALSE;
4356 }
4357
4358 if (ntokens < 3) {
4360 /* TRANS: Nation resetting form of /playernation does not require sex */
4361 _("Leader sex must be given when setting nation."));
4362 free_tokens(token, ntokens);
4363 return FALSE;
4364 }
4365
4366 if (!strcmp(token[2], "0")) {
4367 is_male = FALSE;
4368 } else if (!strcmp(token[2], "1")) {
4369 is_male = TRUE;
4370 } else {
4372 _("Unrecognized gender: %s, expecting 1 or 0."), token[2]);
4373 free_tokens(token, ntokens);
4374 return FALSE;
4375 }
4376
4377 if (ntokens > 4) {
4378 pstyle = style_by_rule_name(token[4]);
4379 if (!pstyle) {
4381 _("Unrecognized style: %s."), token[4]);
4382 free_tokens(token, ntokens);
4383 return FALSE;
4384 }
4385 } else {
4386 pstyle = style_of_nation(pnation);
4387 }
4388
4389 if (!check) {
4390 char error_buf[256];
4391
4392 player_set_nation(pplayer, pnation);
4393 pplayer->style = pstyle;
4394 pplayer->is_male = is_male;
4395
4396 if (ntokens > 3) {
4397 if (!server_player_set_name_full(caller, pplayer, pnation, token[3],
4398 error_buf, sizeof(error_buf))) {
4400 }
4401 } else {
4402 server_player_set_name(pplayer, token[0]);
4403 }
4405 _("Nation of player %s set to [%s]."), player_name(pplayer),
4406 nation_rule_name(pnation));
4408 }
4409 }
4410
4411 free_tokens(token, ntokens);
4412
4413 return TRUE;
4414}
4415
4416/**************************************************************************
4417 Handle quit command
4418**************************************************************************/
4419static bool quit_game(struct connection *caller, bool check)
4420{
4421 if (!check) {
4422 cmd_reply(CMD_QUIT, caller, C_OK, _("Goodbye."));
4423 server_quit();
4424 }
4425
4426 return TRUE;
4427}
4428
4429/**********************************************************************/
4433bool handle_stdin_input(struct connection *caller, char *str)
4434{
4435 return handle_stdin_input_real(caller, str, FALSE, 0);
4436}
4437
4438/**********************************************************************/
4441bool handle_stdin_input_free(struct connection *caller, char *str)
4442{
4443 bool ret = handle_stdin_input_real(caller, str, FALSE, 0);
4444
4445 /* Since handle_stdin_input_real() returned,
4446 * we can be sure this was not freed in atexit(). */
4447 free(str);
4448
4449 return ret;
4450}
4451
4452/**********************************************************************/
4460static bool handle_stdin_input_real(struct connection *caller, char *str,
4461 bool check, int read_recursion)
4462{
4465 char *cptr_s, *cptr_d;
4466 enum command_id cmd;
4467 enum cmdlevel level;
4468
4469 /* Remove leading and trailing spaces, and server command prefix. */
4471 if ('\0' == *cptr_s || '#' == *cptr_s) {
4472 /* This appear to be a comment or blank line. */
4473 return FALSE;
4474 }
4475
4476 if (SERVER_COMMAND_PREFIX == *cptr_s) {
4477 /* Commands may be prefixed with SERVER_COMMAND_PREFIX, even when
4478 * given on the server command line. */
4479 cptr_s++;
4481 if ('\0' == *cptr_s) {
4482 /* This appear to be a blank line. */
4483 return FALSE;
4484 }
4485 }
4487
4488 /* notify to the server console */
4489 if (!check && caller) {
4490 con_write(C_COMMENT, "%s: '%s'", caller->username, str);
4491 }
4492
4493 /* if the caller may not use any commands at all, don't waste any time */
4494 if (may_use_nothing(caller)) {
4495 cmd_reply(CMD_HELP, caller, C_FAIL,
4496 _("Sorry, you are not allowed to use server commands."));
4497 return FALSE;
4498 }
4499
4500 /* copy the full command, in case we need it for voting purposes. */
4502
4503 /*
4504 * cptr_s points now to the beginning of the real command. It has
4505 * skipped leading whitespace, the SERVER_COMMAND_PREFIX and any
4506 * other non-alphanumeric characters.
4507 */
4508 for (cptr_d = command; *cptr_s != '\0' && fc_isalnum(*cptr_s)
4509 && cptr_d < command + sizeof(command) - 1; cptr_s++, cptr_d++) {
4510 *cptr_d = *cptr_s;
4511 }
4512 *cptr_d = '\0';
4513
4514 /* cptr_s now contains the arguments. */
4516
4517 cmd = command_named(command, FALSE);
4518 if (cmd == CMD_AMBIGUOUS) {
4519 cmd = command_named(command, TRUE);
4520 cmd_reply(cmd, caller, C_SYNTAX,
4521 _("Warning: '%s' interpreted as '%s', but it is ambiguous."
4522 " Try '%shelp'."),
4523 command, command_name_by_number(cmd), caller?"/":"");
4524 } else if (cmd == CMD_UNRECOGNIZED) {
4525 cmd_reply(cmd, caller, C_SYNTAX, _("Unknown command '%s%s'. "
4526 " Try '%shelp'."),
4527 caller ? "/" : "", command, caller ? "/" : "");
4528 return FALSE;
4529 }
4530
4532
4533 if (conn_can_vote(caller, NULL) && level == ALLOW_CTRL
4534 && conn_get_access(caller) == ALLOW_BASIC && !check
4535 && !vote_would_pass_immediately(caller, cmd)) {
4536 struct vote *vote;
4537 bool caller_had_vote = (NULL != get_vote_by_caller(caller));
4538
4539 /* Check if the vote command would succeed. If we already have a vote
4540 * going, cancel it in favour of the new vote command. You can only
4541 * have one vote at a time. This is done by vote_new(). */
4543 read_recursion + 1)
4544 && (vote = vote_new(caller, arg, cmd))) {
4546 const struct player *teamplr;
4547 const char *what;
4548 struct ft_color color;
4549
4550 if (caller_had_vote) {
4551 cmd_reply(CMD_VOTE, caller, C_COMMENT,
4552 /* TRANS: "vote" as a process */
4553 _("Your new vote canceled your previous vote."));
4554 }
4555
4557
4558 if (vote_is_team_only(vote)) {
4559 /* TRANS: "vote" as a process */
4560 what = _("New teamvote");
4561 teamplr = conn_get_player(caller);
4563 } else {
4564 /* TRANS: "vote" as a process */
4565 what = _("New vote");
4566 teamplr = NULL;
4568 }
4570 /* TRANS: "[New vote|New teamvote] (number 3)
4571 * by fred: proposed change" */
4572 _("%s (number %d) by %s: %s"), what,
4573 vote->vote_no, caller->username, votedesc);
4574
4575 /* Vote on your own suggestion. */
4576 connection_vote(caller, vote, VOTE_YES);
4577 return TRUE;
4578
4579 } else {
4580 cmd_reply(CMD_VOTE, caller, C_FAIL,
4581 /* TRANS: "vote" as a process */
4582 _("Your new vote (\"%s\") was not "
4583 "legal or was not recognized."), full_command);
4584 return FALSE;
4585 }
4586 }
4587
4588 if (caller
4589 && !((check || vote_would_pass_immediately(caller, cmd))
4590 && conn_get_access(caller) >= ALLOW_BASIC
4591 && level == ALLOW_CTRL)
4592 && conn_get_access(caller) < level) {
4593 cmd_reply(cmd, caller, C_FAIL,
4594 _("You are not allowed to use this command."));
4595 return FALSE;
4596 }
4597
4598 if (!check) {
4599 struct conn_list *echo_list = NULL;
4601
4602 switch (command_echo(command_by_number(cmd))) {
4603 case CMD_ECHO_NONE:
4604 break;
4605 case CMD_ECHO_ADMINS:
4608 if (NULL == echo_list) {
4611 }
4613 }
4615 break;
4616 case CMD_ECHO_ALL:
4618 break;
4619 }
4620
4621 if (NULL != echo_list) {
4622 if (caller) {
4624 "%s: '%s %s'", caller->username, command, arg);
4625 } else {
4627 "%s: '%s %s'", _("(server prompt)"), command, arg);
4628 }
4629 if (echo_list_allocated) {
4631 }
4632 }
4633 }
4634
4635 switch (cmd) {
4636 case CMD_REMOVE:
4637 return remove_player_command(caller, arg, check);
4638 case CMD_SAVE:
4639 return save_command(caller, arg, check);
4640 case CMD_SCENSAVE:
4641 return scensave_command(caller, arg, check);
4642 case CMD_LOAD:
4643 return load_command(caller, arg, check, FALSE);
4644 case CMD_METAPATCHES:
4645 return metapatches_command(caller, arg, check);
4646 case CMD_METAMESSAGE:
4647 return metamessage_command(caller, arg, check);
4648 case CMD_METACONN:
4649 return metaconnection_command(caller, arg, check);
4650 case CMD_METASERVER:
4651 return metaserver_command(caller, arg, check);
4652 case CMD_HELP:
4653 return show_help(caller, arg);
4654 case CMD_SRVID:
4655 return show_serverid(caller, arg);
4656 case CMD_LIST:
4657 return show_list(caller, arg);
4658 case CMD_AITOGGLE:
4659 return toggle_ai_command(caller, arg, check);
4660 case CMD_TAKE:
4661 return take_command(caller, arg, check);
4662 case CMD_OBSERVE:
4663 return observe_command(caller, arg, check);
4664 case CMD_DETACH:
4665 return detach_command(caller, arg, check);
4666 case CMD_CREATE:
4667 return create_command(caller, arg, check);
4668 case CMD_AWAY:
4669 return away_command(caller, check);
4670 case CMD_RESTRICTED:
4671 case CMD_NOVICE:
4672 case CMD_EASY:
4673 case CMD_NORMAL:
4674 case CMD_HARD:
4675 case CMD_CHEATING:
4676#ifdef FREECIV_DEBUG
4677 case CMD_EXPERIMENTAL:
4678#endif
4679 return set_ai_level_named(caller, arg, command_name_by_number(cmd), check);
4680 case CMD_QUIT:
4681 return quit_game(caller, check);
4682 case CMD_CUT:
4683 return cut_client_connection(caller, arg, check);
4684 case CMD_SHOW:
4685 return show_command(caller, arg, check);
4686 case CMD_EXPLAIN:
4687 return explain_option(caller, arg, check);
4688 case CMD_DEBUG:
4689 return debug_command(caller, arg, check);
4690 case CMD_SET:
4691 return set_command(caller, arg, check);
4692 case CMD_TEAM:
4693 return team_command(caller, arg, check);
4694 case CMD_RULESETDIR:
4695 return set_rulesetdir(caller, arg, check, read_recursion);
4696 case CMD_WALL:
4697 return wall(arg, check);
4698 case CMD_CONNECTMSG:
4699 return connectmsg_command(caller, arg, check);
4700 case CMD_VOTE:
4701 return vote_command(caller, arg, check);
4702 case CMD_CANCELVOTE:
4703 return cancelvote_command(caller, arg, check);
4704 case CMD_READ_SCRIPT:
4705 return read_command(caller, arg, check, read_recursion);
4706 case CMD_WRITE_SCRIPT:
4707 return write_command(caller, arg, check);
4708 case CMD_RESET:
4709 return reset_command(caller, arg, check, read_recursion);
4710 case CMD_DEFAULT:
4711 return default_command(caller, arg, check);
4712 case CMD_LUA:
4713 return lua_command(caller, arg, check, read_recursion);
4714 case CMD_KICK:
4715 return kick_command(caller, arg, check);
4716 case CMD_DELEGATE:
4717 return delegate_command(caller, arg, check);
4718 case CMD_AICMD:
4719 return aicmd_command(caller, arg, check);
4720 case CMD_FCDB:
4721 return fcdb_command(caller, arg, check);
4722 case CMD_MAPIMG:
4723 return mapimg_command(caller, arg, check);
4724 case CMD_LOCK:
4725 return lock_command(caller, arg, check);
4726 case CMD_UNLOCK:
4727 return unlock_command(caller, arg, check);
4728 case CMD_RFCSTYLE: /* see console.h for an explanation */
4729 if (!check) {
4731 }
4732 return TRUE;
4733 case CMD_CMDLEVEL:
4734 return cmdlevel_command(caller, arg, check);
4735 case CMD_FIRSTLEVEL:
4736 return firstlevel_command(caller, check);
4737 case CMD_TIMEOUT:
4738 return timeout_command(caller, arg, check);
4739 case CMD_START_GAME:
4740 return start_command(caller, check, FALSE);
4741 case CMD_END_GAME:
4742 return end_command(caller, arg, check);
4743 case CMD_SURRENDER:
4744 return surrender_command(caller, arg, check);
4745 case CMD_IGNORE:
4746 return ignore_command(caller, arg, check);
4747 case CMD_UNIGNORE:
4748 return unignore_command(caller, arg, check);
4749 case CMD_PLAYERCOLOR:
4750 return playercolor_command(caller, arg, check);
4751 case CMD_PLAYERNATION:
4752 return playernation_command(caller, arg, check);
4753 case CMD_NUM:
4754 case CMD_UNRECOGNIZED:
4755 case CMD_AMBIGUOUS:
4756 break;
4757 }
4758 /* should NEVER happen! */
4759 log_error("Unknown command variant: %d.", cmd);
4760 return FALSE;
4761}
4762
4763/**********************************************************************/
4766static bool end_command(struct connection *caller, char *str, bool check)
4767{
4768 if (S_S_RUNNING == server_state()) {
4769 if (check) {
4770 return TRUE;
4771 }
4773 _("Game is over."));
4776 cmd_reply(CMD_END_GAME, caller, C_OK,
4777 _("Ending the game. The server will restart once all clients "
4778 "have disconnected."));
4779 return TRUE;
4780 } else {
4781 cmd_reply(CMD_END_GAME, caller, C_FAIL,
4782 _("Cannot end the game: no game running."));
4783 return FALSE;
4784 }
4785}
4786
4787/**********************************************************************/
4791static bool surrender_command(struct connection *caller, char *str, bool check)
4792{
4793 struct player *pplayer;
4794
4795 if (caller == NULL || !conn_controls_player(caller)) {
4797 _("You are not allowed to use this command."));
4798 return FALSE;
4799 }
4800
4801 if (S_S_RUNNING != server_state()) {
4802 cmd_reply(CMD_SURRENDER, caller, C_FAIL, _("You cannot surrender now."));
4803 return FALSE;
4804 }
4805
4806 pplayer = conn_get_player(caller);
4807 if (player_status_check(pplayer, PSTATUS_SURRENDER)) {
4809 _("You have already conceded the game."));
4810 return FALSE;
4811 }
4812
4813 if (check) {
4814 return TRUE;
4815 }
4816
4818 _("%s has conceded the game and can no longer win."),
4819 player_name(pplayer));
4821 return TRUE;
4822}
4823
4824/* Define the possible arguments to the reset command */
4825#define SPECENUM_NAME reset_args
4826#define SPECENUM_VALUE0 RESET_GAME
4827#define SPECENUM_VALUE0NAME "game"
4828#define SPECENUM_VALUE1 RESET_RULESET
4829#define SPECENUM_VALUE1NAME "ruleset"
4830#define SPECENUM_VALUE2 RESET_SCRIPT
4831#define SPECENUM_VALUE2NAME "script"
4832#define SPECENUM_VALUE3 RESET_DEFAULT
4833#define SPECENUM_VALUE3NAME "default"
4834#include "specenum_gen.h"
4835
4836/**********************************************************************/
4839static const char *reset_accessor(int i)
4840{
4841 i = CLIP(0, i, reset_args_max());
4842 return reset_args_name((enum reset_args) i);
4843}
4844
4845/**********************************************************************/
4849static bool reset_command(struct connection *caller, char *arg, bool check,
4850 int read_recursion)
4851{
4852 enum m_pre_result result;
4853 int ind;
4854
4855 /* match the argument */
4856 result = match_prefix(reset_accessor, reset_args_max() + 1, 0,
4857 fc_strncasecmp, NULL, arg, &ind);
4858
4859 switch (result) {
4860 case M_PRE_EXACT:
4861 case M_PRE_ONLY:
4862 /* we have a match */
4863 break;
4864 case M_PRE_AMBIGUOUS:
4865 case M_PRE_EMPTY:
4866 /* use 'ruleset' [1] if the game was not started; else use 'game' [2] */
4868 cmd_reply(CMD_RESET, caller, C_WARNING,
4869 _("Guessing argument 'ruleset'."));
4871 } else {
4872 cmd_reply(CMD_RESET, caller, C_WARNING,
4873 _("Guessing argument 'game'."));
4874 ind = RESET_GAME;
4875 }
4876 break;
4877 case M_PRE_LONG:
4878 case M_PRE_FAIL:
4879 case M_PRE_LAST:
4880 cmd_reply(CMD_RESET, caller, C_FAIL,
4881 _("The valid arguments are: 'game', 'ruleset', 'script' "
4882 "or 'default'."));
4883 return FALSE;
4884 break;
4885 }
4886
4887 if (check) {
4888 return TRUE;
4889 }
4890
4891 switch (ind) {
4892 case RESET_GAME:
4893 if (!game.info.is_new_game) {
4894 if (settings_game_reset()) {
4895 cmd_reply(CMD_RESET, caller, C_OK,
4896 _("Reset all settings to the values at the game start."));
4897 } else {
4898 cmd_reply(CMD_RESET, caller, C_FAIL,
4899 _("No saved settings from the game start available."));
4900 return FALSE;
4901 }
4902 } else {
4903 cmd_reply(CMD_RESET, caller, C_FAIL, _("No game started..."));
4904 return FALSE;
4905 }
4906 break;
4907
4908 case RESET_RULESET:
4909 /* Restore game settings saved in game.ruleset. */
4911 cmd_reply(CMD_RESET, caller, C_OK,
4912 _("Reset all settings to ruleset values."));
4913 } else {
4914 cmd_reply(CMD_RESET, caller, C_FAIL,
4915 _("Failed to reset settings to ruleset values."));
4916 }
4917 break;
4918
4919 case RESET_SCRIPT:
4920 cmd_reply(CMD_RESET, caller, C_OK,
4921 _("Reset all settings and rereading the server start "
4922 "script."));
4924 /* Load initial script */
4927 read_recursion + 1)) {
4928 if (NULL != caller) {
4929 cmd_reply(CMD_RESET, caller, C_FAIL,
4930 _("Could not read script file '%s'."),
4932 }
4933 return FALSE;
4934 }
4935 break;
4936
4937 case RESET_DEFAULT:
4938 cmd_reply(CMD_RESET, caller, C_OK,
4939 _("Reset all settings to default values."));
4941 break;
4942 }
4943
4945 cmd_reply(CMD_RESET, caller, C_OK, _("Settings re-initialized."));
4946
4947 /* show ruleset summary and list changed values */
4949
4950 return TRUE;
4951}
4952
4953/**********************************************************************/
4956static bool default_command(struct connection *caller, char *arg, bool check)
4957{
4958 struct setting *pset;
4959 char reject_msg[256] = "";
4960
4961 pset = validate_setting_arg(CMD_DEFAULT, caller, arg);
4962
4963 if (!pset) {
4964 /* Reason already reported. */
4965 return FALSE;
4966 }
4967
4968 if (!setting_is_changeable(pset, caller, reject_msg, sizeof(reject_msg))) {
4969 cmd_reply(CMD_DEFAULT, caller, C_FAIL, "%s", reject_msg);
4970
4971 return FALSE;
4972 }
4973
4974 if (!check) {
4976 cmd_reply(CMD_DEFAULT, caller, C_OK,
4977 _("Option '%s' reset to default value, and will track any "
4978 "default changes."), arg);
4979 }
4980
4981 return TRUE;
4982}
4983
4984/* Define the possible arguments to the delegation command */
4985#define SPECENUM_NAME lua_args
4986#define SPECENUM_VALUE0 LUA_CMD
4987#define SPECENUM_VALUE0NAME "cmd"
4988#define SPECENUM_VALUE1 LUA_FILE
4989#define SPECENUM_VALUE1NAME "file"
4990#define SPECENUM_VALUE2 LUA_UNSAFE_CMD
4991#define SPECENUM_VALUE2NAME "unsafe-cmd"
4992#define SPECENUM_VALUE3 LUA_UNSAFE_FILE
4993#define SPECENUM_VALUE3NAME "unsafe-file"
4994#include "specenum_gen.h"
4995
4996/**********************************************************************/
4999static const char *lua_accessor(int i)
5000{
5001 i = CLIP(0, i, lua_args_max());
5002 return lua_args_name((enum lua_args) i);
5003}
5004
5005/**********************************************************************/
5008static bool lua_command(struct connection *caller, char *arg, bool check,
5009 int read_recursion)
5010{
5011 struct stat statbuf;
5012 const char extension[] = ".lua", *real_filename = NULL;
5013 char luafile[4096], tilde_filename[4096];
5014 char *tokens[1], *luaarg = NULL;
5015 int ntokens, ind;
5016 enum m_pre_result result;
5017 bool ret = FALSE;
5018
5020
5021 if (ntokens > 0) {
5022 /* match the argument */
5023 result = match_prefix(lua_accessor, lua_args_max() + 1, 0,
5024 fc_strncasecmp, NULL, tokens[0], &ind);
5025
5026 switch (result) {
5027 case M_PRE_EXACT:
5028 case M_PRE_ONLY:
5029 /* We have a match */
5030 luaarg = arg + strlen(lua_args_name(ind));
5032 break;
5033 case M_PRE_EMPTY:
5034 /* Nothing. */
5035 break;
5036 case M_PRE_AMBIGUOUS:
5037 case M_PRE_LONG:
5038 case M_PRE_FAIL:
5039 case M_PRE_LAST:
5040 /* Fall back to depreciated 'lua <script command>' syntax. */
5041 cmd_reply(CMD_LUA, caller, C_SYNTAX,
5042 _("Fall back to old syntax '%slua <script command>'."),
5043 caller ? "/" : "");
5044 ind = LUA_CMD;
5045 luaarg = arg;
5046 break;
5047 }
5048 }
5049
5050 if (luaarg == NULL) {
5051 cmd_reply(CMD_LUA, caller, C_FAIL,
5052 _("No lua command or lua script file. See '%shelp lua'."),
5053 caller ? "/" : "");
5054 ret = TRUE;
5055 goto cleanup;
5056 }
5057
5058 switch (ind) {
5059 case LUA_CMD:
5060 /* Nothing to check. */
5061 break;
5062 case LUA_UNSAFE_CMD:
5063 if (read_recursion > 0) {
5064 cmd_reply(CMD_LUA, caller, C_FAIL,
5065 _("Unsafe Lua code can only be run by explicit command."));
5066 ret = FALSE;
5067 goto cleanup;
5068 } else if (is_restricted(caller)) {
5069 cmd_reply(CMD_LUA, caller, C_FAIL,
5070 _("You aren't allowed to run unsafe Lua code."));
5071 ret = FALSE;
5072 goto cleanup;
5073 }
5074 break;
5075 case LUA_UNSAFE_FILE:
5076 if (read_recursion > 0) {
5077 cmd_reply(CMD_LUA, caller, C_FAIL,
5078 _("Unsafe Lua code can only be run by explicit command."));
5079 ret = FALSE;
5080 goto cleanup;
5081 } else if (is_restricted(caller)) {
5082 cmd_reply(CMD_LUA, caller, C_FAIL,
5083 _("You aren't allowed to run unsafe Lua code."));
5084 ret = FALSE;
5085 goto cleanup;
5086 }
5087
5089 case LUA_FILE:
5090 /* Abuse real_filename to find if we already have a .lua extension. */
5092 strlen(luaarg));
5093 if (strcmp(real_filename, extension) != 0) {
5094 fc_snprintf(luafile, sizeof(luafile), "%s%s", luaarg, extension);
5095 } else {
5097 }
5098
5099 if (is_restricted(caller)) {
5100 if (!is_safe_filename(luafile)) {
5101 cmd_reply(CMD_LUA, caller, C_FAIL,
5102 _("Freeciv script '%s' disallowed for security reasons."),
5103 luafile);
5104 ret = FALSE;
5105 goto cleanup;;
5106 }
5108 } else {
5110 }
5111
5113 if (!real_filename) {
5114 if (is_restricted(caller)) {
5115 cmd_reply(CMD_LUA, caller, C_FAIL,
5116 _("No Freeciv script found by the name '%s'."),
5118 ret = FALSE;
5119 goto cleanup;
5120 }
5121 /* File is outside data directories */
5123 }
5124 break;
5125 }
5126
5127 if (check) {
5128 ret = TRUE;
5129 goto cleanup;
5130 }
5131
5132 switch (ind) {
5133 case LUA_CMD:
5135 break;
5136 case LUA_UNSAFE_CMD:
5138 break;
5139 case LUA_FILE:
5140 cmd_reply(CMD_LUA, caller, C_COMMENT,
5141 _("Loading Freeciv script file '%s'."), real_filename);
5142
5144 && !fc_stat(real_filename, &statbuf)) {
5146 } else {
5147 cmd_reply(CMD_LUA, caller, C_FAIL,
5148 _("Cannot read Freeciv script '%s'."), real_filename);
5149 ret = FALSE;
5150 }
5151 break;
5152 case LUA_UNSAFE_FILE:
5153 cmd_reply(CMD_LUA, caller, C_COMMENT,
5154 _("Loading Freeciv script file '%s'."), real_filename);
5155
5157 && !fc_stat(real_filename, &statbuf)) {
5159 } else {
5160 cmd_reply(CMD_LUA, caller, C_FAIL,
5161 _("Cannot read Freeciv script '%s'."), real_filename);
5162 ret = FALSE;
5163 }
5164 break;
5165 }
5166
5167 cleanup:
5169 return ret;
5170}
5171
5172/* Define the possible arguments to the delegation command */
5173#define SPECENUM_NAME delegate_args
5174#define SPECENUM_VALUE0 DELEGATE_CANCEL
5175#define SPECENUM_VALUE0NAME "cancel"
5176#define SPECENUM_VALUE1 DELEGATE_RESTORE
5177#define SPECENUM_VALUE1NAME "restore"
5178#define SPECENUM_VALUE2 DELEGATE_SHOW
5179#define SPECENUM_VALUE2NAME "show"
5180#define SPECENUM_VALUE3 DELEGATE_TAKE
5181#define SPECENUM_VALUE3NAME "take"
5182#define SPECENUM_VALUE4 DELEGATE_TO
5183#define SPECENUM_VALUE4NAME "to"
5184#include "specenum_gen.h"
5185
5186/**********************************************************************/
5189static const char *delegate_accessor(int i)
5190{
5191 i = CLIP(0, i, delegate_args_max());
5192 return delegate_args_name((enum delegate_args) i);
5193}
5194
5195/**********************************************************************/
5198static bool delegate_command(struct connection *caller, char *arg,
5199 bool check)
5200{
5201 char *tokens[3];
5203 enum m_pre_result result;
5204 bool player_specified = FALSE; /* affects messages only */
5205 bool ret = FALSE;
5206 const char *username = NULL;
5207 struct player *dplayer = NULL;
5208
5209 if (!game_was_started()) {
5210 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Game not started - "
5211 "cannot delegate yet."));
5212 return FALSE;
5213 }
5214
5216
5217 if (ntokens > 0) {
5218 /* match the argument */
5220 fc_strncasecmp, NULL, tokens[0], &ind);
5221
5222 switch (result) {
5223 case M_PRE_EXACT:
5224 case M_PRE_ONLY:
5225 /* we have a match */
5226 break;
5227 case M_PRE_EMPTY:
5228 if (caller) {
5229 /* Use 'delegate show' as default. */
5231 }
5232 break;
5233 case M_PRE_AMBIGUOUS:
5234 case M_PRE_LONG:
5235 case M_PRE_FAIL:
5236 case M_PRE_LAST:
5238 break;
5239 }
5240 } else {
5241 if (caller) {
5242 /* Use 'delegate show' as default. */
5244 }
5245 }
5246
5248 char buf[256] = "";
5250
5254 const char *name = delegate_args_name(valid_args);
5255
5256 if (name != NULL) {
5257 cat_snprintf(buf, sizeof(buf), "'%s'", name);
5258 if (valid_args != delegate_args_max()) {
5259 cat_snprintf(buf, sizeof(buf), ", ");
5260 }
5261 }
5262 }
5263
5265 /* TRANS: do not translate the command 'delegate'. */
5266 _("Valid arguments for 'delegate' are: %s."), buf);
5267 ret = FALSE;
5268 goto cleanup;
5269 }
5270
5271 /* Get the data (player, username for delegation) and validate it. */
5272 switch (ind) {
5273 case DELEGATE_CANCEL:
5274 /* delegate cancel [player] */
5275 if (ntokens > 1) {
5276 if (!caller || conn_get_access(caller) >= ALLOW_ADMIN) {
5278 dplayer = player_by_name_prefix(tokens[1], &result);
5279 if (!dplayer) {
5280 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5281 ret = FALSE;
5282 goto cleanup;
5283 }
5284 } else {
5286 _("Command level '%s' or greater needed to modify "
5287 "others' delegations."), cmdlevel_name(ALLOW_ADMIN));
5288 ret = FALSE;
5289 goto cleanup;
5290 }
5291 } else {
5292 dplayer = conn_get_player(caller);
5293 if (!dplayer) {
5295 _("Please specify a player for whom delegation should "
5296 "be canceled."));
5297 ret = FALSE;
5298 goto cleanup;
5299 }
5300 }
5301 break;
5302 case DELEGATE_RESTORE:
5303 /* delegate restore */
5304 if (!caller) {
5305 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5306 _("You can't switch players from the console."));
5307 ret = FALSE;
5308 goto cleanup;
5309 }
5310 break;
5311 case DELEGATE_SHOW:
5312 /* delegate show [player] */
5313 if (ntokens > 1) {
5315 dplayer = player_by_name_prefix(tokens[1], &result);
5316 if (!dplayer) {
5317 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5318 ret = FALSE;
5319 goto cleanup;
5320 }
5321 } else {
5322 dplayer = conn_get_player(caller);
5323 if (!dplayer) {
5325 _("Please specify a player for whom the delegation should "
5326 "be shown."));
5327 ret = FALSE;
5328 goto cleanup;
5329 }
5330 }
5331 break;
5332 case DELEGATE_TAKE:
5333 /* delegate take <player> */
5334 if (!caller) {
5335 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5336 _("You can't switch players from the console."));
5337 ret = FALSE;
5338 goto cleanup;
5339 }
5340 if (ntokens > 1) {
5342 dplayer = player_by_name_prefix(tokens[1], &result);
5343 if (!dplayer) {
5344 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[1], result);
5345 ret = FALSE;
5346 goto cleanup;
5347 }
5348 } else {
5350 _("Please specify a player to take control of."));
5351 ret = FALSE;
5352 goto cleanup;
5353 }
5354 break;
5355 case DELEGATE_TO:
5356 break;
5357 }
5358 /* All checks done to this point will give pretty much the same result at
5359 * any time. Checks after this point are more likely to vary over time. */
5360 if (check) {
5361 ret = TRUE;
5362 goto cleanup;
5363 }
5364
5365 switch (ind) {
5366 case DELEGATE_TO:
5367 /* delegate to <username> [player] */
5368 if (ntokens > 1) {
5369 username = tokens[1];
5370 } else {
5372 _("Please specify a user to whom control is to be delegated."));
5373 ret = FALSE;
5374 break;
5375 }
5376 if (ntokens > 2) {
5378 dplayer = player_by_name_prefix(tokens[2], &result);
5379 if (!dplayer) {
5380 cmd_reply_no_such_player(CMD_DELEGATE, caller, tokens[2], result);
5381 ret = FALSE;
5382 break;
5383 }
5384#ifndef HAVE_FCDB
5385 if (caller && conn_get_access(caller) < ALLOW_ADMIN) {
5386#else
5387 if (caller && conn_get_access(caller) < ALLOW_ADMIN
5388 && !(srvarg.fcdb_enabled
5389 && script_fcdb_call("user_delegate_to", caller, dplayer,
5390 username, &ret) && ret)) {
5391#endif
5393 _("Command level '%s' or greater or special permission "
5394 "needed to modify others' delegations."),
5396 ret = FALSE;
5397 break;
5398 }
5399 } else {
5400 dplayer = conn_controls_player(caller) ? conn_get_player(caller) : NULL;
5401 if (!dplayer) {
5402 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5403 _("You do not control a player."));
5404 ret = FALSE;
5405 break;
5406 }
5407 }
5408
5409 /* Delegate control of player to another user. */
5412
5413 /* Forbid delegation of players already controlled by a delegate, and
5414 * those 'put aside' by a delegate.
5415 * For the former, if player is already under active delegate control,
5416 * we wouldn't handle the revocation that would be necessary if their
5417 * delegation changed; and the authority granted to delegates does not
5418 * include the ability to sub-delegate.
5419 * For the latter, allowing control of the 'put aside' player to be
5420 * delegated would break the invariant that whenever a user is connected,
5421 * they are attached to 'their' player. */
5424 /* Attempting to change a 'put aside' player. Must be admin
5425 * or console. */
5427 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5428 _("Can't delegate control of '%s' belonging to %s while "
5429 "they are controlling another player."),
5431 } else if (player_specified) {
5432 /* Admin or console attempting to change a controlled player. */
5433 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5434 _("Can't change delegation of '%s' while controlled by "
5435 "delegate %s."), player_name(dplayer), dplayer->username);
5436 } else {
5437 /* Caller must be the delegate. Give more specific message.
5438 * (We don't know if they thought they were delegating their
5439 * original or delegated player, but we don't allow either.) */
5440 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5441 _("You can't delegate control while you are controlling "
5442 "a delegated player yourself."));
5443 }
5444 ret = FALSE;
5445 break;
5446 }
5447
5448 /* Forbid delegation to player's original owner
5449 * (from above test we know that dplayer->username is the original now) */
5450 if (fc_strcasecmp(dplayer->username, username) == 0) {
5451 if (player_specified) {
5452 /* Probably admin or console. */
5453 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5454 /* TRANS: don't translate 'delegate cancel' */
5455 _("%s already owns '%s', so cannot also be delegate. "
5456 "Use '%sdelegate cancel' to cancel an existing "
5457 "delegation."),
5458 username, player_name(dplayer), caller?"/":"");
5459 } else {
5460 /* Player not specified on command line, so they must have been trying
5461 * to delegate control to themself. Give more specific message. */
5462 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5463 /* TRANS: don't translate '/delegate cancel' */
5464 _("You can't delegate control to yourself. "
5465 "Use '/delegate cancel' to cancel an existing "
5466 "delegation."));
5467 }
5468 ret = FALSE;
5469 break;
5470 }
5471
5472 /* FIXME: if control was already delegated to someone else, that
5473 * delegation is implicitly canceled. Perhaps we should tell someone. */
5474
5476 cmd_reply(CMD_DELEGATE, caller, C_OK,
5477 _("Control of player '%s' delegated to user %s."),
5479 ret = TRUE;
5480 break;
5481
5482 case DELEGATE_SHOW:
5483 /* Show delegations. */
5485
5487 /* No delegation set. */
5489 _("No delegation defined for '%s'."),
5491 } else {
5493 _("Control of player '%s' delegated to user %s."),
5495 }
5496 ret = TRUE;
5497 break;
5498
5499 case DELEGATE_CANCEL:
5501 /* No delegation set. */
5502 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5503 _("No delegation defined for '%s'."),
5505 ret = FALSE;
5506 break;
5507 }
5508
5510 /* Delegation is currently in use. Forcibly break connection. */
5511 struct connection *pdelegate;
5512 /* (Can only happen if admin/console issues this command, as owner
5513 * will end use by their mere presence.) */
5518 /* Should never happen. Generic failure message. */
5519 log_error("Failed to restore %s's connection as %s during "
5520 "'delegate cancel'.", pdelegate->username,
5521 delegate_player_str(pdelegate->server.delegation.playing,
5522 pdelegate->server.delegation.observer));
5523 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5524 ret = FALSE;
5525 break;
5526 }
5528 _("Your delegated control of player '%s' was canceled."),
5530 }
5531
5533 cmd_reply(CMD_DELEGATE, caller, C_OK, _("Delegation of '%s' canceled."),
5535 ret = TRUE;
5536 break;
5537
5538 case DELEGATE_TAKE:
5539 /* Try to take another player. */
5541 fc_assert_ret_val(caller, FALSE);
5542
5543 if (caller->server.delegation.status) {
5544 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5545 /* TRANS: don't translate '/delegate restore'. */
5546 _("You are already controlling a delegated player. "
5547 "Use '/delegate restore' to relinquish control of your "
5548 "current player first."));
5549 ret = FALSE;
5550 break;
5551 }
5552
5553 /* Don't allow 'put aside' players to be delegated; the invariant is
5554 * that while the owning user is connected to the server, they are
5555 * in sole control of 'their' player. */
5556 if (conn_controls_player(caller)
5558 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5559 /* TRANS: don't translate '/delegate cancel'. */
5560 _("Can't take player while you have delegated control "
5561 "yourself. Use '/delegate cancel' to cancel your own "
5562 "delegation first."));
5563 ret = FALSE;
5564 break;
5565 }
5566
5567 /* Taking your own player makes no sense. */
5568 if (conn_controls_player(caller)
5569 && dplayer == conn_get_player(caller)) {
5570 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("You already control '%s'."),
5571 player_name(conn_get_player(caller)));
5572 ret = FALSE;
5573 break;
5574 }
5575
5578 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5579 _("Control of player '%s' has not been delegated to you."),
5581 ret = FALSE;
5582 break;
5583 }
5584
5585 /* If the player is controlled by another user, fail. */
5586 if (dplayer->is_connected) {
5587 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5588 _("Another user already controls player '%s'."),
5590 ret = FALSE;
5591 break;
5592 }
5593
5594 if (!connection_delegate_take(caller, dplayer)) {
5595 /* Should never happen. Generic failure message. */
5596 log_error("%s failed to take control of '%s' during 'delegate take'.",
5597 caller->username, player_name(dplayer));
5598 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5599 ret = FALSE;
5600 break;
5601 }
5602
5603 cmd_reply(CMD_DELEGATE, caller, C_OK,
5604 _("%s is now controlling player '%s'."), caller->username,
5605 player_name(conn_get_player(caller)));
5606 ret = TRUE;
5607 break;
5608
5609 case DELEGATE_RESTORE:
5610 /* Delegate user relinquishes control of delegated player, returning to
5611 * previous view (e.g. observer) if any. */
5612 fc_assert_ret_val(caller, FALSE);
5613
5614 if (!caller->server.delegation.status) {
5615 cmd_reply(CMD_DELEGATE, caller, C_FAIL,
5616 _("You are not currently controlling a delegated player."));
5617 ret = FALSE;
5618 break;
5619 }
5620
5621 if (!connection_delegate_restore(caller)) {
5622 /* Should never happen. Generic failure message. */
5623 log_error("Failed to restore %s's connection as %s during "
5624 "'delegate restore'.", caller->username,
5626 caller->server.delegation.observer));
5627 cmd_reply(CMD_DELEGATE, caller, C_FAIL, _("Unexpected failure."));
5628 ret = FALSE;
5629 break;
5630 }
5631
5632 cmd_reply(CMD_DELEGATE, caller, C_OK,
5633 /* TRANS: "<user> is now connected to <player>" where <player>
5634 * can also be "global observer" or "nothing" */
5635 _("%s is now connected as %s."), caller->username,
5636 delegate_player_str(conn_get_player(caller), caller->observer));
5637 ret = TRUE;
5638 break;
5639 }
5640
5641 cleanup:
5643 return ret;
5644}
5645
5646/**********************************************************************/
5649static const char *delegate_player_str(struct player *pplayer, bool observer)
5650{
5651 static struct astring buf;
5652
5653 if (pplayer) {
5654 if (observer) {
5655 astr_set(&buf, _("%s (observer)"), player_name(pplayer));
5656 } else {
5657 astr_set(&buf, "%s", player_name(pplayer));
5658 }
5659 } else if (observer) {
5660 astr_set(&buf, "%s", _("global observer"));
5661 } else {
5662 /* TRANS: in place of player name or "global observer" */
5663 astr_set(&buf, "%s", _("nothing"));
5664 }
5665
5666 return astr_str(&buf);
5667}
5668
5669/* Define the possible arguments to the mapimg command */
5670/* map image layers */
5671#define SPECENUM_NAME mapimg_args
5672#define SPECENUM_VALUE0 MAPIMG_COLORTEST
5673#define SPECENUM_VALUE0NAME "colortest"
5674#define SPECENUM_VALUE1 MAPIMG_CREATE
5675#define SPECENUM_VALUE1NAME "create"
5676#define SPECENUM_VALUE2 MAPIMG_DEFINE
5677#define SPECENUM_VALUE2NAME "define"
5678#define SPECENUM_VALUE3 MAPIMG_DELETE
5679#define SPECENUM_VALUE3NAME "delete"
5680#define SPECENUM_VALUE4 MAPIMG_SHOW
5681#define SPECENUM_VALUE4NAME "show"
5682#define SPECENUM_COUNT MAPIMG_COUNT
5683#include "specenum_gen.h"
5684
5685/**********************************************************************/
5688static const char *mapimg_accessor(int i)
5689{
5690 i = CLIP(0, i, mapimg_args_max());
5691 return mapimg_args_name((enum mapimg_args) i);
5692}
5693
5694/**********************************************************************/
5697static bool mapimg_command(struct connection *caller, char *arg, bool check)
5698{
5699 enum m_pre_result result;
5700 int ind, ntokens, id;
5701 char *token[2];
5702 bool ret = TRUE;
5703
5704 ntokens = get_tokens(arg, token, 2, TOKEN_DELIMITERS);
5705
5706 if (ntokens > 0) {
5707 /* match the argument */
5709 fc_strncasecmp, NULL, token[0], &ind);
5710
5711 switch (result) {
5712 case M_PRE_EXACT:
5713 case M_PRE_ONLY:
5714 /* we have a match */
5715 break;
5716 case M_PRE_AMBIGUOUS:
5717 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5718 _("Ambiguous 'mapimg' command."));
5719 ret = FALSE;
5720 goto cleanup;
5721 break;
5722 case M_PRE_EMPTY:
5723 /* use 'show' as default */
5724 ind = MAPIMG_SHOW;
5725 break;
5726 case M_PRE_LONG:
5727 case M_PRE_FAIL:
5728 case M_PRE_LAST:
5729 {
5730 char buf[256] = "";
5732
5736 cat_snprintf(buf, sizeof(buf), "'%s'",
5738 if (valid_args != mapimg_args_max()) {
5739 cat_snprintf(buf, sizeof(buf), ", ");
5740 }
5741 }
5742
5743 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5744 _("The valid arguments are: %s."), buf);
5745 ret = FALSE;
5746 goto cleanup;
5747 }
5748 break;
5749 }
5750 } else {
5751 /* use 'show' as default */
5752 ind = MAPIMG_SHOW;
5753 }
5754
5755 switch (ind) {
5756 case MAPIMG_DEFINE:
5757 if (ntokens == 1) {
5758 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5759 _("Missing argument for 'mapimg define'."));
5760 ret = FALSE;
5761 } else {
5762 /* 'mapimg define <mapstr>' */
5763 if (!mapimg_define(token[1], check)) {
5764 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5765 _("Can't use definition: %s."), mapimg_error());
5766 ret = FALSE;
5767 } else if (check) {
5768 /* Validated OK, bail out now */
5769 goto cleanup;
5770 } else if (game_was_started()
5771 && mapimg_isvalid(mapimg_count() - 1) == NULL) {
5772 /* game was started - error in map image definition check */
5773 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5774 _("Can't use definition: %s."), mapimg_error());
5775 ret = FALSE;
5776 } else {
5777 char str[MAX_LEN_MAPDEF];
5778
5779 id = mapimg_count() - 1;
5780
5781 mapimg_id2str(id, str, sizeof(str));
5782 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Defined as map image "
5783 "definition %d: '%s'."),
5784 id, str);
5785 }
5786 }
5787 break;
5788
5789 case MAPIMG_DELETE:
5790 if (ntokens == 1) {
5791 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5792 _("Missing argument for 'mapimg delete'."));
5793 ret = FALSE;
5794 } else if (ntokens == 2 && strcmp(token[1], "all") == 0) {
5795 /* 'mapimg delete all' */
5796 if (check) {
5797 goto cleanup;
5798 }
5799
5800 while (mapimg_count() > 0) {
5801 mapimg_delete(0);
5802 }
5803 cmd_reply(CMD_MAPIMG, caller, C_OK, _("All map image definitions "
5804 "deleted."));
5805 } else if (ntokens == 2 && sscanf(token[1], "%d", &id) != 0) {
5806 /* 'mapimg delete <id>' */
5807 if (check) {
5808 goto cleanup;
5809 }
5810
5811 if (!mapimg_delete(id)) {
5812 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5813 _("Couldn't delete definition: %s."), mapimg_error());
5814 ret = FALSE;
5815 } else {
5816 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Map image definition %d "
5817 "deleted."), id);
5818 }
5819 } else {
5820 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5821 _("Bad argument for 'mapimg delete': '%s'."), token[1]);
5822 ret = FALSE;
5823 }
5824 break;
5825
5826 case MAPIMG_SHOW:
5827 if (ntokens < 2 || (ntokens == 2 && strcmp(token[1], "all") == 0)) {
5828 /* 'mapimg show' or 'mapimg show all' */
5829 if (check) {
5830 goto cleanup;
5831 }
5832 show_mapimg(caller, CMD_MAPIMG);
5833 } else if (ntokens == 2 && sscanf(token[1], "%d", &id) != 0) {
5834 char str[2048];
5835 /* 'mapimg show <id>' */
5836 if (check) {
5837 goto cleanup;
5838 }
5839
5840 if (mapimg_show(id, str, sizeof(str), TRUE)) {
5841 cmd_reply(CMD_MAPIMG, caller, C_OK, "%s", str);
5842 } else {
5843 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5844 _("Couldn't show definition: %s."), mapimg_error());
5845 ret = FALSE;
5846 }
5847 } else {
5848 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5849 _("Bad argument for 'mapimg show': '%s'."), token[1]);
5850 ret = FALSE;
5851 }
5852 break;
5853
5854 case MAPIMG_COLORTEST:
5855 if (check) {
5856 goto cleanup;
5857 }
5858
5860 cmd_reply(CMD_MAPIMG, caller, C_OK, _("Map color test images saved."));
5861 break;
5862
5863 case MAPIMG_CREATE:
5864 if (ntokens < 2) {
5865 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5866 _("Missing argument for 'mapimg create'."));
5867 ret = FALSE;
5868 goto cleanup;
5869 }
5870
5871 if (strcmp(token[1], "all") == 0) {
5872 /* 'mapimg create all' */
5873 if (check) {
5874 goto cleanup;
5875 }
5876
5877 for (id = 0; id < mapimg_count(); id++) {
5878 struct mapdef *pmapdef = mapimg_isvalid(id);
5879
5880 if (pmapdef == NULL
5883 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5884 _("Error saving map image %d: %s."), id, mapimg_error());
5885 ret = FALSE;
5886 }
5887 }
5888 } else if (sscanf(token[1], "%d", &id) != 0) {
5889 struct mapdef *pmapdef;
5890
5891 /* 'mapimg create <id>' */
5892 if (check) {
5893 goto cleanup;
5894 }
5895
5896 pmapdef = mapimg_isvalid(id);
5897 if (pmapdef == NULL
5900 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5901 _("Error saving map image %d: %s."), id, mapimg_error());
5902 ret = FALSE;
5903 }
5904 } else {
5905 cmd_reply(CMD_MAPIMG, caller, C_FAIL,
5906 _("Bad argument for 'mapimg create': '%s'."), token[1]);
5907 ret = FALSE;
5908 }
5909 break;
5910 }
5911
5912 cleanup:
5913
5914 free_tokens(token, ntokens);
5915
5916 return ret;
5917}
5918
5919/**********************************************************************/
5922static bool aicmd_command(struct connection *caller, char *arg, bool check)
5923{
5925 struct player *pplayer;
5926 char *tokens[1], *cmd = NULL;
5927 int ntokens;
5928 bool ret = FALSE;
5929
5931
5932 if (ntokens < 1) {
5933 cmd_reply(CMD_AICMD, caller, C_FAIL,
5934 _("No player given for aicmd."));
5935 goto cleanup;
5936 }
5937
5939
5940 if (NULL == pplayer) {
5942 goto cleanup;
5943 }
5944
5945 /* We have a player - extract the command. */
5946 cmd = arg + strlen(tokens[0]);
5947 cmd = skip_leading_spaces(cmd);
5948
5949 if (strlen(cmd) == 0) {
5950 cmd_reply(CMD_AICMD, caller, C_FAIL,
5951 _("No command for the AI console defined."));
5952 goto cleanup;
5953 }
5954
5955 if (check) {
5956 ret = TRUE;
5957 goto cleanup;
5958 }
5959
5960 /* This check is needed to return a message if the function is not defined
5961 * for the AI of the player. */
5962 if (pplayer && pplayer->ai) {
5963 if (pplayer->ai->funcs.player_console) {
5964 cmd_reply(CMD_AICMD, caller, C_OK,
5965 _("AI console for player %s. Command: '%s'."),
5966 player_name(pplayer), cmd);
5967 CALL_PLR_AI_FUNC(player_console, pplayer, pplayer, cmd);
5968 ret = TRUE;
5969 } else {
5970 cmd_reply(CMD_AICMD, caller, C_FAIL,
5971 _("No AI console defined for the AI '%s' of player %s."),
5972 ai_name(pplayer->ai), player_name(pplayer));
5973 }
5974 } else {
5975 cmd_reply(CMD_AICMD, caller, C_FAIL, _("No AI defined for player %s."),
5976 player_name(pplayer));
5977 }
5978
5979 cleanup:
5981 return ret;
5982}
5983
5984/* Define the possible arguments to the fcdb command */
5985#define SPECENUM_NAME fcdb_args
5986#define SPECENUM_VALUE0 FCDB_RELOAD
5987#define SPECENUM_VALUE0NAME "reload"
5988#define SPECENUM_VALUE1 FCDB_LUA
5989#define SPECENUM_VALUE1NAME "lua"
5990#define SPECENUM_COUNT FCDB_COUNT
5991#include "specenum_gen.h"
5992
5993/**********************************************************************/
5996static const char *fcdb_accessor(int i)
5997{
5998 i = CLIP(0, i, fcdb_args_max());
5999 return fcdb_args_name((enum fcdb_args) i);
6000}
6001
6002/**********************************************************************/
6005static bool fcdb_command(struct connection *caller, char *arg, bool check)
6006{
6007 enum m_pre_result result;
6008 int ind, ntokens;
6009 char *token[1];
6010 bool ret = TRUE;
6011 bool usage = FALSE;
6012
6013#ifndef HAVE_FCDB
6014 cmd_reply(CMD_FCDB, caller, C_FAIL,
6015 _("Freeciv database script deactivated at compile time."));
6016 return FALSE;
6017#endif
6018
6019 if (!srvarg.fcdb_enabled) {
6020 /* Not supposed to be used. It isn't initialized. */
6021 cmd_reply(CMD_FCDB, caller, C_FAIL,
6022 _("Freeciv database script not activated at server start. "
6023 "See the Freeciv server's --auth command line option."));
6024 return FALSE;
6025 }
6026
6027 ntokens = get_tokens(arg, token, 1, TOKEN_DELIMITERS);
6028
6029 if (ntokens > 0) {
6030 /* match the argument */
6032 fc_strncasecmp, NULL, token[0], &ind);
6033
6034 switch (result) {
6035 case M_PRE_EXACT:
6036 case M_PRE_ONLY:
6037 /* we have a match */
6038 break;
6039 case M_PRE_AMBIGUOUS:
6040 cmd_reply(CMD_FCDB, caller, C_FAIL,
6041 _("Ambiguous fcdb command."));
6042 ret = FALSE;
6043 goto cleanup;
6044 break;
6045 case M_PRE_EMPTY:
6046 case M_PRE_LONG:
6047 case M_PRE_FAIL:
6048 case M_PRE_LAST:
6049 usage = TRUE;
6050 break;
6051 }
6052 } else {
6053 usage = TRUE;
6054 }
6055
6056 if (usage) {
6057 char buf[256] = "";
6058 enum fcdb_args valid_args;
6059
6060 for (valid_args = fcdb_args_begin();
6063 cat_snprintf(buf, sizeof(buf), "'%s'",
6065 if (valid_args != fcdb_args_max()) {
6066 cat_snprintf(buf, sizeof(buf), ", ");
6067 }
6068 }
6069
6070 cmd_reply(CMD_FCDB, caller, C_FAIL,
6071 _("The valid arguments are: %s."), buf);
6072 ret = FALSE;
6073 goto cleanup;
6074 }
6075
6076 if (check) {
6077 ret = TRUE;
6078 goto cleanup;
6079 }
6080
6081 switch (ind) {
6082 case FCDB_RELOAD:
6083 /* Reload database lua script. */
6086 break;
6087
6088 case FCDB_LUA:
6089 /* Skip whitespaces. */
6090 arg = skip_leading_spaces(arg);
6091 /* Skip the base argument 'lua'. */
6092 arg += 3;
6093 /* Now execute the scriptlet. */
6094 ret = script_fcdb_do_string(caller, arg);
6095 break;
6096 }
6097
6098 cleanup:
6099
6100 free_tokens(token, ntokens);
6101
6102 return ret;
6103}
6104
6105/**********************************************************************/
6108static void start_cmd_reply(struct connection *caller, bool notify, char *msg)
6109{
6110 cmd_reply(CMD_START_GAME, caller, C_FAIL, "%s", msg);
6111 if (notify) {
6112 notify_conn(NULL, NULL, E_SETTING, ftc_server, "%s", msg);
6113 }
6114}
6115
6116/**********************************************************************/
6119bool start_command(struct connection *caller, bool check, bool notify)
6120{
6121 int human_players;
6122
6123 switch (server_state()) {
6124 case S_S_INITIAL:
6125 /* Sanity check scenario */
6126 if (game.info.is_new_game && !check) {
6127 if (0 < map_startpos_count()
6129 /* If we load a pre-generated map (i.e., a scenario) it is possible
6130 * to increase the number of players beyond the number supported by
6131 * the scenario. The solution is a hack: cut the extra players
6132 * when the game starts. */
6133 log_verbose("Reduced maxplayers from %d to %d to fit "
6134 "to the number of start positions.",
6137 }
6138
6140 int i;
6141 struct player *pplayer;
6142
6143 for (i = player_slot_count() - 1; i >= 0; i--) {
6144 pplayer = player_by_number(i);
6145 if (pplayer) {
6146 server_remove_player(pplayer);
6147 }
6149 break;
6150 }
6151 }
6152
6153 log_verbose("Had to cut down the number of players to the "
6154 "number of map start positions, there must be "
6155 "something wrong with the savegame or you "
6156 "adjusted the maxplayers value.");
6157 }
6158 }
6159
6160 human_players = 0;
6161 players_iterate(plr) {
6162 if (is_human(plr)) {
6163 human_players++;
6164 }
6166
6167 /* check min_players.
6168 * Allow continuing of savegames where some of the original
6169 * players have died */
6172 char buf[512] = "";
6173
6174 fc_snprintf(buf, sizeof(buf),
6175 _("Not enough human players ('minplayers' server setting has value %d); game will not start."),
6177 start_cmd_reply(caller, notify, buf);
6178 return FALSE;
6179 } else if (player_count() < 1) {
6180 /* At least one player required */
6181 start_cmd_reply(caller, notify,
6182 _("No players; game will not start."));
6183 return FALSE;
6184 } else if (normal_player_count() > server.playable_nations) {
6185 if (nation_set_count() > 1) {
6186 start_cmd_reply(caller, notify,
6187 _("Not enough nations in the current nation set "
6188 "for all players; game will not start. "
6189 "(See 'nationset' setting.)"));
6190 } else {
6191 start_cmd_reply(caller, notify,
6192 _("Not enough nations for all players; game will "
6193 "not start."));
6194 }
6195 return FALSE;
6196 } else if (strlen(game.server.start_units) == 0 && !game.server.start_city) {
6197 start_cmd_reply(caller, notify,
6198 _("Neither 'startcity' nor 'startunits' setting gives "
6199 "players anything to start game with; game will "
6200 "not start."));
6201 return FALSE;
6202 } else if (check) {
6203 return TRUE;
6204 } else if (!caller) {
6205 if (notify) {
6206 /* Called from handle_player_ready()
6207 * Last player just toggled ready-status. */
6209 _("All players are ready; starting game."));
6210 }
6211 start_game();
6212 return TRUE;
6213 } else if (NULL == caller->playing || caller->observer) {
6214 /* A detached or observer player can't do /start. */
6215 return TRUE;
6216 } else {
6217 /* This might trigger recursive call to start_command() if this is
6218 * last player who gets ready. In that case caller is NULL. */
6220 return TRUE;
6221 }
6222 case S_S_OVER:
6223 start_cmd_reply(caller, notify,
6224 /* TRANS: given when /start is invoked during gameover. */
6225 _("Cannot start the game: the game is waiting for all clients "
6226 "to disconnect."));
6227 return FALSE;
6228 case S_S_RUNNING:
6229 start_cmd_reply(caller, notify,
6230 /* TRANS: given when /start is invoked while the game
6231 * is running. */
6232 _("Cannot start the game: it is already running."));
6233 return FALSE;
6234 }
6235 log_error("Unknown server state variant: %d.", server_state());
6236 return FALSE;
6237}
6238
6239/**********************************************************************/
6242static bool cut_client_connection(struct connection *caller, char *name,
6243 bool check)
6244{
6246 struct connection *ptarget;
6247
6249
6250 if (!ptarget) {
6252 return FALSE;
6253 } else if (check) {
6254 return TRUE;
6255 }
6256
6258 /* If we cut the connection, unassign the login name.*/
6259 sz_strlcpy(ptarget->playing->username, _(ANON_USER_NAME));
6260 ptarget->playing->unassigned_user = TRUE;
6261 }
6262
6264 _("Cutting connection %s."), ptarget->username);
6265 connection_close_server(ptarget, _("connection cut"));
6266
6267 return TRUE;
6268}
6269
6270
6271/**********************************************************************/
6275{
6276 time_t *d = fc_malloc(sizeof(*d));
6277 *d = *t;
6278 return d;
6279}
6280
6281/**********************************************************************/
6286{
6288 time_t now, time_of_kick = 0;
6289
6290 if (NULL != time_remaining) {
6291 *time_remaining = 0;
6292 }
6293
6297
6298 if (kick_hash_lookup(kick_table_by_addr, pconn->server.ipaddr,
6301 }
6306 }
6307
6308 if (0 == time_of_kick) {
6309 return FALSE; /* Not found. */
6310 }
6311
6312 now = time(NULL);
6314 /* Kick timeout expired. */
6315 if (0 != time_of_addr_kick) {
6316 kick_hash_remove(kick_table_by_addr, pconn->server.ipaddr);
6317 }
6318 if (0 != time_of_user_kick) {
6320 }
6321 return FALSE;
6322 }
6323
6324 if (NULL != time_remaining) {
6326 }
6327 return TRUE;
6328}
6329
6330/**********************************************************************/
6333static bool kick_command(struct connection *caller, char *name, bool check)
6334{
6335 char ipaddr[FC_MEMBER_SIZEOF(struct connection, server.ipaddr)];
6336 struct connection *pconn;
6338 time_t now;
6339
6342 if (NULL == pconn) {
6344 return FALSE;
6345 }
6346
6347 if (NULL != caller && ALLOW_ADMIN > conn_get_access(caller)) {
6348 const int MIN_UNIQUE_CONNS = 3;
6349 const char *unique_ipaddr[MIN_UNIQUE_CONNS];
6350 int i, num_unique_connections = 0;
6351
6352 if (pconn == caller) {
6353 cmd_reply(CMD_KICK, caller, C_FAIL, _("You may not kick yourself."));
6354 return FALSE;
6355 }
6356
6358 for (i = 0; i < num_unique_connections; i++) {
6359 if (0 == strcmp(unique_ipaddr[i], aconn->server.ipaddr)) {
6360 /* Already listed. */
6361 break;
6362 }
6363 }
6364 if (i >= num_unique_connections) {
6367 /* We have enough already. */
6368 break;
6369 }
6370 unique_ipaddr[num_unique_connections - 1] = aconn->server.ipaddr;
6371 }
6373
6375 cmd_reply(CMD_KICK, caller, C_FAIL,
6376 _("There must be at least %d unique connections to the "
6377 "server for this command to be valid."), MIN_UNIQUE_CONNS);
6378 return FALSE;
6379 }
6380 }
6381
6382 if (check) {
6383 return TRUE;
6384 }
6385
6386 sz_strlcpy(ipaddr, pconn->server.ipaddr);
6387 now = time(NULL);
6389
6391 if (0 != strcmp(ipaddr, aconn->server.ipaddr)) {
6392 continue;
6393 }
6394
6396 /* Unassign the username. */
6397 sz_strlcpy(aconn->playing->username, _(ANON_USER_NAME));
6398 aconn->playing->unassigned_user = TRUE;
6399 }
6400
6402
6403 connection_close_server(aconn, _("kicked"));
6405
6406 return TRUE;
6407}
6408
6409
6410/**********************************************************************/
6414static void show_help_intro(struct connection *caller,
6415 enum command_id help_cmd)
6416{
6417 /* This is formatted like extra_help entries for settings and commands: */
6418 char *help = fc_strdup(
6419 _("Welcome - this is the introductory help text for the Freeciv "
6420 "server.\n"
6421 "\n"
6422 "Two important server concepts are Commands and Options. Commands, "
6423 "such as 'help', are used to interact with the server. Some commands "
6424 "take one or more arguments, separated by spaces. In many cases "
6425 "commands and command arguments may be abbreviated. Options are "
6426 "settings which control the server as it is running.\n"
6427 "\n"
6428 "To find out how to get more information about commands and options, "
6429 "use 'help help'.\n"
6430 "\n"
6431 "For the impatient, the main commands to get going are:\n"
6432 " show - to see current options\n"
6433 " set - to set options\n"
6434 " start - to start the game once players have connected\n"
6435 " save - to save the current game\n"
6436 " quit - to exit"));
6437
6439 cmd_reply(help_cmd, caller, C_COMMENT, "%s", help);
6440 FC_FREE(help);
6441}
6442
6443/**********************************************************************/
6447static void show_help_command(struct connection *caller,
6448 enum command_id help_cmd,
6449 enum command_id id)
6450{
6451 const struct command *cmd = command_by_number(id);
6452
6453 if (command_short_help(cmd)) {
6454 cmd_reply(help_cmd, caller, C_COMMENT,
6455 /* TRANS: <untranslated name> - translated short help */
6456 _("Command: %s - %s"),
6457 command_name(cmd),
6458 command_short_help(cmd));
6459 } else {
6460 cmd_reply(help_cmd, caller, C_COMMENT,
6461 /* TRANS: <untranslated name> */
6462 _("Command: %s"),
6463 command_name(cmd));
6464 }
6465 if (command_synopsis(cmd)) {
6466 /* line up the synopsis lines: */
6467 const char *syn = _("Synopsis: ");
6468 size_t synlen = strlen(syn);
6469 char prefix[40];
6470
6471 fc_snprintf(prefix, sizeof(prefix), "%*s", (int) synlen, " ");
6472 cmd_reply_prefix(help_cmd, caller, C_COMMENT, prefix,
6473 "%s%s", syn, command_synopsis(cmd));
6474 }
6475 cmd_reply(help_cmd, caller, C_COMMENT,
6476 _("Level: %s"), cmdlevel_name(command_level(cmd)));
6477 {
6478 char *help = command_extra_help(cmd);
6479
6480 if (help) {
6482 cmd_reply(help_cmd, caller, C_COMMENT, _("Description:"));
6483 cmd_reply_prefix(help_cmd, caller, C_COMMENT, " ", " %s", help);
6484 FC_FREE(help);
6485 }
6486 }
6487}
6488
6489/**********************************************************************/
6493static void show_help_command_list(struct connection *caller,
6494 enum command_id help_cmd)
6495{
6496 enum command_id i;
6497
6498 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6499 cmd_reply(help_cmd, caller, C_COMMENT,
6500 _("The following server commands are available:"));
6501 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6502 if (!caller && con_get_style()) {
6503 for (i = 0; i < CMD_NUM; i++) {
6504 cmd_reply(help_cmd, caller, C_COMMENT, "%s", command_name_by_number(i));
6505 }
6506 } else {
6508 int j;
6509
6510 buf[0] = '\0';
6511 for (i = 0, j = 0; i < CMD_NUM; i++) {
6512 if (may_use(caller, i)) {
6513 cat_snprintf(buf, sizeof(buf), "%-19s", command_name_by_number(i));
6514 if ((++j % 4) == 0) {
6515 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
6516 buf[0] = '\0';
6517 }
6518 }
6519 }
6520 if (buf[0] != '\0') {
6521 cmd_reply(help_cmd, caller, C_COMMENT, "%s", buf);
6522 }
6523 }
6524 cmd_reply(help_cmd, caller, C_COMMENT, horiz_line);
6525}
6526
6527/**********************************************************************/
6531static void cmd_reply_matches(enum command_id cmd,
6532 struct connection *caller,
6534 int *matches, int num_matches)
6535{
6536 char buf[MAX_LEN_MSG];
6537 const char *src, *end;
6538 char *dest;
6539 int i;
6540
6541 if (accessor_fn == NULL || matches == NULL || num_matches < 1) {
6542 return;
6543 }
6544
6545 dest = buf;
6546 end = buf + sizeof(buf) - 1;
6547
6548 for (i = 0; i < num_matches && dest < end; i++) {
6549 src = accessor_fn(matches[i]);
6550 if (!src) {
6551 continue;
6552 }
6553 if (dest != buf) {
6554 *dest++ = ' ';
6555 }
6556 while (*src != '\0' && dest < end) {
6557 *dest++ = *src++;
6558 }
6559 }
6560 *dest = '\0';
6561
6562 cmd_reply(cmd, caller, C_COMMENT, _("Possible matches: %s"), buf);
6563}
6564
6565/**************************************************************************
6566 Additional 'help' arguments
6567**************************************************************************/
6568#define SPECENUM_NAME help_general_args
6569#define SPECENUM_VALUE0 HELP_GENERAL_COMMANDS
6570#define SPECENUM_VALUE0NAME "commands"
6571#define SPECENUM_VALUE1 HELP_GENERAL_OPTIONS
6572#define SPECENUM_VALUE1NAME "options"
6573#define SPECENUM_COUNT HELP_GENERAL_COUNT
6574#include "specenum_gen.h"
6575
6576/**************************************************************************
6577 Unified indices for help arguments:
6578 CMD_NUM - Server commands
6579 HELP_GENERAL_NUM - General help arguments, above
6580 settings_number() - Server options
6581**************************************************************************/
6582#define HELP_ARG_NUM (CMD_NUM + HELP_GENERAL_COUNT + settings_number())
6583
6584/**********************************************************************/
6587static const char *helparg_accessor(int i)
6588{
6589 if (i < CMD_NUM) {
6590 return command_name_by_number(i);
6591 }
6592
6593 i -= CMD_NUM;
6594 if (i < HELP_GENERAL_COUNT) {
6596 }
6597
6599 return optname_accessor(i);
6600}
6601
6602/**********************************************************************/
6605static bool show_help(struct connection *caller, char *arg)
6606{
6607 int matches[64], num_matches = 0;
6609 int ind;
6610
6612 /* no commands means no help, either */
6613
6615 fc_strncasecmp, NULL, arg, &ind, matches,
6617
6618 if (match_result == M_PRE_EMPTY) {
6619 show_help_intro(caller, CMD_HELP);
6620 return FALSE;
6621 }
6623 cmd_reply(CMD_HELP, caller, C_FAIL,
6624 _("Help argument '%s' is ambiguous."), arg);
6627 return FALSE;
6628 }
6629 if (match_result == M_PRE_FAIL) {
6630 cmd_reply(CMD_HELP, caller, C_FAIL,
6631 _("No match for help argument '%s'."), arg);
6632 return FALSE;
6633 }
6634
6635 /* other cases should be above */
6637
6638 if (ind < CMD_NUM) {
6639 show_help_command(caller, CMD_HELP, ind);
6640 return TRUE;
6641 }
6642 ind -= CMD_NUM;
6643
6644 if (ind == HELP_GENERAL_OPTIONS) {
6646 return TRUE;
6647 }
6648 if (ind == HELP_GENERAL_COMMANDS) {
6650 return TRUE;
6651 }
6653
6654 if (ind < settings_number()) {
6655 show_help_option(caller, CMD_HELP, ind);
6656 return TRUE;
6657 }
6658
6659 /* should have finished by now */
6660 log_error("Bug in show_help!");
6661 return FALSE;
6662}
6663
6664/**********************************************************************/
6667static void show_connections(struct connection *caller)
6668{
6670
6671 cmd_reply(CMD_LIST, caller, C_COMMENT,
6672 _("List of connections to server:"));
6674
6676 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no connections>"));
6677 } else {
6680 if (pconn->established) {
6681 cat_snprintf(buf, sizeof(buf), " command access level %s",
6682 cmdlevel_name(pconn->access_level));
6683 }
6684 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6686 }
6688}
6689
6690/**********************************************************************/
6693static void show_delegations(struct connection *caller)
6694{
6695 bool empty = TRUE;
6696
6697 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of all delegations:"));
6699
6700 players_iterate(pplayer) {
6701 const char *delegate_to = player_delegation_get(pplayer);
6702 if (delegate_to != NULL) {
6703 const char *owner =
6704 player_delegation_active(pplayer) ? pplayer->server.orig_username
6705 : pplayer->username;
6707 cmd_reply(CMD_LIST, caller, C_COMMENT,
6708 /* TRANS: last %s is either " (active)" or empty string */
6709 _("%s delegates control over player '%s' to user %s%s."),
6710 owner, player_name(pplayer), delegate_to,
6711 /* TRANS: preserve leading space */
6712 player_delegation_active(pplayer) ? _(" (active)") : "");
6713 empty = FALSE;
6714 }
6716
6717 if (empty) {
6718 cmd_reply(CMD_LIST, caller, C_COMMENT, _("No delegations defined."));
6719 }
6720
6722}
6723
6724/**********************************************************************/
6727static bool show_ignore(struct connection *caller)
6728{
6729 char buf[128];
6730 int n = 1;
6731
6732 if (NULL == caller) {
6733 cmd_reply(CMD_IGNORE, caller, C_FAIL,
6734 _("That would be rather silly, since you are not a player."));
6735 return FALSE;
6736 }
6737
6738 if (0 == conn_pattern_list_size(caller->server.ignore_list)) {
6739 cmd_reply(CMD_LIST, caller, C_COMMENT, _("Your ignore list is empty."));
6740 return TRUE;
6741 }
6742
6743 cmd_reply(CMD_LIST, caller, C_COMMENT, _("Your ignore list:"));
6747 cmd_reply(CMD_LIST, caller, C_COMMENT, "%d: %s", n++, buf);
6750
6751 return TRUE;
6752}
6753
6754/**********************************************************************/
6757void show_players(struct connection *caller)
6758{
6759 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of players:"));
6761
6762 if (player_count() == 0) {
6763 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no players>"));
6764 } else {
6765 players_iterate(pplayer) {
6767 int n;
6768
6769 /* Low access level callers don't get to see barbarians in list: */
6770 if (is_barbarian(pplayer) && caller
6771 && (caller->access_level < ALLOW_CTRL)) {
6772 continue;
6773 }
6774
6775 /* The output for each player looks like:
6776 *
6777 * <Player name> [color]: Team[, Nation][, Username][, Status]
6778 * AI/Barbarian/Human[, AI type, skill level][, Connections]
6779 * [Details for each connection]
6780 */
6781
6782 /* '<Player name> [color]: [Nation][, Username][, Status]' */
6783 buf[0] = '\0';
6784 cat_snprintf(buf, sizeof(buf), "%s [%s]: %s", player_name(pplayer),
6785 player_color_ftstr(pplayer),
6786 team_name_translation(pplayer->team));
6787 if (!game.info.is_new_game) {
6788 cat_snprintf(buf, sizeof(buf), ", %s",
6790 }
6791 if (strlen(pplayer->username) > 0
6792 && strcmp(pplayer->username, "nouser") != 0) {
6793 cat_snprintf(buf, sizeof(buf), _(", user %s"), pplayer->username);
6794 }
6795 if (S_S_INITIAL == server_state() && pplayer->is_connected) {
6796 if (pplayer->is_ready) {
6797 sz_strlcat(buf, _(", ready"));
6798 } else {
6799 /* Emphasizes this */
6800 n = strlen(buf);
6801 featured_text_apply_tag(_(", not ready"),
6802 buf + n, sizeof(buf) - n,
6804 ftc_changed);
6805 }
6806 } else if (!pplayer->is_alive) {
6807 sz_strlcat(buf, _(", Dead"));
6808 }
6809 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6810
6811 /* ' AI/Barbarian/Human[, skill level][, Connections]' */
6812 buf[0] = '\0';
6813 if (is_barbarian(pplayer)) {
6814 sz_strlcat(buf, _("Barbarian"));
6815 } else if (is_ai(pplayer)) {
6816 sz_strlcat(buf, _("AI"));
6817 } else {
6818 sz_strlcat(buf, _("Human"));
6819 }
6820 if (is_ai(pplayer)) {
6821 cat_snprintf(buf, sizeof(buf), _(", %s"), ai_name(pplayer->ai));
6822 cat_snprintf(buf, sizeof(buf), _(", difficulty level %s"),
6823 ai_level_translated_name(pplayer->ai_common.skill_level));
6824 }
6825 n = conn_list_size(pplayer->connections);
6826 if (n > 0) {
6827 cat_snprintf(buf, sizeof(buf),
6828 PL_(", %d connection:", ", %d connections:", n), n);
6829 }
6830 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", buf);
6831
6832 /* ' [Details for each connection]' */
6833 conn_list_iterate(pplayer->connections, pconn) {
6834 fc_snprintf(buf, sizeof(buf),
6835 _("%s from %s (command access level %s), "
6836 "bufsize=%dkb"), pconn->username, pconn->addr,
6837 cmdlevel_name(pconn->access_level),
6838 (pconn->send_buffer->nsize >> 10));
6839 if (pconn->observer) {
6840 /* TRANS: preserve leading space */
6841 sz_strlcat(buf, _(" (observer mode)"));
6842 }
6843 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", buf);
6846 }
6848}
6849
6852};
6853
6854/************************************************************************/
6857static void ruleset_cache_listcmd_cb(const char *mp_name,
6858 const char *filename, void *data_in)
6859{
6860 struct mrc_listcmd_data *data = (struct mrc_listcmd_data *)data_in;
6861 struct section_file *sf;
6862 const char *name;
6863 const char *serv;
6864 const char *rsdir;
6865
6867
6868 if (name == NULL) {
6869 log_error("Modpack \"%s\" not in ruleset cache", mp_name);
6870 return;
6871 }
6872
6873 sf = secfile_load(name, FALSE);
6874
6875 if (sf == NULL) {
6876 log_error("Failed to load modpack file \"%s\"", name);
6877 return;
6878 }
6879
6880 serv = modpack_serv_file(sf);
6882
6883 if (serv != NULL || rsdir != NULL) {
6884 /* Modpack has ruleset component */
6885 cmd_reply(CMD_LIST, data->caller, C_COMMENT, "%s : %s : %s", mp_name,
6886 rsdir != NULL ? rsdir : "-",
6887 serv != NULL ? serv : "-");
6888 }
6889
6890 secfile_destroy(sf);
6891}
6892
6893/**********************************************************************/
6896static void show_rulesets(struct connection *caller)
6897{
6898 struct mrc_listcmd_data data;
6899
6901 /* TRANS: don't translate text between '' */
6902 _("List of available rulesets, and how to load them:"));
6905 _("Ruleset : /rulesetdir <dir> : /read <script>"));
6907
6909
6910 data.caller = caller;
6912
6914}
6915
6916/**********************************************************************/
6920{
6922 struct fileinfo_list *files;
6923
6924 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of scenarios available:"));
6926
6927 files = fileinfolist_infix(get_scenario_dirs(), ".sav", TRUE);
6928
6930 struct section_file *sf = secfile_load_section(pfile->fullname, "scenario", TRUE);
6931
6932 if (secfile_lookup_bool_default(sf, TRUE, "scenario.is_scenario")) {
6933 fc_snprintf(buf, sizeof(buf), "%s", pfile->name);
6934 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
6935 }
6937 fileinfo_list_destroy(files);
6938
6940}
6941
6942/**********************************************************************/
6945static void show_nationsets(struct connection *caller)
6946{
6947 cmd_reply(CMD_LIST, caller, C_COMMENT,
6948 /* TRANS: don't translate text between '' */
6949 _("List of nation sets available for 'nationset' option:"));
6951
6953 const char *description = nation_set_description(pset);
6954 int num_nations = 0;
6955 nations_iterate(pnation) {
6956 if (is_nation_playable(pnation) && nation_is_in_set(pnation, pset)) {
6957 num_nations++;
6958 }
6960 cmd_reply(CMD_LIST, caller, C_COMMENT,
6961 /* TRANS: nation set description; %d refers to number of playable
6962 * nations in set */
6963 PL_(" %-10s %s (%d playable)",
6964 " %-10s %s (%d playable)", num_nations),
6966 num_nations);
6967 if (strlen(description) > 0) {
6968 static const char prefix[] = " ";
6969 char *translated = fc_strdup(_(description));
6971 cmd_reply_prefix(CMD_LIST, caller, C_COMMENT, prefix, "%s%s",
6972 prefix, translated);
6973 }
6975
6977}
6978
6979/**********************************************************************/
6982static void show_teams(struct connection *caller)
6983{
6984 /* Currently this just lists all teams (typically 32 of them) with their
6985 * names and # of players on the team. This could probably be improved. */
6986 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of teams:"));
6988
6990 const struct player_list *members = team_members(pteam);
6991
6992 /* PL_() is needed here because some languages may differentiate
6993 * between 2 and 3 (although English does not). */
6994 cmd_reply(CMD_LIST, caller, C_COMMENT,
6995 /* TRANS: There will always be at least 2 players here. */
6996 PL_("%2d : '%s' : %d player :",
6997 "%2d : '%s' : %d players :",
7001 player_list_iterate(members, pplayer) {
7002 cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", player_name(pplayer));
7005
7007}
7008
7009/**********************************************************************/
7012static void show_mapimg(struct connection *caller, enum command_id cmd)
7013{
7014 int id;
7015
7016 if (mapimg_count() == 0) {
7017 cmd_reply(cmd, caller, C_OK, _("No map image definitions."));
7018 } else {
7019 cmd_reply(cmd, caller, C_COMMENT, _("List of map image definitions:"));
7020 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
7021 for (id = 0; id < mapimg_count(); id++) {
7022 char str[MAX_LEN_MAPDEF] = "";
7023 mapimg_show(id, str, sizeof(str), FALSE);
7024 cmd_reply(cmd, caller, C_COMMENT, _("[%2d] %s"), id, str);
7025 }
7026 cmd_reply(cmd, caller, C_COMMENT, horiz_line);
7027 }
7028}
7029
7030/**********************************************************************/
7033static void show_ais(struct connection *caller)
7034{
7035 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of AI types:"));
7037
7038 ai_type_iterate(ai) {
7039 cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", ai->name);
7041
7043}
7044
7045/**********************************************************************/
7048static void show_colors(struct connection *caller)
7049{
7050 cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of player colors:"));
7052 if (player_count() == 0) {
7053 cmd_reply(CMD_LIST, caller, C_COMMENT, _("<no players>"));
7054 } else {
7055 players_iterate(pplayer) {
7056 cmd_reply(CMD_LIST, caller, C_COMMENT, _("%s (user %s): [%s]"),
7057 player_name(pplayer), pplayer->username,
7058 player_color_ftstr(pplayer));
7060 }
7062}
7063
7064/**************************************************************************
7065 '/list' arguments
7066**************************************************************************/
7067#define SPECENUM_NAME list_args
7068#define SPECENUM_VALUE0 LIST_AIS
7069#define SPECENUM_VALUE0NAME "ais"
7070#define SPECENUM_VALUE1 LIST_COLORS
7071#define SPECENUM_VALUE1NAME "colors"
7072#define SPECENUM_VALUE2 LIST_CONNECTIONS
7073#define SPECENUM_VALUE2NAME "connections"
7074#define SPECENUM_VALUE3 LIST_DELEGATIONS
7075#define SPECENUM_VALUE3NAME "delegations"
7076#define SPECENUM_VALUE4 LIST_IGNORE
7077#define SPECENUM_VALUE4NAME "ignored users"
7078#define SPECENUM_VALUE5 LIST_MAPIMG
7079#define SPECENUM_VALUE5NAME "map image definitions"
7080#define SPECENUM_VALUE6 LIST_PLAYERS
7081#define SPECENUM_VALUE6NAME "players"
7082#define SPECENUM_VALUE7 LIST_RULESETS
7083#define SPECENUM_VALUE7NAME "rulesets"
7084#define SPECENUM_VALUE8 LIST_SCENARIOS
7085#define SPECENUM_VALUE8NAME "scenarios"
7086#define SPECENUM_VALUE9 LIST_NATIONSETS
7087#define SPECENUM_VALUE9NAME "nationsets"
7088#define SPECENUM_VALUE10 LIST_TEAMS
7089#define SPECENUM_VALUE10NAME "teams"
7090#define SPECENUM_VALUE11 LIST_VOTES
7091#define SPECENUM_VALUE11NAME "votes"
7092#include "specenum_gen.h"
7093
7094/**********************************************************************/
7097static const char *list_accessor(int i)
7098{
7099 i = CLIP(0, i, list_args_max());
7100 return list_args_name((enum list_args) i);
7101}
7102
7103/**********************************************************************/
7106static bool show_list(struct connection *caller, char *arg)
7107{
7109 int ind_int;
7110 enum list_args ind;
7111
7114 fc_strncasecmp, NULL, arg, &ind_int);
7115 ind = ind_int;
7116
7117 if (match_result > M_PRE_EMPTY) {
7118 cmd_reply(CMD_LIST, caller, C_SYNTAX,
7119 _("Bad list argument: '%s'. Try '%shelp list'."),
7120 arg, (caller ? "/" : ""));
7121 return FALSE;
7122 }
7123
7124 if (match_result == M_PRE_EMPTY) {
7125 ind = LIST_PLAYERS;
7126 }
7127
7128 switch (ind) {
7129 case LIST_AIS:
7130 show_ais(caller);
7131 return TRUE;
7132 case LIST_COLORS:
7133 show_colors(caller);
7134 return TRUE;
7135 case LIST_CONNECTIONS:
7136 show_connections(caller);
7137 return TRUE;
7138 case LIST_DELEGATIONS:
7139 show_delegations(caller);
7140 return TRUE;
7141 case LIST_IGNORE:
7142 return show_ignore(caller);
7143 case LIST_MAPIMG:
7144 show_mapimg(caller, CMD_LIST);
7145 return TRUE;
7146 case LIST_PLAYERS:
7147 show_players(caller);
7148 return TRUE;
7149 case LIST_RULESETS:
7150 show_rulesets(caller);
7151 return TRUE;
7152 case LIST_SCENARIOS:
7153 show_scenarios(caller);
7154 return TRUE;
7155 case LIST_NATIONSETS:
7156 show_nationsets(caller);
7157 return TRUE;
7158 case LIST_TEAMS:
7159 show_teams(caller);
7160 return TRUE;
7161 case LIST_VOTES:
7162 show_votes(caller);
7163 return TRUE;
7164 }
7165
7166 cmd_reply(CMD_LIST, caller, C_FAIL,
7167 "Internal error: ind %d in show_list", ind);
7168 log_error("Internal error: ind %d in show_list", ind);
7169 return FALSE;
7170}
7171
7172#ifdef FREECIV_HAVE_LIBREADLINE
7173/********************* RL completion functions ***************************/
7174/* To properly complete both commands, player names, options and filenames
7175 there is one array per type of completion with the commands that
7176 the type is relevant for.
7177*/
7178
7179/**********************************************************************/
7187static char *generic_generator(const char *text, int state, int num,
7188 const char*(*index2str)(int))
7189{
7190 static int list_index, len;
7191 const char *name = ""; /* dummy non-NULL string */
7193
7194 /* This function takes a string (text) in the local format and must return
7195 * a string in the local format. However comparisons are done against
7196 * names that are in the internal format (UTF-8). Thus we have to convert
7197 * the text function from the local to the internal format before doing
7198 * the comparison, and convert the string we return *back* to the
7199 * local format when returning it. */
7200
7201 /* If this is a new word to complete, initialize now. This includes
7202 saving the length of TEXT for efficiency, and initializing the index
7203 variable to 0. */
7204 if (state == 0) {
7205 list_index = 0;
7206 len = strlen(mytext);
7207 }
7208
7209 /* Return the next name which partially matches: */
7210 while ((num < 0 && name) || (list_index < num)) {
7212 list_index++;
7213
7214 if (name != NULL && fc_strncasecmp(name, mytext, len) == 0) {
7215 free(mytext);
7217 }
7218 }
7219 free(mytext);
7220
7221 /* If no names matched, then return NULL. */
7222 return ((char *)NULL);
7223}
7224
7225/**********************************************************************/
7228static char *command_generator(const char *text, int state)
7229{
7230 return generic_generator(text, state, CMD_NUM, command_name_by_number);
7231}
7232
7233/**********************************************************************/
7236static char *option_generator(const char *text, int state)
7237{
7238 return generic_generator(text, state, settings_number(), optname_accessor);
7239}
7240
7241/**********************************************************************/
7244static char *olevel_generator(const char *text, int state)
7245{
7246 return generic_generator(text, state, settings_number() + OLEVELS_NUM + 1,
7248}
7249
7250/**********************************************************************/
7254static int completion_option;
7255static const char *option_value_accessor(int idx) {
7257
7258 switch (setting_type(pset)) {
7259 case SST_ENUM:
7260 return setting_enum_val(pset, idx, FALSE);
7261 case SST_BITWISE:
7262 return setting_bitwise_bit(pset, idx, FALSE);
7263 default:
7265 }
7266
7267 return NULL;
7268}
7269
7270/**********************************************************************/
7274static char *option_value_generator(const char *text, int state)
7275{
7276 return generic_generator(text, state, -1, option_value_accessor);
7277}
7278
7279/**********************************************************************/
7282static const char *playername_accessor(int idx)
7283{
7284 const struct player_slot *pslot = player_slot_by_number(idx);
7285
7286 if (!player_slot_is_used(pslot)) {
7287 return NULL;
7288 }
7289
7290 return player_name(player_slot_get_player(pslot));
7291}
7292
7293/**********************************************************************/
7296static char *player_generator(const char *text, int state)
7297{
7298 return generic_generator(text, state, player_slot_count(),
7300}
7301
7302/**********************************************************************/
7305static const char *connection_name_accessor(int idx)
7306{
7307 return conn_list_get(game.all_connections, idx)->username;
7308}
7309
7310/**********************************************************************/
7313static char *connection_generator(const char *text, int state)
7314{
7317}
7318
7319/**********************************************************************/
7322static const char *cmdlevel_arg1_accessor(int idx)
7323{
7324 return cmdlevel_name(idx);
7325}
7326
7327/**********************************************************************/
7330static char *cmdlevel_arg1_generator(const char *text, int state)
7331{
7332 return generic_generator(text, state, cmdlevel_max()+1,
7334}
7335
7336/**********************************************************************/
7340static const char *cmdlevel_arg2_accessor(int idx)
7341{
7342 return ((idx == 0) ? "first" :
7343 (idx == 1) ? "new" :
7344 connection_name_accessor(idx - 2));
7345}
7346
7347/**********************************************************************/
7350static char *cmdlevel_arg2_generator(const char *text, int state)
7351{
7352 return generic_generator(text, state,
7353 /* "first", "new", connection names */
7356}
7357
7358/**********************************************************************/
7361static const char *aitype_accessor(int idx)
7362{
7363 return get_ai_type(idx)->name;
7364}
7365
7366/**********************************************************************/
7369static char *aitype_generator(const char *text, int state)
7370{
7371 return generic_generator(text, state, ai_type_get_count(),
7373}
7374
7375/**********************************************************************/
7378static char *reset_generator(const char *text, int state)
7379{
7380 return generic_generator(text, state, reset_args_max() + 1, reset_accessor);
7381}
7382
7383/**********************************************************************/
7386static char *vote_generator(const char *text, int state)
7387{
7388 return generic_generator(text, state, -1, vote_arg_accessor);
7389}
7390
7391/**********************************************************************/
7394static char *delegate_generator(const char *text, int state)
7395{
7396 return generic_generator(text, state, delegate_args_max() + 1,
7398}
7399
7400/**********************************************************************/
7403static char *mapimg_generator(const char *text, int state)
7404{
7405 return generic_generator(text, state, mapimg_args_max() + 1,
7407}
7408
7409/**********************************************************************/
7412static char *fcdb_generator(const char *text, int state)
7413{
7414 return generic_generator(text, state, FCDB_COUNT, fcdb_accessor);
7415}
7416
7417/**********************************************************************/
7420static char *lua_generator(const char *text, int state)
7421{
7422 return generic_generator(text, state, lua_args_max() + 1, lua_accessor);
7423}
7424
7425/**********************************************************************/
7428static char *help_generator(const char *text, int state)
7429{
7430 return generic_generator(text, state, HELP_ARG_NUM, helparg_accessor);
7431}
7432
7433/**********************************************************************/
7436static char *list_generator(const char *text, int state)
7437{
7438 return generic_generator(text, state, list_args_max() + 1, list_accessor);
7439}
7440
7441/**********************************************************************/
7445static bool contains_token_before_start(int start, int token, const char *arg,
7446 bool allow_fluff)
7447{
7448 char *str_itr = rl_line_buffer;
7449 int arg_len = strlen(arg);
7450
7451 /* Swallow unwanted tokens and their preceding delimiters */
7452 while (token--) {
7453 while (str_itr < rl_line_buffer + start && !fc_isalnum(*str_itr)) {
7454 str_itr++;
7455 }
7456 while (str_itr < rl_line_buffer + start && fc_isalnum(*str_itr)) {
7457 str_itr++;
7458 }
7459 }
7460
7461 /* Swallow any delimiters before the token we're interested in */
7462 while (str_itr < rl_line_buffer + start && !fc_isalnum(*str_itr)) {
7463 str_itr++;
7464 }
7465
7466 if (fc_strncasecmp(str_itr, arg, arg_len) != 0) {
7467 return FALSE;
7468 }
7469 str_itr += arg_len;
7470
7471 if (fc_isalnum(*str_itr)) {
7472 /* Not a distinct word. */
7473 return FALSE;
7474 }
7475
7476 if (!allow_fluff) {
7477 for (; str_itr < rl_line_buffer + start; str_itr++) {
7478 if (fc_isalnum(*str_itr)) {
7479 return FALSE;
7480 }
7481 }
7482 }
7483
7484 return TRUE;
7485}
7486
7487/**********************************************************************/
7492static bool contains_str_before_start(int start, const char *cmd,
7493 bool allow_fluff)
7494{
7495 return contains_token_before_start(start, 0, cmd, allow_fluff);
7496}
7497
7498/**********************************************************************/
7502static bool is_command(int start)
7503{
7504 char *str_itr;
7505
7507 return TRUE;
7508
7509 /* if there is only it is also OK */
7511 while (str_itr - rl_line_buffer < start) {
7512 if (fc_isalnum(*str_itr)) {
7513 return FALSE;
7514 }
7515 str_itr++;
7516 }
7517 return TRUE;
7518}
7519
7520/**********************************************************************/
7523static int num_tokens(int start)
7524{
7525 int res = 0;
7526 bool alnum = FALSE;
7527 char *chptr = rl_line_buffer;
7528
7529 while (chptr - rl_line_buffer < start) {
7530 if (fc_isalnum(*chptr)) {
7531 if (!alnum) {
7532 alnum = TRUE;
7533 res++;
7534 }
7535 } else {
7536 alnum = FALSE;
7537 }
7538 chptr++;
7539 }
7540
7541 return res;
7542}
7543
7544/**************************************************************************
7545 Commands that may be followed by a player name
7546**************************************************************************/
7547static const int player_cmd[] = {
7550 CMD_NOVICE,
7551 CMD_EASY,
7552 CMD_NORMAL,
7553 CMD_HARD,
7555#ifdef FREECIV_DEBUG
7557#endif
7558 CMD_REMOVE,
7559 CMD_TEAM,
7561 -1
7562};
7563
7564/**********************************************************************/
7567static bool is_player(int start)
7568{
7569 int i = 0;
7570
7571 while (player_cmd[i] != -1) {
7573 return TRUE;
7574 }
7575 i++;
7576 }
7577
7578 return FALSE;
7579}
7580
7581/**************************************************************************
7582 Commands that may be followed by a connection name
7583**************************************************************************/
7584static const int connection_cmd[] = {
7585 CMD_CUT,
7586 CMD_KICK,
7587 -1
7588};
7589
7590/**********************************************************************/
7593static bool is_connection(int start)
7594{
7595 int i = 0;
7596
7597 while (connection_cmd[i] != -1) {
7598 if (contains_str_before_start(start,
7600 FALSE)) {
7601 return TRUE;
7602 }
7603 i++;
7604 }
7605
7606 return FALSE;
7607}
7608
7609/**********************************************************************/
7612static bool is_cmdlevel_arg2(int start)
7613{
7615 && num_tokens(start) == 2);
7616}
7617
7618/**********************************************************************/
7621static bool is_cmdlevel_arg1(int start)
7622{
7624}
7625
7626/**************************************************************************
7627 Commands that may be followed by a server option name
7628
7629 CMD_SHOW is handled by option_level_cmd, which is for both option levels
7630 and server options
7631**************************************************************************/
7632static const int server_option_cmd[] = {
7634 CMD_SET,
7636 -1
7637};
7638
7639/**********************************************************************/
7643static bool is_server_option(int start)
7644{
7645 int i = 0;
7646
7647 while (server_option_cmd[i] != -1) {
7649 FALSE)) {
7650 return TRUE;
7651 }
7652 i++;
7653 }
7654
7655 return FALSE;
7656}
7657
7658/**************************************************************************
7659 Commands that may be followed by an option level or server option
7660**************************************************************************/
7661static const int option_level_cmd[] = {
7662 CMD_SHOW,
7663 -1
7664};
7665
7666/**********************************************************************/
7670static bool is_option_level(int start)
7671{
7672 int i = 0;
7673
7674 while (option_level_cmd[i] != -1) {
7676 FALSE)) {
7677 return TRUE;
7678 }
7679 i++;
7680 }
7681
7682 return FALSE;
7683}
7684
7685/**********************************************************************/
7690static bool is_enum_option_value(int start, int *opt_p)
7691{
7693 TRUE)) {
7695 if (setting_type(pset) != SST_ENUM
7696 && setting_type(pset) != SST_BITWISE) {
7697 continue;
7698 }
7699 /* Allow a single token for enum options, multiple for bitwise
7700 * (the separator | will separate tokens for these purposes) */
7704 /* Suppress appended space for bitwise options (user may want |) */
7706 return TRUE;
7707 }
7709 }
7710 return FALSE;
7711}
7712
7713/**************************************************************************
7714 Commands that may be followed by a filename
7715**************************************************************************/
7716static const int filename_cmd[] = {
7717 CMD_LOAD,
7718 CMD_SAVE,
7721 -1
7722};
7723
7724/**********************************************************************/
7727static bool is_filename(int start)
7728{
7729 int i = 0;
7730
7731 while (filename_cmd[i] != -1) {
7733 return TRUE;
7734 }
7735 i++;
7736 }
7737
7738 return FALSE;
7739}
7740
7741/**********************************************************************/
7744static bool is_create_arg2(int start)
7745{
7747 && num_tokens(start) == 2);
7748}
7749
7750/**********************************************************************/
7753static bool is_reset(int start)
7754{
7755 return contains_str_before_start(start,
7757 FALSE);
7758}
7759
7760/**********************************************************************/
7763static bool is_vote(int start)
7764{
7765 return contains_str_before_start(start,
7767 FALSE);
7768}
7769
7770/**********************************************************************/
7773static bool is_delegate_arg1(int start)
7774{
7775 return contains_str_before_start(start,
7777 FALSE);
7778}
7779
7780/**********************************************************************/
7783static bool is_mapimg(int start)
7784{
7785 return contains_str_before_start(start,
7787 FALSE);
7788}
7789
7790/**********************************************************************/
7793static bool is_fcdb(int start)
7794{
7795 return contains_str_before_start(start,
7797 FALSE);
7798}
7799
7800/**********************************************************************/
7803static bool is_lua(int start)
7804{
7805 return contains_str_before_start(start,
7807 FALSE);
7808}
7809
7810/**********************************************************************/
7813static bool is_help(int start)
7814{
7816}
7817
7818/**********************************************************************/
7821static bool is_list(int start)
7822{
7824}
7825
7826/**********************************************************************/
7833char **freeciv_completion(const char *text, int start, int end)
7834{
7835 char **matches = (char **)NULL;
7836
7837 if (is_help(start)) {
7839 } else if (is_command(start)) {
7841 } else if (is_list(start)) {
7843 } else if (is_cmdlevel_arg2(start)) {
7845 } else if (is_cmdlevel_arg1(start)) {
7847 } else if (is_connection(start)) {
7849 } else if (is_player(start)) {
7851 } else if (is_server_option(start)) {
7853 } else if (is_option_level(start)) {
7855 } else if (is_enum_option_value(start, &completion_option)) {
7857 } else if (is_filename(start)) {
7858 /* This function we get from readline */
7860 } else if (is_create_arg2(start)) {
7862 } else if (is_reset(start)) {
7864 } else if (is_vote(start)) {
7866 } else if (is_delegate_arg1(start)) {
7868 } else if (is_mapimg(start)) {
7870 } else if (is_fcdb(start)) {
7872 } else if (is_lua(start)) {
7874 } else {
7875 /* We have no idea what to do */
7876 matches = NULL;
7877 }
7878
7879 /* Don't automatically try to complete with filenames */
7881
7882 return (matches);
7883}
7884
7885#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:251
void astr_free(struct astring *astr)
Definition astring.c:153
const char * astr_build_or_list(struct astring *astr, const char *const *items, size_t number)
Definition astring.c:329
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
#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:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
#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:508
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_list_iterate_end
Definition city.h:510
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:75
#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
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:414
#define MAX_LEN_NAME
Definition fc_types.h:66
#define LINE_BREAK
Definition fc_types.h:77
char * internal_to_local_string_malloc(const char *text)
char * local_to_internal_string_malloc(const char *text)
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
const struct ft_color ftc_log
const struct ft_color ftc_command
const struct ft_color ftc_server
const struct ft_color ftc_any
VAR_ARG_CONST struct ft_color ftc_changed
const struct ft_color ftc_vote_team
const struct ft_color ftc_game_start
const struct ft_color ftc_server_prompt
const struct ft_color ftc_vote_public
#define FT_OFFSET_UNSET
@ TTT_COLOR
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
@ DEBUG_FERRIES
Definition game.h:40
#define GAME_MAX_READ_RECURSION
Definition game.h:748
void send_scenario_description(struct conn_list *dest)
Definition gamehand.c:964
void send_scenario_info(struct conn_list *dest)
Definition gamehand.c:950
void send_game_info(struct conn_list *dest)
Definition gamehand.c:907
void cache_rulesets(void)
Definition gamehand.c:1133
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:2412
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:191
#define __FC_LINE__
Definition log.h:40
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define log_testmatic_alt(altlvl, message,...)
Definition log.h:124
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_normal(message,...)
Definition log.h:107
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:419
int map_startpos_count(void)
Definition map.c:1853
bool map_is_empty(void)
Definition map.c:149
bool mapimg_id2str(int id, char *str, size_t str_len)
Definition mapimg.c:1311
bool mapimg_colortest(const char *savename, const char *path)
Definition mapimg.c:1438
struct mapdef * mapimg_isvalid(int id)
Definition mapimg.c:1121
bool mapimg_define(const char *maparg, bool check)
Definition mapimg.c:769
bool mapimg_delete(int id)
Definition mapimg.c:1204
int mapimg_count(void)
Definition mapimg.c:573
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
Definition mapimg.c:1332
const char * mapimg_error(void)
Definition mapimg.c:759
bool mapimg_show(int id, char *str, size_t str_len, bool detail)
Definition mapimg.c:1223
#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:202
const char * modpack_file_from_ruleset_cache(const char *name)
Definition modpack.c:188
const char * modpack_serv_file(struct section_file *sf)
Definition modpack.c:140
const char * modpack_rulesetdir(struct section_file *sf)
Definition modpack.c:152
#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:567
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
#define player_list_iterate(playerlist, pplayer)
Definition player.h:555
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
#define is_ai(plr)
Definition player.h:230
#define player_list_iterate_end
Definition player.h:557
#define set_as_human(plr)
Definition player.h:231
#define set_as_ai(plr)
Definition player.h:232
#define ANON_PLAYER_NAME
Definition player.h:43
@ PLAYER_DEBUG_DIPLOMACY
Definition player.h:213
@ PLAYER_DEBUG_TECH
Definition player.h:213
#define is_human(plr)
Definition player.h:229
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2268
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1894
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3213
int normal_player_count(void)
Definition plrhand.c:3205
void player_set_under_human_control(struct player *pplayer)
Definition plrhand.c:3452
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition plrhand.c:1823
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Definition plrhand.c:3430
bool server_player_set_name_full(const struct connection *caller, struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Definition plrhand.c:2168
bool player_delegation_active(const struct player *pplayer)
Definition plrhand.c:3267
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:2453
const char * player_color_ftstr(struct player *pplayer)
Definition plrhand.c:1843
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3221
void player_delegation_set(struct player *pplayer, const char *username)
Definition plrhand.c:3251
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1943
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1619
bool player_color_changeable(const struct player *pplayer, const char **reason)
Definition plrhand.c:1717
void assign_player_colors(void)
Definition plrhand.c:1734
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2614
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1212
const char * player_delegation_get(const struct player *pplayer)
Definition plrhand.c:3238
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2590
void reset_all_start_commands(bool plrchange)
Definition plrhand.c:2724
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:50
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 ruleset.c:9367
bool reload_rulesets_settings(void)
Definition ruleset.c:9714
void send_rulesets(struct conn_list *dest)
Definition ruleset.c:9737
#define sanity_check()
Definition sanitycheck.h:43
void savegame_load(struct section_file *sfile)
Definition savemain.c:44
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:152
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:3760
void setting_action(const struct setting *pset)
Definition settings.c:4366
void setting_admin_lock_clear(struct setting *pset)
Definition settings.c:4721
const char * setting_default_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4300
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:4048
struct setting * setting_by_name(const char *name)
Definition settings.c:3306
void setting_set_to_default(struct setting *pset)
Definition settings.c:4336
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4264
const char * setting_extra_help(const struct setting *pset, bool constant)
Definition settings.c:3347
int setting_number(const struct setting *pset)
Definition settings.c:3321
struct setting * setting_by_number(int id)
Definition settings.c:3298
bool setting_int_set(struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3740
bool setting_is_visible(const struct setting *pset, struct connection *caller)
Definition settings.c:3503
bool setting_locked(const struct setting *pset)
Definition settings.c:4673
bool setting_non_default(const struct setting *pset)
Definition settings.c:4647
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3359
void setting_admin_lock_set(struct setting *pset)
Definition settings.c:4701
bool setting_str_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3811
int setting_int_max(const struct setting *pset)
Definition settings.c:3730
bool setting_bitwise_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4220
int settings_number(void)
Definition settings.c:5299
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:3831
const char * setting_enum_val(const struct setting *pset, int val, bool pretty)
Definition settings.c:3890
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
void setting_changed(struct setting *pset)
Definition settings.c:5637
enum setting_default_level setting_get_setdef(const struct setting *pset)
Definition settings.c:5645
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4019
const char * setting_short_help(const struct setting *pset)
Definition settings.c:3338
const char * setting_bitwise_bit(const struct setting *pset, int bit, bool pretty)
Definition settings.c:4085
int setting_int_min(const struct setting *pset)
Definition settings.c:3721
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:4241
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:3685
bool setting_is_changeable(const struct setting *pset, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3457
void settings_reset(void)
Definition settings.c:5265
const char * setting_name(const struct setting *pset)
Definition settings.c:3330
bool settings_game_reset(void)
Definition settings.c:5228
void settings_list_update(void)
Definition settings.c:5566
bool setting_bool_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3654
void send_server_setting(struct conn_list *dest, const struct setting *pset)
Definition settings.c:5308
void send_server_settings(struct conn_list *dest)
Definition settings.c:5427
#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:1101
void remove_trailing_spaces(char *s)
Definition shared.c:421
bool str_to_int(const char *str, int *pint)
Definition shared.c:517
const char * m_pre_description(enum m_pre_result result)
Definition shared.c:1571
struct strvec * fileinfolist(const struct strvec *dirs, const char *suffix)
Definition shared.c:1027
char * skip_leading_spaces(char *s)
Definition shared.c:388
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:1613
const struct strvec * get_scenario_dirs(void)
Definition shared.c:978
void interpret_tilde(char *buf, size_t buf_size, const char *filename)
Definition shared.c:1720
const struct strvec * get_save_dirs(void)
Definition shared.c:941
void remove_leading_spaces(char *s)
Definition shared.c:403
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:1590
bool is_safe_filename(const char *name)
Definition shared.c:253
void remove_leading_trailing_spaces(char *s)
Definition shared.c:444
const struct strvec * get_data_dirs(void)
Definition shared.c:893
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)
Definition shared.c:1211
#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:176
#define MAX_LEN_PATH
Definition shared.h:32
m_pre_result
Definition shared.h:207
@ M_PRE_EXACT
Definition shared.h:208
@ M_PRE_ONLY
Definition shared.h:209
@ M_PRE_LAST
Definition shared.h:214
@ M_PRE_LONG
Definition shared.h:212
@ M_PRE_AMBIGUOUS
Definition shared.h:210
@ M_PRE_EMPTY
Definition shared.h:211
@ M_PRE_FAIL
Definition shared.h:213
#define fileinfo_list_iterate_end
Definition shared.h:178
const char *(* m_pre_accessor_fn_t)(int)
Definition shared.h:220
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:3464
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2581
bool force_end_of_sniff
Definition srv_main.c:188
void start_game(void)
Definition srv_main.c:1838
const char * aifill(int amount)
Definition srv_main.c:2466
void set_server_state(enum server_states newstate)
Definition srv_main.c:341
bool game_was_started(void)
Definition srv_main.c:349
struct server_arguments srvarg
Definition srv_main.c:176
void check_for_full_turn_done(void)
Definition srv_main.c:2216
void fc__noreturn server_quit(void)
Definition srv_main.c:1875
enum server_states server_state(void)
Definition srv_main.c:333
void server_game_free(void)
Definition srv_main.c:3488
#define TOKEN_DELIMITERS
Definition srvdefs.h:20
static bool write_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:1345
static const char * reset_accessor(int i)
Definition stdinhand.c:4839
static bool set_cmdlevel(struct connection *caller, struct connection *ptarget, enum cmdlevel level)
Definition stdinhand.c:1384
static struct setting * validate_setting_arg(enum command_id cmd, struct connection *caller, char *arg)
Definition stdinhand.c:2936
#define LOOKUP_OPTION_AMBIGUOUS
Definition stdinhand.c:1735
static const char * mapimg_accessor(int i)
Definition stdinhand.c:5688
void cmd_reply(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *format,...)
Definition stdinhand.c:423
static bool set_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2970
static enum command_id cmd_of_level(enum ai_level level)
Definition stdinhand.c:1987
static void show_delegations(struct connection *caller)
Definition stdinhand.c:6693
static char setting_status(struct connection *caller, const struct setting *pset)
Definition stdinhand.c:310
static void show_scenarios(struct connection *caller)
Definition stdinhand.c:6919
static bool delegate_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5198
static bool ignore_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4083
static void show_help_command(struct connection *caller, enum command_id help_cmd, enum command_id id)
Definition stdinhand.c:6447
void set_running_game_access_level(void)
Definition stdinhand.c:1639
void notify_if_first_access_level_is_available(void)
Definition stdinhand.c:1455
static const char * lua_accessor(int i)
Definition stdinhand.c:4999
static const char * fcdb_accessor(int i)
Definition stdinhand.c:5996
static void show_help_command_list(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:6493
void stdinhand_turn(void)
Definition stdinhand.c:259
static void show_connections(struct connection *caller)
Definition stdinhand.c:6667
static bool explain_option(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1901
static struct kick_hash * kick_table_by_user
Definition stdinhand.c:120
static void show_ais(struct connection *caller)
Definition stdinhand.c:7033
bool conn_is_kicked(struct connection *pconn, int *time_remaining)
Definition stdinhand.c:6285
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:815
static void show_colors(struct connection *caller)
Definition stdinhand.c:7048
static bool set_ai_level(struct connection *caller, const char *name, enum ai_level level, bool check)
Definition stdinhand.c:2034
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:1865
static bool lock_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3150
void stdinhand_init(void)
Definition stdinhand.c:246
static bool take_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3500
static bool wall(char *str, bool check)
Definition stdinhand.c:1934
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:2131
void show_players(struct connection *caller)
Definition stdinhand.c:6757
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:6531
#define LOOKUP_OPTION_NO_RESULT
Definition stdinhand.c:1734
static const char * list_accessor(int i)
Definition stdinhand.c:7097
static int lookup_option(const char *name)
Definition stdinhand.c:1746
static bool reset_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:4849
static void show_teams(struct connection *caller)
Definition stdinhand.c:6982
static bool handle_stdin_input_real(struct connection *caller, char *str, bool check, int read_recursion)
Definition stdinhand.c:4460
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:1003
static bool metaconnection_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:532
static bool show_serverid(struct connection *caller, char *arg)
Definition stdinhand.c:665
static void show_nationsets(struct connection *caller)
Definition stdinhand.c:6945
static const char * helparg_accessor(int i)
Definition stdinhand.c:6587
static bool metamessage_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:613
static bool away_command(struct connection *caller, bool check)
Definition stdinhand.c:2090
enum cmdlevel access_level_for_next_connection(void)
Definition stdinhand.c:1441
static bool playercolor_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4207
bool handle_stdin_input_free(struct connection *caller, char *str)
Definition stdinhand.c:4441
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2009
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:4956
static bool create_command(struct connection *caller, const char *str, bool check)
Definition stdinhand.c:757
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:383
static const char * delegate_accessor(int i)
Definition stdinhand.c:5189
static void show_rulesets(struct connection *caller)
Definition stdinhand.c:6896
static bool surrender_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4791
static bool end_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4766
static const char * delegate_player_str(struct player *pplayer, bool observer)
Definition stdinhand.c:5649
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:1737
static bool timeout_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1676
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:436
static bool metaserver_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:647
bool handle_stdin_input(struct connection *caller, char *str)
Definition stdinhand.c:4433
static bool cut_client_connection(struct connection *caller, char *name, bool check)
Definition stdinhand.c:6242
static void open_metaserver_connection(struct connection *caller, bool persistent)
Definition stdinhand.c:505
#define HELP_ARG_NUM
Definition stdinhand.c:6582
static time_t * time_duplicate(const time_t *t)
Definition stdinhand.c:6274
static void show_mapimg(struct connection *caller, enum command_id cmd)
Definition stdinhand.c:7012
static bool may_use_nothing(struct connection *caller)
Definition stdinhand.c:298
static void show_votes(struct connection *caller)
Definition stdinhand.c:2479
static const char *const vote_args[]
Definition stdinhand.c:2514
static bool show_settings(struct connection *caller, enum command_id called_as, char *str, bool check)
Definition stdinhand.c:2166
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
Definition stdinhand.c:1176
static bool unlock_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3178
static bool a_connection_exists(void)
Definition stdinhand.c:1419
void stdinhand_free(void)
Definition stdinhand.c:267
static bool cmdlevel_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1469
static bool is_first_access_level_taken(void)
Definition stdinhand.c:1427
#define LOOKUP_OPTION_LEVEL_NAME
Definition stdinhand.c:1736
static bool firstlevel_command(struct connection *caller, bool check)
Definition stdinhand.c:1612
static void start_cmd_reply(struct connection *caller, bool notify, char *msg)
Definition stdinhand.c:6108
static bool connectmsg_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:1946
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:471
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:336
static void show_help_intro(struct connection *caller, enum command_id help_cmd)
Definition stdinhand.c:6414
static bool cancelvote_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:2633
bool set_rulesetdir(struct connection *caller, const char *str, bool check, int read_recursion)
Definition stdinhand.c:3982
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Definition stdinhand.c:3795
static bool read_init_script_real(struct connection *caller, const char *script_filename, bool from_cmdline, bool check, int read_recursion)
Definition stdinhand.c:1194
static void show_settings_one(struct connection *caller, enum command_id cmd, struct setting *pset)
Definition stdinhand.c:2338
static bool toggle_ai_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:734
static bool playernation_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4292
static bool team_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2402
static bool quit_game(struct connection *caller, bool check)
Definition stdinhand.c:4419
static bool vote_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2528
#define cmd_reply_show(string)
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6119
static const char * optname_accessor(int i)
Definition stdinhand.c:1652
static bool show_help(struct connection *caller, char *arg)
Definition stdinhand.c:6605
#define OPTION_NAME_SPACE
Definition stdinhand.c:99
struct strvec * get_init_script_choices(void)
Definition stdinhand.c:1277
static bool remove_player_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:1130
static void ruleset_cache_listcmd_cb(const char *mp_name, const char *filename, void *data_in)
Definition stdinhand.c:6857
static bool debug_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:2728
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:6005
static bool mapimg_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5697
static bool unignore_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:4118
static bool observe_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3352
static bool show_list(struct connection *caller, char *arg)
Definition stdinhand.c:7106
static bool scensave_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:693
static enum sset_level lookup_option_level(const char *name)
Definition stdinhand.c:1720
static bool may_use(struct connection *caller, enum command_id cmd)
Definition stdinhand.c:286
static bool kick_command(struct connection *caller, char *name, bool check)
Definition stdinhand.c:6333
static const char * vote_arg_accessor(int i)
Definition stdinhand.c:2520
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:2156
static bool lua_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:5008
static bool write_init_script(char *script_filename)
Definition stdinhand.c:1287
static enum cmdlevel first_access_level
Definition stdinhand.c:102
static bool detach_command(struct connection *caller, char *str, bool check)
Definition stdinhand.c:3689
static bool aicmd_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:5922
static void close_metaserver_connection(struct connection *caller)
Definition stdinhand.c:519
static bool save_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:676
static bool set_ai_level_named(struct connection *caller, const char *name, const char *level_name, bool check)
Definition stdinhand.c:2023
static bool metapatches_command(struct connection *caller, char *arg, bool check)
Definition stdinhand.c:588
static bool show_ignore(struct connection *caller)
Definition stdinhand.c:6727
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:3210
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:709
static void show_help_option(struct connection *caller, enum command_id help_cmd, int id)
Definition stdinhand.c:1775
static bool read_command(struct connection *caller, char *arg, bool check, int read_recursion)
Definition stdinhand.c:1167
Definition ai.h:50
struct ai_type::@14 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:320
struct city::@17::@19 server
bool debug
Definition city.h:450
int kick_time
Definition game.h:157
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:193
bool debug[DEBUG_LAST]
Definition game.h:206
char connectmsg[MAX_LEN_MSG]
Definition game.h:223
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:170
int timeoutcounter
Definition game.h:211
char rulesetdir[MAX_LEN_NAME]
Definition game.h:242
struct packet_scenario_info scenario
Definition game.h:87
int timeoutint
Definition game.h:207
struct conn_list * all_connections
Definition game.h:96
char save_name[MAX_LEN_NAME]
Definition game.h:224
struct civ_game::@31::@35 server
int timeoutincmult
Definition game.h:209
int timeoutinc
Definition game.h:208
char allow_take[MAX_LEN_ALLOW_TAKE]
Definition game.h:244
bool start_city
Definition game.h:194
int max_players
Definition game.h:160
int timeoutintinc
Definition game.h:210
Definition colors.h:21
struct player * playing
Definition connection.h:151
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
struct connection::@58::@64 server
enum auth_status status
Definition connection.h:217
char ipaddr[MAX_LEN_ADDR]
Definition connection.h:221
struct connection::@58::@64::@65 delegation
struct conn_pattern_list * ignore_list
Definition connection.h:230
struct connection * caller
Definition stdinhand.c:6851
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:114
bool random_name
Definition player.h:293
struct player_ai ai_common
Definition player.h:286
bv_pstatus status
Definition player.h:320
bool is_male
Definition player.h:255
struct government * target_government
Definition player.h:257
char username[MAX_LEN_NAME]
Definition player.h:250
bool is_connected
Definition player.h:294
struct government * government
Definition player.h:256
bool was_created
Definition player.h:292
const struct ai_type * ai
Definition player.h:287
struct unit_list * units
Definition player.h:280
struct conn_list * connections
Definition player.h:296
bool is_alive
Definition player.h:266
struct nation_style * style
Definition player.h:277
struct player::@70::@72 server
bv_debug debug
Definition player.h:330
struct rgbcolor * rgb
Definition player.h:310
bool unassigned_user
Definition player.h:251
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:41
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition timing.c:81
Definition unit.h:138
bool debug
Definition unit.h:234
struct unit::@81::@84 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:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:900
FILE * fc_fopen(const char *filename, const char *opentype)
Definition support.c:507
int fc_break_lines(char *str, size_t desired_len)
Definition support.c:1149
int fc_stat(const char *filename, struct stat *buf)
Definition support.c:576
bool is_reg_file_for_access(const char *name, bool write_access)
Definition support.c:1134
bool fc_isalnum(char c)
Definition support.c:1210
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Definition support.c:238
#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:264
struct timer * timer_new(enum timer_timetype type, enum timer_use use, const char *name)
Definition timing.c:160
double timer_read_seconds(struct timer *t)
Definition timing.c:384
@ 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:396
#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:1569
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