Start() public method

public Start ( ) : void
return void
Exemplo n.º 1
0
        public frmSecondGlance()
        {
            InitializeComponent();

            PacketType[] types = (PacketType[])Enum.GetValues(typeof(PacketType));

            // Fill up the "To Log" combo box with options
            foreach (PacketType type in types)
            {
                if (type != PacketType.Default) cboToLog.Items.Add(type);
            }

            // Set the default selection to the first entry
            cboToLog.SelectedIndex = 0;

            // Setup the proxy
            ProxyConfig proxyConfig = new ProxyConfig("Second Glance", "John Hurliman <*****@*****.**>", 
                new string[0]);
            Proxy = new Proxy(proxyConfig);

            Proxy.Start();

            // Start the timer that moves packets from the queue and displays them
            DisplayTimer.Elapsed += new System.Timers.ElapsedEventHandler(DisplayTimer_Elapsed);
            DisplayTimer.Start();
        }
        public XMLRPCMaster(string listenAddress, int port)
        {
            RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(XMLRPCMaster), "Master.rem", WellKnownObjectMode.Singleton);
            RemotingServices.Marshal(this, "Master.rem");

            string portArg = "--proxy-login-port=0"; //No one will ever log in
            string clientListenIPArg = "--proxy-client-facing-address="+listenAddress; //No client will ever send packets to the server so this is irrelevant
            string clientPortArg = "--proxy-client-facing-port=0"; //No client will ever send packets to the server so this is irrelevant
            string serverListenIPArg = "--proxy-server-facing-address="+listenAddress; //This is the address packets sent by this master will appear from
            string serverPortArg = "--proxy-server-facing-port="+port; //This is the port packets sent by this master will appear from
            string loginURIArg = "--proxy-remote-login-uri=http://"+listenAddress+":0"; //This proxy will never log in.
            string[] args = { portArg, clientListenIPArg, clientPortArg, serverListenIPArg, serverPortArg, loginURIArg };
            ProxyConfig config = new ProxyConfig("Routing God", "*****@*****.**", args);
            proxy = new Proxy(config);
            proxy.Start();
        }
        public void Connect(string masterAddress, string listeningAddress, int masterXmlRpcPort, int port, int xmlRpcPort)
        {
            //socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //socket.Bind(new IPEndPoint(IPAddress.Parse(listeningIP), port));
            //socket.BeginReceiveFrom(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ref remoteEndPoint, new AsyncCallback(ProcessPacket), null);

            IMasterProxy master = XmlRpcProxyGen.Create<IMasterProxy>();
            master.Url = "http://"+masterAddress+":"+masterXmlRpcPort+"/Master.rem";

            new Thread(() => {
                int masterPort = master.Register(name, listeningAddress, port, xmlRpcPort);

                IPAddress masterIP = GetAddress(masterAddress);
                IPAddress listenIP = GetAddress(listeningAddress);

                string serverListenIPArg = "--proxy-remote-facing-address=" + listenIP.ToString();
                string serverListenPortArg = "--proxy-remote-facing-port=" + port;
                string clientLoginPortArg = "--proxy-login-port=0"; //Never going to be used. No one will ever connect to this proxy.
                string loginURIArg = "--proxy-remote-login-uri=http://http://localhost:9000";
                string[] args = { serverListenIPArg, serverListenPortArg, clientLoginPortArg, loginURIArg };
                ProxyConfig config = new ProxyConfig("Routing God", "*****@*****.**", args);
                proxy = new Proxy(config);
                proxy.ActiveCircuit = new IPEndPoint(masterIP, masterPort);

                foreach (PacketType pt in Enum.GetValues(typeof(PacketType)))
                    proxy.AddDelegate(pt, Direction.Incoming, ProcessPacket);

                proxy.Start();

            }).Start();
        }
        public bool Start()
        {
            if (mConfig == null)
                throw new ArgumentException("Unable to start proxy. No configuration specified.");
            try {
                mLoggedIn = false;
                mLastUpdatePacket = DateTime.UtcNow;
                mProxy = new Proxy(mConfig);
                mProxy.AddLoginResponseDelegate(mProxy_LoginResponse);
                mProxy.AddDelegate(PacketType.AgentUpdate, Direction.Outgoing, mProxy_AgentUpdatePacketReceived);
                if (mViewerConfig.GetLocalID) {
                    mLocalID = 0;
                    mProxy.AddDelegate(PacketType.ObjectUpdate, Direction.Incoming, mObjectUpdateListener);
                }

                ThisLogger.Info("Proxying " + mConfig.remoteLoginUri);
                mProxy.Start();

                if (pPositionChanged != null)
                    mProxy.AddDelegate(PacketType.AgentUpdate, Direction.Outgoing, mAgentUpdateListener);

                if (ProxyStarted != null)
                    ProxyStarted();

                stopping = false;
                mCanncelTockenSource = new CancellationTokenSource();

                new Thread(() =>
                {
                    AgentUpdatePacket packet;
                    while (!stopping)
                    {
                        try
                        {
                            packet = agentUpdatePacketQueue.Take(mCanncelTockenSource.Token);
                        }
                        catch (OperationCanceledException)
                        {
                            return;
                        }

                        Vector3 pos = packet.AgentData.CameraCenter;

                        if (mFrame.Core.ControlMode == ControlMode.Absolute)
                        {
                            //new Thread(() => {
                            if (mViewerConfig.CheckForPause)
                            {
                                string key = MakeKey(pos);
                                lock (mUnackedUpdates)
                                {
                                    if (mUnackedUpdates.ContainsKey(key))
                                        mUnackedUpdates.Remove(key);
                                }

                                CheckForPause();
                            }
                            //}).Start();
                        }

                        if (pPositionChanged != null)
                            pPositionChanged(pos, new Rotation(packet.AgentData.CameraAtAxis));
                    }
                }).Start();

                new Thread(() =>
                {
                    ImprovedTerseObjectUpdatePacket packet;
                    while (!stopping)
                    {
                        try
                        {
                            packet = objectUpdatePacketQueue.Take(mCanncelTockenSource.Token);
                        }
                        catch (OperationCanceledException)
                        {
                            return;
                        }

                        foreach (var block in packet.ObjectData)
                        {
                            uint localid = Utils.BytesToUInt(block.Data, 0);

                            if (block.Data[0x5] != 0 && localid == mLocalID)
                            {
                                mAvatarPosition = new Vector3(block.Data, 0x16);
                                mPositionOffset = mAvatarPosition - mFrame.Core.Position;
                                Quaternion rotation = Quaternion.Identity;

                                // Rotation (theta)
                                rotation = new Quaternion(
                                    Utils.UInt16ToFloat(block.Data, 0x2E, -1.0f, 1.0f),
                                    Utils.UInt16ToFloat(block.Data, 0x2E + 2, -1.0f, 1.0f),
                                    Utils.UInt16ToFloat(block.Data, 0x2E + 4, -1.0f, 1.0f),
                                    Utils.UInt16ToFloat(block.Data, 0x2E + 6, -1.0f, 1.0f));

                                mAvatarOrientation = new Rotation(rotation);
                                //mAvatarOrientation = Frame.Core.Orientation;
                            }
                        }
                    }
                }).Start();
            } catch (NullReferenceException e) {
                //Logger.Info("Unable to start proxy. " + e.Message);
                mProxy = null;
                return false;
            }

            return true;
        }
        private void connectButton_Click(object sender, EventArgs e)
        {
            if (proxy != null)
                proxy.Stop();
            string file = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            string portArg = "--proxy-login-port="+portBox.Text;
            string listenIPArg = "--proxy-client-facing-address="+listenIPBox.Text;
            string loginURIArg = "--proxy-remote-login-uri="+loginURIBox.Text;
            string[] args = { portArg, listenIPArg, loginURIArg };
            ProxyConfig config = new ProxyConfig("Routing God", "*****@*****.**", args);
            proxy = new Proxy(config);
            proxy.AddLoginResponseDelegate(response => {
                loggedIn = true;
                if (LoggedIn != null)
                    LoggedIn(proxy, null);
                return response;
            });

            proxy.Start();

            if (OnStarted != null)
                OnStarted(proxy, null);

            startButton.Text = "ReStart";
        }