-
Notifications
You must be signed in to change notification settings - Fork 0
Java Edition
In maven you must add the following repository:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
I in dependencies:
<dependency>
<groupId>com.github.Creadores-Program</groupId>
<artifactId>ServerWebGamePost</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.creadoresprogram</groupId>
<artifactId>ServerWebGamePost</artifactId>
<version>1.2.1</version>
</dependency>
First you need to extend the org.CreadoresProgram.ServerWebGamePost.server.ProcessDatapackServer class
And to process the datapackets that the client sends you must implement Override to the processDatapack function
Something like that:
@Override
public void processDatapack(JSONObject datapack){
//code...
//JSONObject= com.alibaba.fastjson2.JSONObject
//this.server = org.CreadoresProgram.ServerWebGamePost.server.ServerWebGamePostServer instance
}
Simply in the org.CreadoresProgram.ServerWebGamePost.server.ServerWebGamePostServer class Execute the sendDataPacket function
Something like that:
//ServerWebGamePostServer = server
server.sendDataPacket(identifier, json); //identifier you must obtain from the datapacket that the client gives in its datapacket (it is a String) json Is com.alibaba.fastjson2.JSONObject
You can ban IPs with the banIp and unbanIp functions in ServerWebGamePostServer class (The IP is String and is only that argument)
If you never run filter origins the origin header will be "*" if you run it it will only accept the given origins (Origin Header) The functions addFilterOrigin and removeFilterOrigin in ServerWebGamePostServer class only accept one string argument.
You must create a new org.CreadoresProgram.ServerWebGamePost.server.ServerWebGamePostServer instance
ServerWebGamePostServer server = new ServerWebGamePostServer(port, imgSrc, procecerDatapacks);
// port = int(Here you must specify the port where the server opens), imgSrc = String (Directory in string of the server icon type image can be null), procecerDatapacks = ProcessDatapackServer (Datapacket handling instance class)
If you want to implement HTTPS just use the Spark java API
Get the spark service:
//ServerWebGamePostServer = server
server.getSparkServer();
just run the stop function in the Server class
First you need to extend the org.CreadoresProgram.ServerWebGamePost.client.ProcessDatapackClient class
And to process the datapackets that the server sends you must implement Override to the processDatapack function
Something like that:
@Override
public void processDatapack(JSONObject datapack){
//code...
//JSONObject= com.alibaba.fastjson2.JSONObject
//this.server = org.CreadoresProgram.ServerWebGamePost.client.ServerWebGamePostClient instance
}
Simply in the org.CreadoresProgram.ServerWebGamePost.client.ServerWebGamePostClient class Execute the sendDataPacket function
Something like that:
//ServerWebGamePostClient = client
client.sendDataPacket(json); //Remember to add the identifier key to the json (it is a String) json Is com.alibaba.fastjson2.JSONObject
You must create a new org.CreadoresProgram.ServerWebGamePost.client.ServerWebGamePostClient instance
ServerWebGamePostClient client = new ServerWebGamePostClient(domain, port, isHttps);
// domain = String(server domain or ip), port = int(Here you must specify the port where the server), isHttps = boolean(Find out if the server has HTTPS encryption or not)
ProcessDatapackClient procecerDatapacks = new ProcessDatapackClient(client);//your class extends
client.setProcessDatapacks(procecerDatapacks);
//procecerDatapacks = ProcessDatapackClient (Datapacket handling instance class)