Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.filterbubbles.requiemdebug;
- import java.util.Properties;
- import java.util.logging.Logger;
- import org.gotti.wurmunlimited.modloader.interfaces.Configurable;
- import org.gotti.wurmunlimited.modloader.interfaces.Initable;
- import org.gotti.wurmunlimited.modloader.interfaces.PlayerLoginListener;
- import org.gotti.wurmunlimited.modloader.interfaces.PlayerMessageListener;
- import org.gotti.wurmunlimited.modloader.interfaces.ServerStartedListener;
- import org.gotti.wurmunlimited.modloader.interfaces.WurmServerMod;
- import com.wurmonline.server.creatures.Communicator;
- import com.wurmonline.server.players.Player;
- /**
- * An attempt at getting more information on what causes the Requiem of Wurm to freeze up ...and then we can go from there.
- *
- * v1: is it caused by a player doing an action? This will log a brief view of all communication between client/server. Yes. Spammy.
- *
- * @author Friya, 18-Jul-2018
- */
- public class Mod implements WurmServerMod, Initable, Configurable, ServerStartedListener, PlayerMessageListener, PlayerLoginListener
- {
- private static Logger logger = Logger.getLogger(Mod.class.getName());
- @Override
- public void configure(Properties arg0)
- {
- }
- @Override
- public void init()
- {
- Patcher.getInstance().init();
- }
- @Override
- public void onServerStarted()
- {
- }
- @Override
- public void onPlayerLogin(Player arg0)
- {
- }
- @Override
- public boolean onPlayerMessage(Communicator arg0, String arg1)
- {
- return false;
- }
- }
- package com.filterbubbles.requiemdebug;
- import java.lang.reflect.InvocationHandler;
- import java.lang.reflect.Method;
- import java.nio.ByteBuffer;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
- import org.gotti.wurmunlimited.modloader.classhooks.InvocationHandlerFactory;
- import com.wurmonline.server.creatures.Communicator;
- import javassist.CannotCompileException;
- import javassist.ClassPool;
- import javassist.CtClass;
- import javassist.CtMethod;
- import javassist.NotFoundException;
- /**
- * @author Friya, 18-Jul-2018
- */
- public class Patcher
- {
- private static Logger logger = Logger.getLogger(Patcher.class.getName());
- private static Patcher instance = null;
- protected static Patcher getInstance()
- {
- if(instance == null) {
- instance = new Patcher();
- }
- return instance;
- }
- protected void init()
- {
- try {
- interceptReallyHandle();
- patchSends();
- } catch (NotFoundException | CannotCompileException e) {
- logger.log(Level.SEVERE, "failed to patch something...", e);
- }
- }
- private void patchSends() throws NotFoundException, CannotCompileException
- {
- ClassPool cp = HookManager.getInstance().getClassPool();
- CtClass cls = cp.get("com.wurmonline.server.creatures.Communicator");
- CtMethod[] mets = cls.getDeclaredMethods();
- for(CtMethod met : mets) {
- if(met.getName().startsWith("send")
- && met.getName().equals("sendByteStringLength") == false
- && met.getName().equals("sendShortStringLength") == false
- ) {
- met.insertBefore(""
- + "{"
- + " " + Patcher.class.getName() + ".logSend(this, \"" + met.getName() + "\");"
- + "}"
- );
- logger.info("Added logger for " + met.getName());
- }
- }
- }
- private void interceptReallyHandle() throws NotFoundException, CannotCompileException
- {
- HookManager.getInstance().registerHook("com.wurmonline.server.creatures.Communicator", "reallyHandle", null,
- new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- ByteBuffer bb = (ByteBuffer)args[1];
- final byte[] buff = new byte[bb.remaining()];
- bb.duplicate().get(buff);
- if(buff.length > 0) {
- Communicator com = (Communicator)proxy;
- logger.info("cmd in:\t" + buff[0] + "\t" + com.getPlayer().getName() + "\t" + com.player.hasLink() + "\t" + buff.length);
- } else {
- logger.info("cmd in: empty!");
- }
- return method.invoke(proxy, args);
- }
- };
- }
- }
- );
- } // interceptReallyHandle
- /**
- * Called from game.
- *
- * @param com
- * @param method
- */
- static public void logSend(Communicator com, String method)
- {
- String pName;
- if(com != null && com.getPlayer() != null) {
- pName = com.getPlayer().getName();
- } else {
- pName = "<null>";
- }
- logger.info("cmd out:\t" + method + "\t" + pName + "\t" + ((com == null || com.getPlayer() == null) ? "null" : com.getPlayer().hasLink()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement