Example #1
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the client.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            string name = message.ReadString();

            connection.ConnectionData.Username = name;

            connection.SendMessage(new InitializeConnectionComposer(connection.ID));
            connection.SendMessage(new InitializeChatroomsComposer(connection.ServerManager.ChatroomManager.Chatrooms));
        }
Example #2
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()));
            }
        }
Example #3
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the client.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int clientTime = message.ReadInt32();
            int serverTime = (int)(DateTime.UtcNow.Subtract(new DateTime(2016, 1, 1))).TotalMilliseconds;

            connection.SendMessage(new KeepAlivePacketComposer(clientTime, serverTime));
        }
Example #4
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the client.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int    chatroomId = message.ReadInt32();
            string password   = message.ReadString();

            JoinState state = connection.ServerManager.ChatroomManager.JoinChatroom(chatroomId, password, connection);

            connection.SendMessage(new JoinChatroomComposer(chatroomId, state));
        }
        /// <summary>
        /// Creates and returns a private chatroom.
        /// </summary>
        public Chatroom CreatePrivateRoom(int joincount)
        {
            if (ConnectionQueue.Count < joincount)
            {
                return(null);
            }

            Chatroom privateRoom = new Chatroom(ServerManager.ChatroomManager.LastRoomId++);

            PrivateChatrooms.Add(privateRoom.ID, privateRoom);
            ServerManager.ChatroomManager.AddChatroom(privateRoom);

            for (int i = 0; i < joincount; i++)
            {
                ConnectionCore core = ConnectionQueue.Dequeue();

                privateRoom.Join(core);
                core.SendMessage(new CreatePrivateRoomComposer(privateRoom));
                core.SendMessage(new JoinChatroomComposer(privateRoom.ID, JoinState.JoinChatRoomOk));
            }

            return(privateRoom);
        }
Example #6
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the client.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            string roomName = message.ReadString();
            string roomDesc = message.ReadString();
            string roomPass = message.ReadString();

            if (!string.IsNullOrEmpty(roomName))
            {
                var chatroom = connection.ServerManager.ChatroomManager.CreateChatRoom(roomName, roomDesc, roomPass, connection);
                if (chatroom != null)
                {
                    connection.SendMessage(new JoinChatroomComposer(chatroom.ID, JoinState.JoinChatRoomOk));
                }
            }
        }
Example #7
0
 /// <summary>
 /// Initializes all the chatrooms for a connection.
 /// </summary>
 public void InitializeChatrooms(ConnectionCore connection)
 {
     connection.SendMessage(new InitializeChatroomsComposer(Chatrooms));
 }