KF2-YetAnotherScoreboard/YAS/Classes/YAS_OwnerRepInfo.uc

246 lines
4.6 KiB
Ucode
Raw Normal View History

2022-09-07 16:13:13 +00:00
class YAS_OwnerRepInfo extends ReplicationInfo;
2022-09-03 17:26:40 +00:00
2022-09-07 12:57:47 +00:00
var public YAS YAS;
2022-09-03 17:26:40 +00:00
2022-09-07 12:57:47 +00:00
var public repnotify E_LogLevel LogLevel;
var public repnotify SystemRank RankPlayer, RankAdmin;
var public repnotify String DynamicServerName;
var public repnotify bool UsesStats, Custom, PasswordRequired;
2022-09-07 16:13:13 +00:00
var public YAS_RankRepInfo RankRepInfo;
2022-09-07 12:57:47 +00:00
var private KFPlayerController KFPC;
2022-09-03 17:26:40 +00:00
var private YAS_ScoreBoard SC;
2022-09-07 12:57:47 +00:00
var private OnlineSubsystemSteamworks OSS;
2022-09-07 16:13:13 +00:00
var private Array<UniqueNetID> PendingGroupIDs;
2022-09-07 12:57:47 +00:00
const CheckGroupTimer = 0.2f;
const MaxRetries = 3;
var private int Retries;
replication
{
if (bNetInitial)
LogLevel, RankPlayer, RankAdmin;
if (bNetDirty)
DynamicServerName, UsesStats, Custom, PasswordRequired;
}
2022-09-07 16:13:13 +00:00
public simulated function bool SafeDestroy()
{
`Log_Trace();
return (bPendingDelete || bDeleteMe || Destroy());
}
2022-09-07 12:57:47 +00:00
public simulated event ReplicatedEvent(name VarName)
{
`Log_Trace();
switch (VarName)
{
case 'LogLevel':
if (SC != None) SC.LogLevel = LogLevel;
break;
case 'RankPlayer':
if (SC != None) SC.RankPlayer = RankPlayer;
break;
case 'RankAdmin':
if (SC != None) SC.RankAdmin = RankAdmin;
break;
case 'DynamicServerName':
if (SC != None) SC.DynamicServerName = DynamicServerName;
break;
case 'UsesStats':
if (SC != None) SC.UsesStats = UsesStats;
break;
case 'Custom':
if (SC != None) SC.Custom = Custom;
break;
case 'PasswordRequired':
if (SC != None) SC.PasswordRequired = PasswordRequired;
break;
default:
super.ReplicatedEvent(VarName);
break;
}
}
2022-09-03 17:26:40 +00:00
public simulated event PreBeginPlay()
{
2022-09-07 12:57:47 +00:00
`Log_Trace();
2022-09-03 17:26:40 +00:00
if (bPendingDelete || bDeleteMe) return;
Super.PreBeginPlay();
if (Role < ROLE_Authority || WorldInfo.NetMode == NM_StandAlone)
{
GetScoreboard();
}
2022-09-07 12:57:47 +00:00
GetOnlineSubsystem();
2022-09-03 17:26:40 +00:00
}
public simulated event PostBeginPlay()
{
if (bPendingDelete || bDeleteMe) return;
Super.PostBeginPlay();
}
2022-09-07 12:57:47 +00:00
public reliable client function CheckGroupRanks(String JoinedGroupIDs)
{
local Array<String> StringGroupIDs;
local String StringGroupID;
local UniqueNetId GroupUID;
`Log_Trace();
StringGroupIDs = SplitString(JoinedGroupIDs);
if (GetOnlineSubsystem() == None)
{
`Log_Error("Can't get online subsystem");
return;
}
foreach StringGroupIDs(StringGroupID)
{
if (OSS.Int64ToUniqueNetId(StringGroupID, GroupUID))
{
PendingGroupIDs.AddItem(GroupUID);
}
}
Retries = 0;
CheckGroupsCycle();
}
private simulated function CheckGroupsCycle()
{
local UniqueNetId GroupUID;
`Log_Trace();
if (Retries++ >= MaxRetries) return;
// CheckPlayerGroup doesn't return real values right away,
// so we do a dry run and a few checks just in case
foreach PendingGroupIDs(GroupUID) OSS.CheckPlayerGroup(GroupUID);
foreach PendingGroupIDs(GroupUID)
{
if (OSS.CheckPlayerGroup(GroupUID))
{
PendingGroupIDs.Length = 0;
ServerApplyMembership(GroupUID);
return;
}
}
SetTimer(0.2f, false, nameof(CheckGroupsCycle));
}
private reliable server function ServerApplyMembership(UniqueNetId GroupUID)
{
2022-09-07 16:13:13 +00:00
local Rank Rank;
2022-09-07 12:57:47 +00:00
`Log_Trace();
2022-09-07 16:13:13 +00:00
Rank = YAS.RankByGroupID(GroupUID);
if (Rank.RankID > 0)
2022-09-07 12:57:47 +00:00
{
2022-09-07 16:13:13 +00:00
RankRepInfo.Rank = Rank;
2022-09-03 17:26:40 +00:00
}
else
{
2022-09-07 16:13:13 +00:00
`Log_Warn("Cant find related rank for groupUID");
RankRepInfo.Rank = class'YAS_Types'.static.FromSystemRank(RankPlayer);
2022-09-07 12:57:47 +00:00
}
}
public simulated function KFPlayerController GetKFPC()
{
`Log_Trace();
if (KFPC != None) return KFPC;
KFPC = KFPlayerController(Owner);
if (KFPC == None && ROLE < ROLE_Authority)
{
KFPC = KFPlayerController(GetALocalPlayerController());
}
return KFPC;
}
private simulated function OnlineSubsystemSteamworks GetOnlineSubsystem()
{
`Log_Trace();
if (OSS == None)
{
OSS = OnlineSubsystemSteamworks(class'GameEngine'.static.GetOnlineSubsystem());
}
return OSS;
}
private reliable client function GetScoreboard()
{
`Log_Trace();
if (SC == None)
{
if (GetKFPC() != None && KFPC.myHUD != None)
{
SC = YAS_HUD(KFPC.myHUD).Scoreboard;
}
}
if (SC == None)
{
SetTimer(0.2f, false, nameof(GetScoreboard));
return;
2022-09-03 17:26:40 +00:00
}
2022-09-07 12:57:47 +00:00
InitScoreboard();
2022-09-03 17:26:40 +00:00
}
2022-09-07 12:57:47 +00:00
private simulated function InitScoreboard()
2022-09-03 17:26:40 +00:00
{
2022-09-07 12:57:47 +00:00
`Log_Trace();
if (SC == None) return;
SC.LogLevel = LogLevel;
SC.RankPlayer = RankPlayer;
SC.RankAdmin = RankAdmin;
SC.DynamicServerName = DynamicServerName;
SC.UsesStats = UsesStats;
SC.Custom = Custom;
SC.PasswordRequired = PasswordRequired;
2022-09-03 17:26:40 +00:00
}
defaultproperties
{
Role = ROLE_Authority
RemoteRole = ROLE_SimulatedProxy
bAlwaysRelevant = false
bOnlyRelevantToOwner = true
bSkipActorPropertyReplication = false
2022-09-07 12:57:47 +00:00
Retries = 0
2022-09-03 17:26:40 +00:00
}