KF2-YetAnotherScoreboard/ScoreboardExt/Classes/ScoreboardExtMut.uc

281 lines
8.0 KiB
Ucode
Raw Normal View History

2021-05-31 01:46:53 +00:00
class ScoreboardExtMut extends KFMutator
2021-06-08 23:43:00 +00:00
dependson(Types)
2021-05-31 01:46:53 +00:00
config(ScoreboardExt);
2021-06-12 20:11:37 +00:00
`include(Build.uci)
`include(Logger.uci)
2021-05-31 01:46:53 +00:00
2021-06-13 00:02:17 +00:00
const CurrentVersion = 1;
2021-05-31 01:46:53 +00:00
var config int ConfigVersion;
2021-06-12 18:44:20 +00:00
var private OnlineSubsystem Steamworks;
2021-05-31 01:46:53 +00:00
struct SClient
{
var ScoreboardExtRepInfo RepInfo;
var KFPlayerController KFPC;
};
2021-06-13 02:53:33 +00:00
var private array < SClient> RepClients;
var private array < UIDRankRelation> UIDRankRelationsPlayers;
var private array < UIDRankRelation> UIDRankRelationsSteamGroups;
var private array < UIDRankRelation> UIDRankRelationsActive;
2021-06-09 00:58:31 +00:00
var private SCESettings Settings;
2020-01-10 13:14:11 +00:00
function PostBeginPlay()
2020-01-10 13:14:11 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
Super.PostBeginPlay();
2021-06-09 00:58:31 +00:00
2021-05-31 01:46:53 +00:00
WorldInfo.Game.HUDType = class'ScoreboardExtHUD';
2021-06-12 18:44:20 +00:00
Steamworks = class'GameEngine'.static.GetOnlineSubsystem();
2021-06-09 00:58:31 +00:00
2021-05-31 01:46:53 +00:00
InitConfig();
2021-06-12 18:44:20 +00:00
LoadRelations();
2021-06-09 00:58:31 +00:00
Settings.Style = class'ScoreboardStyle'.static.Settings();
Settings.Admin = class'SystemAdminRank'.static.Settings();
Settings.Player = class'SystemPlayerRank'.static.Settings();
2021-06-09 02:47:15 +00:00
Settings.State = class'DynamicStateColor'.static.Settings();
Settings.Ping = class'DynamicPingColor'.static.Settings();
Settings.Level = class'DynamicLevelColor'.static.Settings();
2021-05-31 01:46:53 +00:00
}
function NotifyLogin(Controller C)
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-08 21:48:03 +00:00
AddPlayer(C);
2021-05-31 01:46:53 +00:00
Super.NotifyLogin(C);
}
function NotifyLogout(Controller C)
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-08 21:48:03 +00:00
RemovePlayer(C);
2021-05-31 01:46:53 +00:00
Super.NotifyLogout(C);
}
2021-06-12 20:11:37 +00:00
private function bool IsUID(String ID)
{
`callstack();
return (Left(ID, 2) ~= "0x");
}
2021-05-31 01:46:53 +00:00
private function InitConfig()
{
2021-06-08 21:21:28 +00:00
local RankInfo ExampleRank;
2021-06-12 18:44:20 +00:00
local RankRelation ExamplePlayer;
local RankRelation ExampleSteamGroup;
2021-05-31 01:46:53 +00:00
2021-06-12 20:11:37 +00:00
`callstack();
2021-05-31 01:46:53 +00:00
// Update from config version to current version if needed
switch (ConfigVersion)
{
case 0: // which means there is no config right now
2021-05-31 04:04:26 +00:00
SaveConfig(); // because I want the main settings to be at the beginning of the config :)
2021-06-09 00:58:31 +00:00
class'SystemAdminRank'.static.WriteSettings(class'SystemAdminRank'.static.DefaultSettings());
class'SystemPlayerRank'.static.WriteSettings(class'SystemPlayerRank'.static.DefaultSettings());
class'ScoreboardStyle'.static.WriteSettings(class'ScoreboardStyle'.static.DefaultSettings());
2021-06-09 02:47:15 +00:00
class'DynamicStateColor'.static.WriteSettings(class'DynamicStateColor'.static.DefaultSettings());
class'DynamicPingColor'.static.WriteSettings(class'DynamicPingColor'.static.DefaultSettings());
class'DynamicLevelColor'.static.WriteSettings(class'DynamicLevelColor'.static.DefaultSettings());
2021-05-31 01:46:53 +00:00
2021-05-31 04:04:26 +00:00
// Example rank for player(s)
2021-06-08 21:21:28 +00:00
ExampleRank.ID = 0;
ExampleRank.Rank = "SCE Creator";
ExampleRank.TextColor.R = 130;
ExampleRank.TextColor.G = 250;
ExampleRank.TextColor.B = 235;
ExampleRank.OverrideAdminRank = true;
2021-06-08 21:48:03 +00:00
class'CustomRanks'.default.Rank.AddItem(ExampleRank);
2021-05-31 01:46:53 +00:00
// Example player
2021-06-12 18:44:20 +00:00
ExamplePlayer.ObjectID = "76561198001617867"; // GenZmeY SteamID64
2021-06-08 21:21:28 +00:00
ExamplePlayer.RankID = ExampleRank.ID;
2021-06-08 21:48:03 +00:00
class'PlayerRankRelations'.default.Relation.AddItem(ExamplePlayer);
2021-05-31 04:04:26 +00:00
// Example rank for steam group members
2021-06-08 21:21:28 +00:00
ExampleRank.ID = 1;
ExampleRank.Rank = "[MSK-GS]";
ExampleRank.TextColor.R = 130;
ExampleRank.TextColor.G = 250;
ExampleRank.TextColor.B = 130;
ExampleRank.OverrideAdminRank = false;
2021-06-08 21:48:03 +00:00
class'CustomRanks'.default.Rank.AddItem(ExampleRank);
2021-05-31 04:04:26 +00:00
// Example steam group
2021-06-12 18:44:20 +00:00
ExampleSteamGroup.ObjectID = "103582791465384046"; // MSK-GS SteamID64
2021-06-08 21:21:28 +00:00
ExampleSteamGroup.RankID = ExampleRank.ID;
2021-06-08 21:48:03 +00:00
class'SteamGroupRankRelations'.default.Relation.AddItem(ExampleSteamGroup);
2021-05-31 04:04:26 +00:00
2021-06-08 21:48:03 +00:00
class'CustomRanks'.static.StaticSaveConfig();
class'PlayerRankRelations'.static.StaticSaveConfig();
class'SteamGroupRankRelations'.static.StaticSaveConfig();
2021-06-12 18:44:20 +00:00
2021-05-31 01:46:53 +00:00
case 2147483647:
2021-06-13 00:02:17 +00:00
`info("Config updated to version"@CurrentVersion);
2021-05-31 01:46:53 +00:00
break;
2021-06-12 18:44:20 +00:00
2021-06-13 00:02:17 +00:00
case CurrentVersion:
2021-06-12 20:11:37 +00:00
`info("Config is up-to-date");
2021-05-31 01:46:53 +00:00
break;
2021-06-12 18:44:20 +00:00
2021-05-31 01:46:53 +00:00
default:
2021-06-12 20:11:37 +00:00
`warning("The config version is higher than the current version (are you using an old mutator?)");
2021-06-13 00:02:17 +00:00
`warning("Config version is"@ConfigVersion@"but current version is"@CurrentVersion);
`warning("The config version will be changed to "@CurrentVersion);
2021-05-31 01:46:53 +00:00
break;
}
2021-06-13 00:02:17 +00:00
if (ConfigVersion != CurrentVersion)
2021-06-08 20:31:56 +00:00
{
2021-06-13 00:02:17 +00:00
ConfigVersion = CurrentVersion;
2021-06-08 20:31:56 +00:00
SaveConfig();
}
2021-05-31 01:46:53 +00:00
}
2021-06-12 18:44:20 +00:00
private function LoadRelations()
2021-05-31 01:46:53 +00:00
{
2021-06-12 18:44:20 +00:00
local RankRelation Player, SteamGroup;
2021-06-08 21:21:28 +00:00
local UIDRankRelation UIDInfo;
2021-05-31 01:46:53 +00:00
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-08 21:48:03 +00:00
foreach class'PlayerRankRelations'.default.Relation(Player)
2021-05-31 01:46:53 +00:00
{
2021-06-08 21:21:28 +00:00
UIDInfo.RankID = Player.RankID;
2021-06-12 20:11:37 +00:00
if (IsUID(Player.ObjectID) && Steamworks.StringToUniqueNetId(Player.ObjectID, UIDInfo.UID))
2021-05-31 01:46:53 +00:00
{
2021-06-12 18:44:20 +00:00
if (UIDRankRelationsPlayers.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRankRelationsPlayers.AddItem(UIDInfo);
2021-05-31 01:46:53 +00:00
}
2021-06-12 20:11:37 +00:00
else if (Steamworks.Int64ToUniqueNetId(Player.ObjectID, UIDInfo.UID))
2021-05-31 01:46:53 +00:00
{
2021-06-12 18:44:20 +00:00
if (UIDRankRelationsPlayers.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRankRelationsPlayers.AddItem(UIDInfo);
2021-05-31 01:46:53 +00:00
}
2021-06-12 20:11:37 +00:00
else `warning("Can't add player:"@Player.ObjectID);
2021-06-12 18:44:20 +00:00
}
foreach class'SteamGroupRankRelations'.default.Relation(SteamGroup)
{
UIDInfo.RankID = SteamGroup.RankID;
2021-06-12 20:11:37 +00:00
if (IsUID(SteamGroup.ObjectID) && Steamworks.StringToUniqueNetId(SteamGroup.ObjectID, UIDInfo.UID))
{
if (UIDRankRelationsPlayers.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRankRelationsPlayers.AddItem(UIDInfo);
}
else if (Steamworks.Int64ToUniqueNetId(SteamGroup.ObjectID, UIDInfo.UID))
2021-06-12 18:44:20 +00:00
{
if (UIDRankRelationsSteamGroups.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRankRelationsSteamGroups.AddItem(UIDInfo);
}
2021-06-12 20:11:37 +00:00
else `warning("Can't add steamgroup:"@SteamGroup.ObjectID);
2021-05-31 01:46:53 +00:00
}
2020-01-10 13:14:11 +00:00
}
2021-06-12 18:44:20 +00:00
private function AddPlayer(Controller C)
{
2021-05-31 01:46:53 +00:00
local KFPlayerController KFPC;
2021-06-12 18:44:20 +00:00
local UIDRankRelation Relation;
2021-06-12 20:11:37 +00:00
local SClient RepClient, RepClientNew;
`callstack();
2021-05-31 04:04:26 +00:00
2021-05-31 01:46:53 +00:00
KFPC = KFPlayerController(C);
2021-05-31 04:04:26 +00:00
if (KFPC == None)
2021-05-31 01:46:53 +00:00
return;
2021-06-12 20:11:37 +00:00
RepClientNew.KFPC = KFPC;
RepClientNew.RepInfo = Spawn(class'ScoreboardExtRepInfo', KFPC);
2021-06-13 02:14:00 +00:00
2021-06-12 20:11:37 +00:00
RepClientNew.RepInfo.Mut = Self;
RepClientNew.RepInfo.CustomRanks = class'CustomRanks'.default.Rank;
RepClientNew.RepInfo.SteamGroupRelations = UIDRankRelationsSteamGroups;
RepClientNew.RepInfo.Settings = Settings;
RepClientNew.RepInfo.RankRelation.UID = KFPC.PlayerReplicationInfo.UniqueId;
RepClientNew.RepInfo.RankRelation.RankID = UIDRankRelationsPlayers.Find('UID', RepClientNew.RepInfo.RankRelation.UID);
2021-05-31 01:46:53 +00:00
2021-06-12 20:11:37 +00:00
RepClients.AddItem(RepClientNew);
2021-05-31 01:46:53 +00:00
2021-06-13 01:57:20 +00:00
foreach UIDRankRelationsActive(Relation)
2021-06-12 20:11:37 +00:00
RepClientNew.RepInfo.AddRankRelation(Relation);
2021-05-31 04:04:26 +00:00
2021-06-12 20:11:37 +00:00
RepClientNew.RepInfo.StartFirstTimeReplication();
2021-06-13 01:57:20 +00:00
if (RepClientNew.RepInfo.RankRelation.RankID != INDEX_NONE)
{
UIDRankRelationsActive.AddItem(RepClientNew.RepInfo.RankRelation);
foreach RepClients(RepClient)
RepClient.RepInfo.AddRankRelation(RepClientNew.RepInfo.RankRelation);
}
2021-05-31 01:46:53 +00:00
}
2021-06-12 18:44:20 +00:00
private function RemovePlayer(Controller C)
2021-05-31 01:46:53 +00:00
{
local KFPlayerController KFPC;
2021-06-13 01:57:20 +00:00
local int Index, i;
local UniqueNetId UID;
2021-05-31 01:46:53 +00:00
2021-06-12 20:11:37 +00:00
`callstack();
2021-05-31 01:46:53 +00:00
KFPC = KFPlayerController(C);
if (KFPC == None)
return;
2021-06-13 01:57:20 +00:00
UID = KFPC.PlayerReplicationInfo.UniqueId;
Index = UIDRankRelationsActive.Find('UID', UID);
if (Index != INDEX_NONE)
for (i = 0; i < UIDRankRelationsActive.Length; ++i)
if (Index != i)
RepClients[i].RepInfo.RemoveRankRelation(UIDRankRelationsActive[Index]);
2021-05-31 01:46:53 +00:00
Index = RepClients.Find('KFPC', KFPC);
if (Index == INDEX_NONE)
return;
if (RepClients[Index].RepInfo != None)
RepClients[Index].RepInfo.Destroy();
RepClients.Remove(Index, 1);
}
2021-06-12 18:44:20 +00:00
public function UpdatePlayerRank(UIDRankRelation Rel)
{
local SClient RepClient;
local int Index;
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
Index = UIDRankRelationsActive.Find('UID', Rel.UID);
if (Index != INDEX_NONE)
UIDRankRelationsActive[Index] = Rel;
2021-06-13 01:57:20 +00:00
else
UIDRankRelationsActive.AddItem(Rel);
2021-06-12 18:44:20 +00:00
foreach RepClients(RepClient)
RepClient.RepInfo.UpdateRankRelation(Rel);
}
public function AddPlayerRank(UIDRankRelation Rel)
{
local SClient RepClient;
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
foreach RepClients(RepClient)
RepClient.RepInfo.AddRankRelation(Rel);
}
2021-05-31 01:46:53 +00:00
DefaultProperties
{
2020-01-10 13:14:11 +00:00
}