예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChatMessage"/> class as a normal message.
 /// </summary>
 public ChatMessage(int chatRoomId, int messageId, string message, ChatroomUser user)
 {
     ChatroomID   = chatRoomId;
     MessageID    = messageId;
     Message      = message;
     ChatroomUser = user;
     MessageType  = ChatMessageType.Message;
 }
예제 #2
0
        /// <summary>
        /// Joins a chatroom based on <see cref="Chatroom.ID"/>.
        /// </summary>
        public void JoinChatroom(int chatRoomId, JoinState state)
        {
            if (Chatrooms.ContainsKey(chatRoomId))
            {
                Chatroom room = Chatrooms[chatRoomId];
                OnChatroomJoined(new JoinedChatroomEventArgs(room, state));
                if (ClientManager.ConnectionCore.ConnectionId != -1 && state == JoinState.JoinChatRoomOk)
                {
                    ChatroomUser user = new ChatroomUser(ClientManager.ConnectionCore.ConnectionId, ClientManager.ConnectionCore.ConnectionData.Username);

                    // room.ChatRoomUsers.Add(user.ConnectionId, user);

                    room.IsInChatroom = true;
                }
            }
            else
            {
                OnChatroomJoined(new JoinedChatroomEventArgs(null, JoinState.JoinChatRoomError));
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a chatroom from a packet(<see cref="ClientMessage"/>).
        /// </summary>
        public static Chatroom CreateFromPacket(ClientMessage message)
        {
            int    id          = message.ReadInt32();
            string name        = message.ReadString();
            string description = message.ReadString();
            bool   password    = message.ReadBoolean();
            List <ChatroomUser> chatroomUsers = new List <ChatroomUser>();
            int users = message.ReadInt32();

            for (int i = 0; i < users; i++)
            {
                int    connectionId = message.ReadInt32();
                string username     = message.ReadString();

                // TODO: Return or add this list.
                ChatroomUser user = new ChatroomUser(connectionId, username);
                chatroomUsers.Add(user);
            }

            return(new Chatroom(id, name, description, password));
        }