mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 19:39:04 +07:00
Added server logs / Kick messages / Ban messages
This commit is contained in:
parent
c02329e4b1
commit
6508f1541b
@ -26,7 +26,7 @@ allprojects {
|
|||||||
appName = 'Mindustry'
|
appName = 'Mindustry'
|
||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
roboVMVersion = '2.3.0'
|
roboVMVersion = '2.3.0'
|
||||||
uCoreVersion = 'dec41336067c013f04f0e17db3b06e24d3c11f6a'
|
uCoreVersion = '7a77659cc5bb22c586d73cde6e21b854962e7f64'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.server;
|
package io.anuke.mindustry.server;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
import com.badlogic.gdx.utils.Timer;
|
import com.badlogic.gdx.utils.Timer;
|
||||||
@ -41,12 +42,18 @@ import static io.anuke.ucore.util.Log.*;
|
|||||||
|
|
||||||
public class ServerControl extends Module{
|
public class ServerControl extends Module{
|
||||||
private static final int roundExtraTime = 12;
|
private static final int roundExtraTime = 12;
|
||||||
|
//in bytes: 512 kb is max
|
||||||
|
private static final int maxLogLength = 1024 * 512;
|
||||||
|
|
||||||
private final CommandHandler handler = new CommandHandler("");
|
private final CommandHandler handler = new CommandHandler("");
|
||||||
|
private final FileHandle logFolder = Gdx.files.local("logs/");
|
||||||
|
|
||||||
|
private FileHandle currentLogFile;
|
||||||
private int gameOvers;
|
private int gameOvers;
|
||||||
private boolean inExtraRound;
|
private boolean inExtraRound;
|
||||||
private Task lastTask;
|
private Task lastTask;
|
||||||
|
|
||||||
|
|
||||||
public ServerControl(String[] args){
|
public ServerControl(String[] args){
|
||||||
Settings.defaultList(
|
Settings.defaultList(
|
||||||
"shufflemode", "normal",
|
"shufflemode", "normal",
|
||||||
@ -56,7 +63,8 @@ public class ServerControl extends Module{
|
|||||||
"sector_y", 1,
|
"sector_y", 1,
|
||||||
"shuffle", true,
|
"shuffle", true,
|
||||||
"crashreport", false,
|
"crashreport", false,
|
||||||
"port", port
|
"port", port,
|
||||||
|
"logging", true
|
||||||
);
|
);
|
||||||
|
|
||||||
Log.setLogger(new LogHandler(){
|
Log.setLogger(new LogHandler(){
|
||||||
@ -64,22 +72,27 @@ public class ServerControl extends Module{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void info(String text, Object... args){
|
public void info(String text, Object... args){
|
||||||
print("&lg&fb" + "[INFO] " + format(text, args));
|
print("&lg&fb" + "[INFO] " + text, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void err(String text, Object... args){
|
public void err(String text, Object... args){
|
||||||
print("&lr&fb" + "[ERR!] " + format(text, args));
|
print("&lr&fb" + "[ERR!] " + text, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warn(String text, Object... args){
|
public void warn(String text, Object... args){
|
||||||
print("&ly&fb" + "[WARN] " + format(text, args));
|
print("&ly&fb" + "[WARN] " + text, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(String text, Object... args){
|
public void print(String text, Object... args){
|
||||||
System.out.println("[" + dateTime.format(LocalDateTime.now()) + "] " + format(text + "&fr", args));
|
String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(text + "&fr", args);
|
||||||
|
System.out.println(result);
|
||||||
|
|
||||||
|
if(Settings.getBool("logging")){
|
||||||
|
logToFile("[" + dateTime.format(LocalDateTime.now()) + "] " + format(text + "&fr", false, args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -311,7 +324,7 @@ public class ServerControl extends Module{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Call.sendMessage("[GRAY][[Server]:[] " + arg[0]);
|
Call.sendMessage("[scarlet][[Server]:[] " + arg[0]);
|
||||||
|
|
||||||
info("&lyServer: &lb{0}", arg[0]);
|
info("&lyServer: &lb{0}", arg[0]);
|
||||||
});
|
});
|
||||||
@ -357,6 +370,13 @@ public class ServerControl extends Module{
|
|||||||
info("Crash reporting is now {0}.", value ? "on" : "off");
|
info("Crash reporting is now {0}.", value ? "on" : "off");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handler.register("logging", "<on/off>", "Disables or enables server logs", arg -> {
|
||||||
|
boolean value = arg[0].equalsIgnoreCase("on");
|
||||||
|
Settings.putBool("logging", value);
|
||||||
|
Settings.save();
|
||||||
|
info("Logging is now {0}.", value ? "on" : "off");
|
||||||
|
});
|
||||||
|
|
||||||
handler.register("strict", "<on/off>", "Disables or enables strict mode", arg -> {
|
handler.register("strict", "<on/off>", "Disables or enables strict mode", arg -> {
|
||||||
boolean value = arg[0].equalsIgnoreCase("on");
|
boolean value = arg[0].equalsIgnoreCase("on");
|
||||||
netServer.admins.setStrict(value);
|
netServer.admins.setStrict(value);
|
||||||
@ -400,6 +420,7 @@ public class ServerControl extends Module{
|
|||||||
Player target = playerGroup.find(p -> p.name.equals(arg[0]));
|
Player target = playerGroup.find(p -> p.name.equals(arg[0]));
|
||||||
|
|
||||||
if(target != null){
|
if(target != null){
|
||||||
|
Call.sendMessage("[scarlet] " + target.name + " has been kicked by the server.");
|
||||||
netServer.kick(target.con.id, KickReason.kick);
|
netServer.kick(target.con.id, KickReason.kick);
|
||||||
info("It is done.");
|
info("It is done.");
|
||||||
}else{
|
}else{
|
||||||
@ -425,6 +446,13 @@ public class ServerControl extends Module{
|
|||||||
}else{
|
}else{
|
||||||
err("Invalid type.");
|
err("Invalid type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(Player player : playerGroup.all()){
|
||||||
|
if(netServer.admins.isIDBanned(player.uuid)){
|
||||||
|
Call.sendMessage("[scarlet] " + player.name + " has been banned.");
|
||||||
|
netServer.kick(player.con.id, KickReason.banned);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.register("bans", "List all banned IPs and IDs.", arg -> {
|
handler.register("bans", "List all banned IPs and IDs.", arg -> {
|
||||||
@ -724,4 +752,23 @@ public class ServerControl extends Module{
|
|||||||
state.set(State.menu);
|
state.set(State.menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logToFile(String text){
|
||||||
|
if(currentLogFile != null && currentLogFile.length() > maxLogLength){
|
||||||
|
String date = DateTimeFormatter.ofPattern("MM-dd-yyyy | HH:mm:ss").format(LocalDateTime.now());
|
||||||
|
currentLogFile.writeString("[End of log file. Date: "+ date + "]\n", true);
|
||||||
|
currentLogFile = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentLogFile == null){
|
||||||
|
int i = 0;
|
||||||
|
while(logFolder.child("log-" + i + ".txt").length() >= maxLogLength){
|
||||||
|
i ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLogFile = logFolder.child("log-" + i + ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLogFile.writeString(text + "\n", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user