- Added CVARINFO lump support. This is a lump for defining mod-specific cvars and takes entries
of the form:
<scope> [noarchive] <type> <name> [= <defaultvalue>];
Where <scope> is one of:
* server: This cvar is shared by all players, and in network games, only select players can
change it.
* user: Each player has their own copy of this cvar, which they can change independently.
To prevent the cvar from being written to the config file, add noarchive to its definition.
<Type> is one of:
* int: An integral value. Defaults to 0.
* float: A value that can include a fraction. Defaults to 0.0.
* color: A color value. Default to black ("00 00 00").
* bool: A boolean value that can hold either true or false. Defaults to false.
* string: A string value. It's not too useful for mods but is included for completeness. Defaults to "".
<Name> is the cvar's name and must begin with a letter and may only include alphanumeric
characters and the underscore character.
If you wish a non-standard default add an = character after the cvar's name followed by the
default value you want to use. Example:
server int mymod_coolness = 10;
- Fixed: FStringCVar::SetGenericRepDefault() did not make a copy of the input string.
SVN r4280 (trunk)
This commit is contained in:
parent
2767f31a92
commit
787b84ef91
8 changed files with 214 additions and 40 deletions
|
|
@ -86,6 +86,7 @@ FGameConfigFile::FGameConfigFile ()
|
|||
|
||||
OkayToWrite = false; // Do not allow saving of the config before DoGameSetup()
|
||||
bMigrating = false;
|
||||
bModSetup = false;
|
||||
pathname = GetConfigPath (true);
|
||||
ChangePathName (pathname);
|
||||
LoadConfigFile (MigrateStub, NULL);
|
||||
|
|
@ -376,8 +377,8 @@ void FGameConfigFile::DoGameSetup (const char *gamename)
|
|||
SetRavenDefaults (gameinfo.gametype == GAME_Hexen);
|
||||
}
|
||||
|
||||
// The NetServerInfo section will be read when it's determined that
|
||||
// a netgame is being played.
|
||||
// The NetServerInfo section will be read and override anything loaded
|
||||
// here when it's determined that a netgame is being played.
|
||||
strncpy (subsection, "LocalServerInfo", sublen);
|
||||
if (SetSection (section))
|
||||
{
|
||||
|
|
@ -445,6 +446,24 @@ void FGameConfigFile::DoGameSetup (const char *gamename)
|
|||
OkayToWrite = true;
|
||||
}
|
||||
|
||||
// Like DoGameSetup(), but for mod-specific cvars.
|
||||
// Called after CVARINFO has been parsed.
|
||||
void FGameConfigFile::DoModSetup(const char *gamename)
|
||||
{
|
||||
mysnprintf(section, countof(section), "%s.Player.Mod", gamename);
|
||||
if (SetSection(section))
|
||||
{
|
||||
ReadCVars(CVAR_MODARCHIVE|CVAR_USERINFO|CVAR_NOSEND);
|
||||
}
|
||||
mysnprintf(section, countof(section), "%s.LocalServerInfo.Mod", gamename);
|
||||
if (SetSection (section))
|
||||
{
|
||||
ReadCVars (CVAR_MODARCHIVE|CVAR_SERVERINFO|CVAR_NOSEND);
|
||||
}
|
||||
// Signal that these sections should be rewritten when saving the config.
|
||||
bModSetup = true;
|
||||
}
|
||||
|
||||
void FGameConfigFile::ReadNetVars ()
|
||||
{
|
||||
strncpy (subsection, "NetServerInfo", sublen);
|
||||
|
|
@ -452,21 +471,35 @@ void FGameConfigFile::ReadNetVars ()
|
|||
{
|
||||
ReadCVars (0);
|
||||
}
|
||||
if (bModSetup)
|
||||
{
|
||||
mysnprintf(subsection, sublen, "NetServerInfo.Mod");
|
||||
if (SetSection(section))
|
||||
{
|
||||
ReadCVars(CVAR_MODARCHIVE|CVAR_SERVERINFO|CVAR_NOSEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read cvars from a cvar section of the ini. Flags are the flags to give
|
||||
// to newly-created cvars that were not already defined.
|
||||
void FGameConfigFile::ReadCVars (DWORD flags)
|
||||
{
|
||||
const char *key, *value;
|
||||
FBaseCVar *cvar;
|
||||
UCVarValue val;
|
||||
|
||||
if (!(flags & CVAR_MODARCHIVE))
|
||||
{
|
||||
flags |= CVAR_ARCHIVE|CVAR_UNSETTABLE;
|
||||
}
|
||||
flags |= CVAR_AUTO;
|
||||
while (NextInSection (key, value))
|
||||
{
|
||||
cvar = FindCVar (key, NULL);
|
||||
if (cvar == NULL)
|
||||
{
|
||||
cvar = new FStringCVar (key, NULL,
|
||||
CVAR_AUTO|CVAR_UNSETTABLE|CVAR_ARCHIVE|flags);
|
||||
cvar = new FStringCVar (key, NULL, flags);
|
||||
}
|
||||
val.String = const_cast<char *>(value);
|
||||
cvar->SetGenericRep (val, CVAR_String);
|
||||
|
|
@ -485,18 +518,35 @@ void FGameConfigFile::ArchiveGameData (const char *gamename)
|
|||
ClearCurrentSection ();
|
||||
C_ArchiveCVars (this, CVAR_ARCHIVE|CVAR_USERINFO);
|
||||
|
||||
if (bModSetup)
|
||||
{
|
||||
strncpy (subsection + 6, ".Mod", sublen - 6);
|
||||
SetSection (section, true);
|
||||
ClearCurrentSection ();
|
||||
C_ArchiveCVars (this, CVAR_MODARCHIVE|CVAR_AUTO|CVAR_USERINFO);
|
||||
}
|
||||
|
||||
strncpy (subsection, "ConsoleVariables", sublen);
|
||||
SetSection (section, true);
|
||||
ClearCurrentSection ();
|
||||
C_ArchiveCVars (this, CVAR_ARCHIVE);
|
||||
|
||||
strncpy (subsection, netgame ? "NetServerInfo" : "LocalServerInfo", sublen);
|
||||
// Do not overwrite the serverinfo section if playing a netgame, and
|
||||
// this machine was not the initial host.
|
||||
if (!netgame || consoleplayer == 0)
|
||||
{ // Do not overwrite this section if playing a netgame, and
|
||||
// this machine was not the initial host.
|
||||
{
|
||||
strncpy (subsection, netgame ? "NetServerInfo" : "LocalServerInfo", sublen);
|
||||
SetSection (section, true);
|
||||
ClearCurrentSection ();
|
||||
C_ArchiveCVars (this, CVAR_ARCHIVE|CVAR_SERVERINFO);
|
||||
|
||||
if (bModSetup)
|
||||
{
|
||||
strncpy (subsection, netgame ? "NetServerInfo.Mod" : "LocalServerInfo.Mod", sublen);
|
||||
SetSection (section, true);
|
||||
ClearCurrentSection ();
|
||||
C_ArchiveCVars (this, CVAR_MODARCHIVE|CVAR_AUTO|CVAR_SERVERINFO);
|
||||
}
|
||||
}
|
||||
|
||||
strncpy (subsection, "UnknownConsoleVariables", sublen);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue