loading
open in
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

#include <amxmodx>
#include <amxmisc>
#include <sqlx>

#define PLUGIN "Platforma Redirect"
#define VERSION "2.0"
#define AUTHOR "HaldiR"

#define szHost "bla"
#define szUser "bla"
#define szPass "bla"
#define szDb "bla"

#define MAX_SERVER 10 // aici setezi cate servere sa incarce platforma maxim, in sql pot fi si 100, daca aici pui 10, doar pe primele 10 le ia, ultimele 10 adaugate
#define UPDATE_TIME 1 // interval de timp in care isi face update, minute


new Handle:g_SqlTuple
new iCount = 0 //Numarul maxim de servere
new iServer = 0 //Integer pentru redirectionare pas cu pas
new iDrops = 0 //Numarul total de dropuri

new szBuffer[4000]

new server_list[MAX_SERVER][32]


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	g_SqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDb, 10)
	
	set_task( float( UPDATE_TIME * 60 ), "init_servers", _, _, _, "b")
	
	register_concmd("_list", "print_list")
	register_concmd("_update", "init_servers")
	register_concmd("_total", "show_total")
}

public show_total(id) server_print("###------> TOTAL DROPS: %d", iDrops)

public print_list(id){
	for(new i = 0, n = 0; i < MAX_SERVER; i++){
		if(strlen(server_list[i]) > 0){
			server_print("# [%d] | %s", n + 1, server_list[i])
			n++;
		}
	}
	
	return PLUGIN_HANDLED
}

public plugin_cfg() {
	init_servers();
	server_cmd("mp_timelimit 0;mp_roundtime 9;");
	
	static szFile[64];
	
	formatex( szFile, charsmax( szFile ), "addons/amxmodx/configs/GameMenu.ini");
	
	new iFileIni = fopen( szFile, "rt" );
	
	while( !feof( iFileIni ) ){
		fgets( iFileIni, szBuffer, charsmax( szBuffer ) );
	}
	
	fclose( iFileIni );
}

public init_servers(){
	static sql[256]
	
	formatex(sql, charsmax(sql), "SELECT `server` FROM `server_list` ORDER BY `id` DESC LIMIT %d", MAX_SERVER)
	SQL_ThreadQuery(g_SqlTuple, "sql_init_servers", sql)
}

public reset_list(){
	for(new i = 0; i < iCount; i++){
		arrayset(server_list[i], 0, 31)
	}
}

public sql_init_servers(FailState, Handle:Query, szError[], Errcode){
	
	if(iCount){
		reset_list()
		iCount = 0
	}
	
	static szDate[32]
	
	get_time("%d.%m.%y - %H:%M:%S", szDate, 31)
	server_print("[%s] - Getting server list.", szDate)
	
	QueryStatus(FailState, szError, Errcode)
	
	new i = 0, server[32]
	while(SQL_MoreResults(Query)){
		
		if(i >= MAX_SERVER)
			break
		
		SQL_ReadResult(Query, 0, server, 31)
		formatex(server_list[i], 31, "%s", server)
		SQL_NextRow(Query)
		i++
		iCount++;
	}
	
	SQL_FreeHandle(Query)
}

public client_connect(id){
	if(is_user_bot(id)){
		server_cmd("kick #%d", id)
		return PLUGIN_HANDLED
	}
		
	redirect_user(id)
	
	return PLUGIN_CONTINUE
}

public client_putinserver(id){
	if(is_user_bot(id)){
		server_cmd("kick #%d", id)
		return PLUGIN_HANDLED
	}

	set_task(3.0, "redirect_user", id)
	
	return PLUGIN_CONTINUE
}

public add_game_menu(id){
	
	client_cmd( id, "motdfile ^"resource/GameMenu.res^"" );
	client_cmd( id, "motd_write %s", szBuffer);
	
}


public redirect_user(id){
	
	iDrops++
	
	
	static server[32], name[32]
	
	formatex(server, 31, "%s", server_list[iServer]);
	get_user_name(id, name, 31)
	
	if(strlen(server) == 0){
		client_cmd(id, "disconnect")
		return PLUGIN_HANDLED
	}
	
	add_game_menu(id)
	
	client_cmd(id, "Connect %s", server)
	server_print("[%s] -> %s", name, server)
	
	iServer = ( iServer >= iCount - 1 ? 0 : ( iServer + 1 ) );
	
	return PLUGIN_CONTINUE
}

public QueryStatus(FailState, szError[], Errcode){
	
	static szDate[32], error[512]
	
	get_time("%d.%m.%y - %H:%M:%S", szDate, 31)
	
	if(FailState == TQUERY_CONNECT_FAILED){
		formatex(error, charsmax(error), "[MYSQL CONNECT ERROR] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
		write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
		
		server_print("A aparut o eroare ! Info in logs !")
	}
	else if(FailState == TQUERY_QUERY_FAILED){
		formatex(error, charsmax(error), "[MYSQL QUERY ERROR] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
		write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
		
		server_print("A aparut o eroare ! Info in logs !")
	}
	else if(Errcode){
		formatex(error, charsmax(error), "[MYSQL ERROR CODE] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
		write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
		
		server_print("A aparut o eroare ! Info in logs !")
	}
	
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1048\\ f0\\ fs16 \n\\ par }
*/