Exemplo n.º 1
0
        public void SendPacket(GSASendPacket packet)
        {
            packet._Client = this;

            if (!GSOpcode.Send.ContainsKey(packet.GetType()))
            {
                Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
                return;
            }

            try
            {
                packet.WriteH(GSOpcode.Send[packet.GetType()]); // opcode
                packet.WriteH(0); // packet len
                packet.Write();

                byte[] Data = packet.ToByteArray();
                BitConverter.GetBytes((short)(Data.Length - 4)).CopyTo(Data, 2);

                //if(Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
                _stream = _client.GetStream();
                _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
            }
            catch (Exception ex)
            {
                Log.Warn("Can't send GS packet: {0}", GetType().Name);
                Log.WarnException("GSASendPacket", ex);
                return;
            }
        }
Exemplo n.º 2
0
        public void SendPacket(GSASendPacket packet)
        {
            packet._Client = this;

            if (!GSOpcode.Send.ContainsKey(packet.GetType()))
            {
                Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
                return;
            }

            try
            {
                packet.WriteH(GSOpcode.Send[packet.GetType()]); // opcode
                packet.WriteH(0);                               // packet len
                packet.Write();

                byte[] Data = packet.ToByteArray();
                BitConverter.GetBytes((short)(Data.Length - 4)).CopyTo(Data, 2);

                //if(Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
                _stream = _client.GetStream();
                _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
            }
            catch (Exception ex)
            {
                Log.Warn("Can't send GS packet: {0}", GetType().Name);
                Log.WarnException("GSASendPacket", ex);
                return;
            }
        }