瀏覽代碼

push

master
peter 6 年之前
父節點
當前提交
871005d584

+ 5
- 0
guild.json 查看文件

@@ -0,0 +1,5 @@
1
+{
2
+  "name": "AAA",
3
+  "realm": "Gandling EU",
4
+  "description": "Wee woo"
5
+}

+ 60
- 23
src/backend/Components/Guild/GuildManager.ts 查看文件

@@ -1,37 +1,74 @@
1 1
 import { FrontworkAdmin } from "../../Admin/Admin";
2 2
 import { FrontworkComponent } from "../../Types/FrontworkComponent";
3
-import { _Rank } from "../../Types/Types";
3
+import { _Rank, Rank } from "../../Types/Types";
4
+import { ConfigLoader } from "loadson";
5
+import { GuildManagerIfc, GuildManagerFeatureIfc } from "./RPCInterface";
6
+
7
+export type Guild = {
8
+    name: string
9
+    realm: string
10
+    description: string
11
+}
4 12
 
5 13
 export class GuildManager
6
-implements FrontworkComponent<any>{
14
+implements FrontworkComponent<GuildManagerIfc, GuildManagerFeatureIfc>{
7 15
 
8
-    name = "GuildManager";    
16
+    name = "GuildManager" as "GuildManager";    
9 17
     admin: FrontworkAdmin
10 18
 
19
+    guild: ConfigLoader<Guild>
20
+
21
+    constructor(){
22
+        this.guild = new ConfigLoader({
23
+            name: "guild",
24
+            getDefaultConfig: () => {
25
+                return <Guild>{
26
+                    name: "Tranquil",
27
+                    realm: "Gandling EU",
28
+                    description: "Wee woo"
29
+                }
30
+            }
31
+        }, "./config")
32
+    }
33
+
11 34
     exportRPCs = () => [{
12
-        name: 'getGuildInfo',
13
-        call: async () => {
14
-
15
-            return await Promise.all(
16
-                ['ADMIN', ..._Rank].map(async r => {
17
-                    const res = await this.admin.knex
18
-                    .select('*')
19
-                    .from('users')
20
-                    .where('rank', '=', r)
21
-                    .first()
22
-                    .count()
23
-
24
-                    return {
25
-                        rank:  r,
26
-                        count: res['count(*)']
27
-                    }
28
-                })
29
-            )
30
-        }
35
+        name: 'getHeadCount' as 'getHeadCount',
36
+        call: async () => await this.headCount()
37
+    },{
38
+        name: 'getGuildInfo' as 'getGuildInfo',
39
+        call: async () => this.guild.getConfig()
31 40
     }]
32 41
 
33
-    exportRPCFeatures = () => []
42
+    exportRPCFeatures = () => [{
43
+        name: 'manageGuild' as 'manageGuild',
44
+        exportRPCs: () => [{
45
+            name: 'setName' as 'setName',
46
+            call: async (name:string) => this.guild.setConfigKey('name', name)
47
+        },{
48
+            name: 'setRealm' as 'setRealm',
49
+            call: async (realm:string) => this.guild.setConfigKey('realm', realm)
50
+        }, {
51
+            name: 'setDescription' as 'setDescription',
52
+            call: async (description: string) => this.guild.setConfigKey('description', description)
53
+        }]
54
+    }]
34 55
     
35 56
     getTableDefinitions = () => []
36 57
 
58
+    headCount = async () => await Promise.all(
59
+        ['ADMIN', ..._Rank].map(async r => {
60
+            const res = await this.admin.knex
61
+            .select('*')
62
+            .from('users')
63
+            .where('rank', '=', r)
64
+            .first()
65
+            .count()
66
+
67
+            return <{rank:Rank, count: number}>{
68
+                rank:  r,
69
+                count: res['count(*)']
70
+            }
71
+        })
72
+    )
73
+
37 74
 }

+ 17
- 0
src/backend/Components/Guild/RPCInterface.ts 查看文件

@@ -0,0 +1,17 @@
1
+import { Guild } from "./GuildManager"
2
+import { Rank } from "../../Types/Types"
3
+
4
+export type GuildManagerIfc = {
5
+    GuildManager: {
6
+        getHeadCount: () => Promise<{rank:Rank, count: number}[]>
7
+        getGuildInfo: () => Promise<Guild>
8
+    }
9
+}
10
+
11
+export type GuildManagerFeatureIfc = {
12
+    manageGuild: {
13
+        setName: (name:string) => Promise<Guild>
14
+        setRealm: (realm:string) => Promise<Guild>
15
+        setDescription: (description:string) => Promise<Guild>
16
+    }
17
+}

+ 4
- 4
src/backend/Components/Item/ItemManager.ts 查看文件

@@ -3,13 +3,13 @@ import { TableDefiniton, _Rank } from "../../Types/Types";
3 3
 import { FrontworkAdmin } from "../../Admin/Admin";
4 4
 import { T1 } from "../../Types/Items";
5 5
 import { FrontworkComponent } from "../../Types/FrontworkComponent";
6
-import { RPC } from "rpclibrary";
6
+import { RPC, RPCInterface } from "rpclibrary";
7
+import { ItemManagerIfc, ItemManagerFeatureIfc } from "./RPCInterface";
7 8
 const fetch = require('node-fetch')
8 9
 const xml2js = require('xml2js');
9 10
 const parser = new xml2js.Parser(/* options */);
10 11
 
11 12
 
12
-export type ItemManagerFeatureIfc = any
13 13
 
14 14
 export type Item = {
15 15
     id?:number
@@ -21,10 +21,10 @@ export type Item = {
21 21
 }
22 22
 
23 23
 export class ItemManager
24
-implements FrontworkComponent<any, any, ItemManagerFeatureIfc>, TableDefinitionExporter{
24
+implements FrontworkComponent<ItemManagerIfc, ItemManagerFeatureIfc>, TableDefinitionExporter{
25 25
     
26 26
     admin:FrontworkAdmin    
27
-    name = "ItemManager";    
27
+    name = "ItemManager" as "ItemManager";    
28 28
     
29 29
     exportRPCs(): RPC<any, any>[]{
30 30
         return [{

+ 4
- 0
src/backend/Components/Item/RPCInterface.ts 查看文件

@@ -0,0 +1,4 @@
1
+import { RPCInterface } from "rpclibrary"
2
+
3
+export type ItemManagerIfc = RPCInterface
4
+export type ItemManagerFeatureIfc = RPCInterface

+ 17
- 0
src/backend/Components/Raid/RPCInterface.ts 查看文件

@@ -0,0 +1,17 @@
1
+import { Raid, Signup, User } from "../../Types/Types";
2
+import { RPCInterface } from "rpclibrary";
3
+
4
+export type RaidManagerIfc = RPCInterface
5
+
6
+export type RaidManagerFeatureIfc = {
7
+    manageRaid: {
8
+        createRaid: (raid:Raid) => Promise<any>
9
+        addSignup: (signup: Signup) => Promise<any>
10
+        removeSignup: (signup: Signup) => Promise<any>    
11
+    }
12
+    signup: {
13
+        getRaids: () => Promise<Raid[]>
14
+        getSingups: (raid:Raid) => Promise<Signup[]>
15
+        sign: (user:User, raid:Raid, attending:boolean) => Promise<any>
16
+    }
17
+}

+ 4
- 4
src/backend/Components/Raid/RaidManager.ts 查看文件

@@ -1,11 +1,11 @@
1
-import { TableDefiniton, User, _Rank, Raid, Signup, RaidManagerFeatureIfc } from "../../Types/Types";
1
+import { TableDefiniton, User, _Rank, Raid, Signup } from "../../Types/Types";
2 2
 import { FrontworkAdmin } from "../../Admin/Admin";
3 3
 import { FrontworkComponent } from "../../Types/FrontworkComponent";
4
-
4
+import { RaidManagerFeatureIfc, RaidManagerIfc } from "./RPCInterface";
5 5
 
6 6
 export class RaidManager
7
-implements FrontworkComponent<any, any, RaidManagerFeatureIfc>{
8
-    name = "RaidManager";    
7
+implements FrontworkComponent<RaidManagerIfc, RaidManagerFeatureIfc>{
8
+    name = "RaidManager" as "RaidManager";    
9 9
     admin: FrontworkAdmin
10 10
 
11 11
     exportRPCs = () => []

+ 18
- 0
src/backend/Components/User/RPCInterface.ts 查看文件

@@ -0,0 +1,18 @@
1
+import { Token, Auth, User, RPCPermission } from "../../Types/Types"
2
+
3
+export type UserManagerIfc = {
4
+    Authenticator: {
5
+        login: (username:string, pwHash:string) => Promise<Token>
6
+        authenticate: (token:string | Token) => Promise<Auth>
7
+    }
8
+}
9
+
10
+export type UserManagerFeatureIfc = {
11
+    createUser: {
12
+        createUser: (user:User) => Promise<User>
13
+    }
14
+    modifyPermissions: {
15
+        setPermission: (perm: RPCPermission) => Promise<void>
16
+        getPermissions: () => Promise<RPCPermission[]>
17
+    }
18
+}

+ 4
- 9
src/backend/Components/User/UserManager.ts 查看文件

@@ -1,19 +1,14 @@
1 1
 import { RPCServer } from "rpclibrary";
2
-import { TableDefiniton, AnyRPCExporter, User, RPCPermission, _Rank, Token, Auth, FrontcraftFeatureIfc, Rank, LoginManagerFeatureIfc } from "../../Types/Types";
2
+import { TableDefiniton, AnyRPCExporter, User, RPCPermission, _Rank, Token, Auth, Rank, FrontcraftFeatureIfc } from "../../Types/Types";
3 3
 import { FrontworkAdmin } from "../../Admin/Admin";
4 4
 import { PrivilegedRPCExporter } from "../../Types/PrivilegedRPCExporter";
5 5
 import { FrontworkComponent } from "../../Types/FrontworkComponent";
6 6
 import { getSpecTableData } from "../../Types/PlayerSpecs"
7
+import { UserManagerIfc, UserManagerFeatureIfc } from "./RPCInterface";
7 8
 const uuid = require('uuid/v4')
8 9
 
9
-export type LoginManagerIfc = {
10
-    Authenticator: {
11
-        login: (username:string, pwHash:string) => Promise<Token>
12
-    }
13
-}
14
-
15 10
 export class LoginManager
16
-implements FrontworkComponent<LoginManagerFeatureIfc>{
11
+implements FrontworkComponent<UserManagerIfc, UserManagerFeatureIfc>{
17 12
     name = "Authenticator" as "Authenticator";   
18 13
     admin:FrontworkAdmin
19 14
     
@@ -124,7 +119,7 @@ implements FrontworkComponent<LoginManagerFeatureIfc>{
124 119
         const perm : RPCPermission[] = await this.admin.knex
125 120
             .select(rank)
126 121
             .from('rpcpermissions')
127
-            .where('name', '=', feature)
122
+            .where('name', '=', <string>feature)
128 123
 
129 124
         if(perm.length === 0) return false
130 125
         return perm[0][rank]

+ 2
- 1
src/backend/Launcher.ts 查看文件

@@ -12,7 +12,8 @@ let itemManager = new ItemManager()
12 12
 let guildManager = new GuildManager()
13 13
 let userManager = new LoginManager([
14 14
     raidManager,
15
-    itemManager
15
+    itemManager,
16
+    guildManager
16 17
 ])
17 18
 
18 19
 let components:FrontworkComponent[] = [ guildManager, raidManager, itemManager, userManager ]

+ 7
- 5
src/backend/Types/FrontworkComponent.ts 查看文件

@@ -1,22 +1,24 @@
1 1
 import { PrivilegedRPCExporter } from "./PrivilegedRPCExporter";
2
-import { RPCInterface, RPC, AnyFunction, RPCExporter } from "rpclibrary";
2
+import { RPCInterface, RPCExporter, RPCInterfaceArray } from "rpclibrary";
3 3
 import { TableDefinitionExporter } from "./Interfaces";
4 4
 import { FrontworkAdmin } from "../Admin/Admin";
5 5
 import { TableDefiniton } from "./Types";
6 6
 
7 7
 export interface FrontworkComponent<
8 8
     Ifc extends RPCInterface = RPCInterface, 
9
+    FeatureIfc extends RPCInterface = RPCInterface, 
9 10
     Name extends keyof Ifc = keyof Ifc, 
11
+    FeatureName extends keyof FeatureIfc = keyof FeatureIfc, 
10 12
     SubresT = {}
11 13
 > extends
12
-    PrivilegedRPCExporter<Ifc, Name, SubresT>,
14
+    PrivilegedRPCExporter<Ifc, FeatureIfc, Name, FeatureName, SubresT>,
13 15
     TableDefinitionExporter
14 16
 {
15 17
     admin:FrontworkAdmin
16
-    name: string;
18
+    name: Name;
17 19
 
18
-    exportRPCFeatures(): RPCExporter<Ifc, Name, SubresT>[] 
19
-    exportRPCs(): RPC<string, AnyFunction, {}>[] 
20
+    exportRPCFeatures(): RPCExporter<FeatureIfc, FeatureName, SubresT>[] 
21
+    exportRPCs(): RPCInterfaceArray<Ifc>[Name]
20 22
     getTableDefinitions(): TableDefiniton[] 
21 23
 
22 24
     initialize?(): Promise<any>

+ 8
- 4
src/backend/Types/PrivilegedRPCExporter.ts 查看文件

@@ -1,7 +1,11 @@
1 1
 import { RPCExporter, RPCInterface, RPC, RPCInterfaceArray } from "rpclibrary";
2 2
 
3
-export interface PrivilegedRPCExporter <Ifc extends RPCInterface = RPCInterface, Name extends keyof Ifc = keyof Ifc, SubresT = {}>
4
-extends RPCExporter<any,any>{
5
-
6
-    exportRPCFeatures() : RPCExporter<Ifc, Name, SubresT>[]
3
+export interface PrivilegedRPCExporter <
4
+    Ifc extends RPCInterface = RPCInterface, 
5
+    FeatureIfc extends RPCInterface = RPCInterface,
6
+    Name extends keyof Ifc = keyof Ifc, 
7
+    FeatureName extends keyof FeatureIfc = keyof FeatureIfc, 
8
+    SubresT = {}
9
+>extends RPCExporter<Ifc, Name>{
10
+    exportRPCFeatures() : RPCExporter<FeatureIfc, FeatureName, SubresT>[]
7 11
 }

+ 9
- 31
src/backend/Types/Types.ts 查看文件

@@ -1,5 +1,9 @@
1 1
 import * as Knex from "knex"
2 2
 import { RPCExporter } from "rpclibrary";
3
+import { RaidManagerFeatureIfc } from "../Components/Raid/RPCInterface";
4
+import { ItemManagerIfc, ItemManagerFeatureIfc } from "../Components/Item/RPCInterface";
5
+import { UserManagerIfc, UserManagerFeatureIfc } from "../Components/User/RPCInterface";
6
+
3 7
 
4 8
 export declare type NotificationSeverity = 'Info' | 'Important' | 'Error';
5 9
 
@@ -57,38 +61,12 @@ export type Token = {
57 61
 
58 62
 export type Auth = {port: number, user: User, token: Token}
59 63
 
60
-export type FrontcraftFeatureIfc =  RaidManagerFeatureIfc & LoginManagerFeatureIfc 
61
-
62
-
63
-export type LoginManagerIfc = {
64
-    Authenticator: {
65
-        login: (username:string, pwHash:string) => Promise<Token>
66
-        authenticate: (token:string | Token) => Promise<Auth>
67
-    }
68
-}
64
+export type FrontcraftIfc = UserManagerIfc 
65
+                          & ItemManagerIfc
69 66
 
70
-export type LoginManagerFeatureIfc = {
71
-    createUser: {
72
-        createUser: (user:User) => Promise<User>
73
-    }
74
-    modifyPermissions: {
75
-        setPermission: (perm: RPCPermission) => Promise<void>
76
-        getPermissions: () => Promise<RPCPermission[]>
77
-    }
78
-}
79
-
80
-export type RaidManagerFeatureIfc = {
81
-    manageRaid: {
82
-        createRaid: (raid:Raid) => Promise<any>
83
-        addSignup: (signup: Signup) => Promise<any>
84
-        removeSignup: (signup: Signup) => Promise<any>    
85
-    }
86
-    signup: {
87
-        getRaids: () => Promise<Raid[]>
88
-        getSingups: (raid:Raid) => Promise<Signup[]>
89
-        sign: (user:User, raid:Raid, attending:boolean) => Promise<any>
90
-    }
91
-}
67
+export type FrontcraftFeatureIfc = RaidManagerFeatureIfc 
68
+                                 & UserManagerFeatureIfc
69
+                                 & ItemManagerFeatureIfc
92 70
 
93 71
 export type Spec = {
94 72
     id?: number,

+ 1
- 1
src/frontend/custom-webpack.config.js 查看文件

@@ -1,4 +1,4 @@
1 1
 module.exports = {
2
-    externals: ['http'],
2
+    externals: ['http', 'fs'],
3 3
     node: {global: true, fs: 'empty'}
4 4
 }

+ 4
- 4
src/frontend/src/app/frontcraft/services/login-api.ts 查看文件

@@ -1,12 +1,12 @@
1 1
 import { Injectable } from "@angular/core";
2 2
 import {RPCSocket} from 'rpclibrary/js/src/Frontend'
3 3
 
4
-import { Token, Auth, User, _Class, FrontcraftFeatureIfc, LoginManagerIfc, SomeOf, } from '../../../../../backend/Types/Types'
4
+import { Token, Auth, User, _Class, FrontcraftFeatureIfc, SomeOf, FrontcraftIfc, } from '../../../../../backend/Types/Types'
5 5
 import { CookieService } from 'ngx-cookie-service';
6 6
 
7 7
 @Injectable()
8 8
 export class LoginApiService{
9
-    private socket:RPCSocket & LoginManagerIfc;
9
+    private socket:RPCSocket & FrontcraftIfc;
10 10
     private auth:Auth
11 11
     private privSocket: RPCSocket & SomeOf<FrontcraftFeatureIfc>
12 12
 
@@ -14,7 +14,7 @@ export class LoginApiService{
14 14
         private cookieSvc : CookieService
15 15
     ){}
16 16
 
17
-    getUnprivilegedSocket = () : RPCSocket & LoginManagerIfc => this.socket
17
+    getUnprivilegedSocket = () : RPCSocket & FrontcraftIfc => this.socket
18 18
 
19 19
     private getPrivilegedSocket = async (auth:Auth) : Promise<RPCSocket & SomeOf<FrontcraftFeatureIfc>> => {
20 20
         if(this.privSocket) return this.privSocket
@@ -85,7 +85,7 @@ export class LoginApiService{
85 85
     }
86 86
 
87 87
     initialize = async () : Promise<RPCSocket> => {
88
-        const sock = await RPCSocket.makeSocket<LoginManagerIfc>(20000, window.location.hostname)
88
+        const sock = await RPCSocket.makeSocket<FrontcraftIfc>(20000, window.location.hostname)
89 89
         this.socket = sock
90 90
 
91 91
         const cookie = this.getCookie()

Loading…
取消
儲存