Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using GTANetworkAPI;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using MySql.Data.MySqlClient;
  8.  
  9. namespace One_V.Player
  10. {
  11.     class Data
  12.     {
  13.         public static readonly String DataIndentifier = "PlayerInfo";
  14.         public Client PlayerData { get; set; }
  15.         public String Name { get; set; }
  16.         public int Cash { get; set; }
  17.         public int Level { get; set; }
  18.         public int Age { get; set; }
  19.         public int Health { get; set; }
  20.  
  21.         public Data(Client player)
  22.         {
  23.             this.PlayerData = player;
  24.             this.Name = player.Name;
  25.             this.Cash = 0;
  26.             this.Level = 0;
  27.             this.Age = 0;
  28.             this.Health = 0;
  29.         }
  30.         public void SetHealth(int health)
  31.         {
  32.             this.Health = health;
  33.             this.PlayerData.Health = health;
  34.         }
  35.         public static Data GetDataFromClient(Client player)
  36.         {
  37.             if(player == null)
  38.                 return null;
  39.  
  40.             if (player.HasData(DataIndentifier))
  41.             {
  42.                 return player.GetData(DataIndentifier);
  43.             }
  44.             else
  45.             {
  46.                 Data tmp = new Data(player);
  47.                 player.SetData(DataIndentifier, tmp);
  48.                 return tmp;
  49.             }
  50.         }
  51.  
  52.         public async Task<bool> AccountExists()
  53.         {
  54.             String Query = $"SELECT COUNT(*) AS AccNo FROM `accounts` WHERE `Playername` = @Playername LIMIT 1;";
  55.  
  56.             using(MySqlCommand command = new MySqlCommand(Query, MySQL.MySQL.conn))
  57.             {
  58.                 command.Parameters.AddWithValue("@Playername", this.PlayerData.Name);
  59.  
  60.                 using(var reader = await command.ExecuteReaderAsync())
  61.                 {
  62.                     if(await reader.ReadAsync())
  63.                     {
  64.                         if(Convert.ToInt32(reader["AccNo"]) == 1)
  65.                             return true;
  66.                     }
  67.                 }
  68.                
  69.             }
  70.            return false;
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement