2017-05-26 18:49:27 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-04-09 15:17:10 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using System.Linq;
|
2017-06-07 17:08:29 -04:00
|
|
|
|
|
2018-04-09 15:17:10 -04:00
|
|
|
|
namespace IW4MAdmin.Plugins.Welcome
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
public class Plugin : IPlugin
|
|
|
|
|
{
|
2017-06-12 17:47:31 -04:00
|
|
|
|
String TimesConnected(Player P)
|
|
|
|
|
{
|
|
|
|
|
int connection = P.Connections;
|
|
|
|
|
String Prefix = String.Empty;
|
|
|
|
|
if (connection % 10 > 3 || connection % 10 == 0 || (connection % 100 > 9 && connection % 100 < 19))
|
|
|
|
|
Prefix = "th";
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (connection % 10)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
Prefix = "st";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
Prefix = "nd";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
Prefix = "rd";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (connection)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
case 1:
|
|
|
|
|
return "first";
|
|
|
|
|
case 2:
|
|
|
|
|
return "second";
|
|
|
|
|
case 3:
|
|
|
|
|
return "third";
|
|
|
|
|
case 4:
|
|
|
|
|
return "fourth";
|
|
|
|
|
case 5:
|
|
|
|
|
return "fifth";
|
|
|
|
|
default:
|
|
|
|
|
return connection.ToString() + Prefix;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 16:04:13 -05:00
|
|
|
|
public string Author => "RaidMax";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-11-15 16:04:13 -05:00
|
|
|
|
public float Version => 1.0f;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-11-15 16:04:13 -05:00
|
|
|
|
public string Name => "Welcome Plugin";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2018-03-18 22:25:11 -04:00
|
|
|
|
private BaseConfigurationHandler<WelcomeConfiguration> Config;
|
2018-02-11 20:17:20 -05:00
|
|
|
|
|
2017-10-16 23:47:41 -04:00
|
|
|
|
public async Task OnLoadAsync(IManager manager)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-03-18 22:25:11 -04:00
|
|
|
|
// load custom configuration
|
|
|
|
|
Config = new BaseConfigurationHandler<WelcomeConfiguration>("WelcomePluginSettings");
|
|
|
|
|
if (Config.Configuration() == null)
|
|
|
|
|
{
|
|
|
|
|
Config.Set((WelcomeConfiguration)new WelcomeConfiguration().Generate());
|
|
|
|
|
await Config.Save();
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public Task OnUnloadAsync() => Task.CompletedTask;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public Task OnTickAsync(Server S) => Task.CompletedTask;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public async Task OnEventAsync(GameEvent E, Server S)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-04-13 02:32:30 -04:00
|
|
|
|
if (E.Type == GameEvent.EventType.Connect)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
Player newPlayer = E.Origin;
|
|
|
|
|
if (newPlayer.Level >= Player.Permission.Trusted && !E.Origin.Masked)
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Owner.Broadcast(ProcessAnnouncement(Config.Configuration().PrivilegedAnnouncementMessage, newPlayer));
|
2017-05-28 21:07:33 -04:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
newPlayer.Tell(ProcessAnnouncement(Config.Configuration().UserWelcomeMessage, newPlayer));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (newPlayer.Level == Player.Permission.Flagged)
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
|
|
|
|
var penalty = await new GenericRepository<EFPenalty>().FindAsync(p => p.OffenderId == newPlayer.ClientId && p.Type == Penalty.PenaltyType.Flag);
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Owner.ToAdmins($"^1NOTICE: ^7Flagged player ^5{newPlayer.Name} ^7({penalty.FirstOrDefault()?.Offense}) has joined!");
|
2018-04-13 02:32:30 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
else
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Owner.Broadcast(ProcessAnnouncement(Config.Configuration().UserAnnouncementMessage, newPlayer));
|
2017-06-07 17:08:29 -04:00
|
|
|
|
}
|
2018-02-11 20:17:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string ProcessAnnouncement(string msg, Player joining)
|
|
|
|
|
{
|
|
|
|
|
msg = msg.Replace("{{ClientName}}", joining.Name);
|
2018-08-03 22:11:58 -04:00
|
|
|
|
msg = msg.Replace("{{ClientLevel}}", Utilities.ConvertLevelToColor(joining.Level, joining.ClientPermission.Name));
|
2018-02-11 20:17:20 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
CountryLookupProj.CountryLookup CLT = new CountryLookupProj.CountryLookup($"{Utilities.OperatingDirectory}Plugins{System.IO.Path.DirectorySeparatorChar}GeoIP.dat");
|
2018-02-27 22:27:23 -05:00
|
|
|
|
msg = msg.Replace("{{ClientLocation}}", CLT.LookupCountryName(joining.IPAddressString));
|
2018-02-11 20:17:20 -05:00
|
|
|
|
}
|
2017-06-07 17:08:29 -04:00
|
|
|
|
|
2018-02-11 20:17:20 -05:00
|
|
|
|
catch (Exception)
|
2017-06-07 17:08:29 -04:00
|
|
|
|
{
|
2018-04-09 15:17:10 -04:00
|
|
|
|
joining.CurrentServer.Manager.GetLogger().WriteError("Could not open file Plugins\\GeoIP.dat for Welcome Plugin");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2018-02-11 20:17:20 -05:00
|
|
|
|
msg = msg.Replace("{{TimesConnected}}", TimesConnected(joining));
|
|
|
|
|
|
|
|
|
|
return msg;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|