Raised This Month: $12 Target: $400
 3% 

Read from a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shadow728988
Member
Join Date: Sep 2017
Old 11-17-2019 , 09:08   Read from a file
Reply With Quote #1

Hi, i was hoping if there is a way that when a player is connecting to server they get banned if their steam id is stored in a file or inside the plugin.I guess i know how to do but cant put it in writing so kindly please help.like have the steam id's stored inside a trie and let the plugin read and if found the player gets banned while connecting.
Thank you.
shadow728988 is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 11-17-2019 , 09:25   Re: Read from a file
Reply With Quote #2

Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "Ban System" #define VERSION "1.0" #define AUTHOR "iceeedR" new Array:g_arBans public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("amx_newban", "CmdAddBan", ADMIN_BAN, "<nick>") } public plugin_precache() {     readIni() } public CmdAddBan(id, level, cid) {     if(!cmd_access(id, level, cid, 2))         return PLUGIN_HANDLED         new Arg[MAX_PLAYERS +1]         read_argv(1, Arg, charsmax(Arg))         new player = cmd_target(id, Arg, CMDTARGET_ALLOW_SELF)         if (!player )     {         console_print ( id, "[NEWBAN] Error!" );         return PLUGIN_HANDLED     }         new szName[MAX_NAME_LENGTH], Authid[MAX_AUTHID_LENGTH], szAdminName[MAX_NAME_LENGTH], szBaninfo[50]     get_user_name(player, szName, charsmax(szName))     get_user_name(id, szAdminName, charsmax(szAdminName))     get_user_authid(player, Authid, charsmax(Authid))         formatex(szBaninfo, charsmax(szBaninfo), "* Banned by %s *", szAdminName)         new szConfig[MAX_FMT_LENGTH]     get_configsdir(szConfig, charsmax(szConfig))     add(szConfig, charsmax(szConfig), "/newban.ini")         new iFile = fopen(szConfig,"a+")         if(iFile)     {         fprintf(iFile, "%s^n%s^n%s^n", szName, Authid, szBaninfo)     }     fclose(iFile)         server_cmd("kick #%i ^"MSG BANNED^"", get_user_userid(player))         readIni()         return PLUGIN_CONTINUE } public client_connectex(id, const name[], const ip[], reason[128]) {     new Auth[MAX_AUTHID_LENGTH]     get_user_authid(id, Auth, charsmax(Auth))         for(new i, szName[MAX_NAME_LENGTH];i < ArraySize(g_arBans);i++)     {         ArrayGetString(g_arBans, i, szName, charsmax(szName))         if(containi(name, szName) != -1)         {             formatex(reason, charsmax(reason), "MSG BANNED")             return PLUGIN_HANDLED         }         if(equal(Auth, szName))         {             formatex(reason, charsmax(reason), "MSG BANNED")             return PLUGIN_HANDLED         }     }         return PLUGIN_CONTINUE } readIni() {     g_arBans = ArrayCreate(32)     new szConfig[MAX_FMT_LENGTH]     get_configsdir(szConfig, charsmax(szConfig))     formatex(szConfig, charsmax(szConfig), "%s/newban.ini", szConfig)     new iFile = fopen(szConfig,"a+")     if(iFile)     {         new sText[512],szName[MAX_NAME_LENGTH]                 while(!feof(iFile))         {             fgets(iFile,sText,charsmax(sText))             trim(sText)                         switch(sText[0])             {                 case EOS, '#', ';', '/', '*':                 {                     continue;                 }                                 default:                 {                     parse(sText,szName,charsmax(szName))                     {                         ArrayPushString(g_arBans, szName)                     }                 }             }         }         fclose(iFile)     }     for(new i, szName[MAX_NAME_LENGTH];i < ArraySize(g_arBans);i++)     {         ArrayGetString(g_arBans, i, szName, charsmax(szName))     } } public client_infochanged(id) {     new szNewName[32]     get_user_info( id, "name", szNewName, charsmax(szNewName) );     for(new i, szName[MAX_PLAYERS];i < ArraySize(g_arBans);i++)     {         ArrayGetString(g_arBans, i, szName, charsmax(szName))         if(containi(szNewName, szName) != -1)             server_cmd("kick #%i ^"MSG BANNED^"", get_user_userid(id))     } }
Attached Files
File Type: ini newban.ini (66 Bytes, 48 views)
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/

Last edited by iceeedr; 11-17-2019 at 10:32.
iceeedr is offline
Send a message via Skype™ to iceeedr
shadow728988
Member
Join Date: Sep 2017
Old 11-17-2019 , 09:46   Re: Read from a file
Reply With Quote #3

the ini file is created using readINI() yes?

but what does this do?
Code:
formatex(szConfig, charsmax(szConfig), "%s/YOURBANFILE.ini", szConfig)
shadow728988 is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 11-17-2019 , 10:15   Re: Read from a file
Reply With Quote #4

Quote:
Originally Posted by shadow728988 View Post
but what does this do?
Code:
formatex(szConfig, charsmax(szConfig), "%s/YOURBANFILE.ini", szConfig)
You need to use format() there.
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-17-2019 , 10:27   Re: Read from a file
Reply With Quote #5

Also fclose should be inside the if.
__________________
HamletEagle is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 11-17-2019 , 10:29   Re: Read from a file
Reply With Quote #6

Quote:
Originally Posted by shadow728988 View Post
the ini file is created using readINI() yes?

but what does this do?
Code:
formatex(szConfig, charsmax(szConfig), "%s/YOURBANFILE.ini", szConfig)
readINI () just reads the file the bans are written to and saves them in an array. The file you must create it and put in the configs folder (for better understanding I edited my previous post and attached a ready file there).

Quote:
Originally Posted by edon1337 View Post
You need to use format() there.
You are right, in the rush I ended up putting formatex () but anyway I prefer to use add (). (If not recommended feel free to correct me).
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 11-17-2019 , 10:31   Re: Read from a file
Reply With Quote #7

Quote:
Originally Posted by HamletEagle View Post
Also fclose should be inside the if.
Oops my mistake
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-17-2019 , 12:11   Re: Read from a file
Reply With Quote #8

I don't think your client_infochanged() code is needed for his purposes. For your ban plugin where you want to hook name change, may want to consider switching to this.

I think add() or copy() is ideal, format()/formatex() should be avoided if you are not truly formatting.
Code:
new szConfig[ MAX_FMT_LENGTH ] , iConfigDirLen;
iConfigDirLen = get_configsdir(szConfig, charsmax( szConfig) );
copy( szConfig[ iConfigDirLen ] , charsmax( szConfig ) - iConfigDirLen , "/newban.ini" );
__________________

Last edited by Bugsy; 11-17-2019 at 12:26.
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 11-18-2019 , 10:37   Re: Read from a file
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
I don't think your client_infochanged() code is needed for his purposes. For your ban plugin where you want to hook name change, may want to consider switching to this.

I think add() or copy() is ideal, format()/formatex() should be avoided if you are not truly formatting.
Code:
new szConfig[ MAX_FMT_LENGTH ] , iConfigDirLen;
iConfigDirLen = get_configsdir(szConfig, charsmax( szConfig) );
copy( szConfig[ iConfigDirLen ] , charsmax( szConfig ) - iConfigDirLen , "/newban.ini" );
I completely agree, I just wrote the plugin so that it understands the mechanics of reading / writing to the ban file, I don't use this bans system and wouldn't use it by name.

Now regarding copy / add I totally agree with you.

Regarding the client_infochanged issue I had a problem executing that function, in which the names of the players were being changed "automatically", by names of other players that had already left the server.
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode