Code:
#include <core>
#include <console>
#include <string>
#include <plugin>
#include <admin>
#include <adminlib>
#define DB_ACCESS 512
new g_Version[]="1.0";
public admin_db(HLCommand,HLData,HLUserName,UserIndex)
{
new User[MAX_NAME_LENGTH];
new Data[MAX_TEXT_LENGTH];
new Command[MAX_TEXT_LENGTH];
convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
convert_string(HLUserName,User,MAX_NAME_LENGTH);
convert_string(HLData,Data,MAX_DATA_LENGTH);
new sName[MAX_NAME_LENGTH];
new sTargetWDB[200];
new iUserWONID = 0;
new sUserWONID[20];
new SessionID;
new Team;
new iLines = 0;
new sLine[MAX_DATA_LENGTH];
new directory[] = "woniddb";
new path[MAX_DATA_LENGTH];
if(strlen(Data) > 0)
{
if(check_user(Data) == 1) {
get_username(Data,sName,MAX_NAME_LENGTH);
get_userWONID(sName,iUserWONID);
if (iUserWONID >-2 && iUserWONID<4000000 && strlen(sName) > 0) {
snprintf(sUserWONID,MAX_TEXT_LENGTH,"%i",iUserWONID);
snprintf(path,MAX_TEXT_LENGTH,"%s/%s",directory,sUserWONID);
if (fileexists(path) == 1) {
iLines = filesize(path, 1);
snprintf(sTargetWDB,MAX_TEXT_LENGTH,">> %s <%s>",sName,sUserWONID);
new j = 0;
for ( j = 1; j <= iLines ; j++ )
if(readfile(path,sLine,j,100) != 0)
if ((strlen(sTargetWDB) + strlen(sLine)) + 6 >= 100 ) {
selfmessage(sTargetWDB);
sTargetWDB = "";
snprintf(sTargetWDB,200,"%s ^"%s^"",sTargetWDB,sLine);
} else
snprintf(sTargetWDB,200,"%s ^"%s^"",sTargetWDB,sLine);
selfmessage(sTargetWDB);
}
}
}
}
else
{
new MaxPlayers = maxplayercount();
new i = 0;
for(i=1;i<=MaxPlayers;i++) {
if(playerinfo(i,sName,MAX_NAME_LENGTH,SessionID,iUserWONID,Team) == 1)
{
get_userWONID(sName,iUserWONID);
if (iUserWONID >-2 && iUserWONID<4000000 && strlen(sName) > 0) {
snprintf(sUserWONID,MAX_TEXT_LENGTH,"%i",iUserWONID);
snprintf(path,MAX_TEXT_LENGTH,"%s/%s",directory,sUserWONID);
if (fileexists(path) == 1) {
iLines = filesize(path, 1);
snprintf(sTargetWDB,MAX_TEXT_LENGTH,">> %s <%s>",sName,sUserWONID);
new j = 0;
for ( j = 1; j <= iLines ; j++ )
if(readfile(path,sLine,j,100) != 0)
if ((strlen(sTargetWDB) + strlen(sLine)) + 6 >= 100 ) {
selfmessage(sTargetWDB);
sTargetWDB = "";
snprintf(sTargetWDB,200,"%s ^"%s^"",sTargetWDB,sLine);
} else
snprintf(sTargetWDB,200,"%s ^"%s^"",sTargetWDB,sLine);
selfmessage(sTargetWDB);
}
}
}
}
}
return PLUGIN_HANDLED;
}
WonidDB(wonid[],name[]){
new iLines = 0;
new sLine[MAX_DATA_LENGTH];
new directory[] = "woniddb";
new path[MAX_DATA_LENGTH];
snprintf(path,MAX_TEXT_LENGTH,"%s/%s",directory,wonid);
if (fileexists(path) == 1)
{
iLines = filesize(path, 1);
new i = 0;
for ( i = 1; i <= iLines ; i++ )
if(readfile(path,sLine,i,100) != 0)
if(streq(sLine,name) == 1)
break;
if(i > iLines)
writefile(path,name,iLines+60);
}
else
writefile(path,name,1);
return 1;
}
public plugin_info(HLOldName, HLNewName, UserIndex) {
new iUserWONID = 0;
new sUserWONID[20];
new NewName[MAX_NAME_LENGTH];
new SessionID;
new Team;
if (playerinfo(UserIndex,NewName,MAX_NAME_LENGTH,SessionID,iUserWONID,Team)==1)
if ( strlen(NewName) > 0) {
get_userWONID(NewName,iUserWONID);
if (iUserWONID >-2 && iUserWONID<4000000) {
snprintf(sUserWONID,MAX_TEXT_LENGTH,"%i",iUserWONID);
WonidDB(sUserWONID,NewName);
}
}
return PLUGIN_CONTINUE;
}
public plugin_init() {
plugin_registerinfo("WONID DATABASE Plugin","Saves all wonids connecting to server",g_Version);
plugin_registercmd("admin_db","admin_db",DB_ACCESS,"admin_db <WONID/NAME/NICHTS>: Listet die Wonid Datenbank auf.");
return PLUGIN_CONTINUE;
}