hab alles versucht aber es funktioniert nicht,,bin auch ein Newbi
@sentinel.. Bitte schön.
Code:
/*******************************************************************
** Biohazards Spooky Names Plugin v 1.0 *******
*** ( plugin_logd_spooky_names.sma ) ******
**** INFO: This Plugin compares the names of connecting *****
***** players to those written in a textfile. If the players ****
****** name wasnt found in the file, he will be kicked or ***
******* renamed. **
*******************************************************************/
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
#define ACCESS_CONSOLE 131072
#define ACCESS_SPOOKY 1024
#define NAME_LENGTH 25
#define WONID_LENGTH 15
#define MAX_USERS 30 // How many users do we have maximum
#define MAX_ALTERNATIVE 10 // How many alternative names do we have maximum
#define ACTION_KICK 0 // 0 - Rename..., 1 - Kick unauthorized player
#define DEBUG 0 // 0 - Debug Mode off, 1 - Debug Mode on
new STRING_VERSION[MAX_DATA_LENGTH] = "1.0"; // Plugin Version
new FILENAME[MAX_DATA_LENGTH] = "names.cfg"; // Name of Config-File
new PARSED_NAMES[MAX_USERS][NAME_LENGTH]; // Names from 'names.cfg' will be copied to this array
new PARSED_WONIDS[MAX_USERS][WONID_LENGTH]; // WONIDS from 'names.cfg' will be copied to this array
new BOARD_NAMES[MAX_USERS][MAX_NAME_LENGTH]; // The name of each connecting user will be stored here
new BOARD_WONIDS[MAX_USERS][WONID_LENGTH]; // Holds the users WONID
new STATUS[MAX_USERS][2]; // Holds the status of each user
new ALTERNATIVE_NAMES[MAX_ALTERNATIVE][MAX_NAME_LENGTH]; // Array of alternative Names
new AltNamesQuantity = 0; // Real number of alternative names after initializing plugin
new bEnabled = 1; // 1 - Plugin on, 0 - Plugin off
new bAction = ACTION_KICK;
public admin_spooky_off(HLCommand, HLData, HLUserName, UserIndex)
{
new User[MAX_NAME_LENGTH];
new Text[MAX_TEXT_LENGTH];
convert_string(HLUserName, User, MAX_NAME_LENGTH);
if (bEnabled != 0) {
bEnabled = 0; // Plugin off
say(">>> Spooky Names Plugin has been disabled <<<");
snprintf(Text, MAX_TEXT_LENGTH, "Spooky Names Plugin has been disabled by %s", User);
log(Text);
}
else selfmessage("Spooky Names Plugin already disabled");
return PLUGIN_HANDLED;
}
public admin_spooky_on(HLCommand, HLData, HLUserName, UserIndex)
{
new User[MAX_NAME_LENGTH];
new Text[MAX_TEXT_LENGTH];
convert_string(HLUserName, User, MAX_NAME_LENGTH);
if (bEnabled != 1) {
bEnabled = 1; // Plugin on
say(">>> Spooky Names Plugin has been enabled <<<");
snprintf(Text, MAX_TEXT_LENGTH, "Spooky Names Plugin has been enabled by %s", User);
log(Text);
}
else selfmessage("Spooky Names Plugin already enabled");
return PLUGIN_HANDLED;
}
public sn_HandleTeamSelect(HLCommand,HLData,HLUserName,UserIndex)
{
if (!bEnabled)
return PLUGIN_CONTINUE;
new Data[MAX_DATA_LENGTH];
new sID[MAX_DATA_LENGTH];
new sTeam[MAX_DATA_LENGTH];
new iID;
new sName[MAX_NAME_LENGTH];
new dummy;
new WONID;
new i;
new ValidWONID = 0;
new ValidName = 0;
convert_string(HLData, Data, MAX_DATA_LENGTH);
strsplit(Data, " ", sID, 3, sTeam, 10);
iID = strtonum(sID);
if (playerinfo(iID, sName, MAX_NAME_LENGTH, dummy, WONID, dummy, dummy)) {
numtostr(WONID, BOARD_WONIDS[iID]);
}
if (WONID != 0) {
for (i=0; i<MAX_USERS; i++) {
if (strcmp(BOARD_WONIDS[iID], PARSED_WONIDS[i]) == 0) {
ValidWONID = 1;
}
if (strcmp(sName, PARSED_NAMES[i]) == 0) {
ValidName = 1;
}
}
if (ValidWONID == 1) {
if (ValidName == 1) {
STATUS[iID] = "3"; // Dont annoy him, he is full-valid
} else {
STATUS[iID] = "1"; // Give him his realname
}
} else {
if (ValidName == 1) {
STATUS[iID] = "2"; // Give him an alternative name
} else {
STATUS[iID] = "4"; // Dont annoy him
}
}
}
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
new Text[MAX_TEXT_LENGTH];
if (playerinfo(iID, sName, MAX_NAME_LENGTH, dummy, WONID, dummy, dummy)) {
snprintf(Text,MAX_DATA_LENGTH,"%s hat die WONID: %i und den Status: %s", sName, WONID, STATUS[iID]);
centersay(Text, 5, 255, 255, 255);
}
new maxplayers = maxplayercount();
for (i=1;i<=maxplayers;i++) {
if (playerinfo(i, sName, MAX_NAME_LENGTH, dummy, WONID, dummy, dummy))
{
snprintf(Text,MAX_DATA_LENGTH,"%s hat die WONID: %i", sName, WONID);
log(Text);
}
}
snprintf(Text,MAX_DATA_LENGTH,"ValidWONID ist: %i und ValidName ist: %i", ValidWONID, ValidName);
log(Text);
say(Text);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
return PLUGIN_CONTINUE;
}
public sn_HandleWorld(HLCommand,HLData,HLUserName,UserIndex)
{
if (!bEnabled)
return PLUGIN_CONTINUE;
new Params[MAX_DATA_LENGTH];
new i;
new j;
new sName[MAX_NAME_LENGTH];
new dummy;
new sCommand[MAX_DATA_LENGTH];
new iDead;
new ValidWONID = 0;
new ValidName = 0;
new Text[MAX_TEXT_LENGTH];
convert_string(HLData,Params,MAX_DATA_LENGTH);
switch( Params[ 6 ] )
{
case 'S':
{
for(i=0; i<MAX_USERS; i++) {
if (strcmp(STATUS[i], "9") == 0) {
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
snprintf(Text,MAX_DATA_LENGTH,"%s hat den Status: %s", BOARD_NAMES[i], STATUS[i]);
centersay(Text, 5, 0, 255, 0);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
if (playerinfo(i, sName, MAX_NAME_LENGTH, dummy, dummy, dummy, dummy))
{
for (j=0; j<MAX_USERS; j++) {
if (strcmp(BOARD_WONIDS[i], PARSED_WONIDS[j]) == 0) {
ValidWONID = 1;
}
if (strcmp(sName, PARSED_NAMES[j]) == 0) {
ValidName = 1;
}
}
if (ValidWONID == 1) {
if (ValidName == 1) {
STATUS[i] = "3"; // Dont annoy him, he is full-valid
} else {
STATUS[i] = "1"; // Give him his realname
}
} else {
if (ValidName == 1) {
STATUS[i] = "2"; // Give him an alternative name
} else {
STATUS[i] = "4"; // Dont annoy him
}
}
}
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
snprintf(Text,MAX_DATA_LENGTH,"%s hat nun den Status: %s", BOARD_NAMES[i], STATUS[i]);
say(Text);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
}
if (strcmp(STATUS[i], "1") == 0) {
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
snprintf(Text,MAX_DATA_LENGTH,"%s hat den Status: %s^nund wird nun umbenannt.", BOARD_NAMES[i], STATUS[i]);
centersay(Text, 5, 0, 255, 0);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
if (playerinfo(i, sName, MAX_NAME_LENGTH, dummy, dummy, dummy, iDead))
{
if (bAction == 0) { // Rename him
if (iDead == 0) {
snprintf(sCommand,MAX_DATA_LENGTH,"name ^"%s^"",PARSED_NAMES[i]);
execclient(sName, sCommand);
messageex(sName, "You have been renamed to your^noriginal name.", print_pretty);
STATUS[i] = "9";
}
} else { // Kick him
snprintf(Text,MAX_DATA_LENGTH,"Wrong name: ^"%s^". Use your realname !",sName);
messageex(sName, "", print_console);
messageex(sName, Text, print_console);
kick(sName);
STATUS[i] = "0";
}
}
}
if (strcmp(STATUS[i], "2") == 0) {
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
snprintf(Text,MAX_DATA_LENGTH,"%s hat den Status: %s^nund bekommt einen alternativen Namen.", BOARD_NAMES[i], STATUS[i]);
centersay(Text, 5, 0, 255, 0);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
if (playerinfo(i, sName, MAX_NAME_LENGTH, dummy, dummy, dummy, iDead))
{
if (bAction == 0) { // Rename him
if (iDead == 0) {
snprintf(sCommand,MAX_DATA_LENGTH,"name ^"%s^"", ALTERNATIVE_NAMES[random(AltNamesQuantity-1)]);
execclient(sName, sCommand);
messageex(sName, "You have been renamed because your^nname was not permissible.", print_pretty);
STATUS[i] = "9";
}
} else { // Kick him
snprintf(Text,MAX_DATA_LENGTH,"Wrong name: ^"%s^". Use another name !",BOARD_NAMES[i]);
messageex(sName, "", print_console);
messageex(sName, Text, print_console);
kick(sName);
STATUS[i] = "0";
}
}
}
if (strcmp(STATUS[i], "3") == 0) {
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
snprintf(Text,MAX_DATA_LENGTH,"%s hat den Status: %s^nund darf ungestoert weiterspielen.", BOARD_NAMES[i], STATUS[i]);
centersay(Text, 5, 0, 255, 0);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
STATUS[i] = "9";
}
if (strcmp(STATUS[i], "4") == 0) {
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
snprintf(Text,MAX_DATA_LENGTH,"%s hat den Status: %s^nund darf ungestoert weiterspielen.", BOARD_NAMES[i], STATUS[i]);
centersay(Text, 5, 0, 255, 0);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
STATUS[i] = "9";
}
}
return PLUGIN_CONTINUE;
}
}
return PLUGIN_CONTINUE;
}
public plugin_connect(HLUserName, HLIP, UserIndex)
{
if (!bEnabled)
return PLUGIN_CONTINUE;
if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS) {
new sHLUserName[MAX_TEXT_LENGTH];
new sHLIP[MAX_TEXT_LENGTH];
convert_string(HLUserName, sHLUserName, MAX_DATA_LENGTH);
convert_string(HLIP, sHLIP, MAX_DATA_LENGTH);
strcpy(BOARD_NAMES[UserIndex], sHLUserName, MAX_NAME_LENGTH);
STATUS[UserIndex] = "9";
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
printf("---- DEBUG ----^n");
printf("Name: %s^nIP: %s^nIndex: %d^n",sHLUserName,sHLIP,UserIndex);
printf("---- DEBUG ----^n");
new DbgText[MAX_DATA_LENGTH];
snprintf(DbgText,MAX_DATA_LENGTH,"Name: %s",sHLUserName);
say(DbgText);
snprintf(DbgText,MAX_DATA_LENGTH,"IP: %s",sHLIP);
say(DbgText);
snprintf(DbgText,MAX_DATA_LENGTH,"Index: %i",UserIndex);
say(DbgText);
snprintf(DbgText,MAX_DATA_LENGTH,"%s hat nun den Status: %s",sHLUserName, STATUS[UserIndex]);
centersay(DbgText, 5, 0, 255, 0);
#endif
////////////////////////////// DEBUG END ///////////////////////////////
}
return PLUGIN_CONTINUE;
}
initialize_name_file(loadfile[] = "")
{
new GotLine;
new iLineNum = 0;
new strLineBuf[MAX_TEXT_LENGTH];
new Text[MAX_TEXT_LENGTH];
new tName[NAME_LENGTH];
new tWonID[WONID_LENGTH];
new x = 0;
new y = 0;
new i;
new Alternative = 0;
for(i=0; i<MAX_USERS; i++) {
PARSED_NAMES[i] = "-";
PARSED_WONIDS[i] = "void";
BOARD_NAMES[i] = "-";
BOARD_WONIDS[i] = "void";
STATUS[i] = "0";
ALTERNATIVE_NAMES[i] = "void";
}
/************ File should have the following format: **************
////////////////////////////////////
// This file was generated for //
// Biohazards Spooky Names Plugin //
// ------- //
// Things in here should have the //
// following format: //
// Name; WonID //
// ------- //
// Example: //
// -|FoC.MrSpoocy|-; 1234567 //
////////////////////////////////////
-|FoC.MrSpoocy|-; 1234567
[-Ek-]Biohazard; 7654321
#### List of alternative names ####
Sir Knumskull
John J.
Captain Ahab
Lonestar
Lucker
The Renamed One
I dont want that name
Thats not my real name
What the hell...
Master of Disaster
******************************************************************/
if (fileexists(loadfile) > 0) {
GotLine = readfile(loadfile, strLineBuf, iLineNum, MAX_TEXT_LENGTH);
if (!GotLine) {
log("Something seems to be wrong with that Spooky Names Plugin");
return PLUGIN_HANDLED;
}
while (GotLine) {
if (x >= MAX_USERS) {
log("Spooky Names Plugin >> Name list truncated. Increase MAX_USERS.");
printf("Spooky Names Plugin >> Stopped parsing %s file.^n", loadfile);
break;
}
if (y >= MAX_ALTERNATIVE) {
log("Spooky Names Plugin >> List of alternative names truncated. Increase MAX_ALTERNATIVE.");
printf("Spooky Names Plugin >> Stopped parsing %s file.^n", loadfile);
break;
}
if (strncmp(strLineBuf, "#", 1) == 0) {
Alternative = 1;
}
if ((strncmp(strLineBuf, "#", 1) != 0) && (strncmp(strLineBuf, "//", 2) != 0) && (strlen(strLineBuf) != 0)) {
if (Alternative == 0) {
strsplit(strLineBuf, ";", tName, NAME_LENGTH, tWonID, WONID_LENGTH);
strtrim(tName, " ^t");
strtrim(tWonID, " ^t");
if(strlen(tName) == 0) {
log("Spooky Names Plugin >> Fileformat invalid !");
return PLUGIN_HANDLED;
}
strcpy(PARSED_NAMES[x], tName, NAME_LENGTH);
strcpy(PARSED_WONIDS[x], tWonID, WONID_LENGTH);
x++;
}
if (Alternative == 1) {
strtrim(strLineBuf, " ^t");
strcpy(ALTERNATIVE_NAMES[y], strLineBuf, NAME_LENGTH);
y++;
AltNamesQuantity = y;
}
}
GotLine = readfile(loadfile, strLineBuf, ++iLineNum, MAX_TEXT_LENGTH);
}
}
else {
snprintf(Text, MAX_TEXT_LENGTH, "Spooky Names Plugin >> Cannot find %s file.", FILENAME);
log(Text);
return PLUGIN_HANDLED;
}
///////////////////////////// DEBUG START //////////////////////////////
#if DEBUG
printf("---- DEBUG ----^n");
for (i=0; i<MAX_USERS;i++) {
printf("%s : %s^n",PARSED_NAMES[i], PARSED_WONIDS[i]);
}
printf("---- DEBUG ----^n");
printf("---- ALTERNATIVE NAMES ----^n");
for (i=0; i<MAX_USERS;i++) {
printf("%s^n",ALTERNATIVE_NAMES[i]);
}
printf("---- ALTERNATIVE NAMES ----^n");
#endif
////////////////////////////// DEBUG END ///////////////////////////////
return PLUGIN_CONTINUE;
}
public plugin_init()
{
plugin_registerinfo("Biohazards Spooky Names Plugin","Kicks or renames unauthorized players",STRING_VERSION);
plugin_registercmd("sn_HandleWorld", "sn_HandleWorld", ACCESS_CONSOLE);
plugin_registercmd("sn_HandleTeamSelect", "sn_HandleTeamSelect", ACCESS_CONSOLE);
plugin_registercmd("admin_spooky_off", "admin_spooky_off", ACCESS_SPOOKY, "admin_spooky_off: Disables Spooky Names Plugin.");
plugin_registercmd("admin_spooky_on", "admin_spooky_on", ACCESS_SPOOKY, "admin_spooky_on: Enables Spooky Names Plugin.");
exec("logd_reg 62 admin_command sn_HandleWorld");
exec("logd_reg 54 admin_command sn_HandleTeamSelect");
initialize_name_file(FILENAME);
return PLUGIN_CONTINUE;
}