Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Displaying the country when entering the server and adding NULL checks" #14

Open
wants to merge 1 commit into
base: Version-1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed GeoLite2-Country.mmdb
Binary file not shown.
102 changes: 39 additions & 63 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Core.Translations;
using MaxMind.Db;
using MaxMind.GeoIP2;
using System.IO;


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("WelcomePlayerOneEnable")] public string WelcomePlayerOneEnable { get; set; } = "true";
[JsonPropertyName("WelcomePlayerAllEnable")] public string WelcomePlayerAllEnable { get; set; } = "true";
[JsonPropertyName("DisconnectPlayerAllEnable")] public string DisconnectPlayerAllEnable { 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";
Expand All @@ -30,7 +28,7 @@ public class Main : BasePlugin, IPluginConfig<ConnectInfoConfig>
public override string ModuleVersion => "1.0.0";
public ENetworkDisconnectionReason Reason { get; set; }

public ConnectInfoConfig Config { get; set; } = null!;
public ConnectInfoConfig Config { get; set; }

public void OnConfigParsed(ConnectInfoConfig config)
{
Expand All @@ -40,131 +38,109 @@ public void OnConfigParsed(ConnectInfoConfig config)
public override void Load(bool hotReload)
{
ReWriteColor($"-------------------------------------------");
ReWriteColor($"{Config.Name} Plugin has been enabled :)");
ReWriteColor($"{Config.Name} Plugin has been enebled :)");
ReWriteColor($"{Config.Name} Plugin version - {ModuleVersion}");
ReWriteColor($"-------------------------------------------");
ReWriteColor("ConVars status: ");
if (Config.WelcomePlayerAllEnable == "false" || Config.WelcomePlayerAllEnable == "0")
{
if(Config.WelcomePlayerAllEnable == "false" || Config.WelcomePlayerAllEnable == "0") {
ReWriteColor("WelcomePlayerAllEnable(-None-)");
}
else if (Config.WelcomePlayerAllEnable == "true" || Config.WelcomePlayerAllEnable == "1")
{
else if (Config.WelcomePlayerAllEnable == "true" || Config.WelcomePlayerAllEnable == "1") {
ReWriteColor("WelcomePlayerAllEnable(-Enable-)");
}

if (Config.WelcomePlayerOneEnable == "false" || Config.WelcomePlayerOneEnable == "0")
{
if (Config.WelcomePlayerOneEnable == "false" || Config.WelcomePlayerOneEnable == "0") {
ReWriteColor("WelcomePlayerOneEnable(-None-)");
}
else if (Config.WelcomePlayerOneEnable == "true" || Config.WelcomePlayerOneEnable == "1")
{
else if (Config.WelcomePlayerOneEnable == "true" || Config.WelcomePlayerOneEnable == "1") {
ReWriteColor("WelcomePlayerOneEnable(-Enable-)");
}

if (Config.DisconnectPlayerAllEnable == "false" || Config.DisconnectPlayerAllEnable == "0")
{
if (Config.DisconnectPlayerAllEnable == "false" || Config.DisconnectPlayerAllEnable == "0") {
ReWriteColor("DisconnectPlayerAllEnable(-None-)");
}
else if (Config.DisconnectPlayerAllEnable == "true" || Config.DisconnectPlayerAllEnable == "1")
{
else if (Config.DisconnectPlayerAllEnable == "true" || Config.DisconnectPlayerAllEnable == "1") {
ReWriteColor("DisconnectPlayerAllEnable(-Enable-)");
}
}

public string GetCountry(string ipAddress)
{
using var reader = new DatabaseReader(Path.Combine(ModuleDirectory, "GeoLite2-Country.mmdb"));
var response = reader.Country(ipAddress);
return response?.Country?.IsoCode ?? "Unknown";
}


[GameEventHandler]
public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
{
string ipuser = @event.Userid.IpAddress ?? "Unknown";
string ipuser = @event.Userid.IpAddress;
var playerName = @event.Userid.PlayerName;
var eventr = @event;
var userid = @event.Userid;
var steamId = @event.Userid.SteamID.ToString();
string country = GetCountry(userid.IpAddress?.Split(":")[0] ?? "Unknown");
if (Config.WelcomePlayerAllEnable == "true" || Config.WelcomePlayerAllEnable == "1")
{
if ([email protected])
{
Server.PrintToChatAll(ReplaceMessageTags(Config.WelcomeAllText, playerName, String.Empty, ipuser, steamId, country));
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, country));
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)
{
var player = @event.Userid;
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) {
string playerName = @event.Name;
var reasonInt = @event.Reason;
string country = GetCountry(player.IpAddress?.Split(":")[0] ?? "Unknown");
if (Config.DisconnectPlayerAllEnable == "true" || Config.DisconnectPlayerAllEnable == "1")
{
if (@event.Reason.ToString() != "39")
{
if(Config.DisconnectPlayerAllEnable == "true" || Config.DisconnectPlayerAllEnable == "1") {
if(@event.Reason.ToString() != "39") {
string disconnectReasonString = Localizer[((ENetworkDisconnectionReason)reasonInt).ToString()];
Server.PrintToChatAll(ReplaceMessageTags(Config.disconnectAllText, playerName, disconnectReasonString, String.Empty, String.Empty, country));
Server.PrintToChatAll(ReplaceMessageTags(Config.disconnectAllText, playerName, disconnectReasonString, String.Empty, String.Empty));
}
}
else {}
return HookResult.Continue;
}

public string ReWriteColor(string text)
{
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, string countrycode)
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 ?? "Unknown")
.Replace("{IP}", ConVar.Find("ip")?.StringValue ?? "Unknown")
.Replace("{PORT}", ConVar.Find("hostport")?.GetPrimitiveValue<int>().ToString() ?? "Unknown")
.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)
.Replace("{PLAYERNAME}", playerName.ToString())
.Replace("{IPUSER}", ipuser)
.Replace("{COUNTRYCODE}", countrycode)
.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}" };
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++)
for(int z = 0; z < ColorAlphabet.Length; z++)
input = input.Replace(ColorAlphabet[z], ColorChar[z]);


return input;
}
}
7 changes: 0 additions & 7 deletions Welcome.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MaxMind.Db" Version="4.1.0" />
<PackageReference Include="MaxMind.GeoIP2" Version="5.2.0" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.7" />
</ItemGroup>
<ItemGroup>
<None Update="GeoLite2-Country.mmdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Binary file removed bin/Debug/net8.0/GeoLite2-Country.mmdb
Binary file not shown.
85 changes: 0 additions & 85 deletions bin/Debug/net8.0/Welcome.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,13 @@
".NETCoreApp,Version=v8.0": {
"Welcome/1.0.0": {
"dependencies": {
"MaxMind.Db": "4.1.0",
"MaxMind.GeoIP2": "5.2.0",
"Microsoft.Extensions.Localization.Abstractions": "8.0.7",
"CounterStrikeSharp.API": "1.0.213.0"
},
"runtime": {
"Welcome.dll": {}
}
},
"MaxMind.Db/4.1.0": {
"runtime": {
"lib/net8.0/MaxMind.Db.dll": {
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.0.0.0"
}
}
},
"MaxMind.GeoIP2/5.2.0": {
"dependencies": {
"MaxMind.Db": "4.1.0",
"Microsoft.Extensions.Options": "8.0.0"
},
"runtime": {
"lib/net8.0/MaxMind.GeoIP2.dll": {
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.0.0.0"
}
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions/8.0.0": {
"runtime": {
"lib/net8.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll": {
"assemblyVersion": "8.0.0.0",
"fileVersion": "8.0.23.53103"
}
}
},
"Microsoft.Extensions.Localization.Abstractions/8.0.7": {
"runtime": {
"lib/net8.0/Microsoft.Extensions.Localization.Abstractions.dll": {
Expand All @@ -53,26 +23,6 @@
}
}
},
"Microsoft.Extensions.Options/8.0.0": {
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0",
"Microsoft.Extensions.Primitives": "8.0.0"
},
"runtime": {
"lib/net8.0/Microsoft.Extensions.Options.dll": {
"assemblyVersion": "8.0.0.0",
"fileVersion": "8.0.23.53103"
}
}
},
"Microsoft.Extensions.Primitives/8.0.0": {
"runtime": {
"lib/net8.0/Microsoft.Extensions.Primitives.dll": {
"assemblyVersion": "8.0.0.0",
"fileVersion": "8.0.23.53103"
}
}
},
"CounterStrikeSharp.API/1.0.213.0": {
"runtime": {
"CounterStrikeSharp.API.dll": {
Expand All @@ -89,48 +39,13 @@
"serviceable": false,
"sha512": ""
},
"MaxMind.Db/4.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-lEjCFX0TUQCRmFS8xrXIQSi+4omJ1Fwy0gAHlbnjg8cgSBa0cllP5zOEftQ23EP247EbnF7mNCQ3JsG/bMkHAA==",
"path": "maxmind.db/4.1.0",
"hashPath": "maxmind.db.4.1.0.nupkg.sha512"
},
"MaxMind.GeoIP2/5.2.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-E8i6yQPlAznLTfS8w208uY3oqCg6i7sQ9cxKmlDdhFMXVLfm4sKphOTMsIWdAHJCV7RxW2a3DlqxAPkQrqmqlA==",
"path": "maxmind.geoip2/5.2.0",
"hashPath": "maxmind.geoip2.5.2.0.nupkg.sha512"
},
"Microsoft.Extensions.DependencyInjection.Abstractions/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-cjWrLkJXK0rs4zofsK4bSdg+jhDLTaxrkXu4gS6Y7MAlCvRyNNgwY/lJi5RDlQOnSZweHqoyvgvbdvQsRIW+hg==",
"path": "microsoft.extensions.dependencyinjection.abstractions/8.0.0",
"hashPath": "microsoft.extensions.dependencyinjection.abstractions.8.0.0.nupkg.sha512"
},
"Microsoft.Extensions.Localization.Abstractions/8.0.7": {
"type": "package",
"serviceable": true,
"sha512": "sha512-uCsxqBBJEsSoV52tX/v+bxxN0e1O8WYIRR7tmcEmVVkRSX+0k4ZJcaL79ddus+0HIm3ssjV/dJk56XufDrGDqg==",
"path": "microsoft.extensions.localization.abstractions/8.0.7",
"hashPath": "microsoft.extensions.localization.abstractions.8.0.7.nupkg.sha512"
},
"Microsoft.Extensions.Options/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-JOVOfqpnqlVLUzINQ2fox8evY2SKLYJ3BV8QDe/Jyp21u1T7r45x/R/5QdteURMR5r01GxeJSBBUOCOyaNXA3g==",
"path": "microsoft.extensions.options/8.0.0",
"hashPath": "microsoft.extensions.options.8.0.0.nupkg.sha512"
},
"Microsoft.Extensions.Primitives/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g==",
"path": "microsoft.extensions.primitives/8.0.0",
"hashPath": "microsoft.extensions.primitives.8.0.0.nupkg.sha512"
},
"CounterStrikeSharp.API/1.0.213.0": {
"type": "reference",
"serviceable": false,
Expand Down
Binary file modified bin/Debug/net8.0/Welcome.dll
Binary file not shown.
Binary file modified bin/Debug/net8.0/Welcome.pdb
Binary file not shown.
4 changes: 2 additions & 2 deletions obj/Debug/net8.0/Welcome.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("Welcome")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3ac752de9a403c40afb7417f5bbe5ff51a13bd6f")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9b51790f8044c57a7d55ed31eeaf74333f33f608")]
[assembly: System.Reflection.AssemblyProductAttribute("Welcome")]
[assembly: System.Reflection.AssemblyTitleAttribute("Welcome")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.
// Создано классом WriteCodeFragment MSBuild.

2 changes: 1 addition & 1 deletion obj/Debug/net8.0/Welcome.AssemblyInfoInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c9f3789666e9fcaa787422d9a78c6663f01c685cd2252860bf145e6a2227e8b2
889d05a55cac142e5ad88f57409803ce9d9e1ccff13a56216ea456317abf0209
Binary file modified obj/Debug/net8.0/Welcome.assets.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net8.0/Welcome.csproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6ce483561d07fedefd8b4ccff19807c3964b5eb3e45949270d98bb3ecb951aaa
8e50a08dea72f54f743f20a8d9df27252ac24fd6f540415d926f3f12c3bab0bc
1 change: 0 additions & 1 deletion obj/Debug/net8.0/Welcome.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ F:\git\Welcome\bin\Debug\net8.0\Welcome.pdb
F:\git\Welcome\bin\Debug\net8.0\CounterStrikeSharp.API.dll
F:\git\Welcome\obj\Debug\net8.0\Welcome.csproj.Up2Date
F:\git\Welcome\obj\Debug\net8.0\ref\Welcome.dll
F:\git\Welcome\bin\Debug\net8.0\GeoLite2-Country.mmdb
Binary file modified obj/Debug/net8.0/Welcome.dll
Binary file not shown.
Binary file modified obj/Debug/net8.0/Welcome.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net8.0/Welcome.sourcelink.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"F:\\git\\Welcome\\*":"https://raw.githubusercontent.com/ZIFON/Welcome/3ac752de9a403c40afb7417f5bbe5ff51a13bd6f/*"}}
{"documents":{"F:\\git\\Welcome\\*":"https://raw.githubusercontent.com/ZIFON/Welcome/9b51790f8044c57a7d55ed31eeaf74333f33f608/*"}}
Binary file modified obj/Debug/net8.0/ref/Welcome.dll
Binary file not shown.
Binary file modified obj/Debug/net8.0/refint/Welcome.dll
Binary file not shown.
8 changes: 0 additions & 8 deletions obj/Welcome.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"MaxMind.Db": {
"target": "Package",
"version": "[4.1.0, )"
},
"MaxMind.GeoIP2": {
"target": "Package",
"version": "[5.2.0, )"
},
"Microsoft.Extensions.Localization.Abstractions": {
"target": "Package",
"version": "[8.0.7, )"
Expand Down
6 changes: 1 addition & 5 deletions obj/Welcome.csproj.nuget.g.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.extensions.options\8.0.0\buildTransitive\net6.0\Microsoft.Extensions.Options.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.options\8.0.0\buildTransitive\net6.0\Microsoft.Extensions.Options.targets')" />
</ImportGroup>
</Project>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
Loading