Exemplo n.º 1
0
Arquivo: cServer.cs Projeto: kper/chat
 public cServer(Action<string,Color> stdout,Color adm_color)
 {
     Chatrooms = new ObservableCollection<Chatroom>();
     CreateInitChatRooms();
     this.stdout = stdout;
     this.admin_color = adm_color;
     admin = new User("Server");
 }
Exemplo n.º 2
0
Arquivo: cClient.cs Projeto: kper/chat
        public cClient(User user,Action<string,Color> stdout)
        {
            connection = new Socket(SocketType.Stream, ProtocolType.Tcp);
            formatter = new BinaryFormatter();
            Messages = new ObservableCollection<Message>();
            this.stdout = stdout;
            Messages.CollectionChanged += Messages_CollectionChanged;

            this.user = user;
            this.chatroom = 0;
        }
Exemplo n.º 3
0
Arquivo: cClient.cs Projeto: kper/chat
 public virtual Message generateMessage(User user, int chatroom,string message) => new Message(user,chatroom, true, message);
Exemplo n.º 4
0
		/// <summary>
		/// Adds [GlobalMaxItems] items from this room to a user
		/// </summary>
		public void UpdateUserWithLatestPosts(User user)
		{
			if (!user.Online)
				return;

			lock (itemCache)
			{
				if (itemCache.Count > 0)
				{
					int i = 0;
					if (itemCache.Count > ChatServer.GlobalMaxItems)
						i = itemCache.Count - ChatServer.GlobalMaxItems;


					for (; i < itemCache.Count; i++)
					{
						user.Update(itemCache[i].Item, itemCache[i].ItemGuid, itemCache[i].RoomGuid, itemCache[i].DateTime);
					}
				}
			}
		}
Exemplo n.º 5
0
		/// <summary>
		/// Unregisters a user from this room, and disables all items from this room in their cache.
		/// </summary>
		public void UnRegister(User user, bool disableItemsAndRemoveRoomFromUser)
		{
			if (users.ContainsKey(user.UsrK))
			{
				lock (users)
				{
					if (!users.ContainsKey(user.UsrK))
						return;

					users.Remove(user.UsrK);

					if (disableItemsAndRemoveRoomFromUser)
					{
						user.RemoveRoom(this);
						user.DisableAllItems(this.RoomGuid);
					}

					lastUserExited = DateTime.Now;
				}
			}
		}
Exemplo n.º 6
0
		/// <summary>
		/// Ensures that a user is registered in this room, and adds the latest posts from this room to their cache.
		/// </summary>
		public void EnsureRegistered(User user)
		{
			if (!users.ContainsKey(user.UsrK))
			{
				lock (users)
				{
					if (users.ContainsKey(user.UsrK))
						return;

					users.Add(user.UsrK, user);

					user.AddRoom(this);

					UpdateUserWithLatestPosts(user);
					
				}
			}
		}