Exemplo n.º 1
0
 public void AddLoginUser(User user, IMClientPeer peer)
 {
     //重复登录
     if (user == peer.LoginUser)
     {
         return;
     }
     //同一个peer切换用户
     if (peer.LoginUser != null)
     {
         if (mLoginUsers.ContainsKey(peer.LoginUser.Username))
         {
             mLoginUsers.Remove(peer.LoginUser.Username);
         }
     }
     if (mLoginUsers.TryGetValue(user.Username, out var oldPeer))
     {
         //重复登录
         if (oldPeer == peer)
         {
             return;
         }
         //旧的挤掉线
         mLogger.InfoFormat("挤掉线。旧客户端:{0},新客户端:{1},用户名:{2}", oldPeer, peer, user.Username);
         oldPeer.Disconnect();
         mLoginUsers[user.Username] = peer;
     }
     else
     {
         mLoginUsers.Add(user.Username, peer);
     }
     peer.LoginUser = user;
 }
Exemplo n.º 2
0
        public void RemoveLoginUser(IMClientPeer peer)
        {
            if (peer.LoginUser == null)
            {
                return;
            }
            string username = peer.LoginUser.Username;

            if (string.IsNullOrEmpty(username))
            {
                return;
            }
            //现在登陆的和掉线的不是同一个客户端
            if (!mLoginUsers.TryGetValue(username, out var nowPeer) || nowPeer != peer)
            {
                return;
            }
            mLoginUsers.Remove(username);
        }
Exemplo n.º 3
0
 public bool TryGetPeerByUsername(string username, out IMClientPeer peer)
 {
     return(mLoginUsers.TryGetValue(username, out peer));
 }