예제 #1
0
        /// <summary>
        /// Removes a <see cref="ConnectionCore"/> from the <see cref="Chatroom"/>.
        /// </summary>
        public void Leave(ConnectionCore connection)
        {
            BroadcastChatMessage(connection, BroadcastType.UserLeftChatRoom);

            if (ChatroomUsers.Contains(connection))
            {
                ChatroomUsers.Remove(connection);

                ServerLogger.Chatroom(string.Format("{1}({0}) has disconnected from a chatroom.", connection.ID, connection.ConnectionData.Username));
            }
            else
            {
                ServerLogger.Error(string.Format("{1}({0}) cannot disconnect from a chatroom.", connection.ID, connection.ConnectionData.Username));
            }

            if (Private)
            {
                connection.SendMessage(new RemovePrivateRoomComposer(ID));
            }

            if (ChatroomUsers.Count == 0)
            {
                ServerLogger.Warning(string.Format("Chatroom {0} is empty.", ID.ToString()));
                connection.ServerManager.ChatroomManager.RemoveChatroom(ID);
                ServerLogger.Chatroom(string.Format("Chatroom {0} has been deleted.", ID.ToString()));
            }
        }
예제 #2
0
        /// <summary>
        /// Adds a <see cref="ConnectionCore"/> to the <see cref="Chatroom"/>.
        /// </summary>
        public void Join(ConnectionCore connection)
        {
            if (!Private)
            {
                BroadcastChatMessage(connection, BroadcastType.UserJoinedChatRoom);
            }

            if (!ChatroomUsers.Contains(connection))
            {
                ChatroomUsers.Add(connection);
                ServerLogger.Chatroom(string.Format("{1}({0}) has connected to a chatroom.", connection.ID, connection.ConnectionData.Username));
            }
        }