Beispiel #1
0
 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");
 }
Beispiel #2
0
        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;
        }
Beispiel #3
0
 public virtual Message generateMessage(User user, int chatroom,string message) => new Message(user,chatroom, true, message);
Beispiel #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);
					}
				}
			}
		}
Beispiel #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;
				}
			}
		}
Beispiel #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);
					
				}
			}
		}