Beispiel #1
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, true);
            }
            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);
        }