14 #include <fc_config.h>
22 #include <QCoreApplication>
23 #include <QRegularExpression>
25 #include <readline/readline.h>
86 #define OPTION_NAME_SPACE 25
87 #define REG_EXP "\\s+(?=([^\"]*\"[^\"]*\")*[^\"]*$)"
101 const char *level_name,
bool check);
103 enum ai_level
level,
bool check);
109 enum command_id called_as,
char *str,
bool check);
113 bool check,
int read_recursion);
123 bool check,
int read_recursion);
125 const char *script_filename,
126 bool from_cmdline,
bool check,
153 static const char horiz_line[] =
"------------------------------------------"
154 "------------------------------------";
157 static bool static_should_quit =
false;
162 for (QString &a : str) {
163 a = a.remove(QChar(
'\"'));
185 fc_snprintf(buf, buflen,
_(
"Can't use an empty name."));
188 fc_snprintf(buf, buflen,
_(
"That name exceeds the maximum of %d chars."),
193 fc_snprintf(buf, buflen,
_(
"That name is not allowed."));
211 bool accept_ambiguity)
217 nullptr, token, &ind);
246 kick_table_by_addr->clear();
247 kick_table_by_user->clear();
319 cmdname, prefix, line);
329 struct packet_chat_msg packet;
335 if (caller != pconn) {
336 send_packet_chat_msg(pconn, &packet);
342 if (
nullptr != caller) {
355 const char *format, va_list ap)
363 while ((c1 = strstr(c0,
"\n"))) {
378 const char *format, ...)
382 const
char *format, ...)
385 va_start(ap, format);
397 va_start(ap, format);
411 switch (match_result) {
414 _(
"Name is empty, so cannot be a player."));
418 _(
"Name is too long, so cannot be a player."));
422 _(
"Player name prefix '%s' is ambiguous."),
name);
430 _(
"Unexpected match_result %d (%s) for '%s'."), match_result,
432 qCritical(
"Unexpected match_result %d (%s) for '%s'.", match_result,
446 switch (match_result) {
449 _(
"Name is empty, so cannot be a connection."));
453 _(
"Name is too long, so cannot be a connection."));
457 _(
"Connection name prefix '%s' is ambiguous."),
name);
465 _(
"Unexpected match_result %d (%s) for '%s'."), match_result,
467 qCritical(
"Unexpected match_result %d (%s) for '%s'.", match_result,
481 _(
"Open metaserver connection to [%s]."),
494 _(
"Close metaserver connection to [%s]."),
505 bool persistent =
false;
507 if ((*arg ==
'\0') || (!strcmp(arg,
"?"))) {
510 _(
"Metaserver connection is open."));
513 _(
"Metaserver connection is closed."));
529 _(
"Metaserver connection is already open."));
539 _(
"Metaserver connection is already closed."));
544 _(
"Argument must be 'u', 'up', 'd', 'down', 'p', "
545 "'persistent', or '?'."));
566 _(
"Metaserver patches string set to '%s'."), arg);
569 _(
"Metaserver patches string set to '%s', "
570 "not reporting to metaserver."),
593 _(
"Metaserver message string set to '%s'."), arg);
596 _(
"Metaserver message string set to '%s', "
597 "not reporting to metaserver."),
646 _(
"You cannot save games manually on this server."));
664 _(
"You cannot save games manually on this server."));
691 _(
"%s is now under human control."),
player_name(pplayer));
732 QString ai_type_name;
735 arg = QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
737 if (arg.count() == 1) {
739 }
else if (arg.count() == 2) {
740 ai_type_name = arg.at(1);
743 _(
"Wrong number of arguments to create command."));
749 qUtf8Printable(ai_type_name), check,
750 nullptr,
nullptr, buf,
sizeof(buf));
753 qUtf8Printable(ai_type_name), check,
754 nullptr, buf,
sizeof(buf));
763 if (strlen(buf) > 0) {
783 struct player **newplayer,
char *buf,
786 struct player *pplayer =
nullptr;
788 bool new_slot =
false;
800 _(
"A living user already exists by that name."));
808 _(
"A living player already exists by that name."));
815 _(
"Can't create player, requested nation %s not in "
816 "current nation set."),
824 _(
"Can't create players, nation %s conflicts with %s."),
833 pnation =
pick_a_nation(
nullptr,
false,
true, NOT_A_BARBARIAN);
836 _(
"Can't create players, no nations available."));
853 _(
"%s is replacing dead player %s as an AI-controlled "
863 if (!aplayer->is_alive) {
865 _(
"%s is replacing dead player %s as an AI-controlled "
883 log_debug(
"Increased 'maxplayers' for creation of a new player.");
912 cat_snprintf(buf, buflen,
_(
" Nation of the new player: %s."),
937 if (newplayer !=
nullptr) {
938 *newplayer = pplayer;
947 bool check,
struct player **newplayer,
948 char *buf,
size_t buflen)
951 struct player *pplayer =
nullptr;
952 bool rand_name =
false;
954 if (
name[0] ==
'\0') {
958 fc_snprintf(leader_name,
sizeof(leader_name),
"%s*%d",
ai, filled++);
970 fc_snprintf(buf, buflen,
_(
"A player already exists by that name."));
974 fc_snprintf(buf, buflen,
_(
"A user already exists by that name."));
981 if (
nullptr == pplayer) {
984 fc_snprintf(buf, buflen,
_(
"Can't add more players, server is full."));
991 _(
"Can't add more players, not enough playable nations "
992 "in current nation set (see 'nationset' setting)."));
996 _(
"Can't add more players, not enough playable nations."));
1005 if (ait ==
nullptr) {
1006 fc_snprintf(buf, buflen,
_(
"There is no AI type %s."), ai);
1023 _(
"%s replacing %s as an AI-controlled player."),
name,
1038 _(
"%s has been added as an AI-controlled player (%s)."),
1058 if (newplayer !=
nullptr) {
1059 *newplayer = pplayer;
1076 if (
nullptr == pplayer) {
1083 _(
"Command level '%s' or greater needed to remove a player "
1084 "once the game has started."),
1085 cmdlevel_name(ALLOW_ADMIN));
1094 if (!caller || caller->
used) {
1096 _(
"Removed player %s from the game."),
name);
1115 bool from_cmdline,
bool check)
1133 const char *script_filename,
1134 bool from_cmdline,
bool check,
1138 const auto extension = QLatin1String(
".serv");
1142 qCritical(
"Error: recursive calls to read!");
1147 QString serv_filename = script_filename;
1148 if (!serv_filename.endsWith(extension)) {
1149 serv_filename += extension;
1152 QString tilde_filename;
1156 _(
"Name \"%s\" disallowed for security reasons."),
1157 qUtf8Printable(serv_filename));
1160 tilde_filename = serv_filename;
1166 if (real_filename.isEmpty()) {
1169 _(
"No command script found by the name \"%s\"."),
1170 qUtf8Printable(serv_filename));
1174 real_filename = tilde_filename;
1177 qInfo(
_(
"Loading script file '%s'."), qUtf8Printable(real_filename));
1179 if (QFile::exists(real_filename)
1180 && (script_file =
fc_fopen(qUtf8Printable(real_filename),
"r"))) {
1188 read_recursion + 1)) {
1190 qCritical() << buffer;
1195 fclose(script_file);
1202 _(
"Cannot read command line scriptfile '%s'."),
1203 qUtf8Printable(real_filename));
1204 if (
nullptr != caller) {
1205 qCritical(
_(
"Could not read script file '%s'."),
1206 qUtf8Printable(real_filename));
1235 if (QFile::exists(real_filename)
1236 && (script_file =
fc_fopen(qUtf8Printable(real_filename),
"w"))) {
1237 fprintf(script_file,
"#FREECIV SERVER COMMAND FILE, version %s\n",
1240 "# These are server options saved from a running freeciv-server.\n",
1245 fprintf(script_file,
"rulesetdir %s\n",
game.
server.rulesetdir);
1249 fprintf(script_file,
"cmdlevel %s new\n",
1252 fprintf(script_file,
"cmdlevel %s first\n",
1255 fprintf(script_file,
"%s\n",
1261 fprintf(script_file,
"metaserver %s\n",
1280 fprintf(script_file,
"set %s \"%s\"\n",
setting_name(pset),
1285 fclose(script_file);
1288 qCritical(
_(
"Could not write script file '%s'."),
1289 qUtf8Printable((real_filename)));
1300 _(
"You cannot use the write command on this server"
1301 " for security reasons."));
1303 }
else if (!check) {
1328 _(
"Cannot decrease command access level '%s' "
1329 "for connection '%s'; you only have '%s'."),
1336 _(
"Command access level set to '%s' for connection %s."),
1387 _(
"Anyone can now become game organizer "
1388 "'%s' by issuing the 'first' command."),
1402 enum cmdlevel
level;
1405 arg = QString(str).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
1407 if (arg.count() == 0) {
1411 _(
"Command access levels in effect:"));
1417 if (lvl_name !=
nullptr) {
1419 lvl_name, pconn->username);
1426 _(
"Command access level for new connections: %s"),
1429 _(
"Command access level for first player to take it: %s"),
1437 if (!cmdlevel_is_valid(
level)) {
1439 cmdlevel_names.reserve(CMDLEVEL_COUNT);
1441 for (
level = cmdlevel_begin();
level != cmdlevel_end();
1443 cmdlevel_names.append(cmdlevel_name(
level));
1447 _(
"Command access level must be one of %s."),
1452 _(
"Cannot increase command access level to '%s';"
1453 " you only have '%s' yourself."),
1454 qUtf8Printable(arg.at(0)),
1463 if (arg.count() == 1) {
1467 if (pconn != caller) {
1482 _(
"Command access level set to '%s' for new players."),
1483 cmdlevel_name(
level));
1487 _(
"Command access level set to '%s' "
1488 "for first player to grab it."),
1489 cmdlevel_name(
level));
1493 }
else if (
fc_strcasecmp(qUtf8Printable(arg.at(1)),
"new") == 0) {
1496 _(
"Command access level set to '%s' for new players."),
1497 cmdlevel_name(
level));
1501 _(
"Command access level set to '%s' "
1502 "for first player to grab it."),
1503 cmdlevel_name(
level));
1508 }
else if (
fc_strcasecmp(qUtf8Printable(arg.at(1)),
"first") == 0) {
1511 _(
"Command access level set to '%s' "
1512 "for first player to grab it."),
1513 cmdlevel_name(
level));
1517 _(
"Command access level set to '%s' for new players."),
1518 cmdlevel_name(
level));
1546 _(
"The 'first' command makes no sense from the server command "
1551 _(
"You already have command access level '%s' or better."),
1556 _(
"Someone else is already game organizer."));
1558 }
else if (!check) {
1561 _(
"Connection %s has opted to become the game organizer."),
1574 _(
"Default cmdlevel lowered to 'basic' on game start."));
1594 return "rulesetdir";
1595 }
else if (i < OLEVELS_NUM + 1) {
1596 return sset_level_name(sset_level(i - 1));
1615 _(
"The timeout is currently disabled."));
1622 _(
"The 'timeout' setting is: %6d s = %s"),
1627 _(
"The game is currently not running."));
1632 const int lasted = timer +
game.
server.additional_phase_seconds;
1635 _(
"The current phase has now lasted: %6d s = %s"), lasted, buf);
1637 const int left =
game.
tinfo.seconds_to_phasedone - lasted;
1640 _(
"Time left: %6d s = %s"), left, buf);
1655 _(
"Cannot change the turn timeout while the game is not running."));
1657 }
else if (
game.
info.timeout <= 0) {
1660 _(
"The timeout is disabled, use /set timeout."));
1665 const auto parts = QString(str).split(
':');
1666 if (
parts.size() > 3) {
1671 bool ok[3] = {
true,
true,
true};
1672 int h =
parts.size() > 2 ?
parts.front().toInt(&ok[0]) : 0;
1674 int s =
parts.size() > 0 ?
parts.back().toInt(&ok[2]) : 0;
1675 if (!ok[0] || !ok[1] || !ok[2]) {
1680 int seconds = 3600 * h + 60 * m + s;
1681 if (seconds > 86400 * 365) {
1695 game.
tinfo.seconds_to_phasedone += seconds;
1697 _(
"Adding %d seconds to the current timeout"), seconds);
1699 game.
tinfo.seconds_to_phasedone = timer_now + seconds;
1701 _(
"Setting the remaining time to %d seconds"), seconds);
1726 arg = QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
1728 for (i = 0; i < arg.count(); i++) {
1729 if (!
str_to_int(qUtf8Printable(arg.at(i)), timeouts[i])) {
1731 _(
"Invalid argument %d."), i + 1);
1735 if (arg.isEmpty()) {
1744 _(
"Dynamic timeout set to "
1761 for (i = SSET_ALL; i < OLEVELS_NUM; i++) {
1763 return sset_level(i);
1771 #define LOOKUP_OPTION_NO_RESULT (-1)
1772 #define LOOKUP_OPTION_AMBIGUOUS (-2)
1773 #define LOOKUP_OPTION_LEVEL_NAME (-3)
1774 #define LOOKUP_OPTION_RULESETDIR (-4)
1799 }
else if (
'\0' !=
name[0]
1815 char val_buf[256], def_buf[256];
1817 const char *sethelp;
1831 if (strlen(sethelp) > 0) {
1853 _(
"Default:"), def_buf,
_(
"Maximum:"),
1870 val_buf,
_(
"Default:"), def_buf);
1877 _(
"Possible values (option can take any number of these):"));
1904 _(
"Explanations are available for the following server options:"));
1921 if ((++j % 4) == 0) {
1929 if (buf[0] !=
'\0') {
1953 _(
"No explanation for that yet."));
1959 qCritical(
"Unexpected case %d in %s line %d", cmd, __FILE__,
1972 static bool wall(
char *str,
bool check)
1976 _(
"Server Operator: %s"), str);
1987 unsigned int bufsize =
sizeof(
game.
server.connectmsg);
1996 for (i = 0; c < bufsize - 1 && str[i] !=
'\0'; i++) {
1997 if (str[i] ==
'\\') {
2000 if (str[i] ==
'n') {
2015 _(
"Connectmsg truncated to %u bytes."), bufsize);
2030 case AI_LEVEL_HANDICAPPED:
2032 case AI_LEVEL_NOVICE:
2036 case AI_LEVEL_NORMAL:
2040 case AI_LEVEL_CHEATING:
2042 #ifdef FREECIV_DEBUG
2043 case AI_LEVEL_EXPERIMENTAL:
2044 return CMD_EXPERIMENTAL;
2046 case AI_LEVEL_COUNT:
2049 qCritical(
"Unknown AI level variant: %d.",
level);
2061 _(
"Player '%s' now has AI skill level '%s'."),
2069 const char *level_name,
bool check)
2080 enum ai_level
level,
bool check)
2090 if (
is_ai(pplayer)) {
2097 _(
"Player '%s' now has AI skill level '%s'."),
2101 _(
"%s is not controlled by the AI."),
player_name(pplayer));
2110 if (
is_ai(cplayer)) {
2114 _(
"Player '%s' now has AI skill level '%s'."),
2122 _(
"Default AI skill level set to '%s'."),
2123 ai_level_translated_name(
level));
2139 if (caller ==
nullptr) {
2147 _(
"Only players may use the away command."));
2177 bool check,
int read_recursion)
2182 if (read_recursion != 0) {
2185 show_arg = strdup(
"changed");
2214 enum command_id called_as,
char *str,
bool check)
2217 enum sset_level
level = SSET_ALL;
2221 if (str[0] !=
'\0') {
2231 _(
"Sorry, you do not have access to view option '%s'."),
2244 clen = qstrlen(str);
2253 _(
"Current ruleset directory is \"%s\""),
2269 #define cmd_reply_show(string) \
2270 cmd_reply(called_as, caller, C_COMMENT, "%s", string)
2273 const char *heading =
nullptr;
2278 heading =
_(
"All options with non-default values");
2281 heading =
_(
"All options");
2284 heading =
_(
"Vital options");
2286 case SSET_SITUATIONAL:
2287 heading =
_(
"Situational options");
2290 heading =
_(
"Rarely used options");
2293 heading =
_(
"Options locked by the ruleset");
2305 cmd_reply_show(
_(
"In the column '##' the status of the option is shown:"));
2306 cmd_reply_show(
_(
" - a '!' means the option is locked by the ruleset."));
2308 cmd_reply_show(
_(
" - a '~' means that option follows default value."));
2331 case SSET_SITUATIONAL:
2357 cmd_reply_show(
_(
"A help text for each option is available via 'help "
2360 if (
level == SSET_VITAL) {
2363 "Try 'show changed' to show settings with "
2364 "non-default values.\n"
2365 "Try 'show locked' to show settings locked "
2366 "by the ruleset."));
2371 #undef cmd_reply_show
2404 if (prefix[0] ==
'\0') {
2405 memset(prefix,
' ',
sizeof(prefix) - 1);
2420 char *p = strchr(nl,
'\n');
2435 }
else if (is_changed) {
2460 _(
"Cannot change teams once game has begun."));
2464 if (str !=
nullptr || qstrlen(str) > 0) {
2467 QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
2469 for (
const auto &a : qAsConst(arg)) {
2473 if (arg.count() != 2) {
2475 _(
"Undefined argument. Usage:\n%s"),
2481 if (pplayer ==
nullptr) {
2488 if (
nullptr == tslot) {
2491 if (
str_to_int(qUtf8Printable(arg.at(1)), &teamno)) {
2495 if (
nullptr == tslot) {
2497 _(
"No such team %s. Please give a "
2498 "valid team name or number."),
2499 qUtf8Printable(arg.at(1)));
2538 _(
"%s %d \"%s\" (needs %0.0f%%%s): %d for, "
2539 "%d against, and %d abstained out of %d players."),
2540 title, pvote->vote_no, pvote->cmdline,
2541 MIN(100, pvote->need_pc * 100 + 1),
2544 pvote->yes, pvote->no, pvote->abstain,
count_voters(pvote));
2552 _(
"There are no votes going on."));
2559 static const char *
const vote_args[] = {
"yes",
"no",
"abstain",
nullptr};
2569 int i = 0, which = -1;
2571 struct vote *pvote =
nullptr;
2581 arg = QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
2583 if (arg.isEmpty()) {
2588 _(
"You are not allowed to use this command."));
2593 nullptr, qUtf8Printable(arg.at(0)), &i);
2597 _(
"The argument \"%s\" is ambiguous."),
2598 qUtf8Printable(arg.at(0)));
2603 _(
"Undefined argument. Usage:\n%s"),
2608 if (arg.count() == 1) {
2613 int num_votes = vote_list_size(
vote_list);
2614 if (num_votes == 0) {
2616 _(
"There are no votes running."));
2622 PL_(
"other vote running",
"other votes running", num_votes));
2627 if (!
str_to_int(qUtf8Printable(arg.at(1)), &which)) {
2641 _(
"You are not allowed to vote on that."));
2655 _(
"You abstained from voting on \"%s\""), pvote->
cmdline);
2670 struct vote *pvote =
nullptr;
2682 if (arg[0] ==
'\0') {
2683 if (caller ==
nullptr) {
2687 _(
"Missing argument <vote number> or "
2688 "the string \"all\"."));
2694 _(
"You don't have any vote going on."));
2701 _(
"There isn't any vote going on."));
2707 _(
"All votes have been removed."));
2711 _(
"You are not allowed to use this command."));
2726 _(
"You are not allowed to cancel this vote (%d)."),
vote_no);
2732 _(
"Usage: /cancelvote [<vote number>|all]"));
2742 _(
"%s has canceled the vote \"%s\" (number %d)."),
2749 _(
"The vote \"%s\" (number %d) has been canceled."),
2768 _(
"Can only use this command once game has begun."));
2775 if (str !=
nullptr && qstrlen(str) > 0) {
2778 QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
2783 && strcmp(qUtf8Printable(arg.at(0)),
"diplomacy") == 0) {
2787 if (arg.count() != 2) {
2789 _(
"Undefined argument. Usage:\n%s"),
2795 if (pplayer ==
nullptr) {
2803 _(
"%s diplomacy no longer debugged"),
player_name(pplayer));
2810 }
else if (arg.count() > 0
2811 && strcmp(qUtf8Printable(arg.at(0)),
"tech") == 0) {
2815 if (arg.count() != 2) {
2817 _(
"Undefined argument. Usage:\n%s"),
2823 if (pplayer ==
nullptr) {
2838 }
else if (arg.count() && strcmp(qUtf8Printable(arg.at(0)),
"info") == 0) {
2839 int cities = 0, players = 0,
units = 0, citizen_count = 0;
2850 units += unit_list_size(plr->units);
2853 qInfo(
_(
"players=%d cities=%d citizens=%d units=%d"), players,
cities,
2854 citizen_count,
units);
2856 _(
"players=%d cities=%d citizens=%d units=%d"), players,
2858 }
else if (arg.count() && strcmp(qUtf8Printable(arg.at(0)),
"city") == 0) {
2863 if (arg.count() != 3) {
2865 _(
"Undefined argument. Usage:\n%s"),
2869 if (!
str_to_int(qUtf8Printable(arg.at(1)), &x)
2870 || !
str_to_int(qUtf8Printable(arg.at(2)), &y)) {
2872 _(
"Value 2 & 3 must be integer."));
2882 _(
"No city at this coordinate."));
2885 if (pcity->
server.debug) {
2886 pcity->
server.debug =
false;
2890 pcity->
server.debug =
true;
2893 }
else if (arg.count()
2894 && strcmp(qUtf8Printable(arg.at(0)),
"units") == 0) {
2898 if (arg.count() != 3) {
2900 _(
"Undefined argument. Usage:\n%s"),
2904 if (!
str_to_int(qUtf8Printable(arg.at(1)), &x)
2905 || !
str_to_int(qUtf8Printable(arg.at(2)), &y)) {
2907 _(
"Value 2 & 3 must be integer."));
2916 if (punit->server.debug) {
2917 punit->server.debug =
false;
2922 punit->server.debug =
true;
2929 }
else if (arg.count()
2930 && strcmp(qUtf8Printable(arg.at(0)),
"timing") == 0) {
2932 }
else if (arg.count() > 0
2933 && strcmp(qUtf8Printable(arg.at(0)),
"ferries") == 0) {
2937 _(
"Ferry system is no longer "
2943 }
else if (arg.count() > 0
2944 && strcmp(qUtf8Printable(arg.at(0)),
"unit") == 0) {
2948 if (arg.count() != 2) {
2950 _(
"Undefined argument. Usage:\n%s"),
2954 if (!
str_to_int(qUtf8Printable(arg.at(1)), &
id)) {
2963 if (punit->
server.debug) {
2964 punit->
server.debug =
false;
2969 punit->
server.debug =
true;
2976 _(
"Undefined argument. Usage:\n%s"),
3005 _(
"Use the '%srulesetdir' command to change the ruleset "
3028 char reject_msg[256] =
"";
3032 args = QString(str).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
3035 if (args.count() < 2) {
3037 _(
"Undefined argument. Usage:\n%s"),
3043 CMD_SET, caller,
const_cast<char *
>(qUtf8Printable(args.at(0))));
3065 sizeof(reject_msg)))) {
3070 reject_msg,
sizeof(reject_msg))) {
3079 if (!
str_to_int(qUtf8Printable(args.at(1)), &val)) {
3081 _(
"The parameter %s should only contain +- and 0-9."),
3089 sizeof(reject_msg))) {
3095 sizeof(reject_msg))) {
3109 reject_msg,
sizeof(reject_msg))) {
3115 reject_msg,
sizeof(reject_msg))) {
3130 sizeof(reject_msg)))) {
3135 reject_msg,
sizeof(reject_msg))) {
3149 sizeof(reject_msg)))) {
3154 reject_msg,
sizeof(reject_msg))) {
3169 if (!check && do_update) {
3172 struct packet_chat_msg packet;
3180 send_packet_chat_msg(pconn, &packet);
3212 struct player *pplayer,
bool will_obs,
3213 char *msg,
size_t msg_len)
3217 if (!pplayer && !will_obs) {
3221 fc_strlcpy(msg,
_(
"You cannot take a new player at this time."),
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).",
3242 _(
"You cannot take a new player because there "
3243 "are no free player slots."),
3259 if (!pplayer && will_obs) {
3262 (
game.
info.is_new_game ?
'O' :
'o')))) {
3263 fc_strlcpy(msg,
_(
"Sorry, one can't observe globally in this game."),
3268 if (!(allow = strchr(
game.
server.allow_take,
'b'))) {
3271 _(
"Sorry, one can't observe barbarians in this game."),
3274 fc_strlcpy(msg,
_(
"Sorry, one can't take barbarians in this game."),
3280 if (!(allow = strchr(
game.
server.allow_take,
'd'))) {
3283 _(
"Sorry, one can't observe dead players in this game."),
3287 _(
"Sorry, one can't take dead players in this game."),
3292 }
else if (
is_ai(pplayer)) {
3294 (
game.
info.is_new_game ?
'A' :
'a')))) {
3297 _(
"Sorry, one can't observe AI players in this game."),
3300 fc_strlcpy(msg,
_(
"Sorry, one can't take AI players in this game."),
3307 (
game.
info.is_new_game ?
'H' :
'h')))) {
3310 _(
"Sorry, one can't observe human players in this game."),
3314 _(
"Sorry, one can't take human players in this game."),
3323 if (will_obs && (*allow ==
'2' || *allow ==
'3')) {
3324 fc_strlcpy(msg,
_(
"Sorry, one can't observe in this game."), msg_len);
3328 if (!will_obs && *allow ==
'4') {
3329 fc_strlcpy(msg,
_(
"Sorry, one can't take players in this game."),
3335 && (*allow ==
'1' || *allow ==
'3')) {
3337 _(
"Sorry, one can't take players already "
3338 "connected in this game."),
3358 struct player *pplayer =
nullptr;
3364 arg = QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
3368 if (!caller && arg.isEmpty()) {
3374 if (arg.count() == 2 && (caller && caller->
access_level != ALLOW_HACK)) {
3376 _(
"Only the player name form is allowed."));
3381 if (arg.count() == 1) {
3390 qUtf8Printable(arg.at(0)), &result))) {
3392 qUtf8Printable(arg.at(0)), result);
3398 if (arg.count() == 2) {
3407 qUtf8Printable(arg.at(1)), result);
3429 if (
nullptr != pplayer && pplayer == pconn->
playing && !pconn->
observer
3432 _(
"%s already controls %s. Using 'observe' would remove %s"),
3441 _(
"%s is already observing %s."), pconn->
username,
3499 struct player *pplayer =
nullptr;
3505 arg = QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
3509 if (!caller && arg.count() != 2) {
3515 if (caller && caller->
access_level != ALLOW_HACK && arg.count() != 1) {
3517 _(
"Only the player name form is allowed."));
3521 if (arg.count() == 0) {
3527 if (arg.count() == 2) {
3537 if (strcmp(qUtf8Printable(arg.at(i)),
"-") == 0) {
3540 _(
"You cannot issue \"/take -\" when "
3541 "the game has already started."));
3567 _(
"A delegation is active for player "
3568 "'%s'. /take not possible."),
3580 if ((
nullptr != pplayer && !pconn->
observer && pplayer == pconn->
playing)
3581 || (
nullptr == pplayer && !pconn->
observer
3582 &&
nullptr != pconn->
playing)) {
3592 if (!pplayer && !pconn->
playing
3596 _(
"There is no free player slot for %s."), pconn->
username);
3609 if (
nullptr == caller) {
3611 _(
"Reassigned nation to %s by server console."),
3615 _(
"Reassigned nation to %s by %s."), pconn->
username,
3623 if (!aconn->observer) {
3658 :
is_ai(pplayer) ?
_(
"AI")
3663 _(
"%s failed to attach to any player."), pconn->
username);
3682 struct player *pplayer =
nullptr;
3686 arg = QString(buf).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
3689 if (!caller && arg.count() == 0) {
3696 if (arg.count() == 1
3711 if (pconn != caller && caller && caller->
access_level != ALLOW_HACK) {
3713 _(
"You can not detach other users."));
3720 if (!pplayer && !pconn->
observer) {
3722 _(
"%s is not attached to any player."), pconn->
username);
3748 aplayer->unassigned_user =
true;
3781 bool check,
bool cmdline_load)
3785 struct conn_list *global_observers;
3787 if (!filename || filename[0] ==
'\0') {
3794 _(
"Cannot load a game while another is running."));
3800 _(
"Name \"%s\" disallowed for security reasons."), filename);
3819 for (
const auto &path : paths) {
3821 if (!file.isEmpty()) {
3830 for (
const auto &path : paths) {
3832 QStringLiteral(
"sav"), QStringLiteral(
"gz"),
3833 QStringLiteral(
"bz2"), QStringLiteral(
"xz"),
3834 QStringLiteral(
"zst"), QStringLiteral(
"sav.gz"),
3835 QStringLiteral(
"sav.bz2"), QStringLiteral(
"sav.xz"),
3836 QStringLiteral(
"sav.zst")};
3837 for (
const auto &ext : exts) {
3838 QString
name = filename + QStringLiteral(
".") + ext;
3840 if (!file.isEmpty()) {
3854 _(
"Cannot find savegame or scenario with the name \"%s\"."),
3867 qCritical(
"Error loading savefile '%s': %s", qUtf8Printable(arg),
3870 qUtf8Printable(arg));
3881 global_observers = conn_list_new();
3884 if (pconn->playing !=
nullptr) {
3886 }
else if (pconn->observer) {
3887 conn_list_append(global_observers, pconn);
3913 qDebug(
"Load time: %g seconds (%g apparent)",
3920 qDebug(
"load_command() does send_rulesets()");
3943 if (strcmp(pconn->username, pplayer->
username) == 0) {
3955 if (
nullptr == pconn->playing) {
3961 conn_list_destroy(global_observers);
3969 struct packet_achievement_info pack;
3973 pack.first = (pach->first == pplayer);
3975 lsend_packet_achievement_info(pplayer->
connections, &pack);
3999 if (
nullptr == str ||
'\0' == str[0]) {
4001 _(
"You must provide a ruleset name. Use \"/show ruleset\" to "
4002 "see what is the current ruleset."));
4008 _(
"This setting can't be modified after the game has started."));
4012 if (strcmp(str,
game.
server.rulesetdir) == 0) {
4014 _(
"Ruleset directory is already \"%s\""), str);
4021 _(
"Name \"%s\" disallowed for security reasons."), str);
4025 fc_snprintf(filename,
sizeof(filename),
"%s", str);
4027 if (pfilename.isEmpty()) {
4029 _(
"Ruleset directory \"%s\" not found"), str);
4034 bool success =
true;
4038 qDebug(
"set_rulesetdir() does load_rulesets() with \"%s\"", str);
4043 if (!
load_rulesets(old,
nullptr,
false,
nullptr,
true,
false,
true)) {
4062 _(
"Ruleset directory set to \"%s\""), str);
4066 _(
"Failed loading rulesets from directory \"%s\", using \"%s\""),
4084 if (
nullptr == caller) {
4086 _(
"That would be rather silly, since you are not a player."));
4091 if (
nullptr == ppattern) {
4102 conn_pattern_list_append(caller->
server.ignore_list, ppattern);
4104 _(
"Added pattern %s as entry %d to your ignore list."), buf,
4105 conn_pattern_list_size(caller->
server.ignore_list));
4121 _(
"That would be rather silly, since you are not a player."));
4128 n = conn_pattern_list_size(caller->
server.ignore_list);
4135 if (
'\0' == buf[0]) {
4137 _(
"Missing range. Try /help unignore."));
4139 }
else if ((c = strchr(buf,
'-'))) {
4141 if (
'\0' == buf[0]) {
4146 _(
"\"%s\" is not a valid range. Try /help unignore."), buf);
4154 _(
"\"%s\" is not a valid range. Try /help unignore."), buf);
4160 _(
"\"%s\" is not a valid range. Try /help unignore."), buf);
4166 if (!(1 <= first && first <= last && last <= n)) {
4167 if (first == last) {
4187 _(
"Removed pattern %s (entry %d) from your ignore list."),
4189 conn_pattern_list_remove(caller->
server.ignore_list, ppattern);
4209 struct rgbcolor *prgbcolor =
nullptr;
4214 QString(str).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
4217 if (token.count() != 2) {
4219 _(
"Two arguments needed. See '/help playercolor'."));
4229 qUtf8Printable(token.at(0)), match_result);
4243 if (0 ==
fc_strcasecmp(qUtf8Printable(token.at(1)),
"reset")) {
4245 prgbcolor =
nullptr;
4248 _(
"Can only unset player color before game starts."));
4256 _(
"Invalid player color definition. See '/help playercolor'."));
4262 if (prgbcolor !=
nullptr) {
4265 if (pother != pplayer && pother->
rgb !=
nullptr
4269 _(
"Warning: new color [%s] for %s is identical to %s."),
4284 _(
"Color of player %s set to [%s]."),
player_name(pplayer),
4301 bool is_male =
false;
4305 QString(str).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
4308 if (token.count() == 0) {
4310 _(
"At least one argument needed. See '/help playernation'."));
4316 _(
"Can only set player nation before game starts."));
4324 qUtf8Printable(token.at(0)), match_result);
4328 if (token.count() == 1) {
4333 _(
"Nation of player %s reset."),
player_name(pplayer));
4337 if (token.at(1) == QStringLiteral(
"random")) {
4343 _(
"Unrecognized nation: %s."),
4344 qUtf8Printable(token.at(1)));
4350 _(
"%s nation is not available for user selection."),
4351 qUtf8Printable(token.at(1)));
4357 _(
"%s nation is already in use."),
4358 qUtf8Printable(token.at(1)));
4363 if (token.count() < 3) {
4367 _(
"Player sex must be given when setting nation."));
4371 if (!strcmp(qUtf8Printable(token.at(2)),
"0")) {
4373 }
else if (!strcmp(qUtf8Printable(token.at(2)),
"1")) {
4377 _(
"Unrecognized gender: %s, expecting 1 or 0."),
4378 qUtf8Printable(token.at(2)));
4382 if (token.count() > 4) {
4386 _(
"Unrecognized style: %s."), qUtf8Printable(token.at(4)));
4396 char error_buf[256];
4399 pplayer->
style = pstyle;
4402 if (token.count() > 3) {
4404 qUtf8Printable(token.at(3)),
4405 error_buf,
sizeof(error_buf))) {
4414 _(
"Nation of player %s set to [%s]."),
player_name(pplayer),
4431 static_should_quit =
true;
4432 QCoreApplication::quit();
4459 bool check,
int read_recursion)
4463 char *cptr_s, *cptr_d;
4465 enum cmdlevel
level;
4469 if (
'\0' == *cptr_s ||
'#' == *cptr_s) {
4479 if (
'\0' == *cptr_s) {
4487 if (!check && caller) {
4494 _(
"Sorry, you are not allowed to use server commands."));
4506 for (cptr_d =
command; *cptr_s !=
'\0' && QChar::isLetterOrNumber(*cptr_s)
4508 cptr_s++, cptr_d++) {
4520 _(
"Warning: '%s' interpreted as '%s', but it is ambiguous."
4525 _(
"Unknown command '%s%s'. "
4527 caller ?
"/" :
"",
command, caller ?
"/" :
"");
4546 const struct player *teamplr;
4550 if (caller_had_vote) {
4553 _(
"Your new vote canceled your previous vote."));
4560 what =
_(
"New teamvote");
4565 what =
_(
"New vote");
4582 _(
"Your new vote (\"%s\") was not "
4583 "legal or was not recognized."),
4594 _(
"You are not allowed to use this command."));
4599 struct conn_list *echo_list =
nullptr;
4600 bool echo_list_allocated =
false;
4609 if (
nullptr == echo_list) {
4610 echo_list = conn_list_new();
4611 echo_list_allocated =
true;
4613 conn_list_append(echo_list, pconn);
4623 if (
nullptr != echo_list) {
4629 "%s: '%s %s'",
_(
"(server prompt)"),
command, arg);
4631 if (echo_list_allocated) {
4632 conn_list_destroy(echo_list);
4678 #ifdef FREECIV_DEBUG
4679 case CMD_EXPERIMENTAL:
4700 return wall(arg, check);
4708 return read_command(caller, arg, check, read_recursion);
4716 return lua_command(caller, arg, check, read_recursion);
4764 qCritical(
"Unknown command variant: %d.", cmd);
4778 _(
"Game is over."));
4782 _(
"Ending the game. The server will restart once all clients "
4783 "have disconnected."));
4787 _(
"Cannot end the game: no game running."));
4803 _(
"You are not allowed to use this command."));
4815 _(
"You have already conceded the game."));
4824 _(
"%s has conceded the game and can no longer win."),
4831 #define SPECENUM_NAME reset_args
4832 #define SPECENUM_VALUE0 RESET_GAME
4833 #define SPECENUM_VALUE0NAME "game"
4834 #define SPECENUM_VALUE1 RESET_RULESET
4835 #define SPECENUM_VALUE1NAME "ruleset"
4836 #define SPECENUM_VALUE2 RESET_SCRIPT
4837 #define SPECENUM_VALUE2NAME "script"
4838 #define SPECENUM_VALUE3 RESET_DEFAULT
4839 #define SPECENUM_VALUE3NAME "default"
4840 #include "specenum_gen.h"
4847 i =
CLIP(0, i, reset_args_max());
4848 return reset_args_name(
static_cast<enum reset_args
>(i));
4875 _(
"Guessing argument 'ruleset'."));
4876 ind = RESET_RULESET;
4879 _(
"Guessing argument 'game'."));
4887 _(
"The valid arguments are: 'game', 'ruleset', 'script' "
4902 _(
"Reset all settings to the values at the game start."));
4905 _(
"No saved settings from the game start available."));
4918 _(
"Reset all settings to ruleset values."));
4921 _(
"Failed to reset settings to ruleset values."));
4927 _(
"Reset all settings and rereading the server start "
4934 true,
false, read_recursion + 1)) {
4935 if (
nullptr != caller) {
4937 _(
"Could not read script file '%s'."),
4946 _(
"Reset all settings to default values."));
4966 char reject_msg[256] =
"";
4984 _(
"Option '%s' reset to default value, and will track any "
4985 "default changes."),
4993 #define SPECENUM_NAME lua_args
4994 #define SPECENUM_VALUE0 LUA_CMD
4995 #define SPECENUM_VALUE0NAME "cmd"
4996 #define SPECENUM_VALUE1 LUA_FILE
4997 #define SPECENUM_VALUE1NAME "file"
4998 #define SPECENUM_VALUE2 LUA_UNSAFE_CMD
4999 #define SPECENUM_VALUE2NAME "unsafe-cmd"
5000 #define SPECENUM_VALUE3 LUA_UNSAFE_FILE
5001 #define SPECENUM_VALUE3NAME "unsafe-file"
5002 #include "specenum_gen.h"
5009 i =
CLIP(0, i, lua_args_max());
5010 return lua_args_name(
static_cast<enum lua_args
>(i));
5020 const auto extension = QLatin1String(
".lua");
5021 QString luafile, tilde_filename, real_filename;
5022 char *luaarg =
nullptr;
5029 QString(arg).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
5032 if (tokens.count() > 0) {
5036 nullptr, qUtf8Printable(tokens.at(0)), &ind);
5042 luaarg = arg + qstrlen(lua_args_name(lua_args(ind)));
5054 _(
"Fall back to old syntax '%slua <script command>'."),
5062 if (luaarg ==
nullptr) {
5064 _(
"No lua command or lua script file. See '%shelp lua'."),
5073 case LUA_UNSAFE_CMD:
5074 if (read_recursion > 0) {
5076 _(
"Unsafe Lua code can only be run by explicit command."));
5080 _(
"You aren't allowed to run unsafe Lua code."));
5084 case LUA_UNSAFE_FILE:
5085 if (read_recursion > 0) {
5087 _(
"Unsafe Lua code can only be run by explicit command."));
5091 _(
"You aren't allowed to run unsafe Lua code."));
5098 if (!luafile.endsWith(extension)) {
5099 luafile += extension;
5106 _(
"Freeciv21 script '%s' disallowed for security reasons."),
5107 qUtf8Printable(luafile));
5111 tilde_filename = luafile;
5117 if (real_filename.isEmpty()) {
5120 _(
"No Freeciv21 script found by the name '%s'."),
5121 qUtf8Printable(tilde_filename));
5125 real_filename = tilde_filename;
5138 case LUA_UNSAFE_CMD:
5143 _(
"Loading Freeciv21 script file '%s'."),
5144 qUtf8Printable(real_filename));
5146 if (QFile::exists(real_filename)
5147 && (script_file =
fc_fopen(qUtf8Printable(real_filename),
"r"))) {
5149 fclose(script_file);
5153 _(
"Cannot read Freeciv21 script '%s'."),
5154 qUtf8Printable(real_filename));
5158 case LUA_UNSAFE_FILE:
5160 _(
"Loading Freeciv21 script file '%s'."),
5161 qUtf8Printable(real_filename));
5163 if (QFile::exists(real_filename)
5164 && (script_file =
fc_fopen(qUtf8Printable(real_filename),
"r"))) {
5165 fclose(script_file);
5167 qUtf8Printable(real_filename));
5171 _(
"Cannot read Freeciv21 script '%s'."),
5172 qUtf8Printable(real_filename));
5182 #define SPECENUM_NAME delegate_args
5183 #define SPECENUM_VALUE0 DELEGATE_CANCEL
5184 #define SPECENUM_VALUE0NAME "cancel"
5185 #define SPECENUM_VALUE1 DELEGATE_RESTORE
5186 #define SPECENUM_VALUE1NAME "restore"
5187 #define SPECENUM_VALUE2 DELEGATE_SHOW
5188 #define SPECENUM_VALUE2NAME "show"
5189 #define SPECENUM_VALUE3 DELEGATE_TAKE
5190 #define SPECENUM_VALUE3NAME "take"
5191 #define SPECENUM_VALUE4 DELEGATE_TO
5192 #define SPECENUM_VALUE4NAME "to"
5193 #include "specenum_gen.h"
5200 i =
CLIP(0, i, delegate_args_max());
5201 return delegate_args_name(
static_cast<enum delegate_args
>(i));
5211 int ind = delegate_args_invalid();
5213 bool player_specified =
false;
5215 struct player *dplayer =
nullptr;
5219 _(
"Game not started - "
5220 "cannot delegate yet."));
5225 QString(arg).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
5228 if (tokens.count() > 0) {
5232 qUtf8Printable(tokens.at(0)), &ind);
5242 ind = DELEGATE_SHOW;
5249 ind = delegate_args_invalid();
5255 ind = DELEGATE_SHOW;
5259 if (!delegate_args_is_valid(delegate_args(ind))) {
5261 enum delegate_args valid_args;
5263 for (valid_args = delegate_args_begin();
5264 valid_args != delegate_args_end();
5265 valid_args = delegate_args_next(valid_args)) {
5266 const char *
name = delegate_args_name(valid_args);
5268 if (
name !=
nullptr) {
5270 if (valid_args != delegate_args_max()) {
5278 _(
"Valid arguments for 'delegate' are: %s."), buf);
5284 case DELEGATE_CANCEL:
5286 if (tokens.count() > 1) {
5288 player_specified =
true;
5293 qUtf8Printable(tokens.at(1)), result);
5298 _(
"Command level '%s' or greater needed to modify "
5299 "others' delegations."),
5300 cmdlevel_name(ALLOW_ADMIN));
5307 _(
"Please specify a player for whom delegation should "
5313 case DELEGATE_RESTORE:
5317 _(
"You can't switch players from the console."));
5323 if (tokens.count() > 1) {
5324 player_specified =
true;
5328 qUtf8Printable(tokens.at(1)), result);
5335 _(
"Please specify a player for whom the delegation should "
5345 _(
"You can't switch players from the console."));
5348 if (tokens.count() > 1) {
5349 player_specified =
true;
5353 qUtf8Printable(tokens.at(1)), result);
5358 _(
"Please specify a player to take control of."));
5376 if (tokens.count() > 1) {
5381 _(
"Please specify a user to whom control is to be delegated."));
5385 if (tokens.count() > 2) {
5386 player_specified =
true;
5390 qUtf8Printable(tokens.at(2)), result);
5400 _(
"Command level '%s' or greater or special permission "
5401 "needed to modify others' delegations."),
5402 cmdlevel_name(ALLOW_ADMIN));
5411 _(
"You do not control a player."));
5436 _(
"Can't delegate control of '%s' belonging to %s while "
5437 "they are controlling another player."),
5439 }
else if (player_specified) {
5442 _(
"Can't change delegation of '%s' while controlled by "
5450 _(
"You can't delegate control while you are controlling "
5451 "a delegated player yourself."));
5461 if (player_specified) {
5465 _(
"%s already owns '%s', so cannot also be delegate. "
5466 "Use '%sdelegate cancel' to cancel an existing "
5476 _(
"You can't delegate control to yourself. "
5477 "Use '/delegate cancel' to cancel an existing "
5489 _(
"Control of player '%s' delegated to user %s."),
5501 _(
"No delegation defined for '%s'."),
player_name(dplayer));
5504 _(
"Control of player '%s' delegated to user %s."),
5510 case DELEGATE_CANCEL:
5514 _(
"No delegation defined for '%s'."),
player_name(dplayer));
5529 qCritical(
"Failed to restore %s's connection as %s during "
5530 "'delegate cancel'.",
5533 pdelegate->
server.delegation.playing,
5534 pdelegate->
server.delegation.observer)));
5540 _(
"Your delegated control of player '%s' was canceled."),
5555 if (caller->
server.delegation.status) {
5558 _(
"You are already controlling a delegated player. "
5559 "Use '/delegate restore' to relinquish control of your "
5560 "current player first."));
5572 _(
"Can't take player while you have delegated control "
5573 "yourself. Use '/delegate cancel' to cancel your own "
5574 "delegation first."));
5591 _(
"Control of player '%s' has not been delegated to you."),
5600 _(
"Another user already controls player '%s'."),
5608 qCritical(
"%s failed to take control of '%s' during 'delegate take'.",
5616 _(
"%s is now controlling player '%s'."), caller->
username,
5621 case DELEGATE_RESTORE:
5626 if (!caller->
server.delegation.status) {
5628 _(
"You are not currently controlling a delegated player."));
5635 qCritical(
"Failed to restore %s's connection as %s during "
5636 "'delegate restore'.",
5639 caller->
server.delegation.playing,
5640 caller->
server.delegation.observer)));
5649 _(
"%s is now connected as %s."), caller->
username,
5668 buf = QString(
_(
"%1 (observer)")).arg(
player_name(pplayer));
5670 buf = QStringLiteral(
"%1").arg(
player_name(pplayer));
5673 buf =
_(
"global observer");
5679 return qUtf8Printable(buf);
5684 #define SPECENUM_NAME mapimg_args
5685 #define SPECENUM_VALUE0 MAPIMG_COLORTEST
5686 #define SPECENUM_VALUE0NAME "colortest"
5687 #define SPECENUM_VALUE1 MAPIMG_CREATE
5688 #define SPECENUM_VALUE1NAME "create"
5689 #define SPECENUM_VALUE2 MAPIMG_DEFINE
5690 #define SPECENUM_VALUE2NAME "define"
5691 #define SPECENUM_VALUE3 MAPIMG_DELETE
5692 #define SPECENUM_VALUE3NAME "delete"
5693 #define SPECENUM_VALUE4 MAPIMG_SHOW
5694 #define SPECENUM_VALUE4NAME "show"
5695 #define SPECENUM_COUNT MAPIMG_COUNT
5696 #include "specenum_gen.h"
5703 i =
CLIP(0, i, mapimg_args_max());
5704 return mapimg_args_name(
static_cast<enum mapimg_args
>(i));
5718 QString(arg).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
5720 if (token.count() > 0) {
5723 nullptr, qUtf8Printable(token.at(0)), &ind);
5732 _(
"Ambiguous 'mapimg' command."));
5743 enum mapimg_args valid_args;
5745 for (valid_args = mapimg_args_begin(); valid_args != mapimg_args_end();
5746 valid_args = mapimg_args_next(valid_args)) {
5747 cat_snprintf(buf,
sizeof(buf),
"'%s'", mapimg_args_name(valid_args));
5748 if (valid_args != mapimg_args_max()) {
5754 _(
"The valid arguments are: %s."), buf);
5765 if (token.count() == 1) {
5767 _(
"Missing argument for 'mapimg define'."));
5791 _(
"Defined as map image "
5792 "definition %d: '%s'."),
5799 if (token.count() == 1) {
5801 _(
"Missing argument for 'mapimg delete'."));
5803 }
else if (token.count() == 2
5804 && strcmp(qUtf8Printable(token.at(1)),
"all") == 0) {
5814 _(
"All map image definitions "
5816 }
else if (token.count() == 2
5817 && sscanf(qUtf8Printable(token.at(1)),
"%d", &
id) != 0) {
5829 _(
"Map image definition %d "
5835 _(
"Bad argument for 'mapimg delete': '%s'."),
5836 qUtf8Printable(token.at(1)));
5842 if (token.count() < 2
5843 || (token.count() == 2
5844 && strcmp(qUtf8Printable(token.at(1)),
"all") == 0)) {
5850 }
else if (token.count() == 2
5851 && sscanf(qUtf8Printable(token.at(1)),
"%d", &
id) != 0) {
5867 _(
"Bad argument for 'mapimg show': '%s'."),
5868 qUtf8Printable(token.at(1)));
5873 case MAPIMG_COLORTEST:
5883 if (token.count() < 2) {
5885 _(
"Missing argument for 'mapimg create'."));
5889 if (strcmp(qUtf8Printable(token.at(1)),
"all") == 0) {
5898 if (pmapdef ==
nullptr
5906 }
else if (sscanf(qUtf8Printable(token.at(1)),
"%d", &
id) != 0) {
5915 if (pmapdef ==
nullptr
5924 _(
"Bad argument for 'mapimg create': '%s'."),
5925 qUtf8Printable(token.at(1)));
5942 char *cmd =
nullptr;
5946 QString(arg).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
5949 if (tokens.count() < 1) {
5957 if (
nullptr == pplayer) {
5964 cmd = arg + qstrlen(qUtf8Printable(tokens.at(0)));
5967 if (strlen(cmd) == 0) {
5969 _(
"No command for the AI console defined."));
5979 if (pplayer && pplayer->
ai) {
5982 _(
"AI console for player %s. Command: '%s'."),
5988 _(
"No AI console defined for the AI '%s' of player %s."),
6000 #define SPECENUM_NAME fcdb_args
6001 #define SPECENUM_VALUE0 FCDB_RELOAD
6002 #define SPECENUM_VALUE0NAME "reload"
6003 #define SPECENUM_VALUE1 FCDB_LUA
6004 #define SPECENUM_VALUE1NAME "lua"
6005 #define SPECENUM_COUNT FCDB_COUNT
6006 #include "specenum_gen.h"
6013 i =
CLIP(0, i, fcdb_args_max());
6014 return fcdb_args_name(
static_cast<enum fcdb_args
>(i));
6031 _(
"Freeciv21 database script not activated at server start. "
6032 "See the Freeciv21 server's --auth command line option."));
6037 QString(arg).split(QRegularExpression(
REG_EXP), Qt::SkipEmptyParts);
6040 if (token.count() > 0) {
6043 nullptr, qUtf8Printable(token.at(0)), &ind);
6067 enum fcdb_args valid_args;
6069 for (valid_args = fcdb_args_begin(); valid_args != fcdb_args_end();
6070 valid_args = fcdb_args_next(valid_args)) {
6071 cat_snprintf(buf,
sizeof(buf),
"'%s'", fcdb_args_name(valid_args));
6072 if (valid_args != fcdb_args_max()) {
6128 if (
game.
info.is_new_game && !check) {
6135 qDebug(
"Reduced maxplayers from %d to %d to fit "
6136 "to the number of start positions.",
6155 qDebug(
"Had to cut down the number of players to the "
6156 "number of map start positions, there must be "
6157 "something wrong with the savegame or you "
6158 "adjusted the maxplayers value.");
6178 _(
"Not enough human players ('minplayers' server setting "
6179 "has value %d); game will not start."),
6190 _(
"Not enough nations in the current nation set "
6191 "for all players; game will not start. "
6192 "(See 'nationset' setting.)"));
6195 _(
"Not enough nations for all players; game will "
6199 }
else if (strlen(
game.
server.start_units) == 0
6202 _(
"Neither 'startcity' nor 'startunits' setting gives "
6203 "players anything to start game with; game will "
6208 }
else if (!caller) {
6213 _(
"All players are ready; starting game."));
6231 _(
"Cannot start the game: the game is waiting for all clients "
6238 _(
"Cannot start the game: it is already running."));
6241 qCritical(
"Unknown server state variant: %d.",
server_state());
6282 time_t time_of_addr_kick = 0, time_of_user_kick = 0;
6283 time_t now, time_of_kick = 0;
6285 if (
nullptr != time_remaining) {
6286 *time_remaining = 0;
6293 if (kick_table_by_addr->contains(pconn->
server.ipaddr)) {
6294 time_of_addr_kick = kick_table_by_addr->value(pconn->
server.ipaddr);
6295 time_of_kick = time_of_addr_kick;
6297 if (kick_table_by_user->contains(pconn->
username)) {
6298 time_of_user_kick = kick_table_by_user->value(pconn->
username);
6299 if (time_of_user_kick > time_of_kick) {
6300 time_of_kick = time_of_user_kick;
6304 if (0 == time_of_kick) {
6308 now = time(
nullptr);
6309 if (now - time_of_kick >
game.
server.kick_time) {
6311 if (0 != time_of_addr_kick) {
6312 kick_table_by_addr->remove(pconn->
server.ipaddr);
6314 if (0 != time_of_user_kick) {
6315 kick_table_by_user->remove(pconn->
username);
6320 if (
nullptr != time_remaining) {
6321 *time_remaining =
game.
server.kick_time - (now - time_of_kick);
6338 if (
nullptr == pconn) {
6345 const int MIN_UNIQUE_CONNS = 3;
6347 if (pconn == caller) {
6353 std::set<std::string> unique_ipaddr;
6356 unique_ipaddr.insert(aconn->server.ipaddr);
6357 if (unique_ipaddr.size() >= MIN_UNIQUE_CONNS) {
6364 if (unique_ipaddr.size() < MIN_UNIQUE_CONNS) {
6366 _(
"There must be at least %d unique connections to the "
6367 "server for this command to be valid."),
6378 now = time(
nullptr);
6379 kick_table_by_addr->insert(
ipaddr, now);
6383 if (0 != strcmp(
ipaddr, aconn->server.ipaddr)) {
6390 aconn->playing->unassigned_user =
true;
6393 kick_table_by_user->insert(aconn->username, now);
6411 "Welcome - this is the introductory help text for the Freeciv21 "
6414 "Two important server concepts are Commands and Options. Commands, "
6415 "such as 'help', are used to interact with the server. Some commands "
6416 "take one or more arguments, separated by spaces. In many cases "
6417 "commands and command arguments may be abbreviated. Options are "
6418 "settings which control the server as it is running.\n"
6420 "To find out how to get more information about commands and options, "
6421 "use 'help help'.\n"
6423 "For the impatient, the main commands to get going are:\n"
6424 " show - to see current options\n"
6425 " set - to set options\n"
6426 " start - to start the game once players have connected\n"
6427 " save - to save the current game\n"
6428 " quit - to exit"));
6456 const char *syn =
_(
"Synopsis: ");
6457 size_t synlen = qstrlen(syn);
6460 fc_snprintf(prefix,
sizeof(prefix),
"%*s",
static_cast<int>(synlen),
6490 _(
"The following server commands are available:"));
6493 for (i = 0; i <
CMD_NUM; i++) {
6502 for (i = 0, j = 0; i <
CMD_NUM; i++) {
6505 if ((++j % 4) == 0) {
6511 if (buf[0] !=
'\0') {
6527 const char *src, *end;
6531 if (accessor_fn ==
nullptr || matches ==
nullptr || num_matches < 1) {
6536 end = buf +
sizeof(buf) - 1;
6538 for (i = 0; i < num_matches && dest < end; i++) {
6539 src = accessor_fn(matches[i]);
6546 while (*src !=
'\0' && dest < end) {
6558 #define SPECENUM_NAME help_general_args
6559 #define SPECENUM_VALUE0 HELP_GENERAL_COMMANDS
6560 #define SPECENUM_VALUE0NAME "commands"
6561 #define SPECENUM_VALUE1 HELP_GENERAL_OPTIONS
6562 #define SPECENUM_VALUE1NAME "options"
6563 #define SPECENUM_COUNT HELP_GENERAL_COUNT
6564 #include "specenum_gen.h"
6572 #define HELP_ARG_NUM (CMD_NUM + HELP_GENERAL_COUNT + settings_number())
6584 if (i < HELP_GENERAL_COUNT) {
6585 return help_general_args_name(
static_cast<enum help_general_args
>(i));
6588 i -= HELP_GENERAL_COUNT;
6597 int matches[64], num_matches = 0;
6614 _(
"Help argument '%s' is ambiguous."), arg);
6621 _(
"No match for help argument '%s'."), arg);
6634 if (ind == HELP_GENERAL_OPTIONS) {
6638 if (ind == HELP_GENERAL_COMMANDS) {
6642 ind -= HELP_GENERAL_COUNT;
6650 qCritical(
"Bug in show_help!");
6662 _(
"List of connections to server:"));
6676 if (pconn->established) {
6677 cat_snprintf(buf,
sizeof(buf),
" command access level %s",
6678 cmdlevel_name(pconn->access_level));
6700 if (delegate_to !=
nullptr) {
6702 ? pplayer->
server.orig_username
6707 _(
"%s delegates control over player '%s' to user %s%s."),
6731 if (
nullptr == caller) {
6733 _(
"That would be rather silly, since you are not a player."));
6737 if (0 == conn_pattern_list_size(caller->
server.ignore_list)) {
6794 && strcmp(pplayer->
username,
"nouser") != 0) {
6816 }
else if (
is_ai(pplayer)) {
6821 if (
is_ai(pplayer)) {
6824 buf,
sizeof(buf),
_(
", difficulty level %s"),
6830 PL_(
", %d connection:",
", %d connections:", n), n);
6838 _(
"%s from %s (command access level %s), "
6840 pconn->username, qUtf8Printable(pconn->addr),
6841 cmdlevel_name(pconn->access_level),
6842 (pconn->send_buffer->nsize >> 10));
6843 if (pconn->observer) {
6866 _(
"List of rulesets available with '%sread' command:"),
6867 (caller ?
"/" :
""));
6871 for (
const auto &s : qAsConst(*serv_list)) {
6888 QStringLiteral(
"*.sav*"),
true);
6889 for (
const auto &info : files) {
6891 info.absoluteFilePath(), QStringLiteral(
"scenario"),
true);
6894 auto buf = info.baseName().toUtf8();
6910 _(
"List of nation sets available for 'nationset' option:"));
6916 int num_nations = 0;
6917 for (
auto &pnation :
nations) {
6925 PL_(
" %-10s %s (%d playable)",
" %-10s %s (%d playable)",
6929 if (strlen(description) > 0) {
6930 static const char prefix[] =
" ";
6954 const struct player_list *members =
team_members(pteam);
6960 PL_(
"%2d : '%s' : %d player :",
"%2d : '%s' : %d players :",
6961 player_list_size(members)),
6963 player_list_size(members));
7020 #define SPECENUM_NAME list_args
7021 #define SPECENUM_VALUE0 LIST_COLORS
7022 #define SPECENUM_VALUE0NAME "colors"
7023 #define SPECENUM_VALUE1 LIST_CONNECTIONS
7024 #define SPECENUM_VALUE1NAME "connections"
7025 #define SPECENUM_VALUE2 LIST_DELEGATIONS
7026 #define SPECENUM_VALUE2NAME "delegations"
7027 #define SPECENUM_VALUE3 LIST_IGNORE
7028 #define SPECENUM_VALUE3NAME "ignored users"
7029 #define SPECENUM_VALUE4 LIST_MAPIMG
7030 #define SPECENUM_VALUE4NAME "map image definitions"
7031 #define SPECENUM_VALUE5 LIST_PLAYERS
7032 #define SPECENUM_VALUE5NAME "players"
7033 #define SPECENUM_VALUE6 LIST_RULESETS
7034 #define SPECENUM_VALUE6NAME "rulesets"
7035 #define SPECENUM_VALUE7 LIST_SCENARIOS
7036 #define SPECENUM_VALUE7NAME "scenarios"
7037 #define SPECENUM_VALUE8 LIST_NATIONSETS
7038 #define SPECENUM_VALUE8NAME "nationsets"
7039 #define SPECENUM_VALUE9 LIST_TEAMS
7040 #define SPECENUM_VALUE9NAME "teams"
7041 #define SPECENUM_VALUE10 LIST_VOTES
7042 #define SPECENUM_VALUE10NAME "votes"
7043 #include "specenum_gen.h"
7050 i =
CLIP(0, i, list_args_max());
7051 return list_args_name(
static_cast<enum list_args
>(i));
7066 ind = list_args(ind_int);
7070 _(
"Bad list argument: '%s'. Try '%shelp list'."), arg,
7071 (caller ?
"/" :
""));
7083 case LIST_CONNECTIONS:
7086 case LIST_DELEGATIONS:
7100 case LIST_SCENARIOS:
7103 case LIST_NATIONSETS:
7116 qCritical(
"Internal error: ind %d in show_list", ind);
7135 const char *(*index2str)(
int) )
7137 static int list_index,
len;
7138 const char *
name =
"";
7153 len = qstrlen(mytext);
7157 while ((num < 0 &&
name) || (list_index < num)) {
7158 name = index2str(list_index);
7169 return ((
char *)
nullptr);
7273 return cmdlevel_name(cmdlevel(idx));
7291 return ((idx == 0) ?
"first"
7292 : (idx == 1) ?
"new"
7396 const char *arg,
bool allow_fluff)
7398 char *str_itr = rl_line_buffer;
7399 int arg_len = qstrlen(arg);
7403 while (str_itr < rl_line_buffer + start
7404 && !QChar::isLetterOrNumber(*str_itr)) {
7407 while (str_itr < rl_line_buffer + start
7408 && QChar::isLetterOrNumber(*str_itr)) {
7414 while (str_itr < rl_line_buffer + start
7415 && !QChar::isLetterOrNumber(*str_itr)) {
7424 if (QChar::isLetterOrNumber(*str_itr)) {
7430 for (; str_itr < rl_line_buffer + start; str_itr++) {
7431 if (QChar::isLetterOrNumber(*str_itr)) {
7465 str_itr = rl_line_buffer;
7466 while (str_itr - rl_line_buffer < start) {
7467 if (QChar::isLetterOrNumber(*str_itr)) {
7482 char *chptr = rl_line_buffer;
7484 while (chptr - rl_line_buffer < start) {
7485 if (QChar::isLetterOrNumber(*chptr)) {
7505 #ifdef FREECIV_DEBUG
7643 #ifdef HAVE_SUPPRESS_APPEND
7644 rl_completion_suppress_append = (
setting_type(pset) == SST_BITWISE);
7769 char **matches = (
char **)
nullptr;
7793 matches = rl_completion_matches(text, rl_filename_completion_function);
7806 }
else if (
is_lua(start)) {
7814 rl_attempted_completion_over = 1;
bool achievement_player_has(const struct achievement *pach, const struct player *pplayer)
Has the given player got the achievement?
int achievement_index(const struct achievement *pach)
Return the achievement index.
#define achievements_iterate_end
#define achievements_iterate(_ach_)
struct ai_type * get_ai_type(int id)
Returns ai_type of given id.
const char * ai_name(const struct ai_type *ai)
Return the name of the ai type.
struct ai_type * ai_type_by_name(const char *search)
Find ai type with given name.
int ai_type_get_count()
Return number of ai types.
#define CALL_PLR_AI_FUNC(_func, _player,...)
const char * default_ai_type_name()
Return name of default ai type.
QString strvec_to_and_list(const QVector< QString > &psv)
bool BV_ISSET(const BV &bv, int bit)
#define SERVER_COMMAND_PREFIX
const char * city_name_get(const struct city *pcity)
Return the name of the city.
citizens city_size_get(const struct city *pcity)
Get the city size.
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
enum cmd_echo command_echo(const struct command *pcommand)
Returns the flag of the command to notify the users about its usage.
const char * command_name(const struct command *pcommand)
Return name of the command.
const struct command * command_by_number(int i)
Return command by its number.
const char * command_short_help(const struct command *pcommand)
Returns the short help text of the command (translated).
char * command_extra_help(const struct command *pcommand)
Returns the extra help text of the command (translated).
enum cmdlevel command_level(const struct command *pcommand)
What is the permissions level required for running the command?
const char * command_name_by_number(int i)
Return name of the command by commands number.
const char * command_synopsis(const struct command *pcommand)
Returns the synopsis text of the command (translated).
bool connection_attach(struct connection *pconn, struct player *pplayer, bool observing)
Setup pconn as a client connected to pplayer or observer.
bool connection_delegate_take(struct connection *pconn, struct player *dplayer)
Use a delegation to get control over another player.
struct player * find_uncontrolled_player()
Search for first uncontrolled player.
void connection_close_server(struct connection *pconn, const QString &reason)
Close a connection.
void connection_detach(struct connection *pconn, bool remove_unused_player)
Remove pconn as a client connected to pplayer: Updates pconn->playing, pconn->playing->connections,...
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
Set the access level of a connection, and re-send some needed info.
bool connection_delegate_restore(struct connection *pconn)
Restore the original status of a delegate connection pconn after potentially using a delegation.
size_t conn_pattern_to_string(const struct conn_pattern *ppattern, char *buf, size_t buf_len)
Put a string reprentation of the pattern in 'buf'.
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Thaw a connection list.
struct player * conn_get_player(const struct connection *pconn)
Returns the player that this connection is attached to, or nullptr.
const char * conn_description(const struct connection *pconn, bool is_private)
° Return pointer to static string containing a description for this ° connection, based on pconn->nam...
void conn_pattern_destroy(struct conn_pattern *ppattern)
Free a connection pattern.
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Freeze a connection list.
bool conn_controls_player(const struct connection *pconn)
Returns TRUE if the given connection is attached to a player which it also controls (i....
struct connection * conn_by_user(const char *user_name)
Find connection by exact user name, from game.all_connections, case-insensitve.
enum cmdlevel conn_get_access(const struct connection *pconn)
Returns the current access level of the given connection.
struct connection * conn_by_user_prefix(const char *user_name, enum m_pre_result *result)
struct conn_pattern * conn_pattern_from_string(const char *pattern, enum conn_pattern_type prefer, char *error_buf, size_t error_buf_len)
Creates a new connection pattern from the string.
#define conn_pattern_list_iterate_end
#define conn_list_iterate(connlist, pconn)
#define conn_pattern_list_iterate(plist, ppatern)
#define conn_list_iterate_end
void con_set_style(bool i)
Set style.
void con_write(enum rfc_status rfc_status, const char *message,...)
Write to console and add line-break, and show prompt if required.
bool con_get_style()
Returns rfc-style.
#define MAX_LEN_CONSOLE_LINE
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Set an AI level and related quantities, with no feedback.
#define MAX_NUM_PLAYER_SLOTS
char * local_to_internal_string_malloc(const char *text)
char * internal_to_local_string_malloc(const char *text)
#define PL_(String1, String2, n)
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,...)
Apply a tag to a text.
const struct ft_color ftc_log
const struct ft_color ftc_command
const struct ft_color ftc_server
const struct ft_color ftc_any
const struct ft_color ftc_vote_team
const struct ft_color ftc_game_start
const struct ft_color ftc_server_prompt
struct ft_color ftc_changed
const struct ft_color ftc_vote_public
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
#define GAME_MAX_READ_RECURSION
void send_scenario_description(struct conn_list *dest)
Send description of the current scenario.
void send_scenario_info(struct conn_list *dest)
Send current scenario info.
void send_game_info(struct conn_list *dest)
Send game_info packet; some server options and various stuff...
#define fc_assert_ret(condition)
#define fc_assert(condition)
constexpr auto LOG_NORMAL
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Return the tile for the given cartesian (map) position.
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
int map_startpos_count()
Is there start positions set for map.
bool mapimg_id2str(int id, char *str, size_t str_len)
Return the map image definition 'id' as a mapdef string.
bool mapimg_colortest(const char *savename, const char *path)
Create images which shows all map colors (playercolor, terrain colors).
int mapimg_count()
Return the number of map image definitions.
const char * mapimg_error()
Returns the last error.
struct mapdef * mapimg_isvalid(int id)
Check if a map image definition is valid.
bool mapimg_define(const char *maparg, bool check)
Define on map image.
bool mapimg_delete(int id)
Delete a map image definition.
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
Create the requested map image.
bool mapimg_show(int id, char *str, size_t str_len, bool detail)
Show a map image definition.
struct nation_style * style_of_nation(const struct nation_type *pnation)
Returns nation's style.
const char * nation_set_name_translation(const struct nation_set *pset)
Return the translated name of a nation set.
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Returns how much two nations look good in the same game.
struct government * init_government_of_nation(const struct nation_type *pnation)
Returns initial government type for this nation.
int nation_set_count()
Return the number of nation sets.
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
std::vector< nation_type > nations
bool is_nation_playable(const struct nation_type *nation)
Return whether a nation is "playable"; i.e., whether a human player can choose this nation.
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Check if the given nation is in a given set.
struct nation_type * nation_of_unit(const struct unit *punit)
Return the nation of the player who owns the unit.
const char * nation_set_rule_name(const struct nation_set *pset)
Return the (untranslated) rule name of a nation set.
const char * nation_adjective_for_player(const struct player *pplayer)
Return the (translated) adjective for the given nation of a player.
const char * nation_set_description(const struct nation_set *pset)
Return the (untranslated) user description of a nation set.
struct nation_type * nation_by_rule_name(const char *name)
Returns the nation that has the given (untranslated) rule name (adjective).
const char * nation_plural_translation(const struct nation_type *pnation)
Return the (translated) plural noun of the given nation.
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
#define nation_sets_iterate_end
#define nation_sets_iterate(NAME_pset)
#define NO_NATION_SELECTED
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
void notify_team(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players on pplayer's team.
void package_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Fill a packet_chat_msg structure for common server event.
void event_cache_add_for_all(const struct packet_chat_msg *packet)
Add an event to the cache for all connections.
struct city_list * cities
struct player_slot * player_slot_by_number(int player_id)
Return the possibly unused and uninitialized player slot.
bool player_slot_is_used(const struct player_slot *pslot)
Returns TRUE is this slot is "used" i.e.
struct player * player_by_name(const char *name)
Find player by given name.
struct player * player_by_number(const int player_id)
Return struct player pointer for the given player index.
int player_number(const struct player *pplayer)
Return the player index/number/id.
struct player * player_by_name_prefix(const char *name, enum m_pre_result *result)
Find player by its name prefix.
int player_count()
Return the number of players.
struct player * player_slot_get_player(const struct player_slot *pslot)
Returns the team corresponding to the slot.
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Set the player's nation to the given nation (may be nullptr).
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
struct player * player_by_user(const char *name)
Find player by its user name (not player/leader name)
#define ai_level_cmd(_level_)
#define players_iterate_end
#define players_iterate(_pplayer)
#define player_list_iterate(playerlist, pplayer)
static bool is_barbarian(const struct player *pplayer)
#define player_list_iterate_end
#define set_as_human(plr)
void server_player_set_name(struct player *pplayer, const char *name)
Try to set the player name to 'name'.
void player_status_add(struct player *plr, enum player_status pstatus)
Add a status flag to a player.
void player_set_under_human_control(struct player *pplayer)
Toggle player under human control.
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Creates a new, uninitialized, used player slot.
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Set the player's color.
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Toggle player to AI mode.
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)
Try to set the player name to 'name'.
bool player_delegation_active(const struct player *pplayer)
Returns TRUE if a delegation is active.
void assign_player_colors()
Permanently assign colors to any players that don't already have them.
void send_player_info_c(struct player *src, struct conn_list *dest)
Send information about player slot 'src', or all valid (i.e.
bool player_status_check(struct player *plr, enum player_status pstatus)
Check player status flag.
void player_delegation_set(struct player *pplayer, const char *username)
Define a delegation.
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
This function returns a random-ish nation that is suitable for 'barb_type' and is usable (not already...
void server_remove_player(struct player *pplayer)
This function does not close any connections attached to this player.
void player_info_freeze()
Do not compute and send PACKET_PLAYER_INFO or PACKET_NATION_AVAILABILITY until a call to player_info_...
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Initialize ANY newly-created player on the server.
int normal_player_count()
Return the number of non-barbarian players.
void player_info_thaw()
If the frozen level is back to 0, send all players' infos, and nation availability,...
bool player_color_changeable(const struct player *pplayer, const char **reason)
Return whether a player's color can currently be set with the '/playercolor' command.
const char * player_delegation_get(const struct player *pplayer)
Returns the username that control of the player is delegated to, if any.
bool client_can_pick_nation(const struct nation_type *pnation)
Return whether a nation is "pickable" – whether players can select it at game start.
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Identical to send_player_info_c(), but sends the diplstate of the player.
bool nation_is_in_current_set(const struct nation_type *pnation)
Is the nation in the currently selected nationset? If not, it's not allowed to appear in the game.
const char * player_color_ftstr(struct player *pplayer)
Return the player color as featured text string.
void reset_all_start_commands(bool plrchange)
Called when something is changed; this resets everyone's readiness.
struct section_file * secfile_load(const QString &filename, bool allow_duplicates)
Create a section file from a file.
const char * secfile_error()
Returns the last error which occurred in a string.
void secfile_destroy(struct section_file *secfile)
Free a section file.
void secfile_check_unused(const struct section_file *secfile)
Print log messages for any entries in the file which have not been looked up – ie,...
struct section_file * secfile_load_section(const QString &filename, const QString §ion, bool allow_duplicates)
Create a section file from a file, read only one particular section.
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
Lookup a boolean value in the secfile.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Q_GLOBAL_STATIC(QVector< QString >, future_name_translation)
bool rgbcolor_from_hex(struct rgbcolor **prgbcolor, const char *hex)
Convert a hex string into a rgb color.
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Free rgbcolor structure.
bool rgbcolors_are_equal(const struct rgbcolor *c1, const struct rgbcolor *c2)
Test whether two rgbcolor structures represent the exact same color value.
bool load_rulesets(const char *restore, const char *alt, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Loads the rulesets.
void send_rulesets(struct conn_list *dest)
Send all ruleset information to the specified connections.
bool reload_rulesets_settings()
Reload the game settings saved in the ruleset file.
void savegame_load(struct section_file *sfile)
Main entry point for loading a game.
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Unconditionally save the game, with specified filename.
bool script_fcdb_user_delegate_to(connection *pconn, player *pplayer, const char *delegate, bool &success)
returns Bool, whether pconn is allowed to delegate player to delegate.
bool script_fcdb_do_string(struct connection *caller, const char *str)
Parse and execute the script in str in the lua instance for the freeciv database.
bool script_fcdb_user_take(connection *requester, connection *taker, player *player, bool will_observe, bool &success)
returns Bool, whether requester is allowed to attach taker to pplayer.
bool script_fcdb_init(const QString &fcdb_luafile)
Initialize the scripting state.
void script_fcdb_free()
Free the scripting data.
bool script_server_unsafe_do_string(struct connection *caller, const char *str)
Parse and execute the script in str in an unsafe instance.
bool script_server_do_string(struct connection *caller, const char *str)
Parse and execute the script in str in the same instance as the ruleset.
bool script_server_unsafe_do_file(struct connection *caller, const char *filename)
Parse and execute the script at filename in an unsafe instance.
bool script_server_do_file(struct connection *caller, const char *filename)
Parse and execute the script at filename in the same instance as the ruleset.
bool setting_int_validate(const struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Returns TRUE if 'val' is a valid value for this setting.
void setting_action(const struct setting *pset)
Execute the action callback if needed.
void settings_reset()
Reset all settings iff they are changeable.
bool setting_enum_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Returns TRUE if 'val' is a valid value for this setting.
void setting_set_to_default(struct setting *pset)
Update the setting to the default value.
int setting_number(const struct setting *pset)
Returns the id to the given setting.
bool setting_int_set(struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Set the setting to 'val'.
bool setting_is_visible(const struct setting *pset, struct connection *caller)
Returns whether the specified server setting (option) can be seen by the caller.
bool setting_locked(const struct setting *pset)
Returns if the setting is locked by the ruleset.
bool setting_non_default(const struct setting *pset)
Returns whether the setting has non-default value.
enum sset_type setting_type(const struct setting *pset)
Access function for the setting type.
bool setting_str_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Set the setting to 'val'.
struct setting * setting_by_number(int id)
Returns the setting to the given id.
int setting_int_max(const struct setting *pset)
Returns the maximal integer value for this setting.
bool settings_game_reset()
Reset all settings to the values at game start.
const char * setting_enum_val(const struct setting *pset, int val, bool pretty)
Convert the integer to the string representation of an enumerator.
bool setting_bitwise_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Set the setting to 'val'.
bool setting_str_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Returns TRUE if 'val' is a valid value for this setting.
struct setting * setting_by_name(const char *name)
Returns the setting to the given name.
struct setting_list * level[OLEVELS_NUM]
void setting_changed(struct setting *pset)
Mark setting changed.
const char * setting_name(const struct setting *pset)
Access function for the setting name.
enum setting_default_level setting_get_setdef(const struct setting *pset)
Is the setting in changed state, or the default.
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Compute the name of the current value of the setting.
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Set the setting to 'val'.
int setting_int_min(const struct setting *pset)
Returns the minimal integer value for this setting.
bool setting_bitwise_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Returns TRUE if 'val' is a valid value for this setting.
const char * setting_short_help(const struct setting *pset)
Access function for the short help (not translated yet) of the setting.
const char * setting_extra_help(const struct setting *pset, bool constant)
Access function for the long (extra) help of the setting.
bool setting_bool_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Returns TRUE if 'val' is a valid value for this setting.
void settings_list_update()
Update sorted settings (changed and locked values).
bool setting_is_changeable(const struct setting *pset, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Returns whether the specified server setting (option) can currently be changed by the caller.
const char * setting_bitwise_bit(const struct setting *pset, int bit, bool pretty)
Convert the bit number to its string representation.
int settings_number()
Returns the total number of settings.
const char * setting_default_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Compute the name of the default value of the setting.
bool setting_bool_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Set the setting to 'val'.
void send_server_setting(struct conn_list *dest, const struct setting *pset)
Tell the client about just one server setting.
void send_server_settings(struct conn_list *dest)
Tell the client about all server settings.
#define settings_iterate(_level, _pset)
#define settings_iterate_end
void format_time_duration(time_t t, char *buf, int maxlen)
Convenience function to nicely format a time_t seconds value in to a string with hours,...
char * skip_leading_spaces(char *s)
Returns 's' incremented to first non-space character.
bool is_safe_filename(const QString &name)
Check if the name is safe security-wise.
const QStringList & get_data_dirs()
Returns a list of data directory paths, in the order in which they should be searched.
const char * m_pre_description(enum m_pre_result result)
Return a description string of the result.
void remove_trailing_spaces(char *s)
Terminates string pointed to by 's' to remove traling spaces; Note 's' must point to writeable memory...
bool str_to_int(const char *str, int *pint)
Convert 'str' to it's int reprentation if possible.
const QStringList & get_save_dirs()
Returns a list of save directory paths, in the order in which they should be searched.
QString interpret_tilde(const QString &filename)
Interpret ~ in filename as home dir.
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)
Given n names, with maximum length max_len_name, accessed by accessor_fn(0) to accessor_fn(n-1),...
QString fileinfoname(const QStringList &dirs, const QString &filename)
Returns a filename to access the specified file from a directory by searching all specified directori...
QVector< QString > * fileinfolist(const QStringList &dirs, const char *suffix)
Returns a string vector storing the filenames in the data directories matching the given suffix.
void remove_leading_spaces(char *s)
Removes leading spaces in string pointed to by 's'.
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)
See match_prefix_full().
QFileInfoList find_files_in_path(const QStringList &path, const QString &pattern, bool nodups)
Search for file names matching the pattern in the provided list of directories.
void remove_leading_trailing_spaces(char *s)
Removes leading and trailing spaces in string pointed to by 's'.
const QStringList & get_scenario_dirs()
Returns a list of scenario directory paths, in the order in which they should be searched.
#define CLIP(lower, current, upper)
#define FC_MEMBER_SIZEOF(type, member)
const char *(* m_pre_accessor_fn_t)(int)
#define UNIT_LOG(_, punit, msg,...)
#define CITY_LOG(_, pcity, msg,...)
void server_game_init(bool keep_ruleset_value)
Initialize game data for the server (corresponds to server_game_free).
const char * aifill(int amount)
Fill or remove players to meet the given aifill.
void check_for_full_turn_done()
Check if turn is really done.
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Set nation for player with nation default values.
void server_game_free()
Free game data that we reinitialize as part of a server soft restart.
void handle_player_ready(struct player *requestor, int player_no, bool is_ready)
Handle a player-ready packet.
void start_game()
Start actual game.
void set_server_state(enum server_states newstate)
Set current server state.
struct server_arguments srvarg
bool game_was_started()
Returns iff the game was started once upon a time.
enum server_states server_state()
Return current server state.
static bool write_command(struct connection *caller, char *arg, bool check)
Generate init script from settings currently in use.
static bool is_filename(int start)
Return whether we are completing filename.
static bool set_cmdlevel(struct connection *caller, struct connection *ptarget, enum cmdlevel level)
Set ptarget's cmdlevel to level if caller is allowed to do so.
#define LOOKUP_OPTION_AMBIGUOUS
static const char * mapimg_accessor(int i)
Returns possible parameters for the mapimg command.
void cmd_reply(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *format,...)
var-args version as above, no prefix
static const char * optname_accessor(int i)
Returns possible parameters for the commands that take server options as parameters (CMD_EXPLAIN and ...
void notify_if_first_access_level_is_available()
Check if first access level is available and if it is, notify connections about it.
static bool is_option_level(int start)
Returns true if the readline buffer string matches an option level or an option at the given position...
static bool set_command(struct connection *caller, char *str, bool check)
Handle set command.
static const char * playername_accessor(int idx)
Access player name.
static enum command_id cmd_of_level(enum ai_level level)
Translate an AI level back to its CMD_* value.
static void show_delegations(struct connection *caller)
List all delegations of the current game.
static char setting_status(struct connection *caller, const struct setting *pset)
Return the status of the setting (changeable, locked, fixed).
static void show_scenarios(struct connection *caller)
List scenarios.
static bool delegate_command(struct connection *caller, char *arg, bool check)
Handle delegation of control.
static bool ignore_command(struct connection *caller, char *str, bool check)
/ignore command handler.
static bool is_lua(int start)
Return whether we are completing argument for lua command.
static void show_help_command(struct connection *caller, enum command_id help_cmd, enum command_id id)
Show the caller detailed help for the single COMMAND given by id.
static bool is_command(int start)
Return whether we are completing command name.
static char * cmdlevel_arg1_generator(const char *text, int state)
The valid first argument to "cmdlevel".
static const int player_cmd[]
Commands that may be followed by a player name.
static const char * fcdb_accessor(int i)
Returns possible parameters for the fcdb command.
static void show_help_command_list(struct connection *caller, enum command_id help_cmd)
Show the caller list of COMMANDS.
static bool timeout_set_command(struct connection *caller, char *str, bool check, command_id self, bool add)
Sets the timeout for the current turn.
static void show_connections(struct connection *caller)
List connections; initially mainly for debugging.
static bool explain_option(struct connection *caller, char *str, bool check)
Handle explain command.
static char * lua_generator(const char *text, int state)
The valid arguments for the argument to "lua".
static const char * aitype_accessor(int idx)
Accessor for the second argument to "create": ai type name.
static bool is_enum_option_value(int start, int *opt_p)
Returns TRUE if the readline buffer string is such that we expect an enumerated value at the given po...
bool conn_is_kicked(struct connection *pconn, int *time_remaining)
Returns FALSE if the connection isn't kicked and can connect the server normally.
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)
Try to add a player to a running game in the following order:
static void show_colors(struct connection *caller)
Show a list of all players with the assigned color.
static bool set_ai_level(struct connection *caller, const char *name, enum ai_level level, bool check)
Set AI level.
static bool is_player(int start)
Return whether we are completing player name argument.
char ** freeciv_completion(const char *text, int start, int end)
Attempt to complete on the contents of TEXT.
static const char * lua_accessor(int i)
Returns possible parameters for the reset command.
static void show_help_option_list(struct connection *caller, enum command_id help_cmd)
Show the caller list of OPTIONS.
static char * player_generator(const char *text, int state)
The valid playername arguments.
static bool is_mapimg(int start)
Return whether we are completing first argument for mapimg command.
static bool take_command(struct connection *caller, char *str, bool check)
Take over a player.
static bool wall(char *str, bool check)
Send a message to all players.
static enum cmdlevel default_access_level
static void show_ruleset_info(struct connection *caller, enum command_id cmd, bool check, int read_recursion)
Show changed settings and ruleset summary.
static char * command_generator(const char *text, int state)
The valid commands at the root of the prompt.
static const int filename_cmd[]
Commands that may be followed by a filename.
static char * option_generator(const char *text, int state)
The valid arguments to "set" and "explain".
static bool is_help(int start)
Return whether we are completing help command argument.
void show_players(struct connection *caller)
Show the list of the players of the game.
static void cmd_reply_matches(enum command_id cmd, struct connection *caller, m_pre_accessor_fn_t accessor_fn, int *matches, int num_matches)
Send a reply to the caller listing the matched names from an ambiguous prefix.
#define LOOKUP_OPTION_NO_RESULT
static bool is_first_access_level_taken()
Return whether first access level is already taken.
static const char * delegate_accessor(int i)
Returns possible parameters for the 'delegate' command.
static char * cmdlevel_arg2_generator(const char *text, int state)
The valid arguments for the second argument to "cmdlevel".
static int lookup_option(const char *name)
Find option index by name.
static bool reset_command(struct connection *caller, char *arg, bool check, int read_recursion)
Reload the game settings from the ruleset and reload the init script if one was used.
static void show_teams(struct connection *caller)
Show a list of teams on the command line.
static bool handle_stdin_input_real(struct connection *caller, char *str, bool check, int read_recursion)
Handle "command input", which could really come from stdin on console, or from client chat command,...
static char * generic_generator(const char *text, int state, int num, const char *(*index2str)(int))
A generalised generator function: text and state are "standard" parameters to a readline generator fu...
enum rfc_status create_command_pregame(const char *name, const char *ai, bool check, struct player **newplayer, char *buf, size_t buflen)
Create player in pregame.
void stdinhand_turn()
Update stuff every turn that is related to this code module.
static const char * helparg_accessor(int i)
Convert unified helparg index to string; see above.
static bool metaconnection_command(struct connection *caller, char *arg, bool check)
Handle metaconnection command.
static bool show_serverid(struct connection *caller, char *arg)
Returns the serverid.
static void show_nationsets(struct connection *caller)
List nation sets in the current ruleset.
static bool contains_str_before_start(int start, const char *cmd, bool allow_fluff)
Returns whether the text between the start of rl_line_buffer and the start position is of the form [n...
static char * mapimg_generator(const char *text, int state)
The valid arguments for the first argument to "mapimg".
static bool metamessage_command(struct connection *caller, char *arg, bool check)
Handle metamessage command.
static bool away_command(struct connection *caller, bool check)
Set user to away mode.
static bool playercolor_command(struct connection *caller, char *str, bool check)
/playercolor command handler.
void stdinhand_init()
Initialize stuff related to this code module.
static bool is_fcdb(int start)
Return whether we are completing argument for fcdb command.
static const int server_option_cmd[]
Commands that may be followed by a server option name.
static char * connection_generator(const char *text, int state)
The valid connection user name arguments.
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Set an AI level from the server prompt.
static bool player_name_check(const char *name, char *buf, size_t buflen)
Check the player name.
static bool default_command(struct connection *caller, char *arg, bool check)
Set a setting to its default value.
static bool create_command(struct connection *caller, const char *str, bool check)
Creates a named AI player.
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)
va_list version which allow embedded newlines, and each line is sent separately.
static bool is_list(int start)
Return whether we are completing list command argument.
static void show_rulesets(struct connection *caller)
List rulesets (strictly, .serv init script files that conventionally accompany rulesets).
static bool is_cmdlevel_arg2(int start)
Return whether we are completing cmdlevel command argument 2.
static char * olevel_generator(const char *text, int state)
The valid arguments to "show".
static bool surrender_command(struct connection *caller, char *str, bool check)
Concede the game.
static bool end_command(struct connection *caller, char *str, bool check)
End the game immediately in a draw.
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__
var-args version of above duplicate declaration required for attribute to work...
static char * vote_generator(const char *text, int state)
The valid arguments for the argument to "vote".
#define LOOKUP_OPTION_RULESETDIR
static bool timeout_command(struct connection *caller, char *str, bool check)
Set timeout options.
static void cmd_reply_no_such_player(enum command_id cmd, struct connection *caller, const char *name, enum m_pre_result match_result)
Command specific argument parsing has detected that player argument is invalid.
static bool is_delegate_arg1(int start)
Return whether we are completing first argument for delegate command.
static bool metaserver_command(struct connection *caller, char *arg, bool check)
Handle metaserver command.
bool handle_stdin_input(struct connection *caller, char *str)
Main entry point for "command input".
static bool cut_client_connection(struct connection *caller, char *name, bool check)
Handle cut command.
static void open_metaserver_connection(struct connection *caller, bool persistent)
Start sending game info to metaserver.
static const char * option_value_accessor(int idx)
static int completion_option
Accessor for values of the enum/bitwise option defined by 'completion_option'.
static void show_mapimg(struct connection *caller, enum command_id cmd)
Show a list of all map image definitions on the command line.
static bool may_use_nothing(struct connection *caller)
Whether the caller cannot use any commands at all.
static void show_votes(struct connection *caller)
List all running votes.
static const char * cmdlevel_arg1_accessor(int idx)
Extra accessor function since cmdlevel_name() takes enum argument, not int.
static const char *const vote_args[]
Vote command argument definitions.
static bool show_settings(struct connection *caller, enum command_id called_as, char *str, bool check)
Print a summary of the settings and their values.
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
Main entry point for reading an init script.
static bool is_reset(int start)
Return whether we are completing argument for reset command.
static bool cmdlevel_command(struct connection *caller, char *str, bool check)
Change command access level for individual player, or all, or new.
enum cmdlevel access_level_for_next_connection()
Return access level for next connection.
#define LOOKUP_OPTION_LEVEL_NAME
static bool firstlevel_command(struct connection *caller, bool check)
This special command to set the command access level is not included into cmdlevel_command because of...
static bool connectmsg_command(struct connection *caller, char *str, bool check)
Set message to send to all new connections.
static const char horiz_line[]
static char * delegate_generator(const char *text, int state)
The valid arguments for the first argument to "delegate".
QHash< QString, time_t > kickhash
static void cmd_reply_no_such_conn(enum command_id cmd, struct connection *caller, const char *name, enum m_pre_result match_result)
Command specific argument parsing has detected that connection argument is invalid.
static const char * vote_arg_accessor(int i)
static char * aitype_generator(const char *text, int state)
The valid arguments for the second argument to "create".
static void cmd_reply_line(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *prefix, const char *line)
feedback related to server commands caller == nullptr means console.
static const char * olvlname_accessor(int i)
Returns possible parameters for the /show command.
static void show_help_intro(struct connection *caller, enum command_id help_cmd)
Show caller introductory help about the server.
static char * reset_generator(const char *text, int state)
The valid arguments for the argument to "reset".
static const int option_level_cmd[]
Commands that may be followed by an option level or server option.
static bool cancelvote_command(struct connection *caller, char *arg, bool check)
Cancel a vote...
static bool is_cmdlevel_arg1(int start)
Return whether we are completing cmdlevel command argument.
static bool timeout_show_command(struct connection *caller, char *str, bool check)
Show the current timeout, time left before TC, etc.
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Loads a file, complete with access checks and error messages sent back to the caller on failure.
static bool read_init_script_real(struct connection *caller, const char *script_filename, bool from_cmdline, bool check, int read_recursion)
Returns FALSE iff there was an error.
static void show_settings_one(struct connection *caller, enum command_id cmd, struct setting *pset)
Show one setting.
static bool toggle_ai_command(struct connection *caller, char *arg, bool check)
Handle aitoggle command.
static bool playernation_command(struct connection *caller, char *str, bool check)
/playernation command handler.
static bool team_command(struct connection *caller, char *str, bool check)
Handle team command.
static bool quit_game(struct connection *caller, bool check)
Handle quit command.
static struct setting * validate_setting_arg(enum command_id cmd, struct connection *caller, char *arg)
Helper to validate an argument referring to a server setting.
static bool vote_command(struct connection *caller, char *str, bool check)
Make or participate in a vote.
#define cmd_reply_show(string)
bool start_command(struct connection *caller, bool check, bool notify)
Handle start command.
static bool show_help(struct connection *caller, char *arg)
Handle help command.
static bool contains_token_before_start(int start, int token, const char *arg, bool allow_fluff)
Generalised version of contains_str_before_start, which searches the N'th token in rl_line_buffer (0=...
static char * help_generator(const char *text, int state)
The valid first arguments to "help".
static bool a_connection_exists()
Returns true if there is at least one established connection.
#define OPTION_NAME_SPACE
static bool remove_player_command(struct connection *caller, char *arg, bool check)
Handle remove command.
static int num_tokens(int start)
Number of tokens in rl_line_buffer before start.
static bool debug_command(struct connection *caller, char *str, bool check)
Turn on selective debugging.
static enum command_id command_named(const char *token, bool accept_ambiguity)
Convert a named command into an id.
static const char * connection_name_accessor(int idx)
Access connection user name, from game.all_connections.
static void start_cmd_reply(struct connection *caller, bool notify, const char *msg)
Send start command related message.
QVector< QString > * get_init_script_choices()
Return a list of init scripts found on the data path.
static bool fcdb_command(struct connection *caller, char *arg, bool check)
Handle the freeciv database script module.
static bool set_rulesetdir(struct connection *caller, char *str, bool check, int read_recursion)
Load rulesets from a given ruleset directory.
static bool mapimg_command(struct connection *caller, char *arg, bool check)
Handle mapimg command.
static char * fcdb_generator(const char *text, int state)
The valid arguments for the argument to "fcdb".
static bool unignore_command(struct connection *caller, char *str, bool check)
/unignore command handler.
static bool observe_command(struct connection *caller, char *str, bool check)
Observe another player.
static bool show_list(struct connection *caller, char *arg)
Show list of players or connections, or connection statistics.
static bool scensave_command(struct connection *caller, char *arg, bool check)
For command "scensave foo"; Save the game, with filename=arg, provided server state is ok.
static enum sset_level lookup_option_level(const char *name)
Find option level number by name.
static bool may_use(struct connection *caller, enum command_id cmd)
Whether the caller can use the specified command.
static bool kick_command(struct connection *caller, char *name, bool check)
Kick command handler.
static bool is_connection(int start)
Return whether we are completing connection name argument.
static bool is_server_option(int start)
Returns TRUE if the readline buffer string matches a server option at the given position.
static const char * cmdlevel_arg2_accessor(int idx)
Accessor for the second argument to "cmdlevel": "first" or "new" or a connection name.
static bool is_create_arg2(int start)
Return whether we are completing second argument for create command.
bool should_quit()
Returns whether the server should exit after a command.
static bool is_restricted(struct connection *caller)
Are we operating under a restricted security regime? For now this does not do much.
static bool show_command(struct connection *caller, char *str, bool check)
/show command: show settings and their values.
static bool lua_command(struct connection *caller, char *arg, bool check, int read_recursion)
Evaluate a line of lua script or a lua script file.
static const char * reset_accessor(int i)
Returns possible parameters for the reset command.
static const int connection_cmd[]
Commands that may be followed by a connection name.
static enum cmdlevel first_access_level
void stdinhand_free()
Deinitialize stuff related to this code module.
static bool detach_command(struct connection *caller, char *str, bool check)
Detach from a player.
static bool aicmd_command(struct connection *caller, char *arg, bool check)
Execute a command in the context of the AI of the player.
static void close_metaserver_connection(struct connection *caller)
Stop sending game info to metaserver.
static bool save_command(struct connection *caller, char *arg, bool check)
For command "save foo"; Save the game, with filename=arg, provided server state is ok.
static bool set_ai_level_named(struct connection *caller, const char *name, const char *level_name, bool check)
Handle a user command to set an AI level.
static void write_init_script(char *script_filename)
Write current settings to new init script.
static char * option_value_generator(const char *text, int state)
The valid arguments to "set OPT", where OPT is the enumerated or bitwise option previously defined by...
static bool is_vote(int start)
Return whether we are completing argument for vote command.
static bool metapatches_command(struct connection *caller, char *arg, bool check)
Handle metapatches command.
static bool show_ignore(struct connection *caller)
Show the ignore list of the.
static bool is_allowed_to_take(struct connection *requester, struct connection *taker, struct player *pplayer, bool will_obs, char *msg, size_t msg_len)
Check game.allow_take and fcdb if enabled for permission to take or observe a player.
static char * list_generator(const char *text, int state)
The valid first arguments to "list".
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Handle ai player ai toggling.
static void show_help_option(struct connection *caller, enum command_id help_cmd, int id)
Show the caller detailed help for the single OPTION given by id.
void set_running_game_access_level()
Adjust default command level on game start.
static bool read_command(struct connection *caller, char *arg, bool check, int read_recursion)
Main entry point for the read command.
static const char * list_accessor(int i)
Returns possible parameters for the list command.
static QString delegate_player_str(struct player *pplayer, bool observer)
Return static string describing what a connection is connected to.
static void remove_quotes(QStringList &str)
struct ai_type::@12 funcs
void(* gained_control)(struct player *pplayer)
void(* player_console)(struct player *pplayer, const char *cmd)
struct city::@15::@17 server
struct civ_game::@28::@32 server
struct conn_list * est_connections
struct packet_game_info info
struct conn_list * all_connections
struct packet_timeout_info tinfo
enum cmdlevel access_level
struct connection::@55::@61 server
char username[MAX_LEN_NAME]
char ipaddr[MAX_LEN_ADDR]
enum ai_level skill_level
struct player_ai ai_common
struct government * target_government
char username[MAX_LEN_NAME]
struct player::@65::@67 server
struct government * government
const struct ai_type * ai
struct conn_list * connections
struct nation_style * style
struct unit::@76::@79 server
struct nation_style * style_by_rule_name(const char *name)
Returns style matching rule name or nullptr if there is no style with such name.
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
int fc_break_lines(char *str, size_t desired_len)
Replace the spaces by line breaks when the line lenght is over the desired one.
FILE * fc_fopen(const char *filename, const char *opentype)
Wrapper function for fopen() with filename conversion to local encoding on Windows.
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Compare strings like strncmp(), but ignoring case.
#define sz_strlcpy(dest, src)
int fc__attribute((nonnull(1, 3)))
#define sz_strlcat(dest, src)
int team_index(const struct team *pteam)
Return the team index.
const char * team_name_translation(const struct team *pteam)
Returns the name (translated) of the team.
void team_add_player(struct player *pplayer, struct team *pteam)
Set a player to a team.
const char * team_slot_name_translation(const struct team_slot *tslot)
Returns the name (translated) of the slot.
const struct player_list * team_members(const struct team *pteam)
Returns the member list of the team.
struct team * team_new(struct team_slot *tslot)
Creates a new team for the slot.
void team_remove_player(struct player *pplayer)
Remove the player from the team.
struct team_slot * team_slot_by_rule_name(const char *team_name)
Does a linear search for a (defined) team name.
struct team_slot * team_slot_by_number(int team_id)
Return the possibly unused and uninitialized team slot.
#define teams_iterate_end
#define teams_iterate(_pteam)
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
void timer_destroy(civtimer *t)
Deletes timer.
double timer_read_seconds(civtimer *t)
Read value from timer.
civtimer * timer_new(enum timer_timetype type, enum timer_use use)
Allocate a new timer with specified "type" and "use".
void timer_start(civtimer *t)
Start timing, adding to previous accumulated time if timer has not been cleared.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
const char * unit_name_translation(const struct unit *punit)
Return the (translated) name of the unit.
const char * freeciv21_version()
Returns the raw version string.
int describe_vote(struct vote *pvote, char *buf, int buflen)
Fills the supplied buffer with a string describing the given vote.
struct vote * vote_new(struct connection *caller, const char *allargs, int command_id)
Create and return a newly allocated vote for the command with id 'command_id' and all arguments in th...
bool conn_can_vote(const struct connection *pconn, const struct vote *pvote)
A user cannot vote if: is not connected access level < basic isn't a player the vote is a team vote a...
const struct connection * vote_get_caller(const struct vote *pvote)
Returns the connection that called this vote.
bool vote_is_team_only(const struct vote *pvote)
Returns TRUE if this vote is a "teamvote".
bool vote_would_pass_immediately(const struct connection *caller, int command_id)
Return whether the vote would pass immediately when the caller will vote for.
void connection_vote(struct connection *pconn, struct vote *pvote, enum vote_type type)
Make the given connection vote 'type' on 'pvote', and check the vote.
struct vote_list * vote_list
struct vote * get_vote_by_caller(const struct connection *caller)
Returns the vote called by 'caller', or nullptr if none exists.
int count_voters(const struct vote *pvote)
Helper function that returns the current number of eligible voters.
void clear_all_votes()
Remove all votes.
void remove_vote(struct vote *pvote)
Remove the given vote and send a vote_remove packet to clients.
struct vote * get_vote_by_no(int vote_no)
Returns the vote with vote number 'vote_no', or nullptr.
bool conn_can_see_vote(const struct connection *pconn, const struct vote *pvote)
Usually, all users can see, except in the team vote case.
#define vote_list_iterate_end
#define vote_list_iterate(alist, pvote)