Skip to content

Commit

Permalink
Merge pull request #121 from StenAL/features
Browse files Browse the repository at this point in the history
Fix multiplayer quick start, adjust cut off text, and other minor fixes
  • Loading branch information
PhilippvK authored Nov 4, 2024
2 parents b14125d + 903bc31 commit c3716af
Show file tree
Hide file tree
Showing 37 changed files with 198 additions and 234 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ Common CLI options for both the client and the server:
- `-ip` to set the hostname
- `-p` to set the port
- `-h` to learn about all the available options
- `--verbose` to enable debug logging

Server CLI options:
- `--tracks-dir` to use custom tracks instead of the default set of bundled tracks

Client CLI options:
- `--verbose` to enable debug logging
- `--norandom` to disable randomization for shots
- `--username` to set username from CLI and skip inputting it

Expand Down
6 changes: 3 additions & 3 deletions client/src/main/java/agolf/GameApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public void createImages() {
}

public void connectToServer() {
this.gameContainer.connection = new Conn(this.gameContainer);
if (!this.gameContainer.connection.method1158()) {
this.gameContainer.connection = new GolfConnection(this.gameContainer);
if (!this.gameContainer.connection.openSocketConnection()) {
this.setEndState(END_ERROR_CONNECTION);
}

Expand All @@ -115,7 +115,7 @@ public boolean isDebug() {
return verbose;
}

protected int method32() {
protected int getActivePanel() {
return this.activePanel;
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/agolf/GameContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GameContainer {// some kind of a container for everything
public BadWordFilter badWordFilter;
public AutoPopups autoPopup;
public TrackCollection trackCollection;
public Conn connection;
public GolfConnection connection;
public LobbySelectPanel lobbySelectionPanel;
public LobbyPanel lobbyPanel;
public String defaultLobby;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package agolf;

import com.aapeli.applet.AApplet;
import com.aapeli.connection.ConnListener;
import com.aapeli.connection.Connection;
import com.aapeli.connection.SocketConnectionListener;
import com.aapeli.connection.SocketConnection;
import com.aapeli.tools.Tools;

public class Conn implements ConnListener {
public class GolfConnection implements SocketConnectionListener {

private static final String[] cipherCmds = new String[] {
"status\t",
Expand Down Expand Up @@ -78,30 +78,29 @@ public class Conn implements ConnListener {
"error"
};
private GameContainer gameContainer;
private Connection connection;
private String aString2372;
private String aString2373;
private SocketConnection socketConnection;
private String lastPacketSent;
private String lastPacketReceived;


protected Conn(GameContainer var1) {
protected GolfConnection(GameContainer var1) {
this.gameContainer = var1;
this.aString2372 = this.aString2373 = null;
this.lastPacketSent = this.lastPacketReceived = null;
}

public void dataReceived(String var1) {
public void dataReceived(String packet) {
try {
this.handlePacket(var1);
this.aString2373 = var1;
} catch (Exception var4) {
Exception var2 = var4;
this.handlePacket(packet);
this.lastPacketReceived = packet;
} catch (Exception e) {

try {
this.writeData("error-debug\t" + this.gameContainer.gameApplet.method32() + "\t" + var2.toString().trim().replace('\n', '\\') + "\t" + var1.replace('\t', '\\') + "\t" + this.aString2373.replace('\t', '\\') + "\t" + this.aString2372.replace('\t', '\\'));
} catch (Exception var3) {
this.writeData("error-debug\t" + this.gameContainer.gameApplet.getActivePanel() + "\t" + e.toString().trim().replace('\n', '\\') + "\t" + packet.replace('\t', '\\') + "\t" + this.lastPacketReceived.replace('\t', '\\') + "\t" + this.lastPacketSent.replace('\t', '\\'));
} catch (Exception ex) {
}

this.gameContainer.gameApplet.setEndState(var4);
this.connection.closeConnection();
this.gameContainer.gameApplet.setEndState(e);
this.socketConnection.closeConnection();
}
}

Expand All @@ -122,9 +121,9 @@ public void notifyConnectionDown() {
public void notifyConnectionUp() {
}

protected boolean method1158() {
this.connection = new Connection(this.gameContainer.gameApplet, this, cipherCmds);
return this.connection.openConnection();
protected boolean openSocketConnection() {
this.socketConnection = new SocketConnection(this.gameContainer.gameApplet, this, cipherCmds);
return this.socketConnection.openConnection();
}

protected void sendVersion() {
Expand All @@ -133,13 +132,13 @@ protected void sendVersion() {
}

public void writeData(String var1) {
this.aString2372 = var1;
this.connection.writeData(var1);
this.lastPacketSent = var1;
this.socketConnection.writeData(var1);
}

protected void disconnect() {
if (this.connection != null) {
this.connection.closeConnection();
if (this.socketConnection != null) {
this.socketConnection.closeConnection();
}
}

Expand All @@ -152,7 +151,7 @@ private void handlePacket(String cmd) {
this.gameContainer.gameApplet.setEndState(AApplet.END_ERROR_SERVERFULL);
}

this.connection.closeConnection();
this.socketConnection.closeConnection();
} else if (args[0].equals("versok")) {
this.writeData("language\t" + this.gameContainer.params.getChatLang());
String var4 = this.gameContainer.params.getSessionLocale();
Expand Down
3 changes: 0 additions & 3 deletions client/src/main/java/agolf/game/HackedShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import java.util.Arrays;
import java.util.List;

/**
* mmmkay children.
*/
public class HackedShot implements Runnable {

private static final double aDouble2798 = Math.sqrt(2.0D) / 2.0D;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void update(Graphics g) {
this.graphics.setFont(GameApplet.fontSerif26b);
StringDraw.drawString(this.graphics, this.gameContainer.textManager.getGame("LobbySelect_MultiPlayer"), this.width / 2, 35, 0);
this.graphics.setFont(GameApplet.fontSerif20);
StringDraw.drawOutlinedString(this.graphics, var2, this.gameContainer.textManager.getGame("LobbyReal_CreateTitle"), this.width / 2 - 185, 50, 1);
StringDraw.drawOutlinedString(this.graphics, var2, this.gameContainer.textManager.getGame("LobbyReal_CreateTitle"), this.width / 2 - 165, 50, 1);
StringDraw.drawString(this.graphics, this.gameContainer.textManager.getGame("LobbyReal_JoinTitle"), this.width * 3 / 4, 60, 0);
byte yPos = 86;
this.graphics.setFont(GameApplet.fontDialog12);
Expand Down
22 changes: 11 additions & 11 deletions client/src/main/java/com/aapeli/applet/AApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.aapeli.client.SoundManager;
import com.aapeli.client.StringDraw;
import com.aapeli.client.TextManager;
import com.aapeli.connection.Connection;
import com.aapeli.connection.SocketConnection;
import com.aapeli.tools.QuickTimer;
import com.aapeli.tools.QuickTimerListener;
import com.aapeli.tools.Tools;
Expand Down Expand Up @@ -67,7 +67,7 @@ public abstract class AApplet extends Applet implements Runnable, ActionListener
private Image splashImage;
private long splashTimestamp;
private QuickTimer popupTimer;
private Connection connection;
private SocketConnection socketConnection;
private Image appletImage;
private Graphics appletGraphics;
private boolean verbose;
Expand Down Expand Up @@ -484,7 +484,7 @@ public void run() {
}

this.sendLoadTimes(readyTime, finishedTime, time1, time2, time3, time4, time5, time6);
this.writeThriftDebug("clientconnect", "loadtime:i:" + readyTime + "^loadertime:i:" + finishedTime);
this.writeMetadataLog1("clientconnect", "loadtime:i:" + readyTime + "^loadertime:i:" + finishedTime);
this.loadingPanel.displayButtons();
if (this.endState == 0 && !this.destroyed) {
this.remove(this.loadingPanel);
Expand Down Expand Up @@ -692,20 +692,20 @@ public void allowExternalPopups() {
this.callJavaScriptJSON("{\"block\":\"false\"}");
}

public void setConnectionReference(Connection var1) {
this.connection = var1;
public void setConnectionReference(SocketConnection var1) {
this.socketConnection = var1;
}

public void writeThriftLog(String var1, String var2) {
if (this.connection != null) {
this.connection.writeThriftLog(0, var1, var2);
public void writeMetadataLog0(String dataType, String data) {
if (this.socketConnection != null) {
this.socketConnection.writeMetadataLog(0, dataType, data);
}

}

public void writeThriftDebug(String var1, String var2) {
if (this.connection != null) {
this.connection.writeThriftLog(1, var1, var2);
public void writeMetadataLog1(String dataType, String data) {
if (this.socketConnection != null) {
this.socketConnection.writeMetadataLog(1, dataType, data);
}

}
Expand Down
12 changes: 6 additions & 6 deletions client/src/main/java/com/aapeli/colorgui/ColorList.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ public synchronized void mousePressed(MouseEvent e) {
this.lastMouseClickY = e.getY();
ColorListItem item = this.getItemAt(this.lastMouseClickY);
if (item != null) {
boolean isMetaDown = e.isMetaDown();
boolean isRightClick = e.getButton() == MouseEvent.BUTTON3;
boolean isDoubleClick = e.getClickCount() == 2;
int clickMode = isMetaDown ? ID_RIGHTCLICKED : (isDoubleClick ? ID_DOUBLECLICKED : ID_CLICKED);
int eventId = isRightClick ? ID_RIGHTCLICKED : (isDoubleClick ? ID_DOUBLECLICKED : ID_CLICKED);
short newState = 701;
if (!item.isSelected()) {
if (this.selectable == SELECTABLE_NONE) {
Expand All @@ -251,14 +251,14 @@ public synchronized void mousePressed(MouseEvent e) {

item.setSelected(true);
newState = ItemEvent.SELECTED;
} else if (!isMetaDown) {
} else if (!isRightClick) {
item.setSelected(false);
newState = ItemEvent.DESELECTED;
}

if (this.selectable == SELECTABLE_MULTI) {
int i = this.items.indexOf(item);
if (clickMode == ID_CLICKED && (newState == ItemEvent.SELECTED || newState == ItemEvent.DESELECTED)) {
if (eventId == ID_CLICKED && (newState == ItemEvent.SELECTED || newState == ItemEvent.DESELECTED)) {
if (this.rangeSelectionLastIndex >= 0 && e.isShiftDown()) {
int startOfRange = Math.min(this.rangeSelectionLastIndex, i);
int endOfRange = Math.max(this.rangeSelectionLastIndex, i);
Expand All @@ -275,11 +275,11 @@ public synchronized void mousePressed(MouseEvent e) {
}
}

if (isMetaDown) {
if (isRightClick) {
this.update(this.getGraphics());
}

this.itemPressed(item, clickMode, newState);
this.itemPressed(item, eventId, newState);
this.repaint();
}
}
Expand Down
14 changes: 7 additions & 7 deletions client/src/main/java/com/aapeli/connection/GamePacketQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

class GamePacketQueue implements Runnable {

private Connection conn;
private ConnListener connListener;
private SocketConnection socketConnection;
private SocketConnectionListener socketConnectionListener;
private List<String> packets;
private boolean running;
private Thread thread;


protected GamePacketQueue(Connection conn, ConnListener connListener) {
this.conn = conn;
this.connListener = connListener;
protected GamePacketQueue(SocketConnection socketConnection, SocketConnectionListener socketConnectionListener) {
this.socketConnection = socketConnection;
this.socketConnectionListener = socketConnectionListener;
this.packets = new ArrayList<>();
this.running = true;
this.thread = new Thread(this);
Expand All @@ -29,15 +29,15 @@ public void run() {

String packet;
while ((packet = this.nextGamePacket()) != null) {
this.connListener.dataReceived(packet);
this.socketConnectionListener.dataReceived(packet);
}

if (this.running) {
continue;
}
} catch (Exception e) {
this.running = false;
this.conn.handleCrash();
this.socketConnection.handleCrash();
}

return;
Expand Down
Loading

0 comments on commit c3716af

Please sign in to comment.