Esempio n. 1
0
File: cServer.cs Progetto: 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");
 }
Esempio n. 2
0
File: cClient.cs Progetto: 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;
        }
Esempio n. 3
0
File: cClient.cs Progetto: kper/chat
 public virtual Message generateMessage(User user, int chatroom,string message) => new Message(user,chatroom, true, message);
Esempio 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);
					}
				}
			}
		}
Esempio 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;
				}
			}
		}
Esempio 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);
					
				}
			}
		}