WIP: replication

This commit is contained in:
GenZmeY 2021-06-12 21:44:20 +03:00
parent 2ab3198bbd
commit 9d18ad1f39
7 changed files with 215 additions and 151 deletions

View File

@ -1,8 +1,7 @@
# ScoreboardExt
**TODO:**
1. Customizable colors for player level (depending on difficulty)
2. Check fields char capacity (crop if text is large then cap)
3. Check steam group (?)
4. Rework replication
5. Localization
1. Check fields char capacity (crop if text is large then cap)
2. Check steam group (?)
3. Rework replication
4. Localization

View File

@ -19,7 +19,7 @@ var float PingBars,IdealPing,MaxPing;
// Ranks
var array<RankInfo> CustomRanks;
var array<UIDRankRelation> PlayerRankRelations;
var array<UIDRankRelation> RankRelations;
var SCESettings Settings;
@ -331,10 +331,10 @@ function DrawPlayerEntry( Canvas C, int Index, float YOffset, float Height, floa
KFPRI = KFPRIArray[Index];
HasRank = false;
PlayerInfoIndex = PlayerRankRelations.Find('UID', KFPRI.UniqueId);
PlayerInfoIndex = RankRelations.Find('UID', KFPRI.UniqueId);
if (PlayerInfoIndex != INDEX_NONE )
{
PlayerRankIndex = CustomRanks.Find('ID', PlayerRankRelations[PlayerInfoIndex].RankID);
PlayerRankIndex = CustomRanks.Find('ID', RankRelations[PlayerInfoIndex].RankID);
if (PlayerRankIndex != INDEX_NONE)
{
HasRank = true;

View File

@ -2,4 +2,4 @@ class PlayerRankRelations extends Object
dependson(Types)
config(ScoreboardExt);
var config array<PlayerRankRelation> Relation;
var config array<RankRelation> Relation;

View File

@ -9,6 +9,8 @@ const CurrentVersion = 1;
var config int ConfigVersion;
var private OnlineSubsystem Steamworks;
struct SClient
{
var ScoreboardExtRepInfo RepInfo;
@ -16,7 +18,9 @@ struct SClient
};
var private array<SClient> RepClients;
var private array<UIDRankRelation> UIDRelations;
var private array<UIDRankRelation> UIDRankRelationsPlayers;
var private array<UIDRankRelation> UIDRankRelationsSteamGroups;
var private array<UIDRankRelation> UIDRankRelationsActive;
var private SCESettings Settings;
function PostBeginPlay()
@ -24,9 +28,11 @@ function PostBeginPlay()
Super.PostBeginPlay();
WorldInfo.Game.HUDType = class'ScoreboardExtHUD';
Steamworks = class'GameEngine'.static.GetOnlineSubsystem();
InitConfig();
LoadPlayerRelations();
LoadRelations();
Settings.Style = class'ScoreboardStyle'.static.Settings();
Settings.Admin = class'SystemAdminRank'.static.Settings();
@ -51,8 +57,8 @@ function NotifyLogout(Controller C)
private function InitConfig()
{
local RankInfo ExampleRank;
local PlayerRankRelation ExamplePlayer;
local SteamGroupRankRelation ExampleSteamGroup;
local RankRelation ExamplePlayer;
local RankRelation ExampleSteamGroup;
// Update from config version to current version if needed
switch (ConfigVersion)
@ -77,7 +83,7 @@ private function InitConfig()
class'CustomRanks'.default.Rank.AddItem(ExampleRank);
// Example player
ExamplePlayer.PlayerID = "76561198001617867"; // GenZmeY SteamID64
ExamplePlayer.ObjectID = "76561198001617867"; // GenZmeY SteamID64
ExamplePlayer.RankID = ExampleRank.ID;
class'PlayerRankRelations'.default.Relation.AddItem(ExamplePlayer);
@ -91,19 +97,22 @@ private function InitConfig()
class'CustomRanks'.default.Rank.AddItem(ExampleRank);
// Example steam group
ExampleSteamGroup.SteamGroupID = "103582791465384046"; // MSK-GS SteamID64
ExampleSteamGroup.ObjectID = "103582791465384046"; // MSK-GS SteamID64
ExampleSteamGroup.RankID = ExampleRank.ID;
class'SteamGroupRankRelations'.default.Relation.AddItem(ExampleSteamGroup);
class'CustomRanks'.static.StaticSaveConfig();
class'PlayerRankRelations'.static.StaticSaveConfig();
class'SteamGroupRankRelations'.static.StaticSaveConfig();
case 2147483647:
`log("[ScoreboardExt] Config updated to version"@CurrentVersion);
break;
case CurrentVersion:
`log("[ScoreboardExt] Config is up-to-date");
break;
default:
`log("[ScoreboardExt] Warn: The config version is higher than the current version (are you using an old mutator?)");
`log("[ScoreboardExt] Warn: Config version is"@ConfigVersion@"but current version is"@CurrentVersion);
@ -118,53 +127,71 @@ private function InitConfig()
}
}
private function LoadPlayerRelations()
private function LoadRelations()
{
local PlayerRankRelation Player;
local OnlineSubsystem steamworks;
local RankRelation Player, SteamGroup;
local UIDRankRelation UIDInfo;
steamworks = class'GameEngine'.static.GetOnlineSubsystem();
foreach class'PlayerRankRelations'.default.Relation(Player)
{
UIDInfo.RankID = Player.RankID;
if (Len(Player.PlayerID) == UniqueIDLen && steamworks.StringToUniqueNetId(Player.PlayerID, UIDInfo.UID))
if (Len(Player.ObjectID) == UniqueIDLen && Steamworks.StringToUniqueNetId(Player.ObjectID, UIDInfo.UID))
{
if (UIDRelations.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRelations.AddItem(UIDInfo);
if (UIDRankRelationsPlayers.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRankRelationsPlayers.AddItem(UIDInfo);
}
else if (Len(Player.PlayerID) == SteamIDLen && steamworks.Int64ToUniqueNetId(Player.PlayerID, UIDInfo.UID))
else if (Len(Player.ObjectID) == SteamIDLen && Steamworks.Int64ToUniqueNetId(Player.ObjectID, UIDInfo.UID))
{
if (UIDRelations.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRelations.AddItem(UIDInfo);
if (UIDRankRelationsPlayers.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRankRelationsPlayers.AddItem(UIDInfo);
}
else `Log("[ScoreboardExt] WARN: Can't add player:"@Player.PlayerID);
else `Log("[ScoreboardExt] WARN: Can't add player:"@Player.ObjectID);
}
foreach class'SteamGroupRankRelations'.default.Relation(SteamGroup)
{
UIDInfo.RankID = SteamGroup.RankID;
if (Steamworks.Int64ToUniqueNetId(SteamGroup.ObjectID, UIDInfo.UID))
{
if (UIDRankRelationsSteamGroups.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRankRelationsSteamGroups.AddItem(UIDInfo);
}
else `Log("[ScoreboardExt] WARN: Can't add steamgroup:"@SteamGroup.ObjectID);
}
}
function AddPlayer(Controller C)
private function AddPlayer(Controller C)
{
local KFPlayerController KFPC;
local UIDRankRelation Relation;
local SClient RepClient;
KFPC = KFPlayerController(C);
if (KFPC == None)
return;
RepClient.RepInfo = Spawn(class'ScoreboardExtRepInfo', KFPC);
RepClient.KFPC = KFPC;
RepClient.RepInfo = Spawn(class'ScoreboardExtRepInfo', KFPC);
RepClient.RepInfo.Mut = Self;
RepClient.RepInfo.CustomRanks = class'CustomRanks'.default.Rank;
RepClient.RepInfo.SteamGroupRelations = UIDRankRelationsSteamGroups;
RepClient.RepInfo.Settings = Settings;
RepClient.RepInfo.RankRelation.UID = KFPC.PlayerReplicationInfo.UniqueId;
RepClient.RepInfo.RankRelation.RankID = UIDRankRelationsPlayers.Find('UID', RepClient.RepInfo.RankRelation.UID);
UIDRankRelationsActive.AddItem(RepClient.RepInfo.RankRelation);
RepClients.AddItem(RepClient);
RepClient.RepInfo.PlayerRankRelations = UIDRelations;
RepClient.RepInfo.CustomRanks = class'CustomRanks'.default.Rank;
RepClient.RepInfo.Settings = Settings;
// хуйня
foreach UIDRankRelationsActive(Relation)
foreach RepClients(RepClient)
RepClient.RepInfo.AddRankRelation(Relation);
RepClient.RepInfo.ClientStartReplication();
RepClient.RepInfo.StartFirstTimeReplication();
}
function RemovePlayer(Controller C)
private function RemovePlayer(Controller C)
{
local KFPlayerController KFPC;
local int Index;
@ -173,6 +200,9 @@ function RemovePlayer(Controller C)
if (KFPC == None)
return;
// UID = KFPC.PlayerReplicationInfo.UniqueId;
// Remove Rank Relation here
Index = RepClients.Find('KFPC', KFPC);
if (Index == INDEX_NONE)
return;
@ -183,6 +213,41 @@ function RemovePlayer(Controller C)
RepClients.Remove(Index, 1);
}
/*
private function RemoveRankRelationByUID(UniqueNetId UID)
{
local int Index;
Index = UIDRankRelationsActive.Find('UID', UID);
if (Index != INDEX_NONE)
{
Relation = UIDRankRelationsActive[Index];
for (i = 0; i < UIDRankRelationsActive.Length; ++i)
RepClients[Index].RepInfo.RemoveRankRelation(Relation);
}
}
*/
public function UpdatePlayerRank(UIDRankRelation Rel)
{
local SClient RepClient;
local int Index;
Index = UIDRankRelationsActive.Find('UID', Rel.UID);
if (Index != INDEX_NONE)
UIDRankRelationsActive[Index] = Rel;
foreach RepClients(RepClient)
RepClient.RepInfo.UpdateRankRelation(Rel);
}
public function AddPlayerRank(UIDRankRelation Rel)
{
local SClient RepClient;
foreach RepClients(RepClient)
RepClient.RepInfo.AddRankRelation(Rel);
}
DefaultProperties
{

View File

@ -1,144 +1,150 @@
class ScoreboardExtRepInfo extends ReplicationInfo;
var public array<UIDRankRelation> PlayerRankRelations;
var public array<RankInfo> CustomRanks;
var public SCESettings Settings;
var private bool InitFinished, RanksFinished, InfosFinished;
var private int InfosReplicateProgress, RanksReplicateProgress;
// Server vars
var public ScoreboardExtMut Mut;
// Client vars
var private KFScoreBoard SC;
var private OnlineSubsystemSteamworks SW;
public function ClientStartReplication()
// Fitst time replication
var public array<UIDRankRelation> SteamGroupRelations;
var public array<RankInfo> CustomRanks;
var public SCESettings Settings;
var public UIDRankRelation RankRelation; // Current player rank relation
var private int CustomRanksRepProgress, SteamGroupsRepProgress;
simulated event PostBeginPlay()
{
GetScoreboard();
super.PostBeginPlay();
ClientInit(Settings);
SetTimer(0.01f, true, nameof(ClientReplicateRanks));
SetTimer(0.01f, true, nameof(ClientReplicateInfos));
if (bDeleteMe) return;
if (Role < ROLE_Authority)
{
ClientInit();
}
}
public function ClientReplicateRanks()
private reliable client function ClientInit()
{
if (RanksReplicateProgress < CustomRanks.Length)
if (SC == None)
SC = ScoreboardExtHUD(GetALocalPlayerController().myHUD).Scoreboard;
if (SW == None)
SW = OnlineSubsystemSteamworks(class'GameEngine'.static.GetOnlineSubsystem());
if (SC == None || SW == None)
SetTimer(0.1f, false, nameof(ClientInit));
else
ClearTimer(nameof(ClientInit));
}
public function StartFirstTimeReplication()
{
SetTimer(0.01f, true, nameof(ReplicateCustomRanks));
SetTimer(0.01f, true, nameof(ReplicateSteamGroupRelations));
}
private reliable client function ClientSetSettings(SCESettings Set)
{
SC.Settings = Set;
}
private function ReplicateCustomRanks()
{
if (CustomRanksRepProgress < CustomRanks.Length)
{
ClientAddPlayerRank(CustomRanks[RanksReplicateProgress]);
++RanksReplicateProgress;
ClientAddCustomRank(CustomRanks[CustomRanksRepProgress]);
++CustomRanksRepProgress;
}
else
{
ClearTimer(nameof(ClientReplicateRanks));
RankReplicationFinished();
ClearTimer(nameof(ReplicateCustomRanks));
}
}
public function ClientReplicateInfos()
{
if (InfosReplicateProgress < PlayerRankRelations.Length)
{
ClientAddPlayerInfo(PlayerRankRelations[InfosReplicateProgress]);
++InfosReplicateProgress;
}
else
{
ClearTimer(nameof(ClientReplicateInfos));
InfosReplicationFinished();
}
}
private reliable client function GetScoreboard()
{
if (SC != None)
{
ClearTimer(nameof(GetScoreboard));
return;
}
SC = ScoreboardExtHUD(GetALocalPlayerController().myHUD).Scoreboard;
SetTimer(0.1f, false, nameof(GetScoreboard));
}
private reliable client function ClientAddPlayerRank(RankInfo Rank)
private reliable client function ClientAddCustomRank(RankInfo Rank)
{
CustomRanks.AddItem(Rank);
}
private reliable client function ClientAddPlayerInfo(UIDRankRelation PlayerInfo)
private function ReplicateSteamGroupRelations()
{
PlayerRankRelations.AddItem(PlayerInfo);
}
private reliable client function RankReplicationFinished()
{
RanksFinished = true;
ClientRanksApply();
}
private reliable client function InfosReplicationFinished()
{
InfosFinished = true;
ClientInfosApply();
}
private reliable client function ClientInit(SCESettings _Settings)
{
Settings = _Settings;
ClientSystemApply();
}
private reliable client function ClientSystemApply()
{
if (SC == None)
if (SteamGroupsRepProgress < SteamGroupRelations.Length)
{
SetTimer(0.1f, false, nameof(ClientSystemApply));
return;
ClientAddSteamGroupRelation(SteamGroupRelations[SteamGroupsRepProgress]);
++SteamGroupsRepProgress;
}
SC.Settings = Settings;
InitFinished = true;
Finished();
}
private reliable client function ClientRanksApply()
{
if (SC == None)
else
{
SetTimer(0.1f, false, nameof(ClientRanksApply));
return;
ClearTimer(nameof(ReplicateSteamGroupRelations));
if (RankRelation.RankID == INDEX_NONE)
FindMyRankInSteamGroups();
}
SC.CustomRanks = CustomRanks;
RanksFinished = true;
Finished();
}
private reliable client function ClientInfosApply()
private reliable client function ClientAddSteamGroupRelation(UIDRankRelation Rel)
{
if (SC == None)
{
SetTimer(0.1f, false, nameof(ClientInfosApply));
return;
}
SC.PlayerRankRelations = PlayerRankRelations;
RanksFinished = true;
Finished();
SteamGroupRelations.AddItem(Rel);
}
private reliable client function Finished()
private reliable client function FindMyRankInSteamGroups()
{
if (InitFinished && RanksFinished && InfosFinished)
Destroy();
local UIDRankRelation SteamGroupRel;
foreach SteamGroupRelations(SteamGroupRel)
if (SW.CheckPlayerGroup(SteamGroupRel.UID))
RankRelation.RankID = SteamGroupRel.RankID;
if (RankRelation.RankID != INDEX_NONE)
ServerApplyRank(RankRelation.RankID);
}
private reliable server function ServerApplyRank(int RankID)
{
RankRelation.RankID = RankID;
Mut.UpdatePlayerRank(RankRelation);
}
public function AddRankRelation(UIDRankRelation Rel)
{
ClientAddRankRelation(Rel);
}
private reliable client function ClientAddRankRelation(UIDRankRelation Rel)
{
SC.RankRelations.AddItem(Rel);
}
public function RemoveRankRelation(UIDRankRelation Rel)
{
ClientRemoveRankRelation(Rel);
}
private unreliable client function ClientRemoveRankRelation(UIDRankRelation Rel)
{
SC.RankRelations.RemoveItem(Rel);
}
public function UpdateRankRelation(UIDRankRelation Rel)
{
ClientUpdateRankRelation(Rel);
}
private reliable client function ClientUpdateRankRelation(UIDRankRelation Rel)
{
local int Index;
Index = SC.RankRelations.Find('UID', Rel.UID);
if (Index != INDEX_NONE)
SC.RankRelations[Index] = Rel;
}
defaultproperties
{
InfosReplicateProgress=0
RanksReplicateProgress=0
InitFinished=false
RanksFinished=false
InfosFinished=false
CustomRanksRepProgress = 0;
SteamGroupsRepProgress = 0;
}

View File

@ -2,7 +2,7 @@ class SteamGroupRankRelations extends Object
dependson(Types)
config(ScoreboardExt);
var config array<SteamGroupRankRelation> Relation;
var config array<RankRelation> Relation;
DefaultProperties
{

View File

@ -48,15 +48,9 @@ struct RankInfo
var Fields ApplyColorToFields;
};
struct SteamGroupRankRelation
struct RankRelation
{
var string SteamGroupID;
var int RankID;
};
struct PlayerRankRelation
{
var string PlayerID;
var string ObjectID;
var int RankID;
};