2017-05-26 18:49:27 -04:00
|
|
|
|
using System;
|
|
|
|
|
using SharedLibrary;
|
2017-06-07 17:08:29 -04:00
|
|
|
|
using System.Collections.Generic;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
using SharedLibrary.Interfaces;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2017-06-07 17:08:29 -04:00
|
|
|
|
using SharedLibrary.Network;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
using SharedLibrary.Objects;
|
2018-02-11 20:17:20 -05:00
|
|
|
|
using SharedLibrary.Helpers;
|
2017-06-07 17:08:29 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
namespace Welcome_Plugin
|
|
|
|
|
{
|
|
|
|
|
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";
|
2018-02-11 20:17:20 -05:00
|
|
|
|
/* case 100:
|
2017-06-12 17:47:31 -04:00
|
|
|
|
return "One-Hundreth (amazing!)";
|
|
|
|
|
case 500:
|
|
|
|
|
return "you're really ^5dedicated ^7to this server! This is your ^5500th^7";
|
|
|
|
|
case 1000:
|
2018-02-11 20:17:20 -05:00
|
|
|
|
return "you deserve a medal. it's your ^11000th^7";*/
|
2017-06-12 17:47:31 -04:00
|
|
|
|
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-02-11 20:17:20 -05:00
|
|
|
|
private Dictionary<int, ConfigurationManager> Configs;
|
|
|
|
|
|
2017-10-16 23:47:41 -04:00
|
|
|
|
public async Task OnLoadAsync(IManager manager)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-02-11 20:17:20 -05:00
|
|
|
|
await Task.FromResult(Configs = new Dictionary<int, ConfigurationManager>());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
public async Task OnUnloadAsync()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 18:08:04 -04:00
|
|
|
|
public async Task OnTickAsync(Server S)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 18:08:04 -04:00
|
|
|
|
public async Task OnEventAsync(Event E, Server S)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
if (E.Type == Event.GType.Connect)
|
|
|
|
|
{
|
|
|
|
|
Player newPlayer = E.Origin;
|
2018-02-11 20:17:20 -05:00
|
|
|
|
var cfg = Configs[S.GetHashCode()];
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (newPlayer.Level >= Player.Permission.Trusted && !E.Origin.Masked)
|
2018-02-11 20:17:20 -05:00
|
|
|
|
await E.Owner.Broadcast(ProcessAnnouncement(cfg.GetProperty<string>("PrivilegedAnnouncementMessage"), newPlayer));
|
2017-05-28 21:07:33 -04:00
|
|
|
|
|
2018-02-11 20:17:20 -05:00
|
|
|
|
await newPlayer.Tell(ProcessAnnouncement(cfg.GetProperty<string>("UserWelcomeMessage"), newPlayer));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (newPlayer.Level == Player.Permission.Flagged)
|
2018-02-15 23:01:28 -05:00
|
|
|
|
await E.Owner.ToAdmins($"^1NOTICE: ^7Flagged player ^5{newPlayer.Name} ^7has joined!");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
else
|
2018-02-11 20:17:20 -05:00
|
|
|
|
await E.Owner.Broadcast(ProcessAnnouncement(cfg.GetProperty<string>("UserAnnouncementMessage"), newPlayer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == Event.GType.Start)
|
|
|
|
|
{
|
|
|
|
|
var cfg = new ConfigurationManager(S);
|
|
|
|
|
Configs.Add(S.GetHashCode(), cfg);
|
|
|
|
|
if (cfg.GetProperty<string>("UserWelcomeMessage") == null)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-02-11 20:17:20 -05:00
|
|
|
|
string welcomeMsg = "Welcome ^5{{ClientName}}^7, this is your ^5{{TimesConnected}} ^7time connecting!";
|
|
|
|
|
cfg.AddProperty(new KeyValuePair<string, dynamic>("UserWelcomeMessage", welcomeMsg));
|
|
|
|
|
}
|
2017-05-27 19:29:20 -04:00
|
|
|
|
|
2018-02-11 20:17:20 -05:00
|
|
|
|
if (cfg.GetProperty<string>("PrivilegedAnnouncementMessage") == null)
|
|
|
|
|
{
|
|
|
|
|
string annoucementMsg = "{{ClientLevel}} {{ClientName}} has joined the server";
|
|
|
|
|
cfg.AddProperty(new KeyValuePair<string, dynamic>("PrivilegedAnnouncementMessage", annoucementMsg));
|
|
|
|
|
}
|
2017-06-07 17:08:29 -04:00
|
|
|
|
|
2018-02-11 20:17:20 -05:00
|
|
|
|
if (cfg.GetProperty<string>("UserAnnouncementMessage") == null)
|
|
|
|
|
{
|
2018-02-15 23:01:28 -05:00
|
|
|
|
string annoucementMsg = "^5{{ClientName}} ^7hails from ^5{{ClientLocation}}";
|
2018-02-11 20:17:20 -05:00
|
|
|
|
cfg.AddProperty(new KeyValuePair<string, dynamic>("UserAnnouncementMessage", annoucementMsg));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
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);
|
|
|
|
|
msg = msg.Replace("{{ClientLevel}}", Utilities.ConvertLevelToColor(joining.Level));
|
|
|
|
|
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-02-11 20:17:20 -05: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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|