Server config

This commit is contained in:
HikikoMarmy
2025-02-20 02:41:15 +00:00
parent 5d07483ed7
commit a678e3a7de
4 changed files with 85 additions and 42 deletions

View File

@@ -185,9 +185,10 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="configuration.h" />
<ClInclude Include="Crypto\NorrathCrypt.h" />
<ClInclude Include="Discovery Server\DiscoveryServer.h" />
<ClInclude Include="Discovery Server\DiscoverySession.h" />
<ClInclude Include="Game\RealmCharacterData.h" />
<ClInclude Include="Game\RealmUser.h" />
<ClInclude Include="Game\RealmUserManager.h" />
<ClInclude Include="Game\GameSession.h" />
@@ -206,6 +207,7 @@
<ClInclude Include="Lobby Server\Event\RequestCreatePublicGame.h" />
<ClInclude Include="Lobby Server\Event\RequestDoClientDiscovery.h" />
<ClInclude Include="Lobby Server\Event\RequestGetEncryptionKey.h" />
<ClInclude Include="Lobby Server\Event\RequestGetGame.h" />
<ClInclude Include="Lobby Server\Event\RequestGetRealmStats.h" />
<ClInclude Include="Lobby Server\Event\RequestGetRules.h" />
<ClInclude Include="Lobby Server\Event\RequestLogin.h" />
@@ -229,6 +231,7 @@
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="configuration.cpp" />
<ClCompile Include="Crypto\NorrathCrypt.cpp" />
<ClCompile Include="Discovery Server\DiscoveryServer.cpp" />
<ClCompile Include="Discovery Server\DiscoverySession.cpp" />
@@ -248,6 +251,7 @@
<ClCompile Include="Lobby Server\Event\RequestCreatePublicGame.cpp" />
<ClCompile Include="Lobby Server\Event\RequestDoClientDiscovery.cpp" />
<ClCompile Include="Lobby Server\Event\RequestGetEncryptionKey.cpp" />
<ClCompile Include="Lobby Server\Event\RequestGetGame.cpp" />
<ClCompile Include="Lobby Server\Event\RequestGetRealmStats.cpp" />
<ClCompile Include="Lobby Server\Event\RequestGetRules.cpp" />
<ClCompile Include="Lobby Server\Event\RequestLogin.cpp" />

View File

@@ -2,24 +2,55 @@
#include "global_define.h"
#include "configuration.h"
ServerConfig::ServerConfig()
bool Config::Load( std::string filename )
{
service_ip.clear();
gateway_port = 0;
session_port = 0;
broker_port = 0;
}
ServerConfig::~ServerConfig()
{
}
bool ServerConfig::Load( std::string filename )
{
service_ip = "192.168.1.248";
service_ip = "0.0.0.0";
gateway_port = 40801;
session_port = 40802;
broker_port = 3000; // The game uses 3000 as the default broker port, but also for local net play.
lobby_port = 40802;
discovery_port = 40101;
// Read configuration from ini file
std::ifstream file( filename );
if( !file.is_open() )
{
return false;
}
std::string line;
while( std::getline( file, line ) )
{
if( line.empty() || line[0] == '#' || line[0] == ';' )
{
continue;
}
size_t pos = line.find( '=' );
if( pos == std::string::npos )
{
continue;
}
std::string key = line.substr( 0, pos );
std::string value = line.substr( pos + 1 );
if( key == "service_ip" )
{
service_ip = value;
}
else if( key == "gateway_port" )
{
gateway_port = std::stoi( value );
}
else if( key == "lobby_port" )
{
lobby_port = std::stoi( value );
}
else if( key == "discovery_port" )
{
discovery_port = std::stoi( value );
}
}
return true;
}

View File

@@ -3,22 +3,13 @@
#include <fstream>
#include <string>
class ServerConfig
class Config
{
public:
static ServerConfig &Get()
{
static ServerConfig instance;
return instance;
}
static bool Load( std::string filename );
ServerConfig();
~ServerConfig();
bool Load( std::string filename );
std::string service_ip;
uint16_t gateway_port;
uint16_t session_port;
uint16_t broker_port;
static inline std::string service_ip;
static inline uint16_t gateway_port;
static inline uint16_t lobby_port;
static inline uint16_t discovery_port;
};

View File

@@ -12,29 +12,46 @@ static void ShowStartup()
);
}
static bool NetworkStartup()
{
WORD wVersionRequest = MAKEWORD(2, 2);
WSADATA wsaData;
if (WSAStartup(wVersionRequest, &wsaData) != 0)
{
Log::Error("WSAStartup() failed");
return false;
}
return true;
}
int main()
{
ShowStartup();
WORD wVersionRequest = MAKEWORD( 2, 2 );
WSADATA wsaData;
if( WSAStartup( wVersionRequest, &wsaData ) != 0 )
if (false == NetworkStartup())
{
Log::Error( "WSAStartup() failed" );
Log::Error("Could not initialize network.");
return 0;
}
Log::Info( "Server Start..." );
if( !Config::Load( "config.ini" ) )
{
Log::Error( "Failed to load configuration file." );
return 0;
}
Log::Info( "Server Start..." );
auto &gateway_server = GatewayServer::Get();
gateway_server.Start( "192.168.1.248", 40801 );
gateway_server.Start( Config::service_ip, Config::gateway_port );
auto &lobby_server = LobbyServer::Get();
lobby_server.Start( "192.168.1.248", 40810 );
lobby_server.Start(Config::service_ip, Config::lobby_port);
auto &discovery_server = DiscoveryServer::Get();
discovery_server.Start( "192.168.1.248", 40820 );
discovery_server.Start(Config::service_ip, Config::discovery_port);
while( true )
{