source-gamepanel/packages/database/src/seed.ts

255 lines
7.9 KiB
TypeScript

import { createDb } from './client';
import { games } from './schema/games';
import { users } from './schema/users';
async function seed() {
const databaseUrl = process.env.DATABASE_URL;
if (!databaseUrl) {
console.error('DATABASE_URL is required');
process.exit(1);
}
const db = createDb(databaseUrl);
// Seed super admin
console.log('Seeding super admin...');
// Password: admin123 (argon2id hash)
// In production, change this immediately after first login
const ADMIN_PASSWORD_HASH =
'$argon2id$v=19$m=65536,t=3,p=4$3968YbMY1wOYMK5NTLa2dQ$j8BkXfK7znAAiuYiC9zWgOaBK11VeimROd28QOMMgd0';
await db
.insert(users)
.values({
email: 'admin@gamepanel.local',
username: 'admin',
passwordHash: ADMIN_PASSWORD_HASH,
isSuperAdmin: true,
})
.onConflictDoUpdate({
target: users.email,
set: {
username: 'admin',
passwordHash: ADMIN_PASSWORD_HASH,
isSuperAdmin: true,
updatedAt: new Date(),
},
});
// Seed games
console.log('Seeding games...');
await db
.insert(games)
.values([
{
slug: 'minecraft-java',
name: 'Minecraft: Java Edition',
dockerImage: 'itzg/minecraft-server:latest',
defaultPort: 25565,
startupCommand: '/start',
stopCommand: 'stop',
configFiles: [
{
path: 'server.properties',
parser: 'properties',
editableKeys: [
'server-port',
'max-players',
'motd',
'difficulty',
'gamemode',
'level-seed',
'pvp',
'spawn-protection',
'view-distance',
'online-mode',
'white-list',
],
},
{ path: 'ops.json', parser: 'json' },
{ path: 'whitelist.json', parser: 'json' },
{ path: 'bukkit.yml', parser: 'yaml' },
{ path: 'spigot.yml', parser: 'yaml' },
],
environmentVars: [
{ key: 'EULA', default: 'TRUE', description: 'Accept Minecraft EULA', required: true },
{
key: 'TYPE',
default: 'PAPER',
description: 'Server type (VANILLA, PAPER, SPIGOT, FORGE, FABRIC)',
required: true,
},
{
key: 'VERSION',
default: 'LATEST',
description: 'Minecraft version',
required: true,
},
{ key: 'MEMORY', default: '1G', description: 'JVM memory allocation', required: false },
],
},
{
slug: 'cs2',
name: 'Counter-Strike 2',
dockerImage: 'cm2network/cs2:latest',
defaultPort: 27015,
startupCommand: '',
stopCommand: 'quit',
configFiles: [
{
path: 'game/csgo/cfg/server.cfg',
parser: 'keyvalue',
editableKeys: [
'hostname',
'sv_password',
'rcon_password',
'sv_cheats',
'mp_autoteambalance',
'mp_limitteams',
],
},
{ path: 'game/csgo/cfg/autoexec.cfg', parser: 'keyvalue' },
],
automationRules: [
{
id: 'cs2-install-latest-metamod',
event: 'server.install.completed',
enabled: true,
runOncePerServer: true,
continueOnError: false,
actions: [
{
id: 'install-cs2-metamod',
type: 'http_directory_extract',
indexUrl: 'https://mms.alliedmods.net/mmsdrop/2.0/',
assetNamePattern: '^mmsource-2\\.0\\.0-git\\d+-linux\\.tar\\.gz$',
destination: '/game/csgo',
stripComponents: 0,
maxBytes: 256 * 1024 * 1024,
},
],
},
{
id: 'cs2-install-latest-counterstrikesharp-runtime',
event: 'server.install.completed',
enabled: true,
runOncePerServer: true,
continueOnError: false,
actions: [
{
id: 'install-cs2-runtime',
type: 'github_release_extract',
owner: 'roflmuffin',
repo: 'CounterStrikeSharp',
assetNamePatterns: [
'^counterstrikesharp-with-runtime-.*linux.*\\.zip$',
'^counterstrikesharp-with-runtime.*\\.zip$',
],
destination: '/game/csgo',
stripComponents: 0,
maxBytes: 256 * 1024 * 1024,
},
],
},
],
environmentVars: [
{
key: 'SRCDS_TOKEN',
default: '',
description: 'Steam Game Server Login Token (optional for local testing)',
required: false,
},
{ key: 'CS2_SERVERNAME', default: 'GamePanel CS2 Server', description: 'Server name', required: false },
{ key: 'CS2_PORT', default: '27015', description: 'Game port', required: false },
{ key: 'CS2_STARTMAP', default: 'de_dust2', description: 'Initial map', required: false },
{ key: 'CS2_MAXPLAYERS', default: '16', description: 'Max players', required: false },
{ key: 'CS2_RCONPW', default: '', description: 'RCON password', required: false },
{
key: 'CS2_IP',
default: '0.0.0.0',
description: 'Bind address',
required: false,
},
],
},
{
slug: 'minecraft-bedrock',
name: 'Minecraft: Bedrock Edition',
dockerImage: 'itzg/minecraft-bedrock-server:latest',
defaultPort: 19132,
startupCommand: '',
stopCommand: 'stop',
configFiles: [
{
path: 'server.properties',
parser: 'properties',
editableKeys: [
'server-name',
'server-port',
'max-players',
'gamemode',
'difficulty',
'level-seed',
'online-mode',
'allow-cheats',
'view-distance',
],
},
],
environmentVars: [
{ key: 'EULA', default: 'TRUE', description: 'Accept Minecraft EULA', required: true },
{ key: 'VERSION', default: 'LATEST', description: 'Bedrock server version', required: true },
],
},
{
slug: 'terraria',
name: 'Terraria',
dockerImage: 'ryshe/terraria:latest',
defaultPort: 7777,
startupCommand: '',
stopCommand: 'exit',
configFiles: [
{
path: 'serverconfig.txt',
parser: 'keyvalue',
editableKeys: [
'worldname',
'maxplayers',
'password',
'motd',
'difficulty',
'worldsize',
],
},
],
environmentVars: [
{ key: 'WORLD_NAME', default: 'world', description: 'World file name', required: true },
],
},
{
slug: 'rust',
name: 'Rust',
dockerImage: 'didstopia/rust-server:latest',
defaultPort: 28015,
startupCommand: '',
stopCommand: 'quit',
configFiles: [],
environmentVars: [
{ key: 'RUST_SERVER_NAME', default: 'My Rust Server', description: 'Server name', required: true },
{ key: 'RUST_SERVER_MAXPLAYERS', default: '50', description: 'Max players', required: false },
{ key: 'RUST_SERVER_IDENTITY', default: 'default', description: 'Server identity', required: false },
{ key: 'RUST_RCON_PASSWORD', default: '', description: 'RCON password', required: true },
],
},
])
.onConflictDoNothing();
console.log('Seed completed successfully!');
process.exit(0);
}
seed().catch((err) => {
console.error('Seed failed:', err);
process.exit(1);
});