· 8 years ago · Jan 17, 2018, 01:48 PM
1#include <sourcemod>
2#include <shavit>
3#include <mapchooser>
4
5
6//Database settings
7Database gH_SQL = null;
8char gS_MySQLPrefix[32];
9
10
11char gS_ServerIP[32];
12char gS_MapName[128]; //actual map on this server
13char gS_NextMapName[128]; //nextmap if it exist
14char gS_MapNameP[128]; //actual map on this server
15char gS_NextMapNameP[128]; //nextmap if it exist
16bool NeedMapChange;
17
18
19public Plugin myinfo =
20{
21 name = "Unique Map",
22 author = "lemiwiki",
23 description = "Disallow to play the same map on different bhop servers",
24 version = "1.9",
25 url = "http://ggeasy.pl"
26}
27
28public void OnPluginStart()
29{
30
31 // THIS IS TO GET SERVERIP
32 char server_port[10];
33 char server_ip[16];
34
35 Handle cvar_port = FindConVar("hostport");
36 GetConVarString(cvar_port, server_port, sizeof(server_port));
37 CloseHandle(cvar_port);
38
39 Handle cvar_ip = FindConVar("ip");
40 GetConVarString(cvar_ip, server_ip, sizeof(server_ip));
41 CloseHandle(cvar_ip);
42
43 FormatEx(gS_ServerIP,32,"%s:%s",server_ip,server_port);
44
45 // DATABASE CONNECTIONS
46 gH_SQL = Shavit_GetDatabase();
47 SQL_SetPrefix();
48 SetSQLInfo();
49}
50
51public void OnMapStart()
52{
53 //Getting MapName
54 GetCurrentMap(gS_MapName, 128);
55 //Secure Change of Bools
56 NeedMapChange = false;
57
58 MapProcedure();
59}
60
61void MapProcedure()
62{
63 CreateTimer(0.5, CreateCurrentMapTable);
64 CreateTimer(1.0, GetDataFromDB);
65 CreateTimer(1.2, ReplaceMapInfo);
66}
67
68public Action CreateCurrentMapTable(Handle timer)
69{
70 char[] sQuery = new char[256];
71 FormatEx(sQuery, 256, "CREATE TABLE IF NOT EXISTS `%scurrentmap` (`server_ip` VARCHAR(32), `current_map` VARCHAR(128), `next_map` VARCHAR(128), PRIMARY KEY (`server_ip`));",gS_MySQLPrefix);
72
73 SQL_Query(gH_SQL, sQuery);
74
75 return Plugin_Handled;
76}
77
78public Action GetDataFromDB(Handle timer)
79{
80 char[] sQuery = new char[256];
81 FormatEx(sQuery, 256, "SELECT * FROM %scurrentmap;", gS_MySQLPrefix);
82
83 DBResultSet results = SQL_Query(gH_SQL, sQuery);
84 GetNextMap(gS_NextMapName, 128);
85
86 if(results == null)
87 {
88 LogError("Blad w pobraniu Handle")
89 return Plugin_Handled;
90 }
91
92 while(results.FetchRow())
93 {
94 char ip[32];
95 results.FetchString(0, ip, 32);
96
97 if(!StrEqual(ip, gS_ServerIP))
98 {
99 results.FetchString(1, gS_MapNameP, 128);
100 results.FetchString(2, gS_NextMapNameP, 128);
101
102 if(StrEqual(gS_NextMapName, gS_MapNameP) || StrEqual(gS_NextMapName, gS_NextMapNameP))
103 {
104 NeedMapChange = true;
105 ChangeMap();
106 } //PrintToChatAll("%s to nasza mapka a na drugim serwerze jest %s .... %s ", gS_MapName, ip, gS_MapNameP);
107 }
108 }
109 delete results;
110 return Plugin_Handled;
111
112}
113
114public Action ReplaceMapInfo(Handle timer)
115{
116 char[] sQuery = new char[512];
117 FormatEx(sQuery, 512, "REPLACE INTO %scurrentmap (server_ip, current_map, next_map) VALUES ('%s', '%s', %s);", gS_MySQLPrefix, gS_ServerIP , gS_MapName);
118 SQL_Query(gH_SQL, sQuery);
119
120 return Plugin_Handled;
121}
122
123public Action ChangeMap()
124{
125 if(NeedMapChange)
126 {
127 RemoveNominationByMap(gS_MapNameP);
128 RemoveNominationByMap(gS_NextMapNameP);
129 InitiateMapChooserVote(MapChange_MapEnd);
130 PrintToChatAll("===PENDING MAP VOTE, BECOUSE IT'S ALREADY PLAYED ON THE OTHER SERVER===");
131 PrintToChatAll("===PENDING MAP'S VOTE, BECOUSE IT'S ALREADY PLAYED ON THE OTHER SERVER===");
132 PrintToChatAll("===PENDING MAP'S VOTE, BECOUSE IT'S ALREADY PLAYED ON THE OTHER SERVER===");
133 }
134
135 return Plugin_Handled;
136}
137
138// --------------------
139// DATABASE CONNECTIONS
140// --------------------
141
142public void Shavit_OnDatabaseLoaded()
143{
144 Database db;
145 gH_SQL = db;
146}
147
148void SQL_SetPrefix()
149{
150 char[] sFile = new char[PLATFORM_MAX_PATH];
151 BuildPath(Path_SM, sFile, PLATFORM_MAX_PATH, "configs/shavit-prefix.txt");
152
153 File fFile = OpenFile(sFile, "r");
154
155 if(fFile == null)
156 {
157 SetFailState("Cannot open \"configs/shavit-prefix.txt\". Make sure this file exists and that the server has read permissions to it.");
158 }
159
160 char[] sLine = new char[PLATFORM_MAX_PATH*2];
161
162 while(fFile.ReadLine(sLine, PLATFORM_MAX_PATH*2))
163 {
164 TrimString(sLine);
165 strcopy(gS_MySQLPrefix, 32, sLine);
166
167 break;
168 }
169
170 delete fFile;
171}
172
173Action SetSQLInfo()
174{
175 if(gH_SQL == null)
176 {
177 gH_SQL = Shavit_GetDatabase();
178
179 CreateTimer(0.5, CheckForSQLInfo);
180 }
181
182 else
183 {
184 SQL_DBConnect();
185
186 return Plugin_Stop;
187 }
188
189 return Plugin_Continue;
190}
191
192void SQL_DBConnect()
193{
194 if(gH_SQL != null)
195 {
196 char[] sDriver = new char[8];
197 gH_SQL.Driver.GetIdentifier(sDriver, 8);
198 }
199}
200
201public Action CheckForSQLInfo(Handle Timer)
202{
203 return SetSQLInfo();
204}