Updated to latest Protocol Version
This commit is contained in:
@@ -64,11 +64,10 @@ public class Main {
|
||||
|
||||
protocolBridge = new ProtocolBridge(new WebServer(
|
||||
new File("auth.ini"), new File("rules.ini"),
|
||||
tcpPort, udpPort,
|
||||
sessionExpire, maxUpload),
|
||||
values, ProtocolVersion.PV_1_0_0_BETA, new File("logs"));
|
||||
|
||||
protocolBridge.getProtocolServer().getNetwork().start();
|
||||
protocolBridge.getProtocolServer().getNetwork().start(tcpPort, udpPort);
|
||||
|
||||
commandManager = new CommandManager(values.eventManager);
|
||||
commandManager.registerCommand(StopCommand.class);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.openautonomousconnection.webserver;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.Transport;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.TransportProtocol;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket;
|
||||
@@ -8,7 +8,7 @@ import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponse
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamChunkPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamEndPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamStartPacket;
|
||||
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
|
||||
import org.openautonomousconnection.protocol.side.server.CustomConnectedClient;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.protocol.side.web.managers.RuleManager;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
@@ -32,12 +32,10 @@ public final class WebServer extends ProtocolWebServer {
|
||||
public WebServer(
|
||||
File authFile,
|
||||
File rulesFile,
|
||||
int tcpPort,
|
||||
int udpPort,
|
||||
int sessionExpire,
|
||||
int maxUpload
|
||||
) throws Exception {
|
||||
super(authFile, rulesFile, tcpPort, udpPort, sessionExpire, maxUpload);
|
||||
super(authFile, rulesFile,sessionExpire, maxUpload);
|
||||
|
||||
// NOTE: Values chosen as safe defaults.
|
||||
// move them to Main and pass them in here (no hidden assumptions).
|
||||
@@ -49,7 +47,7 @@ public final class WebServer extends ProtocolWebServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponsePacket onWebRequest(ConnectedWebClient client, WebRequestPacket request) {
|
||||
public WebResponsePacket onWebRequest(CustomConnectedClient client, WebRequestPacket request) {
|
||||
try {
|
||||
String path = request.getPath() == null ? "/" : request.getPath();
|
||||
|
||||
@@ -75,7 +73,7 @@ public final class WebServer extends ProtocolWebServer {
|
||||
}
|
||||
}
|
||||
|
||||
private WebResponsePacket serveFile(ConnectedWebClient client, String path) throws Exception {
|
||||
private WebResponsePacket serveFile(CustomConnectedClient client, String path) throws Exception {
|
||||
if (path.startsWith("/")) path = path.substring(1);
|
||||
if (path.isEmpty()) path = "index.html";
|
||||
|
||||
@@ -97,10 +95,10 @@ public final class WebServer extends ProtocolWebServer {
|
||||
return new WebResponsePacket(200, contentType, Map.of(), data);
|
||||
}
|
||||
|
||||
private void streamFile(ConnectedWebClient client, File file, String contentType) throws IOException, ClassNotFoundException {
|
||||
private void streamFile(CustomConnectedClient client, File file, String contentType) throws IOException, ClassNotFoundException {
|
||||
long total = file.length();
|
||||
|
||||
client.getConnection().sendPacket(new WebStreamStartPacket(200, contentType, Map.of("name", file.getName()), total), Transport.TCP);
|
||||
client.getConnection().sendPacket(new WebStreamStartPacket(200, contentType, Map.of("name", file.getName()), total), TransportProtocol.TCP);
|
||||
|
||||
try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
|
||||
byte[] buf = new byte[STREAM_CHUNK_SIZE];
|
||||
@@ -110,11 +108,11 @@ public final class WebServer extends ProtocolWebServer {
|
||||
byte[] chunk = (r == buf.length) ? buf : Arrays.copyOf(buf, r);
|
||||
client.getConnection().sendPacket(
|
||||
new WebStreamChunkPacket(seq++, chunk),
|
||||
ContentTypeResolver.isVideoFile(file.getName()) ? Transport.UDP : Transport.TCP
|
||||
ContentTypeResolver.isVideoFile(file.getName()) ? TransportProtocol.UDP : TransportProtocol.TCP
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
client.getConnection().sendPacket(new WebStreamEndPacket(true), Transport.TCP);
|
||||
client.getConnection().sendPacket(new WebStreamEndPacket(true), TransportProtocol.TCP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.openautonomousconnection.webserver.api;
|
||||
|
||||
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
|
||||
import org.openautonomousconnection.protocol.side.server.CustomConnectedClient;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.protocol.side.web.managers.SessionManager;
|
||||
|
||||
@@ -23,14 +23,14 @@ public final class SessionContext {
|
||||
this.valid = valid;
|
||||
}
|
||||
|
||||
public static SessionContext from(ConnectedWebClient client, ProtocolWebServer server, Map<String, String> headers) throws IOException {
|
||||
public static SessionContext from(CustomConnectedClient client, ProtocolWebServer server, Map<String, String> headers) throws IOException {
|
||||
if (headers == null) return new SessionContext(null, null, false);
|
||||
|
||||
String sessionId = headers.get("session");
|
||||
if (sessionId == null) return new SessionContext(null, null, false);
|
||||
|
||||
String ip = (client.getConnection().getSocket() != null && client.getConnection().getSocket().getInetAddress() != null)
|
||||
? client.getConnection().getSocket().getInetAddress().getHostAddress() : "";
|
||||
String ip = (client.getConnection().getTcpSocket() != null && client.getConnection().getTcpSocket().getInetAddress() != null)
|
||||
? client.getConnection().getTcpSocket().getInetAddress().getHostAddress() : "";
|
||||
|
||||
String userAgent = headers.getOrDefault("user-agent", "");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.openautonomousconnection.webserver.api;
|
||||
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket;
|
||||
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
|
||||
import org.openautonomousconnection.protocol.side.server.CustomConnectedClient;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.webserver.utils.WebHasher;
|
||||
import org.openautonomousconnection.webserver.utils.RequestParams;
|
||||
@@ -11,14 +11,14 @@ import org.openautonomousconnection.webserver.utils.RequestParams;
|
||||
*/
|
||||
public final class WebPageContext {
|
||||
|
||||
public final ConnectedWebClient client;
|
||||
public final CustomConnectedClient client;
|
||||
public final WebRequestPacket request;
|
||||
public final SessionContext session;
|
||||
public final RequestParams params;
|
||||
public final WebHasher hasher;
|
||||
|
||||
public WebPageContext(
|
||||
ConnectedWebClient client,
|
||||
CustomConnectedClient client,
|
||||
ProtocolWebServer server,
|
||||
WebRequestPacket request,
|
||||
RequestParams params,
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.openautonomousconnection.webserver.runtime;
|
||||
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
|
||||
import org.openautonomousconnection.protocol.side.server.CustomConnectedClient;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.webserver.WebServer;
|
||||
import org.openautonomousconnection.webserver.api.WebPage;
|
||||
@@ -24,7 +24,7 @@ public final class JavaPageDispatcher {
|
||||
private JavaPageDispatcher() {}
|
||||
|
||||
public static WebResponsePacket dispatch(
|
||||
ConnectedWebClient client,
|
||||
CustomConnectedClient client,
|
||||
ProtocolWebServer server,
|
||||
WebRequestPacket request
|
||||
) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user