--- /dev/null
+import { Knex } from "knex";
+
+
+export async function up(knex: Knex): Promise<void> {
+ return knex.schema.createTable('permissions', function(table){
+ table.string('name').primary();
+ }).createTable('player_permissions', function(table) {
+ table.string('permission');
+ table.uuid('player_id');
+ table.primary(['permission', 'player_id']);
+ });
+}
+
+
+export async function down(knex: Knex): Promise<void> {
+ return knex.schema.dropTable('permissions').dropTable('player_permissions');
+}
+
}
let message: Message;
- if(msg.startsWith('/server lmnop')) {
+ if(msg.startsWith('/server') && req.player.permissions.includes('admin')) {
try {
- if(msg === '/server lmnop refresh-monsters') {
+ if(msg === '/server refresh-monsters') {
await createMonsters();
message = broadcastMessage('server', 'Monster refresh!');
}
- else if(msg === '/server lmnop refresh-cities') {
+ else if(msg === '/server refresh-cities') {
await createAllCitiesAndLocations();
message = broadcastMessage('server', 'Cities, Locations, and Paths refreshed!');
}
- else if(msg === '/server lmnop refresh-shops') {
+ else if(msg === '/server refresh-shops') {
await createShopItems();
await createShopEquipment();
message = broadcastMessage('server', 'Refresh shop items');
}
else {
- const str = msg.split('/server lmnop ')[1];
+ const str = msg.split('/server ')[1];
if(str) {
message = broadcastMessage('server', str);
}
export async function loadPlayer(authToken: string): Promise<Player> {
const res = await db.first()
- .select('players.*', 'profession_levels.level', 'profession_levels.exp')
+ .select(
+ 'players.*',
+ 'profession_levels.level',
+ 'profession_levels.exp',
+ db.raw(`coalesce(pp.permissions, '[]'::json) as permissions`)
+ )
.from<Player>('players')
.join('profession_levels', function() {
this.on(function() {
this.andOn('profession_levels.profession', '=', 'players.profession')
})
})
+ .leftJoin(
+ db.raw(`(select json_agg(pp.permission) as permissions, pp.player_id from player_permissions pp group by pp.player_id) pp`),
+ 'pp.player_id','=', 'players.id'
+ )
.where({
'players.id': authToken
});
- return res;
+ return res;
}
export async function createPlayer(): Promise<Player> {
import { SkillDefinition, Skill } from './skills';
import { EquippedItemDetails } from './equipped';
+export type Permission = 'admin' | 'moderator';
+
export type Player = {
id: string,
account_type: 'session' | 'auth',
city_id: number;
stat_points: number;
vigor: number;
+ permissions: Permission[]
}
export type PlayerWithSkills = Player & {