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-07-02 14:54:01 +00:00
|
|
|
FPredefinedMapList: TObjectList<TGameMap>;
|
2014-06-30 21:41:54 +00:00
|
|
|
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;
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
procedure LoadPredefinedMapList(AList: TList<TGameMap>); virtual; abstract;
|
2014-06-30 21:41:54 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-07-02 15:22:41 +00:00
|
|
|
function GetExecutable: string; override;
|
|
|
|
function GetParameters: string; override;
|
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
{ 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-07-02 14:54:01 +00:00
|
|
|
function GetPredefinedMapList: TEnumerable<TGameMap>;
|
|
|
|
function GetMapList: TEnumerable<TGameMap>;
|
|
|
|
|
|
|
|
function GetMapCount: Integer;
|
|
|
|
function GetMap(Index: Integer): TGameMap;
|
|
|
|
|
|
|
|
procedure AddMap(AMap: TGameMap);
|
|
|
|
procedure InsertMap(Index: Integer; AMap: TGameMap);
|
|
|
|
procedure DeleteMap(AIndex: Integer);
|
|
|
|
procedure RemoveMap(AMap: TGameMap);
|
|
|
|
procedure MoveMap(ASourceIndex, ATargetIndex: Integer);
|
|
|
|
|
|
|
|
property PredefinedMapList: TEnumerable<TGameMap> read GetPredefinedMapList;
|
|
|
|
property MapList: TEnumerable<TGameMap> read GetMapList;
|
|
|
|
property MapCount: Integer read GetMapCount;
|
|
|
|
property Map[Index: Integer]: TGameMap read GetMap;
|
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,
|
2014-07-02 14:54:01 +00:00
|
|
|
System.SysUtils,
|
|
|
|
|
2014-07-02 15:22:41 +00:00
|
|
|
Winapi.Windows,
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
UDKIniFile;
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-02 15:22:41 +00:00
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
{ TChivalryGame }
|
|
|
|
constructor TChivalryGame.Create(const ALocation: string);
|
|
|
|
begin
|
|
|
|
inherited Create(ALocation);
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
FPredefinedMapList := TObjectList<TGameMap>.Create(True);
|
2014-06-30 21:41:54 +00:00
|
|
|
FMapList := TObjectList<TGameMap>.Create(True);
|
2014-06-30 14:37:42 +00:00
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
LoadPredefinedMapList(FPredefinedMapList);
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TChivalryGame.Destroy;
|
|
|
|
begin
|
|
|
|
FreeAndNil(FMapList);
|
2014-07-02 14:54:01 +00:00
|
|
|
FreeAndNil(FPredefinedMapList);
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
|
2014-07-02 15:22:41 +00:00
|
|
|
function TChivalryGame.GetExecutable: string;
|
|
|
|
var
|
|
|
|
isWow64: BOOL;
|
|
|
|
bits: string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
{$IFDEF WIN64}
|
|
|
|
bits := 'Win64';
|
|
|
|
{$ELSE}
|
|
|
|
if IsWow64Process(GetCurrentProcess, isWow64) and isWow64 then
|
|
|
|
bits := 'Win64'
|
|
|
|
else
|
|
|
|
bits := 'Win32';
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
Result := Location + 'Binaries\' + bits + '\UDKLogging.exe';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TChivalryGame.GetParameters: string;
|
|
|
|
begin
|
|
|
|
// #ToDo1 -oMvR: 2-7-2014: check how changing the starting map influences the map list,
|
|
|
|
// that could make selecting the starting map possible.
|
|
|
|
// Otherwise, a starting map option would need to shuffle the
|
|
|
|
// map list a bit.
|
|
|
|
if MapCount = 0 then
|
|
|
|
raise Exception.Create('Please add at least one map to the map list');
|
|
|
|
|
|
|
|
Result := Map[0].Name + '?steamsockets -dedicated=true -seekfreeloadingserver';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
procedure TChivalryGame.DoLoad;
|
2014-06-30 14:37:42 +00:00
|
|
|
var
|
2014-07-02 14:54:01 +00:00
|
|
|
gameSettings: TUDKIniFile;
|
|
|
|
engineSettings: TUDKIniFile;
|
2014-06-30 21:41:54 +00:00
|
|
|
mapListValues: TStringList;
|
2014-07-02 14:54:01 +00:00
|
|
|
mapName: string;
|
|
|
|
mapListChanged: Boolean;
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
begin
|
2014-07-02 14:54:01 +00:00
|
|
|
gameSettings := TUDKIniFile.Create(Location + GameSettingsFileName);
|
2014-06-30 14:37:42 +00:00
|
|
|
try
|
2014-07-02 14:54:01 +00:00
|
|
|
SetServerPort(gameSettings.ReadInteger(GameURL, GameURLPort, GameURLPortDefault));
|
|
|
|
SetPeerPort(gameSettings.ReadInteger(GameURL, GameURLPeerPort, GameURLPeerPortDefault));
|
|
|
|
|
|
|
|
SetServerName(gameSettings.ReadString(GameReplicationInfo, GameReplicationInfoServerName, ''));
|
|
|
|
SetMessageOfTheDay(gameSettings.ReadString(GameReplicationInfo, GameReplicationInfoMessageOfTheDay, ''));
|
2014-06-30 14:37:42 +00:00
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
mapListChanged := (FMapList.Count > 0);
|
2014-07-02 15:22:41 +00:00
|
|
|
FMapList.Clear;
|
2014-06-30 21:41:54 +00:00
|
|
|
|
|
|
|
{ Maplist is special; it occurs multiple times and order matters }
|
|
|
|
mapListValues := TStringList.Create;
|
|
|
|
try
|
2014-07-02 14:54:01 +00:00
|
|
|
gameSettings.ReadDuplicateStrings(GameAOCGame, GameAOCGameMapList, mapListValues);
|
|
|
|
for mapName in mapListValues do
|
2014-06-30 21:41:54 +00:00
|
|
|
begin
|
2014-07-02 14:54:01 +00:00
|
|
|
FMapList.Add(CreateGameMap(mapName));
|
|
|
|
mapListChanged := True;
|
2014-06-30 21:41:54 +00:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(mapListValues);
|
|
|
|
end;
|
2014-07-02 14:54:01 +00:00
|
|
|
|
|
|
|
if mapListChanged then
|
|
|
|
PropertyChanged('MapList');
|
2014-06-30 14:37:42 +00:00
|
|
|
finally
|
|
|
|
FreeAndNil(gameSettings);
|
|
|
|
end;
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
engineSettings := TUDKIniFile.Create(Location + EngineSettingsFileName);
|
2014-06-30 14:37:42 +00:00
|
|
|
try
|
2014-07-02 14:54:01 +00:00
|
|
|
SetQueryPort(engineSettings.ReadInteger(EngineSteam, EngineSteamQueryPort, EngineSteamQueryPortDefault));
|
2014-06-30 14:37:42 +00:00
|
|
|
finally
|
|
|
|
FreeAndNil(engineSettings);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
procedure TChivalryGame.DoSave;
|
2014-07-02 14:54:01 +00:00
|
|
|
var
|
|
|
|
gameSettings: TUDKIniFile;
|
|
|
|
engineSettings: TUDKIniFile;
|
|
|
|
map: TGameMap;
|
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
2014-07-02 14:54:01 +00:00
|
|
|
gameSettings := TUDKIniFile.Create(Location + GameSettingsFileName);
|
|
|
|
try
|
|
|
|
gameSettings.WriteInteger(GameURL, GameURLPort, ServerPort);
|
|
|
|
gameSettings.WriteInteger(GameURL, GameURLPeerPort, PeerPort);
|
|
|
|
|
|
|
|
gameSettings.WriteString(GameReplicationInfo, GameReplicationInfoServerName, ServerName);
|
|
|
|
gameSettings.WriteString(GameReplicationInfo, GameReplicationInfoMessageOfTheDay, MessageOfTheDay);
|
|
|
|
|
|
|
|
{ Remove all Maplist references before rewriting the list }
|
|
|
|
gameSettings.DeleteDuplicateKeys(GameAOCGame, GameAOCGameMapList);
|
|
|
|
|
|
|
|
for map in MapList do
|
|
|
|
gameSettings.WriteDuplicateString(GameAOCGame, GameAOCGameMapList, map.Name);
|
|
|
|
|
|
|
|
gameSettings.UpdateFile;
|
|
|
|
finally
|
|
|
|
FreeAndNil(gameSettings);
|
|
|
|
end;
|
|
|
|
|
|
|
|
engineSettings := TUDKIniFile.Create(Location + EngineSettingsFileName);
|
|
|
|
try
|
|
|
|
engineSettings.WriteInteger(EngineSteam, EngineSteamQueryPort, QueryPort);
|
|
|
|
|
|
|
|
engineSettings.UpdateFile;
|
|
|
|
finally
|
|
|
|
FreeAndNil(engineSettings);
|
|
|
|
end;
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 21:41:54 +00:00
|
|
|
function TChivalryGame.CreateGameMap(const AMapName: string): TGameMap;
|
|
|
|
var
|
|
|
|
map: TGameMap;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
for map in PredefinedMapList do
|
2014-06-30 21:41:54 +00:00
|
|
|
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;
|
2014-07-02 14:54:01 +00:00
|
|
|
PropertyChanged('ServerPort');
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.SetPeerPort(const Value: Integer);
|
|
|
|
begin
|
|
|
|
if Value <> FPeerPort then
|
|
|
|
begin
|
|
|
|
FPeerPort := Value;
|
2014-07-02 14:54:01 +00:00
|
|
|
PropertyChanged('PeerPort');
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.SetQueryPort(const Value: Integer);
|
|
|
|
begin
|
|
|
|
if Value <> FQueryPort then
|
|
|
|
begin
|
|
|
|
FQueryPort := Value;
|
2014-07-02 14:54:01 +00:00
|
|
|
PropertyChanged('QueryPort');
|
2014-06-30 14:37:42 +00:00
|
|
|
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;
|
2014-07-02 14:54:01 +00:00
|
|
|
PropertyChanged('ServerName');
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.SetMessageOfTheDay(const Value: string);
|
|
|
|
begin
|
|
|
|
if Value <> FMessageOfTheDay then
|
|
|
|
begin
|
|
|
|
FMessageOfTheDay := Value;
|
2014-07-02 14:54:01 +00:00
|
|
|
PropertyChanged('MessageOfTheDay');
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
function TChivalryGame.GetPredefinedMapList: TEnumerable<TGameMap>;
|
|
|
|
begin
|
|
|
|
Result := FPredefinedMapList;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TChivalryGame.GetMapList: TEnumerable<TGameMap>;
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
|
|
|
Result := FMapList;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
function TChivalryGame.GetMapCount: Integer;
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
2014-07-02 14:54:01 +00:00
|
|
|
Result := FMapList.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TChivalryGame.GetMap(Index: Integer): TGameMap;
|
|
|
|
begin
|
|
|
|
Result := FMapList[Index];
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.AddMap(AMap: TGameMap);
|
|
|
|
begin
|
|
|
|
FMapList.Add(AMap);
|
|
|
|
PropertyChanged('MapList');
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.InsertMap(Index: Integer; AMap: TGameMap);
|
|
|
|
begin
|
|
|
|
FMapList.Insert(Index, AMap);
|
|
|
|
PropertyChanged('MapList');
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.DeleteMap(AIndex: Integer);
|
|
|
|
begin
|
|
|
|
FMapList.Delete(AIndex);
|
|
|
|
PropertyChanged('MapList');
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.RemoveMap(AMap: TGameMap);
|
|
|
|
begin
|
|
|
|
if FMapList.Remove(AMap) > -1 then
|
|
|
|
PropertyChanged('MapList');
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TChivalryGame.MoveMap(ASourceIndex, ATargetIndex: Integer);
|
|
|
|
begin
|
|
|
|
if ATargetIndex <> ASourceIndex then
|
|
|
|
begin
|
|
|
|
FMapList.Move(ASourceIndex, ATargetIndex);
|
|
|
|
PropertyChanged('MapList');
|
|
|
|
end;
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|