mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-10 10:20:41 -07:00
Fixed a critical bug with the Management Server (no more lockouts weeee)
This commit is contained in:
parent
eafc281439
commit
31479d811f
6 changed files with 68 additions and 6 deletions
|
|
@ -4,11 +4,17 @@ archivesBaseName = 'managementserver'
|
|||
|
||||
mainClassName = 'ms.Management'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.guava:guava:29.0-jre'
|
||||
implementation "com.github.ajalt.mordant:mordant:2.0.0-alpha2"
|
||||
implementation "org.jetbrains:markdown-jvm:0.2.0"
|
||||
implementation 'mysql:mysql-connector-java:8.0.21'
|
||||
}
|
||||
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'ms.Management'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package ms.net;
|
||||
|
||||
import ms.world.WorldDatabase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
|
|
@ -8,6 +10,7 @@ import java.nio.channels.SelectionKey;
|
|||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
|
|
@ -63,7 +66,9 @@ public final class IoEventHandler {
|
|||
ByteBuffer buffer = ByteBuffer.allocate(100_000);
|
||||
IoSession session = (IoSession) key.attachment();
|
||||
if (channel.read(buffer) == -1) {
|
||||
System.out.println("Existing session disconnected - likely portscanner or server status checker.");
|
||||
if(session.getGameServer() != null){
|
||||
WorldDatabase.unRegister(session.getGameServer());
|
||||
}
|
||||
key.cancel();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ public final class RegistryReadEvent extends IoReadEvent {
|
|||
boolean quickChat = buffer.get() == 1;
|
||||
boolean lootshare = buffer.get() == 1;
|
||||
String activity = ByteBufferUtils.getString(buffer);
|
||||
System.out.println("["+ revision + "], country = " + country + ", members = " + members + ", pvp = " + pvp + ", quickChat = " + quickChat + ", lootShare = " + lootshare + ", activity = " + activity);
|
||||
for (int i = 0; i < CHECK.length(); i++) {
|
||||
if ((char) buffer.get() != CHECK.charAt(i)) {
|
||||
session.write(3);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import ms.net.IoSession;
|
|||
import ms.net.packet.IoBuffer;
|
||||
import ms.world.info.CountryFlag;
|
||||
import ms.world.info.WorldInfo;
|
||||
import ms09.MSLogger;
|
||||
|
||||
/**
|
||||
* Holds all the world servers.
|
||||
|
|
@ -148,9 +149,25 @@ public class WorldDatabase {
|
|||
throw new IllegalStateException("World " + info.getWorldId() + " is already registered!");
|
||||
}
|
||||
flagUpdate();
|
||||
System.out.println("Registered world - [id=" + info.getWorldId() + ", ip=" + info.getAddress() + ", country=" + info.getCountry().name().toLowerCase() + ", revision=" + info.getRevision() + "]!");
|
||||
MSLogger.logInfo("Registered world - [id=" + info.getWorldId() + ", ip=" + info.getAddress() + ", country=" + info.getCountry().name().toLowerCase() + ", revision=" + info.getRevision() + "]!");
|
||||
return DATABASE[info.getWorldId()] = new GameServer(info);
|
||||
}
|
||||
|
||||
public static void unRegister(GameServer server){
|
||||
int index = -1;
|
||||
for(int i = 0; i < DATABASE.length; i++){
|
||||
GameServer s = DATABASE[i];
|
||||
if(s == server){
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(index != -1){
|
||||
DATABASE[index] = null;
|
||||
WorldInfo info = server.getInfo();
|
||||
MSLogger.logInfo("Unregistered world - [id=" + info.getWorldId() + ", ip=" + info.getAddress() + ", country=" + info.getCountry().name().toLowerCase() + ", revision=" + info.getRevision() + "]!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the world id of the player.
|
||||
|
|
|
|||
37
Management-Server/src/main/kotlin/ms09/MSLogger.kt
Normal file
37
Management-Server/src/main/kotlin/ms09/MSLogger.kt
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package ms09
|
||||
|
||||
import com.github.ajalt.mordant.rendering.TextColors
|
||||
import com.github.ajalt.mordant.terminal.Terminal
|
||||
import java.io.BufferedWriter
|
||||
import java.io.Writer
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
object MSLogger {
|
||||
val t = Terminal()
|
||||
val formatter = SimpleDateFormat("HH:mm:ss")
|
||||
var tradeLog: Writer? = null
|
||||
var tradeLogWriter: BufferedWriter? = null
|
||||
|
||||
|
||||
fun getTime(): String{
|
||||
return "[" + formatter.format(Date(System.currentTimeMillis())) +"]"
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun logInfo(vararg messages: String){
|
||||
for(m in messages){
|
||||
if(m.isNotBlank()) t.println("${getTime()}: [INFO] $m")
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun logErr(message: String){
|
||||
if(message.isNotBlank()) t.println("${getTime()}: ${TextColors.brightRed("[ ERR] $message")}")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun logWarn(message: String){
|
||||
if(message.isNotBlank()) t.println("${getTime()}: ${TextColors.yellow("[WARN] $message")}")
|
||||
}
|
||||
}
|
||||
|
|
@ -45,8 +45,6 @@ public final class SystemTermination {
|
|||
e.printStackTrace();
|
||||
}
|
||||
SystemLogger.logInfo("[SystemTerminator] Server successfully terminated!");
|
||||
Runtime.getRuntime().removeShutdownHook(ServerConstants.SHUTDOWN_HOOK);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue