Skip to content

Commit 08c4a56

Browse files
author
unknown
committed
Initial Commit
0 parents  commit 08c4a56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+74945
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vs
2+
bin

AdditionalMethods.cs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.IO;
3+
using System.Net;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Collections;
9+
using Rocket.API;
10+
using Rocket.Core;
11+
using Rocket.Unturned;
12+
using Rocket.Core.Logging;
13+
using Rocket.Unturned.Player;
14+
using SDG.Unturned;
15+
using Rocket.Core.Plugins;
16+
using UP = Rocket.Unturned.Player.UnturnedPlayer;
17+
using System.Text.RegularExpressions;
18+
19+
namespace ReportDiscord
20+
{
21+
public static class AdditionalMethods
22+
{
23+
public static void sendDiscordWebhook(string url, string escapedJson)
24+
{
25+
var WebReq = WebRequest.Create(url);
26+
WebReq.ContentType = "application/json";
27+
WebReq.Method = "POST";
28+
using (var StrWrt = new StreamWriter(WebReq.GetRequestStream())) StrWrt.Write(escapedJson);
29+
WebResponse Res = WebReq.GetResponse();
30+
StreamReader Reader = new StreamReader(Res.GetResponseStream());
31+
string str = Reader.ReadLine();
32+
while (str != null)
33+
{
34+
Console.WriteLine(str);
35+
str = Reader.ReadLine();
36+
}
37+
Reader.Close();
38+
Res.Close();
39+
}
40+
41+
public static string discordDate()
42+
{
43+
return DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
44+
}
45+
}
46+
}

ChatSystem.cs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Text.RegularExpressions;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Reflection;
8+
using System.Net;
9+
using Rocket.API;
10+
using Rocket.Unturned.Chat;
11+
using Rocket.Unturned.Player;
12+
using SDG.Unturned;
13+
using Steamworks;
14+
using UnityEngine;
15+
16+
namespace ReportDiscord
17+
{
18+
public static class ChatSystem
19+
{
20+
public static CSteamID GetCSteamID(this string id)
21+
{
22+
return new CSteamID(ulong.Parse(id));
23+
}
24+
25+
public static void sendMessage(this IRocketPlayer caller, String message)
26+
{
27+
Regex filter = new Regex(@"<[^>]*>");
28+
String formatlessMessage = filter.Replace(message, string.Empty);
29+
30+
if (caller.DisplayName == "Console")
31+
{
32+
UnturnedChat.Say(caller, formatlessMessage);
33+
}
34+
else
35+
{
36+
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, UnturnedPlayer.FromCSteamID(caller.Id.GetCSteamID()).SteamPlayer(), EChatMode.SAY, null, true);
37+
}
38+
}
39+
40+
public static void sendMessage(this IRocketPlayer caller, String message, String icon)
41+
{
42+
Regex filter = new Regex(@"<[^>]*>");
43+
String formatlessMessage = filter.Replace(message, string.Empty);
44+
45+
if (caller.DisplayName == "Console")
46+
{
47+
UnturnedChat.Say(caller, formatlessMessage);
48+
}
49+
else
50+
{
51+
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, UnturnedPlayer.FromCSteamID(caller.Id.GetCSteamID()).SteamPlayer(), EChatMode.SAY, icon, true);
52+
}
53+
}
54+
55+
public static void sendGlobalMessage(String message)
56+
{
57+
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, null, EChatMode.GLOBAL, null, true);
58+
}
59+
60+
public static void sendGlobalMessage(String message, String icon)
61+
{
62+
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, null, EChatMode.GLOBAL, icon, true);
63+
}
64+
}
65+
}

Commands/ReportCommand.cs

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.IO;
5+
using System.Xml;
6+
using System.Collections;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Rocket.API;
10+
using Rocket.Core;
11+
using Rocket.Unturned;
12+
using Rocket.Core.Logging;
13+
using Rocket.Unturned.Player;
14+
using SDG.Unturned;
15+
using Rocket.Core.Plugins;
16+
using UP = Rocket.Unturned.Player.UnturnedPlayer;
17+
using Rocket.API.Serialisation;
18+
using Rocket.Unturned.Chat;
19+
using SDG.Provider;
20+
using Steamworks;
21+
using UnityEngine;
22+
using ReportDiscord;
23+
using System.Globalization;
24+
25+
namespace ReportDiscord.Commands
26+
{
27+
class ReportCommand : IRocketCommand
28+
{
29+
public AllowedCaller AllowedCaller => AllowedCaller.Player;
30+
31+
public string Name => "report";
32+
33+
public string Help => "alers staff members about a violation";
34+
35+
public string Syntax => "<player> <reason>";
36+
37+
public List<string> Aliases => new List<string>();
38+
39+
public List<string> Permissions
40+
{
41+
get { return new List<string>() { "reportdiscord.report" }; }
42+
}
43+
44+
public void Execute(IRocketPlayer caller, string[] command)
45+
{
46+
UnturnedPlayer player = UnturnedPlayer.FromName(command[0]);
47+
var reason = string.Join(" ", command.Where(s => !string.IsNullOrEmpty(s) && s != command[0]));
48+
49+
if (player != null)
50+
{
51+
if (command.Length > 1)
52+
{
53+
foreach (var steamPlayer in Provider.clients)
54+
{
55+
UnturnedPlayer staffMember = UnturnedPlayer.FromSteamPlayer(steamPlayer);
56+
57+
if (staffMember.HasPermission("reportdiscord.notify"))
58+
{
59+
staffMember.sendMessage($"[<color=red> Report </color>] <color=green>{caller.DisplayName}</color> reports <color=red>{player.DisplayName}</color> for: '{reason}'");
60+
}
61+
}
62+
caller.sendMessage($"[<color=red> Report </color>] You have successfully reported <color=red>{player.DisplayName}</color> for '{reason}'");
63+
player.Player.sendScreenshot(CSteamID.Nil, OnReceivedScreenshot);
64+
void OnReceivedScreenshot(CSteamID player_0, byte[] jpg)
65+
{
66+
Task.Run(async () =>
67+
{
68+
string imageLink = await ImgBB.IMGBB.UploadAsync(jpg);
69+
AdditionalMethods.sendDiscordWebhook(ReportDiscord.Instance.Configuration.Instance.WebhookLink, "{\"username\": \"" + ReportDiscord.Instance.Configuration.Instance.WebhookName + "\", \"avatar_url\": \"" + ReportDiscord.Instance.Configuration.Instance.WebhookAvatar + "\", \"content\": \"" + ReportDiscord.Instance.Configuration.Instance.WebhookMessage + "\", \"embeds\":[ { \"title\":\"" + ReportDiscord.Instance.Configuration.Instance.WebhookTitle + "\", \"color\":"+ int.Parse(ReportDiscord.Instance.Configuration.Instance.WebhookColor.Replace("#", string.Empty), System.Globalization.NumberStyles.HexNumber) +", \"thumbnail\": { \"url\": \"" + ReportDiscord.Instance.Configuration.Instance.WebhookThumbnail + "\"}, \"image\": { \"url\": \"" + imageLink + "\"}, \"footer\": { \"text\": \"" + ReportDiscord.Instance.Configuration.Instance.WebhookFooter + "\", \"icon_url\": \"" + ReportDiscord.Instance.Configuration.Instance.WebhookFooterIcon + "\"}, \"timestamp\": \"" + AdditionalMethods.discordDate() + "\", \"fields\": [ {\"name\": \"Reporter\", \"value\": \"" + caller.DisplayName + "\", \"inline\": \"true\"}, {\"name\": \"Reportee\", \"value\": \"" + player.DisplayName + "\", \"inline\": \"true\"}, {\"name\": \"Reportees SteamID\", \"value\": \"" + player.CSteamID + "\", \"inline\": \"true\"}, { \"name\": \"Reason\", \"value\": \"" + reason + "\" } ]}] }");
70+
});
71+
}
72+
} else
73+
{
74+
caller.sendMessage($"[<color=red> Report </color>] You have not specified report reason");
75+
}
76+
} else
77+
{
78+
caller.sendMessage($"[<color=red> Report </color>] Player not found");
79+
}
80+
}
81+
}
82+
}

Configuration.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Rocket.API;
2+
using Rocket.Core.Assets;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Xml.Serialization;
9+
using Rocket.Unturned.Items;
10+
using SDG.Unturned;
11+
12+
namespace ReportDiscord
13+
{
14+
public class Configuration : IRocketPluginConfiguration
15+
{
16+
public string LicenseKey;
17+
public string WebhookLink;
18+
public string WebhookName;
19+
public string WebhookAvatar;
20+
public string WebhookMessage;
21+
public string WebhookThumbnail;
22+
public string WebhookTitle;
23+
public string WebhookColor;
24+
public string WebhookFooter;
25+
public string WebhookFooterIcon;
26+
public string ImgBBKey;
27+
28+
public void LoadDefaults()
29+
{
30+
LicenseKey = "043beceb-2d7a-41f1-8f92-5678ac358bf5";
31+
WebhookLink = "https://discord.com/api/webhooks/xxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
32+
WebhookAvatar = "https://i.imgur.com/7tjD5qr.png";
33+
WebhookMessage = "Report has been submitted <@&RoleId>. Spy of reported user has been attached.";
34+
WebhookName = "Report Webhook";
35+
WebhookThumbnail = "https://i.imgur.com/7tjD5qr.png";
36+
WebhookTitle = "Report";
37+
WebhookColor = "#FF0000";
38+
WebhookFooter = "Report Plugin, developed by XXFOGS";
39+
WebhookFooterIcon = "https://i.imgur.com/7tjD5qr.png";
40+
ImgBBKey = "GET YOUR API KEY HERE https://imgbb.com";
41+
}
42+
}
43+
}

ImgBB.cs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Newtonsoft.Json;
2+
using SDG.Unturned;
3+
using System;
4+
using System.IO;
5+
using System.Net;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ReportDiscord
10+
{
11+
class ImgBB
12+
{
13+
public static class IMGBB
14+
{
15+
private const string Endpoint = "https://api.imgbb.com/1/upload";
16+
17+
public static async Task<string> UploadAsync(byte[] data)
18+
{
19+
var req = WebRequest.CreateHttp(Endpoint);
20+
req.Method = "POST";
21+
var payload = Encoding.UTF8.GetBytes($"key={ReportDiscord.Instance.Configuration.Instance.ImgBBKey}&image={WebUtility.UrlEncode(Convert.ToBase64String(data))}&name=spy&expiration=86400");
22+
req.ContentType = "application/x-www-form-urlencoded";
23+
req.ContentLength = payload.Length;
24+
25+
using (var network = await req.GetRequestStreamAsync())
26+
{
27+
await network.WriteAsync(payload, 0, payload.Length);
28+
await network.FlushAsync();
29+
}
30+
var resp = (HttpWebResponse)await req.GetResponseAsync();
31+
32+
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
33+
{
34+
var json = await sr.ReadToEndAsync();
35+
36+
var d = JsonConvert.DeserializeObject<ImgBBResult>(json);
37+
38+
return d.data.Display_Url;
39+
}
40+
}
41+
}
42+
43+
public class ImgBBResult
44+
{
45+
public ImgBBData data;
46+
}
47+
48+
public class ImgBBData
49+
{
50+
public string ID;
51+
public string Title;
52+
public string url_Viewer;
53+
public string Url;
54+
public string Display_Url;
55+
public int size;
56+
public int expiration;
57+
public long time;
58+
}
59+
}
60+
}

Plugin.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Timers;
3+
using System.Collections.Generic;
4+
using System.Collections;
5+
using System.Linq;
6+
using System.IO;
7+
using System.Net;
8+
using System.Xml;
9+
using System.Xml.Linq;
10+
using System.Text;
11+
using System.Threading;
12+
using System.Threading.Tasks;
13+
using System.Reflection;
14+
using System.Globalization;
15+
using Rocket.API;
16+
using Rocket.Core;
17+
using Rocket.Unturned;
18+
using Rocket.Unturned.Events;
19+
using Rocket.Unturned.Items;
20+
using Rocket.Unturned.Player;
21+
using Rocket.Unturned.Enumerations;
22+
using Rocket.Unturned.Plugins;
23+
using Rocket.Core.Logging;
24+
using Rocket.API.Collections;
25+
using Rocket.Core.Plugins;
26+
using SDG.Unturned;
27+
using Steamworks;
28+
using SDG;
29+
using UnityEngine;
30+
using UnityEngine.Events;
31+
using UP = Rocket.Unturned.Player.UnturnedPlayer;
32+
using Rocket.API.Serialisation;
33+
using Rocket.Unturned.Chat;
34+
using SDG.Provider;
35+
using Logger = Rocket.Core.Logging.Logger;
36+
37+
namespace ReportDiscord
38+
{
39+
public class ReportDiscord : RocketPlugin<Configuration>
40+
{
41+
public static ReportDiscord Instance;
42+
public string Creator = "XXFOGS";
43+
public string Version = "1.0.0";
44+
45+
protected override void Load()
46+
{
47+
Instance = this;
48+
49+
Logger.Log($"ReportDiscord by {Creator} has been loaded! Version: {Version}");
50+
51+
}
52+
53+
protected override void Unload()
54+
{
55+
Logger.Log("ReportDiscord has been unloaded");
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)