Author Topic: [SCRIPT] Auto-Kick Multi-Clients  (Read 1477 times)

Just a simple script. If a client tries to join the server with a BL_ID matching someone currently on the server, it auto-kicks the extra client who just joined. Will exempt admins, super admin and host.

Code: [Select]
package kickDupsPackage
{
function GameConnection::StartLoad(%client)
{
Parent::StartLoad(%client);
%count = ClientGroup.getCount();
for(%i=0;%i<%count;%i++)
{
%obj = ClientGroup.getObject(%i);
if(%obj==%client)
continue;
if(%obj.isAdmin)
continue;
if(%obj.isSuperAdmin)
continue;
if(%obj.bl_id==getNumKeyID())
continue;
if(%obj.bl_id==%client.bl_id)
{
%client.schedule(1,"delete","No multiclienting.");
break;
}
}
}
};
activatepackage(kickDupsPackage);

pretty sure this will work.  I'm not at my computer r/n so i can't check.

why don't you instead kick the most recent person that joined, what if someone crashes, and then tries to reconnect only to get kicked?
plus it would be funny to punish someone for trying to multi client if their original client lost whatever progress or position they were in

Code: [Select]
//Code
pretty sure this will work.  I'm not at my computer r/n so i can't check.
Thanks, I'l give it a try when I can.

why don't you instead kick the most recent person that joined, what if someone crashes, and then tries to reconnect only to get kicked?
plus it would be funny to punish someone for trying to multi client if their original client lost whatever progress or position they were in
I'm not entirely sure what you're asking, but I'm trying to run a mod that requires that every user have a unique player within the game in order for it to work properly.

I'm not entirely sure what you're asking, but I'm trying to run a mod that requires that every user have a unique player within the game in order for it to work properly.
He's saying that when someone multi clients you should kick the clone that's already on the server instead of the one just joining, as a greater punishment because they lose their position or whatever they were doing.

should be able to swap %client.schedule(1,"delete","No multiclienting."); to %obj.schedule(1,"delete","No multiclienting.");

He's saying that when someone multi clients you should kick the clone that's already on the server instead of the one just joining, as a greater punishment because they lose their position or whatever they were doing.
Oh, I see. In most cases, that would be a good, punitive deterrent, but the mod I'm working with is for linking the BL Server with my Discord server. Keeping everything working is more in my interest than the punitive deterrent idea.

should be able to swap %client.schedule(1,"delete","No multiclienting."); to %obj.schedule(1,"delete","No multiclienting.");
Would this punish the newly-arrived multi-client or the original?

%obj punishes already in server, %client punishes new join

%obj punishes already in server, %client punishes new join
Thanks.

Code: [Select]
package kickDupsPackage
{
function GameConnection::StartLoad(%client)
{
Parent::StartLoad(%client);
if(!%client.isAdmin)
{
%count = ClientGroup.getCount();
for(%i=0;%i<%count;%i++)
{
%obj = ClientGroup.getObject(%i);
if(%obj.bl_id == %client.bl_id && %obj != %client)
{
%obj.delete("No multiclienting.");
break;
}
}
}
}
};
activatepackage(kickDupsPackage);
Better optimized version of Tendon's code. Checking if the subclient is a super admin or host is redundent because they would automatically be regular admin if so.

It's not guaranteed that the host will have admin. See $Pref::Server::AutoAdminServerOwner in config/server/prefs.cs.
isSuperAdmin and isAdmin are not dependent on each other.  I've seen and made code which unintentionally separates them.  So I would not suggest depending on this.


I've finished, tested, and packaged the script as it was originally requested.
Script_KickDups
Code: (server.cs) [Select]
package kickDupsPackage
{
function GameConnection::StartLoad(%client)
{
Parent::StartLoad(%client);
if(%client.bl_id == getNumKeyID())
return;
if(%client.isAdmin)
return;
if(%client.isSuperAdmin)
return;

%count = ClientGroup.getCount();
for(%i=0;%i<%count;%i++)
{
%obj = ClientGroup.getObject(%i);
if(%obj == %client)
continue;
if(%obj.bl_id == %client.bl_id)
{
%client.schedule(0,"delete","No multiclienting.");
return;
}
}
}
};
activatepackage(kickDupsPackage);