diff --git a/Application/Application.csproj b/Application/Application.csproj
index 15acd3da7..f6d81e0fe 100644
--- a/Application/Application.csproj
+++ b/Application/Application.csproj
@@ -6,7 +6,7 @@
2.1.5
false
RaidMax.IW4MAdmin.Application
- 2.1.9.5
+ 2.1.9.6
RaidMax
Forever None
IW4MAdmin
@@ -31,8 +31,8 @@
true
true
- 2.1.9.5
- 2.1.9.5
+ 2.1.9.6
+ 2.1.9.6
diff --git a/Application/RconParsers/T6MRConParser.cs b/Application/RconParsers/T6MRConParser.cs
index 86efa74de..6a26d599d 100644
--- a/Application/RconParsers/T6MRConParser.cs
+++ b/Application/RconParsers/T6MRConParser.cs
@@ -9,8 +9,6 @@ using SharedLibraryCore.Objects;
using SharedLibraryCore.RCon;
using SharedLibraryCore.Exceptions;
using System.Text;
-using System.Linq;
-using System.Net.Http;
namespace IW4MAdmin.Application.RconParsers
{
diff --git a/Application/Server.cs b/Application/Server.cs
index 7568a44df..42419989b 100644
--- a/Application/Server.cs
+++ b/Application/Server.cs
@@ -966,7 +966,6 @@ namespace IW4MAdmin
Offender = Target,
Offense = Reason,
Punisher = Origin,
- Active = true,
When = DateTime.UtcNow,
Link = Target.AliasLink
};
diff --git a/Plugins/Welcome/MaxMind/CountryLookup.cs b/Plugins/Welcome/MaxMind/CountryLookup.cs
deleted file mode 100644
index 63e3d7220..000000000
--- a/Plugins/Welcome/MaxMind/CountryLookup.cs
+++ /dev/null
@@ -1,142 +0,0 @@
-/* CountryLookup.cs
- *
- * Copyright (C) 2008 MaxMind, Inc. All Rights Reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-using SharedLibraryCore;
-using System;
-using System.IO;
-using System.Net;
-
-
-namespace CountryLookupProj
-{
- ///
- /// Summary description for CountryLookup.
- ///
- public class CountryLookup
- {
- private FileStream fileInput;
- private static long COUNTRY_BEGIN = 16776960;
- private static string[] countryCode =
- { "--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR","AS","AT","AU","AW","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BM","BN","BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ",
- "EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","FX","GA","GB","GD","GE","GF","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ",
- "LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA",
- "RE","RO","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TM","TN","TO","TL","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","RS","ZA","ZM","ME","ZW","A1","A2",
- "O1","AX","GG","IM","JE","BL","MF"
- };
- private static string[] countryName =
- {"a third world country","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Netherlands Antilles","Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan","Bosnia and Herzegovina","Barbados","Bangladesh","Belgium",
- "Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Bermuda","Brunei Darussalam","Bolivia","Brazil","Bahamas","Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos (Keeling) Islands","Congo, The Democratic Republic of the","Central African Republic","Congo","Switzerland","Cote D'Ivoire",
- "Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica","Cuba","Cape Verde","Christmas Island","Cyprus","Czech Republic","Germany","Djibouti","Denmark","Dominica","Dominican Republic","Algeria","Ecuador","Estonia","Egypt","Western Sahara","Eritrea","Spain","Ethiopia","Finland","Fiji","Falkland Islands (Malvinas)",
- "Micronesia, Federated States of","Faroe Islands","France","France, Metropolitan","Gabon","United Kingdom","Grenada","Georgia","French Guiana","Ghana","Gibraltar","Greenland","Gambia","Guinea","Guadeloupe","Equatorial Guinea","Greece","South Georgia and the South Sandwich Islands","Guatemala","Guam","Guinea-Bissau","Guyana",
- "Hong Kong","Heard Island and McDonald Islands","Honduras","Croatia","Haiti","Hungary","Indonesia","Ireland","Israel","India","British Indian Ocean Territory","Iraq","Iran, Islamic Republic of","Iceland","Italy","Jamaica","Jordan","Japan","Kenya","Kyrgyzstan","Cambodia","Kiribati","Comoros","Saint Kitts and Nevis",
- "Korea, Democratic People's Republic of","Korea, Republic of","Kuwait","Cayman Islands","Kazakstan","Lao People's Democratic Republic","Lebanon","Saint Lucia","Liechtenstein","Sri Lanka","Liberia","Lesotho","Lithuania","Luxembourg","Latvia","Libyan Arab Jamahiriya","Morocco","Monaco","Moldova, Republic of","Madagascar",
- "Marshall Islands","Macedonia","Mali","Myanmar","Mongolia","Macau","Northern Mariana Islands","Martinique","Mauritania","Montserrat","Malta","Mauritius","Maldives","Malawi","Mexico","Malaysia","Mozambique","Namibia","New Caledonia","Niger","Norfolk Island","Nigeria","Nicaragua","Netherlands",
- "Norway","Nepal","Nauru","Niue","New Zealand","Oman","Panama","Peru","French Polynesia","Papua New Guinea","Philippines","Pakistan","Poland","Saint Pierre and Miquelon","Pitcairn Islands","Puerto Rico","Palestinian Territory","Portugal","Palau","Paraguay","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saudi Arabia",
- "Solomon Islands","Seychelles","Sudan","Sweden","Singapore","Saint Helena","Slovenia","Svalbard and Jan Mayen","Slovakia","Sierra Leone","San Marino","Senegal","Somalia","Suriname","Sao Tome and Principe","El Salvador","Syrian Arab Republic","Swaziland","Turks and Caicos Islands","Chad","French Southern Territories","Togo",
- "Thailand","Tajikistan","Tokelau","Turkmenistan","Tunisia","Tonga","Timor-Leste","Turkey","Trinidad and Tobago","Tuvalu","Taiwan","Tanzania, United Republic of","Ukraine","Uganda","United States Minor Outlying Islands","United States","Uruguay","Uzbekistan","Holy See (Vatican City State)","Saint Vincent and the Grenadines",
- "Venezuela","Virgin Islands, British","Virgin Islands, U.S.","Vietnam","Vanuatu","Wallis and Futuna","Samoa","Yemen","Mayotte","Serbia","South Africa","Zambia","Montenegro","Zimbabwe","Anonymous Proxy","Satellite Provider",
- "Other","Aland Islands","Guernsey","Isle of Man","Jersey","Saint Barthelemy","Saint Martin"};
-
-
- public CountryLookup(string fileName)
- {
- fileInput = new FileStream(fileName, FileMode.Open, FileAccess.Read);
- }
-
- private long AddrToNum(IPAddress addr)
- {
- long ipnum = 0;
- byte[] b = BitConverter.GetBytes((UInt32)addr.ToString().ConvertToIP());
- for (int i = 0; i < 4; ++i)
- {
- long y = b[i];
- if (y < 0)
- {
- y += 256;
- }
- ipnum += y << ((3 - i) * 8);
- }
- return ipnum;
- }
-
- public string LookupCountryCode(IPAddress addr)
- {
- return (countryCode[(int)SeekCountry(0, AddrToNum(addr), 31)]);
- }
-
- public string LookupCountryName(string str)
- {
- IPAddress addr;
- try
- {
- addr = IPAddress.Parse(str);
- }
- catch (FormatException)
- {
- return "a third world country";
- }
- return LookupCountryName(addr);
- }
-
- public string LookupCountryName(IPAddress addr)
- {
- return (countryName[(int)SeekCountry(0, AddrToNum(addr), 31)]);
- }
-
- private long SeekCountry(long offset, long ipnum, int depth)
- {
- byte[] buf = new byte[6];
- long[] x = new long[2];
-
- fileInput.Seek(6 * offset, 0);
- fileInput.Read(buf, 0, 6);
-
- for (int i = 0; i < 2; i++)
- {
- x[i] = 0;
- for (int j = 0; j < 3; j++)
- {
- int y = buf[i * 3 + j];
- if (y < 0)
- {
- y += 256;
- }
- x[i] += (y << (j * 8));
- }
- }
-
- if ((ipnum & (1 << depth)) > 0)
- {
- if (x[1] >= COUNTRY_BEGIN)
- {
- return x[1] - COUNTRY_BEGIN;
- }
- return SeekCountry(x[1], ipnum, depth - 1);
- }
- else
- {
- if (x[0] >= COUNTRY_BEGIN)
- {
- return x[0] - COUNTRY_BEGIN;
- }
- return SeekCountry(x[0], ipnum, depth - 1);
- }
- }
- }
-}
diff --git a/Plugins/Welcome/MaxMind/GeoIP.dat b/Plugins/Welcome/MaxMind/GeoIP.dat
deleted file mode 100644
index be8b031f7..000000000
Binary files a/Plugins/Welcome/MaxMind/GeoIP.dat and /dev/null differ
diff --git a/Plugins/Welcome/Plugin.cs b/Plugins/Welcome/Plugin.cs
index e94de5dd4..6de871050 100644
--- a/Plugins/Welcome/Plugin.cs
+++ b/Plugins/Welcome/Plugin.cs
@@ -10,6 +10,9 @@ using SharedLibraryCore.Database.Models;
using System.Linq;
using SharedLibraryCore.Database;
using Microsoft.EntityFrameworkCore;
+using System.Net;
+using Newtonsoft.Json.Linq;
+using System.Text.RegularExpressions;
namespace IW4MAdmin.Plugins.Welcome
{
@@ -84,9 +87,9 @@ namespace IW4MAdmin.Plugins.Welcome
{
Player newPlayer = E.Origin;
if (newPlayer.Level >= Player.Permission.Trusted && !E.Origin.Masked)
- E.Owner.Broadcast(ProcessAnnouncement(Config.Configuration().PrivilegedAnnouncementMessage, newPlayer));
+ E.Owner.Broadcast(await ProcessAnnouncement(Config.Configuration().PrivilegedAnnouncementMessage, newPlayer));
- newPlayer.Tell(ProcessAnnouncement(Config.Configuration().UserWelcomeMessage, newPlayer));
+ newPlayer.Tell(await ProcessAnnouncement(Config.Configuration().UserWelcomeMessage, newPlayer));
if (newPlayer.Level == Player.Permission.Flagged)
{
@@ -101,30 +104,49 @@ namespace IW4MAdmin.Plugins.Welcome
.FirstOrDefaultAsync();
}
- E.Owner.ToAdmins($"^1NOTICE: ^7Flagged player ^5{newPlayer.Name} ^7({penaltyReason}) has joined!");
+ E.Owner.ToAdmins($"^1NOTICE: ^7Flagged player ^5{newPlayer.Name} ^7({penaltyReason}) has joined!");
}
else
- E.Owner.Broadcast(ProcessAnnouncement(Config.Configuration().UserAnnouncementMessage, newPlayer));
+ E.Owner.Broadcast(await ProcessAnnouncement(Config.Configuration().UserAnnouncementMessage, newPlayer));
}
}
- private string ProcessAnnouncement(string msg, Player joining)
+ private async Task ProcessAnnouncement(string msg, Player joining)
{
msg = msg.Replace("{{ClientName}}", joining.Name);
msg = msg.Replace("{{ClientLevel}}", Utilities.ConvertLevelToColor(joining.Level, joining.ClientPermission.Name));
- try
+ // this prevents it from trying to evaluate it every message
+ if (msg.Contains("{{ClientLocation}}"))
{
- CountryLookupProj.CountryLookup CLT = new CountryLookupProj.CountryLookup($"{Utilities.OperatingDirectory}Plugins{System.IO.Path.DirectorySeparatorChar}GeoIP.dat");
- msg = msg.Replace("{{ClientLocation}}", CLT.LookupCountryName(joining.IPAddressString));
- }
-
- catch (Exception)
- {
- joining.CurrentServer.Logger.WriteError("Could not open file Plugins\\GeoIP.dat for Welcome Plugin");
+ msg = msg.Replace("{{ClientLocation}}", await GetCountryName(joining.IPAddressString));
}
msg = msg.Replace("{{TimesConnected}}", TimesConnected(joining));
return msg;
}
+
+ ///
+ /// makes a webrequest to determine IP origin
+ ///
+ /// IP address to get location of
+ ///
+ private async Task GetCountryName(string ip)
+ {
+ using (var wc = new WebClient())
+ {
+ try
+ {
+ string response = await wc.DownloadStringTaskAsync(new Uri($"http://extreme-ip-lookup.com/json/{ip}"));
+ var responseObj = JObject.Parse(response);
+
+ return responseObj["country"].ToString();
+ }
+
+ catch
+ {
+ return "a third world country";
+ }
+ }
+ }
}
}
diff --git a/Plugins/Welcome/Welcome.csproj b/Plugins/Welcome/Welcome.csproj
index 808c406b0..66dac03e9 100644
--- a/Plugins/Welcome/Welcome.csproj
+++ b/Plugins/Welcome/Welcome.csproj
@@ -19,18 +19,12 @@
-
-
- Never
-
-
-
-
+
diff --git a/SharedLibraryCore/Events/GameEvent.cs b/SharedLibraryCore/Events/GameEvent.cs
index 3cc639957..c59e55187 100644
--- a/SharedLibraryCore/Events/GameEvent.cs
+++ b/SharedLibraryCore/Events/GameEvent.cs
@@ -220,7 +220,8 @@ namespace SharedLibraryCore
{
return (queuedEvent.Target != null && queuedEvent.Target.ClientNumber != -1) &&
(queuedEvent.Target.State != Player.ClientState.Connected &&
- queuedEvent.Target.NetworkId != 0);
+ queuedEvent.Target.NetworkId != 0 &&
+ queuedEvent.Origin?.ClientId != 1);
}
}
}
diff --git a/SharedLibraryCore/File.cs b/SharedLibraryCore/File.cs
deleted file mode 100644
index 7be05c67f..000000000
--- a/SharedLibraryCore/File.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using System.Net;
-using System.Net.Http;
-using System.Threading.Tasks;
-using System.Linq;
-
-namespace SharedLibraryCore
-{
- public class RemoteFile : IFile
- {
- readonly string Location;
- string[] FileCache = new string[0];
-
- public RemoteFile(string location) : base(string.Empty)
- {
- Location = location;
- }
-
- private void Retrieve()
- {
- using (var cl = new HttpClient())
- FileCache = cl.GetStringAsync(Location).Result.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- }
-
- public override long Length()
- {
- Retrieve();
- return FileCache.Sum(l => l.Length);
- }
-
- public override Task Tail(int lineCount)
- {
- return Task.FromResult(FileCache);
- }
-
- }
-
- public class IFile
- {
- public IFile(String fileName)
- {
- if (fileName != string.Empty)
- {
- Name = fileName;
- Handle = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true), Utilities.EncodingType);
-
- sze = Handle.BaseStream.Length;
- }
- }
-
- public virtual long Length()
- {
- sze = Handle.BaseStream.Length;
- return sze;
- }
-
- public void Close()
- {
- Handle?.Close();
- }
-
- public String[] ReadAllLines()
- {
- return Handle?.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
- }
-
- public String GetText()
- {
- return Handle?.ReadToEnd();
- }
-
- public virtual async Task Tail(int lineCount)
- {
- var buffer = new List(lineCount);
- string line;
- for (int i = 0; i < lineCount; i++)
- {
- line = await Handle.ReadLineAsync();
- if (line == null) return buffer.ToArray();
- buffer.Add(line);
- }
-
- int lastLine = lineCount - 1; //The index of the last line read from the buffer. Everything > this index was read earlier than everything <= this indes
-
- while (null != (line = await Handle.ReadLineAsync()))
- {
- lastLine++;
- if (lastLine == lineCount) lastLine = 0;
- buffer[lastLine] = line;
- }
-
- if (lastLine == lineCount - 1) return buffer.ToArray();
- var retVal = new string[lineCount];
- buffer.CopyTo(lastLine + 1, retVal, 0, lineCount - lastLine - 1);
- buffer.CopyTo(0, retVal, lineCount - lastLine - 1, lastLine + 1);
- return retVal;
- }
- //END
-
- private long sze;
- private readonly String Name;
- private StreamReader Handle;
- }
-}
diff --git a/SharedLibraryCore/RCon/Connection.cs b/SharedLibraryCore/RCon/Connection.cs
index d362da7ae..90f4f991f 100644
--- a/SharedLibraryCore/RCon/Connection.cs
+++ b/SharedLibraryCore/RCon/Connection.cs
@@ -95,6 +95,7 @@ namespace SharedLibraryCore.RCon
Ttl = 42,
ExclusiveAddressUse = true,
};
+
connectionState.OnSentData.Reset();
connectionState.OnReceivedData.Reset();
connectionState.ConnectionAttempts++;
@@ -103,7 +104,7 @@ namespace SharedLibraryCore.RCon
#endif
try
{
- response = await SendPayloadAsync(payload);
+ response = await SendPayloadAsync(payload, waitForResponse);
connectionState.OnComplete.Release(1);
connectionState.ConnectionAttempts = 0;
}
@@ -139,7 +140,7 @@ namespace SharedLibraryCore.RCon
return splitResponse;
}
- private async Task SendPayloadAsync(byte[] payload)
+ private async Task SendPayloadAsync(byte[] payload, bool waitForResponse)
{
var connectionState = ActiveQueries[this.Endpoint];
var rconSocket = (Socket)connectionState.SendEventArgs.UserToken;
@@ -171,6 +172,11 @@ namespace SharedLibraryCore.RCon
}
}
+ if (!waitForResponse)
+ {
+ return new byte[0];
+ }
+
connectionState.ReceiveEventArgs.SetBuffer(connectionState.ReceiveBuffer);
// get our response back
diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs
index 0488bd7b8..e7924c8f5 100644
--- a/SharedLibraryCore/Server.cs
+++ b/SharedLibraryCore/Server.cs
@@ -321,7 +321,6 @@ namespace SharedLibraryCore
protected int ConnectionErrors;
protected List BroadcastMessages;
protected TimeSpan LastMessage;
- protected IFile LogFile;
protected DateTime LastPoll;
protected ManualResetEventSlim OnRemoteCommandResponse;
diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs
index 2e0177ce0..85eafe294 100644
--- a/SharedLibraryCore/Services/PenaltyService.cs
+++ b/SharedLibraryCore/Services/PenaltyService.cs
@@ -24,7 +24,6 @@ namespace SharedLibraryCore.Services
PunisherId = newEntity.Punisher.ClientId,
LinkId = newEntity.Link.AliasLinkId,
Type = newEntity.Type,
- Active = true,
Expires = newEntity.Expires,
Offense = newEntity.Offense,
When = newEntity.When,
@@ -69,19 +68,7 @@ namespace SharedLibraryCore.Services
public async Task> Find(Func expression)
{
throw await Task.FromResult(new Exception());
- /*
- return await Task.FromResult(new List());
- // fixme: this is so slow!
- return await Task.Run(() =>
- {
- using (var context = new DatabaseContext())
- return context.Penalties
- .Include(p => p.Offender)
- .Include(p => p.Punisher)
- .Where(expression)
- .Where(p => p.Active)
- .ToList();
- });*/
+
}
public Task Get(int entityID)
@@ -225,8 +212,6 @@ namespace SharedLibraryCore.Services
return list;
}
-
-
}
}
diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs
index 4e86d8e1e..a99b0b2fc 100644
--- a/SharedLibraryCore/Utilities.cs
+++ b/SharedLibraryCore/Utilities.cs
@@ -27,7 +27,13 @@ namespace SharedLibraryCore
#endif
public static Encoding EncodingType;
public static Localization.Layout CurrentLocalization = new Localization.Layout(new Dictionary());
- public static Player IW4MAdminClient(Server server = null) => new Player() { ClientId = 1, Level = Player.Permission.Console, CurrentServer = server };
+ public static Player IW4MAdminClient(Server server = null) => new Player()
+ {
+ ClientId = 1,
+ State = Player.ClientState.Connected,
+ Level = Player.Permission.Console,
+ CurrentServer = server
+ };
public static string HttpRequest(string location, string header, string headerValue)
{