Beispiel #1
0
        // public bool Friend()
        /// <summary>
        ///
        /// </summary>
        /// <param name="Conn">TCP连接</param>
        /// <param name="receipt">登录凭证</param>
        /// <param name="ISReConn">是否是重连</param>
        public void CheckOpenid(TCP Conn, LoginReceipt receipt, bool ISReConn)
        {
            MySqlConnection mySql = new MySqlConnection(Sqlconnstr);

            mySql.Open();
            string       cmdStr = string.Format("select * from User where Openid='{0}';", receipt.UserOpenid);
            MySqlCommand cmd    = new MySqlCommand(cmdStr, mySql);

            try
            {
                MySqlDataReader reader  = cmd.ExecuteReader();
                bool            HasRows = reader.HasRows;
                reader.Close();
                cmd.Dispose();
                if (HasRows)
                {
                    HandleConnMethodPool.TrueCheckOpenid(Conn, receipt, ISReConn);
                }
                else
                {
                    HandleConnMethodPool.FalseCheckOpenid(Conn);
                }
            }
            catch (Exception e)
            {
                cmd.Dispose();
                Console.WriteLine("[DataMgr] CheckOpenid :" + e.Message + Thread.CurrentThread.Name);
                HandleConnMethodPool.FalseCheckOpenid(Conn);
            }
            mySql.Close();
            cmd.Dispose();
        }
        /// <summary>
        /// 登录校验
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="protocoBase"></param>
        public void CheckOpenid(TCP conn, ProtocolBase protocoBase)//登录校验
        {
            ProtocolBytes bytes        = (ProtocolBytes)protocoBase;
            LoginReceipt  LReceipt     = JsonConvert.DeserializeObject <LoginReceipt>(bytes.GetDecode()[1].ToString());
            Thread        ChechOpenidT = new Thread(new ThreadStart(delegate { DataMgr.instance.CheckOpenid(conn, LReceipt, false); }))
            {
                Name = LReceipt.UserOpenid
            };

            ChechOpenidT.Start();
        }
 public void Reconnect(TCP conn, ProtocolBase proto)
 {
     try
     {
         ProtocolBytes bytes   = (ProtocolBytes)proto;
         object[]      vs      = bytes.GetDecode();
         LoginReceipt  receipt = JsonConvert.DeserializeObject <LoginReceipt>(bytes.GetDecode()[1].ToString());
         for (int i = 0; i < NMC.instance.tcps.Length; i++)
         {
             if (NMC.instance.tcps[i] == null)
             {
                 continue;
             }
             if (NMC.instance.tcps[i].Player == null)
             {
                 continue;
             }
             if (NMC.instance.tcps[i].Player.Openid == receipt.UserOpenid)
             {
                 if (NMC.instance.tcps[i].Player.NowDeviceUID != receipt.DeviceUID)
                 {
                     Console.WriteLine("ReConnection Check failed");
                     NMC.instance.CloseTCP(conn);
                     return;
                 }
                 conn.Player          = NMC.instance.tcps[i].Player;
                 conn.Player.Conn     = conn;
                 NMC.instance.tcps[i] = null;
                 ProtocolBytes Ret = new ProtocolBytes();
                 Ret.SetProtocol(Fursion_Protocol.ReConnectRet);
                 conn.Send(Ret);
                 return;
             }
             else
             {
                 NMC.instance.CloseTCP(conn);
             }
         }
         Console.WriteLine(" This User Not Find ");
         Thread ChechOpenidT = new Thread(new ThreadStart(delegate { DataMgr.instance.CheckOpenid(conn, receipt, true); }))
         {
             Name = receipt.UserOpenid
         };
         ChechOpenidT.Start();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message + " ReConnect");
     }
 }
        public static void TrueCheckOpenid(TCP conn, LoginReceipt receipt, bool ISReConn)
        {
            ProtocolBytes RetBytes = new ProtocolBytes();

            RetBytes.SetProtocol(Fursion_Protocol.CheckOpenid);
            if (receipt.OnlineRec)
            {
                if (Player.Kickoff(receipt.UserOpenid, false))
                {
                    RetBytes.AddData(2);
                    conn.Send(RetBytes);
                    return;
                }
            }
            else
            {
                if (Player.Kickoff(receipt.UserOpenid, true))
                {
                    RetBytes.AddData(2);
                    conn.Send(RetBytes);
                    return;
                }
            }
            PlayerData playerData = DataMgr.instance.GetPlayerData(receipt.UserOpenid);

            if (playerData == null)
            {
                RetBytes.AddData(-1);
                conn.Send(RetBytes);
                return;
            }
            conn.Player = new Player(receipt.UserOpenid, conn)
            {
                Data = playerData
            };
            conn.Player.NowDeviceUID = receipt.DeviceUID;
            RetBytes.AddData(0);//Success
            conn.Player.UserData = DataMgr.instance.GetUserData(conn.Player.Openid);
            Friend friend = FriendMC.A.InitFriendListInfo(conn.Player);

            if (friend.GoodList.Keys.Count != 0)
            {
                ProtocolBytes onlineRet = new ProtocolBytes();
                onlineRet.SetProtocol(Fursion_Protocol.Friend_OnlineNotice);
                onlineRet.AddData(conn.Player.Openid);
                foreach (string id in friend.GoodList.Keys)
                {
                    if (FriendMC.OnlinePlayerList.ContainsKey(id))
                    {
                        FriendMC.OnlinePlayerList[id].Send(onlineRet);
                    }
                }
            }
            string FriendListStr = JsonConvert.SerializeObject(friend);

            RetBytes.AddData(FriendListStr);
            ServerMC.This.GetServerInfo(RetBytes, conn);
            if (ISReConn)
            {
                ProtocolBytes Ret = new ProtocolBytes();
                Ret.SetProtocol(Fursion_Protocol.ReConnectRet);
                conn.Send(Ret);
            }
            Console.WriteLine("登录成功******发送   ");
        }