-
Notifications
You must be signed in to change notification settings - Fork 0
Node.JS & Deno Edition
In your script add this with NPM installed
npm Command:
npm install https://github.com/Creadores-Program/ServerWebGamePost/releases/download/1.2.1/ServerWebGamePost-1.2.0.Nodejs.Edition.tgzpackage.json:
"dependencies":{
"ServerWebGamePost": "1.2.0"
}Script:
const ServerWebGamePost = requiere("ServerWebGamePost");deno.json:
{
"nodeModulesDir": true
}Script:
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const ServerWebGamePost = require("ServerWebGamePost");You need to create a callback function. Something like that:
function processDatapacks(datapack){
//datapack = json
}You can use the sendDatapacket function of the Server class:
//server = ServerWebGamePost.Server Instance
server.sendDataPacket(datapack.identifier, {
key: "data..."
});
//first argument = String(client identifier), Second argument = json(Datapacket)You can ban IPs with the banIp and unbanIp functions in ServerWebGamePost.Server 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 ServerWebGamePost.Server class only accept one string argument.
You must create a new ServerWebGamePost.Server instance
var Server = new ServerWebGamePost.Server(port, imgSrc, procecerDatapacks);
// port = Number(port where the server will open), imgSrc String (Server icon directory can be null), procecerDatapacks function(Callback for handling data packets)If you want to implement HTTPS just use the http API
Get the http server:
//server = ServerWebGamePost.Server instance
server.getHttpServer();just run the stop function in the Server class
Same as the server
function processDatapacks(datapack){
//datapack = json
}Simply in the ServerWebGamePost.Client class Execute the sendDatapacket function
Something like that:
//client = ServerWebGamePost.Client
client.sendDatapacket(packet);
//packet = json
// Remember to also send the identifier keyYou must create a new ServerWebGamePost.Client instance
var client = new ServerWebGamePost.Client(domain, port, isHttps);
// domain = String (server domain or IP)
// port = Number (Server port)
// isHttps= boolean (whether the server has HTTPS encryption or not)
client.processDatapacks = callback;
//callback = function(Callback in charge of handling data packets )