forked from Klayeryt/Welcome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
141 lines (123 loc) · 7.38 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Text.Json.Serialization;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Cvars;
namespace Main;
public class ConnectInfoConfig : BasePluginConfig
{
[JsonPropertyName("PluginName")] public string Name { get; set; } = "[Welcome] | ";
[JsonPropertyName("Timer")] public float Timer { get; set; } = 10.0f;
[JsonPropertyName("WelcomePlayerOneEnable")] public string WelcomePlayerOneEnable { get; set; } = "true";
[JsonPropertyName("WelcomePlayerAllEnable")] public string WelcomePlayerAllEnable { get; set; } = "true";
[JsonPropertyName("DisconnectPlayerAllEnable")] public string DisconnectPlayerAllEnable { get; set; } = "true";
[JsonPropertyName("WelcomeText")] public string WelcomeText { get; set; } = " {RED}---------------------------------{ENTER} {LIGHTBLUE}Welcome on server {PLAYERNAME} {ENTER} Now map: {MAP} {ENTER} Players online: {PLAYERS}/{MAXPLAYERS} {ENTER} {RED}Your IP: {IPUSER} {ENTER} {RED}------------------------------ ";
[JsonPropertyName("disconnectAllText")] public string disconnectAllText { get; set; } = " {RED} {PLAYERNAME} disconnect to reason: {REASON} ";
[JsonPropertyName("WelcomeAllText")] public string WelcomeAllText { get; set; } = " {RED} {PLAYERNAME} connected to server";
}
public class Main : BasePlugin, IPluginConfig<ConnectInfoConfig>
{
public override string ModuleName => "Welcome";
public override string ModuleAuthor => "Xenomoros";
public override string ModuleVersion => "1.0";
public ConnectInfoConfig Config { get; set; }
public void OnConfigParsed(ConnectInfoConfig config)
{
Config = config;
}
public override void Load(bool hotReload)
{
ReWriteColor($"-------------------------------------------");
ReWriteColor($"{Config.Name} Plugin has been enebled :)");
ReWriteColor($"{Config.Name} Plugin version - {ModuleVersion}");
ReWriteColor($"-------------------------------------------");
ReWriteColor("ConVars status: ");
if(Config.WelcomePlayerAllEnable == "false" || Config.WelcomePlayerAllEnable == "0") {
ReWriteColor("WelcomePlayerAllEnable(-None-)");
}
else if (Config.WelcomePlayerAllEnable == "true" || Config.WelcomePlayerAllEnable == "1") {
ReWriteColor("WelcomePlayerAllEnable(-Enable-)");
}
if (Config.WelcomePlayerOneEnable == "false" || Config.WelcomePlayerOneEnable == "0") {
ReWriteColor("WelcomePlayerOneEnable(-None-)");
}
else if (Config.WelcomePlayerOneEnable == "true" || Config.WelcomePlayerOneEnable == "1") {
ReWriteColor("WelcomePlayerOneEnable(-Enable-)");
}
if (Config.DisconnectPlayerAllEnable == "false" || Config.DisconnectPlayerAllEnable == "0") {
ReWriteColor("DisconnectPlayerAllEnable(-None-)");
}
else if (Config.DisconnectPlayerAllEnable == "true" || Config.DisconnectPlayerAllEnable == "1") {
ReWriteColor("DisconnectPlayerAllEnable(-Enable-)");
}
}
[GameEventHandler]
public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
{
string ipuser = @event.Userid.IpAddress;
var playerName = @event.Userid.PlayerName;
var eventr = @event;
var userid = @event.Userid;
var steamId = @event.Userid.SteamID.ToString();
if(Config.WelcomePlayerAllEnable == "true" || Config.WelcomePlayerAllEnable == "1") {
if([email protected]) {
Server.PrintToChatAll(ReplaceMessageTags(Config.WelcomeAllText, playerName, String.Empty, ipuser, steamId));
}
}
else {}
if(Config.WelcomePlayerOneEnable == "true" || Config.WelcomePlayerOneEnable == "1") {
if([email protected]) {
AddTimer(Config.Timer, () => {
userid.PrintToChat(ReplaceMessageTags(Config.WelcomeText, playerName, String.Empty, ipuser, steamId));
});
}
}
else {}
return HookResult.Stop;
}
[GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) {
string playerName = @event.Name;
if(Config.DisconnectPlayerAllEnable == "true" || Config.DisconnectPlayerAllEnable == "1") {
if(@event.Reason.ToString() != "39") {
Server.PrintToChatAll(ReplaceMessageTags(Config.disconnectAllText, playerName, @event.Reason.ToString(), String.Empty, String.Empty));
}
}
else {}
return HookResult.Continue;
}
public string ReWriteColor(string text) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"{text}");
Console.ForegroundColor = ConsoleColor.White;
return text;
}
private string ReplaceMessageTags(string message, string playerName, string reason, string ipuser, string SteamPlID)
{
var replacedMessage = message
.Replace("{ENTER}", "\u2029")
.Replace("{MAP}", NativeAPI.GetMapName())
.Replace("{TIME}", DateTime.Now.ToString("HH:mm:ss"))
.Replace("{DATE}", DateTime.Now.ToString("dd.MM.yyyy"))
.Replace("{SERVERNAME}", ConVar.Find("hostname")!.StringValue)
.Replace("{IP}", ConVar.Find("ip")!.StringValue)
.Replace("{PORT}", ConVar.Find("hostport")!.GetPrimitiveValue<int>().ToString())
.Replace("{MAXPLAYERS}", Server.MaxPlayers.ToString())
.Replace("{PLAYERS}", Utilities.GetPlayers().Count.ToString())
.Replace("{REASON}", reason)
.Replace("{PLAYERNAME}", playerName.ToString())
.Replace("{IPUSER}", ipuser)
.Replace("{STEAMID}", SteamPlID);
replacedMessage = ReplaceMessageColors(replacedMessage);
return replacedMessage;
}
private string ReplaceMessageColors(string input) {
string[] ColorAlphabet = {"{GREEN}", "{BLUE}", "{RED}", "{SILVER}", "{MAGENTA}", "{GOLD}", "{DEFAULT}", "{LIGHTBLUE}", "{LIGHTPURPLE}", "{LIGHTRED}", "{LIGHTYELLOW}", "{YELLOW}", "{GREY}", "{LIME}", "{OLIVE}", "{ORANGE}", "{DARKRED}", "{DARKBLUE}", "{BLUEGREY}", "{PURPLE}"};
string[] ColorChar = {$"{ChatColors.Green}", $"{ChatColors.Blue}", $"{ChatColors.Red}", $"{ChatColors.Silver}", $"{ChatColors.Magenta}", $"{ChatColors.Gold}", $"{ChatColors.Default}", $"{ChatColors.LightBlue}", $"{ChatColors.LightPurple}", $"{ChatColors.LightRed}", $"{ChatColors.LightYellow}", $"{ChatColors.Yellow}", $"{ChatColors.Grey}", $"{ChatColors.Lime}", $"{ChatColors.Olive}", $"{ChatColors.Orange}", $"{ChatColors.Darkred}", $"{ChatColors.DarkBlue}", $"{ChatColors.BlueGrey}", $"{ChatColors.Purple}"};
for(int z = 0; z < ColorAlphabet.Length; z++)
input = input.Replace(ColorAlphabet[z], ColorChar[z]);
return input;
}
}