pridaní metody pro restart serveru
parent
00bf11e673
commit
9bbbcb7e9f
|
|
@ -1,5 +1,7 @@
|
|||
package jnet.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jnet.lib.BuilddDate;
|
||||
|
|
@ -45,7 +47,6 @@ public class Server {
|
|||
}
|
||||
|
||||
|
||||
LogWindow.addRow("tset");
|
||||
|
||||
LogFile.clear();
|
||||
LogFile.setDebug(false);
|
||||
|
|
@ -143,5 +144,30 @@ public class Server {
|
|||
np.start();
|
||||
|
||||
}
|
||||
|
||||
public static void restartServer() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
try {
|
||||
String java = System.getProperty("java.home") + "/bin/java";
|
||||
File jarFile = new File(Server.class
|
||||
.getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||
|
||||
List<String> command = new ArrayList<>();
|
||||
command.add(java);
|
||||
command.add("-jar");
|
||||
command.add(jarFile.getAbsolutePath());
|
||||
|
||||
new ProcessBuilder(command).start();
|
||||
System.exit(0);
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("Restart failed! " + ex.getMessage());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LogFile.printErr("Restart failed! " + e.getMessage());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import io.netty.channel.Channel;
|
|||
import io.netty.channel.group.ChannelGroup;
|
||||
import io.netty.channel.group.DefaultChannelGroup;
|
||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ListIterator;
|
||||
import jnet.lib.LogFile;
|
||||
|
|
@ -79,6 +80,7 @@ public class ServerMessageParser {
|
|||
sendAll(new Message(Message.ONLINE_CLIENTS, Server.onlineClients));
|
||||
// odeslat nastaveni serveru
|
||||
ServerConfig sc = new ServerConfig(
|
||||
Server.config.getInt("ping_repeat"),
|
||||
Server.config.getInt("ping_attempt"),
|
||||
Server.config.getInt("ping_timeout"),
|
||||
Server.config.getInt("instability_attempt"),
|
||||
|
|
@ -109,6 +111,16 @@ public class ServerMessageParser {
|
|||
LogFile.printInfo("Authorization failed (ser: " + username + " )");
|
||||
}
|
||||
break;
|
||||
|
||||
case Message.RESTART:
|
||||
LogFile.printInfo("Prijat pozadavek na restart serveru");
|
||||
Server.restartServer();
|
||||
break;
|
||||
|
||||
case Message.UPTIME:
|
||||
long uptime = ManagementFactory.getRuntimeMXBean().getUptime();
|
||||
send(Message.UPTIME, uptime);
|
||||
break;
|
||||
|
||||
case Message.NEW_OBJECT_TYPE:
|
||||
ObjectType not = (ObjectType) msg.getMsg();
|
||||
|
|
@ -136,7 +148,7 @@ public class ServerMessageParser {
|
|||
case Message.ADD_OBJECT:
|
||||
MapObject mo = Database.addMapObject((MapObject) msg.getMsg());
|
||||
// pridat do seznamu
|
||||
iteratorMapObject.add(mo);
|
||||
Server.mapObject.add(mo);
|
||||
// odesle všem novy objekt
|
||||
sendAll(new Message(Message.ADD_OBJECT, mo));
|
||||
// prida event a odesle ho
|
||||
|
|
@ -273,6 +285,7 @@ public class ServerMessageParser {
|
|||
case Message.SERVER_CONFIG:
|
||||
ServerConfig sc = (ServerConfig) msg.getMsg();
|
||||
// ulozeni
|
||||
Server.config.setInt("ping_repeat", sc.getPingRepeat());
|
||||
Server.config.setInt("ping_attempt", sc.getPingAttempt());
|
||||
Server.config.setInt("ping_timeout", sc.getPingTimeout());
|
||||
Server.config.setInt("instability_attempt", sc.getInstabilityAttempt());
|
||||
|
|
|
|||
Loading…
Reference in New Issue