コード例 #1
0
        public void FromByteArray_Returns_Expected_Data()
        {
            var msg = new MessageBuilder()
                      .WriteCode(MessageCode.Server.Ping)
                      .Build();

            var ex = Record.Exception(() => ServerPing.FromByteArray(msg));

            Assert.Null(ex);
        }
コード例 #2
0
        public void ToByteArray_Constructs_The_Correct_Message()
        {
            var msg = new ServerPing().ToByteArray();

            var reader = new MessageReader <MessageCode.Server>(msg);
            var code   = reader.ReadCode();

            Assert.Equal(MessageCode.Server.Ping, code);
            Assert.Equal(8, msg.Length);
        }
コード例 #3
0
        public void FromByteArray_Throws_MessageException_On_Code_Mismatch()
        {
            var msg = new MessageBuilder()
                      .WriteCode(MessageCode.Server.BranchLevel)
                      .WriteInteger(1)
                      .Build();

            var ex = Record.Exception(() => ServerPing.FromByteArray(msg));

            Assert.NotNull(ex);
            Assert.IsType <MessageException>(ex);
        }
コード例 #4
0
        private static void MessageHandler(ushort obj1, byte[] obj2, ulong obj3, bool obj4)
        {
            try
            {
                ClientMessage Recieved = Utilities.Utility.Deserialize <ClientMessage>(obj2);
                if (Recieved.MessageType == ClientMessageType.TransferServer)
                {
                    Transfer TransferMessage = Recieved.GetTransferData();

                    ServerPing.StartServerPing(TransferMessage);
                }
            }
            catch (Exception ex)
            {
                TryShow(ex.ToString());
            }
        }
コード例 #5
0
ファイル: server.cs プロジェクト: kleopatra999/chronojump
    /*
     * private static string getIP() {
     *      string strHostName = "";
     *      strHostName = System.Net.Dns.GetHostName();
     *      IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
     *      IPAddress[] addr = ipEntry.AddressList;
     *      return addr[addr.Length-1].ToString();
     * }
     */

    public static string Ping(bool doInsertion, string progName, string progVersion)
    {
        try {
            ChronojumpServer myServer = new ChronojumpServer();
            LogB.Information(myServer.ConnectDatabase());

            int    evalSID   = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID"));
            string machineID = SqlitePreferences.Select("machineID");

            ServerPing myPing = new ServerPing(evalSID, progName + " " + progVersion, UtilAll.GetOS(),
                                                                         //getIP(), DateTime.Now); //evaluator IP, date
                                               machineID, DateTime.Now); //evaluator machineID, date

            //if !doIsertion nothing will be uploaded,
            //is ok for uploadPerson to know if server is online
            string versionAvailable = myServer.UploadPing(myPing, doInsertion);

            LogB.Information(myServer.DisConnectDatabase());
            return(versionAvailable);
        } catch (Exception e) {
            LogB.Information("Server Connection", e.Message);
            return(Constants.ServerOffline);
        }
    }
コード例 #6
0
ファイル: ChronojumpServer.cs プロジェクト: GNOME/chronojump
 public System.IAsyncResult BeginUploadPing(ServerPing myPing, bool doInsertion, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UploadPing", new object[] {
                 myPing,
                 doInsertion}, callback, asyncState);
 }
コード例 #7
0
ファイル: ChronojumpServer.cs プロジェクト: GNOME/chronojump
 public void UploadPingAsync(ServerPing myPing, bool doInsertion, object userState)
 {
     if ((this.UploadPingOperationCompleted == null)) {
         this.UploadPingOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUploadPingCompleted);
     }
     this.InvokeAsync("UploadPing", new object[] {
                 myPing,
                 doInsertion}, this.UploadPingOperationCompleted, userState);
 }
コード例 #8
0
ファイル: ChronojumpServer.cs プロジェクト: GNOME/chronojump
 public void UploadPingAsync(ServerPing myPing, bool doInsertion)
 {
     this.UploadPingAsync(myPing, doInsertion, null);
 }
コード例 #9
0
ファイル: ChronojumpServer.cs プロジェクト: GNOME/chronojump
 public string UploadPing(ServerPing myPing, bool doInsertion)
 {
     object[] results = this.Invoke("UploadPing", new object[] {
                 myPing,
                 doInsertion});
     return ((string)(results[0]));
 }
コード例 #10
0
ファイル: server.cs プロジェクト: dineshkummarc/chronojump
    /*
    private static string getIP() {
        string strHostName = "";
        strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
        IPAddress[] addr = ipEntry.AddressList;
        return addr[addr.Length-1].ToString();
    }
    */
    public static string Ping(bool doInsertion, string progName, string progVersion)
    {
        try {
            ChronojumpServer myServer = new ChronojumpServer();
            Log.WriteLine(myServer.ConnectDatabase());

            int evalSID = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID"));
            string machineID = SqlitePreferences.Select("machineID");

            ServerPing myPing = new ServerPing(evalSID, progName + " " + progVersion, Util.GetOS(),
                    //getIP(), DateTime.Now); //evaluator IP, date
                    machineID, DateTime.Now); //evaluator machineID, date

            //if !doIsertion nothing will be uploaded,
            //is ok for uploadPerson to know if server is online
            string versionAvailable = myServer.UploadPing(myPing, doInsertion);

            Log.WriteLine(myServer.DisConnectDatabase());
            return versionAvailable;
        } catch (Exception e){
            Log.WriteLine("Server Connection "+e.Message);
            return Constants.ServerOffline;
        }
    }
コード例 #11
0
    public string UploadPing(ServerPing myPing, bool doInsertion)
    {
        //problemes getting user ip:
        //when it works it should be assigned to myPing.IP
        //string a = Request.UserHostName;
        //Console.WriteLine(System.Web.HttpRequest.UserHostAdress);

        Console.WriteLine("ping string: " + myPing.ToString());

        string strHostName = "";
        strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
        IPAddress[] addr = ipEntry.AddressList;
        string ip = addr[addr.Length-1].ToString();

        Console.WriteLine("ip: " + ip);

        //!doInsertion is a way to know if server is connected
        //but without inserting nothing
        //is ok before uploading a session

        //Console.WriteLine("IP: " + System.Web.HttpRequest.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + System.Net.HttpRequest.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + System.Net.Request.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + HttpContext.Current.Request.UserHostAddress);
        //Console.WriteLine("IP context : " + this.Context.Request.UserHostAddress);
        //Console.WriteLine("IP : " + this.Request.UserHostAddress);

        //Console.WriteLine("IP : " + System.Net.HttpListenerRequest.UserHostAddress.ToString());
        //System.Net.HttpListenerRequest req = new System.Net.HttpListenerRequest();
        //Console.WriteLine("IP : " + req.UserHostAddress.ToString());

        //		System.Net.HttpListenerRequest req;
        //string a = System.Net.HttpListenerRequest.UserHostAddress;
        //		string a = req.UserHostAddress;

        //string a = this.System.Net.HttpListenerRequest.UserHostAddress;

        //		System.Net.HttpListenerRequest request = new HttpListenerRequest (String.Empty, "http://localhost/", String.Empty);
        //		string a = request.UserHostAddress;

        //http://lists.ximian.com/pipermail/mono-list/2007-January/033998.html

        /*
        HttpListener listener = new HttpListener();

        listener.AuthenticationSchemeSelectorDelegate += delegate{
            Console.WriteLine("Asking for authentication scheme");
            return AuthenticationSchemes.Basic;
        };

        listener.Start();
        HttpListenerContext context = listener.GetContext();
        HttpListenerRequest request = context.Request;
        Console.WriteLine("IP req: " + request.UserHostAddress);
        */

        if(doInsertion)
            myPing.InsertAtDB(false);

        return SqlitePreferences.Select("versionAvailable");
    }
コード例 #12
0
        static void Main(string[] args)
        {
            // Set up log providers
            LogProvider.RegisterProvider(new FileLogWriter("packetLog.txt", LogImportance.Low));
            LogProvider.RegisterProvider(new ConsoleLogWriter(LogImportance.High));

            // Set up endpoint, ping server
            var endPoint = ParseEndPoint(args[0]);
            var ping     = ServerPing.DoPing(endPoint);

            Console.WriteLine("{0}/{1} {2} ({3}): {4}", ping.CurrentPlayers, ping.MaxPlayers, ping.ServerVersion,
                              ping.ProtocolVersion, ping.MotD);

            //var lastLogin = LastLogin.GetLastLogin();
            //var session = Session.DoLogin(lastLogin.Username, lastLogin.Password);
            var session = new Session("TestBot");

            // Connect to server
            var client = new MinecraftClient(session);

            client.Connect(endPoint);

            client.PlayerDied   += (s, e) => Console.WriteLine("Player died! Type 'respawn' to respawn.");
            client.Disconnected += (s, e) => Console.WriteLine("Disconnected: " + e.Reason);

            string input = "";

            while (input != "quit")
            {
                input = Console.ReadLine();
                if (input == null)
                {
                    continue;
                }

                if (input.StartsWith("move "))
                {
                    var parts   = input.Split(' ');
                    var amountX = int.Parse(parts[1]);
                    var amountZ = int.Parse(parts[2]);

                    client.Move(amountX, amountZ);
                }
                else if (input.StartsWith("look "))
                {
                    var parts  = input.Split(' ');
                    var amount = float.Parse(parts[2]);
                    if (parts[1] == "yaw")
                    {
                        client.Yaw = amount;
                    }
                    else
                    {
                        client.Pitch = amount;
                    }
                }
                else if (input.StartsWith("lookat "))
                {
                    var parts = input.Split(' ');
                    var pos   = new Vector3
                    {
                        X = double.Parse(parts[1]),
                        Y = double.Parse(parts[2]),
                        Z = double.Parse(parts[3])
                    };

                    client.LookAt(pos);
                }
                else if (input.StartsWith("say "))
                {
                    client.SendChat(input.Substring(4));
                }
                else if (input == "respawn")
                {
                    client.Respawn();
                }
                else if (input == "save")
                {
                    client.World.Save("testWorld", true);
                }
                else if (input == "under")
                {
                    Console.WriteLine(client.World.GetBlock(client.Position + Vector3.Down).GetType().Name);
                }
            }

            client.Disconnect("Quitting");
        }
コード例 #13
0
        private Task ValidateLibraries()
        {
            var serverClient = new ServerPing();

            serverClient.ClientType = ClientType.DesktopClient;

            var apiLoc = textBox1.Text;

            libsValidated      = false;
            progressBar1.Style = ProgressBarStyle.Marquee;
            msgLbl.Text        = "Ping " + apiLoc;
            _setButton.Enabled = false;
            button1.Enabled    = false;
            button1.Visible    = false;

            return(Task.Factory.StartNew(() =>
            {
                var result = Application.PingWebApiServer(serverClient, apiLoc);
                return result != null;
            }).ContinueWith(r =>
            {
                List <vi_DesktopLibrary> libsDef = new List <vi_DesktopLibrary>();
                if (r.Result)
                {
                    this.Invoke(new Action(() =>
                    {
                        msgLbl.Text = "Get Libraries Information.";
                    }));

                    libsDef = Application.GetCurrentLibraries().ToList();
                    Application.FilterExistingLibraries(libsDef);

                    this.Invoke(new Action(() =>
                    {
                        progressBar1.Value = 0;
                        progressBar1.Step = 1;
                        progressBar1.Maximum = libsDef.Count;
                        progressBar1.Style = ProgressBarStyle.Blocks;
                        _setButton.Enabled = true;
                        button1.Enabled = true;
                        textBox2.Enabled = true;
                        msgLbl.Text = "Finished.";
                        textBox2.Focus();
                    }));
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        progressBar1.Style = ProgressBarStyle.Blocks;
                        _setButton.Enabled = true;

                        msgLbl.Text = "Cannot Ping Server.";
                    }));
                }

                return libsDef;
            }).ContinueWith(r =>
            {
                if (r.Result.Count > 0)
                {
                    foreach (var item in r.Result)
                    {
                        this.Invoke(new Action(() =>
                        {
                            msgLbl.Text = "Downloading " + item.AssemblyName + item.FileExtension;
                        }));

                        var bin = Application.DownloadLib(item.BinaryDataId);
                        if (!Directory.Exists(Application.LibPath + "bin"))
                        {
                            Directory.CreateDirectory(Application.LibPath + "bin");
                        }
                        this.Invoke(new Action(() =>
                        {
                            msgLbl.Text = "Saving " + item.AssemblyName + item.FileExtension;
                        }));
                        File.WriteAllBytes(Application.LibPath + "bin\\" + item.AssemblyName + item.FileExtension, bin.DeflateDecompress());

                        Invoke(new Action((progressBar1.PerformStep)));
                    }
                }
            }).ContinueWith(r =>
            {
                this.Invoke(new Action(() =>
                {
                    progressBar1.Value = 0;
                    msgLbl.Text = "Libraries Downloaded";
                    libsValidated = true;
                }));
            }));
        }
コード例 #14
0
    public string UploadPing(ServerPing myPing, bool doInsertion)
    {
        //problemes getting user ip:
        //when it works it should be assigned to myPing.IP
        //string a = Request.UserHostName;
        //Console.WriteLine(System.Web.HttpRequest.UserHostAdress);

        Console.WriteLine("ping string: " + myPing.ToString());


        string strHostName = "";

        strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

        IPAddress[] addr = ipEntry.AddressList;
        string      ip   = addr[addr.Length - 1].ToString();

        Console.WriteLine("ip: " + ip);



        //!doInsertion is a way to know if server is connected
        //but without inserting nothing
        //is ok before uploading a session

        //Console.WriteLine("IP: " + System.Web.HttpRequest.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + System.Net.HttpRequest.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + System.Net.Request.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + HttpContext.Current.Request.UserHostAddress);
        //Console.WriteLine("IP context : " + this.Context.Request.UserHostAddress);
        //Console.WriteLine("IP : " + this.Request.UserHostAddress);

        //Console.WriteLine("IP : " + System.Net.HttpListenerRequest.UserHostAddress.ToString());
        //System.Net.HttpListenerRequest req = new System.Net.HttpListenerRequest();
        //Console.WriteLine("IP : " + req.UserHostAddress.ToString());

//		System.Net.HttpListenerRequest req;
        //string a = System.Net.HttpListenerRequest.UserHostAddress;
//		string a = req.UserHostAddress;

        //string a = this.System.Net.HttpListenerRequest.UserHostAddress;

//		System.Net.HttpListenerRequest request = new HttpListenerRequest (String.Empty, "http://localhost/", String.Empty);
//		string a = request.UserHostAddress;

        //http://lists.ximian.com/pipermail/mono-list/2007-January/033998.html

        /*
         * HttpListener listener = new HttpListener();
         *
         * listener.AuthenticationSchemeSelectorDelegate += delegate{
         *      Console.WriteLine("Asking for authentication scheme");
         *      return AuthenticationSchemes.Basic;
         * };
         *
         *
         *
         * listener.Start();
         * HttpListenerContext context = listener.GetContext();
         * HttpListenerRequest request = context.Request;
         * Console.WriteLine("IP req: " + request.UserHostAddress);
         */



        if (doInsertion)
        {
            myPing.InsertAtDB(false);
        }

        return(SqlitePreferences.Select("versionAvailable"));
    }