/// <summary>
 /// 新增一个在线的客户端
 /// </summary>
 /// <param name="account"></param>
 public void AddOnlineClient(NetAccount account)
 {
     hybirdLock.Enter();
     OnlineClients.Add(account);
     m_ClientsOnlineCache = JArray.FromObject(OnlineClients).ToString();
     hybirdLock.Leave();
 }
        private bool disposedValue = false; // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (groupName == MagicStrings.DefaultGroup)
            {
                throw new InvalidOperationException("不允许销毁默认组");
            }
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 释放托管状态(托管对象)。
                    Owner = null;
#if DEBUG
                    Console.WriteLine($"解散组 {this.groupName} 中共有{this.OnlineClients.Count}人");
#endif
                    foreach (var onlineClient in OnlineClients)
                    {
                        onlineClient.QuitGroup(this.groupName, null);
                    }
                    OnlineClients.Clear();
                }

                // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
                // TODO: 将大型字段设置为 null。
                GroupName = null;

                disposedValue = true;
            }
        }
 public void OnNavigatedTo(NavigationContext navigationContext)
 {
     Console.WriteLine("OnNavigatedTo");
     _modules.LoadModule(nameof(ProgressModule));
     Console.WriteLine(SelfToken.OnlineState);
     ClientProxy.Open();
     ClientProxy.UpdateWhoIam(SelfToken);
     OnlineClients.Clear();
     this.OnlineClients.AddRange(ClientProxy.GetOnlineUsers(SelfToken));
 }
        private void RemoteServicePush_UserOnlineStateChanged(ClientToken obj)
        {
            Console.WriteLine($"RemotePush {obj.NickName} {obj.OnlineState}");
            var client = ClientTokenList.Find(OnlineClients.ToList(), obj);

            if (client == null)
            {
                OnlineClients.Add(obj);
            }
            else
            {
                ClientToken.PropertyCopy(obj, client);
            }
        }
예제 #5
0
        void ProcessClientInfo(Message msg, IPEndPoint iPEnd)
        {
            string name = (string)msg.Data;

            if (OnlineClients.ContainsKey(name))
            {
                OnlineClients[name].Time = 0;
            }
            else
            {
                Client client = new Client {
                    Name = name, IPEnd = iPEnd, Time = 0
                };
                OnlineClients[name] = client;
            }
        }
        /// <summary>
        /// 根据在线客户端的唯一ID进行移除指定的客户端
        /// </summary>
        /// <param name="uniqueId"></param>
        public void RemoveOnlineClient(string uniqueId)
        {
            hybirdLock.Enter();

            int index = -1;

            for (int i = 0; i < OnlineClients.Count; i++)
            {
                if (OnlineClients[i].UniqueId == uniqueId)
                {
                    index = i;
                    break;
                }
            }

            if (index >= 0)
            {
                OnlineClients.RemoveAt(index);
            }

            m_ClientsOnlineCache = JArray.FromObject(OnlineClients).ToString();

            hybirdLock.Leave();
        }
예제 #7
0
 void ChectHeart()
 {
     checkTask = Task.Run(async() =>
     {
         while (!exit)
         {
             foreach (var client in OnlineClients.Values)
             {
                 client.Time++;
             }
             foreach (var room in OnlineRooms.Values)
             {
                 room.Time++;
             }
             DetectClients();
             DetectRooms();
             await Task.Delay(1000);
             var rmClientKeys = (from pair in OnlineClients where pair.Value.Time > 1 select pair.Key).ToList();
             rmClientKeys.Select(key => OnlineClients.TryRemove(key, out var v));
             var rmRoomKeys = (from pair in OnlineRooms where pair.Value.Time > 1 select pair.Key).ToList();
             rmRoomKeys.Select(key => OnlineRooms.TryRemove(key, out var v));
         }
     });
 }