· 8 years ago · Mar 11, 2018, 10:56 AM
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;
15using Rocket.Core.Permissions;
16using Rocket.Core;
17using SDG.Unturned;
18
19namespace Countrys
20{
21 public class Countrys : RocketPlugin<UConfig>
22 {
23 public RocketPermissionsManager Permissions = R.Instance.GetComponent<RocketPermissionsManager>();
24 [RocketCommand("country", "", "", Rocket.API.AllowedCaller.Player)]
25 //Lav is look at vehicle
26 public void Execute(IRocketPlayer caller, params string[] command)
27 {
28 UnturnedPlayer Uply = caller as UnturnedPlayer;
29
30 if(command.Length == 1)
31 {
32
33 string mySelectQuery = "select exists (select 1 from COUNTRYS where steamid =" + Uply.Id + ");";
34 MySqlCommand myCommand = new MySqlCommand(mySelectQuery, connection);
35 connection.Open();
36 MySqlDataReader myReader;
37 myReader = myCommand.ExecuteReader();
38 try
39 {
40 myReader.Read();
41 bool doesexist = myReader.GetBoolean(0);
42 if (doesexist == true)
43 {
44 Logger.Log("Gay");
45 }
46 else
47 {
48 if (command[0].ToLower() == "sweden" || command[0].ToLower() == "sweden".Substring(0, 3))
49 {
50 UnturnedPlayer ply = UnturnedPlayer.FromName(caller.DisplayName);
51 PerseusIsGay(2, ply);
52 Permissions.AddPlayerToGroup("sweds", caller);
53
54
55
56 }
57 else if (command[0].ToLower() == "estonia" || command[0].ToLower() == "estonia".Substring(0, 3))
58 {
59 UnturnedPlayer ply = UnturnedPlayer.FromName(caller.DisplayName);
60 Permissions.AddPlayerToGroup("estonia", caller);
61 PerseusIsGay(1, ply);
62 }
63 }
64 }
65 finally
66 {
67 myReader.Close();
68 connection.Close();
69 }
70 }
71 }
72 public MySqlConnection connection;
73 public static Countrys Insta;
74 protected override void Load()
75 {
76 Insta = this;
77 Logger.Log("UCountys Has Been Loaded");
78 DBConnectionInit();
79 U.Events.OnPlayerConnected += Events_OnPlayerConnected;
80 }
81
82 private void Events_OnPlayerConnected(UnturnedPlayer player)
83 {
84 string mySelectQuery = "select exists (select 1 from COUNTRYS where steamid =" + player.Id + ");";
85 MySqlCommand myCommand = new MySqlCommand(mySelectQuery, connection);
86 connection.Open();
87 MySqlDataReader myReader;
88 myReader = myCommand.ExecuteReader();
89 try
90 {
91 myReader.Read();
92 bool doesexist = myReader.GetBoolean(0);
93 if (doesexist != true)
94 {
95 EffectManager.sendUIEffect(10090, short.Parse((player.CSteamID.m_SteamID / 9390480284091).ToString()), player.CSteamID, false);
96 }
97 }
98 finally
99 {
100 myReader.Close();
101 connection.Close();
102 }
103
104
105 }
106
107 public void DBConnectionInit ()
108 {
109 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 + ";";
110 connection = new MySqlConnection(DBConnectstring);
111 try { connection.Open(); } catch(MySqlException) {
112 Logger.Log("Can't Connect To The Database. Check If Your Configuration Is Done Correctly");
113 }
114 connection.Close();
115 TableChecker();
116
117 }
118 public void TableChecker()
119 {
120 string qry = "CREATE TABLE IF NOT EXISTS COUNTRYS (steamid BIGINT, Country INT(1));";
121 MySqlCommand cmd = new MySqlCommand(qry,connection);
122 connection.Open();
123 cmd.ExecuteNonQuery();
124 connection.Close();
125
126 }
127
128
129 public void PerseusIsGay(int choice, UnturnedPlayer player)
130 {
131 switch (choice)
132 {
133 case 1:
134 string qry1 = "INSERT INTO COUNTRYS (steamid, Country) VALUES(" + player.Id + ", " + 2 + ")";
135 MySqlCommand cmd = new MySqlCommand(qry1, connection);
136 connection.Open();
137 cmd.ExecuteNonQuery();
138 connection.Close();
139 break;
140
141 case 2:
142 string qry2 = "INSERT INTO COUNTRYS (steamid, Country) VALUES(" + player.Id + ", " + 3 + ");";
143 MySqlCommand cmd1 = new MySqlCommand(qry2, connection);
144 connection.Open();
145 cmd1.ExecuteNonQuery();
146 connection.Close();
147 break;
148 }
149
150 }
151
152 protected override void Unload()
153 {
154 base.Unload();
155 Logger.Log("UCountys Has Been Unloaded");
156 Insta = null;
157 U.Events.OnPlayerConnected -= Events_OnPlayerConnected;
158 }
159
160 }
161}