230 lines
5.4 KiB
ObjectPascal
230 lines
5.4 KiB
ObjectPascal
|
unit Game.Chivalry;
|
||
|
|
||
|
interface
|
||
|
uses
|
||
|
System.Generics.Collections,
|
||
|
|
||
|
Game.Base,
|
||
|
Game.Intf;
|
||
|
|
||
|
|
||
|
type
|
||
|
TChivalryGame = class(TCustomGame, IGameNetwork, IGameName, IGameMapList)
|
||
|
private
|
||
|
FServerPort: Integer;
|
||
|
FPeerPort: Integer;
|
||
|
FQueryPort: Integer;
|
||
|
|
||
|
FServerName: string;
|
||
|
FMessageOfTheDay: string;
|
||
|
|
||
|
FSupportedMapList: TList<IGameMap>;
|
||
|
FMapList: TList<string>;
|
||
|
protected
|
||
|
procedure LoadSupportedMapList(AList: TList<IGameMap>); virtual; abstract;
|
||
|
public
|
||
|
constructor Create(const ALocation: string); override;
|
||
|
destructor Destroy; override;
|
||
|
|
||
|
procedure Load; override;
|
||
|
procedure Save; override;
|
||
|
|
||
|
{ IGameNetwork }
|
||
|
function GetServerPort: Integer;
|
||
|
function GetPeerPort: Integer;
|
||
|
function GetQueryPort: Integer;
|
||
|
|
||
|
procedure SetServerPort(const Value: Integer);
|
||
|
procedure SetPeerPort(const Value: Integer);
|
||
|
procedure SetQueryPort(const Value: Integer);
|
||
|
|
||
|
property ServerPort: Integer read GetServerPort write SetServerPort;
|
||
|
property PeerPort: Integer read GetPeerPort write SetPeerPort;
|
||
|
property QueryPort: Integer read GetQueryPort write SetQueryPort;
|
||
|
|
||
|
{ IGameName }
|
||
|
function GetServerName: string;
|
||
|
function GetMessageOfTheDay: string;
|
||
|
|
||
|
procedure SetServerName(const Value: string);
|
||
|
procedure SetMessageOfTheDay(const Value: string);
|
||
|
|
||
|
property ServerName: string read GetServerName write SetServerName;
|
||
|
property MessageOfTheDay: string read GetMessageOfTheDay write SetMessageOfTheDay;
|
||
|
|
||
|
{ IGameMapList }
|
||
|
function GetMapList: System.Generics.Collections.TList<System.string>;
|
||
|
function GetSupportedMapList: System.Generics.Collections.TList<Game.Intf.IGameMap>;
|
||
|
end;
|
||
|
|
||
|
|
||
|
implementation
|
||
|
uses
|
||
|
System.IniFiles,
|
||
|
System.SysUtils;
|
||
|
|
||
|
|
||
|
const
|
||
|
GameSettingsFileName = 'UDKGame\Config\PCServer-UDKGame.ini';
|
||
|
GameURL = 'URL';
|
||
|
GameURLPort = 'Port'; GameURLPortDefault = 7777;
|
||
|
GameURLPeerPort = 'PeerPort'; GameURLPeerPortDefault = 7778;
|
||
|
|
||
|
GameReplicationInfo = 'Engine.GameReplicationInfo';
|
||
|
GameReplicationInfoServerName = 'ServerName';
|
||
|
GameReplicationInfoMessageOfTheDay = 'MessageOfTheDay';
|
||
|
|
||
|
|
||
|
EngineSettingsFileName = 'UDKGame\Config\PCServer-UDKEngine.ini';
|
||
|
EngineSteam = 'OnlineSubsystemSteamworks.OnlineSubsystemSteamworks';
|
||
|
EngineSteamQueryPort = 'QueryPort'; EngineSteamQueryPortDefault = 27015;
|
||
|
|
||
|
|
||
|
|
||
|
{ TChivalryGame }
|
||
|
constructor TChivalryGame.Create(const ALocation: string);
|
||
|
begin
|
||
|
inherited Create(ALocation);
|
||
|
|
||
|
FSupportedMapList := TList<IGameMap>.Create;
|
||
|
FMapList := TList<string>.Create;
|
||
|
|
||
|
LoadSupportedMapList(FSupportedMapList);
|
||
|
end;
|
||
|
|
||
|
|
||
|
destructor TChivalryGame.Destroy;
|
||
|
begin
|
||
|
FreeAndNil(FMapList);
|
||
|
FreeAndNil(FSupportedMapList);
|
||
|
|
||
|
inherited Destroy;
|
||
|
end;
|
||
|
|
||
|
procedure TChivalryGame.Load;
|
||
|
var
|
||
|
gameSettings: TMemIniFile;
|
||
|
engineSettings: TMemIniFile;
|
||
|
|
||
|
begin
|
||
|
gameSettings := TMemIniFile.Create(Location + GameSettingsFileName);
|
||
|
try
|
||
|
FServerPort := gameSettings.ReadInteger(GameURL, GameURLPort, GameURLPortDefault);
|
||
|
FPeerPort := gameSettings.ReadInteger(GameURL, GameURLPeerPort, GameURLPeerPortDefault);
|
||
|
|
||
|
FServerName := gameSettings.ReadString(GameReplicationInfo, GameReplicationInfoServerName, '');
|
||
|
FMessageOfTheDay := gameSettings.ReadString(GameReplicationInfo, GameReplicationInfoMessageOfTheDay, '');
|
||
|
finally
|
||
|
FreeAndNil(gameSettings);
|
||
|
end;
|
||
|
|
||
|
engineSettings := TMemIniFile.Create(Location + EngineSettingsFileName);
|
||
|
try
|
||
|
FQueryPort := engineSettings.ReadInteger(EngineSteam, EngineSteamQueryPort, EngineSteamQueryPortDefault);
|
||
|
finally
|
||
|
FreeAndNil(engineSettings);
|
||
|
end;
|
||
|
|
||
|
// #ToDo1 -oMvR: 30-6-2014: load map list
|
||
|
end;
|
||
|
|
||
|
|
||
|
procedure TChivalryGame.Save;
|
||
|
begin
|
||
|
// #ToDo1 -oMvR: 30-6-2014: save to INI files
|
||
|
end;
|
||
|
|
||
|
|
||
|
function TChivalryGame.GetServerPort: Integer;
|
||
|
begin
|
||
|
Result := FServerPort;
|
||
|
end;
|
||
|
|
||
|
|
||
|
function TChivalryGame.GetPeerPort: Integer;
|
||
|
begin
|
||
|
Result := FPeerPort;
|
||
|
end;
|
||
|
|
||
|
|
||
|
function TChivalryGame.GetQueryPort: Integer;
|
||
|
begin
|
||
|
Result := FQueryPort;
|
||
|
end;
|
||
|
|
||
|
|
||
|
procedure TChivalryGame.SetServerPort(const Value: Integer);
|
||
|
begin
|
||
|
if Value <> FServerPort then
|
||
|
begin
|
||
|
FServerPort := Value;
|
||
|
Notify('ServerPort');
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
|
||
|
procedure TChivalryGame.SetPeerPort(const Value: Integer);
|
||
|
begin
|
||
|
if Value <> FPeerPort then
|
||
|
begin
|
||
|
FPeerPort := Value;
|
||
|
Notify('PeerPort');
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
|
||
|
procedure TChivalryGame.SetQueryPort(const Value: Integer);
|
||
|
begin
|
||
|
if Value <> FQueryPort then
|
||
|
begin
|
||
|
FQueryPort := Value;
|
||
|
Notify('QueryPort');
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
|
||
|
function TChivalryGame.GetServerName: string;
|
||
|
begin
|
||
|
Result := FServerName;
|
||
|
end;
|
||
|
|
||
|
|
||
|
function TChivalryGame.GetMessageOfTheDay: string;
|
||
|
begin
|
||
|
Result := FMessageOfTheDay;
|
||
|
end;
|
||
|
|
||
|
|
||
|
procedure TChivalryGame.SetServerName(const Value: string);
|
||
|
begin
|
||
|
if Value <> FServerName then
|
||
|
begin
|
||
|
FServerName := Value;
|
||
|
Notify('ServerName');
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
|
||
|
procedure TChivalryGame.SetMessageOfTheDay(const Value: string);
|
||
|
begin
|
||
|
if Value <> FMessageOfTheDay then
|
||
|
begin
|
||
|
FMessageOfTheDay := Value;
|
||
|
Notify('MessageOfTheDay');
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
|
||
|
function TChivalryGame.GetMapList: System.Generics.Collections.TList<System.string>;
|
||
|
begin
|
||
|
Result := FMapList;
|
||
|
end;
|
||
|
|
||
|
|
||
|
function TChivalryGame.GetSupportedMapList: System.Generics.Collections.TList<Game.Intf.IGameMap>;
|
||
|
begin
|
||
|
Result := FSupportedMapList;
|
||
|
end;
|
||
|
|
||
|
end.
|