Autor Tema: Pinger Packet netPing  (Leído 350 veces)

Micr0

  • Newbie
  • *
  • Mensajes: 6
  • Karma: +0/-0
    • Ver Perfil
Pinger Packet netPing
« en: Junio 01, 2019, 05:21:00 am »
Hi i want ask some one can test the pinger im test but on my computer server client and send me ping 0
need me some why can test :) with some one

Código: [Seleccionar]
### Eclipse Workspace Patch 1.0
#P L2jAdmins_Core
Index: src/l2j/gameserver/network/external/client/NetPing.java
===================================================================
--- src/l2j/gameserver/network/external/client/NetPing.java   (nonexistent)
+++ src/l2j/gameserver/network/external/client/NetPing.java   (working copy)
@@ -0,0 +1,33 @@
+package l2j.gameserver.network.external.client;
+
+import l2j.gameserver.model.actor.instance.L2PcInstance;
+import l2j.gameserver.network.AClientPacket;
+import l2j.gameserver.network.Pinger;
+
+public class NetPing extends AClientPacket
+{
+   int kID;
+   int ping;
+   int mtu;
+   
+   @Override
+   protected void readImpl()
+   {
+      kID = readD();
+      ping = readD();
+      mtu = readD();
+   }
+   
+   @Override
+   protected void runImpl()
+   {
+      L2PcInstance activeChar = getClient().getActiveChar();
+      if (activeChar == null)
+      {
+         return;
+      }
+      Pinger.getInstance().answerPing(activeChar.getObjectId());
+      // System.out.println("PING:"+ping+":MTU:"+mtu);
+   }
+   
+}
\ No newline at end of file
Index: src/l2j/gameserver/network/PacketHandler.java
===================================================================
--- src/l2j/gameserver/network/PacketHandler.java   (revision 117)
+++ src/l2j/gameserver/network/PacketHandler.java   (working copy)
@@ -521,9 +521,9 @@
                case 0xa7:
                   msg = new MultiSellChoose();
                   break;
-               // case 0xa8:
-               // NetPing
-               // break;
+               case 0xa8:
+                  msg = new NetPing();
+                  break;
                case 0xaa:
                   msg = new RequestUserCommand();
                   break;
Index: src/l2j/gameserver/network/Pinger.java
===================================================================
--- src/l2j/gameserver/network/Pinger.java   (nonexistent)
+++ src/l2j/gameserver/network/Pinger.java   (working copy)
@@ -0,0 +1,101 @@
+package l2j.gameserver.network;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import l2j.gameserver.model.actor.instance.L2PcInstance;
+import l2j.gameserver.model.world.L2World;
+import l2j.gameserver.network.external.server.NetPing;
+
+public class Pinger extends Thread
+{
+   private static Pinger instance;
+   
+   public static Pinger getInstance()
+   {
+      if (instance == null)
+      {
+         instance = new Pinger();
+      }
+      return instance;
+   }
+   
+   private Pinger()
+   {
+   }
+   
+   private Map<Integer, Integer> pingTimes = new HashMap<>();
+   
+   public int getPingTimes(int objId)
+   {
+      Integer times = pingTimes.get(objId);
+      if (times == null)
+      {
+         return 0;
+      }
+      else
+      {
+         return times;
+      }
+   }
+   
+   public void answerPing(int objId)
+   {
+      if (!true)
+      {
+         return;
+      }
+      synchronized (pingTimes)
+      {
+         pingTimes.remove(objId);
+      }
+   }
+   
+   @Override
+   public void run()
+   {
+      for (;;)
+      {
+         try
+         {
+            Thread.sleep(3000);
+         }
+         catch (final InterruptedException e)
+         {
+         }
+         try
+         {
+            Map<Integer, Integer> newPingTimes = new HashMap<>();
+            synchronized (pingTimes)
+            {
+               for (final L2PcInstance player : L2World.getInstance().getAllPlayers())
+               {
+                  if (player == null)
+                  {
+                     continue;
+                  }
+                  int oid = player.getObjectId();
+                  int times = getPingTimes(oid);
+                  if (times > 2)
+                  {
+                     player.logout();
+                  }
+                  else
+                  {
+                     newPingTimes.put(oid, times + 1);
+                     // System.out.println("::::::::::::"+times);
+                  }
+                  player.sendPacket(new NetPing(player.getObjectId()));
+               }
+            }
+            pingTimes = newPingTimes;
+         }
+         catch (Exception ignored)
+         {
+         } ;
+      }
+   }
+}
\ No newline at end of file
Index: src/l2j/gameserver/network/external/server/NetPing.java
===================================================================
--- src/l2j/gameserver/network/external/server/NetPing.java   (nonexistent)
+++ src/l2j/gameserver/network/external/server/NetPing.java   (working copy)
@@ -0,0 +1,20 @@
+package l2j.gameserver.network.external.server;
+
+import l2j.gameserver.network.AServerPacket;
+
+public class NetPing extends AServerPacket
+{
+   int kID;
+   
+   public NetPing(int kID)
+   {
+      this.kID = kID;
+   }
+   
+   @Override
+   protected void writeImpl()
+   {
+      writeC(0xd3);
+      writeD(kID);
+   }
+}
\ No newline at end of file

method to get ping Pinger.getPingTimes(activeChar.getObjectId());
thanks :)

fissban

  • Desarrollador
  • Full Member
  • *
  • Mensajes: 152
  • Karma: +0/-0
    • Ver Perfil
Re:Pinger Packet netPing
« Respuesta #1 en: Junio 01, 2019, 07:50:04 pm »
what is the function of each client packet <-> server?
<script src="//db-ip.com/tools/showipcountry.js" async="async"></script>

Micr0

  • Newbie
  • *
  • Mensajes: 6
  • Karma: +0/-0
    • Ver Perfil
Re:Pinger Packet netPing
« Respuesta #2 en: Junio 02, 2019, 04:07:38 am »
mm the idea is to show all player ping in the GUI > EngineManager moybe but can test give me ping 0 because the server and client its run on my computer

fissban

  • Desarrollador
  • Full Member
  • *
  • Mensajes: 152
  • Karma: +0/-0
    • Ver Perfil
Re:Pinger Packet netPing
« Respuesta #3 en: Junio 02, 2019, 09:23:36 pm »
Here what we should question is if C4 has support for these packages but even so your code does not like how you have worked.

wee can use
https://stackoverflow.com/questions/11506321/how-to-ping-an-ip-address
<script src="//db-ip.com/tools/showipcountry.js" async="async"></script>

Micr0

  • Newbie
  • *
  • Mensajes: 6
  • Karma: +0/-0
    • Ver Perfil
Re:Pinger Packet netPing
« Respuesta #4 en: Junio 04, 2019, 04:05:38 am »