2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
9 * @file config.cpp Configuration of the connection strings for network stuff using environment variables.
12 #include "../../stdafx.h"
14 #include "../../string_func.h"
16 #include "../../safeguards.h"
19 * Get the environment variable using std::getenv and when it is an empty string (or nullptr), return a fallback value instead.
20 * @param variable The environment variable to read from.
21 * @param fallback The fallback in case the environment variable is not set.
22 * @return The environment value, or when that does not exist the given fallback value.
24 static const char *GetEnv(const char *variable
, const char *fallback
)
26 const char *value
= std::getenv(variable
);
27 return StrEmpty(value
) ? fallback
: value
;
31 * Get the connection string for the game coordinator from the environment variable OTTD_COORDINATOR_CS,
32 * or when it has not been set a hard coded default DNS hostname of the production server.
33 * @return The game coordinator's connection string.
35 const char *NetworkCoordinatorConnectionString()
37 return GetEnv("OTTD_COORDINATOR_CS", "coordinator.openttd.org");
41 * Get the connection string for the STUN server from the environment variable OTTD_STUN_CS,
42 * or when it has not been set a hard coded default DNS hostname of the production server.
43 * @return The STUN server's connection string.
45 const char *NetworkStunConnectionString()
47 return GetEnv("OTTD_STUN_CS", "stun.openttd.org");
51 * Get the connection string for the content server from the environment variable OTTD_CONTENT_SERVER_CS,
52 * or when it has not been set a hard coded default DNS hostname of the production server.
53 * @return The content server's connection string.
55 const char *NetworkContentServerConnectionString()
57 return GetEnv("OTTD_CONTENT_SERVER_CS", "content.openttd.org");
61 * Get the URI string for the content mirror from the environment variable OTTD_CONTENT_MIRROR_URI,
62 * or when it has not been set a hard coded URI of the production server.
63 * @return The content mirror's URI string.
65 const char *NetworkContentMirrorUriString()
67 return GetEnv("OTTD_CONTENT_MIRROR_URI", "https://binaries.openttd.org/bananas");
71 * Get the URI string for the survey from the environment variable OTTD_SURVEY_URI,
72 * or when it has not been set a hard coded URI of the production server.
73 * @return The survey's URI string.
75 const char *NetworkSurveyUriString()
77 return GetEnv("OTTD_SURVEY_URI", "https://survey-participate.openttd.org/");