static void UploadStats(Client client, Packet msg) { try { if (!client.Connected) { throw new Exception(); } Stats stats = new Stats(); stats.FromBytes(msg.Bytes, 0); User user = DataBase.GetUser(client.UserID).Value; // If new stats are newer, update if (stats.LastUpdated > user.Statistics.LastUpdated) { user.Statistics = stats; } DataBase.SaveUser(user); } catch (Exception) { client.Send(new Packet(PacketCode.UploadStats, PacketInfo.Error)); } }
static void LogIn(Client client, Packet msg) { try { uint id = BitConverter.ToUInt32(msg.Bytes, 0); uint loginInfo = BitConverter.ToUInt32(msg.Bytes, 4); if (DataBase.GetUser(id)?.LoginInfo == loginInfo) { client.LoggedIn = true; client.UserID = id; } client.Send(new Packet(PacketCode.LogIn, PacketInfo.Success)); } catch (Exception) { client.Send(new Packet(PacketCode.LogIn, PacketInfo.Error)); } }