Example #1
0
        public bool _pinAck     = true;                                // is this ping action has been responsed.
        //private Dictionary<int, int> _lastPing = new Dictionary<int, int>();

        public void SendPing()
        {
            // unless we got the last ping msg back, or we wont do this ping action agian.
            UInt32 now = (UInt32)DateTime.UtcNow.Millisecond;

            if (!_pinAck)
            {
                Console.WriteLine("     Sending failed."
                                  + "did not get ack for ping id : {0} \n"
                                  + "which sent in sec: {1} \n"
                                  + "           now is: {2} \n"
                                  + "      latencey is: {3} \n"
                                  , _ping
                                  , _lastPing
                                  , now
                                  , _latencey);
                return;
            }

            System.Random ro = new System.Random();
            _ping     = (UInt32)ro.Next(0, 60000);
            _lastPing = now;
            _pinAck   = false;

            WorldPack pack = new WorldPack(Opcodes.CMSG_PING, 100 + 2 * sizeof(UInt32));

            pack.W((UInt32)_ping);
            pack.W((UInt32)_latencey); // this is calculate on last pong.
            OutPacket(pack);
        }
Example #2
0
        // 客户端登陆请求发起。
        // 被认证的账号才可以进行其他游戏数据操作。
        // 被认证的账号才可以选择角色登陆。
        // 认证之后将返回SMSG_AUTH_RESPONSE
        public void c_Login(string acc, string pwd)
        {
            WorldPack pack = new WorldPack(Opcodes.CMSG_AUTH_SESSION, (ushort)(acc.Length + pwd.Length + 4));

            pack.W(acc);
            pack.W(pwd);
            OutPacket(pack);
        }
Example #3
0
        void KeepAlive(Int32 now)
        {
            WorldPack pack = new WorldPack();

            pack.W(SYS_PACKET_KEEP_ALIVE);
            pack.W(now);
            pack.W(1);
            gcOutPacket(pack, true);
        }
Example #4
0
        /// <summary>
        /// 当前如果是认证状态,则可以发起角色进入游戏请求.如果成功,随后会返回初始化数据.
        /// 否则返回 SMSG_CHARACTER_LOGIN_FAILED
        /// </summary>
        /// <param name="charID"></param>
        public void c_Logon(UInt16 charID)  // 使用角色登陆游戏请求。
        {
            WorldPack pack = new WorldPack(Opcodes.CMSG_PLAYER_LOGIN, sizeof(UInt16));

            pack.W((UInt16)charID);
            OutPacket(pack);
        }
Example #5
0
        // pack for 3K, for 100 clients's sending. server will broad cast this test login msg.
        public void SendContens()
        {
            WorldPack pack = new WorldPack(Opcodes.MSG_GM_SUMMON, 3096);

            for (int i = 0; i < 100; i++)
            {
                pack.W("有人从很远很远的地方尝试调用 connect()来连接你的机器上的某个端口(当然是你已经在 listen()的");
            }
        }
Example #6
0
        bool HandleSysPack(WorldPack pack)
        {
            Debug.Log("SystemPack Start");
            if (!pack.isSystem)
            {
                return(false);
            }
            short type  = 0;
            Int16 param = 0;

            pack.R(ref type);
            Debug.Log("SystemPack " + type.ToString());
            switch (type)
            {
            case SYS_PACKET_KEEP_ALIVE:
                pack.R(ref param);
                // Sys_Log("recv keep alive msg");
                byte      p1 = 1;
                WorldPack pk = new WorldPack();
                pk.W(SYS_PACKET_ALIVE_ACK);
                pk.W(param);
                pk.W(p1);
                gcOutPacket(pk, true);
                break;

            case SYS_PACKET_ALIVE_ACK:
                pack.R(ref param);
                // Sys_Log("recv alive ack msg");
                m_rtt = Time.time - (float)param / 1000.0f;
                break;

            case SYS_PACKET_SET_SEED:
            {
                pack.R(ref param);
                SetSeed(param);
                ConnectWorkFinish(true);
            }
            break;

            default:
                return(false);
            }
            return(true);
        }
Example #7
0
        WorldPack rpcToPack(string methodName, params object[] par)
        {
            WorldPack pack  = new WorldPack(Opcodes.CMSG_GODMODE, (UInt16)(methodName.Length * 2 + 2 + 8000));
            UInt32    prams = 0;

            pack.W(prams);
            pack.W(methodName);
            int    count = 0;
            UInt32 type  = 0;

            foreach (object ob in par)
            {
                if (ob is System.Int32)
                {
                    pack.W((Int32)ob);
                    type = LUA_TBNUMBER;
                }
                else if (ob is System.Int16)
                {
                    Int16 temp = (Int16)ob;
                    pack.W((Int32)temp);
                    type = LUA_TBNUMBER;
                }
                else if (ob is System.UInt16)
                {
                    UInt16 temp = (UInt16)ob;
                    pack.W((Int32)temp);
                    type = LUA_TBNUMBER;
                }
                else if (ob is System.UInt32)
                {
                    pack.W((UInt32)ob);
                    type = LUA_TFUNCTION;
                }
                else if (ob is System.Int64)
                {
                    Int64 temp = (Int64)ob;
                    pack.W((Int64)temp);
                    type = LUA_TUSERDATA;
                }
                else if (ob is System.Boolean)
                {
                    pack.W((Boolean)ob);
                    type = LUA_TBOOLEAN;
                }
                else if (ob is System.String)
                {
                    pack.W((string)ob);
                    type = LUA_TSTRING;
                }
                else
                {
                    Debug.LogError("RPC: callServerMethod Got unknown data type methods");
                }

                prams = (prams | (type & 0xf) << 3 * count++);
            }
            pack.wpos(0);
            pack.W(prams);

            return(pack);
        }