[Trait("Category", "SkipOnMacOS")] // TODO: revisit running this on the MSFT-hosted MacOS agent public void TestHostInfo() { var utils = new InetUtils(new InetOptions(), GetLogger()); var info = utils.FindFirstNonLoopbackHostInfo(); Assert.NotNull(info.IpAddress); }
public void TestHostInfo() { InetUtils utils = new InetUtils(new InetOptions()); HostInfo info = utils.FindFirstNonLoopbackHostInfo(); Assert.NotNull(info.IpAddress); }
[Trait("Category", "SkipOnMacOS")] // TODO: revisit running this on the MSFT-hosted MacOS agent public void TestGetFirstNonLoopbackAddress() { var utils = new InetUtils(new InetOptions() { UseOnlySiteLocalInterfaces = true }, GetLogger()); Assert.NotNull(utils.FindFirstNonLoopbackAddress()); }
public void TestPreferredNetworksListIsEmpty() { InetOptions properties = new InetOptions(); InetUtils utils = new InetUtils(properties); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1"))); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1"))); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.255.10.1"))); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.0.10.1"))); }
public void TestSiteLocalAddresses() { InetOptions properties = new InetOptions() { UseOnlySiteLocalInterfaces = true }; InetUtils utils = new InetUtils(properties); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1"))); Assert.False(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1"))); }
void mNewsFetcher_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled || mNewsFetcher.CancellationPending) { return; } if (!htmlReader1.IsDisposed) { htmlReader1.WriteHtml(InetUtils.GrabWebpage(URL)); } }
public void TestIgnoreInterface() { InetOptions properties = new InetOptions() { IgnoredInterfaces = "docker0,veth.*" }; InetUtils inetUtils = new InetUtils(properties); Assert.True(inetUtils.IgnoreInterface("docker0")); Assert.True(inetUtils.IgnoreInterface("vethAQI2QT")); Assert.False(inetUtils.IgnoreInterface("docker1")); }
public void TestPreferredNetworksRegex() { InetOptions properties = new InetOptions() { PreferredNetworks = "192.168.*,10.0.*" }; InetUtils utils = new InetUtils(properties); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1"))); Assert.False(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1"))); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.0.10.1"))); Assert.False(utils.IsPreferredAddress(IPAddress.Parse("10.255.10.1"))); }
public void TestPreferredNetworksSimple() { var properties = new InetOptions() { PreferredNetworks = "192,10.0" }; var utils = new InetUtils(properties, GetLogger()); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1"))); Assert.False(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1"))); Assert.False(utils.IsPreferredAddress(IPAddress.Parse("10.255.10.1"))); Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.0.10.1"))); }
void OnOutgoingData(Player p, PacketEventArgs e) { if (e.Type == Packet.Types.MOTD) { string ip; if (Server.DebugMode) { ip = "127.0.0.1"; } else { ip = InetUtils.GrabWebpage("http://www.mcforge.net/serverdata/ip.php"); } Packet pa = new Packet(); pa.Add(Packet.Types.MOTD); pa.Add((byte)7); pa.Add(ServerSettings.GetSetting("ServerName"), 64); pa.Add(ServerSettings.GetSetting("MOTD") + " &0cfg=" + ip + ":" + ServerSettings.GetSetting("Port") + "/" + p.Level.Name, 64); pa.Add((byte)0); e.Data = pa.bytes; } //Because this is way more fun and requires no edits to the core ~Gamemakergm else if (e.Type == Packet.Types.Message) { if (PluginSettings.GetSettingBoolean("joinleave-alert")) { string incoming = Encoding.ASCII.GetString(e.Data).Trim(); //Logger.Log(incoming); if (incoming.Contains("joined the game!")) { e.Cancel(); WOM.GlobalSendJoin(incoming.Substring(1, incoming.Length - incoming.IndexOf("joined the game!"))); } else if (incoming.Contains("has disconnected")) { e.Cancel(); WOM.GlobalSendLeave(incoming.Substring(1, incoming.Length - incoming.IndexOf("has disconnected"))); } } } else { return; } }
protected virtual string GetDefaultHostName() { string temp; try { var inetUtils = new InetUtils(new InetOptions(), _logger); var hostInfo = inetUtils.FindFirstNonLoopbackHostInfo(); temp = hostInfo.Hostname; _logger?.LogDebug("Using hostname [" + temp + "] for hostname."); } catch (Exception e) { _logger?.LogWarning("Could not get host name, using 'localhost' as default value", e); temp = "localhost"; } return(temp); }
internal static void InIt() { #if DEBUG && !UPDATE return; #endif Thread check = new Thread(new ThreadStart(delegate { while (true) { if (InetUtils.CanConnectToInternet()) { Tick(); } Thread.Sleep(checkinterval * 60000); //This could keep the Process open for a long time after closing the program //TODO: ThreadHelper.longsleep(int millis) breaking on severshutdown after checking every 5s } })); check.Start(); Player.OnAllPlayersCommand.SystemLvl += new Event <Player, CommandEventArgs> .EventHandler(OnAllPlayersCommand_SystemLvl); }
/// <summary> /// Determines whether the player has a valid account /// </summary> /// <param name="player">The player.</param> /// <param name="playerKey">The player key.</param> /// <returns> /// <c>true</c> if the player has a valid account; otherwise, <c>false</c>. /// </returns> public static bool IsValidAccount(NewPlayer player, string playerKey) { if (ServerSettings.GetSettingBoolean("offline") || InetUtils.IsLocalIP(player.IP)) { return(true); } while (playerKey.Length < 32) { playerKey = "0" + playerKey; } MD5 hash = MD5.Create(); StringBuilder builder = new StringBuilder(32); foreach (byte b in hash.ComputeHash(Encoding.ASCII.GetBytes(ServerSettings.Salt + player.Username))) { builder.AppendFormat("{0:x2}", b); } return(string.Equals(builder.ToString(), playerKey, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Inits this instance. /// </summary> public static void Init() { Running = true; Logger.WriteLog("--------- Server Started at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " ---------"); Logger.Log("Debug mode started", LogType.Debug); //TODO Add debug messages //TODO load the level if it exists Block.InIt(); Logger.Log("Starting update timer", LogType.Debug); UpdateTimer = new System.Threading.Timer((e) => Update(), null, 0, 100); Logger.Log("Log timer started", LogType.Debug); Logger.Log("Loading DLL's", LogType.Debug); LoadAllDlls.Init(); Logger.Log("Finished loading DLL's", LogType.Debug); Logger.Log("Sending Heartbeat..", LogType.Debug); Logger.Log("Auto-Updater Starting..", LogType.Debug); Updater.InIt(); HeartThread = new Thread(new ThreadStart(Heartbeat.ActivateHeartBeat)); HeartThread.Start(); Logger.Log("Starting Physics Tick..", LogType.Debug); PhysicsBlock.InIt(); CmdReloadCmds reload = new CmdReloadCmds(); reload.Initialize(); Groups.PlayerGroup.Load(); VerifyGroup = Groups.PlayerGroup.Find(ServerSettings.GetSetting("VerifyGroup")); Mainlevel = Level.LoadLevel(ServerSettings.GetSetting("Main-Level")); if (Mainlevel == null) { Mainlevel = Level.CreateLevel(new Vector3S(256, 128, 64), Level.LevelTypes.Flat); ServerSettings.SetSetting("Main-Level", null, "main"); } Level.Levels.Add(Mainlevel); if (ServerSettings.GetSettingBoolean("LoadAllLevels")) { Level.LoadAllLevels(); } BlockQueue.Start(); Backup.StartBackup(); Database.Init(); CreateCoreFiles(); InternetUtils = new InetUtils(); InetUtils.InternetAvailable = InetUtils.CanConnectToInternet(); Logger.Log("Loading Bans", LogType.Debug); Logger.Log("IPBANS", LogType.Debug); IPBans = new List <string>(File.ReadAllLines("bans/IPBans.txt")); Logger.Log("IPBANS", LogType.Debug); UsernameBans = new List <string>(File.ReadAllLines("bans/NameBans.txt")); StartListening(); Started = true; if (OnServerFinishSetup != null) { OnServerFinishSetup(); } blockThread = new Thread(new ThreadStart(delegate { while (true) { Thread.Sleep(60000); Level.Levels.ForEach(delegate(Level l) { try { l.SaveToBinary(); } catch (Exception e) { Logger.LogError(e); } }); } })); blockThread.Start(); Logger.Log("[Important]: Server Started.", Color.Black, Color.White); if (!ServerSettings.GetSettingBoolean("VerifyNames")) { Logger.Log("[Important]: The server is running with verify names off! This could lead to bad things! Please turn on verify names if you dont know the risk and dont want these bad things to happen!", LogType.Critical); } if (ServerSettings.GetSettingBoolean("IRC-Enabled")) { try { IRC = new ServerChat(); IRC.Connect(); } catch (Exception e) { Logger.LogError(e); } } if (ServerSettings.GetSettingBoolean("GC-Enabled")) { GC = new GlobalChat(); try { GC.Connect(); } catch (Exception e) { Logger.LogError(e); } } try { RC = new ConsoleListener(); RC.Start(); } catch { } PlayerConnectionTimeoutChecker = new Thread(() => { int sleep = ServerSettings.GetSettingInt("AutoTimeout"); if (sleep < 0) { sleep = 30; } if (sleep != 0) { while (Running) { for (int i = 0; i < sleep && Running; i++) { Thread.Sleep(1000); } if (!Running) { break; } foreach (Player p in Players) { if (p.lastReceived.AddSeconds(sleep) < DateTime.Now) { #if !DEBUG p.Kick("The connection timed out"); #endif } } } } }); PlayerConnectionTimeoutChecker.Start(); }
[Trait("Category", "SkipOnMacOS")] // TODO: revisit running this on the MSFT-hosted MacOS agent public void TestGetFirstNonLoopbackHostInfo() { var utils = new InetUtils(new InetOptions(), GetLogger()); Assert.NotNull(utils.FindFirstNonLoopbackHostInfo()); }
public void TestDefaultIgnoreInterface() { InetUtils inetUtils = new InetUtils(new InetOptions()); Assert.False(inetUtils.IgnoreInterface("docker0")); }
public void TestGetFirstNonLoopbackAddress() { InetUtils utils = new InetUtils(new InetOptions()); Assert.NotNull(utils.FindFirstNonLoopbackAddress()); }
public void TestConvert() { InetUtils utils = new InetUtils(new InetOptions()); Assert.NotNull(utils.ConvertAddress(Dns.GetHostEntry("localhost").AddressList[0])); }