public static void Register(byte[] data, IPEndPoint ip, Server server) { Models.Client current = null; //< Who is doing the request string message = ""; // Unpack the packet in the correct format ProfilePacket regPacket = Packet.Unpack <ProfilePacket>(data); server.DebugInfo("Register request recieved."); server.DebugInfo("RegisterReq Packet: " + regPacket.ToString()); // Send a package depending on registration success if (ClientsManagement.RegisterClient(regPacket, ip, ref current, out message)) { // Send RegisterAck if all data is correct server.Udp.SendMessage(new AckErrorPacket( PacketTypes.RegisterAck, "Congratulations now you are registered.").Pack(), ip); server.DebugInfo(regPacket.FirstName + " " + regPacket.LastName + " has been registered as " + regPacket.Username); server.Clients.Add(new ClientStatus(current)); } else { // Send the error server.DebugInfo("Register: " + regPacket.FirstName + " " + regPacket.LastName + " request not accepted"); server.Udp.SendError(message, ip); } }
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); } }