Skip to content

Node.JS & Deno Edition

Trollhunters501PC edited this page Dec 16, 2024 · 6 revisions

NPM

In your script add this with NPM installed

npm Command:

npm install https://github.com/Creadores-Program/ServerWebGamePost/releases/download/1.1.1/ServerWebGamePost-1.1.1.Nodejs.Edition.tgz

Node.js

package.json:

"dependencies":{
  "ServerWebGamePost": "1.1.1"
}

Script:

const ServerWebGamePost = requiere("ServerWebGamePost");

Deno:

deno.json:

{
  "nodeModulesDir": true
}

Script:

import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const ServerWebGamePost = require("ServerWebGamePost");

Create Server

Processing Datapackets

You need to create a callback function. Something like that:

function processDatapacks(datapack){
//datapack = json
}

Send Datapackets

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)

Create Instance

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)

Implement HTTPS encryption

If you want to implement HTTPS just use the http API

Get the http server:

//server = ServerWebGamePost.Server instance
server.getHttpServer();

Stop server

just run the stop function in the Server class

Create Client

Processing Datapackets

Same as the server

function processDatapacks(datapack){
//datapack = json
}

Send Datapackets

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 key

Create Instance

You 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 )