Better server colors

This commit is contained in:
Anuken
2020-10-20 11:21:47 -04:00
parent 9060a9518a
commit 9ab272a01f
15 changed files with 176 additions and 119 deletions

View File

@@ -89,7 +89,7 @@ public class Vars implements Loadable{
/** duration of time between turns in ticks */
public static final float turnDuration = 2 * Time.toMinutes;
/** chance of an invasion per turn, 1 = 100% */
public static final float baseInvasionChance = 1f / 25f;
public static final float baseInvasionChance = 1f / 30f;
/** how many turns have to pass before invasions start */
public static final int invasionGracePeriod = 20;
/** min armor fraction damage; e.g. 0.05 = at least 5% damage */
@@ -285,10 +285,10 @@ public class Vars implements Loadable{
if(loadedLogger) return;
String[] tags = {"[green][D][]", "[royal][I][]", "[yellow][W][]", "[scarlet][E][]", ""};
String[] stags = {"&lc&fb[D]", "&lg&fb[I]", "&ly&fb[W]", "&lr&fb[E]", ""};
String[] stags = {"&lc&fb[D]", "&lb&fb[I]", "&ly&fb[W]", "&lr&fb[E]", ""};
Seq<String> logBuffer = new Seq<>();
Log.setLogger((level, text) -> {
Log.logger = (level, text) -> {
String result = text;
String rawText = Log.format(stags[level.ordinal()] + "&fr " + text);
System.out.println(rawText);
@@ -304,9 +304,9 @@ public class Vars implements Loadable{
}
}
ui.scriptfrag.addMessage(Log.removeCodes(result));
ui.scriptfrag.addMessage(Log.removeColors(result));
}
});
};
Events.on(ClientLoadEvent.class, e -> logBuffer.each(ui.scriptfrag::addMessage));
@@ -319,18 +319,19 @@ public class Vars implements Loadable{
settings.setAppName(appName);
Writer writer = settings.getDataDirectory().child("last_log.txt").writer(false);
LogHandler log = Log.getLogger();
Log.setLogger((level, text) -> {
LogHandler log = Log.logger;
//ignore it
Log.logger = (level, text) -> {
log.log(level, text);
try{
writer.write("[" + Character.toUpperCase(level.name().charAt(0)) +"] " + Log.removeCodes(text) + "\n");
writer.write("[" + Character.toUpperCase(level.name().charAt(0)) +"] " + Log.removeColors(text) + "\n");
writer.flush();
}catch(IOException e){
e.printStackTrace();
//ignore it
}
});
};
loadedFileLogger = true;
}

View File

@@ -194,14 +194,14 @@ public class NetClient implements ApplicationListener{
}
//server console logging
Log.info("&y@: &lb@", player.name, message);
Log.info("&fi@: @", "&lc" + player.name, "&lw" + message);
//invoke event for all clients but also locally
//this is required so other clients get the correct name even if they don't know who's sending it yet
Call.sendMessage(message, colorizeName(player.id(), player.name), player);
}else{
//log command to console but with brackets
Log.info("<&y@: &lm@&lg>", player.name, message);
Log.info("<&fi@: @&fr>", "&lk" + player.name, "&lw" + message);
//a command was sent, now get the output
if(response.type != ResponseType.valid){

View File

@@ -508,7 +508,8 @@ public class NetServer implements ApplicationListener{
Call.playerDisconnect(player.id());
}
if(Config.showConnectMessages.bool()) Log.info("&lm[@] &lc@ has disconnected. &lg&fi(@)", player.uuid(), player.name, reason);
String message = Strings.format("&lb@&fi&lk has disconnected. &fi&lk[&lb@&fi&lk] (@)", player.name, player.uuid(), reason);
if(Config.showConnectMessages.bool()) Log.info(message);
}
player.remove();
@@ -736,7 +737,8 @@ public class NetServer implements ApplicationListener{
if(Config.showConnectMessages.bool()){
Call.sendMessage("[accent]" + player.name + "[accent] has connected.");
Log.info("&lm[@] &y@ has connected.", player.uuid(), player.name);
String message = Strings.format("&lb@&fi&lk has connected. &fi&lk[&lb@&fi&lk]", player.name, player.uuid());
Log.info(message);
}
if(!Config.motd.string().equalsIgnoreCase("off")){
@@ -785,7 +787,7 @@ public class NetServer implements ApplicationListener{
public void openServer(){
try{
net.host(Config.port.num());
info("&lcOpened a server on port @.", Config.port.num());
info("Opened a server on port @.", Config.port.num());
}catch(BindException e){
Log.err("Unable to host: Port already in use! Make sure no other servers are running on the same port in your network.");
state.set(State.menu);

View File

@@ -112,6 +112,14 @@ public abstract class UnlockableContent extends MappableContent{
}
}
/** Unlocks this content, but does not fire any events. */
public void quiteUnlock(){
if(!unlocked()){
unlocked = true;
Core.settings.put(name + "-unlocked", true);
}
}
public boolean unlocked(){
if(net.client()) return state.rules.researched.contains(name);
return unlocked || alwaysUnlocked;

View File

@@ -6,6 +6,7 @@ import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.game.EventType.*;
import mindustry.io.legacy.*;
import mindustry.maps.*;
import mindustry.type.*;
import mindustry.world.blocks.storage.*;
@@ -260,6 +261,11 @@ public class Universe{
private void load(){
seconds = Core.settings.getInt("utimei");
turn = Core.settings.getInt("turn");
if(Core.settings.has("unlocks")){
LegacyIO.readResearch();
Core.settings.remove("unlocks");
}
}
}

View File

@@ -2,6 +2,8 @@ package mindustry.io.legacy;
import arc.*;
import arc.struct.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.ui.dialogs.JoinDialog.*;
import java.io.*;
@@ -48,4 +50,35 @@ public class LegacyIO{
return arr;
}
public static void readResearch(){
try{
byte[] bytes = Core.settings.getBytes("unlocks");
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(bytes));
int length = stream.readInt();
if(length > 0){
stream.readUTF(); //name of key type
stream.readUTF(); //name of value type
//each element is an array list
for(int i = 0; i < length; i++){
ContentType type = ContentType.all[stream.readInt()];
int arrLength = stream.readInt();
if(arrLength > 0){
stream.readUTF(); //type of contents (String)
for(int j = 0; j < arrLength; j++){
String name = stream.readUTF();
Content out = Vars.content.getByName(type, name);
if(out instanceof UnlockableContent u){
u.unlock();
}
}
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}

View File

@@ -59,12 +59,12 @@ public class Scripts implements Disposable{
if(o instanceof Undefined) o = "undefined";
return String.valueOf(o);
}catch(Throwable t){
return getError(t);
return getError(t, false);
}
}
private String getError(Throwable t){
t.printStackTrace();
private String getError(Throwable t, boolean log){
if(log) Log.err(t);
return t.getClass().getSimpleName() + (t.getMessage() == null ? "" : ": " + t.getMessage());
}
@@ -138,7 +138,7 @@ public class Scripts implements Disposable{
if(currentMod != null){
file = currentMod.name + "/" + file;
}
log(LogLevel.err, file, "" + getError(t));
log(LogLevel.err, file, "" + getError(t, true));
return false;
}
}

View File

@@ -577,7 +577,10 @@ public class Administration{
autosave("Whether the periodically save the map when playing.", false),
autosaveAmount("The maximum amount of autosaves. Older ones get replaced.", 10),
autosaveSpacing("Spacing between autosaves in seconds.", 60 * 5),
debug("Enable debug logging", false, () -> Log.setLogLevel(debug() ? LogLevel.debug : LogLevel.info));
debug("Enable debug logging", false, () -> {
LogLevel level = debug() ? LogLevel.debug : LogLevel.info;
Log.level = level;
});
public static final Config[] all = values();

View File

@@ -58,8 +58,6 @@ public class NetworkIO{
state.rules = JsonIO.read(Rules.class, stream.readUTF());
state.map = new Map(SaveIO.getSaveWriter().readStringMap(stream));
Log.info("READ RULES: @", state.rules.researched);
state.wave = stream.readInt();
state.wavetime = stream.readFloat();