14 #include <fc_config.h>
18 #include <QNetworkAccessManager>
19 #include <QNetworkReply>
20 #include <QNetworkRequest>
66 return "development version: beware";
99 if (
game.
server.meta_info.user_message[0] !=
'\0') {
114 const char *user_message;
118 if (user_message ==
nullptr) {
120 if (automatic !=
nullptr) {
150 if (
string !=
nullptr &&
string[0] !=
'\0') {
172 _(
"Not reporting to the metaserver in this game."));
186 const char *set_name)
193 query->addQueryItem(QStringLiteral(
"vn[]"),
196 QStringLiteral(
"vv[]"),
207 auto *manager =
new QNetworkAccessManager;
210 auto *post =
static_cast<QUrlQuery *
>(arg);
213 request.setHeader(QNetworkRequest::UserAgentHeader,
215 request.setHeader(QNetworkRequest::ContentTypeHeader,
216 QLatin1String(
"application/x-www-form-urlencoded"));
218 manager->post(request, post->toString(QUrl::FullyEncoded).toUtf8());
223 QObject::connect(reply, &QNetworkReply::finished, [&] {
224 if (reply->error() != QNetworkReply::NoError) {
225 con_puts(C_METAERROR, _(
"Error connecting to metaserver"));
226 qCritical(_(
"Error message: %s"),
227 qUtf8Printable(reply->errorString()));
232 reply->deleteLater();
233 manager->deleteLater();
278 QUrlQuery *post =
new QUrlQuery;
280 post->addQueryItem(QStringLiteral(
"host"), QString::fromUtf8(host));
281 post->addQueryItem(QStringLiteral(
"port"),
283 post->addQueryItem(QStringLiteral(
"state"), QString::fromUtf8(state));
284 post->addQueryItem(QStringLiteral(
"ruleset"), QString::fromUtf8(rs));
287 post->addQueryItem(QStringLiteral(
"bye"), QStringLiteral(
"1"));
291 if (srvtype !=
nullptr) {
292 post->addQueryItem(QStringLiteral(
"type"), QString::fromUtf8(srvtype));
295 post->addQueryItem(QStringLiteral(
"patches"),
297 post->addQueryItem(QStringLiteral(
"capability"),
301 post->addQueryItem(QStringLiteral(
"message"),
306 post->addQueryItem(QStringLiteral(
"dropplrs"), QStringLiteral(
"1"));
313 bool is_player_available =
true;
317 if (!plr->is_alive) {
318 type = QLatin1String(
"Dead");
320 type = QLatin1String(
"Barbarian");
321 }
else if (
is_ai(plr)) {
322 type = QLatin1String(
"A.I.");
324 type = QLatin1String(
"Human");
326 type = QLatin1String(
"-");
329 post->addQueryItem(QStringLiteral(
"plu[]"),
330 QString::fromUtf8(plr->username));
331 post->addQueryItem(QStringLiteral(
"plt[]"), type);
332 post->addQueryItem(QStringLiteral(
"pll[]"),
335 QStringLiteral(
"pln[]"),
340 QStringLiteral(
"plf[]"),
344 post->addQueryItem(QStringLiteral(
"plh[]"),
345 pconn ? pconn->
addr : QLatin1String(
""));
351 is_player_available =
false;
352 }
else if (!plr->is_alive && !strchr(
game.
server.allow_take,
'd')) {
353 is_player_available =
false;
354 }
else if (
is_ai(plr)
356 (
game.
info.is_new_game ?
'A' :
'a'))) {
357 is_player_available =
false;
360 (
game.
info.is_new_game ?
'H' :
'h'))) {
361 is_player_available =
false;
365 is_player_available =
false;
368 if (is_player_available) {
372 if (
is_human(plr) && plr->is_alive) {
379 post->addQueryItem(QStringLiteral(
"available"),
380 QStringLiteral(
"%1").arg(players));
381 post->addQueryItem(QStringLiteral(
"humans"),
382 QStringLiteral(
"%1").arg(humans));
387 static const char *
settings[] = {
"timeout",
"endturn",
"minplayers",
388 "maxplayers",
"aifill",
"allowtake",
412 post->addQueryItem(QStringLiteral(
"vn[]"), QStringLiteral(
"turn"));
413 post->addQueryItem(QStringLiteral(
"vv[]"),
414 QStringLiteral(
"%1").arg(
game.
info.turn));
415 post->addQueryItem(QStringLiteral(
"vn[]"), QStringLiteral(
"year"));
418 post->addQueryItem(QStringLiteral(
"vv[]"),
419 QStringLiteral(
"%1").arg(
game.
info.year));
421 post->addQueryItem(QStringLiteral(
"vv[]"),
422 QStringLiteral(
"Calendar not set up"));
428 meta_srv_thread->start(QThread::NormalPriority);
471 static civtimer *last_send_timer =
nullptr;
472 static bool want_update;
489 if (last_send_timer) {
491 last_send_timer =
nullptr;
495 meta_srv_thread->wait();
496 meta_srv_thread->quit();
513 if ((flag ==
META_REFRESH) && !want_update && last_send_timer
520 if (!last_send_timer) {
const char *const our_capability
struct connection * conn_by_user(const char *user_name)
Find connection by exact user name, from game.all_connections, case-insensitve.
void con_flush()
Ensure timely update.
void con_puts(enum rfc_status rfc_status, const char *str)
Write to console and add line-break, and show prompt if required.
#define fc_assert_ret_val_msg(condition, val, message,...)
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
#define NO_NATION_SELECTED
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
#define players_iterate_end
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
int normal_player_count()
Return the number of non-barbarian players.
static struct setting settings[]
struct setting * setting_by_name(const char *name)
Returns the setting to the given name.
const char * setting_name(const struct setting *pset)
Access function for the setting name.
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.
struct server_arguments srvarg
enum server_states server_state()
Return current server state.
struct civ_game::@28::@32 server
struct packet_ruleset_control control
struct packet_game_info info
struct civ_map::@39::@41 server
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
int fc_gethostname(char *buf, size_t len)
Call gethostname() if supported, else just returns -1.
#define sz_strlcpy(dest, src)
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.
void timer_clear(civtimer *t)
Reset accumulated time to zero, and stop timer if going.
const char * freeciv21_version()
Returns the raw version string.