Exemplo n.º 1
0
        public static void Login(byte[] data, IPEndPoint ip, Server server)
        {
            Models.Client current = null;   //< Who is doing the request

            // Unpack
            LoginReqPacket logPacket = Packet.Unpack <LoginReqPacket>(data);

            server.DebugInfo("Login request recieved.");
            server.DebugInfo("LoginReq Packet: " + logPacket.ToString());


            if (ClientsManagement.LoginClient(logPacket, ref current, out string message))
            {
                if (server.GetClient(current.Username).Stat == ClientStatus.Status.Logged)
                {
                    server.DebugInfo("Login: User is already logged");
                    message = "USer is already logged";
                    server.Udp.SendError(message, ip);
                    return;
                }

                // Client login
                server.DebugInfo("Client " + current.ToString() + " is now logged in.");
                string alea = Server.GenerateAlea();
                server.SetStatus(logPacket.Username, ClientStatus.Status.Logged, alea, DateTime.Now);

                // Send the profile info of the database to client
                server.DebugInfo("Sending profile info to " + logPacket.Username + ".");

                // Return user profile with the ack
                server.Udp.SendMessage(new ProfilePacket(
                                           PacketTypes.LoginAck,
                                           alea,  // New alea generated
                                           current.FirstName,
                                           current.LastName,
                                           current.Age,
                                           current.PhoneNumber,
                                           current.Gender,
                                           current.Username,
                                           current.Password,
                                           current.Email,
                                           server.GetContacts(server.GetClient(current.Username)),
                                           server.GetUnreadMessages(server.GetClient(current.Username)),
                                           server.GetAgendaEvents(current.Username),
                                           server.GetSocialNetworks(current.Username)
                                           ).Pack(), ip);

                // Mark messages as read
                server.MarkReadMessages(server.GetClient(current.Username));
            }
            else
            {
                server.DebugInfo("Login: Request not accepted");
                server.Udp.SendError(message, ip);
            }
        }
Exemplo n.º 2
0
        public static void ProfileUpdate(byte[] data, IPEndPoint ip, Server server)
        {
            ProfilePacket pPacket = Packet.Unpack <ProfilePacket>(data);

            server.DebugInfo("Update profile recieved.");
            server.DebugInfo("Update profile Packet: " + pPacket.ToString());

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

            if (ClientsManagement.UpdateProfile(pPacket, ref current, out string message))
            {
                // Profile updated
                server.DebugInfo("Update Profile: " + pPacket.Username + "'s profile updated.");

                // Return user profile with the ack
                server.Udp.SendMessage(new ProfilePacket(
                                           PacketTypes.ProfileUpdateAck,
                                           current.Alea,  // New alea generated
                                           current.Client.FirstName,
                                           current.Client.LastName,
                                           current.Client.Age,
                                           current.Client.PhoneNumber,
                                           current.Client.Gender,
                                           current.Client.Username,
                                           current.Client.Password,
                                           current.Client.Email,
                                           server.GetContacts(current),
                                           server.GetUnreadMessages(current),
                                           server.GetAgendaEvents(current.Client.Username),
                                           server.GetSocialNetworks(current.Client.Username)
                                           ).Pack(), ip);

                server.MarkReadMessages(current);
            }
            else
            {
                server.DebugInfo("Profile Update: Request not accepted");
                server.Udp.SendError(message, ip);
            }
        }