AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Some problem in my plugin (may be Two Dimensional Arrays problem) (https://forums.alliedmods.net/showthread.php?t=242132)

ryo89589 06-14-2014 14:30

Some problem in my plugin (may be Two Dimensional Arrays problem)
 
PHP Code:

#include <amxmodx>
#include <amxmisc>
 
new plugin_enabledpip[65][22]
 
public 
plugin_init()
{
 
plugin_enabled register_cvar("amx_betasys""0")
 
register_concmd("amx_addpass""addpass"ADMIN_RCON"<playername|auth> - add specified player as a pass user")
 
register_concmd("amx_delpass""delpass"ADMIN_RCON"<playername|auth> - delete specified player as a pass user")
}
 
public 
client_authorized(id)
 return 
get_pcvar_num(plugin_enabled) ? checkUser(id) : PLUGIN_CONTINUE
 
public delayed_kick(user[])
 
server_cmd("kick #%d"user[0])
 
public 
checkUser(id)
{
 new 
serip[22], userip[22]
 
get_user_ip(0seripcharsmax(serip), 1)
 
get_user_ip(iduseripcharsmax(userip), 1)
 
 if( 
equal(userippip[0], 21) )
  return 
PLUGIN_HANDLED
 
 
new userid[3]
 
userid[0] = get_user_userid(id)
 
set_task(0.1"delayed_kick"0userid1)
 
 return 
PLUGIN_CONTINUE
}
 
public 
addpass(idlevelcid)
{
 if (!
cmd_access(idlevelcid2))
  return 
PLUGIN_HANDLED
 
 
new name[33], ip[22], arg[33]
 
read_argv(1arg32)
 
get_user_name(idnamecharsmax(name))
 
get_user_ip(idipcharsmax(ip))
 
 if( !
equal(argpip[0], 21) )
  
copy(pip[0], charsmax(arg), arg)
 
 return 
PLUGIN_HANDLED
}
 
public 
delpass(idlevelcid)
{
 if (!
cmd_access(idlevelcid2))
  return 
PLUGIN_HANDLED
 
 
new name[33], ip[22], arg[22]
 
read_argv(1argcharsmax(arg))
 
get_user_name(idnamecharsmax(name))
 
get_user_ip(idipcharsmax(ip))
 
 if( 
equal(argpip[0], 21) )
  
copy(pip[0], 0"")
 
 return 
PLUGIN_HANDLED


When I delete an IP, all IP will be affected.
I think "delpass" There are some problems.
Please help me to check for problems. Thank you!

Also, please help me to check all two-dimensional array.
Are there any problems? Thank you very much!

Flick3rR 06-14-2014 16:38

Re: Some problem in my plugin (may be Two Dimensional Arrays problem)
 
I think that this serip is the problem, because you get the IP of everyone (with index 0) and I think this can't be don..

aron9forever 06-14-2014 17:10

Re: Some problem in my plugin (may be Two Dimensional Arrays problem)
 
Quote:

Originally Posted by Flick3rR (Post 2151732)
I think that this serip is the problem, because you get the IP of everyone (with index 0) and I think this can't be don..

getting index 0's ip gets the server's ip
can't understand code or whether op wants that or not but it should help
to get all ips use a loop

ryo89589 06-14-2014 22:04

Re: Some problem in my plugin (may be Two Dimensional Arrays problem)
 
Quote:

Originally Posted by Flick3rR (Post 2151732)
I think that this serip is the problem, because you get the IP of everyone (with index 0) and I think this can't be don..

Quote:

Originally Posted by aron9forever (Post 2151749)
getting index 0's ip gets the server's ip
can't understand code or whether op wants that or not but it should help
to get all ips use a loop

Let me give you a new one:
PHP Code:

#include <amxmodx>
#include <amxmisc>
 
#define PLUGIN_NAME "Beta Server System"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "ryo89589"
 
new plugin_enabledpip[65][22]
 
public 
plugin_init()
{
 
register_plugin(PLUGIN_NAME,PLUGIN_VERSION,PLUGIN_AUTHOR)
 
plugin_enabled register_cvar("amx_betasys""0")
 
register_concmd("amx_addpass""addpass"ADMIN_RCON"<playername|auth> - add specified player as a pass user")
 
register_concmd("amx_delpass""delpass"ADMIN_RCON"<playername|auth> - delete specified player as a pass user")
}
 
public 
client_authorized(id)
 return 
get_pcvar_num(plugin_enabled) ? checkUser(id) : PLUGIN_CONTINUE
 
public delayed_kick(user[])
 
server_cmd("kick #%d"user[0])
 
public 
checkUser(id)
{
 new 
serip[22], userip[22]
 
get_user_ip(0seripcharsmax(serip), 1)
 
get_user_ip(iduseripcharsmax(userip), 1)
 
 if( 
equal(useripserip21) || equal(userippip[0], 21) )
  return 
PLUGIN_HANDLED
 
 
new userid[3]
 
userid[0] = get_user_userid(id)
 
set_task(0.1"delayed_kick"0userid1)
 
 return 
PLUGIN_CONTINUE
}
 
public 
addpass(idlevelcid)
{
 if (!
cmd_access(idlevelcid2))
  return 
PLUGIN_HANDLED
 
 
new name[33], ip[22], arg[33]
 
read_argv(1arg32)
 
get_user_name(idnamecharsmax(name))
 
get_user_ip(idipcharsmax(ip))
 
 if( !
equal(argpip[0], 21) )
  
copy(pip[0], charsmax(arg), arg)
 
 return 
PLUGIN_HANDLED
}
 
public 
delpass(idlevelcid)
{
 if (!
cmd_access(idlevelcid2))
  return 
PLUGIN_HANDLED
 
 
new name[33], ip[22], arg[22]
 
read_argv(1argcharsmax(arg))
 
get_user_name(idnamecharsmax(name))
 
get_user_ip(idipcharsmax(ip))
 
 if( 
equal(argpip[0], 21) )
  
copy(pip[0], 0"")
 
 return 
PLUGIN_HANDLED


This adds "equal(userip, serip, 21)" only.

The problem still exists.

When I use amx_addpass added the player as a pass user, this is no problem.
Players can enter the server.

When I add multiple ip in the database, the problems will arise.
Only the latest IP can pass.
Also, when I delete an ip , all pass user's IP will be affect.
So, I think "addpass" & "delpass" There are some problems.
Please help me to check. Thank you!!

Black Rose 06-14-2014 23:27

Re: Some problem in my plugin (may be Two Dimensional Arrays problem)
 
What's the point of using an array with 65 indexes when you only use the first?
Why are you using IP instead of SteamID? Why are you not using the built in functionality of AMXX? That's just stupid.
Your use of charsmax() will defenitely cause index out of bounds errors to frequent your console window.
You're passing 0 as the len for copy() in delpass(), I'm not sure if that'll work. You don't even need that function to clear a string. A simple arrayset() or even nulling the first cell would be fine.

ryo89589 06-15-2014 01:10

Re: Some problem in my plugin (may be Two Dimensional Arrays problem)
 
Quote:

Originally Posted by Black Rose (Post 2151849)
What's the point of using an array with 65 indexes when you only use the first?
Why are you using IP instead of SteamID? Why are you not using the built in functionality of AMXX? That's just stupid.
Your use of charsmax() will defenitely cause index out of bounds errors to frequent your console window.
You're passing 0 as the len for copy() in delpass(), I'm not sure if that'll work. You don't even need that function to clear a string. A simple arrayset() or even nulling the first cell would be fine.

Thank you for helping me to check!
1. I used an array with 65 indexes, because I think I should set a limit of 64.
2. I used IP, because I opened a non-steam server.
Therefore, not all players are using SteamID.
3. I do not know the built in functionality of AMXX, so I do not use it.
Please tell me the built in functionality of AMXX. Thank you.
4. I'm sorry, I can not understand. I was in "Two Dimensional Arrays" is very poor.
Please help me correct. Thank you. Thank you. Please.


All times are GMT -4. The time now is 21:17.

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