I'm developing a plugin (ConnectionTools) to control VPN / proxy and Geo Location, but I have some problems: When a player connects, causes the server lag at all, sometimes it is 0.2 sec, and sometimes 2 sec ...
perhaps, by the ping response IPHUB?
some way to do this in the background to avoid this lag to the server ?.
Thank you for reading!!
perhaps, by the ping response IPHUB?
some way to do this in the background to avoid this lag to the server ?.
Thank you for reading!!
C#:
public void OnPlayerConnected(Fougerite.Player player)
{
var ip = player.NetworkPlayer.externalIP;
var nombre = player.Name;
var id = player.SteamID;
// Cear la solicitud de la URL.
HttpWebRequest hRequest = ((HttpWebRequest)WebRequest.Create("http://iphub.info/api.php?ip=" + ip + "&showtype=4"));
hRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Smartphone; 176x220)";
StreamReader reader = new StreamReader(hRequest.GetResponse().GetResponseStream());
string res = reader.ReadToEnd();
//COMPONER LAS VARIABLES
//Ejemplo de el contenido de la variable res {"hostname":"onsnetwork.nl","countryCode":"NL","countryName":"Netherlands","region":"undefined","asn":"AS50673 SERVERIUS-AS","proxy":1}
string info = @"" + res;
string infofinal = info.Replace('"', ' ').Replace('}', ' ');
string[] pares = infofinal.Split(new char[] { ',' });
string hostName = pares[0].Split(new char[] { ':' }).ToArray()[1];
string countryCode = pares[1].Split(new char[] { ':' }).ToArray()[1];
string countryName = pares[2].Split(new char[] { ':' }).ToArray()[1];
string region = pares[3].Split(new char[] { ':' }).ToArray()[1];
string asn = pares[4].Split(new char[] { ':' }).ToArray()[1];
string proxy = pares[5].Split(new char[] { ':' }).ToArray()[1];
/* player.Message("hostName" + " - " + hostName);
player.Message("countryCode" + " - " + countryCode);
player.Message("countryName" + " - " + countryName);
player.Message("region" + " - " + region);
player.Message("asn" + " - " + asn);
player.Message("proxy" + " - " + proxy);
*/
// Mostrarlo.
Server.GetServer().BroadcastFrom("SERVER", player.Name + " has joined the server from: [color #F7BE81]" + countryName);
if (res.ToString().Contains(":1}"))
{
player.Disconnect();
string line = "[" + DateTime.Now + "] *** Proxy: YES" + " - IP: " + ip + " - ID: " + id + " - CODE: " + countryCode + " - CountryName: " + countryName + " - " + nombre;
file = new System.IO.StreamWriter(rutaproxydetection, true);
file.WriteLine(line);
file.Close();
Server.GetServer().BroadcastFrom("INVALID CONNECTION", "[color #F7BE81] The player [color #FFFFFF]" + nombre + "[color #F7BE81] has been kicked from the server - Invalid Network ");
}
if (res.ToString().Contains(":0}"))
{
string line = "[" + DateTime.Now + "] *** Proxy: NO" + " - IP: " + ip + " - ID: " + id + " - CODE: " + countryCode + " - CountryName: " + countryName + " - " + nombre;
file = new System.IO.StreamWriter(rutalog, true);
file.WriteLine(line);
file.Close();
}
// Cerrar el stream abierto.
reader.Close();
}