checkpoint
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { FrontworkAdmin } from "../../Admin/Admin";
|
||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||
import { _Rank } from "../../Types/Types";
|
||||
|
||||
export class GuildManager
|
||||
implements FrontworkComponent<any>{
|
||||
|
||||
name = "GuildManager";
|
||||
admin: FrontworkAdmin
|
||||
|
||||
exportRPCs = () => [{
|
||||
name: 'getGuildInfo',
|
||||
call: async () => {
|
||||
|
||||
return await Promise.all(
|
||||
['ADMIN', ..._Rank].map(async r => {
|
||||
const res = await this.admin.knex
|
||||
.select('*')
|
||||
.from('users')
|
||||
.where('rank', '=', r)
|
||||
.first()
|
||||
.count()
|
||||
|
||||
return {
|
||||
rank: r,
|
||||
count: res['count(*)']
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}]
|
||||
|
||||
exportRPCFeatures = () => []
|
||||
|
||||
getTableDefinitions = () => []
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export type Item = {
|
||||
}
|
||||
|
||||
export class ItemManager
|
||||
implements FrontworkComponent<ItemManagerFeatureIfc>, TableDefinitionExporter{
|
||||
implements FrontworkComponent<any, any, ItemManagerFeatureIfc>, TableDefinitionExporter{
|
||||
|
||||
admin:FrontworkAdmin
|
||||
name = "ItemManager";
|
||||
|
||||
@@ -4,7 +4,7 @@ import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||
|
||||
|
||||
export class RaidManager
|
||||
implements FrontworkComponent<RaidManagerFeatureIfc>{
|
||||
implements FrontworkComponent<any, any, RaidManagerFeatureIfc>{
|
||||
name = "RaidManager";
|
||||
admin: FrontworkAdmin
|
||||
|
||||
|
||||
+27
-9
@@ -1,13 +1,19 @@
|
||||
import { RPCServer } from "rpclibrary";
|
||||
import { TableDefiniton, AnyRPCExporter, User, RPCPermission, _Rank, Token, Auth, FrontcraftFeatureIfc, Rank } from "../../Types/Types";
|
||||
import { TableDefiniton, AnyRPCExporter, User, RPCPermission, _Rank, Token, Auth, FrontcraftFeatureIfc, Rank, LoginManagerFeatureIfc } from "../../Types/Types";
|
||||
import { FrontworkAdmin } from "../../Admin/Admin";
|
||||
import { PrivilegedRPCExporter } from "../../Types/PrivilegedRPCExporter";
|
||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||
import { getSpecTableData } from "../../Types/PlayerSpecs"
|
||||
const uuid = require('uuid/v4')
|
||||
|
||||
export type LoginManagerIfc = {
|
||||
Authenticator: {
|
||||
login: (username:string, pwHash:string) => Promise<Token>
|
||||
}
|
||||
}
|
||||
|
||||
export class LoginManager
|
||||
implements FrontworkComponent{
|
||||
implements FrontworkComponent<LoginManagerFeatureIfc>{
|
||||
name = "Authenticator" as "Authenticator";
|
||||
admin:FrontworkAdmin
|
||||
|
||||
@@ -59,7 +65,8 @@ implements FrontworkComponent{
|
||||
table.string("name").notNullable().unique()
|
||||
table.string("pwhash").notNullable()
|
||||
table.string("rank").notNullable()
|
||||
table.string("class").notNullable()
|
||||
table.integer("specid").notNullable()
|
||||
table.foreign('specid').references('specs.id')
|
||||
table.string("email").nullable().unique()
|
||||
}
|
||||
},{
|
||||
@@ -77,6 +84,13 @@ implements FrontworkComponent{
|
||||
table.foreign('user_id').references('users')
|
||||
table.dateTime('created').defaultTo(this.admin.knex.fn.now())
|
||||
}
|
||||
},{
|
||||
name: 'specs',
|
||||
tableBuilder: (table) => {
|
||||
table.increments('id').primary()
|
||||
table.string('class')
|
||||
table.string('name')
|
||||
}
|
||||
}
|
||||
,...this.exporters.flatMap(exp => exp['getTableDefinitions']?exp['getTableDefinitions']():undefined)]
|
||||
}
|
||||
@@ -90,6 +104,10 @@ implements FrontworkComponent{
|
||||
})))
|
||||
|
||||
await Promise.all(this.exporters.map(ex => ex['initialize']?ex['initialize']():undefined))
|
||||
|
||||
console.log(getSpecTableData())
|
||||
|
||||
await this.admin.knex('specs').insert(getSpecTableData()).catch(console.log)
|
||||
}
|
||||
|
||||
async setPermission(permission: RPCPermission){
|
||||
@@ -147,12 +165,12 @@ implements FrontworkComponent{
|
||||
if(typeof tokenValue !== 'string') tokenValue = tokenValue.value
|
||||
|
||||
const res : User[] = await this.admin.knex
|
||||
.select('users.id', 'name', 'class', 'rank', 'email')
|
||||
.from('tokens')
|
||||
.join('users', function(){
|
||||
this.on('users.id', '=', 'tokens.user_id')
|
||||
})
|
||||
.where({ value: tokenValue})
|
||||
.select('users.id', 'name', 'specid', 'rank', 'email')
|
||||
.from('tokens')
|
||||
.join('users', function(){
|
||||
this.on('users.id', '=', 'tokens.user_id')
|
||||
})
|
||||
.where({ value: tokenValue})
|
||||
|
||||
if(res.length === 0)
|
||||
throw new Error('authentication failed')
|
||||
@@ -1,19 +1,21 @@
|
||||
import { FrontworkAdmin } from './Admin/Admin'
|
||||
import { RaidManager } from "./Components/Raid/RaidManager";
|
||||
import { ItemManager } from "./Components/Item/ItemManager";
|
||||
import { LoginManager } from "./Components/Login/LoginManager";
|
||||
import { LoginManager } from "./Components/User/UserManager";
|
||||
import { Debugger } from './Components/Debugger/Debugger';
|
||||
import { FrontworkComponent } from './Types/FrontworkComponent';
|
||||
import { GuildManager } from './Components/Guild/GuildManager';
|
||||
require('events').EventEmitter.defaultMaxListeners = 0;
|
||||
|
||||
let raidManager = new RaidManager()
|
||||
let itemManager = new ItemManager()
|
||||
let loginManager = new LoginManager([
|
||||
let guildManager = new GuildManager()
|
||||
let userManager = new LoginManager([
|
||||
raidManager,
|
||||
itemManager
|
||||
])
|
||||
|
||||
let components:FrontworkComponent[] = [ raidManager, itemManager, loginManager ]
|
||||
let components:FrontworkComponent[] = [ guildManager, raidManager, itemManager, userManager ]
|
||||
let dbg = new Debugger(components)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { Class, _Class, Spec } from "./Types";
|
||||
|
||||
const specs : { [classname in Class] : string[] } = {
|
||||
Warrior : [
|
||||
'Arms',
|
||||
'Fury',
|
||||
'Protection'
|
||||
],
|
||||
|
||||
Rogue: [
|
||||
'Subetly',
|
||||
'Combat',
|
||||
'Assassination'
|
||||
],
|
||||
|
||||
Hunter: [
|
||||
'Beast Mastery',
|
||||
'Marksmanship',
|
||||
'Survival'
|
||||
],
|
||||
|
||||
Paladin: [
|
||||
'Holy',
|
||||
'Protection',
|
||||
'Retribution'
|
||||
],
|
||||
|
||||
Priest: [
|
||||
'Discipline',
|
||||
'Holy',
|
||||
'Shadow'
|
||||
],
|
||||
|
||||
Druid: [
|
||||
'Feral (Tank)',
|
||||
'Feral (DPS)',
|
||||
'Restoration',
|
||||
'Balance'
|
||||
],
|
||||
|
||||
Mage: [
|
||||
'Frost',
|
||||
'Arcane',
|
||||
'Fire'
|
||||
],
|
||||
|
||||
Warlock: [
|
||||
'Demonology',
|
||||
'Destruction',
|
||||
'Affliction'
|
||||
],
|
||||
|
||||
Shaman: [
|
||||
'Restoration',
|
||||
'Enhancement',
|
||||
'Elemental'
|
||||
],
|
||||
}
|
||||
|
||||
export function getSpecTableData() : Spec[]{
|
||||
return _Class.flatMap((_class) => {
|
||||
const specNames : string[] = specs[_class]
|
||||
return specNames.map(specName => {
|
||||
return {
|
||||
name: specName,
|
||||
class: _class
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -31,7 +31,7 @@ export type User = {
|
||||
id?: number
|
||||
name: string
|
||||
pwhash: string
|
||||
class: Class
|
||||
specid: number
|
||||
rank: Rank
|
||||
email?: string
|
||||
}
|
||||
@@ -90,6 +90,12 @@ export type RaidManagerFeatureIfc = {
|
||||
}
|
||||
}
|
||||
|
||||
export type Spec = {
|
||||
id?: number,
|
||||
class: Class,
|
||||
name: string
|
||||
}
|
||||
|
||||
export type SomeOf<T> = {
|
||||
[K in keyof T]? : T[K]
|
||||
}
|
||||
Reference in New Issue
Block a user