C#:
using System;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Libraries.Covalence;
using ConVar;
using Newtonsoft.Json.Linq;
using Oxide.Core.Libraries;
using System.Linq;
using Oxide.Core.Plugins;
using System.Collections;
using Oxide.Core;
namespace Oxide.Plugins {
[Info("Report", "MYSTERY", "0.0.1")]
public class MReport : RustPlugin {
[PluginReference]
Plugin ImageLibrary;
private class Configuration {
[JsonProperty("Причины репорта")]
public List<string> ReasonReport = new List<string>();
[JsonProperty("Webhooks для дискорда")]
public string WebHook;
public static Configuration Generate() {
return new Configuration {
ReasonReport = new List<string> {
"CHEATS / SOFT", "MACROS", "3+",
}
, WebHook = "",
}
;
}
}
private static Configuration Settings;
protected override void LoadConfig() {
base.LoadConfig();
try {
Settings = Config.ReadObject<Configuration>();
}
catch {
PrintWarning($"Error reading config, creating one new config!");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
protected override void SaveConfig() => Config.WriteObject(Settings);
private void OnServerInitialized() {
if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{Name}/Report Data")) RD = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, ReportData>>($"{Name}/Report Data");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/RSystem/Report.png", "report");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/RSystem/active.png", "acg");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/RSystem/right.png", "kitn");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/RSystem/left.png", "kitb");
BasePlayer.activePlayerList.ToList().ForEach(OnPlayerConnected);
}
void OnPlayerConnected(BasePlayer player) {
var IPa = ParseIp(player.net.connection.ipaddress);
if (!RD.ContainsKey(player.userID)) {
ReportData NewUser = new ReportData() {
DisplayName = player.displayName, SteamID = player.userID, IP = new List<string>(), Reason = new List<string>(), ReportCount = 0, ReportSteam = new List<ulong>(), Online = true,
}
;
RD.Add(player.userID, NewUser);
var User = RD[player.userID];
if (!User.IP.Contains(IPa)) User.IP.Add(IPa);
User.Online = true;
OnServerSave();
}
var Userd = RD[player.userID];
if (!Userd.IP.Contains(IPa)) Userd.IP.Add(IPa);
Userd.Online = true;
OnServerSave();
}
void OnPlayerDisconnected(BasePlayer player) {
var User = RD[player.userID];
User.Online = false;
OnServerSave();
}
void OnServerSave() {
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject($"{Name}/Report Data", RD);
}
private static string ParseIp(string input) {
if (input.Contains(":")) return input.Split(':')[0];
return input;
}
private Dictionary<ulong, ReportData> RD = new Dictionary<ulong, ReportData>();
private class ReportData {
[JsonProperty("Name")]
public string DisplayName;
[JsonProperty("SteamID")]
public ulong SteamID;
[JsonProperty("IP")]
public List<string> IP;
[JsonProperty("Reason")]
public List<string> Reason;
[JsonProperty("Report Count")]
public int ReportCount;
[JsonProperty("Report Steam")]
public List<ulong> ReportSteam;
[JsonProperty("Online")]
public bool Online;
}
public string GetImage(string shortname, ulong skin = 0) => (string)ImageLibrary?.Call("GetImage", shortname, skin);
[ChatCommand("report")]
void CmdChatStjore(BasePlayer player, string command, string[] args) {
UIR(player);
}
[ConsoleCommand("report")]
void ConsoleSkip(ConsoleSystem.Arg args) {
var player = args.Player();
if (player != null && args.HasArgs(1)) {
if (args.Args[0] == "profile") {
Rep(player, ulong.Parse(args.Args[1]), int.Parse(args.Args[2]));
}
if (args.Args[0] == "back") {
UIR(player);
}
if (args.Args[0] == "skip") {
UIR(player, int.Parse(args.Args[1]));
}
if (args.Args[0] == "soft") {
AddRep(player, ulong.Parse(args.Args[1]), args.Args[2]);
}
}
}
void AddRep(BasePlayer player, ulong p, string r) {
var DB = RD[p];
DB.Reason.Add(r);
if (!DB.ReportSteam.Contains(player.userID)) DB.ReportSteam.Add(player.userID);
DB.ReportCount++;
OnServerSave();
var text = "↓Отправил жалобу на игрока↓";
var text1 = $"Жалоба [{r}]";
var c = $"Количество репортов на игрока [{DB.ReportCount}]";
IPlayer Suspect = covalence.Players.FindPlayerById(p.ToString());
DiscordSendMessage(player.displayName, Suspect.Name, player.userID.ToString(), Suspect.Id.ToString(), text, text1, c);
CuiHelper.DestroyUi(player, "Pr");
UIR(player);
}
private static string RE = "UI_re";
void UIR(BasePlayer player, int page = 0) {
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, RE);
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Image = {
Color = "0 0 0 0"
}
}
, "MYSTERY", RE);
if(BasePlayer.activePlayerList.Count() > (page + 1) * 10) {
container.Add(new CuiElement {
Parent = RE, Components = {
new CuiRawImageComponent {
Png = (string) ImageLibrary.Call("GetImage", $"kitn")
}
, new CuiRectTransformComponent {
AnchorMin = $"0.523 0.02", AnchorMax = $"0.593 0.11"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0.523 0.02", AnchorMax = $"0.593 0.11", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Command = $"report skip {page + 1}"
}
, Text = {
Text = $"", Color = "1 1 1 0", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
}
}
, RE);
}
if(page >= 1) {
container.Add(new CuiElement {
Parent = RE, Components = {
new CuiRawImageComponent {
Png = (string) ImageLibrary.Call("GetImage", $"kitb")
}
, new CuiRectTransformComponent {
AnchorMin = $"0.37 0.02", AnchorMax = $"0.44 0.11"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0.37 0.02", AnchorMax = $"0.44 0.11", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Command = $"report skip {page - 1}"
}
, Text = {
Text = $"", Color = "1 1 1 0", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
}
}
, RE);
}
float width = 0.200f, height = 0.100f, startxBox = 0.100f, startyBox = 0.900f - height, xmin = startxBox, ymin = startyBox, p = 0;
var items = BasePlayer.activePlayerList;
foreach (var check in items.Skip(page * 32).Take(32)) {
p++;
container.Add(new CuiElement {
Parent = RE, Name = "Imagesr", Components = {
new CuiRawImageComponent {
Png = (string) ImageLibrary.Call("GetImage", "report")
}
, new CuiRectTransformComponent {
AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width * 0.9f} {ymin + height * 0.9f}"
}
}
}
);
string ImageAvatar = GetImage(check.UserIDString, 0);
container.Add(new CuiElement {
Parent = $"Imagesr", Components = {
new CuiRawImageComponent {
Png = ImageAvatar
}
, new CuiRectTransformComponent {
AnchorMin = "0.02 0.05", AnchorMax = $"0.3 0.95"
}
,
}
}
);
container.Add(new CuiElement {
Parent = "Imagesr", Components = {
new CuiTextComponent {
Text = $"{check.displayName}\n{check.userID}", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleLeft, FontSize = 11, Font = "robotocondensed-regular.ttf"
}
, new CuiRectTransformComponent {
AnchorMin = $"0.32 0", AnchorMax = $"0.88 1"
}
, new CuiOutlineComponent {
Color = "0.90 0.66 0.64 0.5", Distance = "0.1 0.1"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.88 0", AnchorMax = "1 1"
}
, Button = {
Command = $"report profile {check.userID} {p + page * 32}", Color = "0 0 0 0"
}
, Text = {
Text = "", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 20, Color = "0 0 0 0"
}
}
, "Imagesr");
xmin += width;
if (xmin + width >= 1) {
xmin = startxBox;
ymin -= height;
}
}
CuiHelper.AddUi(player, container);
}
void Rep(BasePlayer player, ulong SteamID, int p) {
IPlayer Suspect = covalence.Players.FindPlayerById(SteamID.ToString());
var DB = RD[SteamID];
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, "Pr");
CuiHelper.DestroyUi(player, RE);
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0.4 0.2", AnchorMax = "0.6 0.8", OffsetMax = "0 0"
}
, Image = {
Color = "0 0 0 0.7"
}
}
, "MYSTERY", "Pr");
string ImageAvatar = GetImage(SteamID.ToString(), 0);
container.Add(new CuiElement {
Parent = $"Pr", Components = {
new CuiRawImageComponent {
Png = ImageAvatar
}
, new CuiRectTransformComponent {
AnchorMin = "0.02 0.83", AnchorMax = $"0.3 0.99"
}
,
}
}
);
container.Add(new CuiElement {
Parent = "Pr", Components = {
new CuiTextComponent {
Text = $"{Suspect.Id}", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleLeft, FontSize = 12
}
, new CuiRectTransformComponent {
AnchorMin = $"0.33 0.9", AnchorMax = $"0.98 1"
}
, new CuiOutlineComponent {
Color = "0.90 0.66 0.64 0.5", Distance = "0.1 0.1"
}
}
}
);
container.Add(new CuiElement {
Parent = "Pr", Components = {
new CuiTextComponent {
Text = $"{Suspect.Name}", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleLeft, FontSize = 12
}
, new CuiRectTransformComponent {
AnchorMin = $"0.33 0.85", AnchorMax = $"0.98 0.9"
}
, new CuiOutlineComponent {
Color = "0.90 0.66 0.64 0.5", Distance = "0.1 0.1"
}
}
}
);
container.Add(new CuiElement {
Parent = "Pr", Components = {
new CuiTextComponent {
Text = $"REPORTS {DB.ReportCount}", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleCenter, FontSize = 12
}
, new CuiRectTransformComponent {
AnchorMin = $"0.02 0.6", AnchorMax = $"0.98 0.7"
}
, new CuiOutlineComponent {
Color = "0.90 0.66 0.64 0.5", Distance = "0.1 0.1"
}
}
}
);
float width1 = 0.93f, height1 = 0.110f, startxBox1 = 0.03f, startyBox1 = 0.5f - height1, xmin1 = startxBox1, ymin1 = startyBox1;
foreach (var check in Settings.ReasonReport) {
container.Add(new CuiElement {
Parent = "Pr", Name = "Countf", Components = {
new CuiRawImageComponent {
Png = (string) ImageLibrary.Call("GetImage", "acg")
}
, new CuiRectTransformComponent {
AnchorMin = $"{xmin1} {ymin1}", AnchorMax = $"{xmin1 + width1} {ymin1 + height1 * 0.9}"
}
}
}
);
container.Add(new CuiElement {
Parent = "Countf", Components = {
new CuiTextComponent {
Text = $"{check}", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleLeft, FontSize = 12
}
, new CuiRectTransformComponent {
AnchorMin = $"0.3 0", AnchorMax = $"0.88 1"
}
, new CuiOutlineComponent {
Color = "0.90 0.66 0.64 0.5", Distance = "0.1 0.1"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0 0", AnchorMax = $"1 1"
}
, Button = {
Command = $"report soft {Suspect.Id} {check}", Color = "1 1 1 0"
}
, Text = {
Text = "", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 20, Color = "0 0 0 0"
}
}
, "Countf");
xmin1 += width1;
if (xmin1 + width1 >= 1) {
xmin1 = startxBox1;
ymin1 -= height1;
}
}
CuiHelper.AddUi(player, container);
}
void DiscordSendMessage(string p = null, string p1 = null, string id = null, string id1 = null, string t = null, string r = null, string count = null) {
if (String.IsNullOrEmpty(Settings.WebHook)) return;
List<Fields> fields = new List<Fields> {
new Fields(p, id, false), new Fields(t, "", false), new Fields(p1, id1, false), new Fields(r, count, false),
}
;
FancyMessage newMessage = new FancyMessage(null, false, new FancyMessage.Embeds[1] {
new FancyMessage.Embeds(null, 525133, fields, new Authors($"{Name}", "https://rustplugins.top", "https://i.imgur.com/FezBXS3.png", null), new Footer("Author: WOLF#4002", "https://i.imgur.com/Hf3Tiox.png", "https://rustplugins.top"))
}
);
Request($"{Settings.WebHook}", newMessage.toJSON());
}
#region FancyDiscord
public class FancyMessage {
public string content {
get;
set;
}
public bool tts {
get;
set;
}
public Embeds[] embeds {
get;
set;
}
public class Embeds {
public string title {
get;
set;
}
public int color {
get;
set;
}
public List<Fields> fields {
get;
set;
}
public Footer footer {
get;
set;
}
public Authors author {
get;
set;
}
public Embeds(string title, int color, List<Fields> fields, Authors author, Footer footer) {
this.title = title;
this.color = color;
this.fields = fields;
this.author = author;
this.footer = footer;
}
}
public FancyMessage(string content, bool tts, Embeds[] embeds) {
this.content = content;
this.tts = tts;
this.embeds = embeds;
}
public string toJSON() => JsonConvert.SerializeObject(this);
}
public class Footer {
public string text {
get;
set;
}
public string icon_url {
get;
set;
}
public string proxy_icon_url {
get;
set;
}
public Footer(string text, string icon_url, string proxy_icon_url) {
this.text = text;
this.icon_url = icon_url;
this.proxy_icon_url = proxy_icon_url;
}
}
public class Authors {
public string name {
get;
set;
}
public string url {
get;
set;
}
public string icon_url {
get;
set;
}
public string proxy_icon_url {
get;
set;
}
public Authors(string name, string url, string icon_url, string proxy_icon_url) {
this.name = name;
this.url = url;
this.icon_url = icon_url;
this.proxy_icon_url = proxy_icon_url;
}
}
public class Fields {
public string name {
get;
set;
}
public string value {
get;
set;
}
public bool inline {
get;
set;
}
public Fields(string name, string value, bool inline) {
this.name = name;
this.value = value;
this.inline = inline;
}
}
private void Request(string url, string payload, Action<int> callback = null) {
Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("Content-Type", "application/json");
webrequest.Enqueue(url, payload, (code, response) => {
if (code != 200 && code != 204) {
if (response != null) {
try {
JObject json = JObject.Parse(response);
if (code == 429) {
float seconds = float.Parse(Math.Ceiling((double)(int)json["retry_after"] / 1000).ToString());
}
else {
PrintWarning($" Discord rejected that payload! Responded with \"{json["message"].ToString()}\" Code: {code}");
}
}
catch {
PrintWarning($"Failed to get a valid response from discord! Error: \"{response}\" Code: {code}");
}
}
else {
PrintWarning($"Discord didn't respond (down?) Code: {code}");
}
}
try {
callback?.Invoke(code);
}
catch (Exception ex) {
}
}
, this, RequestMethod.POST, header);
}
#endregion
}
}