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

            connection.ClientManager.ChatroomManager.AddPrivateRoom(chatRoom);
        }
Example #2
0
        private async void SaveAndConnect()
        {
            try
            {
                ConnectionCore xMLCore = new ConnectionCore();
                if (EditModel != null)
                {
                    EditModel = xMLCore.Connections.FirstOrDefault(x => x.Connection.ConnectionName == EditModel.ConnectionName)?.Connection;

                    EditModel.ConnectionName = ConnModel.ConnectionName;
                    EditModel.ConnType       = ConnModel.ConnType;
                    EditModel.Host           = ConnModel.Host;
                    EditModel.Port           = ConnModel.Port;
                    EditModel.UserName       = ConnModel.UserName;
                    EditModel.Password       = ConnModel.Password;
                    EditModel.BuilderBuildConnection();
                }
                else
                {
                    ConnModel.BuilderBuildConnection();
                    xMLCore.Connections.Insert(0, new TreeViewModel()
                    {
                        Connection = ConnModel
                    });
                }
                xMLCore.ConnectionSerialize();
            }
            catch (Exception ex)
            {
                await dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {ex.Message}  /r/nStackTrace: {ex.StackTrace}");
            }
        }
Example #3
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the server.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int       chatRoomId = message.ReadInt32();
            JoinState state      = (JoinState)message.ReadInt32();

            connection.ClientManager.ChatroomManager.JoinChatroom(chatRoomId, state);
        }
Example #4
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the client.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            string chatmessage = message.ReadString();
            int    chatroomId  = message.ReadInt32();

            connection.ServerManager.ChatroomManager.SendMessage(chatroomId, chatmessage, connection);
        }
Example #5
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()));
            }
        }
 /// <summary>
 /// Handles the incoming packet that has been sent from the client.
 /// </summary>
 public void Parse(ClientMessage message, ConnectionCore connection)
 {
     do
     {
         connection.ConnectionData.UserData.Add(DataPackage.Read(message));
     }while (message.RemainingLength() > 0);
 }
Example #7
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 #8
0
        private async void CreateAsync(object window)
        {
            Window         win    = window as Window;
            string         entity = "";
            ConnectionCore cc     = null;

            try
            {
                SettingsCore settings = new SettingsCore();
                settings.SettingsSerialize();
                cc     = new Cores.ConnectionCore(new ConnectionModel(Type, ConnString));
                entity = cc.CreateModel(Document.Text, settings.Settings);
            }
            catch (Exception ex)
            {
                await _dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {ex.Message}  /r/nStackTrace: {ex.StackTrace}");

                return;
            }

            if (cc != null && cc.Errors.Count > 0)
            {
                await _dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {cc.Errors.First().Message}  /r/nStackTrace: {cc.Errors.First().StackTrace}");
            }
            else
            {
                win.Tag          = entity;
                win.DialogResult = true;
                win.Close();
            }
        }
 /// <summary>
 /// Removes a specific connection to the connection queue.
 /// </summary>
 public void RemoveFromQueue(ConnectionCore connection)
 {
     if (ConnectionQueue.Contains(connection))
     {
         ConnectionQueue.Remove(connection);
         ServerLogger.PrivateRoom($"Removed {connection.ConnectionData.Username} ({connection.ConnectionData.ClientIP.ToString()}) from the privatechatroom queue");
     }
 }
Example #10
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the server.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            // Read the connectionId
            int connectionId = message.ReadInt32();

            // Set the connectionId
            connection.ConnectionId = connectionId;
        }
Example #11
0
        /// <summary>
        /// Broadcasts a message to the <see cref="Chatroom"/>.
        /// </summary>
        public void BroadcastChatMessage(ConnectionCore connection, BroadcastType broadcastType)
        {
            BroadcastMessageComposer comp = new BroadcastMessageComposer(ID, _LastChatMessageId++, connection.ID, connection.ConnectionData.Username, broadcastType);

            foreach (ConnectionCore user in ChatroomUsers.ToArray())
            {
                user.SendMessage(comp);
            }
        }
Example #12
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 #13
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>
        /// Sends a chatmessage to the chatroom.
        /// </summary>
        public void SendChatMessage(int privateRoomId, string privateMessage, ConnectionCore connection)
        {
            if (PrivateChatrooms.ContainsKey(privateRoomId))
            {
                Chatroom room = PrivateChatrooms[privateRoomId];

                room.SendMessage(connection, privateMessage);
            }
        }
Example #15
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);
            }
        }
Example #16
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the client.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int length = message.ReadInt32();

            byte[] voice      = message.ReadBytes(length);
            int    chatroomId = message.ReadInt32();

            connection.ServerManager.ChatroomManager.SendMessage(chatroomId, voice, connection);
        }
Example #17
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);
            }
        }
Example #18
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);
        }
Example #19
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);
         }
     }
 }
Example #20
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the server.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int    chatroomId  = message.ReadInt32();
            int    messageId   = message.ReadInt32();
            int    UserId      = message.ReadInt32();
            string username    = message.ReadString();
            string chatMessage = message.ReadString();

            Chatrooms.ChatMessage ChatMessage = new Chatrooms.ChatMessage(chatroomId, messageId, chatMessage, new ChatroomUser(UserId, username));
            connection.ClientManager.ChatroomManager.HandleMessage(ChatMessage);
        }
Example #21
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the server.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            // Reads the clientTime
            int clientTime = message.ReadInt32();

            // Reads the serverTime
            int serverTime = message.ReadInt32();

            // Calculate the latency
            int totalLatency = (serverTime) - (clientTime);
        }
        /// <summary>
        /// Handles the incoming packet that has been sent from the server.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int chatroomId = message.ReadInt32();
            int messageId  = message.ReadInt32();
            int userId     = message.ReadInt32();

            string broadcastMessage = message.ReadString();

            Chatrooms.ChatMessage broadcastChatMessage = new Chatrooms.ChatMessage(chatroomId, messageId, broadcastMessage);
            connection.ClientManager.ChatroomManager.HandleMessage(broadcastChatMessage);
        }
Example #23
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the client.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int userId = message.ReadInt32();
            int roomId = message.ReadInt32();

            Chatroom room = connection.ServerManager.ChatroomManager.GetChatroom(roomId);

            if (room != null)
            {
                room.Leave(connection);
            }
        }
Example #24
0
 /// <summary>
 /// Handles a packet that has been sent from a client.
 /// </summary>
 public void HandlePacket(ClientMessage message, ConnectionCore connection)
 {
     // Handle the packet if it exists
     if (PacketHandlers.ContainsKey(message.PacketId))
     {
         ServerLogger.Handled($"[{message.PacketId}] {message.ToString()}"); PacketHandlers[message.PacketId].Parse(message, connection);
     }
     else
     {
         ServerLogger.Unhandled($"[{message.PacketId}] {message.ToString()}");
     }
 }
Example #25
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the server.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            int    chatroomId = message.ReadInt32();
            int    messageId  = message.ReadInt32();
            int    UserId     = message.ReadInt32();
            int    length     = message.ReadInt32();
            string username   = message.ReadString();

            byte[] chatMessage = message.ReadBytes(length);

            Chatrooms.Voice.VoiceMessage voiceMessage = new Chatrooms.Voice.VoiceMessage(chatroomId, messageId, chatMessage, new ChatroomUser(UserId, username));
            connection.ClientManager.ChatroomManager.HandleMessage(voiceMessage);
        }
Example #26
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));
            }
        }
Example #27
0
        /// <summary>
        /// Handles the incoming packet that has been sent from the server.
        /// </summary>
        public void Parse(ClientMessage message, ConnectionCore connection)
        {
            Dictionary <int, Chatroom> chatRooms = new Dictionary <int, Chatroom>();
            int chatRoomUsers = message.ReadInt32();

            for (int i = 0; i < chatRoomUsers; i++)
            {
                Chatroom chatRoom = Chatroom.CreateFromPacket(message);
                chatRooms.Add(chatRoom.ID, chatRoom);
            }

            connection.ClientManager.ChatroomManager.InitializeChatrooms(chatRooms);
        }
Example #28
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));
                }
            }
        }
        /// <summary>
        /// Adds a specific connection to the connection queue.
        /// </summary>
        public void AddToQueue(ConnectionCore connection)
        {
            if (ConnectionQueue.Contains(connection))
            {
                return;
            }

            ServerLogger.PrivateRoom($"Added {connection.ConnectionData.Username} ({connection.ConnectionData.ClientIP.ToString()}) to the private chatroom queue");
            ConnectionQueue.Enqueue(connection);

            if (ConnectionQueue.Count >= 2)
            {
                CreatePrivateRoom(2);
            }
        }
Example #30
0
        /// <summary>
        /// Handles the packet that has been received.
        /// </summary>
        public void HandlePacket(ClientMessage message, ConnectionCore connection)
        {
            if (PacketHandlers.ContainsKey(message.PacketId))
            {
                PacketHandlers[message.PacketId].Parse(message, connection);

                // Log the Handled packet
                // Console.WriteLine($"Handled {message.PacketId} with {message.Packet.GetType().ToString()}");
            }
            else
            {
                // Log the Handled packet
                // Console.WriteLine($"Unhandled {message.PacketId} with {message.Packet.GetType().ToString()}");
            }
        }