Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Rewrite network communication #98

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@
</properties>

<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/java/agolf/Conn.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void notifyConnectionDown() {
public void notifyConnectionUp() {
}

protected boolean method1158() {
protected boolean connect() {
this.connection = new Connection(this.gameContainer.gameApplet, this, cipherCmds);
return this.connection.openConnection();
}
Expand Down Expand Up @@ -176,7 +176,7 @@ else if (args[0].equals("status")) {
}

if (args[0].equals("lobbyselect")) {
this.gameContainer.lobbySelectionPanel.handlePacket(args);
// this.gameContainer.lobbySelectionPanel.handlePacket(args);
} else if (args[0].equals("lobby")) {
this.gameContainer.lobbyPanel.handlePacket(args);
}
Expand Down
69 changes: 43 additions & 26 deletions client/src/main/java/agolf/GameApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.aapeli.applet.AApplet;
import com.aapeli.client.*;
import org.moparforia.client.Launcher;
import org.moparforia.client.networking.Client;

import javax.net.ssl.SSLException;
import java.awt.*;

public class GameApplet extends AApplet {
Expand All @@ -25,15 +27,17 @@ public class GameApplet extends AApplet {
public static final Font fontDialog14b = new Font("Dialog", 1, 14);
public static final Font fontDialog12 = new Font("Dialog", 0, 12);
public static final Font fontDialog11 = new Font("Dialog", 0, 11);
private GameContainer gameContainer;
public GameContainer gameContainer;
private int anInt3769;
private SynchronizedBool syncUnknownBool;
private SynchronizedBool emailVerified;
private SynchronizedInteger syncPlayerAccessLevel;
private boolean disableGuestChat;
private boolean aBoolean3773;
private Image anImage3774;
private boolean verbose = false;

public Client connection;


public void initApplet(Parameters var1) {
this.syncIsValidSite = new SynchronizedBool(this.isValidSite());
Expand Down Expand Up @@ -84,9 +88,14 @@ public void createImages() {
}

public void connectToServer() {
this.gameContainer.connection = new Conn(this.gameContainer);
if (!this.gameContainer.connection.method1158()) {
this.setEndState(END_ERROR_CONNECTION);
this.connection = new Client(this.param.getServerIp(), this.param.getServerPort(), this);
try {
this.connection.connect();
// if (!this.connection.connect()) {
// this.setEndState(END_ERROR_CONNECTION);
// }
} catch (InterruptedException | SSLException e) {
e.printStackTrace();
}

}
Expand All @@ -97,10 +106,17 @@ public void appletReady() {
this.setGameSettings(false, 0, true, true); // enabled Bad Word Filter!
this.gameContainer.trackCollection = new TrackCollection();
this.anImage3774 = this.createImage(735, 375);
this.gameContainer.connection.sendVersion();
this.setGameState(1);
}

public void destroyApplet() {
if (this.connection != null) {
try {
this.connection.disconnect();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
this.gameContainer.destroy();
}

Expand All @@ -116,16 +132,13 @@ public void setGameState(int var1) {// setGameState..maybe?
this.setGameState(var1, 0, 0);
}

protected void setGameState(int var1, int var2) {
public void setGameState(int var1, int var2) {
this.setGameState(var1, var2, 0);
}

protected void setGameState(int panelActive, int lobbyId, int lobbyExtra) {
if (panelActive != this.anInt3769 && this.syncIsValidSite.get()) {
this.anInt3769 = panelActive;
if (this.gameContainer.lobbySelectionPanel != null) {
this.gameContainer.lobbySelectionPanel.destroyRNOP();
}

this.clearContent();
if (panelActive == 1) {
Expand All @@ -140,16 +153,17 @@ protected void setGameState(int panelActive, int lobbyId, int lobbyExtra) {
TrackTestLoginPanel var4 = new TrackTestLoginPanel(this, super.appletWidth, super.appletHeight);
var4.setLocation(0, 0);
this.addToContent(var4);
} else if (this.hasSession()) {
super.param.noGuestAutoLogin();
this.gameContainer.connection.writeData("login\t" + super.param.getSession());
this.anInt3769 = 0;
} else if (!this.gameContainer.synchronizedTrackTestMode.get()) {
this.gameContainer.connection.writeData("login");
this.anInt3769 = 0;
} else {

}
// else if (this.hasSession()) {
// super.param.noGuestAutoLogin();
// this.gameContainer.connection.writeData("login\t" + super.param.getSession());
// this.anInt3769 = 0;
// } else if (!this.gameContainer.synchronizedTrackTestMode.get()) {
// this.gameContainer.connection.writeData("login");
// this.anInt3769 = 0;
// } else {
//
// }
}

if (panelActive == 2) {
Expand All @@ -175,7 +189,6 @@ protected void setGameState(int panelActive, int lobbyId, int lobbyExtra) {

if (!var5) {
this.addToContent(this.gameContainer.lobbySelectionPanel);
this.gameContainer.lobbySelectionPanel.resetRNOP();
}
}

Expand Down Expand Up @@ -212,20 +225,20 @@ protected void setGameState(int panelActive, int lobbyId, int lobbyExtra) {
}
}

protected void setGameSettings(boolean emailUnconfirmed, int var2, boolean useBadWordFilter, boolean var4) {
this.syncUnknownBool = new SynchronizedBool(emailUnconfirmed);
this.syncPlayerAccessLevel = new SynchronizedInteger(var2);
public void setGameSettings(boolean emailVerified, int playerAccessLevel, boolean useBadWordFilter, boolean var4) {
this.emailVerified = new SynchronizedBool(emailVerified);
this.syncPlayerAccessLevel = new SynchronizedInteger(playerAccessLevel);
this.gameContainer.badWordFilter = useBadWordFilter ? new BadWordFilter(super.textManager) : null;
this.disableGuestChat = var4;
}

protected void trackTestLogin(String username, String password) {
this.setGameState(0);
this.gameContainer.connection.writeData("ttlogin\t" + username + "\t" + password);
this.gameContainer.gameApplet.connection.login(username);
}

public boolean isEmailVerified() {
return this.syncUnknownBool.get();
return this.emailVerified.get();
}

public int getPlayerAccessLevel() {
Expand Down Expand Up @@ -266,7 +279,11 @@ public void gameFinished(boolean var1) {

public void quit(String from) {
this.setEndState(END_QUIT);
this.gameContainer.connection.writeData((from != null ? from + "\t" : "") + "quit");
try {
this.connection.disconnect();
} catch (InterruptedException e) {
e.printStackTrace();
}
this.setGameState(5);
}

Expand Down
7 changes: 1 addition & 6 deletions client/src/main/java/agolf/GameContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.aapeli.client.SoundManager;
import com.aapeli.client.TextManager;
import com.aapeli.tools.Tools;
import org.moparforia.client.networking.Client;

public class GameContainer {// some kind of a container for everything

Expand All @@ -22,7 +23,6 @@ public class GameContainer {// some kind of a container for everything
public BadWordFilter badWordFilter;
public AutoPopups autoPopup;
public TrackCollection trackCollection;
public Conn connection;
public LobbySelectPanel lobbySelectionPanel;
public LobbyPanel lobbyPanel;
public String defaultLobby;
Expand All @@ -47,11 +47,6 @@ protected void destroy() {
if (this.autoPopup != null) {
this.autoPopup.close();
}

if (this.connection != null) {
this.connection.disconnect();
}

}

private void init() {
Expand Down
76 changes: 12 additions & 64 deletions client/src/main/java/agolf/LobbySelectPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.aapeli.colorgui.ColorButton;
import com.aapeli.colorgui.ColorCheckbox;
import com.aapeli.tools.Tools;
import org.moparforia.shared.game.LobbyType;
import org.moparforia.shared.networking.packets.SelectGameTypePacket;

import java.awt.Color;
import java.awt.Graphics;
Expand Down Expand Up @@ -36,7 +38,6 @@ public class LobbySelectPanel extends Panel implements ActionListener, MouseList
private ColorCheckbox checkboxPlayHidden;
private Choicer choicerGraphics;
private int[] lobbyNumPlayers;
private LobbySelectRNOPspammer lobbySelectRNOP;
private static final String[] aStringArray544 = new String[22];


Expand Down Expand Up @@ -143,34 +144,6 @@ public void itemStateChanged(ItemEvent evt) {
this.gameContainer.graphicsQualityIndex = this.choicerGraphics.getSelectedIndex();
}

public static String method442(int var0) {
if (aLongArray528 == null) {
aLongArray528 = new long[anInt527];

for (int var1 = 0; var1 < anInt527; ++var1) {
aLongArray528[var1] = 0L;
}
}

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

for (int var6 = 0; var6 < anInt527; ++var6) {
long var7 = aLongArray528[var6] + (long) anIntArray526[var6] - var2;
if (var7 > var4) {
var4 = var7;
}
}

for (int var9 = anInt527 - 1; var9 >= 1; --var9) {
aLongArray528[var9] = aLongArray528[var9 - 1];
}

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

protected boolean method443(int var1, boolean var2) {
if (this.gameContainer.disableSinglePlayer && var1 == 1) {
return false;
Expand All @@ -181,32 +154,15 @@ protected boolean method443(int var1, boolean var2) {
}
}

protected void resetRNOP() {
this.destroyRNOP();
this.lobbySelectRNOP = new LobbySelectRNOPspammer(this);
}

protected void destroyRNOP() {
if (this.lobbySelectRNOP != null) {
this.lobbySelectRNOP.stop();
this.lobbySelectRNOP = null;
}

}

protected void handlePacket(String[] args) {
if (args[1].equals("nop")) {
for (int i = 0; i < 3; ++i) {
this.lobbyNumPlayers[i] = Integer.parseInt(args[2 + i]);
}

this.repaint();
}

public void setNumberOfPlayers(int single, int dual, int multi) {
lobbyNumPlayers[0] = single;
lobbyNumPlayers[1] = dual;
lobbyNumPlayers[2] = multi;
this.repaint();
}

protected void writeData(String var1) {
this.gameContainer.connection.writeData("lobbyselect\t" + var1);
// this.gameContainer.connection.writeData("lobbyselect\t" + var1);
}

private void create() {
Expand Down Expand Up @@ -281,17 +237,9 @@ 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) {
return false;
} else {
this.gameContainer.gameApplet.setGameState(0);
this.writeData(method442(var1));
return true;
}
}

protected void requestNumberOfPlayers() {
this.writeData("rnop");
private boolean selectLobby(int lobby) {
this.gameContainer.gameApplet.setGameState(0);
this.gameContainer.gameApplet.connection.send(new SelectGameTypePacket(LobbyType.getLobby(lobby)));
return true;
}
}
35 changes: 0 additions & 35 deletions client/src/main/java/agolf/LobbySelectRNOPspammer.java

This file was deleted.

2 changes: 1 addition & 1 deletion client/src/main/java/agolf/game/GameCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class GameCanvas extends GameBackgroundCanvas implements Runnable, MouseM
private boolean norandom;

// aimbot stuff
final private boolean allowCheating = false;
public final boolean allowCheating = false;
private double hackedX = 0;
private double hackedY = 0;
private boolean isCheating = false;
Expand Down
Loading