搜索
查看: 2190|回复: 0

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

[复制链接]
发表于 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[MAX_LENGTH+1]
//update time
new g_uptime
//new g_initflag
new g_datadir[MAX_LENGTH+1]
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your code here...
new basedir[32]
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[64],user[32],pass[32],db[32],error[MAX_ERR_LENGTH+1],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("[PSD] Error No.%d: %s", ercode,error)
   }else
{
    server_print("[PSD] 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("[PSD] Closing connection...")
return PLUGIN_CONTINUE
}
//initialize all player status
public init_status()
{
new datfile[MAX_LENGTH+10],datfile2[MAX_LENGTH+20]
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("[PSD] Initialize Successful, and backup csstats.dat now.")  
   server_print("[PSD] Please reloading server...")
  }else{
   server_print("[PSD] Initialize Failed...")
  }
}else{
  server_print("[PSD] Can't Initializing... Sequence Failed...")
}
return PLUGIN_CONTINUE
}
/*
init_sequence()
{
if(get_pcvar_num(g_initflag)!=1)return PLUGIN_CONTINUE
new cmd[1]

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[MAX_QUERY_LENGTH]
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[MAX_NAME_LENGTH+1],sAuthid[MAX_NAME_LENGTH+1]
new iKills,iDeaths,iHS,iTK,iShots,iHits,iScore,Float:iEff,Float:iAcc,Float:iAccHS,Float:iKdRate
new izStats[8], izBody[8]
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[STATS_KILLS]
  iDeaths = izStats[STATS_DEATHS]
  iHS = izStats[STATS_HS]
  iTK = izStats[STATS_TKS]
  iShots = izStats[STATS_SHOTS]
  iHits = izStats[STATS_HITS]
  iScore = izStats[STATS_KILLS] - izStats[STATS_DEATHS] - izStats[STATS_TKS]
  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("[PSD] 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("[PSD] Error: Can't reset database..");
else
  server_print("[PSD] 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("[PSD] 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[MAX_NAME_LENGTH+1],sAuthid[MAX_NAME_LENGTH+1]
new iKills,iDeaths,iHS,iTK,iShots,iHits,iScore,Float:iEff,Float:iAcc,Float:iAccHS,Float:iKdRate
new izStats[8], izBody[8]
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[STATS_KILLS]
iDeaths = izStats[STATS_DEATHS]
iHS = izStats[STATS_HS]
iTK = izStats[STATS_TKS]
iShots = izStats[STATS_SHOTS]
iHits = izStats[STATS_HITS]
iScore = izStats[STATS_KILLS] - izStats[STATS_DEATHS] - izStats[STATS_TKS]
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[MAX_ERR_LENGTH+1]
SQL_QueryError(result,err,MAX_ERR_LENGTH)
server_print("[PSD] Error: %s",err)
}
*/
// Stats formulas
Float:accuracy(izStats[8])
{
if (!izStats[STATS_SHOTS])
  return (0.0)

return (100.0 * float(izStats[STATS_HITS]) / float(izStats[STATS_SHOTS]))
}
Float:accuracyHeadShot(izStats[8])
{
if (!izStats[STATS_SHOTS])
  return (0.0)

return (100.0 * float(izStats[STATS_HS]) / float(izStats[STATS_SHOTS]))
}
Float:effec(izStats[8])
{
if (!izStats[STATS_KILLS])
  return (0.0)

return (100.0 * float(izStats[STATS_KILLS]) / float(izStats[STATS_KILLS] + izStats[STATS_DEATHS]))
}
Float:kdrate(izStats[8])
{
if(!izStats[STATS_KILLS] || !izStats[STATS_DEATHS])
  return (0.0)
return (float(izStats[STATS_KILLS])/ float(izStats[STATS_DEATHS]))
}
游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表