L2JMobius

Vanguard Account Auto-Kick

Paiplayer · 4 · 4768

Offline Paiplayer

  • Knight
  • ***
    • Posts: 74
While developing a control panel for various purposes I've identified the need to, somehow, keep the player logged out of the game (for instance to remove items from a character inventory or swap it between accounts).

That's how the idea of creating a system that would "kick" the player came up.

First of all: to it works you'll need to change a method and rebuild the GameServer.jar because the kick method is privately implemented on LoginServerThread.java and we need to make it public. Below is a diff of the file that has to be modified:

Code: [Select]
diff --git a/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/LoginServerThread.java b/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/LoginServerThread.java
index 784130d..91ada95 100644
--- a/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/LoginServerThread.java
+++ b/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/LoginServerThread.java
@@ -565,7 +565,7 @@
  * Kick player for the given account.
  * @param account the account
  */
- private void doKickPlayer(String account)
+ public void doKickPlayer(String account)
  {
  final GameClient client = _accountsInGameServer.get(account);
  if (client != null)
Note: I don't really know what the overall impact of this is, but it was the only way to which I managed to implement my method in a functional way. If someone has any other idea I'll accepting advices.

Then you need to create a table to put in there the account_name who needs to be kicked.

Code: [Select]
CREATE TABLE `accounts_need_to_be_kicked`  (
  `account_name` varchar(255) CHARACTER NOT NULL,
  PRIMARY KEY (`account_name`) USING BTREE
) ENGINE = InnoDB

Every 1 second, the server will check if there is any account in this list and, if so, it will send a kick signal to the account/character even if it is on the login screen. character selection. The script isn't prepared to remove the account after kicking it!

To the script run you'll need to save it as /game/data/scripts/custom/KickAccount.java .
Code: [Select]
package custom;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


import java.util.logging.Logger;
import org.l2jmobius.gameserver.LoginServerThread;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.quest.Event;

/**
* Custom account kick to L2jMobius
* Author: PaiPlayer
*/


public class KickAccount extends Event
{
private static final Logger LOGGER = Logger.getLogger(KickAccount.class.getName());


    private KickAccount(){
        LOGGER.info("KickAccount System Activated");
        ThreadPool.scheduleAtFixedRate(() -> eventStart(null), 5000, 1000); 
    }

    private void doKick(){
        try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement("SELECT * FROM accounts_need_to_be_kicked"))
{
try (ResultSet inv = statement.executeQuery())
{
while (inv.next())
{
final String account_name = inv.getString("account_name");
                    LoginServerThread.getInstance().doKickPlayer(account_name);
}
}
}
catch (Exception e)
{
LOGGER.severe("could not restore container:" + e);
}
       
    }

    @Override
public boolean eventStart(Player eventMaker)
{
        doKick();
        return false;
    }

    @Override
public boolean eventStop()
{
        return false;
    }

    @Override
public boolean eventBypass(Player player, String bypass)
{
return false;
}

    public static void main(String[] args)
{
new KickAccount();
}
}


To change how often the server will check on the database for kickable accounts you need to change this line, swapping the value 1000 with how much miliseconds the server must wait between table checks:

 
Code: [Select]
ThreadPool.scheduleAtFixedRate(() -> eventStart(null), 5000, 1000); 

Enjoy!
Want a developer? Check here or call me on Discord: PaiPlayer#5051


Online nasseka

  • Distinguished King
  • *****
    • Posts: 1729
    • L2Unknown
The ban does the same thing i guess xD.
Overall i don't see any use of this feature.
But to complete it, add admin command /autokick *acccount* and /stopautokick *account*  to add/remove accounts.


Offline Paiplayer

  • Knight
  • ***
    • Posts: 74
The ban does the same thing i guess xD.
Overall i don't see any use of this feature.
But to complete it, add admin command /autokick *acccount* and /stopautokick *account*  to add/remove accounts.

Even if you set accesslevel to -100 on both, character and account table, the currently online characters will not be disconnected.

And "you don't see any use of this feature.", as I say: in my case I have one customized panel where people will be able to retrieve items from their characters and send their characters between accounts, and the involved characters/accounts can't be online during the proccess.
Want a developer? Check here or call me on Discord: PaiPlayer#5051


Online nasseka

  • Distinguished King
  • *****
    • Posts: 1729
    • L2Unknown
Well i'm pretty sure they can be online. Just you need to make the script and send the required info from the panel :)