To change the server name, which is controlled by
hostname console variable (cvar):
1. Use
FindConVar to grab
hostname cvar.
PHP Code:
ConVar hHostName = FindConVar("hostname");
2. Use
ConVar.SetString to change the
hostname cvar.
PHP Code:
hHostName.SetString("New Server Name");
If you want to get the current hostname, then you can use
ConVar.GetString to store the current hostname in a buffer.
PHP Code:
char szBuffer[64];
hHostName.GetString(szBuffer, sizeof(szBuffer));
PrintToServer("The server's current hostname is: %s", szBuffer);
Side-note: even though ConVars are Handles, you do not need to close them because they are global variables that you access using
FindConVar.