ChivalryServerLauncher/source/model/Game.Chivalry.pas

271 lines
6.4 KiB
ObjectPascal
Raw Normal View History

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: TObjectList<TGameMap>;
FMapList: TObjectList<TGameMap>;
protected
procedure DoLoad; override;
procedure DoSave; override;
procedure LoadSupportedMapList(AList: TList<TGameMap>); virtual; abstract;
function CreateGameMap(const AMapName: string): TGameMap; virtual;
public
constructor Create(const ALocation: string); override;
destructor Destroy; 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 GetSupportedMapList: TList<TGameMap>;
function GetMapList: TList<TGameMap>;
end;
implementation
uses
System.Classes,
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';
GameAOCGame = 'AOC.AOCGame';
GameAOCGameMapList = 'Maplist';
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 := TObjectList<TGameMap>.Create(True);
FMapList := TObjectList<TGameMap>.Create(True);
LoadSupportedMapList(FSupportedMapList);
end;
destructor TChivalryGame.Destroy;
begin
FreeAndNil(FMapList);
FreeAndNil(FSupportedMapList);
inherited Destroy;
end;
procedure TChivalryGame.DoLoad;
var
gameSettings: TMemIniFile;
engineSettings: TMemIniFile;
mapListValues: TStringList;
valueIndex: Integer;
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, '');
{ Maplist is special; it occurs multiple times and order matters }
mapListValues := TStringList.Create;
try
gameSettings.ReadSectionValues(GameAOCGame, mapListValues);
for valueIndex := 0 to Pred(mapListValues.Count) do
begin
if SameText(mapListValues.Names[valueIndex], GameAOCGameMapList) then
FMapList.Add(CreateGameMap(mapListValues.ValueFromIndex[valueIndex]));
end;
finally
FreeAndNil(mapListValues);
end;
finally
FreeAndNil(gameSettings);
end;
engineSettings := TMemIniFile.Create(Location + EngineSettingsFileName);
try
FQueryPort := engineSettings.ReadInteger(EngineSteam, EngineSteamQueryPort, EngineSteamQueryPortDefault);
finally
FreeAndNil(engineSettings);
end;
end;
procedure TChivalryGame.DoSave;
begin
// #ToDo1 -oMvR: 30-6-2014: save to INI files
end;
function TChivalryGame.CreateGameMap(const AMapName: string): TGameMap;
var
map: TGameMap;
begin
Result := nil;
for map in GetSupportedMapList do
if SameText(map.Name, AMapName) then
begin
Result := TGameMap.Create(map);
break;
end;
if not Assigned(Result) then
Result := TGameMap.Create(AMapName, '', '');
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: TList<TGameMap>;
begin
Result := FMapList;
end;
function TChivalryGame.GetSupportedMapList: TList<TGameMap>;
begin
Result := FSupportedMapList;
end;
end.