Is there a way to determine who the last person to join the server is? I'm asking because I'd like to make a reserved slot plugin, and It needs to know who the last player to join the server is.
Thanks.
Is there a way to determine who the last person to join the server is? I'm asking because I'd like to make a reserved slot plugin, and It needs to know who the last player to join the server is.
Thanks.
You can get the time a player joined a server. This timestamp is saved in $players[]->joined
The one with the highest value is the one who joined at last
But why dont you use the build in function to reserve some slots. sv_privateClients X and sv_privatePassword are the needed dvars.
I found out I can make a script run everytime someone joins the server, so that's the way that I did it.
The reason I do not use the built in reserved slots feature is that it actually "reserves" the slots, meaning that nobody but who has the password to join in those slots can fill them. This means that if I have a 16 slot server, and say 6 reserved slots, the maximum amount of public people that can join my server is 10, weather or not those other 6 slots have anybody in them. Also I really don't like that whole password thing, I'd rather have it be passive to the end user.
Another reason I don't like the password is that I'm making a script where if you donate to help support my server, you automatically get put into the database of safe hashes (reserved slots) for one month, once that month is up you are automatically removed from the safe hashes table, and can be once again kicked for people that are on the list.
The only problem with the way that I have this setup, is that you need to have an odd number of slots in your server, so that It can always keep one open.
I'm going to share this plugin with you guys, but before anyone actually uses it (because I don't want any problems with people's servers), I need someone with more knowledge then me, to tell me if this plugin will actually work.
Here it is:
<?
/*
Config:
PUT THE FOLLOWING PARAGRAPH INTO YOUR CONFIG.CFG
[reserved]
enabled = 0
admin = 0
reason_serverfull = "Sorry this server is currently full."
reason_reserved = "Sorry you have been kicked to make room for a reserved slot member."
msg_reserved = "<KICKED_PLAYER> has been kicked to make room for reserved slot member <JOINED_PLAYER>."
//Database Information
mysql_user = "MySQL username"
mysql_pass = "MySQL password"
mysql_host = "MySQL hostname"
mysql_name = "MySQL database name"
*/
$mod->setDefaultCV("reserved", "enabled", 0);
$mod->setDefaultCV("reserved", "admin", 0);
$mod->setDefaultCV("reserved", "slots", 0);
$mod->setDefaultCV("reserved", "reason_serverfull", "Sorry this server is currently full.");
$mod->setDefaultCV("reserved", "reason_reserved", "Sorry you have been kicked to make room for a reserved slot member.");
$mod->setDefaultCV("reserved", "msg_reserved", "<KICKED_PLAYER> has been kicked to make room for reserved slot member <JOINED_PLAYER>.");
$mod->setDefaultCV("reserved", "mysql_user", "NULL");
$mod->setDefaultCV("reserved", "mysql_pass", "NULL");
$mod->setDefaultCV("reserved", "mysql_host", "localhost");
$mod->setDefaultCV("reserved", "mysql_name", "manuadmin");
$mod->registerEvent("playerJoined", "reservedslots_main");
function reservedslots_main($guid){
global $players;
global $mod;
if(!mysql_link()){return;}
//Determine if server setting is an odd number, it has to be in order to work correctly.
if($odd = $mod->getCV("reserved", "slots")%2){
$logging->write(MOD_WARNING, "Reserved slots mod disabled, you musth have an odd number of slots in your server.");
return;
}
//If server is not full, then don't to anything.
if(count($players) < $mod->getCV("reserved", "slots")){
return;
}
//If server is full -> gotta kick someone.
if(count($players) >= $mod->getCV("reserved", "slots")){
//Get Safe GUID's from database
while($hashes = mysql_query("SELECT * FROM reserved WHERE expire > '".time()."' AND enabled = '1'")){
$safe[$hashes['hash']] = 1;
}
//Determine if new user is a reserved slot member.
if($safe[$guid] || $players[$guid]->isProtected()){
openslot($safe,$guid);
return
}else{
$players[$guid]->kick($mod->getCV("reserved", "reason_serverfull"));
}
}
mysql_close();
}
function mysql_link(){
global $mod;
$db = mysql_connect($mod->getCV("reserved", "mysql_host"),$mod->getCV("reserved", "mysql_user"),$mod->getCV("reserved", "mysql_pass")) or $logging->write(MOD_WARNING, "Could not connect to database, reserved slot mod failed.");
$db1 = mysql_select_db($mod->getCV("reserved", "mysql_name")) or $logging->write(MOD_WARNING, "Could not select database, reserved slot mod failed.");
if($db && $db1){
return true;
}else{
return false;
}
}
function open_slot($safe,$guid){
global $players;
global $mod;
//Get the player info of the player that can be kicked.
$kicker = find_slot($safe);
if(!$kicker){
//If no information is provided, kick the player who just joined, regardless of reserved slot status.
$player = $players[$guid]->getName();
$logging->write(MOD_NOTICE, "Player $player has been removed because the server is full of reserved slots.");
$players[$guid]->kick($mod->getCV("reserved", "reason_serverfull"));
return;
}else{
//If information is provided, kick the person who is given.
$player = $players[$kicker["guid"]]->getName();
$new = $player[$guid]->getName();
$logging->write(MOD_NOTICE, "Player \"$player\" has been removed because a reserved slot member \"$new\" joined.");
$player[$kicker["guid"]]->kick($mod->getCV("reserved", "reason_reserverd"));
$search = array("<JOINED_PLAYER>","<KICKED_PLAYER>");
$replace = array($player,$new);
$mod->rconSay(str_replace($search,$replace,$mod->getCV("reserved", "msg_reserved")));
return $player;
}
}
function find_slot($safe){
global $mod;
global $players;
$playerlist = $mod->rconPlayerList();
foreach($playerlist as $player){
//If the user is not in the safe list, add them to the kickable list.
if(!$safe[$player["guid"]]){
$kickable[] = $player;
$scores[] = $player["score"];
}
}
//If nobody in the server is kickable it is now officially full, return false.
if(!$kickable){
return false;
}
foreach($kickable as $player){
//If score is not below 0 or ping above 300 remove them from the list.
if($player["score"] < 0 || $player["ping"] > 300){
$kickers[] = $player;
$score[] = $player["score"];
}
}
//If nobody is left you have to go back to the other list
if(!$kickers){
asort($scores);
foreach($scores as $playerid => $score){
//Return the person with the lowest score out of the kickable people.
return $kickers[$playerid];
}
}else{
asort($score);
foreach($score as $playerid => $score){
//Return the person with the lowest score out of the kickable people.
return $kickable[$playerid];
}
}
}
?>
Alles anzeigen
The MySQL table that it uses:
CREATE TABLE IF NOT EXISTS `reserved` (
`hash` varchar(32) NOT NULL,
`expires` int(10) NOT NULL,
`created` int(10) NOT NULL,
`donamount` varchar(5) NOT NULL,
`enabled` tinyint(2) NOT NULL,
KEY `hash` (`hash`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Anybody that knows what they are doing better than I do (which is most of you), please tell me if this will work, and if it's safe to use on a server.