Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
asd
node_modules
package-lock.json
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"watch": "tsc --watch"
},
"devDependencies": {
"@types/node": "^18.14.2"
}
}
154 changes: 154 additions & 0 deletions scripts/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateFishPlayer = exports.getCreateFishPlayer = exports.getStopped = exports.free = exports.addStopped = void 0;
var config_1 = require("./config");
// Add a player's uuid to the stopped api
function addStopped(uuid) {
var req = Http.post("http://".concat(config_1.ip, ":5000/api/addStopped"), JSON.stringify({ id: uuid }))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;
try {
req.submit(function (response, exception) {
//Log.info(response.getResultAsString());
if (exception || !response) {
Log.info('\n\nStopped API encountered an error while trying to add a stopped player.\n\n');
}
});
}
catch (e) {
Log.info('\n\nStopped API encountered an error while trying to add a stopped player.\n\n');
}
}
exports.addStopped = addStopped;
;
// Remove a player's uuid from the stopped api
function free(uuid) {
var req = Http.post("http://".concat(config_1.ip, ":5000/api/free"), JSON.stringify({ id: uuid }))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;
try {
req.submit(function (response, exception) {
//Log.info(response.getResultAsString());
if (exception || !response) {
Log.info('\n\nStopped API encountered an error while trying to free a stopped player.\n\n');
}
});
}
catch (e) {
Log.info('\n\nStopped API encountered an error while trying to free a stopped player.\n\n');
}
}
exports.free = free;
;
// Check if player is stopped from API
function getStopped(uuid, callback) {
var req = Http.post("http://".concat(config_1.ip, ":5000/api/getStopped"), JSON.stringify({ id: uuid }))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;
try {
req.submit(function (response, exception) {
if (exception || !response) {
Log.info('\n\nStopped API encountered an error while trying to retrieve stopped players.\n\n');
}
else {
var temp = response.getResultAsString();
if (!temp.length)
return false;
callback(JSON.parse(temp).data);
}
});
}
catch (e) {
Log.info('\n\nStopped API encountered an error while trying to retrieve stopped players.\n\n');
}
}
exports.getStopped = getStopped;
;
// Get the saved fishPlayer from the api, which will save the player if it doesn't exist
function getCreateFishPlayer(fishPlayer, callback) {
// omit the mindustry player object from the api call
var player = fishPlayer.player, rest = __rest(fishPlayer, ["player"]);
var req = Http.post("http://".concat(config_1.ip, ":5000/api/getCreateFishPlayer"), JSON.stringify(__assign({}, rest)))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;
try {
req.submit(function (response, exception) {
if (exception || !response) {
var temp = response === null || response === void 0 ? void 0 : response.getResultAsString();
if (!temp.length)
return false;
var parsedReponseError = JSON.parse(response).error;
Log.info("\n\n".concat(parsedReponseError !== null && parsedReponseError !== void 0 ? parsedReponseError : 'Stopped API encountered an error while trying to fetch a player.', "\n\n"));
}
else {
var temp = response.getResultAsString();
if (!temp.length)
return false;
callback(JSON.parse(temp).data);
}
});
}
catch (e) {
Log.info('\n\nStopped API encountered an error while trying to fetch a player.\n\n');
}
}
exports.getCreateFishPlayer = getCreateFishPlayer;
;
// Update fishPlayer data on the api
function updateFishPlayer(fishPlayer, callback) {
// omit the mindustry player object from the api call
var player = fishPlayer.player, rest = __rest(fishPlayer, ["player"]);
var req = Http.post("http://".concat(config_1.ip, ":5000/api/updateFishPlayer"), JSON.stringify(__assign({}, rest)))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;
try {
req.submit(function (response, exception) {
// Log.info(response.getResultAsString());
if (exception || !response) {
var temp = response === null || response === void 0 ? void 0 : response.getResultAsString();
if (!temp.length)
return false;
var parsedReponseError = JSON.parse(response).error;
Log.info("\n\n".concat(parsedReponseError !== null && parsedReponseError !== void 0 ? parsedReponseError : 'Stopped API encountered an error while trying to update a player.', "\n\n"));
}
else {
var temp = response.getResultAsString();
if (!temp.length)
return false;
callback(JSON.parse(temp).status);
}
});
}
catch (e) {
Log.info('\n\nStopped API encountered an error while trying to fetch a player.\n\n');
}
}
exports.updateFishPlayer = updateFishPlayer;
;
119 changes: 119 additions & 0 deletions scripts/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { ip } from "./config";
import { FishPlayer } from "./players";

// Add a player's uuid to the stopped api
export function addStopped(uuid:string){
const req = Http.post(`http://${ip}:5000/api/addStopped`, JSON.stringify({ id: uuid }))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;

try {
req.submit((response, exception) => {
//Log.info(response.getResultAsString());
if(exception || !response){
Log.info('\n\nStopped API encountered an error while trying to add a stopped player.\n\n');
}
});
} catch(e){
Log.info('\n\nStopped API encountered an error while trying to add a stopped player.\n\n');
}
};

// Remove a player's uuid from the stopped api
export function free(uuid:string){
const req = Http.post(`http://${ip}:5000/api/free`, JSON.stringify({ id: uuid }))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;

try {
req.submit((response, exception) => {
//Log.info(response.getResultAsString());
if(exception || !response){
Log.info('\n\nStopped API encountered an error while trying to free a stopped player.\n\n');
}
});
} catch(e){
Log.info('\n\nStopped API encountered an error while trying to free a stopped player.\n\n');
}
};

// Check if player is stopped from API
export function getStopped(uuid:string, callback:(stopped:boolean) => unknown){
const req = Http.post(`http://${ip}:5000/api/getStopped`, JSON.stringify({ id: uuid }))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;

try {
req.submit((response, exception) => {
if(exception || !response){
Log.info(
'\n\nStopped API encountered an error while trying to retrieve stopped players.\n\n'
);
} else {
let temp = response.getResultAsString();
if(!temp.length) return false;
callback(JSON.parse(temp).data);
}
});
} catch(e){
Log.info('\n\nStopped API encountered an error while trying to retrieve stopped players.\n\n');
}
};

// Get the saved fishPlayer from the api, which will save the player if it doesn't exist
export function getCreateFishPlayer(fishPlayer: FishPlayer, callback: (returnedFishPlayer: FishPlayer) => unknown){
// omit the mindustry player object from the api call
const { player, ...rest} = fishPlayer;
const req = Http.post(`http://${ip}:5000/api/getCreateFishPlayer`, JSON.stringify({...rest}))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;

try {
req.submit((response, exception) => {
if(exception || !response){
let temp = response?.getResultAsString();
if(!temp.length) return false;
const parsedReponseError = JSON.parse(response).error
Log.info(`\n\n${parsedReponseError ?? 'Stopped API encountered an error while trying to fetch a player.'}\n\n`);
} else {
let temp = response.getResultAsString();
if(!temp.length) return false;
callback(JSON.parse(temp).data);
}
});
} catch(e){
Log.info('\n\nStopped API encountered an error while trying to fetch a player.\n\n');
}
};

// Update fishPlayer data on the api
export function updateFishPlayer(fishPlayer: FishPlayer, callback: (status: string) => unknown){
// omit the mindustry player object from the api call
const { player, ...rest} = fishPlayer;
const req = Http.post(`http://${ip}:5000/api/updateFishPlayer`, JSON.stringify({...rest}))
.header('Content-Type', 'application/json')
.header('Accept', '*/*');
req.timeout = 10000;

try {
req.submit((response, exception) => {
// Log.info(response.getResultAsString());
if(exception || !response){
let temp = response?.getResultAsString();
if(!temp.length) return false;
const parsedReponseError = JSON.parse(response).error
Log.info(`\n\n${parsedReponseError ?? 'Stopped API encountered an error while trying to update a player.'}\n\n`);
} else {
let temp = response.getResultAsString();
if(!temp.length) return false;
callback(JSON.parse(temp).status);
}
});
} catch(e){
Log.info('\n\nStopped API encountered an error while trying to fetch a player.\n\n');
}
};
Loading