Skip to content

Commit b418fcf

Browse files
Read game information from gameinfo.conf file, fix Unvanquished/Unvanquished#817
Co-authored-by: Sebastian Schmidt <schro.sb@gmail.com> Co-authored-by: Thomas “illwieckz” Debesse <dev@illwieckz.net>
1 parent f0fbea6 commit b418fcf

20 files changed

Lines changed: 337 additions & 76 deletions

src.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ set(ENGINELIST
248248
${ENGINE_DIR}/sys/con_common.h
249249
${ENGINE_DIR}/sys/con_common.cpp
250250
${ENGINE_DIR}/sys/sys_events.h
251+
${ENGINE_DIR}/qcommon/gameinfo.h
252+
${ENGINE_DIR}/qcommon/gameinfo.cpp
251253
)
252254

253255
if (WIN32)

src/common/Defs.h

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
#ifndef COMMON_DEFS_H_
3232
#define COMMON_DEFS_H_
3333

34-
#define PRODUCT_NAME "Unvanquished"
35-
/** Case, No spaces */
36-
#define PRODUCT_NAME_UPPER "UNVANQUISHED"
37-
/** No case, No spaces */
38-
#define PRODUCT_NAME_LOWER "unvanquished"
34+
#ifndef ENGINE_NAME
35+
#define ENGINE_NAME "Daemon Engine"
36+
#endif
3937

40-
#define PRODUCT_VERSION "0.52.1"
38+
#ifndef ENGINE_VERSION
39+
#define ENGINE_VERSION "0.52.1"
40+
#endif
4141

42-
/** Default base package */
43-
#define DEFAULT_BASE_PAK PRODUCT_NAME_LOWER
44-
45-
/** URI scheme and server browser filter */
46-
#define GAMENAME_STRING "unv"
47-
#define GAMENAME_FOR_MASTER PRODUCT_NAME_UPPER
42+
#ifndef ENGINE_DATE
43+
#define ENGINE_DATE __DATE__
44+
#endif
4845

4946
#define MAX_MASTER_SERVERS 5
50-
#define MASTER1_SERVER_NAME "master.unvanquished.net"
51-
#define MASTER2_SERVER_NAME "master2.unvanquished.net"
52-
#define MASTER3_SERVER_NAME ""
53-
#define MASTER4_SERVER_NAME ""
54-
#define MASTER5_SERVER_NAME ""
55-
56-
#define WWW_BASEURL "dl.unvanquished.net/pkg"
57-
5847
#define AUTOEXEC_NAME "autoexec.cfg"
5948

6049
#define CONFIG_NAME "autogen.cfg"
6150
#define KEYBINDINGS_NAME "keybindings.cfg"
6251
#define TEAMCONFIG_NAME "teamconfig.cfg"
6352

6453
#define UNNAMED_PLAYER "UnnamedPlayer"
65-
#define UNNAMED_SERVER PRODUCT_NAME " " PRODUCT_VERSION " Server"
6654

6755
/** file containing our RSA public and private keys */
6856
#define RSAKEY_FILE "pubkey"

src/common/FileSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,19 +2332,19 @@ std::string DefaultHomePath()
23322332
wchar_t buffer[MAX_PATH];
23332333
if (!SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, buffer)))
23342334
return "";
2335-
return Str::UTF16To8(buffer) + "\\My Games\\" PRODUCT_NAME;
2335+
return Str::UTF16To8(buffer) + "\\My Games\\" + Gameinfo::getInstance().name();
23362336
#else
23372337
const char* home = getenv("HOME");
23382338
if (!home)
23392339
return "";
23402340
#ifdef __APPLE__
2341-
return std::string(home) + "/Library/Application Support/" PRODUCT_NAME;
2341+
return std::string(home) + "/Library/Application Support/" + Gameinfo::getInstance().name();
23422342
#else
23432343
const char* _xdgDataHome = getenv("XDG_DATA_HOME");
23442344
std::string xdgDataHome = _xdgDataHome == nullptr ? Path::Build(Path::Build(std::string(home), ".local") ,"share") : std::string(_xdgDataHome);
23452345
std::string xdgHomePath;
23462346

2347-
xdgHomePath = Path::Build(xdgDataHome, PRODUCT_NAME_LOWER);
2347+
xdgHomePath = Path::Build(xdgDataHome, Gameinfo::getInstance().name_lower());
23482348

23492349
return xdgHomePath;
23502350
#endif

src/engine/client/ClientApplication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ClientApplication : public Application {
9898
void Shutdown(bool error, Str::StringRef message) override {
9999
#if defined(_WIN32) || defined(BUILD_GRAPHICAL_CLIENT)
100100
if (error) {
101-
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, PRODUCT_NAME, message.c_str(), nullptr);
101+
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, ENGINE_NAME, message.c_str(), nullptr);
102102
}
103103
#endif
104104

src/engine/client/cl_console.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ void Con_DrawAboutText()
688688
//ANIMATION_TYPE_FADE but also ANIMATION_TYPE_SCROLL_DOWN needs this, latter, since it might otherwise scroll out the console
689689
color.SetAlpha( 0.66f * consoleState.currentAnimationFraction );
690690

691-
Con_DrawRightFloatingTextLine( 0, color, Q3_VERSION );
692-
Con_DrawRightFloatingTextLine( 1, color, Q3_ENGINE );
691+
Con_DrawRightFloatingTextLine( 0, color, GAME_NAME_VERSION );
692+
Con_DrawRightFloatingTextLine( 1, color, ENGINE_NAME_VERSION );
693693
}
694694

695695
/*

src/engine/client/cl_main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,10 @@ void CL_Connect_f()
10181018
}
10191019

10201020
// Skip the URI scheme.
1021-
if ( !Q_strnicmp( server, URI_SCHEME, URI_SCHEME_LENGTH ) )
1021+
std::string uri_scheme = Str::Format("%s://", Gameinfo::getInstance().uriprotocol());
1022+
if ( !Q_strnicmp( server, uri_scheme.c_str(), uri_scheme.length() ) )
10221023
{
1023-
server += URI_SCHEME_LENGTH;
1024+
server += uri_scheme.length();
10241025
}
10251026

10261027
// Set and skip the password.
@@ -2894,7 +2895,7 @@ void CL_Init()
28942895

28952896
p_team = Cvar_Get("p_team", "0", CVAR_ROM );
28962897

2897-
cl_gamename = Cvar_Get( "cl_gamename", GAMENAME_FOR_MASTER, CVAR_TEMP );
2898+
cl_gamename = Cvar_Get( "cl_gamename", Gameinfo::getInstance().name_upper().c_str(), CVAR_TEMP );
28982899
cl_altTab = Cvar_Get( "cl_altTab", "1", 0 );
28992900

29002901
//bani
@@ -3112,7 +3113,7 @@ void CL_ServerInfoPacket( const netadr_t& from, msg_t *msg )
31123113
// Arnout: if this isn't the correct game, ignore it
31133114
gameName = Info_ValueForKey( infoString, "gamename" );
31143115

3115-
if ( !gameName[ 0 ] || Q_stricmp( gameName, GAMENAME_STRING ) )
3116+
if ( !gameName[ 0 ] || Q_stricmp( gameName, Gameinfo::getInstance().gamename().c_str() ) )
31163117
{
31173118
Log::Debug( "Different game info packet: %s", infoString );
31183119
return;

src/engine/client/dl_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ if (curl_easy_setopt(request_, option, value) != CURLE_OK) { \
169169
return false; \
170170
}
171171

172-
SETOPT( CURLOPT_USERAGENT, Str::Format( "%s %s", PRODUCT_NAME "/" PRODUCT_VERSION, curl_version() ).c_str() )
173-
SETOPT( CURLOPT_REFERER, Str::Format("%s%s", URI_SCHEME, Cvar::GetValue("cl_currentServerIP")).c_str() )
172+
SETOPT( CURLOPT_USERAGENT, Str::Format( "%s %s", ENGINE_NAME "/" ENGINE_VERSION, curl_version() ).c_str() )
173+
SETOPT( CURLOPT_REFERER, Str::Format("%s://%s", Gameinfo::getInstance().uriprotocol().c_str(), Cvar::GetValue("cl_currentServerIP")).c_str() )
174174
SETOPT( CURLOPT_URL, url.c_str() )
175175
SETOPT( CURLOPT_PROTOCOLS, long(CURLPROTO_HTTP) )
176176
SETOPT( CURLOPT_WRITEFUNCTION, curl_write_callback(LibcurlWriteCallback) )

src/engine/framework/System.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ std::string GetSingletonSocketPath()
7171
char homePathHash[33] = "";
7272
Com_MD5Buffer(homePath.data(), homePath.size(), homePathHash, sizeof(homePathHash));
7373
#ifdef _WIN32
74-
return std::string("\\\\.\\pipe\\" PRODUCT_NAME) + suffix + "-" + homePathHash;
74+
return std::string("\\\\.\\pipe\\") + Gameinfo::getInstance().name() + suffix + "-" + homePathHash;
7575
#else
7676
// We use a temporary directory rather that using the homepath because
7777
// socket paths are limited to about 100 characters. This also avoids issues
7878
// when the homepath is on a network filesystem.
79-
return std::string("/tmp/." PRODUCT_NAME_LOWER) + suffix + "-" + homePathHash + "/socket";
79+
return std::string("/tmp/.") + Gameinfo::getInstance().name_lower() + suffix + "-" + homePathHash + "/socket";
8080
#endif
8181
}
8282

@@ -408,7 +408,7 @@ static void StartSignalThread()
408408
// Command line arguments
409409
struct cmdlineArgs_t {
410410
cmdlineArgs_t()
411-
: homePath(FS::DefaultHomePath()), libPath(FS::DefaultBasePath()), reset_config(false), use_curses(Application::GetTraits().useCurses) {}
411+
: homePath(""), libPath(FS::DefaultBasePath()), reset_config(false), use_curses(Application::GetTraits().useCurses) {}
412412

413413
std::string homePath;
414414
std::string libPath;
@@ -467,7 +467,7 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
467467
}
468468

469469
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-help")) {
470-
std::string helpUrl = Application::GetTraits().supportsUri ? " | -connect " URI_SCHEME "ADDRESS[:PORT]" : "";
470+
std::string helpUrl = Application::GetTraits().supportsUri ? Str::Format(" [%s://ADDRESS[:PORT]]", Gameinfo::getInstance().uriprotocol()) : "";
471471
printf("Usage: %s [-OPTION]... [+COMMAND...%s]\n", argv[0], helpUrl.c_str());
472472
printf("Possible options are:\n"
473473
" -homepath <path> set the path used for user-specific configuration files and downloaded dpk files\n"
@@ -482,7 +482,7 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
482482
);
483483
OSExit(0);
484484
} else if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-version")) {
485-
printf(PRODUCT_NAME " " PRODUCT_VERSION "\n");
485+
printf(ENGINE_NAME_VERSION "\n");
486486
OSExit(0);
487487
} else if (!strcmp(argv[i], "-set")) {
488488
if (i >= argc - 2) {
@@ -549,16 +549,21 @@ static void Init(int argc, char** argv)
549549
#endif
550550

551551
// Print a banner and a copy of the command-line arguments
552-
Log::Notice(Q3_VERSION " " PLATFORM_STRING " " ARCH_STRING " " __DATE__);
553552
std::string argsString = "cmdline:";
554553
for (int i = 1; i < argc; i++) {
555554
argsString.push_back(' ');
556555
argsString.append(argv[i]);
557556
}
558-
Log::Notice(argsString);
559557

560558
Sys::SetupCrashHandler(); // If Breakpad is enabled, this handler will soon be replaced.
561559
Sys::ParseCmdline(argc, argv, cmdlineArgs);
560+
Gameinfo::getInstance().parse(FS::Path::Build(cmdlineArgs.libPath, "gameinfo.conf"));
561+
Log::Notice("%s", GAME_NAME_VERSION);
562+
Log::Notice("%s %s %s %s", ENGINE_NAME_VERSION, PLATFORM_STRING, ARCH_STRING, ENGINE_DATE);
563+
Log::Notice(argsString);
564+
if (cmdlineArgs.homePath.empty()) {
565+
cmdlineArgs.homePath = FS::DefaultHomePath();
566+
}
562567

563568
// Platform-specific initialization
564569
#ifdef _WIN32

src/engine/qcommon/common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ void Com_Init()
651651
Cmd_AddCommand( "writebindings", Com_WriteBindings_f );
652652
#endif
653653

654-
s = va( "%s %s %s %s", Q3_VERSION, PLATFORM_STRING, ARCH_STRING, __DATE__ );
654+
s = va( "%s %s %s %s %s", GAME_NAME_VERSION, ENGINE_NAME_VERSION, PLATFORM_STRING, ARCH_STRING, ENGINE_DATE );
655655
com_version = Cvar_Get( "version", s, CVAR_ROM | CVAR_SERVERINFO );
656656

657657
Cmd_AddCommand( "in_restart", Com_In_Restart_f );
@@ -695,7 +695,7 @@ void Com_WriteConfigToFile( const char *filename, void (*writeConfig)( fileHandl
695695
return;
696696
}
697697

698-
FS_Printf( f, "// generated by " PRODUCT_NAME ", do not modify\n" );
698+
FS_Printf( f, "// generated by %s, do not modify\n", Gameinfo::getInstance().name().c_str() );
699699
writeConfig( f );
700700
FS_FCloseFile( f );
701701
}

src/engine/qcommon/files.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ constexpr FS::offset_t MAX_FILE_LENGTH = 1000 * 1000 * 1000;
3636
const char TEMP_SUFFIX[] = ".tmp";
3737

3838
// Cvars to select the base and extra packages to use
39-
static Cvar::Cvar<std::string> fs_basepak("fs_basepak", "base pak to load", 0, DEFAULT_BASE_PAK);
39+
static Cvar::Cvar<std::string> fs_basepak( "fs_basepak", "base pak to load", 0, "" );
4040
static Cvar::Cvar<std::string> fs_extrapaks("fs_extrapaks", "space-seperated list of paks to load in addition to the base pak", 0, "");
4141

4242
struct handleData_t {
@@ -673,14 +673,16 @@ void FS_LoadBasePak()
673673
return; // success
674674
}
675675

676-
if (fs_basepak.Get() != DEFAULT_BASE_PAK) {
677-
Log::Notice("Could not load base pak '%s', falling back to default: '%s'", fs_basepak.Get().c_str(), DEFAULT_BASE_PAK);
678-
if (FS_LoadPak(DEFAULT_BASE_PAK)) {
676+
if (fs_basepak.Get().c_str() != Gameinfo::getInstance().basepak().c_str()) {
677+
Log::Notice("Could not load base pak '%s', falling back to default: '%s'",
678+
fs_basepak.Get().c_str(), Gameinfo::getInstance().basepak().c_str());
679+
680+
if (FS_LoadPak(Gameinfo::getInstance().basepak().c_str())) {
679681
return; // success
680682
}
681683
}
682684

683-
Sys::Error("Could not load default base pak '%s'", DEFAULT_BASE_PAK);
685+
Sys::Error("Could not load default base pak '%s'", Gameinfo::getInstance().basepak().c_str());
684686
}
685687

686688
void FS_LoadAllMapMetadata()

0 commit comments

Comments
 (0)