/// <summary>
        /// Runs the server pinger
        /// </summary>
        /// <returns>True if the server is reachable</returns>
        public bool Ping()
        {
            // todo: don't block the UI thread while it's pinging
            var pingButton = _view.FindViewById <Button>(Resource.Id.PingButton);
            var motdBox    = _view.FindViewById <WebView>(Resource.Id.ServerMotd);

            pingButton.Enabled = false;

            _pinger = new MinecraftPinger(Address, Port);
            var status = Task.Factory.StartNew(Loop).Result.Result;

            if (!status.Equals("Success"))
            {
                var error = $"<html><body><strong>Error: </strong>{status}</body></html>";
                motdBox.LoadData(error, "text/html; charset=utf-8", "UTF-8");
                pingButton.Enabled = true;
                return(false);
            }

            // convert the favicon from a Base64 PNG to an Image object
            // the first 22 characters are cut off as they're not a part of the image
            try {
                var icon = _view.FindViewById <ImageView>(Resource.Id.ServerIcon);
                if (_serverStatus.Favicon.Length > 22)
                {
                    var data = Convert.FromBase64String(_serverStatus.Favicon[22..]);
예제 #2
0
        public static void Main(string[] args)
        {
            IMinecraftPinger pinger = new MinecraftPinger("play.minesuperior.com", 25565);

            Task.Run(async() =>
            {
                while (true)
                {
                    var status = await pinger.RequestAsync();

                    Console.WriteLine(status.Players.Online + " people online");

                    Task.Delay(1000).Wait();
                }
            }).Wait();
        }
예제 #3
0
        private void FTBProcess()
        {
            MinecraftPinger feedthebeast = new MinecraftPinger(ServerAdress, 25565, "Minecraft Feed The Beast");

            do
            {
                FTBState = feedthebeast.Ping();

                if (CanRun)
                {
                    Form.SetFTBState(FTBState);
                }

                Debug.WriteLine("FTB FINIS : " + FTBState);
                Thread.Sleep(FTBTimer * 1000);
            } while (CanRun);
        }
예제 #4
0
        private void VanillaProcess()
        {
            MinecraftPinger vanilla = new MinecraftPinger(ServerAdress, 25566, "Minecraft Vanilla");

            do
            {
                VanillaState = vanilla.Ping();

                if (CanRun)
                {
                    Form.SetVanillaState(VanillaState);
                }

                Debug.WriteLine("VANILLA FINIS : " + VanillaState);
                Thread.Sleep(VanillaTimer * 1000);
            } while (CanRun);
        }
예제 #5
0
        private static async Task <string> StartMonitoring()
        {
            try
            {
                MinecraftPinger mcServerStatus  = new MinecraftPinger("13.75.221.179", 25565);
                Status          minecraftStatus = await mcServerStatus.PingAsync();


                var monitorMessage = $"mcnumplayers={minecraftStatus.Players.Online}, " +
                                     $"mccapacity={minecraftStatus.Players.Max}, " +
                                     $"mcpopulation={minecraftStatus.Players?.Sample?.Count}";

                return(monitorMessage);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Exception: {exception.Message}, Deails:{exception.StackTrace}");
                return(string.Empty);
            }
        }