mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-14 14:24:37 +01:00
Fix console when using dumb terminal
This commit is contained in:
@@ -6,6 +6,7 @@ import org.jline.reader.EndOfFileException;
|
|||||||
import org.jline.reader.LineReaderBuilder;
|
import org.jline.reader.LineReaderBuilder;
|
||||||
import org.jline.reader.UserInterruptException;
|
import org.jline.reader.UserInterruptException;
|
||||||
import org.jline.reader.impl.LineReaderImpl;
|
import org.jline.reader.impl.LineReaderImpl;
|
||||||
|
import org.jline.terminal.Terminal;
|
||||||
import org.jline.terminal.TerminalBuilder;
|
import org.jline.terminal.TerminalBuilder;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -24,7 +25,6 @@ import lombok.Getter;
|
|||||||
|
|
||||||
public class LunarCore {
|
public class LunarCore {
|
||||||
private static final Logger log = (Logger) LoggerFactory.getLogger(LunarCore.class);
|
private static final Logger log = (Logger) LoggerFactory.getLogger(LunarCore.class);
|
||||||
private static LineReaderImpl reader;
|
|
||||||
private static File configFile = new File("./config.json");
|
private static File configFile = new File("./config.json");
|
||||||
private static Config config;
|
private static Config config;
|
||||||
|
|
||||||
@@ -37,12 +37,17 @@ public class LunarCore {
|
|||||||
@Getter private static CommandManager commandManager;
|
@Getter private static CommandManager commandManager;
|
||||||
@Getter private static ServerType serverType = ServerType.BOTH;
|
@Getter private static ServerType serverType = ServerType.BOTH;
|
||||||
|
|
||||||
|
private static LineReaderImpl reader;
|
||||||
|
@Getter private static boolean usingDumbTerminal;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Setup console reader
|
// Setup console reader
|
||||||
try {
|
try {
|
||||||
reader = (LineReaderImpl) LineReaderBuilder.builder()
|
reader = (LineReaderImpl) LineReaderBuilder.builder()
|
||||||
.terminal(TerminalBuilder.builder().dumb(true).build())
|
.terminal(TerminalBuilder.builder().dumb(true).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
usingDumbTerminal = Terminal.TYPE_DUMB.equals(reader.getTerminal().getType());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,20 +12,22 @@ import emu.lunarcore.util.Utils;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import kcp.highway.Ukcp;
|
import kcp.highway.Ukcp;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class GameSession {
|
public class GameSession {
|
||||||
@Getter private final GameServer server;
|
private final GameServer server;
|
||||||
@Getter private InetSocketAddress address;
|
private InetSocketAddress address;
|
||||||
|
|
||||||
@Getter private Account account;
|
private Account account;
|
||||||
@Getter private Player player;
|
private Player player;
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
private Ukcp ukcp;
|
@Getter(AccessLevel.PRIVATE) private Ukcp ukcp;
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
@Getter private SessionState state = SessionState.WAITING_FOR_TOKEN;
|
private SessionState state = SessionState.WAITING_FOR_TOKEN;
|
||||||
private boolean useSecretKey;
|
private boolean useSecretKey;
|
||||||
|
|
||||||
private GameSession(GameServer server) {
|
private GameSession(GameServer server) {
|
||||||
@@ -168,8 +170,7 @@ public class GameSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void logPacket(String sendOrRecv, int opcode, byte[] payload) {
|
public void logPacket(String sendOrRecv, int opcode, byte[] payload) {
|
||||||
LunarCore.getLogger().info(sendOrRecv + ": " + CmdIdUtils.getOpcodeName(opcode) + " (" + opcode + ")");
|
LunarCore.getLogger().info(sendOrRecv + ": " + CmdIdUtils.getOpcodeName(opcode) + " (" + opcode + ")" + System.lineSeparator() + Utils.bytesToHex(payload));
|
||||||
LunarCore.getLineReader().printAbove(Utils.bytesToHex(payload));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package emu.lunarcore.util;
|
package emu.lunarcore.util;
|
||||||
|
|
||||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
|
||||||
import ch.qos.logback.core.AppenderBase;
|
import ch.qos.logback.core.AppenderBase;
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
import ch.qos.logback.classic.PatternLayout;
|
import ch.qos.logback.classic.PatternLayout;
|
||||||
|
|
||||||
import emu.lunarcore.LunarCore;
|
import emu.lunarcore.LunarCore;
|
||||||
@@ -26,6 +26,10 @@ public class LunarConsoleAppender extends AppenderBase<ILoggingEvent> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void append(ILoggingEvent event) {
|
protected void append(ILoggingEvent event) {
|
||||||
LunarCore.getLineReader().printAbove(layout.doLayout(event));
|
if (LunarCore.isUsingDumbTerminal()) {
|
||||||
|
System.out.print(layout.doLayout(event));
|
||||||
|
} else {
|
||||||
|
LunarCore.getLineReader().printAbove(layout.doLayout(event));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user