Exemplo n.º 1
0
        public static void Alive(byte[] data, IPEndPoint ip, Server server)
        {
            string message = "";

            BasicReqPacket aPacket = Packet.Unpack <BasicReqPacket>(data);

            server.DebugInfo("Alive inf recieved.");
            server.DebugInfo("AliveInf Packet: " + aPacket.ToString());

            ClientStatus current = server.GetClient(aPacket.Username);

            if (ClientsManagement.CheckBasics(current, ClientStatus.Status.Disconnected, aPacket.Alea, out message))
            {
                // Save the last alive
                current.LastAlive = DateTime.Now;
                // Send ack
                server.Udp.SendMessage(new AckErrorPacket(PacketTypes.AliveAck, "Alive correct").Pack(), ip);
            }
            else
            {
                server.DebugInfo("Alive: Incorrect alive from " + aPacket.Username);
                server.DebugInfo(aPacket.Username + " now is disconnected.");

                if (server.ClientsOnChat.Any(d => d.Key == current.Client.Username))
                {
                    server.ClientsOnChat.Remove(current.Client.Username);
                }
                // Disconnect the client
                current.Disconnect();
                // Send error
                server.Udp.SendError(message, ip);
            }
        }
Exemplo n.º 2
0
        public static void Logout(byte[] data, IPEndPoint ip, Server server)
        {
            string message = "";

            BasicReqPacket logoutPacket = Packet.Unpack <BasicReqPacket>(data);

            server.DebugInfo("Logut request recieved.");
            server.DebugInfo("LogoutReq Packet: " + logoutPacket.ToString());

            ClientStatus current = server.GetClient(logoutPacket.Username);

            if (ClientsManagement.CheckBasics(current, ClientStatus.Status.Disconnected, logoutPacket.Alea, out message))
            {
                server.DebugInfo("Logout: Correct logut from " + logoutPacket.Username);
                server.DebugInfo(logoutPacket.Username + " now is disconnected.");
                if (server.ClientsOnChat.Any(d => d.Key == current.Client.Username))
                {
                    server.ClientsOnChat.Remove(current.Client.Username);
                }
                current.Disconnect();

                // Return ack
                server.Udp.SendMessage(new AckErrorPacket(PacketTypes.LogoutAck, "Logged out correctly.").Pack(), ip);
            }
            else
            {
                server.DebugInfo("Logout: Incorrect logut.");
                // Send error
                message = "Logout error: " + message;
                server.Udp.SendError(message, ip);
            }
        }
        public static void SendContactRequests(byte[] data, Server server, IPEndPoint ip)
        {
            string message = "";

            // Unpack the petition
            BasicReqPacket cPacket = Packet.Unpack <BasicReqPacket>(data);

            List <Models.ContactRequest> sent     = null;
            List <Models.ContactRequest> recieved = null;


            server.DebugInfo("Contact requests list requested by " + cPacket.Username);
            server.DebugInfo(cPacket.ToString());

            if (ClientsManagement.ContactRequestsList(cPacket,
                                                      server.GetClient(cPacket.Username),
                                                      ref sent,
                                                      ref recieved,
                                                      out message))
            {
                // List filled correctly
                server.Udp.SendMessage(new ContactReqListPacket(PacketTypes.ContactAck,
                                                                cPacket.Alea,
                                                                sent,
                                                                recieved).Pack(),
                                       ip);

                server.DebugInfo("Contact list requests sended correctly to + " + cPacket.Username);
            }
            else
            {
                server.DebugInfo("Contact requests list error: " + message);
                server.Udp.SendError(message, ip);
            }
        }
Exemplo n.º 4
0
        public static void DeleteAccount(byte[] data, IPEndPoint ip, Server server)
        {
            string message = "";

            BasicReqPacket delPacket = Packet.Unpack <BasicReqPacket>(data);

            server.DebugInfo("Delete account request recieved.");
            server.DebugInfo("DeleteAccountReq Packet: " + delPacket.ToString());

            ClientStatus current = server.GetClient(delPacket.Username);

            if (ClientsManagement.CheckBasics(current, ClientStatus.Status.Disconnected, delPacket.Alea, out message))
            {
                server.DebugInfo("Delete Account: Account was " + delPacket.Username + " correctly deleted.");

                // Send the ack first
                server.Udp.SendMessage(new AckErrorPacket(PacketTypes.DeleteAccountAck, "Account deleted correctly.").Pack(), ip);

                // Delete client from database
                server.DeleteCLientFromDataBase(delPacket.Username);
            }
            else
            {
                server.DebugInfo("Delete account: Acount can't be deleted.");
                // Send error
                message = "Delete error: " + message;
                server.Udp.SendError(message, ip);
            }
        }
Exemplo n.º 5
0
        public static void ReadyChatClient(byte[] data, TcpClient client, Server server)
        {
            string message = "";
            // Unpack the data
            BasicReqPacket packet = Packet.Unpack <BasicReqPacket>(data);

            // Get the client who is requesting
            ClientStatus c = server.GetClient(packet.Username);

            // Check the basics
            if (ClientsManagement.CheckBasics(c, ClientStatus.Status.Disconnected, packet.Alea, out message))
            {
                // Add client to dicctionary with his respective tcpclient
                server.ClientsOnChat.Add(c.Client.Username, client);

                server.DebugInfo("Client Ready for chat: " + c.Client.Username + " is ready for chatting.");

                // Send ack
                server.Tcp.SendMessage(new AckErrorPacket(PacketTypes.ReadyChatAck, "Now you are ready for chat").Pack(), client);
            }
            else
            {
                server.DebugInfo("Client Ready for chat error: " + message);
                server.Tcp.SendError(message, client);
            }
        }