Example #1
0
        private void AttachedIncoming(InterceptedEventArgs e)
        {
            // If we can't read a string, leave this method.
            if (!e.Packet.CanRead<string>()) return;

            string value = e.Packet.ReadString();
            switch (value.ToLower())
            {
                case "block":
                {
                    e.IsBlocked = true;
                    break;
                }

                case "replace":
                {
                    // Replace the first string found in the packet.
                    e.Replacement.Replace<string>(0, "Replaced!");
                    break;
                }

                case "freeze":
                {
                    // Tell the contractor to continue reading data from local/remote endpoint.
                    // Does not wait for this method to finish, but the packet being processed
                    // can still be used: blocked/replaced
                    if (e.IsAsyncCapable)
                        e.ContinueRead();

                    // Simulate a long synchronous process for one second(1000ms).
                    Thread.Sleep(1000);
                    break;
                }
            }
        }
Example #2
0
        public void HandleIncoming(InterceptedEventArgs e)
        {
            if (e.Packet?.IsCorrupted ?? true)
            {
                return;
            }

            e.Packet.Position = 0;
            bool ignoreCurrent = false;

            try
            {
                if (_inAttaches.ContainsKey(e.Packet.Header))
                {
                    _inAttaches[e.Packet.Header](this, e);
                }

                if (DetectIncoming && _inPrevious.Count > 0)
                {
                    e.Packet.Position = 0;
                    HMessage previous = _inPrevious.Pop();

                    if (!_inLocked.ContainsKey(e.Packet.Header) &&
                        !_inLocked.ContainsKey(previous.Header))
                    {
                        ignoreCurrent = HandleIncoming(e.Packet, previous);
                    }
                    else
                    {
                        ignoreCurrent = true;
                    }

                    if (ignoreCurrent)
                    {
                        e.Packet.Position = 0;
                        previous.Position = 0;

                        if (_inLocked.ContainsKey(e.Packet.Header))
                        {
                            _inLocked[e.Packet.Header](e);
                        }
                        else if (_inLocked.ContainsKey(previous.Header))
                        {
                            var args = new InterceptedEventArgs(previous);
                            _inLocked[previous.Header](args);
                        }
                    }
                }
            }
            finally
            {
                e.Packet.Position = 0;

                if (!ignoreCurrent && DetectIncoming)
                {
                    _inPrevious.Push(e.Packet);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Raises the <see cref="DataIncoming"/> event.
        /// </summary>
        /// <param name="e">An <see cref="InterceptedEventArgs"/> that contains the event data.</param>
        /// <returns></returns>
        protected virtual void OnDataIncoming(InterceptedEventArgs e)
        {
            EventHandler <InterceptedEventArgs> handler = DataIncoming;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #4
0
        protected virtual void RaiseOnGameEvent <T>(EventHandler <T> handler, InterceptedEventArgs e) where T : InterceptedEventArgs
        {
            if (handler != null)
            {
                var args = (T)Activator.CreateInstance(typeof(T),
                                                       e.Continuation, e.Step, e.Packet);

                OnGameEvent(handler, args, e);
            }
        }
Example #5
0
        protected void RaiseOnFurnitureMove(InterceptedEventArgs e)
        {
            if (FurnitureMove != null)
            {
                var args = new FurnitureMoveEventArgs(e.Continuation, e.Step, e.Packet);
                OnFurnitureMove(args);

                e.Cancel       = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #6
0
        protected void RaiseOnHostWalk(InterceptedEventArgs e)
        {
            if (HostWalk != null)
            {
                var args = new HostWalkEventArgs(e.Continuation, e.Step, e.Packet);
                OnHostWalk(args);

                e.Cancel       = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #7
0
        protected void RaiseOnEntityAction(InterceptedEventArgs e)
        {
            if (EntityAction != null)
            {
                var args = new EntityActionEventArgs(e.Continuation, e.Step, e.Packet);
                OnEntityAction(args);

                e.Cancel       = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #8
0
        protected void RaiseOnFurnitureMove(InterceptedEventArgs e)
        {
            if (FurnitureMove != null)
            {
                var args = new FurnitureMoveEventArgs(e.Continuation, e.Step, e.Packet);
                OnFurnitureMove(args);

                e.Cancel = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #9
0
        protected void RaiseOnPlayerGesture(InterceptedEventArgs e)
        {
            if (PlayerGesture != null)
            {
                var args = new PlayerGestureEventArgs(e.Continuation, e.Step, e.Packet);
                OnPlayerGesture(args);

                e.Cancel       = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #10
0
        public void HandleIncoming(InterceptedEventArgs e)
        {
            bool ignoreCurrent = true;

            try
            {
                e.Packet.Position = 0;
                if (_inAttaches.ContainsKey(e.Packet.Header))
                {
                    _inAttaches[e.Packet.Header](e);
                }

                if (DetectIncoming)
                {
                    e.Packet.Position = 0;
                    HMessage previous = _inPrevious.Count > 0 ?
                                        _inPrevious.Pop() : e.Packet;

                    bool currentDetected  = InDetected.ContainsKey(e.Packet.Header);
                    bool previousDetected = InDetected.ContainsKey(previous.Header);

                    if (!currentDetected && !previousDetected)
                    {
                        ignoreCurrent = HandleIncoming(e.Packet, previous);
                    }

                    if (ignoreCurrent)
                    {
                        e.Packet.Position     =
                            previous.Position = 0;

                        if (InDetected.ContainsKey(e.Packet.Header))
                        {
                            InDetected[e.Packet.Header](e);
                        }
                        else if (InDetected.ContainsKey(previous.Header))
                        {
                            var args = new InterceptedEventArgs(null, e.Step - 1, previous);
                            InDetected[previous.Header](args);
                        }
                    }
                }
            }
            finally
            {
                e.Packet.Position = 0;

                if (DetectIncoming && !ignoreCurrent)
                {
                    _inPrevious.Push(e.Packet);
                }
            }
        }
Example #11
0
        protected virtual void HandleInterception(bool isOutgoing, InterceptedEventArgs e)
        {
            if (Extensions.Count < 1) return;

            ExtensionForm[] extensions = _extensions.ToArray();
            foreach (ExtensionForm extension in extensions)
            {
                if (!extension.IsRunning) continue;

                if (isOutgoing) extension.Triggers.HandleOutgoing(e);
                else extension.Triggers.HandleIncoming(e);
            }
        }
Example #12
0
        protected void OnPersonMove(InterceptedEventArgs obj)
        {
            // byteify the packet
            HMessage hmsg = obj.Packet;
            byte[] data = hmsg.ToBytes();

            // parse msg length and sender key
            int sender = data[9] + (data[8] << 8);

            if(sender == circleID) {
                // set new center
                x = data[13];
                y = data[17];
            }
        }
Example #13
0
        // Intercept the window ID on double click
        protected void OnWindowClicked(InterceptedEventArgs obj)
        {
            // byteify the packet
            HMessage hmsg = obj.Packet;
            byte[] data = hmsg.ToBytes();

            // parse-set the windowID
            windowID = 0;
            windowID += (data[9] << 0);
            windowID += (data[8] << 8);
            windowID += (data[7] << 16);
            windowID += (data[6] << 24);

            Connection.SendToServerAsync(SAY_OUT, (windowID / 10000).ToString(), 0, 0);
        }
Example #14
0
        private void HandleMessage(byte[] data, HDestination destination)
        {
            var args = new InterceptedEventArgs(ReadMessageAsync,
                0, new HMessage(data, destination));

            Task readTask = ReadMessageAsync(); // Keep reading.
            if (destination == HDestination.Server)
            {
                _extension.Triggers.HandleOutgoing(args);
                OnDataOutgoing(args);
            }
            else
            {
                _extension.Triggers.HandleIncoming(args);
                OnDataIncoming(args);
            }
        }
Example #15
0
        protected void OnSpaceSelected(InterceptedEventArgs args)
        {
            if (chooseFlag)
            {
                //[0][0][0][10][7]Á[0][0][0][8][0][0][0][7]
                // block the packet
                chooseFlag = false;
                args.IsBlocked = true;

                // parse space
                byte[] data = args.Packet.ToBytes();
                space = new Tuple<int, int>(data[9], data[13]);

                // debug print space
                //string space_string = "(" + space.Item1 + ", " + space.Item2 + ")";
                //Connection.SendToServerAsync(3871, space_string, 4, 0);
            }
        }
Example #16
0
        protected void OnChatIncoming(InterceptedEventArgs obj)
        {
            if (mimicFlag)
            {
                HMessage hmsg = obj.Packet;

                // parse msg length
                byte[] data = hmsg.ToBytes();
                int n = data[11];

                // parse msg string
                List<byte> strlist = data.ToList();
                strlist = strlist.GetRange(12, n + 12);
                string char_string = Encoding.UTF8.GetString(strlist.ToArray());

                // print msg string
                Connection.SendToServerAsync(SAY_OUT, char_string, 4, msg_idx);
            }
        }
Example #17
0
        private void DataIncoming(object sender, InterceptedEventArgs e)
        {
            switch (e.Step)
            {
                case 1:
                {
                    if (RealExponent == 0)
                        RealExponent = DEFAULT_REAL_EXPONENT;

                    if (string.IsNullOrWhiteSpace(RealModulus))
                        RealModulus = DEFAULT_REAL_MODULUS;

                    Remote.Exchange = new HKeyExchange(RealExponent, RealModulus);
                    Local.Exchange = new HKeyExchange(FAKE_EXPONENT, FAKE_MODULUS, FAKE_PRIVATE_EXPONENT);

                    Remote.Exchange.DoHandshake(e.Packet.ReadString(),
                        e.Packet.ReadString(e.Packet.Position));

                    e.Replacement.Replace<string>(0, Local.Exchange.GetSignedPrime());
                    e.Replacement.Replace<string>(e.Packet.Position, Local.Exchange.GetSignedGenerator());
                    break;
                }
                case 2:
                {
                    _remoteKey = Remote.Exchange.GetSharedKey(e.Packet.ReadString());
                    e.Replacement.Replace<string>(0, Local.Exchange.GetPublicKey());

                    RealExponent = 0;
                    RealModulus = string.Empty;

                    Local.Exchange.Dispose();
                    Remote.Exchange.Dispose();

                    Local.Decrypter = new Rc4(_localKey);
                    Remote.Decrypter = new Rc4(_remoteKey);

                    _main.Connection.DataIncoming -= DataIncoming;
                    break;
                }
            }
        }
Example #18
0
        private void HandleIncoming(byte[] data, int count)
        {
            var args = new InterceptedEventArgs(ReadIncomingAsync, count, data, HDestination.Client);

            Triggers.HandleIncoming(args);

            if (!args.Cancel && !BlockedIncoming.Contains(args.Packet.Header))
            {
                OnDataIncoming(args);

                if (!args.Cancel)
                {
                    SendToClientAsync(args.Packet.ToBytes());
                }
            }

            if (!args.WasContinued)
            {
                ReadIncomingAsync();
            }
        }
Example #19
0
        // We can block/replace packets in attach methods.
        private void MyOutCallback(object sender, InterceptedEventArgs e)
        {
            // We can't read an integer for this packet, let's leave.
            if (!e.Packet.CanRead<string>()) return;

            string value = e.Packet.ReadString(0);
            switch (value)
            {
                // If the string value is "block", let's block it.
                case "block":
                {
                    e.IsBlocked = true;
                    break;
                }

                // If the string value is "replace", let's replace it with "REPLACED!".
                case "replace":
                {
                    e.Replacement.Replace<string>("REPLACED");
                    break;
                }

                // If the string value is "wait", let's do some heavy processing, and still allow data to come through.
                case "wait":
                {
                    // This will tell the caller to continue spitting out data, while we have it wait for this end result.
                    // We can still replace/block this packet while more data comes through.
                    e.ContinueRead();

                    // Simulate long process.
                    Thread.Sleep(5000);

                    // It turns out Clyde DOES want to replace this packet after waiting 5 seconds, god dammit.
                    e.Replacement.Replace<string>("We waited 5 seconds, and replaced. God dammit Clyde");

                    // Don't worry though, we got you, now you never have to worry about Clyde messing up your day ever again.
                    break;
                }
            }
        }
Example #20
0
        private void HandleOutgoing(HMessage packet, int count)
        {
            var args = new InterceptedEventArgs(ReadOutgoingAsync, count, packet);

            OnDataOutgoing(args);

            if (!args.IsBlocked)
            {
                SendToServerAsync(args.Replacement.ToBytes()).Wait();
                var executeTaskList = new List <Task <int> >(args.Executions.Count);
                for (int i = 0; i < args.Executions.Count; i++)
                {
                    executeTaskList.Add(
                        SendToServerAsync(args.Executions[i].ToBytes()));
                }
                Task.WhenAll(executeTaskList).Wait();
            }
            if (!args.WasContinued)
            {
                Task readOutTask = ReadOutgoingAsync();
            }
        }
Example #21
0
        // flip the habbo chat string
        protected void OnDiceIncoming(InterceptedEventArgs obj)
        {
            if (flag)
            {
                // byteify the packet
                HMessage hmsg = obj.Packet;
                byte[] data = hmsg.ToBytes();

                // parse dice value
                int len = data.Length;
                int val = data[len - 1];

                if (val >= 1 && val <= 6)
                {
                    // build chat string
                    string char_string = "" + val;

                    // print chat string
                    Connection.SendToServerAsync(3871, char_string, 4, 0);
                }
            }
        }
Example #22
0
        protected void OnFurniPlaced(InterceptedEventArgs args)
        {
            if (runFlag)
            {
                // packet ex.
                //[0][0][0]6[5]Ô {×C[0][0][0][0][0][8][0][0][0][3][0][0][0][0][0][3]0.0[0]

                // parse space
                byte[] data = args.Packet.ToBytes();
                Tuple<int, int> furni_space = new Tuple<int, int>(data[17], data[21]);

                // move to that space
                //if (space.Equals(furni_space))
                //{
                    Connection.SendToServerAsync(SPACE_SEL, furni_space.Item1, furni_space.Item2);
                //}

                // debug print space
                //string space_string = "(" + furni_space.Item1 + ", " + furni_space.Item2 + ")";
                //Connection.SendToServerAsync(3871, space_string, 4, 0);
            }
        }
Example #23
0
        // shout incoming
        protected void OnShoutIncoming(InterceptedEventArgs obj)
        {
            if (mimicFlag)
            {
                // byteify the packet
                HMessage hmsg = obj.Packet;
                byte[] data = hmsg.ToBytes();

                // parse msg length and sender key
                int sender = data[9] + (data[8] << 8);
                int len = data[11];

                if (sender == copyID)
                {
                    // parse msg string
                    List<byte> strlist = data.ToList();
                    strlist = strlist.GetRange(12, len + 12);
                    string char_string = Encoding.UTF8.GetString(strlist.ToArray());

                    // print msg string
                    Connection.SendToServerAsync(SHOUT_OUT, char_string, 0);
                }
            }
        }
Example #24
0
 private void DataIncoming(object sender, InterceptedEventArgs e) =>
     HandleIncoming(e);
Example #25
0
 public void HandleIncoming(InterceptedEventArgs e)
 {
     HandleInterception(false, e);
 }
Example #26
0
 public void RaiseOnHostClickPlayer(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostClickPlayer, e);
 }
Example #27
0
        private void DataOutgoing(object sender, InterceptedEventArgs e)
        {
            switch (e.Step)
            {
                case 3:
                {
                    _localKey = Local.Exchange.GetSharedKey(e.Packet.ReadString());
                    e.Replacement.Replace<string>(0, Remote.Exchange.GetPublicKey());
                    break;
                }
                case 4:
                {
                    Local.Encrypter = new Rc4(_localKey);
                    Remote.Encrypter = new Rc4(_remoteKey);

                    _main.Connection.DataOutgoing -= DataOutgoing;
                    break;
                }
            }
        }
Example #28
0
 public void RaiseOnPlayerDance(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(PlayerDance, e);
 }
Example #29
0
 public void RaiseOnHostUpdateClothes(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostUpdateClothes, e);
 }
Example #30
0
        public void HandleIncoming(InterceptedEventArgs e)
        {
            if (e.Packet?.IsCorrupted ?? true) return;

            e.Packet.Position = 0;
            bool ignoreCurrent = false;
            try
            {
                if (_inAttaches.ContainsKey(e.Packet.Header))
                    _inAttaches[e.Packet.Header](this, e);

                if (DetectIncoming && _inPrevious.Count > 0)
                {
                    e.Packet.Position = 0;
                    HMessage previous = _inPrevious.Pop();

                    if (!_inLocked.ContainsKey(e.Packet.Header) &&
                        !_inLocked.ContainsKey(previous.Header))
                        ignoreCurrent = HandleIncoming(e.Packet, previous);
                    else ignoreCurrent = true;

                    if (ignoreCurrent)
                    {
                        e.Packet.Position = 0;
                        previous.Position = 0;

                        if (_inLocked.ContainsKey(e.Packet.Header))
                            _inLocked[e.Packet.Header](e);
                        else if (_inLocked.ContainsKey(previous.Header))
                        {
                            var args = new InterceptedEventArgs(previous);
                            _inLocked[previous.Header](args);
                        }
                    }
                }
            }
            finally
            {
                e.Packet.Position = 0;

                if (!ignoreCurrent && DetectIncoming)
                    _inPrevious.Push(e.Packet);

            }
        }
Example #31
0
        private void DataIncoming(object sender, InterceptedEventArgs e)
        {
            try
            {
                switch (e.Step - _inStepOffset)
                {
                    case 1:
                    {
                        if (RealExponent == 0)
                            RealExponent = DEFAULT_REAL_EXPONENT;

                        if (string.IsNullOrWhiteSpace(RealModulus))
                            RealModulus = DEFAULT_REAL_MODULUS;

                        Remote.Exchange = new HKeyExchange(RealExponent, RealModulus);
                        Local.Exchange = new HKeyExchange(FAKE_EXPONENT, FAKE_MODULUS, FAKE_PRIVATE_EXPONENT);

                        string possibleSignedPrime = e.Packet.ReadString();
                        if (!e.Packet.CanRead<string>())
                        {
                            _bannerToken = possibleSignedPrime;

                            Eavesdropper.EavesdropperResponse += EavesdropperResponse;
                            Eavesdropper.Initiate(8080);
                            return;
                        }
                        string signedGenerator = e.Packet.ReadString();

                        Remote.Exchange.DoHandshake(possibleSignedPrime, signedGenerator);
                        Local.Exchange.Rsa.Padding = Remote.Exchange.Rsa.Padding;

                        e.Replacement = new HMessage(e.Packet.Header,
                            Local.Exchange.GetSignedPrime(), Local.Exchange.GetSignedGenerator());
                        break;
                    }
                    case 2:
                    {
                        if (e.Packet.Length < 5)
                        {
                            _inStepOffset++;
                            return;
                        }

                        _remoteKey = Remote.Exchange.GetSharedKey(e.Packet.ReadString());
                        if (_banner == null)
                        {
                            Local.Exchange.Rsa.Padding = Remote.Exchange.Rsa.Padding;
                            e.Replacement.Replace<string>(0, Local.Exchange.GetPublicKey());
                        }
                        else e.Replacement = new HMessage(e.Packet.Header, "1");

                        RealExponent = 0;
                        RealModulus = string.Empty;

                        Local.Exchange.Dispose();
                        Remote.Exchange.Dispose();

                        Local.Decrypter = new Rc4(_localKey);
                        Remote.Decrypter = new Rc4(_remoteKey);
                        break;
                    }
                    case 3:
                    {
                        if (Remote.IsDecryptionRequired)
                            Local.Encrypter = new Rc4(_localKey);

                        MainUI.Connection.DataIncoming -= DataIncoming;
                        break;
                    }
                }
            }
            catch
            {
                MainUI.Connection.DataIncoming -= DataIncoming;
                MainUI.Connection.DataOutgoing -= DataOutgoing;
            }
            finally { e.IsBlocked = false; }
        }
Example #32
0
 public void RaiseOnHostRaiseSign(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostRaiseSign, e);
 }
Example #33
0
 public void RaiseOnHostExitRoom(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostExitRoom, e);
 }
Example #34
0
 public void RaiseOnFurnitureLoad(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(FurnitureLoad, e);
 }
Example #35
0
 public void RaiseOnHostMoveFurniture(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostMoveFurniture, e);
 }
Example #36
0
        protected void RaiseOnEntityLoad(InterceptedEventArgs e)
        {
            if (EntityLoad != null)
            {
                var args = new EntityLoadEventArgs(e.Continuation, e.Step, e.Packet);
                OnEntityLoad(args);

                e.Cancel = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #37
0
 private void Connection_DataOutgoing(object sender, InterceptedEventArgs e)
 {
 }
Example #38
0
 public void RaiseOnHostShout(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostShout, e);
 }
Example #39
0
 protected virtual void OnDataIncoming(InterceptedEventArgs e)
 {
     DataIncoming?.Invoke(this, e);
 }
Example #40
0
 public void RaiseOnHostWalk(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostWalk, e);
 }
Example #41
0
        private void HandleIncoming(byte[] data, int count)
        {
            var args = new InterceptedEventArgs(ReadIncomingAsync, count, data, HDestination.Client);
            Triggers.HandleIncoming(args);

            if (!args.Cancel && !BlockedIncoming.Contains(args.Packet.Header))
            {
                OnDataIncoming(args);

                if (!args.Cancel)
                    SendToClientAsync(args.Packet.ToBytes());
            }

            if (!args.WasContinued)
                ReadIncomingAsync();
        }
Example #42
0
 public void RaiseOnFurnitureDrop(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(FurnitureDrop, e);
 }
Example #43
0
 public void RaiseOnPlayerGesture(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(PlayerGesture, e);
 }
Example #44
0
 public void RaiseOnFurnitureMove(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(FurnitureMove, e);
 }
Example #45
0
 public void RaiseOnHostUpdateMotto(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostUpdateMotto, e);
 }
Example #46
0
 public void RaiseOnEntityLoad(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(EntityLoad, e);
 }
Example #47
0
 public void RaiseOnHostDance(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostDance, e);
 }
Example #48
0
        protected void RaiseOnHostWalk(InterceptedEventArgs e)
        {
            if (HostWalk != null)
            {
                var args = new HostWalkEventArgs(e.Continuation, e.Step, e.Packet);
                OnHostWalk(args);

                e.Cancel = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #49
0
 private void DataOutgoing(object sender, InterceptedEventArgs e) =>
     HandleOutgoing(e);
Example #50
0
 public void RaiseOnEntityAction(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(EntityAction, e);
 }
Example #51
0
 public void HandleOutgoing(InterceptedEventArgs e)
 {
     HandleInterception(true, e);
 }
Example #52
0
 public void RaiseOnPlayerKickHost(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(PlayerKickHost, e);
 }
Example #53
0
        private void HandleIncoming(HMessage packet, int count)
        {
            var args = new InterceptedEventArgs(ReadIncomingAsync, count, packet);
            OnDataIncoming(args);

            if (!args.IsBlocked)
            {
                SendToClientAsync(args.Replacement.ToBytes()).Wait();
                var executeTaskList = new List<Task<int>>(args.Executions.Count);
                for (int i = 0; i < args.Executions.Count; i++)
                {
                    executeTaskList.Add(
                        SendToClientAsync(args.Executions[i].ToBytes()));
                }
                Task.WhenAll(executeTaskList).Wait();
            }

            if (!args.WasContinued)
            {
                Task readInTask = ReadIncomingAsync();
            }
        }
Example #54
0
        protected void RaiseOnPlayerGesture(InterceptedEventArgs e)
        {
            if (PlayerGesture != null)
            {
                var args = new PlayerGestureEventArgs(e.Continuation, e.Step, e.Packet);
                OnPlayerGesture(args);

                e.Cancel = args.Cancel;
                e.WasContinued = args.WasContinued;
            }
        }
Example #55
0
        private void HandleIncoming(HMessage packet, int count)
        {
            var args = new InterceptedEventArgs(ReadIncomingAsync, count, packet);
            Triggers.HandleIncoming(args);
            OnDataIncoming(args);

            if (!args.WasContinued && IsReading)
            {
                Task readInTask = ReadIncomingAsync();
            }
        }
Example #56
0
 protected virtual void OnGameEvent <T>(EventHandler <T> handler, T arguments, InterceptedEventArgs e) where T : InterceptedEventArgs
 {
     try { handler?.Invoke(this, arguments); }
     catch { /* Swallow all exceptions. */ }
     finally
     {
         e.IsBlocked    = arguments.IsBlocked;
         e.Replacement  = arguments.Replacement;
         e.WasContinued = arguments.WasContinued;
     }
 }
Example #57
0
        private void DataOutgoing(object sender, InterceptedEventArgs e)
        {
            try
            {
                switch (e.Step)
                {
                    case 2:
                    {
                        if (e.Packet.Length > 6)
                        {
                            MainUI.Connection.DataIncoming -= DataIncoming;
                            MainUI.Connection.DataOutgoing -= DataOutgoing;
                            break;
                        }
                        break;
                    }
                    case 3:
                    {
                        if (!string.IsNullOrWhiteSpace(_bannerToken))
                        {
                            if (_banner == null)
                            {
                                MainUI.Connection.DataIncoming -= DataIncoming;
                                MainUI.Connection.DataOutgoing -= DataOutgoing;

                                Eavesdropper.Terminate();
                                Eavesdropper.EavesdropperResponse -= EavesdropperResponse;

                                return;
                            }
                            else _localKey = new byte[] { 1 };
                        }
                        else _localKey = Local.Exchange.GetSharedKey(e.Packet.ReadString());

                        Remote.Exchange.Rsa.Padding = Local.Exchange.Rsa.Padding;
                        e.Replacement.Replace<string>(0, Remote.Exchange.GetPublicKey());
                        break;
                    }
                    case 4:
                    {
                        if (Local.IsDecryptionRequired)
                            Remote.Encrypter = new Rc4(_remoteKey);

                        MainUI.Connection.DataOutgoing -= DataOutgoing;
                        break;
                    }
                }
            }
            catch
            {
                MainUI.Connection.DataIncoming -= DataIncoming;
                MainUI.Connection.DataOutgoing -= DataOutgoing;
            }
            finally { e.IsBlocked = false; }
        }
Example #58
0
 public void RaiseOnPlayerUpdate(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(PlayerUpdate, e);
 }
Example #59
0
 public void RaiseOnHostNavigateRoom(InterceptedEventArgs e)
 {
     RaiseOnGameEvent(HostNavigateRoom, e);
 }
Example #60
0
 /// <summary>
 /// Raises the <see cref="DataOutgoing"/> event.
 /// </summary>
 /// <param name="e">An <see cref="InterceptedEventArgs"/> that contains the event data.</param>
 /// <returns></returns>
 protected virtual void OnDataOutgoing(InterceptedEventArgs e)
 {
     EventHandler<InterceptedEventArgs> handler = DataOutgoing;
     if (handler != null) handler(this, e);
 }