Exemple #1
0
        /// <summary>
        ///     Sends the pepper authentification message to server.
        /// </summary>
        internal void SendPepperAuthentification(ClientHelloMessage authMessage, PiranhaMessage pepperloginMessage, byte[] serverPublicKey)
        {
            this._pepperState = 1;

            this._sendEncrypter    = null;
            this._receiveEncrypter = null;

            this._pepperLoginMessage = pepperloginMessage;

            this.Send(authMessage);
        }
        public void InitRC4Encryption(string nonce)
        {
            if (this.m_receiveEncrypter != null)
            {
                this.m_receiveEncrypter.Destruct();
            }
            if (this.m_sendEncrypter != null)
            {
                this.m_sendEncrypter.Destruct();
            }

            this.m_receiveEncrypter = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, nonce);
            this.m_sendEncrypter    = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, nonce);
        }
Exemple #3
0
 internal void InitRC4Encrypters(string key, string nonce)
 {
     this.ReceiveEncrypter = new RC4Encrypter(key, nonce);
     this.SendEncrypter    = new RC4Encrypter(key, nonce);
 }
Exemple #4
0
        public void Dispose()
        {
            if (!this.Disposed)
            {
                this.Disposed = true;
                this.State    = State.DISCONNECTED;

                this.Chat?.Quit(this);

                if (this.Account != null)
                {
                    if (this.Account.Battle != null)
                    {
                        if (!this.Account.Battle.Ended)
                        {
                            if (this.Account.Battle.Attacker == this.Account.Home.Level)
                            {
                                this.Account.Battle.Trofeislogichlost();
                                this.Account.Battle.Trofeislogichwin();
                                this.Account.Battle.EndBattleAsync();
                                this.Account.Battle = null;
                            }
                        }
                        else
                        {
                            this.Account.Battle = null;
                        }
                    }

                    if (this.Account.Player != null)
                    {
                        Resources.Accounts.SavePlayer(this.Account.Player);

                        /*
                         * if (this.GameMode?.Level != null && this.Account.Player.BattleIdV2 > 0)
                         * {
                         *  Resources.BattlesV2.Dequeue(this.GameMode.Level);
                         * }
                         */

                        if (this.Account.Player.Alliance != null)
                        {
                            Player _;
                            long   id = (((long)this.Account.HighId) << 32) | (uint)this.Account.LowId;

                            this.Account.Player.Alliance.DecrementTotalConnected();
                            this.Account.Player.Alliance.Members.Connected.TryRemove(id, out _);
                        }
                    }

                    if (this.Account.Home != null)
                    {
                        Resources.Accounts.SaveHome(this.Account.Home);
                    }

                    this.Account.Device = null;
                }

                if (this.GameMode?.CommandManager != null)
                {
                    if (this.GameMode.CommandManager.ServerCommands != null)
                    {
                        foreach (Command Command in this.GameMode.CommandManager.ServerCommands.Values.ToArray())
                        {
                            Command.Execute();
                        }
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "CommandManager != null but ServerCommands == null");
                    }
                }

                /*
                 * Account = null;
                 * Chat = null;
                 * GameMode = null;
                 */
                ReceiveEncrypter = null;
                SendEncrypter    = null;
            }
        }
 public void InitEncrypters(string nonce = "nonce")
 {
     this.m_receiveEncrypter = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, nonce);
     this.m_sendEncrypter    = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, nonce);
 }
Exemple #6
0
 /// <summary>
 ///     Initializes the instance of encrypters.
 /// </summary>
 internal void InitEncrypters(string nonce)
 {
     this._sendEncrypter    = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, nonce);
     this._receiveEncrypter = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, nonce);
 }
Exemple #7
0
        /// <summary>
        ///     Called when the gateway receive a packet.
        /// </summary>
        internal int OnReceive(byte[] packet, int length)
        {
            if (length >= 7)
            {
                length -= 7;

                int messageType    = packet[1] | packet[0] << 8;
                int messageLength  = packet[4] | packet[3] << 8 | packet[2] << 16;
                int messageVersion = packet[6] | packet[5] << 8;

                if (length >= messageLength)
                {
                    int    encodingLength    = messageLength;
                    byte[] encodingByteArray = new byte[messageLength];
                    Array.Copy(packet, 7, encodingByteArray, 0, messageLength);

                    if (this._receiveEncrypter != null)
                    {
                        byte[] encryptedByteArray = encodingByteArray;
                        byte[] decryptedByteArray = new byte[messageLength - this._receiveEncrypter.GetOverheadEncryption()];

                        this._receiveEncrypter.Decrypt(encryptedByteArray, decryptedByteArray, messageLength);

                        encodingByteArray = decryptedByteArray;
                        encodingLength   -= this._receiveEncrypter.GetOverheadEncryption();
                    }

                    PiranhaMessage message = LogicMagicMessageFactory.Instance.CreateMessageByType(messageType);

                    if (message != null)
                    {
                        message.SetMessageVersion((short)messageVersion);
                        message.GetByteStream().SetByteArray(encodingByteArray, encodingLength);

                        try
                        {
                            message.Decode();

                            if (message.GetMessageType() == 20000)
                            {
                                ExtendedSetEncryptionMessage extendedSetEncryptionMessage = (ExtendedSetEncryptionMessage)message;
                                LogicMersenneTwisterRandom   scrambler = new LogicMersenneTwisterRandom(0);

                                byte byte100 = 0;

                                for (int i = 0; i < 100; i++)
                                {
                                    byte100 = (byte)scrambler.NextInt();
                                }

                                byte[] nonce          = extendedSetEncryptionMessage.RemoveNonce();
                                string scrambledNonce = null;

                                for (int i = 0; i < nonce.Length; i++)
                                {
                                    scrambledNonce += (char)(nonce[i] ^ (byte)(scrambler.NextInt() & byte100));
                                }

                                if (this._receiveEncrypter != null)
                                {
                                    this._receiveEncrypter.Destruct();
                                    this._receiveEncrypter = null;
                                }

                                if (this._sendEncrypter != null)
                                {
                                    this._sendEncrypter.Destruct();
                                    this._sendEncrypter = null;
                                }

                                this._receiveEncrypter = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, scrambledNonce);
                                this._sendEncrypter    = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, scrambledNonce);
                            }
                            else
                            {
                                this.MessageManager.ReceiveMessage(message);
                            }
                        }
                        catch (Exception exception)
                        {
                            Logging.Error("Client::onReceive message decode exception, trace: " + exception);
                        }

                        Logging.Print("Client::sendMessage message " + message.GetType().Name + " received");
                    }
                    else
                    {
                        Logging.Warning("NetworkMessaging::onReceive Ignoring message of unknown type " + messageType);
                    }

                    return(messageLength + 7);
                }
            }

            return(0);
        }
Exemple #8
0
 /// <summary>
 ///     Sets the encrypter instances.
 /// </summary>
 internal void SetEncrypters(StreamEncrypter sendEncrypter, StreamEncrypter receiveEncrypter)
 {
     this._sendEncrypter    = sendEncrypter;
     this._receiveEncrypter = receiveEncrypter;
 }