Skip to content

Commit

Permalink
PingTask
Browse files Browse the repository at this point in the history
First PingTask added. Will be rewrited soon
  • Loading branch information
Alemiz committed Jul 5, 2019
1 parent 839077b commit c9d6304
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/alemiz/stargate/gate/GateAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ public static void ping(String client){
}
}

/*This function is for checking ping for every client
* It may be rewrite soon, so we can call it "deprecated" */
public static void pingAll(){
gateServer.clients.forEach((client, handler)->{
ping(client);
});
System.out.println("Ping ALL!");
}

}
12 changes: 12 additions & 0 deletions src/alemiz/stargate/gate/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import alemiz.stargate.StarGate;
import alemiz.stargate.gate.events.CustomPacketEvent;
import alemiz.stargate.gate.packets.*;
import alemiz.stargate.gate.tasks.PingTask;
import alemiz.stargate.untils.gateprotocol.Convertor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
Expand Down Expand Up @@ -78,6 +79,12 @@ public void run() {

serverThread = new Thread(serverTask);
serverThread.start();

/* Launching PingTask is very easy
* Just set delay (60seconds) and launch task*/
long interval = 60 * 1000;
Timer timer = new Timer();
timer.schedule(new PingTask(), 0, interval);
}

/**
Expand Down Expand Up @@ -192,4 +199,9 @@ private void handlePacket(String client, StarGatePacket packet){
}
}

/* Server Data*/

public Map<String, Handler> getClients() {
return clients;
}
}
13 changes: 13 additions & 0 deletions src/alemiz/stargate/gate/tasks/PingTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package alemiz.stargate.gate.tasks;

import alemiz.stargate.gate.GateAPI;
import alemiz.stargate.gate.Server;

import java.util.TimerTask;

public class PingTask extends TimerTask {
@Override
public void run() {
GateAPI.pingAll();
}
}

0 comments on commit c9d6304

Please sign in to comment.