Freeciv21
Develop your civilization from humble roots to a global empire
capstr.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include <cstdlib> // getenv()
15 
16 // utility
17 #include "support.h"
18 
19 // generated
20 #include "fc_version.h"
21 
22 // common
23 #include "connection.h" // MAX_LEN_CAPSTR
24 
25 #include "capstr.h"
26 
29 
30 /* Capabilities: original author: Mitch Davis (mjd@alphalink.com.au)
31  *
32  * The capability string is a string clients and servers trade to find
33  * out if they can talk to each other, and using which protocol version,
34  * and which features and behaviors to expect. The string is a list of
35  * words, separated by whitespace and/or commas, where each word indicates
36  * a capability that this version of Freeciv understands.
37  * If a capability word is mandatory, it should start with a "+".
38  *
39  * eg, #define CAPABILITY "+1.6, MapScroll, +AutoSettlers"
40  *
41  * Client and server functions can test these strings for a particular
42  * capability by calling the functions in capability.c
43  *
44  * Each executable has a string our_capability (above), which gives the
45  * capabilities of the running executable. This is normally initialised
46  * with CAPABILITY, but can be changed at run-time by setting the
47  * FREECIV_CAPS environment variable, though that is probably mainly
48  * useful for testing purposes.
49  *
50  * For checking the connections of other executables, each
51  * "struct connection" has a capability string, which gives the
52  * capability of the executable at the other end of the connection.
53  * So for the client, the capability of the server is in
54  * client.conn.capability, and for the server, the capabilities of
55  * connected clients are in player_by_number(i)->conn.capability
56  * The client now also knows the capabilities of other clients,
57  * via player_by_number(i)->conn.capability.
58  *
59  * Note the connection struct is a parameter to the functions to send and
60  * receive packets, which may be convenient for adjusting how a packet is
61  * sent or interpreted based on the capabilities of the connection.
62  *
63  * At the time of a major release, the capability string may be
64  * simplified; eg, the example string above could be replaced by "+1.7".
65  * (This should probably only happen if a mandatory capability has
66  * been introduced since the previous release.)
67  * Whoever makes such a change has responsibility to search the Freeciv
68  * code, and look for places where people are using has_capability.
69  * If you're taking a capability out of the string, because now every
70  * client and server supports it, then you should take out the
71  * if (has_capability()) code so that this code is always executed.
72  *
73  * (The savefile and ruleset files have strings which are used similarly,
74  * and checked by the same has_capability function, but the strings there
75  * are not directly related to the capability strings discussed here.)
76  *
77  * The actual capability string is now defined in fc_version.
78  */
79 
84 {
85  const char *s;
86 
87  s = getenv("FREECIV_CAPS");
88  if (!s) {
89  s = NETWORK_CAPSTRING;
90  }
92 }
const char *const our_capability
Definition: capstr.cpp:28
void init_our_capability()
Setup our internal network capability string.
Definition: capstr.cpp:83
static char our_capability_internal[MAX_LEN_CAPSTR]
Definition: capstr.cpp:27
#define MAX_LEN_CAPSTR
Definition: connection.h:42
#define sz_strlcpy(dest, src)
Definition: support.h:140