C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Rust;
using UnityEngine;
using WebSocketSharp;
namespace Oxide.Plugins {
[Info("RSystem", "XAVIER", "1.0.0")]
public class RSystem : RustPlugin {
public class PlayerData {
public int AlertAll = 0;
public int RAll = 0;
public string LastReport = "";
public int TimeOut = 0;
public int Kill = 1;
public int Death = 1;
}
private object OnPlayerDeath(BasePlayer player, HitInfo hitInfo) {
if (player != null) {
if (hitInfo == null || !player.userID.IsSteamId()) return null;
var data = _playerData[player.userID];
if (hitInfo.InitiatorPlayer != null) {
if (!hitInfo.InitiatorPlayer.userID.IsSteamId()) return null;
BasePlayer initiator = hitInfo.InitiatorPlayer;
var PlayerstatInitiator = _playerData[initiator.userID];
if (hitInfo.damageTypes.GetMajorityDamageType() == DamageType.Suicide) {
data.Death++;
return null;
}
PlayerstatInitiator.Kill++;
data.Death++;
}
else {
if (hitInfo.damageTypes.GetMajorityDamageType() == DamageType.Suicide) return null;
data.Death++;
}
}
return null;
}
public Dictionary<ulong, PlayerData> _playerData = new Dictionary<ulong, PlayerData>();
void OnServerInitialized() {
try {
_playerData = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<ulong, PlayerData>>(Name);
}
catch {
_playerData = new Dictionary<ulong, PlayerData>();
}
foreach (var player in BasePlayer.activePlayerList) {
OnPlayerConnected(player);
}
}
void OnPlayerConnected(BasePlayer player) {
if (!_playerData.ContainsKey(player.userID)) _playerData.Add(player.userID, new PlayerData());
GetAvatar(player.userID, avatar => ImageLibrary?.Call("AddImage", avatar, $"avatar_{player.UserIDString}"));
}
private readonly Regex Regex = new Regex(@"<avatarFull><!\[CDATA\[(.*)\]\]></avatarFull>");
private void GetAvatar(ulong userId, Action<string> callback) {
if (callback == null) return;
webrequest.Enqueue($"http://steamcommunity.com/profiles/{userId}?xml=1", null, (code, response) => {
if (code != 200 || response == null) return;
var avatar = Regex.Match(response).Groups[1].ToString();
if (avatar.IsNullOrEmpty()) return;
callback.Invoke(avatar);
}
, this);
}
void Unload() {
Interface.Oxide.DataFileSystem.WriteObject(Name, _playerData);
}
public string HexToCuiColor(string HEX, float Alpha = 100) {
if (string.IsNullOrEmpty(HEX)) HEX = "#FFFFFF";
var str = HEX.Trim('#');
var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
return $"{(double)r / 255} {(double)g / 255} {(double)b / 255} {Alpha / 100}";
}
#region Configuration
private PluginConfig config;
protected override void LoadDefaultConfig() {
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig() {
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
if (config.PluginVersion < Version) UpdateConfigValues();
Config.WriteObject(config, true);
}
private void UpdateConfigValues() {
PluginConfig baseConfig = PluginConfig.DefaultConfig();
if (config.PluginVersion < new VersionNumber(1, 0, 2)) {
PrintWarning("Config update detected! Updating config values...");
PrintWarning("Config update completed!");
}
config.PluginVersion = Version;
}
protected override void SaveConfig() {
Config.WriteObject(config);
}
[ConsoleCommand("report.opentab")]
void ConsoleOpenReport(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
CuiHelper.DestroyUi(player, "StaticMenu");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiElement {
Parent = "UI_MenuLayer", Name = "StaticMenu", Components = {
new CuiImageComponent {
Color = "0 0 0 0"
}
, new CuiRectTransformComponent {
AnchorMin = "0.125 0.08333331", AnchorMax = "0.8755208 0.8324074"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0.8850433", AnchorMax = "1 0.8862795", OffsetMax = "0 0"
}
, Button = {
Color = HexToCuiColor("#FBFBFF", 20)
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 23, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
}
, "StaticMenu");
container.Add(new CuiLabel {
Text = {
Text = $"Имя игрока", Font = "robotocondensed-regular.ttf", FontSize = 13, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = $"0.05690494 0.9270704", AnchorMax = $"0.1596114 0.9567367"
}
,
}
, "StaticMenu");
container.Add(new CuiLabel {
Text = {
Text = $"Убийств", Font = "robotocondensed-regular.ttf", FontSize = 13, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
, RectTransform = {
AnchorMin = $"0.2789729 0.9270704", AnchorMax = $"0.3261639 0.9567367"
}
,
}
, "StaticMenu");
container.Add(new CuiLabel {
Text = {
Text = $"Смертей", Font = "robotocondensed-regular.ttf", FontSize = 13, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
, RectTransform = {
AnchorMin = $"0.4531611 0.9270704", AnchorMax = $"0.5003521 0.9567367"
}
,
}
, "StaticMenu");
container.Add(new CuiLabel {
Text = {
Text = $"КДА", Font = "robotocondensed-regular.ttf", FontSize = 13, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
, RectTransform = {
AnchorMin = $"0.6204095 0.9270704", AnchorMax = $"0.6682859 0.9567367"
}
,
}
, "StaticMenu");
CuiHelper.AddUi(player, container);
OpenReportList(player, 1);
}
[PluginReference]
private Plugin ImageLibrary;
void OpenReportList(BasePlayer player, int page) {
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, "StaticMenu" + ".back");
CuiHelper.DestroyUi(player, "StaticMenu" + ".next");
for (int i = 0; i < 6; i++) {
CuiHelper.DestroyUi(player, "StaticMenu" + $".{i}.ListPlayer");
}
int pagex = page + 1;
container.Add(new CuiElement {
Parent = "StaticMenu", Name = "StaticMenu" + ".next", Components = {
new CuiRawImageComponent {
Png = (string)ImageLibrary?.Call("GetImage", "https://i.imgur.com/P5rDCQP.png"), Color = pagex > 0 && (pagex - 1) * 6 < BasePlayer.activePlayerList.Count ? HexToCuiColor("") : HexToCuiColor("#FFFFFF", 10)
}
, new CuiRectTransformComponent {
AnchorMin = "0.9104796 0.06056862", AnchorMax = "0.9437898 0.1186651"
}
,
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Color = "0 0 0 0", Command = pagex > 0 && (pagex - 1) * 6 < BasePlayer.activePlayerList.Count ? $"report.tab page {page + 1}" : ""
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 20, Align = TextAnchor.MiddleCenter
}
}
, "StaticMenu" + ".next");
container.Add(new CuiElement {
Parent = "StaticMenu", Name = "StaticMenu" + ".back", Components = {
new CuiRawImageComponent {
Png = (string)ImageLibrary?.Call("GetImage", "https://i.imgur.com/b4TUg0Z.png"), Color = page != 1 ? HexToCuiColor("") : HexToCuiColor("#FFFFFF", 10)
}
, new CuiRectTransformComponent {
AnchorMin = "0.8716169 0.06056862", AnchorMax = "0.9049271 0.1186651"
}
,
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Color = "0 0 0 0", Command = page != 1 ? $"report.tab page {page - 1}" : ""
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 20, Align = TextAnchor.MiddleCenter
}
}
, "StaticMenu" + ".back");
foreach (var check in BasePlayer.activePlayerList.OrderByDescending(p => _playerData[p.userID].RAll).Select((i, t) => new {
A = i, B = t - (page - 1) * 6
}
).Skip((page - 1) * 6).Take(6)) {
var data = _playerData[check.A.userID];
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"{0 + check.B * 0.120 - Math.Floor((double) check.B / 1) * 1 * 0.120} {0.7713226 - Math.Floor((double) check.B / 1) * 0.16}", AnchorMax = $"{1 + check.B * 0.120 - Math.Floor((double) check.B / 1) * 1 * 0.120} {0.8862794 - Math.Floor((double) check.B / 1) * 0.16 }", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Command = ""
}
, Text = {
Text = $"", Align = TextAnchor.LowerRight, Font = "robotocondensed-regular.ttf", FontSize = 15
}
}
, "StaticMenu", "StaticMenu" + $".{check.B}.ListPlayer");
container.Add(new CuiElement {
FadeOut = 0.3f, Parent = "StaticMenu" + $".{check.B}.ListPlayer", Components = {
new CuiRawImageComponent {
FadeIn = 0.3f, Png = (string) ImageLibrary?.Call("GetImage", $"avatar_{player.userID.ToString()}")
}
, new CuiRectTransformComponent {
AnchorMin = "0.05551699 0.2365592", AnchorMax = "0.08952117 0.7526883"
}
}
}
);
container.Add(new CuiElement {
FadeOut = 0.3f, Parent = "StaticMenu" + $".{check.B}.ListPlayer", Components = {
new CuiTextComponent {
Text = $"{check.A.displayName}", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-regular.ttf", FontSize = 12, Color = HexToCuiColor("#BFBFBF")
}
, new CuiRectTransformComponent {
AnchorMin = "0.09993061 0.365591", AnchorMax = "0.1825121 0.6236559"
}
}
}
);
container.Add(new CuiElement {
FadeOut = 0.3f, Parent = "StaticMenu" + $".{check.B}.ListPlayer", Components = {
new CuiTextComponent {
Text = $"{data.Kill}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 11, Color = HexToCuiColor("#BFBFBF")
}
, new CuiRectTransformComponent {
AnchorMin = "0.278279 0.365591", AnchorMax = "0.3268579 0.6236559"
}
}
}
);
container.Add(new CuiElement {
FadeOut = 0.3f, Parent = "StaticMenu" + $".{check.B}.ListPlayer", Components = {
new CuiTextComponent {
Text = $"{data.Death}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 11, Color = HexToCuiColor("#BFBFBF")
}
, new CuiRectTransformComponent {
AnchorMin = "0.4531612 0.365591", AnchorMax = "0.5017401 0.6236559"
}
}
}
);
container.Add(new CuiElement {
FadeOut = 0.3f, Parent = "StaticMenu" + $".{check.B}.ListPlayer", Components = {
new CuiTextComponent {
Text = $"{data.Kill / data.Death}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 11, Color = HexToCuiColor("#BFBFBF")
}
, new CuiRectTransformComponent {
AnchorMin = "0.6197156 0.365591", AnchorMax = "0.6682945 0.6236559"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.7890354 0.2473122", AnchorMax = "0.9430951 0.7419357"
}
, Button = {
Command = $"report.tab reportopen {player.userID}", Color = HexToCuiColor("#6C26DD")
}
, Text = {
Text = "Отправить жалобу", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
}
}
, "StaticMenu" + $".{check.B}.ListPlayer");
}
CuiHelper.AddUi(player, container);
}
[ConsoleCommand("report.tab")]
void reportTabSelect(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if (args.Args[0] == "reportopen") {
var target = BasePlayer.Find(args.Args[1]);
if (target == null) {
player.ChatMessage("Игрок с таким ником не найден!");
return;
}
OpenReportSelect(player, target);
}
else if (args.Args[0] == "report") {
string reason = args.Args[1];
BasePlayer target = BasePlayer.Find(args.Args[2]);
if (target == null) {
CuiHelper.DestroyUi(player, Layer);
SendReply(player, "Данный игрок вышел с сервера!");
return;
}
CuiHelper.DestroyUi(player, Layer);
_playerData[target.userID].RAll++;
_playerData[target.userID].LastReport = reason;
SendVkMessage(VKADMIN(), $"Игрок: {player.displayName}({player.userID})" + $"\nДанный игрок пожаловался на:{target.displayName}({target.userID})" + $"\nПричина жалобы: {reason}");
SendReply(player, $"Вы успешно отправили репорт на игрока {target.displayName}\nСпасибо за помощь!");
}
else if (args.Args[0] == "page") {
int page = 1;
if (int.TryParse(args.Args[1], out page)) {
if (page > 0 && (page - 1) * 6 <= BasePlayer.activePlayerList.Count) {
OpenReportList(player, page);
}
}
}
}
private string URLEncode(string input) {
if (input.Contains("#")) input = input.Replace("#", "%23");
if (input.Contains("$")) input = input.Replace("$", "%24");
if (input.Contains("+")) input = input.Replace("+", "%2B");
if (input.Contains("/")) input = input.Replace("/", "%2F");
if (input.Contains(":")) input = input.Replace(":", "%3A");
if (input.Contains(";")) input = input.Replace(";", "%3B");
if (input.Contains("?")) input = input.Replace("?", "%3F");
if (input.Contains("@")) input = input.Replace("@", "%40");
return input;
}
void GetCallback(int number, string param, string message) {
}
private string app = "v=5.92";
private string RandomId() => UnityEngine.Random.Range(Int32.MinValue, Int32.MaxValue).ToString();
private void SendVkMessage(string reciverID, string msg) => webrequest.Enqueue("https://api.vk.com/method/messages.send?user_ids=" + reciverID + "&message=" + URLEncode(msg) + "&"+app + "&random_id=" + RandomId() + "&access_token=" + config.VKTOKEN, null, (code, response) => GetCallback(code, response, "Сообщение"), this);
public string VKADMIN() => config.VkID;
public string Layer = "UI_ReportLayer";
void OpenReportSelect(BasePlayer player, BasePlayer target) {
CuiHelper.DestroyUi(player, Layer);
var container = new CuiElementContainer();
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Image = {
Color = "0 0 0 0"
}
}
, "Overlay", Layer);
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.125 0.08333331", AnchorMax = "0.875 0.9166667"
}
, Image = {
Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat", Color = HexToCuiColor($"19191C", 80)
}
}
, Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.3916667 0.3203704", AnchorMax = "0.6083333 0.6796296", OffsetMax = "0 0"
}
, Button = {
Color = HexToCuiColor("#19191C", 90)
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 23, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
}
, Layer, ".Main");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.3916667 0.5907407", AnchorMax = "0.6078125 0.5925926", OffsetMax = "0 0"
}
, Button = {
Color = HexToCuiColor("#FBFBFF", 20)
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 23, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
}
, Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5833334 0.6351852", AnchorMax = "0.6083333 0.6796296", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Close = Layer
}
, Text = {
Text = "X", Font = "robotocondensed-regular.ttf", FontSize = 23, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
}
, Layer);
container.Add(new CuiElement {
FadeOut = 0.3f, Parent = Layer, Components = {
new CuiTextComponent {
Text = $"{target.displayName}\n<color=#BFBFBF>Подать жалобу</color>", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-regular.ttf", FontSize = 12,
}
, new CuiRectTransformComponent {
AnchorMin = "0.440625 0.612963", AnchorMax = "0.5822917 0.6583334"
}
}
}
);
container.Add(new CuiElement {
FadeOut = 0.3f, Parent = Layer, Components = {
new CuiRawImageComponent {
FadeIn = 0.3f, Png = (string) ImageLibrary?.Call("GetImage", $"avatar_{player.userID.ToString()}")
}
, new CuiRectTransformComponent {
AnchorMin = "0.4088541 0.612963", AnchorMax = "0.4333333 0.6583334"
}
}
}
);
foreach (var check in config.ReasonBan.Select((i, t) => new {
A = i, B = t
}
)) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"{0 + check.B * 0.020 - Math.Floor((double) check.B / 1) * 1 * 0.020} {0.6314433 - Math.Floor((double) check.B / 1) * 0.121}", AnchorMax = $"{1 + check.B * 0.020 - Math.Floor((double) check.B / 1) * 1 * 0.020} {0.7525773 - Math.Floor((double) check.B / 1) * 0.121}", OffsetMax = "0 0"
}
, Button = {
Color = HexToCuiColor("#FBFBFF", 10), Command = $"report.tab report {check.A.Value} {target.userID}"
}
, Text = {
Text = $" {check.A.Value}", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-regular.ttf", FontSize = 14, Color = HexToCuiColor("#FBFBFF", 50)
}
}
, ".Main", ".Main" + $".{check.B}");
}
CuiHelper.AddUi(player, container);
}
private class PluginConfig {
[JsonProperty("VK токен группы")]
public string VKTOKEN;
[JsonProperty(PropertyName = "VkID администраторов (пример 11111, 22222)")]
public string VkID;
[JsonProperty("Причины репортов")]
public Dictionary<string, string> ReasonBan = new Dictionary<string, string>();
[JsonProperty("Версия конфигурации")]
public VersionNumber PluginVersion = new VersionNumber();
public static PluginConfig DefaultConfig() {
return new PluginConfig() {
VKTOKEN = "JDHSAKDJHASDJK", VkID = "111111, 22222222", PluginVersion = new VersionNumber(), ReasonBan = new Dictionary<string, string>() {
["1"]
= "3+", ["2"] = "Багоюз", ["3"] = "Чит", ["4"] = "Макрос"
}
}
;
}
}
#endregion
}
}