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

View File

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

View File

@ -2,4 +2,4 @@ class PlayerRankRelations extends Object
dependson(Types) dependson(Types)
config(ScoreboardExt); 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 config int ConfigVersion;
var private OnlineSubsystem Steamworks;
struct SClient struct SClient
{ {
var ScoreboardExtRepInfo RepInfo; var ScoreboardExtRepInfo RepInfo;
@ -16,7 +18,9 @@ struct SClient
}; };
var private array<SClient> RepClients; 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; var private SCESettings Settings;
function PostBeginPlay() function PostBeginPlay()
@ -24,9 +28,11 @@ function PostBeginPlay()
Super.PostBeginPlay(); Super.PostBeginPlay();
WorldInfo.Game.HUDType = class'ScoreboardExtHUD'; WorldInfo.Game.HUDType = class'ScoreboardExtHUD';
Steamworks = class'GameEngine'.static.GetOnlineSubsystem();
InitConfig(); InitConfig();
LoadPlayerRelations();
LoadRelations();
Settings.Style = class'ScoreboardStyle'.static.Settings(); Settings.Style = class'ScoreboardStyle'.static.Settings();
Settings.Admin = class'SystemAdminRank'.static.Settings(); Settings.Admin = class'SystemAdminRank'.static.Settings();
@ -51,8 +57,8 @@ function NotifyLogout(Controller C)
private function InitConfig() private function InitConfig()
{ {
local RankInfo ExampleRank; local RankInfo ExampleRank;
local PlayerRankRelation ExamplePlayer; local RankRelation ExamplePlayer;
local SteamGroupRankRelation ExampleSteamGroup; local RankRelation ExampleSteamGroup;
// Update from config version to current version if needed // Update from config version to current version if needed
switch (ConfigVersion) switch (ConfigVersion)
@ -77,7 +83,7 @@ private function InitConfig()
class'CustomRanks'.default.Rank.AddItem(ExampleRank); class'CustomRanks'.default.Rank.AddItem(ExampleRank);
// Example player // Example player
ExamplePlayer.PlayerID = "76561198001617867"; // GenZmeY SteamID64 ExamplePlayer.ObjectID = "76561198001617867"; // GenZmeY SteamID64
ExamplePlayer.RankID = ExampleRank.ID; ExamplePlayer.RankID = ExampleRank.ID;
class'PlayerRankRelations'.default.Relation.AddItem(ExamplePlayer); class'PlayerRankRelations'.default.Relation.AddItem(ExamplePlayer);
@ -91,19 +97,22 @@ private function InitConfig()
class'CustomRanks'.default.Rank.AddItem(ExampleRank); class'CustomRanks'.default.Rank.AddItem(ExampleRank);
// Example steam group // Example steam group
ExampleSteamGroup.SteamGroupID = "103582791465384046"; // MSK-GS SteamID64 ExampleSteamGroup.ObjectID = "103582791465384046"; // MSK-GS SteamID64
ExampleSteamGroup.RankID = ExampleRank.ID; ExampleSteamGroup.RankID = ExampleRank.ID;
class'SteamGroupRankRelations'.default.Relation.AddItem(ExampleSteamGroup); class'SteamGroupRankRelations'.default.Relation.AddItem(ExampleSteamGroup);
class'CustomRanks'.static.StaticSaveConfig(); class'CustomRanks'.static.StaticSaveConfig();
class'PlayerRankRelations'.static.StaticSaveConfig(); class'PlayerRankRelations'.static.StaticSaveConfig();
class'SteamGroupRankRelations'.static.StaticSaveConfig(); class'SteamGroupRankRelations'.static.StaticSaveConfig();
case 2147483647: case 2147483647:
`log("[ScoreboardExt] Config updated to version"@CurrentVersion); `log("[ScoreboardExt] Config updated to version"@CurrentVersion);
break; break;
case CurrentVersion: case CurrentVersion:
`log("[ScoreboardExt] Config is up-to-date"); `log("[ScoreboardExt] Config is up-to-date");
break; break;
default: default:
`log("[ScoreboardExt] Warn: The config version is higher than the current version (are you using an old mutator?)"); `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); `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 RankRelation Player, SteamGroup;
local OnlineSubsystem steamworks;
local UIDRankRelation UIDInfo; local UIDRankRelation UIDInfo;
steamworks = class'GameEngine'.static.GetOnlineSubsystem();
foreach class'PlayerRankRelations'.default.Relation(Player) foreach class'PlayerRankRelations'.default.Relation(Player)
{ {
UIDInfo.RankID = Player.RankID; 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) if (UIDRankRelationsPlayers.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRelations.AddItem(UIDInfo); 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) if (UIDRankRelationsPlayers.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRelations.AddItem(UIDInfo); 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 KFPlayerController KFPC;
local UIDRankRelation Relation;
local SClient RepClient; local SClient RepClient;
KFPC = KFPlayerController(C); KFPC = KFPlayerController(C);
if (KFPC == None) if (KFPC == None)
return; return;
RepClient.RepInfo = Spawn(class'ScoreboardExtRepInfo', KFPC);
RepClient.KFPC = 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); RepClients.AddItem(RepClient);
RepClient.RepInfo.PlayerRankRelations = UIDRelations; // хуйня
RepClient.RepInfo.CustomRanks = class'CustomRanks'.default.Rank; foreach UIDRankRelationsActive(Relation)
RepClient.RepInfo.Settings = Settings; 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 KFPlayerController KFPC;
local int Index; local int Index;
@ -173,6 +200,9 @@ function RemovePlayer(Controller C)
if (KFPC == None) if (KFPC == None)
return; return;
// UID = KFPC.PlayerReplicationInfo.UniqueId;
// Remove Rank Relation here
Index = RepClients.Find('KFPC', KFPC); Index = RepClients.Find('KFPC', KFPC);
if (Index == INDEX_NONE) if (Index == INDEX_NONE)
return; return;
@ -183,6 +213,41 @@ function RemovePlayer(Controller C)
RepClients.Remove(Index, 1); 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 DefaultProperties
{ {

View File

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

View File

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

View File

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