コード例 #1
0
        /// <summary>Function to determine if a chatroom exists or not</summary>
        /// <param name="sRoomId">ID of chatroom user looking for</param>
        /// <returns>Returns TRUE/FALSE to indicate if chatroom has not been found</returns>
        /// <author>Created by Irfaan on March 11, 2017</author>
        private bool fChatRoomNotFound(string sRoomId)
        {
            // Variables declaration
            string   sChatroomXML;
            XElement Chatrooms;
            XElement xeRoom;

            // Initialisations
            sChatroomXML = string.Concat(Request.PhysicalApplicationPath, "App_Data/chatrooms.xml");
            Chatrooms    = XElement.Load(sChatroomXML);

            // Try to find the chatroom
            try
            {
                xeRoom = (from el in Chatrooms.Elements("chatRoom")
                          where (string)el.Attribute("roomId") == sRoomId
                          select el).First();
                sChatroomName      = xeRoom.Element("chatRoomName").Value;
                dCreatedOn         = Convert.ToDateTime(xeRoom.Element("createdAt").Value);
                sMainAdministrator = xeRoom.Element("administrators").Element("administrator").Element("displayName").Value;
            }
            catch
            {
                // Chatroom not found
                xeRoom = null;
            }
            return(xeRoom == null);
        }
コード例 #2
0
        /// <summary>
        /// Initiliazes all the chatrooms based on the <see cref="Dictionary{TKey, TValue}"/> parameter.
        /// </summary>
        public void InitializeChatrooms(Dictionary <int, Chatroom> rooms)
        {
            foreach (var item in rooms)
            {
                Chatroom room = item.Value;

                if (!Chatrooms.ContainsKey(room.ID))
                {
                    Chatrooms.Add(room.ID, room);
                    ChatroomsList.Add(room);
                }
            }

            List <Chatroom> toRemove = new List <Chatroom>();

            foreach (var item in Chatrooms)
            {
                if (!item.Value.IsPrivate && !rooms.ContainsKey(item.Key))
                {
                    toRemove.Add(item.Value);
                }
            }

            foreach (var item in toRemove)
            {
                Chatrooms.Remove(item.ID);
                ChatroomsList.Remove(item);
            }

            OnChatroomsChanged(new EventArgs());
        }
コード例 #3
0
        private static void AddRooms()
        {
            try
            {
                chatmanager = new DatabaseManager(30, 10, DatabaseType.MySQL);
                chatmanager.setServerDetails(Setting["server"], uint.Parse(Setting["mport"]), Setting["username"], "", "chatserver");
                chatmanager.init();
            }
            catch (Exception e)
            {
                Out.WriteLine("Error: " + e.Message, "MySQL", ConsoleColor.Red);
                Console.ReadKey();
                Environment.Exit(0);
            }
            try
            {
                manager = new DatabaseManager(30, 10, DatabaseType.MySQL);
                manager.setServerDetails(Setting["server"], uint.Parse(Setting["mport"]), Setting["username"], "", "aurora");
                manager.init();
            }
            catch (Exception e)
            {
                Out.WriteLine("Error: " + e.Message, "MySQL", ConsoleColor.Red);
                Console.ReadKey();
                Environment.Exit(0);
            }

            using (var dbClient = chatmanager.getQueryreactor())
            {
                var data = (DataTable)dbClient.query("SELECT * FROM chatrooms");
                foreach (DataRow row in data.Rows)
                {
                    var chat = new Chatroom
                    {
                        Index = Convert.ToInt32(row[0]),
                        Name  = row[1].ToString(),
                        Id    = Convert.ToInt32(row[2])
                    };
                    Chatrooms.Add(chat.Id, chat);
                }
                var mmo = new Chatroom
                {
                    Index = Convert.ToInt32(1),
                    Name  = "MMO",
                    Id    = Convert.ToInt32(22)
                }; var vru = new Chatroom
                {
                    Index = Convert.ToInt32(1),
                    Name  = "VRU",
                    Id    = Convert.ToInt32(253)
                }; var eic = new Chatroom
                {
                    Index = Convert.ToInt32(1),
                    Name  = "EIC",
                    Id    = Convert.ToInt32(252)
                };
            }
            Out.WriteLine("" + Chatrooms.Count + " Chat rooms are loaded.");
        }
コード例 #4
0
 /// <summary>
 /// Handles a chatroom voice message.
 /// </summary>
 public void HandleMessage(Voice.VoiceMessage message)
 {
     if (Chatrooms.ContainsKey(message.ChatroomID))
     {
         Chatroom room = Chatrooms[message.ChatroomID];
         room.NewMessage(message);
     }
 }
コード例 #5
0
        /// <summary>
        /// Sends a voice message to a certain <see cref="Chatroom"/>.
        /// </summary>
        public void SendMessage(int chatroomId, byte[] voice, ConnectionCore connection)
        {
            if (Chatrooms.ContainsKey(chatroomId))
            {
                Chatroom room = Chatrooms[chatroomId];

                room.SendMessage(connection, voice);
            }
        }
コード例 #6
0
        /// <summary>
        /// Sends a message to a certain <see cref="Chatroom"/>.
        /// </summary>
        public void SendMessage(int chatroomId, string chatmessage, ConnectionCore connection)
        {
            if (Chatrooms.ContainsKey(chatroomId))
            {
                Chatroom room = Chatrooms[chatroomId];

                room.SendMessage(connection, chatmessage);
            }
        }
コード例 #7
0
        /// <summary>
        /// Adds a private chatroom to the chatroom mananger.
        /// </summary>
        public void AddPrivateRoom(Chatroom room)
        {
            room.IsPrivate = true;

            Chatrooms.Add(room.ID, room);
            ChatroomsList.Add(room);

            OnChatroomsChanged(new EventArgs());
        }
コード例 #8
0
 /// <summary>
 /// Disconnects a <see cref="ConnectionCore"/> from each chatroom in <see cref="Chatrooms"/>.
 /// </summary>
 public void LeaveAllChatrooms(ConnectionCore connection)
 {
     foreach (var room in Chatrooms.ToList())
     {
         if (room.Value.ChatroomUsers.Contains(connection))
         {
             room.Value.Leave(connection);
         }
     }
 }
コード例 #9
0
        /// <summary>
        /// Createsand returns a <see cref="Chatroom"/> based on the name, description and password.
        /// </summary>
        public Chatroom CreateChatRoom(string name, string desc, string pass, ConnectionCore connection)
        {
            Chatroom chatRoom = new Chatroom(LastRoomId++, name, desc, pass);

            chatRoom.Join(connection);
            Chatrooms.Add(chatRoom.ID, chatRoom);

            ServerManager.ConnectionController.SendMessage(new InitializeChatroomsComposer(Chatrooms));
            return(chatRoom);
        }
コード例 #10
0
 /// <summary>
 /// Removes a chatroom based on the <see cref="Chatroom.ID"/>.
 /// </summary>
 public void RemoveChatroom(int chatroomId)
 {
     if (Chatrooms.ContainsKey(chatroomId))
     {
         Chatroom room = Chatrooms[chatroomId];
         DisconnectChatroom(room);
         ChatroomsList.Remove(room);
         Chatrooms.Remove(chatroomId);
     }
 }
コード例 #11
0
        /// <summary>
        /// Returns a <see cref="bool"/> value whether the user is in the chatroom.
        /// </summary>
        public bool IsInChatroom(int id)
        {
            if (Chatrooms.ContainsKey(id))
            {
                Chatroom room = Chatrooms[id];
                return(room.IsInChatroom);
            }

            return(false);
        }
コード例 #12
0
        public void ChatroomMenu()
        {
            Send("What chatroom would you like to join?");
            string input = "";

            do
            {
                input = GetUserInput(ListChatrooms + "\n");
            } while (!Chatrooms.ContainsKey(input));

            ChangeChatroom(Chatrooms[input]);
        }
コード例 #13
0
 /// <summary>
 /// Returns a <see cref="Chatroom"/> based on its ID.
 /// </summary>
 public Chatroom GetChatroom(int chatroomId)
 {
     try
     {
         if (Chatrooms.ContainsKey(chatroomId))
         {
             return(Chatrooms[chatroomId]);
         }
         else
         {
             return(null);
         }
     }
     catch
     {
         return(null);
     }
 }
コード例 #14
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));
            }
        }
コード例 #15
0
        /// <summary>
        /// Connects a user to a chatroom and returns a <see cref="JoinState"/>.
        /// </summary>
        public JoinState JoinChatroom(int chatRoomId, string password, ConnectionCore connection)
        {
            if (Chatrooms.ContainsKey(chatRoomId))
            {
                Chatroom room = Chatrooms[chatRoomId];

                if (string.IsNullOrEmpty(room.Password) || password == room.Password || room.Owner == connection.ID)
                {
                    room.Join(connection);
                    return(JoinState.JoinChatRoomOk);
                }
                else
                {
                    return(JoinState.JoinChatRoomWrongPassword);
                }
            }
            else
            {
                return(JoinState.JoinChatRoomError);
            }
        }
コード例 #16
0
 /// <summary>
 /// Removes a <see cref="Chatroom"/> based on its ID.
 /// </summary>
 public void RemoveChatroom(int chatroomId)
 {
     Chatrooms.Remove(chatroomId);
     ServerManager.ConnectionController.SendMessage(new InitializeChatroomsComposer(Chatrooms));
 }
コード例 #17
0
 /// <summary>
 /// Adds a chatroom to the <see cref="Chatrooms"/> <see cref="Dictionary{TKey, TValue}"/>.
 /// </summary>
 public void AddChatroom(Chatroom chatroom)
 {
     Chatrooms.Add(chatroom.ID, chatroom);
 }