/// <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); }
/// <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()); }
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."); }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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()); }
/// <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); } } }
/// <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); }
/// <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); } }
/// <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); }
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]); }
/// <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); } }
/// <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)); } }
/// <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); } }
/// <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)); }
/// <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); }