push
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "AAA",
|
||||
"realm": "Gandling EU",
|
||||
"description": "Wee woo"
|
||||
}
|
||||
@@ -1,37 +1,74 @@
|
||||
import { FrontworkAdmin } from "../../Admin/Admin";
|
||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||
import { _Rank } from "../../Types/Types";
|
||||
import { _Rank, Rank } from "../../Types/Types";
|
||||
import { ConfigLoader } from "loadson";
|
||||
import { GuildManagerIfc, GuildManagerFeatureIfc } from "./RPCInterface";
|
||||
|
||||
export type Guild = {
|
||||
name: string
|
||||
realm: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export class GuildManager
|
||||
implements FrontworkComponent<any>{
|
||||
implements FrontworkComponent<GuildManagerIfc, GuildManagerFeatureIfc>{
|
||||
|
||||
name = "GuildManager";
|
||||
name = "GuildManager" as "GuildManager";
|
||||
admin: FrontworkAdmin
|
||||
|
||||
guild: ConfigLoader<Guild>
|
||||
|
||||
constructor(){
|
||||
this.guild = new ConfigLoader({
|
||||
name: "guild",
|
||||
getDefaultConfig: () => {
|
||||
return <Guild>{
|
||||
name: "Tranquil",
|
||||
realm: "Gandling EU",
|
||||
description: "Wee woo"
|
||||
}
|
||||
}
|
||||
}, "./config")
|
||||
}
|
||||
|
||||
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(*)']
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
name: 'getHeadCount' as 'getHeadCount',
|
||||
call: async () => await this.headCount()
|
||||
},{
|
||||
name: 'getGuildInfo' as 'getGuildInfo',
|
||||
call: async () => this.guild.getConfig()
|
||||
}]
|
||||
|
||||
exportRPCFeatures = () => []
|
||||
exportRPCFeatures = () => [{
|
||||
name: 'manageGuild' as 'manageGuild',
|
||||
exportRPCs: () => [{
|
||||
name: 'setName' as 'setName',
|
||||
call: async (name:string) => this.guild.setConfigKey('name', name)
|
||||
},{
|
||||
name: 'setRealm' as 'setRealm',
|
||||
call: async (realm:string) => this.guild.setConfigKey('realm', realm)
|
||||
}, {
|
||||
name: 'setDescription' as 'setDescription',
|
||||
call: async (description: string) => this.guild.setConfigKey('description', description)
|
||||
}]
|
||||
}]
|
||||
|
||||
getTableDefinitions = () => []
|
||||
|
||||
headCount = async () => await Promise.all(
|
||||
['ADMIN', ..._Rank].map(async r => {
|
||||
const res = await this.admin.knex
|
||||
.select('*')
|
||||
.from('users')
|
||||
.where('rank', '=', r)
|
||||
.first()
|
||||
.count()
|
||||
|
||||
return <{rank:Rank, count: number}>{
|
||||
rank: r,
|
||||
count: res['count(*)']
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Guild } from "./GuildManager"
|
||||
import { Rank } from "../../Types/Types"
|
||||
|
||||
export type GuildManagerIfc = {
|
||||
GuildManager: {
|
||||
getHeadCount: () => Promise<{rank:Rank, count: number}[]>
|
||||
getGuildInfo: () => Promise<Guild>
|
||||
}
|
||||
}
|
||||
|
||||
export type GuildManagerFeatureIfc = {
|
||||
manageGuild: {
|
||||
setName: (name:string) => Promise<Guild>
|
||||
setRealm: (realm:string) => Promise<Guild>
|
||||
setDescription: (description:string) => Promise<Guild>
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@ import { TableDefiniton, _Rank } from "../../Types/Types";
|
||||
import { FrontworkAdmin } from "../../Admin/Admin";
|
||||
import { T1 } from "../../Types/Items";
|
||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||
import { RPC } from "rpclibrary";
|
||||
import { RPC, RPCInterface } from "rpclibrary";
|
||||
import { ItemManagerIfc, ItemManagerFeatureIfc } from "./RPCInterface";
|
||||
const fetch = require('node-fetch')
|
||||
const xml2js = require('xml2js');
|
||||
const parser = new xml2js.Parser(/* options */);
|
||||
|
||||
|
||||
export type ItemManagerFeatureIfc = any
|
||||
|
||||
export type Item = {
|
||||
id?:number
|
||||
@@ -21,10 +21,10 @@ export type Item = {
|
||||
}
|
||||
|
||||
export class ItemManager
|
||||
implements FrontworkComponent<any, any, ItemManagerFeatureIfc>, TableDefinitionExporter{
|
||||
implements FrontworkComponent<ItemManagerIfc, ItemManagerFeatureIfc>, TableDefinitionExporter{
|
||||
|
||||
admin:FrontworkAdmin
|
||||
name = "ItemManager";
|
||||
name = "ItemManager" as "ItemManager";
|
||||
|
||||
exportRPCs(): RPC<any, any>[]{
|
||||
return [{
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import { RPCInterface } from "rpclibrary"
|
||||
|
||||
export type ItemManagerIfc = RPCInterface
|
||||
export type ItemManagerFeatureIfc = RPCInterface
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Raid, Signup, User } from "../../Types/Types";
|
||||
import { RPCInterface } from "rpclibrary";
|
||||
|
||||
export type RaidManagerIfc = RPCInterface
|
||||
|
||||
export type RaidManagerFeatureIfc = {
|
||||
manageRaid: {
|
||||
createRaid: (raid:Raid) => Promise<any>
|
||||
addSignup: (signup: Signup) => Promise<any>
|
||||
removeSignup: (signup: Signup) => Promise<any>
|
||||
}
|
||||
signup: {
|
||||
getRaids: () => Promise<Raid[]>
|
||||
getSingups: (raid:Raid) => Promise<Signup[]>
|
||||
sign: (user:User, raid:Raid, attending:boolean) => Promise<any>
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { TableDefiniton, User, _Rank, Raid, Signup, RaidManagerFeatureIfc } from "../../Types/Types";
|
||||
import { TableDefiniton, User, _Rank, Raid, Signup } from "../../Types/Types";
|
||||
import { FrontworkAdmin } from "../../Admin/Admin";
|
||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||
|
||||
import { RaidManagerFeatureIfc, RaidManagerIfc } from "./RPCInterface";
|
||||
|
||||
export class RaidManager
|
||||
implements FrontworkComponent<any, any, RaidManagerFeatureIfc>{
|
||||
name = "RaidManager";
|
||||
implements FrontworkComponent<RaidManagerIfc, RaidManagerFeatureIfc>{
|
||||
name = "RaidManager" as "RaidManager";
|
||||
admin: FrontworkAdmin
|
||||
|
||||
exportRPCs = () => []
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Token, Auth, User, RPCPermission } from "../../Types/Types"
|
||||
|
||||
export type UserManagerIfc = {
|
||||
Authenticator: {
|
||||
login: (username:string, pwHash:string) => Promise<Token>
|
||||
authenticate: (token:string | Token) => Promise<Auth>
|
||||
}
|
||||
}
|
||||
|
||||
export type UserManagerFeatureIfc = {
|
||||
createUser: {
|
||||
createUser: (user:User) => Promise<User>
|
||||
}
|
||||
modifyPermissions: {
|
||||
setPermission: (perm: RPCPermission) => Promise<void>
|
||||
getPermissions: () => Promise<RPCPermission[]>
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,14 @@
|
||||
import { RPCServer } from "rpclibrary";
|
||||
import { TableDefiniton, AnyRPCExporter, User, RPCPermission, _Rank, Token, Auth, FrontcraftFeatureIfc, Rank, LoginManagerFeatureIfc } from "../../Types/Types";
|
||||
import { TableDefiniton, AnyRPCExporter, User, RPCPermission, _Rank, Token, Auth, Rank, FrontcraftFeatureIfc } from "../../Types/Types";
|
||||
import { FrontworkAdmin } from "../../Admin/Admin";
|
||||
import { PrivilegedRPCExporter } from "../../Types/PrivilegedRPCExporter";
|
||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||
import { getSpecTableData } from "../../Types/PlayerSpecs"
|
||||
import { UserManagerIfc, UserManagerFeatureIfc } from "./RPCInterface";
|
||||
const uuid = require('uuid/v4')
|
||||
|
||||
export type LoginManagerIfc = {
|
||||
Authenticator: {
|
||||
login: (username:string, pwHash:string) => Promise<Token>
|
||||
}
|
||||
}
|
||||
|
||||
export class LoginManager
|
||||
implements FrontworkComponent<LoginManagerFeatureIfc>{
|
||||
implements FrontworkComponent<UserManagerIfc, UserManagerFeatureIfc>{
|
||||
name = "Authenticator" as "Authenticator";
|
||||
admin:FrontworkAdmin
|
||||
|
||||
@@ -124,7 +119,7 @@ implements FrontworkComponent<LoginManagerFeatureIfc>{
|
||||
const perm : RPCPermission[] = await this.admin.knex
|
||||
.select(rank)
|
||||
.from('rpcpermissions')
|
||||
.where('name', '=', feature)
|
||||
.where('name', '=', <string>feature)
|
||||
|
||||
if(perm.length === 0) return false
|
||||
return perm[0][rank]
|
||||
|
||||
@@ -12,7 +12,8 @@ let itemManager = new ItemManager()
|
||||
let guildManager = new GuildManager()
|
||||
let userManager = new LoginManager([
|
||||
raidManager,
|
||||
itemManager
|
||||
itemManager,
|
||||
guildManager
|
||||
])
|
||||
|
||||
let components:FrontworkComponent[] = [ guildManager, raidManager, itemManager, userManager ]
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
import { PrivilegedRPCExporter } from "./PrivilegedRPCExporter";
|
||||
import { RPCInterface, RPC, AnyFunction, RPCExporter } from "rpclibrary";
|
||||
import { RPCInterface, RPCExporter, RPCInterfaceArray } from "rpclibrary";
|
||||
import { TableDefinitionExporter } from "./Interfaces";
|
||||
import { FrontworkAdmin } from "../Admin/Admin";
|
||||
import { TableDefiniton } from "./Types";
|
||||
|
||||
export interface FrontworkComponent<
|
||||
Ifc extends RPCInterface = RPCInterface,
|
||||
FeatureIfc extends RPCInterface = RPCInterface,
|
||||
Name extends keyof Ifc = keyof Ifc,
|
||||
FeatureName extends keyof FeatureIfc = keyof FeatureIfc,
|
||||
SubresT = {}
|
||||
> extends
|
||||
PrivilegedRPCExporter<Ifc, Name, SubresT>,
|
||||
PrivilegedRPCExporter<Ifc, FeatureIfc, Name, FeatureName, SubresT>,
|
||||
TableDefinitionExporter
|
||||
{
|
||||
admin:FrontworkAdmin
|
||||
name: string;
|
||||
name: Name;
|
||||
|
||||
exportRPCFeatures(): RPCExporter<Ifc, Name, SubresT>[]
|
||||
exportRPCs(): RPC<string, AnyFunction, {}>[]
|
||||
exportRPCFeatures(): RPCExporter<FeatureIfc, FeatureName, SubresT>[]
|
||||
exportRPCs(): RPCInterfaceArray<Ifc>[Name]
|
||||
getTableDefinitions(): TableDefiniton[]
|
||||
|
||||
initialize?(): Promise<any>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { RPCExporter, RPCInterface, RPC, RPCInterfaceArray } from "rpclibrary";
|
||||
|
||||
export interface PrivilegedRPCExporter <Ifc extends RPCInterface = RPCInterface, Name extends keyof Ifc = keyof Ifc, SubresT = {}>
|
||||
extends RPCExporter<any,any>{
|
||||
|
||||
exportRPCFeatures() : RPCExporter<Ifc, Name, SubresT>[]
|
||||
export interface PrivilegedRPCExporter <
|
||||
Ifc extends RPCInterface = RPCInterface,
|
||||
FeatureIfc extends RPCInterface = RPCInterface,
|
||||
Name extends keyof Ifc = keyof Ifc,
|
||||
FeatureName extends keyof FeatureIfc = keyof FeatureIfc,
|
||||
SubresT = {}
|
||||
>extends RPCExporter<Ifc, Name>{
|
||||
exportRPCFeatures() : RPCExporter<FeatureIfc, FeatureName, SubresT>[]
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
import * as Knex from "knex"
|
||||
import { RPCExporter } from "rpclibrary";
|
||||
import { RaidManagerFeatureIfc } from "../Components/Raid/RPCInterface";
|
||||
import { ItemManagerIfc, ItemManagerFeatureIfc } from "../Components/Item/RPCInterface";
|
||||
import { UserManagerIfc, UserManagerFeatureIfc } from "../Components/User/RPCInterface";
|
||||
|
||||
|
||||
export declare type NotificationSeverity = 'Info' | 'Important' | 'Error';
|
||||
|
||||
@@ -57,38 +61,12 @@ export type Token = {
|
||||
|
||||
export type Auth = {port: number, user: User, token: Token}
|
||||
|
||||
export type FrontcraftFeatureIfc = RaidManagerFeatureIfc & LoginManagerFeatureIfc
|
||||
export type FrontcraftIfc = UserManagerIfc
|
||||
& ItemManagerIfc
|
||||
|
||||
|
||||
export type LoginManagerIfc = {
|
||||
Authenticator: {
|
||||
login: (username:string, pwHash:string) => Promise<Token>
|
||||
authenticate: (token:string | Token) => Promise<Auth>
|
||||
}
|
||||
}
|
||||
|
||||
export type LoginManagerFeatureIfc = {
|
||||
createUser: {
|
||||
createUser: (user:User) => Promise<User>
|
||||
}
|
||||
modifyPermissions: {
|
||||
setPermission: (perm: RPCPermission) => Promise<void>
|
||||
getPermissions: () => Promise<RPCPermission[]>
|
||||
}
|
||||
}
|
||||
|
||||
export type RaidManagerFeatureIfc = {
|
||||
manageRaid: {
|
||||
createRaid: (raid:Raid) => Promise<any>
|
||||
addSignup: (signup: Signup) => Promise<any>
|
||||
removeSignup: (signup: Signup) => Promise<any>
|
||||
}
|
||||
signup: {
|
||||
getRaids: () => Promise<Raid[]>
|
||||
getSingups: (raid:Raid) => Promise<Signup[]>
|
||||
sign: (user:User, raid:Raid, attending:boolean) => Promise<any>
|
||||
}
|
||||
}
|
||||
export type FrontcraftFeatureIfc = RaidManagerFeatureIfc
|
||||
& UserManagerFeatureIfc
|
||||
& ItemManagerFeatureIfc
|
||||
|
||||
export type Spec = {
|
||||
id?: number,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
externals: ['http'],
|
||||
externals: ['http', 'fs'],
|
||||
node: {global: true, fs: 'empty'}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import {RPCSocket} from 'rpclibrary/js/src/Frontend'
|
||||
|
||||
import { Token, Auth, User, _Class, FrontcraftFeatureIfc, LoginManagerIfc, SomeOf, } from '../../../../../backend/Types/Types'
|
||||
import { Token, Auth, User, _Class, FrontcraftFeatureIfc, SomeOf, FrontcraftIfc, } from '../../../../../backend/Types/Types'
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
@Injectable()
|
||||
export class LoginApiService{
|
||||
private socket:RPCSocket & LoginManagerIfc;
|
||||
private socket:RPCSocket & FrontcraftIfc;
|
||||
private auth:Auth
|
||||
private privSocket: RPCSocket & SomeOf<FrontcraftFeatureIfc>
|
||||
|
||||
@@ -14,7 +14,7 @@ export class LoginApiService{
|
||||
private cookieSvc : CookieService
|
||||
){}
|
||||
|
||||
getUnprivilegedSocket = () : RPCSocket & LoginManagerIfc => this.socket
|
||||
getUnprivilegedSocket = () : RPCSocket & FrontcraftIfc => this.socket
|
||||
|
||||
private getPrivilegedSocket = async (auth:Auth) : Promise<RPCSocket & SomeOf<FrontcraftFeatureIfc>> => {
|
||||
if(this.privSocket) return this.privSocket
|
||||
@@ -85,7 +85,7 @@ export class LoginApiService{
|
||||
}
|
||||
|
||||
initialize = async () : Promise<RPCSocket> => {
|
||||
const sock = await RPCSocket.makeSocket<LoginManagerIfc>(20000, window.location.hostname)
|
||||
const sock = await RPCSocket.makeSocket<FrontcraftIfc>(20000, window.location.hostname)
|
||||
this.socket = sock
|
||||
|
||||
const cookie = this.getCookie()
|
||||
|
||||
Reference in New Issue
Block a user