Esempio n. 1
0
        private void OnMessageReceived(object sender, MessageEventArgs e)
        {
            OuterNetworkMessage message = (OuterNetworkMessage)e.Message;

            Buffer = message.Data;

            if (OuterNetworkOpcode.Recv.ContainsKey(message.Opcode))
            {
                string opCodeLittleEndianHex = BitConverter.GetBytes(message.Opcode).ToHex();
                Log.Debug("Recieve [{0}]: 0x{1}{2} [{3}]",
                          OuterNetworkOpcode.Recv[message.Opcode].Name,
                          opCodeLittleEndianHex.Substring(2),
                          opCodeLittleEndianHex.Substring(0, 2),
                          Buffer.Length);

                Log.Debug("Data:\n{0}", Buffer.FormatHex());

                ((OuterNetworkRecvPacket)Activator.CreateInstance(OuterNetworkOpcode.Recv[message.Opcode])).Process(this);
            }
            else
            {
                string opCodeLittleEndianHex = BitConverter.GetBytes(message.Opcode).ToHex();
                Log.Debug("Unknown InnerOpcode: 0x{0}{1} [{2}]",
                          opCodeLittleEndianHex.Substring(2),
                          opCodeLittleEndianHex.Substring(0, 2),
                          Buffer.Length);

                Log.Debug("Data:\n{0}", Buffer.FormatHex());
            }
        }
Esempio n. 2
0
        private bool Send()
        {
            OuterNetworkMessage message;

            if (SendLock == null)
            {
                return(false);
            }

            lock (SendLock)
            {
                if (SendData.Count == 0)
                {
                    return(Client.CommunicationState == CommunicationStates.Connected);
                }

                message = new OuterNetworkMessage {
                    Data = new byte[SendDataSize]
                };

                int pointer = 0;
                for (int i = 0; i < SendData.Count; i++)
                {
                    Array.Copy(SendData[i], 0, message.Data, pointer, SendData[i].Length);
                    pointer += SendData[i].Length;
                }

                SendData.Clear();
                SendDataSize = 0;
            }

            try
            {
                Client.SendMessage(message);
            }
            catch
            {
                //Already closed
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        private bool Send()
        {
            OuterNetworkMessage message;

            if (SendLock == null)
                return false;

            lock (SendLock)
            {
                if (SendData.Count == 0)
                    return Client.CommunicationState == CommunicationStates.Connected;

                message = new OuterNetworkMessage { Data = new byte[SendDataSize] };

                int pointer = 0;
                for (int i = 0; i < SendData.Count; i++)
                {
                    Array.Copy(SendData[i], 0, message.Data, pointer, SendData[i].Length);
                    pointer += SendData[i].Length;
                }

                SendData.Clear();
                SendDataSize = 0;
            }

            try
            {
                Client.SendMessage(message);
            }
            catch
            {
                //Already closed
                return false;
            }

            return true;
        }
Esempio n. 4
0
        private bool ReadMessage(List<IScsMessage> messages)
        {
            Stream.Position = 0;

            if (Stream.Length < 4)
                return false;

            int headerBytesLength = 8;
            int opcodeoffset = 4;
            int lengthoffset = 6;

            switch (WorldServer.CountryCode)
            {
                case CountryCode.CN:
                    {
                        headerBytesLength = 9;
                        opcodeoffset = 5;
                        lengthoffset = 7;
                    }
                    break;
                case CountryCode.EN:
                    {
                        headerBytesLength = 8;
                        opcodeoffset = 4;
                        lengthoffset = 6;
                    }
                    break;
                case CountryCode.TH:
                    {
                        headerBytesLength = 8;
                        opcodeoffset = 4;
                        lengthoffset = 6;
                    }
                    break;
                case CountryCode.TW:
                    {
                        headerBytesLength = 9;
                        opcodeoffset = 5;
                        lengthoffset = 7;
                    }
                    break;
            }

            byte[] headerBytes = new byte[headerBytesLength];
            Stream.Read(headerBytes, 0, headerBytesLength);

            int alllength = BitConverter.ToUInt16(headerBytes, 0);
            int sessionId = BitConverter.ToUInt16(headerBytes, 2);
            int opcode = BitConverter.ToUInt16(headerBytes, opcodeoffset);
            int length = BitConverter.ToUInt16(headerBytes, lengthoffset);

            if (opcode != 8 && Stream.Length < length)
                return false;

            OuterNetworkMessage message = new OuterNetworkMessage
            {
                TotalLength = (short)alllength,
                UserSession = (short)sessionId,
                Opcode = (short)opcode,
                Data = new byte[alllength - 6]
            };

            Stream.Read(message.Data, 0, message.Data.Length);

            messages.Add(message);

            TrimStream();

            return true;
        }
Esempio n. 5
0
        private bool ReadMessage(List <IScsMessage> messages)
        {
            Stream.Position = 0;

            if (Stream.Length < 4)
            {
                return(false);
            }

            int headerBytesLength = 8;
            int opcodeoffset      = 4;
            int lengthoffset      = 6;

            switch (WorldServer.CountryCode)
            {
            case CountryCode.CN:
            {
                headerBytesLength = 9;
                opcodeoffset      = 5;
                lengthoffset      = 7;
            }
            break;

            case CountryCode.EN:
            {
                headerBytesLength = 8;
                opcodeoffset      = 4;
                lengthoffset      = 6;
            }
            break;

            case CountryCode.TH:
            {
                headerBytesLength = 8;
                opcodeoffset      = 4;
                lengthoffset      = 6;
            }
            break;

            case CountryCode.TW:
            {
                headerBytesLength = 9;
                opcodeoffset      = 5;
                lengthoffset      = 7;
            }
            break;
            }

            byte[] headerBytes = new byte[headerBytesLength];
            Stream.Read(headerBytes, 0, headerBytesLength);

            int alllength = BitConverter.ToUInt16(headerBytes, 0);
            int sessionId = BitConverter.ToUInt16(headerBytes, 2);
            int opcode    = BitConverter.ToUInt16(headerBytes, opcodeoffset);
            int length    = BitConverter.ToUInt16(headerBytes, lengthoffset);

            if (opcode != 8 && Stream.Length < length)
            {
                return(false);
            }

            OuterNetworkMessage message = new OuterNetworkMessage
            {
                TotalLength = (short)alllength,
                UserSession = (short)sessionId,
                Opcode      = (short)opcode,
                Data        = new byte[alllength - 6]
            };

            Stream.Read(message.Data, 0, message.Data.Length);

            messages.Add(message);

            TrimStream();

            return(true);
        }