예제 #1
0
        public static void OnConnected(IAsyncResult connected)
        {
            C2CS_GameUserLogin lg = GenerateStLogin();

            RpcSendHander.Send_GameUserLogin(lg);

            if (m_timer == null)
            {
                m_timer = new Timer(OnTick, null, 0, 20000);
            }

            OnRecvStateMsg(EMsgState.eOnConnected, string.Format("OnConnected->{0}:{1}", m_sIp, m_nPort));
        }
예제 #2
0
        private static C2CS_GameUserLogin GenerateStLogin()
        {
            C2CS_GameUserLogin gul = new C2CS_GameUserLogin();

            gul.bCLLogin = true;
            gul.uRcpId   = 10;
            gul.nRcpCode = 10;
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            int             timeStamp = (int)(DateTime.Now - startTime).TotalSeconds;                          // 相差秒数

            gul.uRcpTime   = timeStamp;
            gul.nUserId    = 10;
            gul.uChannelId = GameMgr.Instance.GetChannel();
            gul.szPassword = new Byte[64];
            Array.Clear(gul.szPassword, 0, 64);
            byte[] bytes = Encoding.Default.GetBytes(m_sToken);
            System.Buffer.BlockCopy(bytes, 0, gul.szPassword, 0, bytes.Length);

            gul.szIp = new Byte[16];
            Array.Clear(gul.szIp, 0, 16);
            bytes = Encoding.Default.GetBytes("127.0.0.1");
            System.Buffer.BlockCopy(bytes, 0, gul.szIp, 0, bytes.Length);

            gul.uMachineId      = 3;
            gul.uMachineIdHash  = 10;
            gul.nVersionLength  = 16;
            gul.uPassportLength = 128;

            gul.sVersion = new Byte[16];
            Array.Clear(gul.sVersion, 0, 16);
            string sversion = GameMgr.Instance.GetGameVersion();

            bytes = Encoding.Default.GetBytes(sversion);
            System.Buffer.BlockCopy(bytes, 0, gul.sVersion, 0, bytes.Length);

            gul.sPassport = new Byte[128];
            Array.Clear(gul.sPassport, 0, 128);

            bytes = Encoding.Default.GetBytes(m_sOpenId);
            System.Buffer.BlockCopy(bytes, 0, gul.sPassport, 0, bytes.Length);

            return(gul);
        }