2014-06-30 14:37:42 +00:00
|
|
|
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;
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
FSupportedMapList: TObjectList<TGameMap>;
|
|
|
|
FMapList: TObjectList<TGameMap>;
|
2014-06-30 14:37:42 +00:00
|
|
|
protected
|
2014-06-30 21:41:54 +00:00
|
|
|
procedure DoLoad; override;
|
|
|
|
procedure DoSave; override;
|
|
|
|
|
|
|
|
procedure LoadSupportedMapList(AList: TList<TGameMap>); virtual; abstract;
|
|
|
|
|
|
|
|
function CreateGameMap(const AMapName: string): TGameMap; virtual;
|
2014-06-30 14:37:42 +00:00
|
|
|
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 }
|
2014-06-30 21:41:54 +00:00
|
|
|
function GetSupportedMapList: TList<TGameMap>;
|
|
|
|
function GetMapList: TList<TGameMap>;
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
2014-06-30 21:41:54 +00:00
|
|
|
System.Classes,
|
2014-06-30 14:37:42 +00:00
|
|
|
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';
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
GameAOCGame = 'AOC.AOCGame';
|
|
|
|
GameAOCGameMapList = 'Maplist';
|
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
EngineSettingsFileName = 'UDKGame\Config\PCServer-UDKEngine.ini';
|
|
|
|
EngineSteam = 'OnlineSubsystemSteamworks.OnlineSubsystemSteamworks';
|
|
|
|
EngineSteamQueryPort = 'QueryPort'; EngineSteamQueryPortDefault = 27015;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ TChivalryGame }
|
|
|
|
constructor TChivalryGame.Create(const ALocation: string);
|
|
|
|
begin
|
|
|
|
inherited Create(ALocation);
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
FSupportedMapList := TObjectList<TGameMap>.Create(True);
|
|
|
|
FMapList := TObjectList<TGameMap>.Create(True);
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
LoadSupportedMapList(FSupportedMapList);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TChivalryGame.Destroy;
|
|
|
|
begin
|
|
|
|
FreeAndNil(FMapList);
|
|
|
|
FreeAndNil(FSupportedMapList);
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
|
|
|
|
procedure TChivalryGame.DoLoad;
|
2014-06-30 14:37:42 +00:00
|
|
|
var
|
|
|
|
gameSettings: TMemIniFile;
|
|
|
|
engineSettings: TMemIniFile;
|
2014-06-30 21:41:54 +00:00
|
|
|
mapListValues: TStringList;
|
|
|
|
valueIndex: Integer;
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
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, '');
|
2014-06-30 21:41:54 +00:00
|
|
|
|
|
|
|
{ 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;
|
2014-06-30 14:37:42 +00:00
|
|
|
finally
|
|
|
|
FreeAndNil(gameSettings);
|
|
|
|
end;
|
|
|
|
|
|
|
|
engineSettings := TMemIniFile.Create(Location + EngineSettingsFileName);
|
|
|
|
try
|
|
|
|
FQueryPort := engineSettings.ReadInteger(EngineSteam, EngineSteamQueryPort, EngineSteamQueryPortDefault);
|
|
|
|
finally
|
|
|
|
FreeAndNil(engineSettings);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
procedure TChivalryGame.DoSave;
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
|
|
|
// #ToDo1 -oMvR: 30-6-2014: save to INI files
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
function TChivalryGame.GetMapList: TList<TGameMap>;
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
|
|
|
Result := FMapList;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
function TChivalryGame.GetSupportedMapList: TList<TGameMap>;
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
|
|
|
Result := FSupportedMapList;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|