· 8 years ago · Mar 10, 2018, 04:26 PM
1using Rocket.Core.Logging;
2using Rocket.Core.Plugins;
3using Rocket.Unturned;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using MySql.Data;
10using MySql.Data.MySqlClient;
11using Rocket.Unturned.Chat;
12using Rocket.Core.Commands;
13using Rocket.API;
14using Rocket.Unturned.Player;
15
16namespace Countrys
17{
18 public class Countrys : RocketPlugin<UConfig>
19 {
20 [RocketCommand("country", "", "", Rocket.API.AllowedCaller.Player)]
21 //Lav is look at vehicle
22 public void Execute(IRocketPlayer caller, params string[] command)
23 {
24 UnturnedPlayer Uply = UnturnedPlayer.FromName(caller.DisplayName);
25 OnPlayerConnected(Uply);
26 }
27
28 public MySqlConnection connection;
29 public static Countrys Insta;
30 protected override void Load()
31 {
32 Insta = this;
33 Logger.Log("UCountys Has Been Loaded");
34 DBConnectionInit();
35 }
36
37 public void DBConnectionInit ()
38 {
39 string DBConnectstring = "SERVER=" + Insta.Configuration.Instance.MysqlServerIP + ";" + "PORT=" + Insta.Configuration.Instance.MySqlServerPort + ";" + "DATABASE=" + Insta.Configuration.Instance.MySqlServerDatabase + ";" + "UID=" + Insta.Configuration.Instance.MySqlServerUser + ";" + "Pwd=" + Insta.Configuration.Instance.MySqlServerPassword + ";";
40 connection = new MySqlConnection(DBConnectstring);
41 try { connection.Open(); } catch(MySql.Data.MySqlClient.MySqlException) {
42 Logger.Log("Can't Connect To The Database. Check If Your Configuration Is Done Correctly");
43 }
44 connection.Close();
45 TableChecker();
46
47 }
48 public void TableChecker()
49 {
50 string qry = "CREATE TABLE IF NOT EXISTS COUNTRYS (steamid INT(17), Country INT(1));";
51 MySqlCommand cmd = new MySqlCommand(qry,connection);
52 connection.Open();
53 cmd.ExecuteNonQuery();
54 connection.Close();
55
56 }
57
58 public void OnPlayerConnected(UnturnedPlayer player)
59 {
60 string mySelectQuery = "select exists (select 1 from COUNTRYS where steamid =" + player.CSteamID + ");";
61 MySqlCommand myCommand = new MySqlCommand(mySelectQuery, connection);
62 connection.Open();
63 MySqlDataReader myReader;
64 myReader = myCommand.ExecuteReader();
65 try
66 {
67
68 myReader.Read();
69 bool doesexist = myReader.GetBoolean(0);
70 if(doesexist == true)
71 {
72 Logger.Log("Gay");
73 } else
74 {
75 Logger.Log("Cancer");
76 }
77
78
79 }
80 finally
81 {
82 myReader.Close();
83 connection.Close();
84 }
85
86
87
88 }
89
90 protected override void Unload()
91 {
92 base.Unload();
93 Logger.Log("UCountys Has Been Unloaded");
94 Insta = null;
95 }
96
97 }
98}