static void SignUp(Client client, Packet msg) { try { int index = 0; int nameLength = BitConverter.ToInt32(msg.Bytes, index); index += 4; string name = Encoding.UTF8.GetString(msg.Bytes, index, nameLength); index += nameLength; uint id; do { id = (uint)random.Next(int.MinValue, int.MaxValue); }while (DataBase.ExistsUser(id)); uint loginInfo = (uint)random.Next(int.MinValue, int.MaxValue); User user = new User(name, id, loginInfo); DataBase.SaveUser(user); client.LoggedIn = true; client.UserID = id; List <byte> bytes = new List <byte>(); bytes.AddRange(BitConverter.GetBytes(id)); bytes.AddRange(BitConverter.GetBytes(loginInfo)); client.Send(new Packet(PacketCode.SignUp, PacketInfo.Success, bytes.ToArray())); } catch (Exception) { client.Send(new Packet(PacketCode.SignUp, PacketInfo.Error)); } }