Skip to content

Commit

Permalink
tidy up abstract client stuff -> ClientUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Oct 13, 2024
1 parent dba2302 commit ce4de99
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 201 deletions.
18 changes: 8 additions & 10 deletions client/src/main/java/EntropyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import javax.swing.WindowConstants;

import logging.LoggerUncaughtExceptionHandler;
import online.util.DesktopEntropyClient;
import screen.MainScreen;
import screen.ScreenCache;
import util.*;
Expand All @@ -24,14 +23,13 @@ public static void main(String[] args)
Debug.initialise(new DebugOutputSystemOut());
Thread.setDefaultUncaughtExceptionHandler(new LoggerUncaughtExceptionHandler());
MainUtilKt.configureLogging();
AbstractClient.setInstance(new DesktopEntropyClient());

//Dev mode
AbstractClient.parseProgramArguments(args);
ClientUtil.parseProgramArguments(args);

setLookAndFeel();

if (AbstractClient.devMode)
if (ClientUtil.devMode)
{
setInstanceNumber();
}
Expand All @@ -56,13 +54,13 @@ else if (!bindOnPort(BIND_PORT_NUMBER))

private static void setLookAndFeel()
{
logger.info("laf.init", "Initialising Look & Feel - Operating System: " + AbstractClient.operatingSystem);
logger.info("laf.init", "Initialising Look & Feel - Operating System: " + ClientUtil.operatingSystem);

String lookAndFeel = null;
try
{
lookAndFeel = prefs.get(PREFERENCES_STRING_LOOK_AND_FEEL, "Metal");
if (AbstractClient.isAppleOs()
if (ClientUtil.isAppleOs()
&& lookAndFeel.equals("Metal"))
{
//This doesn't seem to work on macs...
Expand Down Expand Up @@ -94,11 +92,11 @@ private static void setInstanceNumber()
while (!boundSuccessfully)
{
startingPortNumber++;
AbstractClient.instanceNumber++;
ClientUtil.instanceNumber++;
boundSuccessfully = bindOnPort(startingPortNumber);
}

logger.info("instanceCheck", "I am instance number " + AbstractClient.instanceNumber);
logger.info("instanceCheck", "I am instance number " + ClientUtil.instanceNumber);
}

private static boolean bindOnPort(int portNumber)
Expand All @@ -120,12 +118,12 @@ private static void checkForUpdatesIfRequired()
{
boolean checkForUpdates = Registry.prefs.getBoolean(PREFERENCES_BOOLEAN_CHECK_FOR_UPDATES, true);
if (!checkForUpdates
|| AbstractClient.devMode)
|| ClientUtil.devMode)
{
logger.info("updateCheck", "Not checking for updates as preference is disabled or I'm in dev mode");
return;
}

AbstractClient.getInstance().checkForUpdatesIfRequired();
ClientUtil.checkForUpdatesIfRequired();
}
}
2 changes: 1 addition & 1 deletion client/src/main/java/online/screen/EntropyLobby.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void run()
AchievementsUtil.unlockConnected();

//Start the notification thread, this is how the server will send us unsolicited messages
AbstractClient.getInstance().startNotificationThreads();
ClientUtil.startNotificationThreads();

AchievementsDialog achievementsDialog = ScreenCache.getAchievementsDialog();
achievementsDialog.refresh(false);
Expand Down
88 changes: 0 additions & 88 deletions client/src/main/java/online/util/DesktopEntropyClient.java

This file was deleted.

4 changes: 2 additions & 2 deletions client/src/main/java/online/util/HeartbeatRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.w3c.dom.Document;

import util.AbstractClient;
import util.ClientUtil;
import util.MessageUtil;

import static utils.CoreGlobals.logger;
Expand All @@ -26,7 +26,7 @@ public void run()
{
while (lobby.isVisible())
{
long lastSentMessageMillis = AbstractClient.getInstance().getLastSentMessageMillis();
long lastSentMessageMillis = ClientUtil.getLastSentMessageMillis();
long currentMillis = System.currentTimeMillis();
long difference = currentMillis - lastSentMessageMillis;
if (difference >= HEARTBEAT_THREADHOLD)
Expand Down
8 changes: 0 additions & 8 deletions client/src/main/java/online/util/XmlBuilderClient.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package online.util;

import javax.crypto.SecretKey;

import object.Bid;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import util.AbstractClient;
import util.Debug;
import util.EncryptionUtil;
import util.KeyGeneratorUtil;
import util.MessageUtil;
import util.OnlineConstants;
import util.XmlConstants;
import util.XmlUtil;

Expand Down
7 changes: 3 additions & 4 deletions client/src/main/java/screen/MainScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import online.util.XmlBuilderDesktop;
import org.w3c.dom.Document;
import util.*;
import utils.CoreGlobals;

import javax.swing.*;
import javax.swing.border.BevelBorder;
Expand Down Expand Up @@ -659,15 +658,15 @@ private void selectGameScreen(int gameMode)
@Override
public boolean commandsEnabled()
{
return AbstractClient.devMode
return ClientUtil.devMode
|| rewards.getBoolean(Registry.REWARDS_BOOLEAN_CHEATS, false);
}

@Override
public String processCommand(String command)
{
String textToShow = "";
if (AbstractClient.devMode)
if (ClientUtil.devMode)
{
boolean processed = processDevModeCommand(command);
if (processed)
Expand Down Expand Up @@ -748,7 +747,7 @@ public void onStart()
leftPanel.add(gamePanel, BorderLayout.CENTER);

//If we've just updated, show the change log automatically
if (AbstractClient.justUpdated)
if (ClientUtil.justUpdated)
{
ChangeLog dialog = new ChangeLog();
dialog.setLocationRelativeTo(null);
Expand Down
10 changes: 4 additions & 6 deletions client/src/main/java/util/ClientNotificationRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ public class ClientNotificationRunnable implements Runnable
private static final int SO_TIMEOUT_MILLIS = 120000; //2 minutes

private String socketType = null;
private AbstractClient client = null;

public ClientNotificationRunnable(AbstractClient client, String socketType)
public ClientNotificationRunnable(String socketType)
{
this.client = client;
this.socketType = socketType;
}

Expand All @@ -23,16 +21,16 @@ public void run()
String messageStr = null;
String response = null;

while (client.isOnline())
while (ClientUtil.isOnline())
{
try
{
String username = client.getUsername();
String username = ClientUtil.getUsername();
Document notificationXml = XmlUtil.factorySimpleMessage(username, socketType);
messageStr = XmlUtil.getStringFromDocument(notificationXml);

//Send encrypted, with a 1 minute timeout
response = client.sendSync(notificationXml, true, SO_TIMEOUT_MILLIS, true);
response = ClientUtil.sendSync(notificationXml, true, SO_TIMEOUT_MILLIS, true);

//If the thread has stopped due to a d/c, we'll get a null response.
if (response == null)
Expand Down
Loading

0 comments on commit ce4de99

Please sign in to comment.