PDA

View Full Version : DoD LAN Priority


knife108
10-11-2007, 02:50 AM
//based on:
//slots_reservation --f117bomb ;
//ilovelan --Avalanche;

////////////////////////////////////
//
//Cvar:
//* amx_reservation <value>
//* 1 - Kicks the Player with shortest playing time when a LAN user connects to a full server.
//* 2 - Kick the Player with the highest ping when a LAN user connects to a full server.
//
//set a lan.ini file in addons/amxmodx/data/

//add LAN ips in lan.ini:
// 10.0
// 192.168
// 217.147.10
// 217.147.20
//
////////////////////////////////////


#include <amxmodx>
#include <amxmisc>



// filename of LAN ips
#define FILENAME "addons/amxmodx/data/lan.ini"


// Comment if you don't want to hide true max_players
#define HIDE_RESERVEDSLOTS

public plugin_init()
{
register_plugin("DoD Slot for LAN","0.1","")
register_cvar("amx_reservation","1")

#if defined HIDE_RESERVEDSLOTS
set_cvar_num( "sv_visiblemaxplayers" , get_maxplayers() - 1 )
#endif

}

public client_authorized(id) {

new maxplayers = get_maxplayers()
new players = get_playersnum( 1 )
new limit = maxplayers - 1
new resType = get_cvar_num( "amx_reservation" )
new who

if ( players > limit ) //21/20
{
if ( get_user_flags(id) & is_user_LAN(id) )
{
switch(resType) {
case 1:
who = kickFresh()
case 2:
who = kickLag()
}
if(who) {
new name[32]
get_user_name( who, name , 31 )
client_cmd(id,"echo ^"* %s was kicked for the LAN

users!^"" ,name )
}
return PLUGIN_CONTINUE
}

if ( is_user_bot(id) )
server_cmd("kick #%d", get_user_userid(id) )
else
client_cmd(id,"echo ^"There are no available slots left!

^";disconnect")

return PLUGIN_HANDLED // block connect in other plugins (especially in

consgreet)
}
return PLUGIN_CONTINUE
}


kickLag() {
new who = 0, ping, loss, worst = -1
new maxplayers = get_maxplayers()
for(new i = 1; i <= maxplayers; ++i) {
if ( !is_user_connected(i) && !is_user_connecting(i) )
continue // not used slot
if (get_user_flags(i)& is_user_LAN(i))
continue // has reservation, skip him
get_user_ping(i,ping,loss) // get ping
if ( ping > worst ) {
worst = ping
who = i
}
}
if(who)
if ( is_user_bot(who) )
server_cmd("kick #%d", get_user_userid(who) )
else
client_cmd(who,"echo ^"Dropped due to high ping to free slot

for LAN users^";disconnect")
return who

}

kickFresh() {
new who = 0, itime, shortest = 0x7fffffff
new maxplayers = get_maxplayers()
for(new i = 1; i <= maxplayers; ++i){
if ( !is_user_connected(i) && !is_user_connecting(i) )
continue // not used slot
if (get_user_flags(i)& is_user_LAN(i))
continue // has reservation, skip him
itime = get_user_time(i) // get user playing time with connection

duration
if ( shortest > itime ) {
shortest = itime
who = i
}
}
if(who)
if ( is_user_bot(who) )
server_cmd("kick #%d", get_user_userid(who) )
else
client_cmd(who,"echo ^"There are no available slots left!

^";disconnect")
return who
}

// see if this player is a member of the LAN
public bool:is_user_LAN(id) {

new ip[32];
get_user_ip(id,ip,31,0);

new line, text[64], txtlen;
while( (line = read_file(FILENAME,line,text,63,txtlen)) != 0 ) {
trim(text);

if( equali(ip,text,strlen(text)) ) {
return true;
}
}

return false;
}



server command line +maxplayer 26 ,and restart server the maxvisibleplayer is 25, full is 25/25 !

LAN users can't join when server is 25/25 !

something wrong ? :(

pls test it !

FeuerSturm
10-12-2007, 02:42 AM
if you hide the reserved slot players can't connect through the server browser
when the server is "full", so the LAN players would either connect through
console (connect xxx.xxx.xxx.xxx:xxxxx) or you have to unhide the reserved
slot to let players connect via steam server browser.

knife108
10-12-2007, 03:53 AM
i had commented this line


//#define HIDE_RESERVEDSLOTS



restart server sv_maxvisibleplayers = "-1" ?

if hide reserved slots sv_maxvisibleplayers = 25

when no LAN users join server,it will "full" at 25/26, but it shows 26/26,i mean server did not kick the 26th player!

does any problem with the codes ?

FeuerSturm
10-12-2007, 01:03 PM
i looked through the code quickly and i have to say there's a lot of stuff
in it that "might" work and a lot of stuff that won't work.

i wouldn't use that plugin at all, i would suggest to use my "DoD AdminSlots v0.7 (http://dodplugins.net/forums/showthread.php?t=15)"
and setup all the LAN IPs in users.ini like that:

"XXX.XXX.XXX.XXX" "" "b" "de"

the flag "b" is the reserved slot, after that it should work.

besides the fact that the plugin is "crap" that you posted, it's not DoD
specific at all.

Use DoD AdminSlots and you won't have a problem anymore!

knife108
10-12-2007, 01:12 PM
i looked through the code quickly and i have to say there's a lot of stuff
in it that "might" work and a lot of stuff that won't work.

i wouldn't use that plugin at all, i would suggest to use my "DoD AdminSlots v0.7 (http://dodplugins.net/forums/showthread.php?t=15)"
and setup all the LAN IPs in users.ini like that:

"XXX.XXX.XXX.XXX" "" "b" "de"

the flag "b" is the reserved slot, after that it should work.

besides the fact that the plugin is "crap" that you posted, it's not DoD
specific at all.

Use DoD AdminSlots and you won't have a problem anymore!

thx buddy !

i would do all u said and if i hide the slots , does the LAN users in users.ini can join the server via steam browser ?

FeuerSturm
10-12-2007, 01:22 PM
if the slot is hidden, the steam browser thinks the server is full, there's
no way to get around not hidding it.

knife108
10-12-2007, 11:08 PM
i added no any admin user only LAN ips to user.ini file like "XXX.XXX.XXX.XXX" "" "b" "de"

should i setup the amx_password_field "1234" for them ,i mean the client also need add setinfo "1234" to config.cfg ?