Esempio n. 1
0
        public void AddCmdPacket(CmdPacket packet)
        {
            ushort dataSize = System.Convert.ToUInt16(packet.GetDataSize());

            m_pktFlag     = PROTOCOL_FLAG << 4;
            m_pktDataSize = dataSize;
            m_buffer.Clear();
            m_buffer.AddRange(packet.GetData());
        }
Esempio n. 2
0
        void OnReceive(CmdPacket packet)
        {
            short cmd = 0;

            packet.ReadShort(ref cmd);
            string ret = "";

            packet.ReadString(ref ret);
            Sys_Log(ret);
        }
Esempio n. 3
0
        int HandleSysPacket(CmdPacket packet)
        {
            short type  = 0;
            uint  param = 0;

            if (!packet.ReadShort(ref type))
            {
                return(0);
            }
            switch (type)
            {
            case SYS_PACKET_KEEP_ALIVE:
                if (!packet.ReadUInt(ref param))
                {
                    return(0);
                }
                Sys_Log("recv keep alive msg");
                m_sendCmdPkt.BeginWrite();
                m_sendCmdPkt.WriteShort(SYS_PACKET_ALIVE_ACK);
                m_sendCmdPkt.WriteInt((int)param);
                SendPacket(m_sendCmdPkt, true, true);
                break;

            case SYS_PACKET_ALIVE_ACK:
                if (!packet.ReadUInt(ref param))
                {
                    return(0);
                }
                Sys_Log("recv alive ack msg");
                m_rtt = Sys_GetTime() - param;
                break;

            case SYS_PACKET_SET_SEED:
                if (!packet.ReadUInt(ref param))
                {
                    return(0);
                }
                SetSeed(param);
                m_state = TNetState.NET_STATE_CONNECTED;
                OnConnect(true);
                break;

            default:
                return(0);
            }
            return(type);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            TcpSession client = new TcpSession();

            client.Connect("127.0.0.1", 8885);
            while (true)
            {
                string say = Console.ReadLine();
                if (say.Length > 0)
                {
                    CmdPacket packet = new CmdPacket();
                    packet.BeginWrite();
                    packet.WriteShort(22);
                    packet.WriteString(say);
                    client.SendPacket(packet);
                }
            }
        }
Esempio n. 5
0
 bool GetPacket(CmdPacket packet)
 {
     while (RecvPacket(m_recvNetPkt))
     {
         /* attach a cmd packet for read */
         m_recvNetPkt.AttachCmdPacket(packet);
         if (m_recvNetPkt.IsSysPacket())
         {
             /* if a system msg packet,handle it */
             HandleSysPacket(packet);
             continue;
         }
         else
         {
             /* get a user data packet,return */
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
 bool SendPacket(CmdPacket packet, bool flush, bool sys)
 {
     lock (m_sendNetPkt)
     {
         if (m_state != TNetState.NET_STATE_CONNECTED)
         {
             return(false);
         }
         m_seq++;
         if (m_seq > MAX_NET_PACKET_SEQ)
         {
             m_seq = 1;
         }
         m_sendNetPkt.AddCmdPacket(packet);
         m_sendNetPkt.SetSeq(m_seq);
         if (sys)
         {
             m_sendNetPkt.SetSysPacket();
         }
         else
         {
             if (m_bEncrypt)
             {
                 m_sendNetPkt.Encrypt(m_seed, m_seedLen);
             }
             if (m_bCompress)
             {
                 m_sendNetPkt.Compress();
             }
         }
         PushData(m_sendNetPkt.GetBuffer());
         if (flush)
         {
             FlushData();
         }
         return(true);
     }
 }
Esempio n. 7
0
 public void AttachCmdPacket(CmdPacket packet)
 {
     packet.BeginRead(m_buffer);
 }
Esempio n. 8
0
 public void SendPacket(CmdPacket packet)
 {
     SendPacket(packet, false, false);
 }