Ejemplo n.º 1
0
        public void SendTalk(MessageModes mode, params object[] rest)
        {
            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.Talk);
            message.AddU8((byte)mode);

            if (rest.Length == 1 && rest[0] is string)
            {
                message.AddString(rest[0] as string);
            }
            else if (rest.Length == 2 && rest[0] is string && rest[1] is string)
            {
                message.AddString(rest[0] as string);
                message.AddString(rest[1] as string);
            }
            else if (rest.Length == 2 && rest[0] is int && rest[1] is string)
            {
                int channelID = (int)rest[0];
                message.AddU16((ushort)channelID);
                message.AddString(rest[1] as string);
            }

            WriteToOutput(message);
        }
Ejemplo n.º 2
0
        public void SendLeaveChannel(int channelID)
        {
            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.LeaveChannel);
            message.AddU16((ushort)channelID);
            WriteToOutput(message);
        }
Ejemplo n.º 3
0
        void AddMessageLength(OutputMessage message)
        {
            int pos = message.Tell();

            message.Seek(0);
            message.AddU16((ushort)message.GetBufferLength());
            message.IncreaseHeaderLength(sizeof(ushort));
            message.Seek(pos + sizeof(ushort));
        }
Ejemplo n.º 4
0
        public void SendExcludeFromChannel(string name, int channelID)
        {
            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.ExcludeFromChannel);
            message.AddString(name);
            message.AddU16((ushort)channelID);
            WriteToOutput(message);
        }
Ejemplo n.º 5
0
        public void SendUseTwoObjects(UnityEngine.Vector3Int firstPosition, uint firstID, int firstData, UnityEngine.Vector3Int secondPosition, uint secondID, int secondData)
        {
            if (firstPosition.x != 65535 || secondPosition.x != 65535)
            {
                m_Player.StopAutowalk(false);
            }

            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.UseTwoObject);
            message.AddPosition(firstPosition);
            message.AddU16((ushort)firstID);
            message.AddU8((byte)firstData);
            message.AddPosition(secondPosition);
            message.AddU16((ushort)secondID);
            message.AddU8((byte)secondData);
            WriteToOutput(message);
        }
Ejemplo n.º 6
0
        public void SendLook(UnityEngine.Vector3Int position, uint typeID, int stackPosition)
        {
            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.Look);
            message.AddPosition(position);
            message.AddU16((ushort)typeID);
            message.AddU8((byte)stackPosition);
            WriteToOutput(message);
        }
Ejemplo n.º 7
0
        public void SendUseOnCreature(UnityEngine.Vector3Int position, uint typeID, int positionOrData, uint creatureID)
        {
            if (position.x != 65535)
            {
                m_Player.StopAutowalk(false);
            }

            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.UseObject);
            message.AddPosition(position);
            message.AddU16((ushort)typeID);
            message.AddU8((byte)positionOrData);
            message.AddU32(creatureID);
            WriteToOutput(message);
        }
Ejemplo n.º 8
0
        protected void SendLogin()
        {
            OutputMessage message = new OutputMessage();

            message.AddU8(ClientLoginOpCodes.EnterAccount);
            message.AddU16(Utility.OperatingSystem.GetCurrentOs());

            var gameManager = OpenTibiaUnity.GameManager;

            message.AddU16((ushort)gameManager.ProtocolVersion);
            if (gameManager.GetFeature(GameFeatures.GameClientVersion))
            {
                message.AddU32((uint)gameManager.ClientVersion);
            }

            if (gameManager.GetFeature(GameFeatures.GameContentRevision))
            {
                message.AddU16(Constants.ContentRevision);
                message.AddU16(0);
            }
            else
            {
                message.AddU32(Constants.DatSignature);
            }

            message.AddU32(Constants.SprSignature);
            message.AddU32(Constants.PicSignature);

            if (gameManager.GetFeature(GameFeatures.GamePreviewState))
            {
                message.AddU8(0x00);
            }

            int offset = message.Tell();
            var random = new System.Random();

            if (gameManager.GetFeature(GameFeatures.GameLoginPacketEncryption))
            {
                message.AddU8(0); // first byte must be zero

                GenerateXteaKey(random);
                AddXteaKey(message);
            }

            if (gameManager.GetFeature(GameFeatures.GameAccountNames))
            {
                message.AddString(AccountName);
            }
            else
            {
                message.AddU32(uint.Parse(AccountName));
            }

            message.AddString(Password);

            int paddingBytes = Crypto.RSA.GetRsaSize() - (message.Tell() - offset);

            for (int i = 0; i < paddingBytes; i++)
            {
                message.AddU8((byte)random.Next(0xFF));
            }

            if (gameManager.GetFeature(GameFeatures.GameLoginPacketEncryption))
            {
                Crypto.RSA.EncryptMessage(message);
            }

            if (gameManager.GetFeature(GameFeatures.GameOGLInformation))
            {
                message.AddU8(1);
                message.AddU8(1);

                if (gameManager.ClientVersion >= 1072)
                {
                    message.AddString(string.Format("{0} {1}", OpenTibiaUnity.GraphicsVendor, OpenTibiaUnity.GraphicsDevice));
                }
                else
                {
                    message.AddString(OpenTibiaUnity.GraphicsDevice);
                }

                message.AddString(OpenTibiaUnity.GraphicsVersion);
            }

            if (gameManager.GetFeature(GameFeatures.GameAuthenticator))
            {
                offset = message.Tell();

                message.AddU8(0);
                message.AddString(string.Empty); // no auth-token

                message.AddU8(0);                // stay logged-in for a while

                paddingBytes = Crypto.RSA.GetRsaSize() - (message.Tell() - offset);
                for (int i = 0; i < paddingBytes; i++)
                {
                    message.AddU8((byte)random.Next(0xFF));
                }

                Crypto.RSA.EncryptMessage(message);
            }

            if (gameManager.GetFeature(GameFeatures.GameProtocolChecksum))
            {
                ChecksumEnabled = true;
            }

            WriteToOutput(message);

            if (gameManager.GetFeature(GameFeatures.GameLoginPacketEncryption))
            {
                XteaEnabled = true;
            }
        }
Ejemplo n.º 9
0
        // TODO: use a pool instead
        // and confirm the encryption of the packet ONLY on a successful sent
        // This is working, but using a pool is more of a robust

        public void SendLoginPacket(uint challengeTimestamp, byte challengeRandom)
        {
            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.PendingGame);
            message.AddU16(Utility.OperatingSystem.GetCurrentOs());

            var gameManager = OpenTibiaUnity.GameManager;

            message.AddU16((ushort)gameManager.ProtocolVersion);
            if (gameManager.GetFeature(GameFeatures.GameClientVersion))
            {
                message.AddU32((uint)gameManager.ClientVersion);
            }

            if (gameManager.GetFeature(GameFeatures.GameContentRevision))
            {
                message.AddU16(Constants.ContentRevision);
            }

            if (gameManager.GetFeature(GameFeatures.GamePreviewState))
            {
                message.AddU8(0);
            }

            int offset = message.Tell();

            message.AddU8(0); // first byte must be zero;

            var random = new System.Random();

            if (gameManager.GetFeature(GameFeatures.GameLoginPacketEncryption))
            {
                GenerateXteaKey(random);
                AddXteaKey(message);
                message.AddU8(0x00); // gm
            }

            if (gameManager.GetFeature(GameFeatures.GameSessionKey))
            {
                message.AddString(SessionKey);
                message.AddString(CharacterName);
            }
            else
            {
                if (gameManager.GetFeature(GameFeatures.GameAccountNames))
                {
                    message.AddString(AccountName);
                }
                else
                {
                    message.AddU32(uint.Parse(AccountName));
                }

                message.AddString(CharacterName);
                message.AddString(Password);

                if (gameManager.GetFeature(GameFeatures.GameAuthenticator))
                {
                    message.AddString(AuthenticatorToken);
                }
            }

            if (gameManager.GetFeature(GameFeatures.GameChallengeOnLogin))
            {
                message.AddU32(challengeTimestamp);
                message.AddU8(challengeRandom);
            }

            int paddingBytes = Crypto.RSA.GetRsaSize() - (message.Tell() - offset);

            for (int i = 0; i < paddingBytes; i++)
            {
                message.AddU8((byte)random.Next(0xFF));
            }

            if (gameManager.GetFeature(GameFeatures.GameLoginPacketEncryption))
            {
                Crypto.RSA.EncryptMessage(message);
            }

            if (gameManager.GetFeature(GameFeatures.GameProtocolChecksum))
            {
                ChecksumEnabled = true;
            }

            WriteToOutput(message);

            if (gameManager.GetFeature(GameFeatures.GameLoginPacketEncryption))
            {
                XteaEnabled = true;
            }
        }