Hi everybody!
I write a plugin to replace amxx native user authorization engine. It requests the database for user info and sets flags according to user's group.
4 now I’ve done the following:
Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <dbi>
#define PLUGIN "Auth Plugin"
#define VERSION "1.0"
#define AUTHOR "PlayingTalking"
#define dbhost "127.0.0.1"
#define dbname "xxx"
#define dbuser "xxx"
#define dbpass "xxx"
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_event("ResetHUD", "hook_join_auth","be")
}
public hook_join_auth(id) {
new playername[35]
new playerpass[35]
new playergroup
get_user_name(id, playername, 50)
new error[35]
new Sql:dbh = dbi_connect(dbhost, dbuser, dbpass, dbname, error, 255);
if (dbh == SQL_FAILED) {
log_amx("[PT Auth] SQL Connection Failed = %s", error)
return PLUGIN_HANDLED;
}
new Result:result
result = dbi_query(dbh, "SELECT username, password, groupid FROM tblusers WHERE username = '%s'", playername)
if (result > RESULT_NONE) {
if (dbi_num_rows(result)>0) {
dbi_nextrow(result)
dbi_field(result, 1, playername, 31)
dbi_field(result, 2, playerpass, 31)
playergroup=dbi_field(result, 3)
new setinfopass[32]
get_user_info(id, "_password", setinfopass, 31)
new md5sum[34]
md5(setinfopass,md5sum)
if (md5sum[31] == playerpass[31]) {
//new flags
remove_user_flags(id, ADMIN_USER)
switch(playergroup){
case 5: // Site Admin – Server Top Admin
{
set_user_flags(id, read_flags("abcdefghijklmnopqrstu"))
}
case 3: // Site Moderator – Server Admin
{
set_user_flags(id, read_flags("bcdefju"))
}
case 2: // VIP
{
set_user_flags(id, read_flags("bj"))
}
case 1: // User
{
set_user_flags(id, read_flags("j"))
}
}
} else {
server_cmd("kick #%d Wrong password for player %s. ",uid, playername)
}
}
dbi_free_result(result)
}
dbi_close(dbh)
return PLUGIN_HANDLED
}
Everything works fine but the plugin has 2 disadvantages:
1. The procedure of checking is called every round which is 2 often. And it starts only when a player is alive and has joined a team
2. This method disallows the slot reservation mechanism.
I’ve tried to add the following:
Code:
public client_connect(id)
{
hook_join_auth(id)
}
It work but as I funded out (imho) my function is called before amxx native auth procedures. Thus my plugin firstly sets proper flags to player and after that amxx changes them, back to "z"
This is my first plugin and everything I’ve done I've done by reading this forum. But now I couldn't fide answer for the question here:
Q1: How to call my function after amxx calls its own. Or if it s possible even disable amxx native authorization mechanism?
Maybe smb suggests an other salvation. To my mind:
1. At player connects server plugin should check his info and set flags according to group (top admin, common admin, vip, user) and flag "z" to other not registered users.
2. The same when client_infochanged
3. In future I want to disable slot reservation in my server. And therefore when an admin or vip connects full server the plugin should kick one of not registered players with worst kills/deaths coefficient. So my second question is:
Q2: how can I get players list with their kill/deaths information?