public static bool Register(Profile newProfile, Client client, out string message) { try { // Pack register request packet Packets.ProfilePacket reg = new Packets.ProfilePacket( Packets.PacketTypes.RegisterReq, "0000000", //> For registering always 7 0's newProfile.FirstName, newProfile.LastName, newProfile.Age, newProfile.PhoneNumber, (Profile.Sex)newProfile.Gender, newProfile.Username, newProfile.Password, newProfile.Email ); // Send register request package client.Udp.SendMessage(reg.Pack()); // Recieve the data var data = client.Udp.RecieveMessage(); // Unpack the data and check the type Packets.Packet p = Packets.Packet.Unpack <Packets.Packet>(data); switch ((Packets.PacketTypes)p.Type) { case Packets.PacketTypes.RegisterAck: // Complete registration client.DebugInfo("Register: Done!"); message = "Registration successfully completed. Now You can login."; return(true); case Packets.PacketTypes.Error: message = "Error: " + Packets.Packet.Unpack <Packets.AckErrorPacket>(data).Message; client.DebugInfo("Register: " + message); break; default: client.DebugInfo("Register: Unexpected type."); message = "Error, unexpected type."; break; } return(false); } catch (System.Net.Sockets.SocketException) { client.DebugInfo("Server is offline."); message = "Server is offline."; return(false); } }
public static bool UpdateProfile(Profile newProfile, Client client, out string message) { try { // Pack login request packet Packets.ProfilePacket profilePacket = new Packets.ProfilePacket( Packets.PacketTypes.ProfileUpdateReq, client.Alea, newProfile ); // Send login request package client.Udp.SendMessage(profilePacket.Pack()); // Recieve the data var data = client.Udp.RecieveMessage(); // Unpack the data and check the type Packets.Packet p = Packets.Packet.Unpack <Packets.Packet>(data); switch ((Packets.PacketTypes)p.Type) { case Packets.PacketTypes.ProfileUpdateAck: // Complete profile update Packets.ProfilePacket profileP = Packets.Packet.Unpack <Packets.ProfilePacket>(data); // No set new messages when alive profileP.Messages = client.Profile.Messages; client.Profile.SetFromPacket(profileP); message = "Profile Updated"; return(true); case Packets.PacketTypes.Error: message = "Error: " + Packets.Packet.Unpack <Packets.AckErrorPacket>(data).Message; client.DebugInfo("Update Profile: " + message); break; default: client.DebugInfo("Update Profile: Unexpected type."); message = "Error, unexpected type."; break; } return(false); } catch (System.Net.Sockets.SocketException e) { client.DebugInfo("Server is offline."); message = e.ToString(); return(false); } }