public SetFollowCamPropertiestForm()
        {
            string file = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            string port = "8080";
            //string listenIP = "138.251.194.192";
            string listenIP = "127.0.0.1";
            string loginURI = "http://apollo.cs.st-andrews.ac.uk:8002";

            string portArg = "--proxy-login-port="+port;
            string listenIPArg = "--proxy-client-facing-address="+listenIP;
            string loginURIArg = "--proxy-remote-login-uri="+loginURI;
            string[] args = { portArg, listenIPArg, loginURIArg };
            ProxyConfig config = new ProxyConfig("Routing God", "*****@*****.**", args);
            mProxy = new Proxy(config);
            mProxy.AddLoginResponseDelegate(response => {
                mLoggedIn = true;
                return response;
            });
            mProxy.AddDelegate(PacketType.ObjectUpdate, Direction.Incoming, (p, ep) => {
                ObjectUpdatePacket packet = (ObjectUpdatePacket) p;
                foreach (var block in packet.ObjectData) {
                    if (block.PCode == (byte) PCode.Avatar) {
                        string name = Utils.BytesToString(block.NameValue);
                        name = name.Replace("STRING RW SV ", "");
                        string[] tokens = name.Split(' ', '\n');
                        string firstName = tokens[1];
                        string lastName = tokens[3];
                        string title = tokens.Length > 5 ? tokens[5] : "";

                        //avatarsListBox.DataSource = avatarsBindingSource;
                        avatarsBindingSource.Add(new Avatar(firstName, lastName, block.ID, block.FullID));

                        Console.WriteLine("\n\n Added " + firstName + " " + lastName + ".\n\n");
                    }
                }
                //"FirstName STRING RW SV Routing\nLastName STRING RW SV God\nTitle STRING RW SV "
                return packet;
            });

            InitializeComponent();

            focusRotationPanel.Vector = Vector3.UnitX;
        }
Beispiel #2
0
        private void Init(string[] args, ProxyConfig proxyConfig)
        {
            //bool externalPlugin = false;
            this.args = args;

            if (proxyConfig == null)
            {
                proxyConfig = new ProxyConfig("GridProxy", "Austin Jennings / Andrew Ortman", args);
            }
            proxy = new Proxy(proxyConfig);

            // add delegates for login
            proxy.AddLoginRequestDelegate(new XmlRpcRequestDelegate(LoginRequest));
            proxy.AddLoginResponseDelegate(new XmlRpcResponseDelegate(LoginResponse));

            // add a delegate for outgoing chat
            proxy.AddDelegate(PacketType.ChatFromViewer, Direction.Outgoing, new PacketDelegate(ChatFromViewerOut));

            //  handle command line arguments
            foreach (string arg in args)
                if (arg == "--log-login")
                    logLogin = true;
                else if (arg.Substring(0, 2) == "--")
                {
                    int ipos = arg.IndexOf("=");
                    if (ipos != -1)
                    {
                        string sw = arg.Substring(0, ipos);
                        string val = arg.Substring(ipos + 1);

                        Logger.Log("arg '" + sw + "' val '" + val + "'", Helpers.LogLevel.Debug);

                        if (sw == "--load")
                        {
                            //externalPlugin = true;
                            LoadPlugin(val);
                        }
                    }
                }

            commandDelegates["/load"] = new CommandDelegate(CmdLoad);
        }
        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";
        }