Large improvements to server stability
This commit is contained in:
@@ -1,54 +1,33 @@
|
||||
package core.game.system.task;
|
||||
package core.game.system.task
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* A class holding methods to execute tasks.
|
||||
* @author Emperor
|
||||
*/
|
||||
public final class TaskExecutor {
|
||||
object TaskExecutor {
|
||||
|
||||
/**
|
||||
* The executor to use.
|
||||
*/
|
||||
private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor();
|
||||
/**
|
||||
* Executes an SQL handling task.
|
||||
* @param task The task.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun executeSQL(task: () -> Unit) {
|
||||
GlobalScope.launch {
|
||||
task.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The SQL task executor.
|
||||
*/
|
||||
private static final ScheduledExecutorService SQL_EXECUTOR = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
/**
|
||||
* Constructs a new {@code TaskExecutor} {@code Object}.
|
||||
*/
|
||||
private TaskExecutor() {
|
||||
/*
|
||||
* empty.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL handling task.
|
||||
* @param task The task.
|
||||
*/
|
||||
public static void executeSQL(Runnable task) {
|
||||
SQL_EXECUTOR.execute(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the task.
|
||||
* @param task The task to execute.
|
||||
*/
|
||||
public static void execute(Runnable task) {
|
||||
EXECUTOR.execute(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the executor.
|
||||
* @return The executor.
|
||||
*/
|
||||
public static ScheduledExecutorService getExecutor() {
|
||||
return EXECUTOR;
|
||||
}
|
||||
/**
|
||||
* Executes the task.
|
||||
* @param task The task to execute.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun execute(task: () -> Unit) {
|
||||
GlobalScope.launch {
|
||||
task.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import core.gui.ConsoleFrame;
|
||||
import core.gui.ConsoleTab;
|
||||
import core.tools.PlayerLoader;
|
||||
import core.tools.StringUtils;
|
||||
import kotlin.Unit;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
@@ -417,6 +418,7 @@ public final class UtilityTab extends ConsoleTab {
|
||||
populating = true;
|
||||
players.clear();
|
||||
TaskExecutor.execute(() -> {
|
||||
Thread.currentThread().setName("Utility Tab");
|
||||
ConsoleFrame.getInstance().getPlayerTab().getPlayerNames().clear();
|
||||
ConsoleFrame.getInstance().getPlayerTab().populatePlayerSearch();
|
||||
for (String name : ConsoleFrame.getInstance().getPlayerTab().getPlayerNames()) {
|
||||
@@ -435,6 +437,7 @@ public final class UtilityTab extends ConsoleTab {
|
||||
populating = false;
|
||||
System.gc();
|
||||
lblPlayersLoaded.setText("Players loaded: " + players.size());
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import core.net.EventProducer;
|
||||
import core.net.IoSession;
|
||||
import core.net.NioReactor;
|
||||
import core.net.producer.MSHSEventProducer;
|
||||
import kotlin.Unit;
|
||||
import rs09.game.node.entity.player.info.login.LoginParser;
|
||||
import rs09.game.system.SystemLogger;
|
||||
import rs09.game.world.GameWorld;
|
||||
@@ -76,15 +77,13 @@ public final class WorldCommunicator {
|
||||
return;
|
||||
}
|
||||
loginAttempts.put(parser.getDetails().getUsername(), parser);
|
||||
TaskExecutor.executeSQL(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!parser.getDetails().parse()) {
|
||||
parser.getDetails().getSession().write(Response.INVALID_LOGIN_SERVER, true);
|
||||
return;
|
||||
}
|
||||
MSPacketRepository.sendPlayerRegistry(parser);
|
||||
TaskExecutor.executeSQL(() -> {
|
||||
if (!parser.getDetails().parse()) {
|
||||
parser.getDetails().getSession().write(Response.INVALID_LOGIN_SERVER, true);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
MSPacketRepository.sendPlayerRegistry(parser);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import core.game.system.mysql.SQLManager;
|
||||
import core.game.system.task.TaskExecutor;
|
||||
import core.net.Constants;
|
||||
import core.net.IoSession;
|
||||
import kotlin.Unit;
|
||||
import rs09.ServerConstants;
|
||||
import rs09.game.system.SystemLogger;
|
||||
import rs09.game.world.GameWorld;
|
||||
@@ -76,19 +77,17 @@ public class AccountRegister extends SQLEntryHandler<RegistryDetails> {
|
||||
break;
|
||||
}
|
||||
System.out.println(username);
|
||||
TaskExecutor.executeSQL(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (PlayerSQLManager.hasSqlAccount(username, "username")) {
|
||||
response(session, RegistryResponse.NOT_AVAILBLE_USER);
|
||||
return;
|
||||
}
|
||||
response(session, RegistryResponse.SUCCESS);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
TaskExecutor.executeSQL(() -> {
|
||||
try {
|
||||
if (PlayerSQLManager.hasSqlAccount(username, "username")) {
|
||||
response(session, RegistryResponse.NOT_AVAILBLE_USER);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
response(session, RegistryResponse.SUCCESS);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
break;
|
||||
case 36://Register details
|
||||
@@ -129,21 +128,19 @@ public class AccountRegister extends SQLEntryHandler<RegistryDetails> {
|
||||
buffer.getInt();
|
||||
@SuppressWarnings("deprecation")
|
||||
final RegistryDetails details = new RegistryDetails(name, SystemManager.getEncryption().hashPassword(password), new Date(year, month, day), country);
|
||||
TaskExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (PlayerSQLManager.hasSqlAccount(name, "username")) {
|
||||
response(session, RegistryResponse.CANNOT_CREATE);
|
||||
return;
|
||||
}
|
||||
SQLEntryHandler.write(new AccountRegister(details));
|
||||
response(session, RegistryResponse.SUCCESS);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
TaskExecutor.execute(() -> {
|
||||
try {
|
||||
if (PlayerSQLManager.hasSqlAccount(name, "username")) {
|
||||
response(session, RegistryResponse.CANNOT_CREATE);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
SQLEntryHandler.write(new AccountRegister(details));
|
||||
response(session, RegistryResponse.SUCCESS);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
response(session, RegistryResponse.CANNOT_CREATE);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user