Jump to content
GIGN Forum

Palidziet Nedaudz Ar Servera Monitoru!


Recommended Posts

Mans:

#include <amxmodx>
#include <amxmisc>
#include <dbi>

#define PLUGIN "Server monitor"
#define VERSION "0.1"
#define AUTHOR "n3wn4m3"

new team_wins[2]
new Sql:mysql

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    register_event("TextMsg","join_spec","b","2Spec_Mode")
    register_event("TeamScore", "team_score", "a")
    register_event("HLTV", "new_round", "a")
    register_event("TextMsg", "event_game_will_restart", "a", "2=#Game_will_restart_in")
    
    register_cvar("monitor_host","")
    register_cvar("monitor_db","")
    register_cvar("monitor_user","")
    register_cvar("monitor_pass","")
    
    set_task(0.5, "sql_init")

}



public sql_init() {
    new host[64],db[64],user[64],pass[64]
    get_cvar_string("monitor_host",host,64)
    get_cvar_string("monitor_db",db,64)
    get_cvar_string("monitor_user",user,64)
    get_cvar_string("monitor_pass",pass,64)
    
    mysql = dbi_connect(host, user, pass, db)
    
    if (mysql < SQL_OK) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        return 0
    }
    return PLUGIN_CONTINUE
}

public event_game_will_restart() {    
    team_wins[0] = 0
    team_wins[1] = 0    
}

public team_score() {    
    new team[2]
    read_data(1, team, 1)
    
    if(team[0] == 'C')
        team_wins[0] = read_data(2) 
    
    else if(team[0] == 'T')
        team_wins[1] = read_data(2)
    
    return PLUGIN_CONTINUE    
} 

public new_round() {    
    new players[32], num, playerid, names[32]
    get_players(players, num)
    
    new timeleft[32]
    new timelimit[32]
    new mapname[32]
    
    get_cvar_string("amx_timeleft", timeleft, 31)
    get_cvar_string("mp_timelimit", timelimit, 31)
    get_mapname(mapname, 31)
    
    new maxplayers = get_maxplayers()
    
    new Result:res = dbi_query(mysql, "UPDATE details SET timeleft='%s', timelimit='%s', mapname='%s', maxplayers='%d', scoret='%d', scorect='%d'", timeleft, timelimit, mapname, maxplayers, team_wins[1], team_wins[0])

    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res)
    }
    
    for(new i = 0; i < num; i++) {
        
        playerid = players[i]
        get_user_name(playerid, names, 31)
        
        new frags = get_user_frags(playerid)
        new team[32]
        get_user_team(playerid, team, 31)
        
        new Result:resfg = dbi_query(mysql, "UPDATE players SET frags='%d', team='%s' WHERE name='%s'", frags, team, names)
        
        if (resfg < RESULT_NONE) {
            new err[255]
            new errNum = dbi_error(mysql, err, 254)
            server_print("[MONITOR]: %s|%d", err, errNum)
            return 1
            } else {
            dbi_free_result(resfg)
        }
    }
    
    return PLUGIN_CONTINUE
}

public client_putinserver(id) {
    
    new namep[32]
    get_user_name(id, namep, 31)
    
    new Result:res = dbi_query(mysql, "INSERT INTO players (name, team) VALUES ('%s', 'SPECTATOR')", namep)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public join_spec(id) {
    
    new team[32],name[32]
    get_user_team(id, team, 31)
    get_user_name(id, name, 31)
    
    new Result:res = dbi_query(mysql, "UPDATE players SET name='%s', team='%s' WHERE name='%s'", name, team, name)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public client_infochanged(id) {
    
    new team[32],name[32]
    get_user_team(id, team, 31)
    get_user_name(id, name, 31)
    
    new newname[32], oldname[32] 
    get_user_info(id, "name", newname,31) 
    get_user_name(id,oldname,31)
    
    if (!equal(newname, oldname)) {
        
        new Result:res = dbi_query(mysql, "UPDATE players SET name='%s', team='%s' WHERE name='%s'", newname, team, oldname)
        
        if (res < RESULT_NONE) {
            new err[255]
            new errNum = dbi_error(mysql, err, 254)
            server_print("[MONITOR]: %s|%d", err, errNum)
            return 1
            } else {
            
            dbi_free_result(res)
        }
    }
    
    new Result:res = dbi_query(mysql, "UPDATE players SET name='%s', team='%s' WHERE name='%s'", name, team, name)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public client_disconnect(id) {
    
    new name[32]
    get_user_name(id, name, 31)
    
    new Result:res = dbi_query(mysql, "DELETE FROM players WHERE name='%s'", name)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public plugin_end() {
    

    new Result:res1 = dbi_query(mysql, "UPDATE details SET timeleft='', timelimit='', mapname='', maxplayers='', scoret='', scorect=''")
    
    if (res1 < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res1)
    }
    
    new Result:res2 = dbi_query(mysql, "TRUNCATE TABLE players")
    
    if (res2 < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res2)
    }
    
    dbi_close(mysql)
    return PLUGIN_CONTINUE
}

Oriģināls:

#include <amxmodx>
#include <amxmisc>
#include <dbi>

#define PLUGIN "Server monitor"
#define VERSION "0.1"
#define AUTHOR "n3wn4m3"

new team_wins[2]
new Sql:mysql

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    register_event("TextMsg","join_spec","b","2Spec_Mode")
    register_event("TeamScore", "team_score", "a")
    register_event("HLTV", "new_round", "a")
    register_event("TextMsg", "event_game_will_restart", "a", "2=#Game_will_restart_in")
    
    register_cvar("monitor_host","")
    register_cvar("monitor_db","")
    register_cvar("monitor_user","")
    register_cvar("monitor_pass","")
    
    set_task(0.5, "sql_init")

}



public sql_init() {
    new host[64],db[64],user[64],pass[64]
    get_cvar_string("monitor_host",host,64)
    get_cvar_string("monitor_db",db,64)
    get_cvar_string("monitor_user",user,64)
    get_cvar_string("monitor_pass",pass,64)
    
    mysql = dbi_connect(host, user, pass, db)
    
    if (mysql < SQL_OK) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        return 0
    }
    return PLUGIN_CONTINUE
}

public event_game_will_restart() {    
    team_wins[0] = 0
    team_wins[1] = 0    
}

public team_score() {    
    new team[2]
    read_data(1, team, 1)
    
    if(team[0] == 'C')
        team_wins[0] = read_data(2) 
    
    else if(team[0] == 'T')
        team_wins[1] = read_data(2)
    
    return PLUGIN_CONTINUE    
} 

public new_round() {    
    new players[32], num, playerid, names[32]
    get_players(players, num)
    
    new nextmap[32]
    new timeleft[32]
    new timelimit[32]
    new mapname[32]
    
    get_cvar_string("amx_nextmap", nextmap, 31)
    get_cvar_string("amx_timeleft", timeleft, 31)
    get_cvar_string("mp_timelimit", timelimit, 31)
    get_mapname(mapname, 31)
    
    new maxplayers = get_maxplayers()
    
    new Result:res = dbi_query(mysql, "UPDATE details SET nextmap='%s', timeleft='%s', timelimit='%s', mapname='%s', maxplayers='%d', scoret='%d', scorect='%d'", nextmap, timeleft, timelimit, mapname, maxplayers, team_wins[1], team_wins[0])

    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res)
    }
    
    for(new i = 0; i < num; i++) {
        
        playerid = players[i]
        get_user_name(playerid, names, 31)
        
        new frags = get_user_frags(playerid)
        new deaths = get_user_deaths(playerid)
        new team[32]
        get_user_team(playerid, team, 31)
        
        new Result:resfg = dbi_query(mysql, "UPDATE players SET frags='%d', deaths='%d', team='%s' WHERE name='%s'", frags, deaths, team, names)
        
        if (resfg < RESULT_NONE) {
            new err[255]
            new errNum = dbi_error(mysql, err, 254)
            server_print("[MONITOR]: %s|%d", err, errNum)
            return 1
            } else {
            dbi_free_result(resfg)
        }
    }
    
    return PLUGIN_CONTINUE
}

public client_putinserver(id) {
    
    new namep[32]
    get_user_name(id, namep, 31)
    
    new Result:res = dbi_query(mysql, "INSERT INTO players (name, team) VALUES ('%s', 'SPECTATOR')", namep)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public join_spec(id) {
    
    new team[32],name[32]
    get_user_team(id, team, 31)
    get_user_name(id, name, 31)
    
    new Result:res = dbi_query(mysql, "UPDATE players SET name='%s', team='%s' WHERE name='%s'", name, team, name)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public client_infochanged(id) {
    
    new team[32],name[32]
    get_user_team(id, team, 31)
    get_user_name(id, name, 31)
    
    new newname[32], oldname[32] 
    get_user_info(id, "name", newname,31) 
    get_user_name(id,oldname,31)
    
    if (!equal(newname, oldname)) {
        
        new Result:res = dbi_query(mysql, "UPDATE players SET name='%s', team='%s' WHERE name='%s'", newname, team, oldname)
        
        if (res < RESULT_NONE) {
            new err[255]
            new errNum = dbi_error(mysql, err, 254)
            server_print("[MONITOR]: %s|%d", err, errNum)
            return 1
            } else {
            
            dbi_free_result(res)
        }
    }
    
    new Result:res = dbi_query(mysql, "UPDATE players SET name='%s', team='%s' WHERE name='%s'", name, team, name)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public client_disconnect(id) {
    
    new name[32]
    get_user_name(id, name, 31)
    
    new Result:res = dbi_query(mysql, "DELETE FROM players WHERE name='%s'", name)
    
    if (res < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        
        dbi_free_result(res)
    }
    
    return PLUGIN_CONTINUE
}

public plugin_end() {
    

    new Result:res1 = dbi_query(mysql, "UPDATE details SET nextmap='', timeleft='', timelimit='', mapname='', maxplayers='', scoret='', scorect=''")
    
    if (res1 < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res1)
    }
    
    new Result:res2 = dbi_query(mysql, "TRUNCATE TABLE players")
    
    if (res2 < RESULT_NONE) {
        new err[255]
        new errNum = dbi_error(mysql, err, 254)
        server_print("[MONITOR]: %s|%d", err, errNum)
        return 1
        } else {
        dbi_free_result(res2)
    }
    
    dbi_close(mysql)
    return PLUGIN_CONTINUE
}

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...