@armoury/fivem-framework-server 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/server/services/session/session.service.js +0 -6
- package/dist/cjs/shared/models/index.js +1 -0
- package/dist/cjs/shared/models/session-claim.js +8 -0
- package/dist/cjs/shared/models/session.js +94 -6
- package/dist/esm/server/services/session/session.service.js +0 -6
- package/dist/esm/shared/models/index.js +1 -0
- package/dist/esm/shared/models/session-claim.js +5 -0
- package/dist/esm/shared/models/session.js +94 -6
- package/dist/types/server/services/session/session.service.d.ts +0 -2
- package/dist/types/shared/models/index.d.ts +1 -0
- package/dist/types/shared/models/session-claim.d.ts +13 -0
- package/dist/types/shared/models/session.d.ts +66 -5
- package/package.json +2 -2
|
@@ -19,12 +19,6 @@ let SessionService = class SessionService {
|
|
|
19
19
|
constructor(armouryResource) {
|
|
20
20
|
this.armouryResource = armouryResource;
|
|
21
21
|
}
|
|
22
|
-
getClaimValue(sessionId, claimName) {
|
|
23
|
-
return this.armouryResource.instance.getClaimValue(sessionId, claimName);
|
|
24
|
-
}
|
|
25
|
-
setClaim(sessionId, claimName, value) {
|
|
26
|
-
return this.armouryResource.instance.setClaim(sessionId, claimName, value);
|
|
27
|
-
}
|
|
28
22
|
getNumPlayersConnected() {
|
|
29
23
|
return this.armouryResource.instance.getNumPlayersConnected();
|
|
30
24
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionClaimType = void 0;
|
|
4
|
+
var SessionClaimType;
|
|
5
|
+
(function (SessionClaimType) {
|
|
6
|
+
SessionClaimType[SessionClaimType["Direct"] = 0] = "Direct";
|
|
7
|
+
SessionClaimType[SessionClaimType["Proxied"] = 1] = "Proxied";
|
|
8
|
+
})(SessionClaimType || (exports.SessionClaimType = SessionClaimType = {}));
|
|
@@ -1,20 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Session = void 0;
|
|
4
|
+
const session_claim_1 = require("./session-claim");
|
|
4
5
|
class Session {
|
|
5
|
-
constructor(id, platformId, lastKnownName, principal
|
|
6
|
+
constructor(id, platformId, lastKnownName, principal) {
|
|
6
7
|
this.id = id;
|
|
7
8
|
this.platformId = platformId;
|
|
8
9
|
this.lastKnownName = lastKnownName;
|
|
9
10
|
this.principal = principal;
|
|
10
|
-
this.claims = claims;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Gets the public state of a player.
|
|
14
|
+
*
|
|
15
|
+
* @param stateItemName the name of the state item to update.
|
|
16
|
+
* @returns the value from the state, or null if not found.
|
|
17
|
+
*/
|
|
18
|
+
getState(stateItemName) {
|
|
13
19
|
var _a;
|
|
14
|
-
return (_a = this.
|
|
20
|
+
return (_a = Cfx.Player(this.id).state[`session:${stateItemName}:value`]) !== null && _a !== void 0 ? _a : null;
|
|
15
21
|
}
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Updates the state of a player.
|
|
24
|
+
*
|
|
25
|
+
* **`⚠️ Warning:`** If your intention is to save data which should NOT be accessible to the
|
|
26
|
+
* client, please use `setServerClaim` instead.
|
|
27
|
+
*
|
|
28
|
+
* ---
|
|
29
|
+
*
|
|
30
|
+
* In a client script, this will always be the replicated value set by the server.
|
|
31
|
+
* In a server script, this will update the state for that player.
|
|
32
|
+
*
|
|
33
|
+
* @param stateItemName the name of the state item to update.
|
|
34
|
+
* @param value the value to set to the state.
|
|
35
|
+
* @param replicate whether to replicate this value. This will always be false in a client script.
|
|
36
|
+
* @returns the value which has been set.
|
|
37
|
+
*/
|
|
38
|
+
setState(stateItemName, value, replicate) {
|
|
39
|
+
Cfx.Player(this.id).state.set(`session:${stateItemName}:value`, value, replicate !== null && replicate !== void 0 ? replicate : Cfx.Server.IsDuplicityVersion());
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets the state of the player, where the state is data NOT accessible to the client.
|
|
44
|
+
*
|
|
45
|
+
* @param claimName the name of the claim/state item to get.
|
|
46
|
+
* @returns the value from the state, or null if not found.
|
|
47
|
+
*/
|
|
48
|
+
getServerClaimValue(claimName) {
|
|
49
|
+
var _a;
|
|
50
|
+
if (!Cfx.Server.IsDuplicityVersion()) {
|
|
51
|
+
console.error('Claims are not currently available in client scripts.');
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const claimValue = Cfx.Player(this.id).state[`session:${claimName}:value`];
|
|
55
|
+
if (claimValue == null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const kind = (_a = Cfx.Player(this.id).state[`session:${claimName}:kind`]) !== null && _a !== void 0 ? _a : session_claim_1.SessionClaimType.Direct;
|
|
59
|
+
if (kind === session_claim_1.SessionClaimType.Proxied) {
|
|
60
|
+
const proxiedValue = this.getProxiedServerClaimValue(claimName);
|
|
61
|
+
Cfx.Player(this.id).state.set(`session:${claimName}:value`, proxiedValue, false);
|
|
62
|
+
return proxiedValue;
|
|
63
|
+
}
|
|
64
|
+
return this.getState(claimName);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets proxied state of a player. This is usually state which doesn't hold
|
|
68
|
+
* primitive data types (for example, an `item`).
|
|
69
|
+
*
|
|
70
|
+
* @param claim the claim object to proxy for.
|
|
71
|
+
* @returns the value from the proxied state, or null if not found or impossible.
|
|
72
|
+
*/
|
|
73
|
+
getProxiedServerClaimValue(claimName) {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
if (!Cfx.Server.IsDuplicityVersion()) {
|
|
76
|
+
console.error('Proxied claims are not currently available in client scripts.');
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const resource = Cfx.GlobalState[`session:${claimName}:proxy`];
|
|
80
|
+
if (!resource) {
|
|
81
|
+
console.error(`There was no proxied claim registered for claim with name ${claimName}, `
|
|
82
|
+
+ 'returning null.');
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return (_b = (_a = globalThis.exports[resource]) === null || _a === void 0 ? void 0 : _a.getProxiedClaimValue(claimName, this.id)) !== null && _b !== void 0 ? _b : null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Updates the state of the player, but doesn't replicate the value to the client.
|
|
89
|
+
* Useful when you want to have data NOT accessible to the client, on the server.
|
|
90
|
+
*
|
|
91
|
+
* @param claimName the name of the claim/state item to update.
|
|
92
|
+
* @returns the updated value, or null if not found or impossible to update.
|
|
93
|
+
*/
|
|
94
|
+
setServerClaim(claimName, value) {
|
|
95
|
+
if (!Cfx.Server.IsDuplicityVersion()) {
|
|
96
|
+
console.error('Claims are not currently available in client scripts.');
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const proxy = Cfx.GlobalState[`session:${claimName}:proxy`];
|
|
100
|
+
if (proxy != null) {
|
|
101
|
+
console.error(`Attempting to set value of server claim ${claimName}, but there's a proxy registered `
|
|
102
|
+
+ 'for it. Returning null, and doing nothing.');
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
this.setState(claimName, value, false);
|
|
18
106
|
return value;
|
|
19
107
|
}
|
|
20
108
|
}
|
|
@@ -16,12 +16,6 @@ let SessionService = class SessionService {
|
|
|
16
16
|
constructor(armouryResource) {
|
|
17
17
|
this.armouryResource = armouryResource;
|
|
18
18
|
}
|
|
19
|
-
getClaimValue(sessionId, claimName) {
|
|
20
|
-
return this.armouryResource.instance.getClaimValue(sessionId, claimName);
|
|
21
|
-
}
|
|
22
|
-
setClaim(sessionId, claimName, value) {
|
|
23
|
-
return this.armouryResource.instance.setClaim(sessionId, claimName, value);
|
|
24
|
-
}
|
|
25
19
|
getNumPlayersConnected() {
|
|
26
20
|
return this.armouryResource.instance.getNumPlayersConnected();
|
|
27
21
|
}
|
|
@@ -1,17 +1,105 @@
|
|
|
1
|
+
import { SessionClaimType } from './session-claim';
|
|
1
2
|
export class Session {
|
|
2
|
-
constructor(id, platformId, lastKnownName, principal
|
|
3
|
+
constructor(id, platformId, lastKnownName, principal) {
|
|
3
4
|
this.id = id;
|
|
4
5
|
this.platformId = platformId;
|
|
5
6
|
this.lastKnownName = lastKnownName;
|
|
6
7
|
this.principal = principal;
|
|
7
|
-
this.claims = claims;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Gets the public state of a player.
|
|
11
|
+
*
|
|
12
|
+
* @param stateItemName the name of the state item to update.
|
|
13
|
+
* @returns the value from the state, or null if not found.
|
|
14
|
+
*/
|
|
15
|
+
getState(stateItemName) {
|
|
10
16
|
var _a;
|
|
11
|
-
return (_a = this.
|
|
17
|
+
return (_a = Cfx.Player(this.id).state[`session:${stateItemName}:value`]) !== null && _a !== void 0 ? _a : null;
|
|
12
18
|
}
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Updates the state of a player.
|
|
21
|
+
*
|
|
22
|
+
* **`⚠️ Warning:`** If your intention is to save data which should NOT be accessible to the
|
|
23
|
+
* client, please use `setServerClaim` instead.
|
|
24
|
+
*
|
|
25
|
+
* ---
|
|
26
|
+
*
|
|
27
|
+
* In a client script, this will always be the replicated value set by the server.
|
|
28
|
+
* In a server script, this will update the state for that player.
|
|
29
|
+
*
|
|
30
|
+
* @param stateItemName the name of the state item to update.
|
|
31
|
+
* @param value the value to set to the state.
|
|
32
|
+
* @param replicate whether to replicate this value. This will always be false in a client script.
|
|
33
|
+
* @returns the value which has been set.
|
|
34
|
+
*/
|
|
35
|
+
setState(stateItemName, value, replicate) {
|
|
36
|
+
Cfx.Player(this.id).state.set(`session:${stateItemName}:value`, value, replicate !== null && replicate !== void 0 ? replicate : Cfx.Server.IsDuplicityVersion());
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the state of the player, where the state is data NOT accessible to the client.
|
|
41
|
+
*
|
|
42
|
+
* @param claimName the name of the claim/state item to get.
|
|
43
|
+
* @returns the value from the state, or null if not found.
|
|
44
|
+
*/
|
|
45
|
+
getServerClaimValue(claimName) {
|
|
46
|
+
var _a;
|
|
47
|
+
if (!Cfx.Server.IsDuplicityVersion()) {
|
|
48
|
+
console.error('Claims are not currently available in client scripts.');
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const claimValue = Cfx.Player(this.id).state[`session:${claimName}:value`];
|
|
52
|
+
if (claimValue == null) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const kind = (_a = Cfx.Player(this.id).state[`session:${claimName}:kind`]) !== null && _a !== void 0 ? _a : SessionClaimType.Direct;
|
|
56
|
+
if (kind === SessionClaimType.Proxied) {
|
|
57
|
+
const proxiedValue = this.getProxiedServerClaimValue(claimName);
|
|
58
|
+
Cfx.Player(this.id).state.set(`session:${claimName}:value`, proxiedValue, false);
|
|
59
|
+
return proxiedValue;
|
|
60
|
+
}
|
|
61
|
+
return this.getState(claimName);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets proxied state of a player. This is usually state which doesn't hold
|
|
65
|
+
* primitive data types (for example, an `item`).
|
|
66
|
+
*
|
|
67
|
+
* @param claim the claim object to proxy for.
|
|
68
|
+
* @returns the value from the proxied state, or null if not found or impossible.
|
|
69
|
+
*/
|
|
70
|
+
getProxiedServerClaimValue(claimName) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
if (!Cfx.Server.IsDuplicityVersion()) {
|
|
73
|
+
console.error('Proxied claims are not currently available in client scripts.');
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const resource = Cfx.GlobalState[`session:${claimName}:proxy`];
|
|
77
|
+
if (!resource) {
|
|
78
|
+
console.error(`There was no proxied claim registered for claim with name ${claimName}, `
|
|
79
|
+
+ 'returning null.');
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return (_b = (_a = globalThis.exports[resource]) === null || _a === void 0 ? void 0 : _a.getProxiedClaimValue(claimName, this.id)) !== null && _b !== void 0 ? _b : null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Updates the state of the player, but doesn't replicate the value to the client.
|
|
86
|
+
* Useful when you want to have data NOT accessible to the client, on the server.
|
|
87
|
+
*
|
|
88
|
+
* @param claimName the name of the claim/state item to update.
|
|
89
|
+
* @returns the updated value, or null if not found or impossible to update.
|
|
90
|
+
*/
|
|
91
|
+
setServerClaim(claimName, value) {
|
|
92
|
+
if (!Cfx.Server.IsDuplicityVersion()) {
|
|
93
|
+
console.error('Claims are not currently available in client scripts.');
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const proxy = Cfx.GlobalState[`session:${claimName}:proxy`];
|
|
97
|
+
if (proxy != null) {
|
|
98
|
+
console.error(`Attempting to set value of server claim ${claimName}, but there's a proxy registered `
|
|
99
|
+
+ 'for it. Returning null, and doing nothing.');
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
this.setState(claimName, value, false);
|
|
15
103
|
return value;
|
|
16
104
|
}
|
|
17
105
|
}
|
|
@@ -2,8 +2,6 @@ import { ResourceRef, Session } from '@armoury/fivem-framework-common';
|
|
|
2
2
|
export declare class SessionService {
|
|
3
3
|
private readonly armouryResource;
|
|
4
4
|
constructor(armouryResource: ResourceRef);
|
|
5
|
-
getClaimValue<T>(sessionId: number, claimName: string): T | null;
|
|
6
|
-
setClaim<T>(sessionId: number, claimName: string, value: T): T | null;
|
|
7
5
|
getNumPlayersConnected(): number;
|
|
8
6
|
getAllPlayerIds(): number[];
|
|
9
7
|
getAllPlayerPrincipals(): number[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface SessionDirectClaim<TVal = unknown> {
|
|
2
|
+
$kind: SessionClaimType.Direct;
|
|
3
|
+
cachedValue: TVal;
|
|
4
|
+
}
|
|
5
|
+
export interface SessionProxiedClaim {
|
|
6
|
+
$kind: SessionClaimType.Proxied;
|
|
7
|
+
resource: string;
|
|
8
|
+
}
|
|
9
|
+
export type SessionClaim<TVal = unknown> = SessionDirectClaim<TVal> | SessionProxiedClaim;
|
|
10
|
+
export declare enum SessionClaimType {
|
|
11
|
+
Direct = 0,
|
|
12
|
+
Proxied = 1
|
|
13
|
+
}
|
|
@@ -1,17 +1,78 @@
|
|
|
1
1
|
export interface Session {
|
|
2
|
+
/**
|
|
3
|
+
* The session ID, which always matches the server ID of a
|
|
4
|
+
* player.
|
|
5
|
+
*/
|
|
2
6
|
readonly id: number;
|
|
7
|
+
/**
|
|
8
|
+
* The platform identifier for this player. Most often, this
|
|
9
|
+
* will be the FiveM identifier for a player.
|
|
10
|
+
*/
|
|
3
11
|
readonly platformId: string;
|
|
12
|
+
/**
|
|
13
|
+
* The name this player has most recently used when logging in.
|
|
14
|
+
* NEVER trust this value - it can change with every reconnect.
|
|
15
|
+
*/
|
|
4
16
|
readonly lastKnownName: string;
|
|
17
|
+
/**
|
|
18
|
+
* The principal of a session. Most often, this will be the
|
|
19
|
+
* account ID of that player.
|
|
20
|
+
*/
|
|
5
21
|
principal?: number;
|
|
6
|
-
readonly claims: Record<string, unknown>;
|
|
7
22
|
}
|
|
8
23
|
export declare class Session {
|
|
9
24
|
readonly id: number;
|
|
10
25
|
readonly platformId: string;
|
|
11
26
|
readonly lastKnownName: string;
|
|
12
27
|
principal?: number | undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
constructor(id: number, platformId: string, lastKnownName: string, principal?: number | undefined);
|
|
29
|
+
/**
|
|
30
|
+
* Gets the public state of a player.
|
|
31
|
+
*
|
|
32
|
+
* @param stateItemName the name of the state item to update.
|
|
33
|
+
* @returns the value from the state, or null if not found.
|
|
34
|
+
*/
|
|
35
|
+
getState<T>(stateItemName: string): T | null;
|
|
36
|
+
/**
|
|
37
|
+
* Updates the state of a player.
|
|
38
|
+
*
|
|
39
|
+
* **`⚠️ Warning:`** If your intention is to save data which should NOT be accessible to the
|
|
40
|
+
* client, please use `setServerClaim` instead.
|
|
41
|
+
*
|
|
42
|
+
* ---
|
|
43
|
+
*
|
|
44
|
+
* In a client script, this will always be the replicated value set by the server.
|
|
45
|
+
* In a server script, this will update the state for that player.
|
|
46
|
+
*
|
|
47
|
+
* @param stateItemName the name of the state item to update.
|
|
48
|
+
* @param value the value to set to the state.
|
|
49
|
+
* @param replicate whether to replicate this value. This will always be false in a client script.
|
|
50
|
+
* @returns the value which has been set.
|
|
51
|
+
*/
|
|
52
|
+
setState<T extends Primitive>(stateItemName: string, value: T, replicate?: boolean): T | null;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the state of the player, where the state is data NOT accessible to the client.
|
|
55
|
+
*
|
|
56
|
+
* @param claimName the name of the claim/state item to get.
|
|
57
|
+
* @returns the value from the state, or null if not found.
|
|
58
|
+
*/
|
|
59
|
+
getServerClaimValue<T>(claimName: string): T | null;
|
|
60
|
+
/**
|
|
61
|
+
* Gets proxied state of a player. This is usually state which doesn't hold
|
|
62
|
+
* primitive data types (for example, an `item`).
|
|
63
|
+
*
|
|
64
|
+
* @param claim the claim object to proxy for.
|
|
65
|
+
* @returns the value from the proxied state, or null if not found or impossible.
|
|
66
|
+
*/
|
|
67
|
+
private getProxiedServerClaimValue;
|
|
68
|
+
/**
|
|
69
|
+
* Updates the state of the player, but doesn't replicate the value to the client.
|
|
70
|
+
* Useful when you want to have data NOT accessible to the client, on the server.
|
|
71
|
+
*
|
|
72
|
+
* @param claimName the name of the claim/state item to update.
|
|
73
|
+
* @returns the updated value, or null if not found or impossible to update.
|
|
74
|
+
*/
|
|
75
|
+
setServerClaim<T extends Primitive>(claimName: string, value: T): T | null;
|
|
17
76
|
}
|
|
77
|
+
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
78
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armoury/fivem-framework-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "Server APIs for the Armoury FiveM framework",
|
|
5
5
|
"main": "dist/cjs/server/index.js",
|
|
6
6
|
"module": "dist/esm/server/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"rxjs": "^7.8.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@armoury/fivem-framework-common": "1.0.
|
|
30
|
+
"@armoury/fivem-framework-common": "1.0.27"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|