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

Improve custom tasmod server #177

Merged
merged 60 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
483afb3
Add lombok and refactor logger
PancakeTAS May 27, 2023
fc56586
Implement asynchronous client
PancakeTAS May 27, 2023
cbdf96e
Implement server and update client
PancakeTAS May 27, 2023
e0a2f1d
Implement authentication system
PancakeTAS Jun 14, 2023
56e8f85
Launch server and client on launch
PancakeTAS Jun 14, 2023
00f116f
Start moving packets to new system
PancakeTAS Jun 14, 2023
c51f1b6
Continue with packets
PancakeTAS Jun 14, 2023
fc261b9
Mark fields as final and preinitialize buffers
PancakeTAS Aug 8, 2023
475f113
Fix loggers
PancakeTAS Aug 8, 2023
bf3a131
Don't manually calculate sizes
PancakeTAS Aug 8, 2023
e2ee5b2
Update loom
PancakeTAS Aug 10, 2023
bd3069b
Rewrite to enums
PancakeTAS Aug 10, 2023
749a60e
Update method calls too
PancakeTAS Aug 10, 2023
682683a
Delombokified code
ScribbleTAS Aug 11, 2023
e220f5b
Adding packet handler interfaces and helpers for sending packets
ScribbleTAS Aug 12, 2023
690b8c3
WIP Packet rewrite
ScribbleTAS Aug 13, 2023
71a015e
Added tests for bufferbuilder and server
ScribbleTAS Aug 13, 2023
b78e1b3
Adding tests for the Client/Server
ScribbleTAS Aug 14, 2023
98aae99
Continued rewriting packets
ScribbleTAS Aug 15, 2023
ef8c655
Continued with packets
ScribbleTAS Aug 17, 2023
a9d3622
Finishing packets, renaming and removing classes
ScribbleTAS Aug 19, 2023
620ab76
Increased ttl for ServerTest
ScribbleTAS Aug 19, 2023
c6a02e1
Disabled ServerTest for now, doesn't seem to work with github...
ScribbleTAS Aug 19, 2023
4937f58
Added scheduler for opening the main menu
ScribbleTAS Aug 21, 2023
9cc75c5
Added logger as static import
ScribbleTAS Aug 22, 2023
b4c0c3a
Changed default port, added static import for logger
ScribbleTAS Aug 22, 2023
58a577e
Implementing tickrate packets, registering packet handlers
ScribbleTAS Aug 23, 2023
57c89fe
Documentation and small code improvements
ScribbleTAS Aug 27, 2023
a68cd0c
Fixed requesting motion, simplified NBTTagCompound sending
ScribbleTAS Sep 1, 2023
d3262e5
Fixing and discovering savestating issues
ScribbleTAS Sep 2, 2023
41d430b
Added defaults to infohud, added reset button, switched middleclick a…
ScribbleTAS Sep 3, 2023
59ab7ca
Changing to usernames instead off uuid, fixing BufferUnderflow crashes
ScribbleTAS Sep 3, 2023
9697829
Rearranging registering in main methods and documentation 🚂
ScribbleTAS Sep 5, 2023
8f1eb9d
Fixed labels going off screen in InfoHud
ScribbleTAS Sep 10, 2023
8f5f046
Networking for PlaybackControllerClient and TASstateServer to Playbac…
ScribbleTAS Sep 10, 2023
54d4e0b
More documentation for packets
ScribbleTAS Sep 10, 2023
55ae4a6
Updating loader version to 0.14.23
ScribbleTAS Oct 5, 2023
6ec4a45
Adding log4j config to server console
ScribbleTAS Oct 5, 2023
8b30d81
Testing multiplayer connections
ScribbleTAS Oct 5, 2023
eaefa65
Rewriting connection things
ScribbleTAS Oct 9, 2023
5a502a2
Fixing server closing
ScribbleTAS Oct 15, 2023
55b3e19
Fixed connecting to the wrong server
ScribbleTAS Oct 15, 2023
22ce325
Fixed tickadvance not working as intended
ScribbleTAS Oct 20, 2023
95c7065
Added disconnect packet and check for timeout
ScribbleTAS Oct 22, 2023
6455551
Fixed Redirect throwing errors
ScribbleTAS Oct 22, 2023
38eb555
Fixed client and server timing out in tickrate 0
ScribbleTAS Oct 22, 2023
8e235d0
Fixed gui controls crashing in tr 0
ScribbleTAS Oct 22, 2023
9b7fcca
Updated junit
ScribbleTAS Oct 22, 2023
9e4ab6d
Add property for "integrated" server
ScribbleTAS Oct 24, 2023
149dc1b
Removed timeout system
ScribbleTAS Oct 24, 2023
24739c2
Added a trace statement for network packets and it's contents
ScribbleTAS Nov 12, 2023
e8a7dc2
Networking fixes
ScribbleTAS Nov 12, 2023
7fd795b
[Savestates] Fixed a rare crash with gui screens
ScribbleTAS Nov 12, 2023
c60195e
Trying to fix savestates
ScribbleTAS Nov 12, 2023
2cb0fdc
[Savestates] Remove WASLOADING state
ScribbleTAS Nov 13, 2023
8614dbb
[Event] Drafting new event firing
ScribbleTAS Nov 13, 2023
d2bfe4b
Revert "[Event] Drafting new event firing"
ScribbleTAS Nov 15, 2023
e85bc87
[Networking] Added config option for automatically connecting to a cu…
ScribbleTAS Nov 15, 2023
e013634
[Networking] Documentation fixes 🚂
ScribbleTAS Nov 15, 2023
f69a6f2
[Networking] Finishing documentation 🚂 for packet ids
ScribbleTAS Nov 16, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ build
# other
eclipse
run/
logs/
logs/
/.apt_generated_tests/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.legacyfabric:yarn:${project.minecraft_version}+build.mcp"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

// task for downloading KillTheRng
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx3G

# Fabric properties
minecraft_version=1.12.2
loader_version=0.14.19
loom_version=1.2-SNAPSHOT
loader_version=0.14.23
loom_version=1.3-SNAPSHOT

# Mod properties
mod_name=Tool-Assisted Speedrun Mod
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/minecrafttas/common/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ public class Common {
public static final Logger LOGGER = LogManager.getLogger("Common");

public static final Marker Event = MarkerManager.getMarker("Event");

public static final Marker Server = MarkerManager.getMarker("Server");

public static final Marker Client = MarkerManager.getMarker("Client");

public static final Marker Timeout = MarkerManager.getMarker("Timeout");
}
3 changes: 2 additions & 1 deletion src/main/java/com/minecrafttas/common/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void delete(ConfigOptions configOption) {
}

public static enum ConfigOptions{
FileToOpen("fileToOpen", "");
FileToOpen("fileToOpen", ""),
ServerConnection("serverConnection", "");

private String configKey;
private String defaultValue;
Expand Down
29 changes: 16 additions & 13 deletions src/main/java/com/minecrafttas/common/KeybindManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@

/**
* Keybind manager
* @author Pancake
*/
public abstract class KeybindManager implements EventClientGameLoop {
public abstract class KeybindManager implements EventClientGameLoop {

public static class Keybind {

private KeyBinding keyBinding;
private String category;
private Runnable onKeyDown;

/**
* Initialize keybind
* @param name Name of keybind
* @param category Category of keybind
*
* @param name Name of keybind
* @param category Category of keybind
* @param defaultKey Default key of keybind
* @param onKeyDown Will be run when the keybind is pressed
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown) {
this.keyBinding = new KeyBinding(name, defaultKey, category);
Expand All @@ -36,16 +38,16 @@ public Keybind(String name, String category, int defaultKey, Runnable onKeyDown)
}

}

private List<Keybind> keybindings;

/**
* Initialize keybind manager
*/
public KeybindManager() {
this.keybindings = new ArrayList<>();
}

/**
* Handle registered keybindings on game loop
*/
Expand All @@ -57,23 +59,24 @@ public void onRunClientGameLoop(Minecraft mc) {
}

protected abstract boolean isKeyDown(KeyBinding i);

/**
* Register new keybind
* @param keybind Keybind
*
* @param keybind Keybind to register
*/
public KeyBinding registerKeybind(Keybind keybind) {
this.keybindings.add(keybind);
KeyBinding keyBinding = keybind.keyBinding;

// add category
GameSettings options = Minecraft.getMinecraft().gameSettings;
if (!KeyBinding.CATEGORY_ORDER.containsKey(keybind.category))
KeyBinding.CATEGORY_ORDER.put(keybind.category, KeyBinding.CATEGORY_ORDER.size() + 1);

// add keybinding
options.keyBindings = ArrayUtils.add(options.keyBindings, keyBinding);
return keyBinding;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.minecrafttas.common.events;

import java.nio.ByteBuffer;

import com.minecrafttas.common.server.exception.PacketNotImplementedException;

@FunctionalInterface
public interface CompactPacketHandler {

public void onPacket(ByteBuffer buf, String username) throws PacketNotImplementedException;
}
52 changes: 38 additions & 14 deletions src/main/java/com/minecrafttas/common/events/EventClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.minecrafttas.common.events;

import com.minecrafttas.common.Common;
import com.minecrafttas.common.events.EventListener.EventBase;
import com.minecrafttas.common.events.EventListenerRegistry.EventBase;
import com.minecrafttas.common.server.Client;
import com.mojang.authlib.GameProfile;

import net.minecraft.client.Minecraft;
Expand All @@ -26,7 +27,7 @@ public static interface EventOpenGui extends EventBase {

public static GuiScreen fireOpenGuiEvent(GuiScreen gui) {
Common.LOGGER.trace(Common.Event, "Firing OpenGuiEvent");
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventOpenGui) {
EventOpenGui event = (EventOpenGui) eventListener;
GuiScreen newGui = event.onOpenGui(gui);
Expand All @@ -53,7 +54,7 @@ public static interface EventLaunchIntegratedServer extends EventBase {

public static void fireOnLaunchIntegratedServer() {
Common.LOGGER.trace(Common.Event, "Firing LaunchIntegratedServer");
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventLaunchIntegratedServer) {
EventLaunchIntegratedServer event = (EventLaunchIntegratedServer) eventListener;
event.onLaunchIntegratedServer();
Expand All @@ -76,7 +77,7 @@ public static interface EventDoneLoadingWorld extends EventBase {

public static void fireOnDoneLoadingWorld() {
Common.LOGGER.trace(Common.Event, "Firing DoneLoadingWorld");
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventDoneLoadingWorld) {
EventDoneLoadingWorld event = (EventDoneLoadingWorld) eventListener;
event.onDoneLoadingWorld();
Expand All @@ -99,7 +100,7 @@ public static interface EventClientTick extends EventBase {
public void onClientTick(Minecraft mc);

public static void fireOnClientTick(Minecraft mc) {
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventClientTick) {
EventClientTick event = (EventClientTick) eventListener;
event.onClientTick(mc);
Expand All @@ -123,7 +124,7 @@ public static interface EventClientInit extends EventBase {

public static void fireOnClientInit(Minecraft mc) {
Common.LOGGER.trace(Common.Event, "Firing ClientInit");
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventClientInit) {
EventClientInit event = (EventClientInit) eventListener;
event.onClientInit(mc);
Expand All @@ -146,7 +147,7 @@ public static interface EventClientGameLoop extends EventBase {
public void onRunClientGameLoop(Minecraft mc);

public static void fireOnClientGameLoop(Minecraft mc) {
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventClientGameLoop) {
EventClientGameLoop event = (EventClientGameLoop) eventListener;
event.onRunClientGameLoop(mc);
Expand All @@ -170,7 +171,7 @@ public static interface EventCamera extends EventBase {
public CameraData onCameraEvent(CameraData dataIn);

public static CameraData fireCameraEvent(CameraData dataIn) {
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventCamera) {
EventCamera event = (EventCamera) eventListener;
CameraData data = event.onCameraEvent(dataIn);
Expand Down Expand Up @@ -223,7 +224,7 @@ public static interface EventPlayerLeaveClientSide extends EventBase {

public static void firePlayerLeaveClientSide(EntityPlayerSP player) {
Common.LOGGER.trace(Common.Event, "Firing PlayerLeaveClientSideEvent");
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventPlayerLeaveClientSide) {
EventPlayerLeaveClientSide event = (EventPlayerLeaveClientSide) eventListener;
event.onPlayerLeaveClientSide(player);
Expand All @@ -247,7 +248,7 @@ public static interface EventPlayerJoinedClientSide extends EventBase {

public static void firePlayerJoinedClientSide(EntityPlayerSP player) {
Common.LOGGER.trace(Common.Event, "Firing PlayerJoinedClientSide");
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventPlayerJoinedClientSide) {
EventPlayerJoinedClientSide event = (EventPlayerJoinedClientSide) eventListener;
event.onPlayerJoinedClientSide(player);
Expand All @@ -264,21 +265,44 @@ public static void firePlayerJoinedClientSide(EntityPlayerSP player) {
*/
public static interface EventOtherPlayerJoinedClientSide extends EventBase {

public void onOtherPlayerJoinedClientSide(GameProfile profile);

/**
* Fired when a different player other than yourself joins a server or a world
* @param player The game profile of the player that joins the server or the world
*/
public void onOtherPlayerJoinedClientSide(GameProfile profile);


public static void fireOtherPlayerJoinedClientSide(GameProfile profile) {
Common.LOGGER.trace(Common.Event, "Firing OtherPlayerJoinedClientSide");
for (EventBase eventListener : EventListener.getEventListeners()) {
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventOtherPlayerJoinedClientSide) {
EventOtherPlayerJoinedClientSide event = (EventOtherPlayerJoinedClientSide) eventListener;
event.onOtherPlayerJoinedClientSide(profile);
}
}
}


}

/**
* Fired when the connection to the custom server was closed on the client side.
*/
public static interface EventDisconnectClient extends EventBase {

/**
* Fired when the connection to the custom server was closed on the client side.
* @param client The client that is disconnecting
*/
public void onDisconnectClient(Client client);

public static void fireDisconnectClient(Client client) {
Common.LOGGER.trace(Common.Event, "Firing EventDisconnectClient");
for (EventBase eventListener : EventListenerRegistry.getEventListeners()) {
if(eventListener instanceof EventDisconnectClient) {
EventDisconnectClient event = (EventDisconnectClient) eventListener;
event.onDisconnectClient(client);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

import java.util.ArrayList;

public class EventListener {
public class EventListenerRegistry {

private static ArrayList<EventBase> EVENTLISTENER_REGISTRY = new ArrayList<>();


public static void register(EventBase eventListener) {
if (eventListener == null) {
throw new NullPointerException("Tried to register a packethandler with value null");
}
EVENTLISTENER_REGISTRY.add(eventListener);
}

public static void unregister(EventBase eventListener) {
if (eventListener == null) {
throw new NullPointerException("Tried to unregister a packethandler with value null");
}
EVENTLISTENER_REGISTRY.remove(eventListener);
}

Expand Down
Loading