The guide contains all the code templates that were previously given out for Guardian.
Please note: These code templates have only been released as support is no longer provided for discontinued products.
Java:
public void onEnable() {
License license = new License(new URI("http://127.0.2.1:25565/api/client"),"<license>", "Vitality", "1.0", "apikeyhere", "<hwid>");
if (!license.check()) return;
}
Java:
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.http.HttpEntity;
@RequiredArgsConstructor
@Getter
public class License {
private final URI host;
private final String licenseKey;
private final String product;
private final String version;
private final String apiKey;
private final String hwid;
private int statusCode;
private String discordName;
private String discordID;
private String statusMsg;
public boolean check() {
HttpPost post = new HttpPost(host);
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair("licensekey", licenseKey));
urlParameters.add(new BasicNameValuePair("product", product));
urlParameters.add(new BasicNameValuePair("version", version));
urlParameters.add(new BasicNameValuePair("hwid", hwid));
try {
post.setEntity(new UrlEncodedFormEntity(urlParameters));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
post.setHeader("Authorization", apiKey);
try (CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = httpClient.execute(post)) {
String data = EntityUtils.toString(response.getEntity());
JSONObject obj = new JSONObject(data);
if(!obj.has("status_msg") || !obj.has("status_id")) {
return false;
}
statusCode = obj.getInt("status_code");
statusMsg = obj.getString("status_msg");
if(obj.getString("status_overview") == null){
return false;
}
Java:
</dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
JavaScript:
const { Client, Collection, MessageEmbed } = require("discord.js");
const fs = require("fs");
const yaml = require("js-yaml");
const http = require("http");
const url = require("url");
const uuid = require('uuid');
const License = require("./License"); // Import the License class from License.js
const client = new Client({
intents: 32767,
});
module.exports = client;
process.on('unhandledRejection', error => {
console.error(error);
});
client.on('shardError', error => {
console.error(error);
});
client.commands = new Collection();
client.config = yaml.load(fs.readFileSync("settings/config.yml", "utf8"), 4);
client.embeds = yaml.load(fs.readFileSync("settings/embeds.yml", "utf8"), 4);
client.buttons = yaml.load(fs.readFileSync("settings/buttons.yml", "utf8"), 4);
client.messages = yaml.load(fs.readFileSync("settings/messages.yml", "utf8"), 4);
// Ensure that 'client' is fully initialized before loading the handler
client.once('ready', () => {
require("./handler")(client);
let isLicenseValid = false; // Track the license validity
// Function to authenticate the license and login the client
async function authenticateLicense() {
const licenseKey = client.config.LICENSE_KEY; // Get the license key from the configuration file
if (!licenseKey || licenseKey === "ENTER-YOUR-LICENSE-KEY-HERE") {
console.error(`░██████╗░██╗░░░██╗░█████╗░██████╗░██████╗░██╗░█████╗░███╗░░██╗ ██╗░░░██╗██████╗░░░░░█████╗░.`);
console.error(`██╔════╝░██║░░░██║██╔══██╗██╔══██╗██╔══██╗██║██╔══██╗████╗░██║ ██║░░░██║╚════██╗░░░██╔══██╗`);
console.error(`██║░░██╗░██║░░░██║███████║██████╔╝██║░░██║██║███████║██╔██╗██║ ╚██╗░██╔╝░░███╔═╝░░░██║░░██║`);
console.error(`██║░░╚██╗██║░░░██║██╔══██║██╔══██╗██║░░██║██║██╔══██║██║╚████║ ░╚████╔╝░██╔══╝░░░░░██║░░██║`);
console.error(`╚██████╔╝╚██████╔╝██║░░██║██║░░██║██████╔╝██║██║░░██║██║░╚███║ ░░╚██╔╝░░███████╗██╗╚█████╔╝`);
console.error(`░╚═════╝░░╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝ ░░░╚═╝░░░╚══════╝╚═╝░╚════╝░`);
console.error(`You have not entered your license key, Please visit the settings/config.yml and enter your license to continue.`);
process.exit(1);
}
try {
const license = new License(
new URL("http://5.9.117.55:5035/api/client"),
licenseKey,
"Guardian",
"2.0",
"J7kP3mR9sT2wE5xY8zA1",
);
const isValid = await license.check();
if (!isValid) {
if (isLicenseValid) {
console.error("░██████╗░██╗░░░██╗░█████╗░██████╗░██████╗░██╗░█████╗░███╗░░██╗ ██╗░░░██╗██████╗░░░░░█████╗░.");
console.error("██╔════╝░██║░░░██║██╔══██╗██╔══██╗██╔══██╗██║██╔══██╗████╗░██║ ██║░░░██║╚════██╗░░░██╔══██╗");
console.error("██║░░██╗░██║░░░██║███████║██████╔╝██║░░██║██║███████║██╔██╗██║ ╚██╗░██╔╝░░███╔═╝░░░██║░░██║");
console.error("██║░░╚██╗██║░░░██║██╔══██║██╔══██╗██║░░██║██║██╔══██║██║╚████║ ░╚████╔╝░██╔══╝░░░░░██║░░██║");
console.error("╚██████╔╝╚██████╔╝██║░░██║██║░░██║██████╔╝██║██║░░██║██║░╚███║ ░░╚██╔╝░░███████╗██╗╚█████╔╝");
console.error("░╚═════╝░░╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝ ░░░╚═╝░░░╚══════╝╚═╝░╚════╝░");
console.error("Failed to authenticate license, Please visit the Vifez Discord to have your license reset.");
process.exit(1);
}
} else {
if (!isLicenseValid) {
console.log("░██████╗░██╗░░░██╗░█████╗░██████╗░██████╗░██╗░█████╗░███╗░░██╗ ██╗░░░██╗██████╗░░░░░█████╗░.");
console.log("██╔════╝░██║░░░██║██╔══██╗██╔══██╗██╔══██╗██║██╔══██╗████╗░██║ ██║░░░██║╚════██╗░░░██╔══██╗");
console.log("██║░░██╗░██║░░░██║███████║██████╔╝██║░░██║██║███████║██╔██╗██║ ╚██╗░██╔╝░░███╔═╝░░░██║░░██║");
console.log("██║░░╚██╗██║░░░██║██╔══██║██╔══██╗██║░░██║██║██╔══██║██║╚████║ ░╚████╔╝░██╔══╝░░░░░██║░░██║");
console.log("╚██████╔╝╚██████╔╝██║░░██║██║░░██║██████╔╝██║██║░░██║██║░╚███║ ░░╚██╔╝░░███████╗██╗╚█████╔╝");
console.log("░╚═════╝░░╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝ ░░░╚═╝░░░╚══════╝╚═╝░╚════╝░");
console.log("License Successfully Authenticated");
}
isLicenseValid = true;
}
if (isLicenseValid) {
// License is valid, login the client
client.login(client.config.TOKEN);
} else {
console.error("░██████╗░██╗░░░██╗░█████╗░██████╗░██████╗░██╗░█████╗░███╗░░██╗ ██╗░░░██╗██████╗░░░░░█████╗░.");
console.error("██╔════╝░██║░░░██║██╔══██╗██╔══██╗██╔══██╗██║██╔══██╗████╗░██║ ██║░░░██║╚════██╗░░░██╔══██╗");
console.error("██║░░██╗░██║░░░██║███████║██████╔╝██║░░██║██║███████║██╔██╗██║ ╚██╗░██╔╝░░███╔═╝░░░██║░░██║");
console.error("██║░░╚██╗██║░░░██║██╔══██║██╔══██╗██║░░██║██║██╔══██║██║╚████║ ░╚████╔╝░██╔══╝░░░░░██║░░██║");
console.error("╚██████╔╝╚██████╔╝██║░░██║██║░░██║██████╔╝██║██║░░██║██║░╚███║ ░░╚██╔╝░░███████╗██╗╚█████╔╝");
console.error("░╚═════╝░░╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝ ░░░╚═╝░░░╚══════╝╚═╝░╚════╝░");
console.error("Failed to authenticate license, Please visit the Vifez Discord to have your license reset.");
process.exit(1);
}
} catch (error) {
console.error("Failed to authenticate license:", error);
process.exit(1);
}
}
// Authenticate the license and login the client on bot startup
authenticateLicense();
// Check license validity every 30 seconds
setInterval(authenticateLicense, 30 * 1000);
});
// Log in to Discord
client.login(client.config.TOKEN);
JavaScript:
// License authentication
const url = require('url');
const http = require('http');
class License {
constructor(host, licenseKey, product, version, apiKey, hwid) {
this.host = host;
this.licenseKey = licenseKey;
this.product = product;
this.version = version;
this.apiKey = apiKey;
this.hwid = hwid;
this.statusCode = 0;
this.discordName = '';
this.discordID = '';
this.statusMsg = '';
}
async check() {
const urlParameters = new url.URLSearchParams();
urlParameters.append('licensekey', this.licenseKey);
urlParameters.append('product', this.product);
urlParameters.append('version', this.version);
urlParameters.append('hwid', this.hwid);
const options = {
method: 'POST',
headers: {
'Authorization': this.apiKey,
'Content-Type': 'application/x-www-form-urlencoded',
},
};
try {
const response = await new Promise((resolve, reject) => {
const req = http.request(this.host, options, resolve);
req.on('error', reject);
req.write(urlParameters.toString());
req.end();
});
const data = await new Promise((resolve, reject) => {
let responseData = '';
response.on('data', chunk => (responseData += chunk));
response.on('end', () => resolve(responseData));
response.on('error', reject);
});
const { status_code, status_msg, clientname, discord_id } = JSON.parse(data);
if (typeof status_code === 'undefined' || typeof status_msg === 'undefined') {
return false;
}
this.statusCode = Number(status_code);
this.statusMsg = status_msg;
if (typeof clientname === 'undefined' || typeof discord_id === 'undefined') {
return false;
}
this.discordName = clientname;
this.discordID = discord_id;
return true;
} catch (error) {
console.error('Failed to check license:', error);
return false;
}
}
}
module.exports = License;
Please note: These code templates have only been released as support is no longer provided for discontinued products.