311890 发表于 2008-11-9 14:19:29

如何将如下的插件代码中修改为盗版也可以使用呢?

代码如下:此代码只能用于正版服务器,是通过authid来统计,现在想用于盗版服务器,使用name来统计,应该修改什么地方?

/* Plugin generated by AMXX-Studio */
//29.05.2008 v0.7 add batch process.
//28.05.2008 v0.6 any fix.
//25.04.2008 v0.5 fix connecting bug for windows.
//23.04.2008 v0.4 add cvar and errcode.
//22.04.2008 v0.3 cut some "public"
//20.04.2008 v0.2 single quotation in name no write bug fix.
//19.04.2008 v0.1 first release
#include <amxmodx>
#include <amxmisc>
#include <csx>
#include <sqlx>
#define PLUGIN "Player Status in DB"
#define VERSION "0.73"
#define AUTHOR "SandStriker"
#define STATS_KILLS             0
#define STATS_DEATHS            1
#define STATS_HS                2
#define STATS_TKS               3
#define STATS_SHOTS             4
#define STATS_HITS            5
#define STATS_DAMAGE            6
#define MAX_NAME_LENGTH 31
#define MAX_ERR_LENGTH 128
#define MAX_QUERY_LENGTH 1024
#define MAX_LENGTH 31
#define MAX_PLAYERS 32 + 1
#define TASK_ID 6218742
//Database setting pointers
new g_dbhost,g_dbuser,g_dbpass,g_dbname,g_tbname
//Database Handles
new Handle:g_dbt,Handle:g_dbc
//Table name
new g_ptbname
//update time
new g_uptime
//new g_initflag
new g_datadir
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your code here...
new basedir
register_srvcmd("amx_psd_update","insert_batch",-1," - Batch processing update in DB.")
register_srvcmd("amx_psd_reset","reset_database",-1," - Reset in DB.")
register_srvcmd("amx_psd_initialize","init_status",-1," - initializing all player status and dataabse.")
//register_srvcmd("Y","init_sequence",-1,"")
//register_srvcmd("N","init_sequence",-1,"")

//register_event("SendAudio", "EndRoundUpdate", "a", "2=%!MRAD_terwin", "2=%!MRAD_ctwin", "2=%!MRAD_rounddraw")
g_uptime = register_cvar("amx_psd_uptime","15")
g_dbhost = register_cvar("amx_sql_host","127.0.0.1")
g_dbuser = register_cvar("amx_sql_user","root")
g_dbpass = register_cvar("amx_sql_pass","")
g_dbname = register_cvar("amx_sql_db","cstrike")
g_tbname = register_cvar("psd_tbname","statustable")
//g_initflag = register_cvar("psb_initflag","0")

register_cvar("amx_sql_type","mysql")
   get_configsdir(basedir, 31)
formatex(basedir,31,"%s/sql.cfg",basedir)
   server_cmd("exec %s",basedir)
get_datadir(g_datadir,31)

set_task(1.0,"plugin_core",0,"",0,"",0)
return PLUGIN_HANDLED_MAIN
}
//LoadPlugin
public plugin_core()
{
new host,user,pass,db,error,ercode
get_pcvar_string(g_dbhost, host, 63)
   get_pcvar_string(g_dbuser, user, 31)
   get_pcvar_string(g_dbpass, pass, 31)
   get_pcvar_string(g_dbname, db, 31)
get_pcvar_string(g_tbname, g_ptbname,31)
      
g_dbt = SQL_MakeDbTuple(host,user,pass,db)
g_dbc = SQL_Connect(g_dbt,ercode,error,127)

if(g_dbc == Empty_Handle)
{
   server_print(" Error No.%d: %s", ercode,error)
   }else
{
    server_print(" Connecting successful.")
    init_database()
//init_insert()
//sql_disconnect()
set_task(get_pcvar_num(g_uptime)*60.0,"UpdateInServer",TASK_ID,"",0,"b")
   }
return PLUGIN_CONTINUE
}
//Module setting
public plugin_modules()
{
require_module("mysql")
require_module("csx")
return PLUGIN_CONTINUE
}
//End Plugin
public plugin_end()
{
if(task_exists(TASK_ID))
remove_task(TASK_ID)
sql_disconnect()
return PLUGIN_CONTINUE
}
//Disconnect MySQL server
sql_disconnect()
{
SQL_FreeHandle(g_dbc)
SQL_FreeHandle(g_dbt)
server_print(" Closing connection...")
return PLUGIN_CONTINUE
}
//initialize all player status
public init_status()
{
new datfile,datfile2
formatex(datfile,MAX_LENGTH+9,"%s/csstats.dat",g_datadir)
get_time("%Y%M%D",datfile2,MAX_LENGTH+19)
formatex(datfile2,MAX_LENGTH+19,"%s/csstats-%s.bak",g_datadir,datfile2)
server_print(datfile)
if(file_exists(datfile))
{
if(rename_file(datfile,datfile2,1))
{
   server_print(" Initialize Successful, and backup csstats.dat now.")
   server_print(" Please reloading server...")
}else{
   server_print(" Initialize Failed...")
}
}else{
server_print(" Can't Initializing... Sequence Failed...")
}
return PLUGIN_CONTINUE
}
/*
init_sequence()
{
if(get_pcvar_num(g_initflag)!=1)return PLUGIN_CONTINUE
new cmd

read_argc(0,cmd,1)
if(equali(cmd,"Y"))
set_pcvar_num(g_initflag,2)
else(equali(cmd,"N"))
set_pcvar_num(g_initflag,0)
return PLUGIN_CONTINUE
}
*/
//Create Table
init_database()
{
new Handle:result
new QUERY
formatex(QUERY,MAX_QUERY_LENGTH,
"CREATE TABLE IF NOT EXISTS `%s` (`authid` VARCHAR( 32 ) NOT NULL, `name` VARCHAR( 32 ) NOT NULL , `date` TIMESTAMP( 10 ) NOT NULL , `score` INT NOT NULL ,`kills` INT NOT NULL , `teamkills` INT NOT NULL, `deaths` INT NOT NULL , `hits` INT NOT NULL , `shots` INT NOT NULL , `headshots` INT NOT NULL , `efficiency` DOUBLE (19,2) DEFAULT NULL, `accuracy` double(19,2) default NULL,`accuracyHS` double(19,2) default NULL,`kdrate` double(19,2) default NULL, PRIMARY KEY(`authid`))", g_ptbname)
result = SQL_PrepareQuery(g_dbc, QUERY)
SQL_Execute(result)
formatex(QUERY,MAX_QUERY_LENGTH,"ALTER TABLE `%s` ADD `kdrate` double(19,2) default NULL",g_ptbname)
result = SQL_PrepareQuery(g_dbc, QUERY)
SQL_Execute(result)
SQL_FreeHandle(result)
return PLUGIN_CONTINUE
}
//Batch Poccessing
public insert_batch()
{
new iMax = get_statsnum()
new Handle:result
new sName,sAuthid
new iKills,iDeaths,iHS,iTK,iShots,iHits,iScore,Float:iEff,Float:iAcc,Float:iAccHS,Float:iKdRate
new izStats, izBody
for(new i=0;i<iMax;i++)
{
get_stats(i, izStats, izBody, sName, MAX_NAME_LENGTH,sAuthid,MAX_NAME_LENGTH)
if(equal(sAuthid,"VALVE_ID_PENDING") || equal(sAuthid,"STEAM_ID_LAN")) continue
replace_all(sName, MAX_NAME_LENGTH, "'", "")
iKills = izStats
iDeaths = izStats
iHS = izStats
iTK = izStats
iShots = izStats
iHits = izStats
iScore = izStats - izStats - izStats
iEff = effec(izStats)
iAcc = accuracy(izStats)
iAccHS = accuracyHeadShot(izStats)
iKdRate = kdrate(izStats)

result = SQL_PrepareQuery(g_dbc, "INSERT INTO `%s` (authid,name,date,score,kills,teamkills,deaths,hits,shots,headshots,efficiency,accuracy,accuracyHS,kdrate) values('%s','%s',NOW(),%i,%i,%i,%i,%i,%i,%i,%1.2f,%1.2f,%1.2f,%1.2f)", g_ptbname, sAuthid, sName, iScore, iKills, iTK, iDeaths, iHits, iShots, iHS, iEff, iAcc, iAccHS,iKdRate)
if(!SQL_Execute(result))
{
   result = SQL_PrepareQuery(g_dbc, "UPDATE `%s` SET name='%s',date=NOW(),score=%i,kills=%i,teamkills=%i,deaths=%i,hits=%i,shots=%i,headshots=%i,efficiency=%1.2f,accuracy=%1.2f, accuracyHS=%1.2f, kdrate=%1.2f WHERE authid='%s'", g_ptbname, sName, iScore, iKills, iTK, iDeaths, iHits, iShots, iHS, iEff, iAcc, iAccHS, iKdRate,sAuthid)
   SQL_Execute(result)
}
SQL_FreeHandle(result)
}
server_print(" Updating successful.")
return PLUGIN_HANDLED
}
//Clear table in Database
public reset_database()
{
new Handle:result
result=SQL_PrepareQuery(g_dbc, "TRUNCATE TABLE `%s`", g_ptbname);
if(!SQL_Execute(result))
server_print(" Error: Can't reset database..");
else
server_print(" Reset Database successful.")
return PLUGIN_HANDLED
}
//update player in server
public UpdateInServer()
{
new id
for(id = 1;id < MAX_PLAYERS;id++)
if(is_user_connected(id)) SequentialData(id)
server_print(" Updating successful.")
return PLUGIN_CONTINUE
}
//client disconnect update
public client_disconnect(id)
{
if(is_user_connected(id)) SequentialData(id)
return PLUGIN_CONTINUE
}
//client connected update
public client_putinserver(id)
{
if(is_user_connected(id)) SequentialData(id)
return PLUGIN_CONTINUE
}
//add or update recode line
SequentialData(id)
{
new Handle:result
new sName,sAuthid
new iKills,iDeaths,iHS,iTK,iShots,iHits,iScore,Float:iEff,Float:iAcc,Float:iAccHS,Float:iKdRate
new izStats, izBody
get_user_stats(id, izStats, izBody)
get_user_name(id,sName, MAX_NAME_LENGTH)
get_user_authid(id,sAuthid,MAX_NAME_LENGTH)
if(equal(sAuthid,"VALVE_ID_PENDING") || equal(sAuthid,"STEAM_ID_LAN")) return PLUGIN_CONTINUE
replace_all(sName, MAX_NAME_LENGTH, "'", "")
iKills = izStats
iDeaths = izStats
iHS = izStats
iTK = izStats
iShots = izStats
iHits = izStats
iScore = izStats - izStats - izStats
iEff = effec(izStats)
iAcc = accuracy(izStats)
iAccHS = accuracyHeadShot(izStats)
iKdRate = kdrate(izStats)

result = SQL_PrepareQuery(g_dbc, "INSERT INTO `%s` (authid,name,date,score,kills,teamkills,deaths,hits,shots,headshots,efficiency,accuracy,accuracyHS,kdrate) values('%s','%s',NOW(),%i,%i,%i,%i,%i,%i,%i,%1.2f,%1.2f,%1.2f,%1.2f)", g_ptbname, sAuthid, sName, iScore, iKills, iTK, iDeaths, iHits, iShots, iHS, iEff, iAcc, iAccHS,iKdRate)
if(!SQL_Execute(result))
{
result = SQL_PrepareQuery(g_dbc, "UPDATE `%s` SET name='%s',date=NOW(),score=%i,kills=%i,teamkills=%i,deaths=%i,hits=%i,shots=%i,headshots=%i,efficiency=%1.2f,accuracy=%1.2f, accuracyHS=%1.2f, kdrate=%1.2f WHERE authid='%s'", g_ptbname, sName, iScore, iKills, iTK, iDeaths, iHits, iShots, iHS, iEff, iAcc, iAccHS, iKdRate,sAuthid)
SQL_Execute(result)
}
SQL_FreeHandle(result)
return PLUGIN_CONTINUE
}
/*
CheckError(Handle:result)
{
new err
SQL_QueryError(result,err,MAX_ERR_LENGTH)
server_print(" Error: %s",err)
}
*/
// Stats formulas
Float:accuracy(izStats)
{
if (!izStats)
return (0.0)

return (100.0 * float(izStats) / float(izStats))
}
Float:accuracyHeadShot(izStats)
{
if (!izStats)
return (0.0)

return (100.0 * float(izStats) / float(izStats))
}
Float:effec(izStats)
{
if (!izStats)
return (0.0)

return (100.0 * float(izStats) / float(izStats + izStats))
}
Float:kdrate(izStats)
{
if(!izStats || !izStats)
return (0.0)
return (float(izStats)/ float(izStats))
}
页: [1]
查看完整版本: 如何将如下的插件代码中修改为盗版也可以使用呢?