- Production (MySQL)
bun production
- Development (Sqlite)
bun development
- Production (MySQL)
bun setup
- Development (Sqlite)
bun setup-sqlite
bun test
bun create-config
bun docker
bun stop-docker
Important
The below environment variables are required
Location: /.env.production
DATABASE_HOST
DATABASE_USER
DATABASE_PASSWORD
DATABASE_NAME
EMAIL_USER
EMAIL_PASSWORD
EMAIL_SERVICE
EMAIL_TEST
SQL_SSL_MODE DISABLED | ENABLED
DATABASE_ENGINE sqlite | mysql
WEBSRV_PORT
WEBSRV_PORTSSL
WEBSRV_USESSL
WEBSRV_USECERT
GOOGLE_TRANSLATE_API_KEY
WEB_SOCKET_URL
ASSET_PATH
DOMAIN
GAME_NAME
DATABASE_PORT
declare interface Identity {
id: string;
useragent: string;
}
const PacketTypes: PacketType = {
0: "PING",
1: "PONG",
2: "CONNECTION_COUNT",
3: "RATE_LIMITED",
4: "LOGIN",
5: "LOGIN_SUCCESS",
6: "LOGIN_FAILED",
7: "LOAD_MAP",
8: "TIME_SYNC",
9: "MOVEXY",
10: "AUTH",
11: "LOGOUT",
12: "DISCONNECT",
13: "SPAWN_PLAYER",
14: "LOAD_PLAYERS",
15: "DISCONNECT_PLAYER",
16: "INVENTORY",
17: "CHAT",
18: "STATS",
19: "CLIENTCONFIG",
20: "REGISTER",
21: "TELEPORTXY",
22: "SELECTPLAYER",
23: "BENCHMARK",
24: "STEALTH",
25: "ATTACK",
26: "PROJECTILEXY",
27: "REVIVE",
28: "UPDATESTATS",
29: "TARGETCLOSEST",
30: "AUDIO",
};
declare interface Packet {
type: PacketType;
data: PacketData;
id: string | null;
useragent: string | null;
}
const RateLimitOptions: RateLimitOptions = {
maxRequests: 2000,
time: 2000,
maxWindowTime: 1000,
};
declare interface RateLimitOptions {
maxRequests: number;
time: number;
maxWindowTime: number;
}
import cache from '../services/cache'; // Main player cache
import assetCache from '../services/assetCache'; // Asset caching
Adds an item to the cache
Adds a nested item to the cache
Fetches an item from the cache
Removes an item from the cache
Clears the cache
Fetches all items from the cache
Updates an item in cache
Updates a nested item in cache
import { Events } from "../socket/server";
Returns the amount of clients that are currently connected
Returns a list that contains client connection data
Broadcasts a message to all connected clients
Returns a list that contains client request data
Returns a list of rate limited clients
Fires immediately after the server starts
Listener.on("onAwake", (data) => {
console.log("Awake event emitted");
});
Fires immediately after onAwake
Listener.on("onStart", (data) => {
console.log("Start event emitted");
});
Fires immediately after onStart every 60 frames
Listener.on("onUpdate", (data) => {
console.log("Update event emitted");
});
Fires immediately after onStart every 100ms
Listener.on("onFixedUpdate", (data) => {
console.log("Fixed update event emitted");
});
Runs every 1 minute
Listener.on("onSave", (data) => {
console.log("Save event emitted");
});
Fires when a new connection is established
Listener.on("onConnection", (data) => {
console.log(`New connection: ${data}`);
});
Fires when a connection is dropped
Listener.on("onDisconnect", (data) => {
console.log(`Disconnected: ${data}`);
});
import inventory from "../systems/inventory";
declare interface InventoryItem {
name: string;
quantity: number;
}
Add an item to player inventory
await inventory.add(username, { name: "item_name", quantity: number });
Remove an item from player inventory
await inventory.remove(username, { name: "item_name", quantity: number });
Find an item from player inventory
await inventory.find(username, { name: "item_name" });
Delete an item from player inventory
await inventory.delete(username, { name: "item_name" });
Fetches a player's inventory
await inventory.get(username);
import weapons from "../systems/weapon";
declare interface WeaponData {
name: string;
damage: number;
mana: number;
range: number;
quality: string;
type: string;
description: string;
}
Adds a weapon to the weapon database
await weapons.add(weapon);
Removes a weapon to the weapon database
await weapons.remove(weapon);
Fetches a weapon from the weapon database
await weapons.find(weapon);
Updates a weapon in the weapon database
await weapons.update(weapon);
Lists all weapons in the weapon database
await weapons.list();
import items from "../systems/items";
declare interface Item {
name: string;
quality: string;
description: string;
}
Add an item to the item database
await items.add({ name: "item_name", quality: "item_quality", description: "item_description" });
Remove an item from the item database
await items.remove({ name: "item_name" });
List all items from the item database
await items.list();
Find an item from the item database
await items.find({ name: "item_name" });
Updates an item in the database
await items.update(item);
import player from "../systems/player";
declare interface Player {
id?: string;
name?: string;
position?: PositionData;
map?: string;
}
Get a player's location data
await player.getLocation({ name: username }) as LocationData | null;
Sets a player's sessionId
await player.setSessionId(token, sessionId);
Get a player's sessionId
await player.getSessionId(token);
Logs a player in
await player.login("user_name, password);
Logs the player out by clearing the auth token
await player.logout(sessionId);
Clears the players session by clearing the session id
await player.clearSessionId(sessionId);
Gets a player's username by sessionId
await player.getUsernameBySession(sessionId);
Gets a player's username by authentication token
await player.getUsernameByToken(sessionId);
Registers a new player account
await player.register(username, password, email, request);
Finds a player by username
await player.findByUsername(username);
Finds a player by email
await player.findByEmail(email);
Assigns a player an authentication token
await player.setToken(username);
Gets a players email
await player.getEmail(sessionId);
Sets the players location to the main map at 0, 0
await player.returnHome(sessionId);
Checks if the player is currently online
await player.isOnline(username);
Checks if the player is currently banned
await player.isBanned(username);
Fetches a player's stats
await player.getStats(username);
Sets a player's stats
await player.setStats(username, stats);
Fetches a player's client configuration
await player.getConfig(username);
Sets a player's client configuration
await player.getConfig(session_id, stats);
Checks if a player would collide with a future position
await player.checkIfWouldCollide(map, position);
Kicks a player from the server
await player.kick(username, websocket);
Bans a player from the server
await player.ban(username, websocket);
Returns true if a self can attack another player
await player.canAttack(self, target, range);
Returns the closest player or null
import audio from "../systems/audio";
declare interface AudioData {
name: string;
data: Buffer;
pitch?: number;
}
List all audio files in cache
audio.list() as AudioData[];
Fetches an audio file from cache
audio.get(name) as AudioData[];