Skip to content

Commit

Permalink
Merge pull request #109 from StenAL/features
Browse files Browse the repository at this point in the history
Fix client connection retries, lobby resizing, and lobby joining delays
  • Loading branch information
PhilippvK authored May 28, 2024
2 parents dc2b5b3 + 6759ad7 commit ee9374e
Show file tree
Hide file tree
Showing 16 changed files with 761 additions and 776 deletions.
8 changes: 4 additions & 4 deletions client/src/main/java/agolf/GameApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ protected void setGameState(int panelActive, int lobbyId, int lobbyExtra) {
boolean var5 = false;
if (this.gameContainer.defaultLobby != null) {
if (this.gameContainer.defaultLobby.equalsIgnoreCase("singlehidden")) {
var5 = this.gameContainer.lobbySelectionPanel.method443(1, true);
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(1, true);
} else if (this.gameContainer.defaultLobby.equalsIgnoreCase("single")) {
var5 = this.gameContainer.lobbySelectionPanel.method443(1, false);
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(1, false);
} else if (this.gameContainer.defaultLobby.equalsIgnoreCase("dual")) {
var5 = this.gameContainer.lobbySelectionPanel.method443(2, false);
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(2, false);
} else if (this.gameContainer.defaultLobby.equalsIgnoreCase("multi")) {
var5 = this.gameContainer.lobbySelectionPanel.method443(3, false);
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(3, false);
}

this.gameContainer.defaultLobby = null;
Expand Down
53 changes: 26 additions & 27 deletions client/src/main/java/agolf/LobbySelectPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

public class LobbySelectPanel extends Panel implements ActionListener, MouseListener, ItemListener {

private static final int[] anIntArray526 = new int[]{3000, 7000, 15000};
private static final int anInt527 = anIntArray526.length;
private static long[] aLongArray528;
private static final int[] lobbyJoinDelays = new int[]{1000};
private static long[] lobbyJoinAvailableTimestamps;
private static boolean playHidden;
private GameContainer gameContainer;
private int width;
Expand Down Expand Up @@ -143,41 +142,41 @@ public void itemStateChanged(ItemEvent evt) {
this.gameContainer.graphicsQualityIndex = this.choicerGraphics.getSelectedIndex();
}

public static String method442(int var0) {
if (aLongArray528 == null) {
aLongArray528 = new long[anInt527];
public static String getLobbySelectMessage(int lobbyId) {
if (lobbyJoinAvailableTimestamps == null) {
lobbyJoinAvailableTimestamps = new long[lobbyJoinDelays.length];

for (int var1 = 0; var1 < anInt527; ++var1) {
aLongArray528[var1] = 0L;
for (int i = 0; i < lobbyJoinDelays.length; ++i) {
lobbyJoinAvailableTimestamps[i] = 0L;
}
}

long var2 = System.currentTimeMillis();
long var4 = 0L;
long now = System.currentTimeMillis();
long sleepTime = 0L;

for (int var6 = 0; var6 < anInt527; ++var6) {
long var7 = aLongArray528[var6] + (long) anIntArray526[var6] - var2;
if (var7 > var4) {
var4 = var7;
for (int i = 0; i < lobbyJoinDelays.length; ++i) {
long delayNeededForTimestamp = lobbyJoinAvailableTimestamps[i] + (long) lobbyJoinDelays[i] - now;
if (delayNeededForTimestamp > sleepTime) {
sleepTime = delayNeededForTimestamp;
}
}

for (int var9 = anInt527 - 1; var9 >= 1; --var9) {
aLongArray528[var9] = aLongArray528[var9 - 1];
for (int i = lobbyJoinDelays.length - 1; i >= 1; --i) {
lobbyJoinAvailableTimestamps[i] = lobbyJoinAvailableTimestamps[i - 1];
}

aLongArray528[0] = var2 + var4;
Tools.sleep(var4);
return "select\t" + (var0 <= 2 ? String.valueOf(var0) : "x") + (var0 == 1 && playHidden ? "h" : "");
lobbyJoinAvailableTimestamps[0] = now + sleepTime;
Tools.sleep(sleepTime);
return "select\t" + (lobbyId <= 2 ? String.valueOf(lobbyId) : "x") + (lobbyId == 1 && playHidden ? "h" : "");
}

protected boolean method443(int var1, boolean var2) {
if (this.gameContainer.disableSinglePlayer && var1 == 1) {
protected boolean selectLobby(int lobbyId, boolean playHidden) {
if (this.gameContainer.disableSinglePlayer && lobbyId == 1) {
return false;
} else {
this.checkboxPlayHidden.setState(var2);
playHidden = var2;
return this.selectLobby(var1);
this.checkboxPlayHidden.setState(playHidden);
LobbySelectPanel.playHidden = playHidden;
return this.selectLobby(lobbyId);
}
}

Expand Down Expand Up @@ -281,12 +280,12 @@ private void drawNumPlayers(Graphics g, int x, int numPlayers) {
}
}

private boolean selectLobby(int var1) {
if (this.lobbyNumPlayers[var1 - 1] >= this.lobbyMaxPlayers && this.gameContainer.gameApplet.getPlayerAccessLevel() == 0) {
private boolean selectLobby(int lobbyId) {
if (this.lobbyNumPlayers[lobbyId - 1] >= this.lobbyMaxPlayers && this.gameContainer.gameApplet.getPlayerAccessLevel() == 0) {
return false;
} else {
this.gameContainer.gameApplet.setGameState(0);
this.writeData(method442(var1));
this.writeData(getLobbySelectMessage(lobbyId));
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/agolf/game/ChatPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected void addBroadcastMessage(String message) {
}

private void create() {
this.setLayout((LayoutManager) null);
this.setLayout(null);
this.textAreaChat = new ChatTextArea(this.gameContainer.textManager, this.gameContainer.badWordFilter, this.width, this.height - 22, new Font("Dialog", 0, 11));
this.textAreaChat.setLocation(0, 0);
this.textFieldMessage = new InputTextField(this.gameContainer.textManager.getGame("GameChat_TypeHere"), 200, true);
Expand Down
26 changes: 13 additions & 13 deletions client/src/main/java/agolf/lobby/LobbyChatPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ protected boolean handlePacket(String[] args) {
aBoolean3714 = false;// ??
}
} else {
super.gui_output.clear();
super.gui_userlist.removeAllUsers();
super.chatTextArea.clear();
super.userList.removeAllUsers();
}

int numSingleLobby = Integer.parseInt(args[2]);
Expand Down Expand Up @@ -124,7 +124,7 @@ protected boolean handlePacket(String[] args) {
message = this.gameContainer.textManager.getGame("LobbyChat_UsersInThisLobbyXX", lobbyUsers, ingameUsers);
}

super.gui_output.addPlainMessage(message);
super.chatTextArea.addPlainMessage(message);
message = null;
if (this.lobbyId == 1 && (dualLobbyUsers >= 1 || multiLobbyUsers >= 1)) {
message = "(";
Expand Down Expand Up @@ -202,10 +202,10 @@ protected boolean handlePacket(String[] args) {
}

if (message != null) {
super.gui_output.addPlainMessage(message);
super.chatTextArea.addPlainMessage(message);
}

super.gui_output.addLine();
super.chatTextArea.addLine();
return true;
}
else if(args[1].equals("users")) {
Expand All @@ -226,7 +226,7 @@ else if(args[1].equals("ownjoin")) {
else if(args[1].equals("join") || args[1].equals("joinfromgame")) {
String userData = this.userJoin(args[2]);
if (!this.isNoJoinPartMessages()) {
super.gui_output.addJoinMessage(this.gameContainer.textManager.getGame("LobbyChat_User" + (args[1].equals("join") ? "Joined" : "ReturnedFromGame"), userData));
super.chatTextArea.addJoinMessage(this.gameContainer.textManager.getGame("LobbyChat_User" + (args[1].equals("join") ? "Joined" : "ReturnedFromGame"), userData));
}

return true;
Expand All @@ -236,7 +236,7 @@ else if(args[1].equals("part")) {
int reason = Integer.parseInt(args[3]);
if(reason == 1 && this.lobbyId == 1) {
if (!this.isNoGameMessages()) {
super.gui_output.addMessage(this.gameContainer.textManager.getGame("LobbyChat_UserStartedSp", args[2]));
super.chatTextArea.addMessage(this.gameContainer.textManager.getGame("LobbyChat_UserStartedSp", args[2]));
}

return true;
Expand All @@ -250,13 +250,13 @@ else if(args[1].equals("part")) {
var5 = this.gameContainer.textManager.getGame("LobbyChat_User" + reasons[reason], args[2], args[4]);
}

super.gui_output.addMessage(var5);
super.chatTextArea.addMessage(var5);
}

return true;
} else if(reason >= 4) {
if (!this.isNoJoinPartMessages()) {
super.gui_output.addPartMessage(this.gameContainer.textManager.getGame("LobbyChat_UserLeft" + (reason == 5 ? "ConnectionProblem" : ""), args[2]));
super.chatTextArea.addPartMessage(this.gameContainer.textManager.getGame("LobbyChat_UserLeft" + (reason == 5 ? "ConnectionProblem" : ""), args[2]));
}

return true;
Expand All @@ -266,7 +266,7 @@ else if(args[1].equals("part")) {
}
else if(args[1].equals("gsn")) {
if (!this.isNoGameMessages()) {
super.gui_output.addMessage(this.gameContainer.textManager.getGame("LobbyChat_UsersStartedDp", args[2], args[3]));
super.chatTextArea.addMessage(this.gameContainer.textManager.getGame("LobbyChat_UsersStartedDp", args[2], args[3]));
}

return true;
Expand Down Expand Up @@ -297,14 +297,14 @@ else if (args[1].equals("nc")) {
protected void getUser(String name, boolean var2) {
UserListItem var3;
if (name != null) {
var3 = super.gui_userlist.getUser(name);
var3 = super.userList.getUser(name);
if (var3 == null) {
return;
}
} else {
var3 = super.gui_userlist.getLocalUser();
var3 = super.userList.getLocalUser();
}

super.gui_userlist.setNotAcceptingChallenges(var3, var2);
super.userList.setNotAcceptingChallenges(var3, var2);
}
}
29 changes: 14 additions & 15 deletions client/src/main/java/agolf/lobby/LobbyControlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import com.aapeli.colorgui.ColorButton;

import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class LobbyControlPanel extends Panel implements ActionListener {

private GameContainer gameContainer;
private int height;
private int width;
private int height;
private ColorButton buttonBack;
private ColorButton buttonSingle;
//private ColorButton buttonDual;
Expand All @@ -25,8 +24,8 @@ class LobbyControlPanel extends Panel implements ActionListener {

protected LobbyControlPanel(GameContainer gameContainer, int width, int height) {
this.gameContainer = gameContainer;
this.height = width;
this.width = height;
this.width = width;
this.height = height;
this.setSize(width, height);
this.create();
}
Expand All @@ -36,13 +35,13 @@ public void addNotify() {
this.repaint();
}

public void paint(Graphics var1) {
this.update(var1);
public void paint(Graphics graphics) {
this.update(graphics);
}

public void update(Graphics var1) {
var1.setColor(GameApplet.colourGameBackground);
var1.fillRect(0, 0, this.height, this.width);
public void update(Graphics graphics) {
graphics.setColor(GameApplet.colourGameBackground);
graphics.fillRect(0, 0, this.width, this.height);
}

public void actionPerformed(ActionEvent evt) {
Expand All @@ -66,7 +65,7 @@ public void actionPerformed(ActionEvent evt) {

if (lobbyId > 0) {
this.gameContainer.gameApplet.setGameState(0);
this.gameContainer.lobbyPanel.writeData(LobbySelectPanel.method442(lobbyId));
this.gameContainer.lobbyPanel.writeData(LobbySelectPanel.getLobbySelectMessage(lobbyId));
}

}
Expand Down Expand Up @@ -98,15 +97,15 @@ protected void setState(int state) {
}

private void create() {
this.setLayout((LayoutManager) null);
this.setLayout(null);
this.buttonBack = new ColorButton(this.gameContainer.textManager.getGame("LobbyControl_Main"));
this.buttonBack.setBackground(GameApplet.colourButtonYellow);
this.buttonBack.setBounds(0, 0, this.height, 20);
this.buttonBack.setBounds(0, 0, this.width, 20);
this.buttonBack.addActionListener(this);
this.add(this.buttonBack);
if (!this.gameContainer.disableSinglePlayer) {
this.buttonSingle = new ColorButton(this.gameContainer.textManager.getGame("LobbyControl_Single"));
this.buttonSingle.setBounds(0, 27, this.height, 20);
this.buttonSingle.setBounds(0, 27, this.width, 20);
this.buttonSingle.addActionListener(this);
}

Expand All @@ -117,11 +116,11 @@ private void create() {
*/

this.buttonMulti = new ColorButton(this.gameContainer.textManager.getGame("LobbyControl_Multi"));
this.buttonMulti.setBounds(0, 77, this.height, 20);
this.buttonMulti.setBounds(0, 77, this.width, 20);
this.buttonMulti.addActionListener(this);
this.buttonQuit = new ColorButton(this.gameContainer.textManager.getGame("LobbyControl_Quit"));
this.buttonQuit.setBackground(GameApplet.colourButtonRed);
this.buttonQuit.setBounds(0, this.width - 20, this.height, 20);
this.buttonQuit.setBounds(0, this.height - 20, this.width, 20);
this.buttonQuit.addActionListener(this);
this.add(this.buttonQuit);
}
Expand Down
28 changes: 14 additions & 14 deletions client/src/main/java/agolf/lobby/LobbyPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import com.aapeli.multiuser.UserListItem;
import org.moparforia.client.Launcher;

import java.awt.Graphics;
import java.awt.Panel;
import java.awt.*;

public class LobbyPanel extends Panel {

Expand All @@ -32,6 +31,7 @@ public LobbyPanel(GameContainer gameContainer, int width, int height) {
this.gameContainer = gameContainer;
this.width = width;
this.height = height;
this.setLayout(null);
this.setSize(width, height);
}

Expand All @@ -40,13 +40,13 @@ public void addNotify() {
this.repaint();
}

public void paint(Graphics var1) {
this.update(var1);
public void paint(Graphics graphics) {
this.update(graphics);
}

public void update(Graphics var1) {
var1.setColor(GameApplet.colourGameBackground);
var1.fillRect(0, 0, this.width, this.height);
public void update(Graphics graphics) {
graphics.setColor(GameApplet.colourGameBackground);
graphics.fillRect(0, 0, this.width, this.height);
}

public void selectLobby(int lobbyId, int lobbyExtra) {
Expand Down Expand Up @@ -193,17 +193,17 @@ public void handlePacket(String[] args) {

}

public void broadcastMessage(String var1) {
public void broadcastMessage(String message) {
if (this.lobbyChatPanelSingle != null) {
this.lobbyChatPanelSingle.broadcastMessage(var1);
this.lobbyChatPanelSingle.broadcastMessage(message);
}

if (this.lobbyChatPanelDual != null) {
this.lobbyChatPanelDual.broadcastMessage(var1);
this.lobbyChatPanelDual.broadcastMessage(message);
}

if (this.lobbyChatPanelMulti != null) {
this.lobbyChatPanelMulti.broadcastMessage(var1);
this.lobbyChatPanelMulti.broadcastMessage(message);
}

}
Expand All @@ -224,9 +224,9 @@ protected void getUser(String name, boolean var2) {
this.lobbyChatPanelDual.getUser(name, var2);
}

protected boolean isNotAcceptingChallenges(String var1) {
UserListItem var2 = this.lobbyChatPanelDual.gui_userlist.getUser(var1);
return var2 != null ? var2.isNotAcceptingChallenges() : true;
protected boolean isNotAcceptingChallenges(String user) {
UserListItem userItem = this.lobbyChatPanelDual.userList.getUser(user);
return userItem != null ? userItem.isNotAcceptingChallenges() : true;
}

protected Choicer addChoicerNumTracks(Panel container, int x, int y, int width, int height) {
Expand Down
Loading

0 comments on commit ee9374e

Please sign in to comment.