KF2-YetAnotherScoreboard/ScoreboardExt/Classes/ScoreboardExtMut.uc

254 lines
7.6 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);
const SteamIDLen = 17;
const UniqueIDLen = 18;
const CurrentVersion = 1;
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;
};
var private array<SClient> RepClients;
2021-06-12 18:44:20 +00:00
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
{
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-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-08 21:48:03 +00:00
RemovePlayer(C);
2021-05-31 01:46:53 +00:00
Super.NotifyLogout(C);
}
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
// 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:
`log("[ScoreboardExt] Config updated to version"@CurrentVersion);
break;
2021-06-12 18:44:20 +00:00
2021-05-31 01:46:53 +00:00
case CurrentVersion:
`log("[ScoreboardExt] Config is up-to-date");
break;
2021-06-12 18:44:20 +00:00
2021-05-31 01:46:53 +00:00
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);
`log("[ScoreboardExt] Warn: The config version will be changed to "@CurrentVersion);
break;
}
2021-06-08 20:31:56 +00:00
if (ConfigVersion != CurrentVersion)
{
ConfigVersion = CurrentVersion;
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-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 18:44:20 +00:00
if (Len(Player.ObjectID) == UniqueIDLen && 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 18:44:20 +00:00
else if (Len(Player.ObjectID) == SteamIDLen && 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 18:44:20 +00:00
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);
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-05-31 01:46:53 +00:00
local SClient RepClient;
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;
RepClient.KFPC = KFPC;
2021-06-12 18:44:20 +00:00
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);
2021-05-31 01:46:53 +00:00
RepClients.AddItem(RepClient);
2021-06-12 18:44:20 +00:00
// хуйня
foreach UIDRankRelationsActive(Relation)
foreach RepClients(RepClient)
RepClient.RepInfo.AddRankRelation(Relation);
2021-05-31 04:04:26 +00:00
2021-06-12 18:44:20 +00:00
RepClient.RepInfo.StartFirstTimeReplication();
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;
local int Index;
KFPC = KFPlayerController(C);
if (KFPC == None)
return;
2021-06-12 18:44:20 +00:00
// UID = KFPC.PlayerReplicationInfo.UniqueId;
// Remove Rank Relation here
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
/*
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);
}
2021-05-31 01:46:53 +00:00
DefaultProperties
{
2020-01-10 13:14:11 +00:00
}