mirror of
https://github.com/HikikoMarmy/Champions-Reborn-Server.git
synced 2026-04-11 03:19:49 -03:00
Server config
This commit is contained in:
@@ -185,9 +185,10 @@
|
|||||||
</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="configuration.h" />
|
||||||
<ClInclude Include="Crypto\NorrathCrypt.h" />
|
<ClInclude Include="Crypto\NorrathCrypt.h" />
|
||||||
<ClInclude Include="Discovery Server\DiscoveryServer.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\RealmUser.h" />
|
||||||
<ClInclude Include="Game\RealmUserManager.h" />
|
<ClInclude Include="Game\RealmUserManager.h" />
|
||||||
<ClInclude Include="Game\GameSession.h" />
|
<ClInclude Include="Game\GameSession.h" />
|
||||||
@@ -206,6 +207,7 @@
|
|||||||
<ClInclude Include="Lobby Server\Event\RequestCreatePublicGame.h" />
|
<ClInclude Include="Lobby Server\Event\RequestCreatePublicGame.h" />
|
||||||
<ClInclude Include="Lobby Server\Event\RequestDoClientDiscovery.h" />
|
<ClInclude Include="Lobby Server\Event\RequestDoClientDiscovery.h" />
|
||||||
<ClInclude Include="Lobby Server\Event\RequestGetEncryptionKey.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\RequestGetRealmStats.h" />
|
||||||
<ClInclude Include="Lobby Server\Event\RequestGetRules.h" />
|
<ClInclude Include="Lobby Server\Event\RequestGetRules.h" />
|
||||||
<ClInclude Include="Lobby Server\Event\RequestLogin.h" />
|
<ClInclude Include="Lobby Server\Event\RequestLogin.h" />
|
||||||
@@ -229,6 +231,7 @@
|
|||||||
<ClInclude Include="targetver.h" />
|
<ClInclude Include="targetver.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="configuration.cpp" />
|
||||||
<ClCompile Include="Crypto\NorrathCrypt.cpp" />
|
<ClCompile Include="Crypto\NorrathCrypt.cpp" />
|
||||||
<ClCompile Include="Discovery Server\DiscoveryServer.cpp" />
|
<ClCompile Include="Discovery Server\DiscoveryServer.cpp" />
|
||||||
<ClCompile Include="Discovery Server\DiscoverySession.cpp" />
|
<ClCompile Include="Discovery Server\DiscoverySession.cpp" />
|
||||||
@@ -248,6 +251,7 @@
|
|||||||
<ClCompile Include="Lobby Server\Event\RequestCreatePublicGame.cpp" />
|
<ClCompile Include="Lobby Server\Event\RequestCreatePublicGame.cpp" />
|
||||||
<ClCompile Include="Lobby Server\Event\RequestDoClientDiscovery.cpp" />
|
<ClCompile Include="Lobby Server\Event\RequestDoClientDiscovery.cpp" />
|
||||||
<ClCompile Include="Lobby Server\Event\RequestGetEncryptionKey.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\RequestGetRealmStats.cpp" />
|
||||||
<ClCompile Include="Lobby Server\Event\RequestGetRules.cpp" />
|
<ClCompile Include="Lobby Server\Event\RequestGetRules.cpp" />
|
||||||
<ClCompile Include="Lobby Server\Event\RequestLogin.cpp" />
|
<ClCompile Include="Lobby Server\Event\RequestLogin.cpp" />
|
||||||
|
|||||||
@@ -2,24 +2,55 @@
|
|||||||
#include "global_define.h"
|
#include "global_define.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
|
||||||
ServerConfig::ServerConfig()
|
bool Config::Load( std::string filename )
|
||||||
{
|
{
|
||||||
service_ip.clear();
|
service_ip = "0.0.0.0";
|
||||||
gateway_port = 0;
|
|
||||||
session_port = 0;
|
|
||||||
broker_port = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerConfig::~ServerConfig()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ServerConfig::Load( std::string filename )
|
|
||||||
{
|
|
||||||
service_ip = "192.168.1.248";
|
|
||||||
gateway_port = 40801;
|
gateway_port = 40801;
|
||||||
session_port = 40802;
|
lobby_port = 40802;
|
||||||
broker_port = 3000; // The game uses 3000 as the default broker port, but also for local net play.
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3,22 +3,13 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ServerConfig
|
class Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static ServerConfig &Get()
|
static bool Load( std::string filename );
|
||||||
{
|
|
||||||
static ServerConfig instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerConfig();
|
static inline std::string service_ip;
|
||||||
~ServerConfig();
|
static inline uint16_t gateway_port;
|
||||||
|
static inline uint16_t lobby_port;
|
||||||
bool Load( std::string filename );
|
static inline uint16_t discovery_port;
|
||||||
|
|
||||||
std::string service_ip;
|
|
||||||
uint16_t gateway_port;
|
|
||||||
uint16_t session_port;
|
|
||||||
uint16_t broker_port;
|
|
||||||
};
|
};
|
||||||
29
main.cpp
29
main.cpp
@@ -12,29 +12,46 @@ static void ShowStartup()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
static bool NetworkStartup()
|
||||||
{
|
{
|
||||||
ShowStartup();
|
|
||||||
|
|
||||||
WORD wVersionRequest = MAKEWORD(2, 2);
|
WORD wVersionRequest = MAKEWORD(2, 2);
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
if (WSAStartup(wVersionRequest, &wsaData) != 0)
|
if (WSAStartup(wVersionRequest, &wsaData) != 0)
|
||||||
{
|
{
|
||||||
Log::Error("WSAStartup() failed");
|
Log::Error("WSAStartup() failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
ShowStartup();
|
||||||
|
|
||||||
|
if (false == NetworkStartup())
|
||||||
|
{
|
||||||
|
Log::Error("Could not initialize network.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::Info( "Server Start..." );
|
Log::Info( "Server Start..." );
|
||||||
|
|
||||||
|
if( !Config::Load( "config.ini" ) )
|
||||||
|
{
|
||||||
|
Log::Error( "Failed to load configuration file." );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
auto &gateway_server = GatewayServer::Get();
|
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();
|
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();
|
auto &discovery_server = DiscoveryServer::Get();
|
||||||
discovery_server.Start( "192.168.1.248", 40820 );
|
discovery_server.Start(Config::service_ip, Config::discovery_port);
|
||||||
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user