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 { FrontworkAdmin } from "../../Admin/Admin";
|
||||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
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
|
export class GuildManager
|
||||||
implements FrontworkComponent<any>{
|
implements FrontworkComponent<GuildManagerIfc, GuildManagerFeatureIfc>{
|
||||||
|
|
||||||
name = "GuildManager";
|
name = "GuildManager" as "GuildManager";
|
||||||
admin: FrontworkAdmin
|
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 = () => [{
|
exportRPCs = () => [{
|
||||||
name: 'getGuildInfo',
|
name: 'getHeadCount' as 'getHeadCount',
|
||||||
call: async () => {
|
call: async () => await this.headCount()
|
||||||
|
},{
|
||||||
return await Promise.all(
|
name: 'getGuildInfo' as 'getGuildInfo',
|
||||||
['ADMIN', ..._Rank].map(async r => {
|
call: async () => this.guild.getConfig()
|
||||||
const res = await this.admin.knex
|
|
||||||
.select('*')
|
|
||||||
.from('users')
|
|
||||||
.where('rank', '=', r)
|
|
||||||
.first()
|
|
||||||
.count()
|
|
||||||
|
|
||||||
return {
|
|
||||||
rank: r,
|
|
||||||
count: res['count(*)']
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}]
|
}]
|
||||||
|
|
||||||
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 = () => []
|
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 { FrontworkAdmin } from "../../Admin/Admin";
|
||||||
import { T1 } from "../../Types/Items";
|
import { T1 } from "../../Types/Items";
|
||||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
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 fetch = require('node-fetch')
|
||||||
const xml2js = require('xml2js');
|
const xml2js = require('xml2js');
|
||||||
const parser = new xml2js.Parser(/* options */);
|
const parser = new xml2js.Parser(/* options */);
|
||||||
|
|
||||||
|
|
||||||
export type ItemManagerFeatureIfc = any
|
|
||||||
|
|
||||||
export type Item = {
|
export type Item = {
|
||||||
id?:number
|
id?:number
|
||||||
@@ -21,10 +21,10 @@ export type Item = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ItemManager
|
export class ItemManager
|
||||||
implements FrontworkComponent<any, any, ItemManagerFeatureIfc>, TableDefinitionExporter{
|
implements FrontworkComponent<ItemManagerIfc, ItemManagerFeatureIfc>, TableDefinitionExporter{
|
||||||
|
|
||||||
admin:FrontworkAdmin
|
admin:FrontworkAdmin
|
||||||
name = "ItemManager";
|
name = "ItemManager" as "ItemManager";
|
||||||
|
|
||||||
exportRPCs(): RPC<any, any>[]{
|
exportRPCs(): RPC<any, any>[]{
|
||||||
return [{
|
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 { FrontworkAdmin } from "../../Admin/Admin";
|
||||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||||
|
import { RaidManagerFeatureIfc, RaidManagerIfc } from "./RPCInterface";
|
||||||
|
|
||||||
export class RaidManager
|
export class RaidManager
|
||||||
implements FrontworkComponent<any, any, RaidManagerFeatureIfc>{
|
implements FrontworkComponent<RaidManagerIfc, RaidManagerFeatureIfc>{
|
||||||
name = "RaidManager";
|
name = "RaidManager" as "RaidManager";
|
||||||
admin: FrontworkAdmin
|
admin: FrontworkAdmin
|
||||||
|
|
||||||
exportRPCs = () => []
|
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 { 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 { FrontworkAdmin } from "../../Admin/Admin";
|
||||||
import { PrivilegedRPCExporter } from "../../Types/PrivilegedRPCExporter";
|
import { PrivilegedRPCExporter } from "../../Types/PrivilegedRPCExporter";
|
||||||
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
import { FrontworkComponent } from "../../Types/FrontworkComponent";
|
||||||
import { getSpecTableData } from "../../Types/PlayerSpecs"
|
import { getSpecTableData } from "../../Types/PlayerSpecs"
|
||||||
|
import { UserManagerIfc, UserManagerFeatureIfc } from "./RPCInterface";
|
||||||
const uuid = require('uuid/v4')
|
const uuid = require('uuid/v4')
|
||||||
|
|
||||||
export type LoginManagerIfc = {
|
|
||||||
Authenticator: {
|
|
||||||
login: (username:string, pwHash:string) => Promise<Token>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class LoginManager
|
export class LoginManager
|
||||||
implements FrontworkComponent<LoginManagerFeatureIfc>{
|
implements FrontworkComponent<UserManagerIfc, UserManagerFeatureIfc>{
|
||||||
name = "Authenticator" as "Authenticator";
|
name = "Authenticator" as "Authenticator";
|
||||||
admin:FrontworkAdmin
|
admin:FrontworkAdmin
|
||||||
|
|
||||||
@@ -124,7 +119,7 @@ implements FrontworkComponent<LoginManagerFeatureIfc>{
|
|||||||
const perm : RPCPermission[] = await this.admin.knex
|
const perm : RPCPermission[] = await this.admin.knex
|
||||||
.select(rank)
|
.select(rank)
|
||||||
.from('rpcpermissions')
|
.from('rpcpermissions')
|
||||||
.where('name', '=', feature)
|
.where('name', '=', <string>feature)
|
||||||
|
|
||||||
if(perm.length === 0) return false
|
if(perm.length === 0) return false
|
||||||
return perm[0][rank]
|
return perm[0][rank]
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ let itemManager = new ItemManager()
|
|||||||
let guildManager = new GuildManager()
|
let guildManager = new GuildManager()
|
||||||
let userManager = new LoginManager([
|
let userManager = new LoginManager([
|
||||||
raidManager,
|
raidManager,
|
||||||
itemManager
|
itemManager,
|
||||||
|
guildManager
|
||||||
])
|
])
|
||||||
|
|
||||||
let components:FrontworkComponent[] = [ guildManager, raidManager, itemManager, userManager ]
|
let components:FrontworkComponent[] = [ guildManager, raidManager, itemManager, userManager ]
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
import { PrivilegedRPCExporter } from "./PrivilegedRPCExporter";
|
import { PrivilegedRPCExporter } from "./PrivilegedRPCExporter";
|
||||||
import { RPCInterface, RPC, AnyFunction, RPCExporter } from "rpclibrary";
|
import { RPCInterface, RPCExporter, RPCInterfaceArray } from "rpclibrary";
|
||||||
import { TableDefinitionExporter } from "./Interfaces";
|
import { TableDefinitionExporter } from "./Interfaces";
|
||||||
import { FrontworkAdmin } from "../Admin/Admin";
|
import { FrontworkAdmin } from "../Admin/Admin";
|
||||||
import { TableDefiniton } from "./Types";
|
import { TableDefiniton } from "./Types";
|
||||||
|
|
||||||
export interface FrontworkComponent<
|
export interface FrontworkComponent<
|
||||||
Ifc extends RPCInterface = RPCInterface,
|
Ifc extends RPCInterface = RPCInterface,
|
||||||
|
FeatureIfc extends RPCInterface = RPCInterface,
|
||||||
Name extends keyof Ifc = keyof Ifc,
|
Name extends keyof Ifc = keyof Ifc,
|
||||||
|
FeatureName extends keyof FeatureIfc = keyof FeatureIfc,
|
||||||
SubresT = {}
|
SubresT = {}
|
||||||
> extends
|
> extends
|
||||||
PrivilegedRPCExporter<Ifc, Name, SubresT>,
|
PrivilegedRPCExporter<Ifc, FeatureIfc, Name, FeatureName, SubresT>,
|
||||||
TableDefinitionExporter
|
TableDefinitionExporter
|
||||||
{
|
{
|
||||||
admin:FrontworkAdmin
|
admin:FrontworkAdmin
|
||||||
name: string;
|
name: Name;
|
||||||
|
|
||||||
exportRPCFeatures(): RPCExporter<Ifc, Name, SubresT>[]
|
exportRPCFeatures(): RPCExporter<FeatureIfc, FeatureName, SubresT>[]
|
||||||
exportRPCs(): RPC<string, AnyFunction, {}>[]
|
exportRPCs(): RPCInterfaceArray<Ifc>[Name]
|
||||||
getTableDefinitions(): TableDefiniton[]
|
getTableDefinitions(): TableDefiniton[]
|
||||||
|
|
||||||
initialize?(): Promise<any>
|
initialize?(): Promise<any>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { RPCExporter, RPCInterface, RPC, RPCInterfaceArray } from "rpclibrary";
|
import { RPCExporter, RPCInterface, RPC, RPCInterfaceArray } from "rpclibrary";
|
||||||
|
|
||||||
export interface PrivilegedRPCExporter <Ifc extends RPCInterface = RPCInterface, Name extends keyof Ifc = keyof Ifc, SubresT = {}>
|
export interface PrivilegedRPCExporter <
|
||||||
extends RPCExporter<any,any>{
|
Ifc extends RPCInterface = RPCInterface,
|
||||||
|
FeatureIfc extends RPCInterface = RPCInterface,
|
||||||
exportRPCFeatures() : RPCExporter<Ifc, Name, SubresT>[]
|
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 * as Knex from "knex"
|
||||||
import { RPCExporter } from "rpclibrary";
|
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';
|
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 Auth = {port: number, user: User, token: Token}
|
||||||
|
|
||||||
export type FrontcraftFeatureIfc = RaidManagerFeatureIfc & LoginManagerFeatureIfc
|
export type FrontcraftIfc = UserManagerIfc
|
||||||
|
& ItemManagerIfc
|
||||||
|
|
||||||
|
export type FrontcraftFeatureIfc = RaidManagerFeatureIfc
|
||||||
export type LoginManagerIfc = {
|
& UserManagerFeatureIfc
|
||||||
Authenticator: {
|
& ItemManagerFeatureIfc
|
||||||
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 Spec = {
|
export type Spec = {
|
||||||
id?: number,
|
id?: number,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
externals: ['http'],
|
externals: ['http', 'fs'],
|
||||||
node: {global: true, fs: 'empty'}
|
node: {global: true, fs: 'empty'}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
import {RPCSocket} from 'rpclibrary/js/src/Frontend'
|
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';
|
import { CookieService } from 'ngx-cookie-service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LoginApiService{
|
export class LoginApiService{
|
||||||
private socket:RPCSocket & LoginManagerIfc;
|
private socket:RPCSocket & FrontcraftIfc;
|
||||||
private auth:Auth
|
private auth:Auth
|
||||||
private privSocket: RPCSocket & SomeOf<FrontcraftFeatureIfc>
|
private privSocket: RPCSocket & SomeOf<FrontcraftFeatureIfc>
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ export class LoginApiService{
|
|||||||
private cookieSvc : CookieService
|
private cookieSvc : CookieService
|
||||||
){}
|
){}
|
||||||
|
|
||||||
getUnprivilegedSocket = () : RPCSocket & LoginManagerIfc => this.socket
|
getUnprivilegedSocket = () : RPCSocket & FrontcraftIfc => this.socket
|
||||||
|
|
||||||
private getPrivilegedSocket = async (auth:Auth) : Promise<RPCSocket & SomeOf<FrontcraftFeatureIfc>> => {
|
private getPrivilegedSocket = async (auth:Auth) : Promise<RPCSocket & SomeOf<FrontcraftFeatureIfc>> => {
|
||||||
if(this.privSocket) return this.privSocket
|
if(this.privSocket) return this.privSocket
|
||||||
@@ -85,7 +85,7 @@ export class LoginApiService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
initialize = async () : Promise<RPCSocket> => {
|
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
|
this.socket = sock
|
||||||
|
|
||||||
const cookie = this.getCookie()
|
const cookie = this.getCookie()
|
||||||
|
|||||||
Reference in New Issue
Block a user