@funfair-works/ggs-protocol 0.0.1
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/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/protocol.d.ts +171 -0
- package/lib/protocol.js +69 -0
- package/package.json +18 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export declare enum MessageId {
|
|
2
|
+
/**
|
|
3
|
+
* 列出所有游戏房间。
|
|
4
|
+
* @sender client
|
|
5
|
+
*/
|
|
6
|
+
listRooms = "listRooms",
|
|
7
|
+
/**
|
|
8
|
+
* 创建游戏房间。
|
|
9
|
+
* @sender client
|
|
10
|
+
*/
|
|
11
|
+
createRoom = "createRoom",
|
|
12
|
+
/**
|
|
13
|
+
* 请求加入游戏。
|
|
14
|
+
* @sender client
|
|
15
|
+
*/
|
|
16
|
+
requestJoinRoom = "requestJoinRoom",
|
|
17
|
+
/**
|
|
18
|
+
* 请求加入游戏响应。
|
|
19
|
+
* @sender server
|
|
20
|
+
*/
|
|
21
|
+
requestJoinRoomResponse = "requestJoinResponse",
|
|
22
|
+
/**
|
|
23
|
+
* 玩家加入。
|
|
24
|
+
* @sender server
|
|
25
|
+
*/
|
|
26
|
+
playerJoinRoom = "playerJoin",
|
|
27
|
+
/**
|
|
28
|
+
* 请求离开游戏。
|
|
29
|
+
* @sender client
|
|
30
|
+
*/
|
|
31
|
+
requestLeaveRoom = "requestLeave",
|
|
32
|
+
/**
|
|
33
|
+
* 玩家离开。
|
|
34
|
+
* @sender server
|
|
35
|
+
*/
|
|
36
|
+
playerLeaveRoom = "playerLeave",
|
|
37
|
+
/**
|
|
38
|
+
* 单播。
|
|
39
|
+
* @sender client
|
|
40
|
+
*/
|
|
41
|
+
unicast = "unicast",
|
|
42
|
+
/**
|
|
43
|
+
* 广播。
|
|
44
|
+
* @sender client
|
|
45
|
+
*/
|
|
46
|
+
broadcast = "broadcast",
|
|
47
|
+
/**
|
|
48
|
+
* 消息响应。
|
|
49
|
+
* @sender server
|
|
50
|
+
*/
|
|
51
|
+
messageReceived = "messageReceived",
|
|
52
|
+
/**
|
|
53
|
+
* 服务器错误。
|
|
54
|
+
*/
|
|
55
|
+
serverError = "serverError"
|
|
56
|
+
}
|
|
57
|
+
export type CustomData = Uint8Array | string;
|
|
58
|
+
export interface MessageMap {
|
|
59
|
+
[MessageId.listRooms]: {};
|
|
60
|
+
[MessageId.createRoom]: {
|
|
61
|
+
secret?: string;
|
|
62
|
+
payload: CustomData;
|
|
63
|
+
};
|
|
64
|
+
[MessageId.requestJoinRoom]: {
|
|
65
|
+
roomId: number;
|
|
66
|
+
payload: CustomData;
|
|
67
|
+
};
|
|
68
|
+
[MessageId.requestJoinRoomResponse]: {
|
|
69
|
+
playerIdInRoom: number;
|
|
70
|
+
payload: CustomData;
|
|
71
|
+
room: GameRoom;
|
|
72
|
+
};
|
|
73
|
+
[MessageId.playerJoinRoom]: {
|
|
74
|
+
playerIdInRoom: number;
|
|
75
|
+
name: string;
|
|
76
|
+
debug?: {
|
|
77
|
+
clientId: number;
|
|
78
|
+
};
|
|
79
|
+
payload: CustomData;
|
|
80
|
+
};
|
|
81
|
+
[MessageId.requestLeaveRoom]: {};
|
|
82
|
+
[MessageId.playerLeaveRoom]: {
|
|
83
|
+
playerIdInRoom: number;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* 单播。
|
|
87
|
+
* @sender client
|
|
88
|
+
*/
|
|
89
|
+
[MessageId.unicast]: {
|
|
90
|
+
receiver: number;
|
|
91
|
+
data: CustomData;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* 单播响应。
|
|
95
|
+
* @sender server
|
|
96
|
+
*/
|
|
97
|
+
[MessageId.messageReceived]: {
|
|
98
|
+
sender: number;
|
|
99
|
+
data: CustomData;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* 广播。
|
|
103
|
+
* @sender client
|
|
104
|
+
*/
|
|
105
|
+
[MessageId.broadcast]: {
|
|
106
|
+
excepts?: number[];
|
|
107
|
+
data: CustomData;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* 消息。
|
|
111
|
+
* @sender client
|
|
112
|
+
*/
|
|
113
|
+
[MessageId.serverError]: {
|
|
114
|
+
code: number;
|
|
115
|
+
message: string;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export interface RPCMap {
|
|
119
|
+
[MessageId.listRooms]: {
|
|
120
|
+
rooms: GameRoom[];
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export type Message<T extends MessageId> = MessageMap[T];
|
|
124
|
+
export type ResponseMessage<T extends keyof RPCMap> = RPCMap[T];
|
|
125
|
+
export type RequestingMessageId = keyof RPCMap;
|
|
126
|
+
export interface GameRoom {
|
|
127
|
+
id: number;
|
|
128
|
+
players: Array<{
|
|
129
|
+
id: number;
|
|
130
|
+
name: string;
|
|
131
|
+
}>;
|
|
132
|
+
secret?: string;
|
|
133
|
+
payload?: CustomData;
|
|
134
|
+
maxPlayers: number;
|
|
135
|
+
owner: number;
|
|
136
|
+
}
|
|
137
|
+
export declare enum ServerErrorCode {
|
|
138
|
+
unknown = 0
|
|
139
|
+
}
|
|
140
|
+
export declare enum MessageEnvelopType {
|
|
141
|
+
notification = 0,
|
|
142
|
+
request = 1,
|
|
143
|
+
response = 2,
|
|
144
|
+
requestException = 3
|
|
145
|
+
}
|
|
146
|
+
export interface EnvelopBase {
|
|
147
|
+
__stack__?: string;
|
|
148
|
+
}
|
|
149
|
+
export type RequestEnvelop<T extends RequestingMessageId> = {
|
|
150
|
+
type: MessageEnvelopType.request;
|
|
151
|
+
requestId: number;
|
|
152
|
+
messageId: T;
|
|
153
|
+
message: Message<T>;
|
|
154
|
+
} & EnvelopBase;
|
|
155
|
+
export type ResponseEnvelop<T extends RequestingMessageId> = {
|
|
156
|
+
type: MessageEnvelopType.response;
|
|
157
|
+
requestId: number;
|
|
158
|
+
message: ResponseMessage<T>;
|
|
159
|
+
} & EnvelopBase;
|
|
160
|
+
export type RequestExceptionEnvelop = {
|
|
161
|
+
type: MessageEnvelopType.requestException;
|
|
162
|
+
requestId: number;
|
|
163
|
+
errorMessage: string;
|
|
164
|
+
} & EnvelopBase;
|
|
165
|
+
export type NotificationEnvelop<TMessageId extends MessageId> = {
|
|
166
|
+
type: MessageEnvelopType.notification;
|
|
167
|
+
messageId: TMessageId;
|
|
168
|
+
message: Message<TMessageId>;
|
|
169
|
+
} & EnvelopBase;
|
|
170
|
+
export type MessageEnvelop = RequestEnvelop<RequestingMessageId> | ResponseEnvelop<RequestingMessageId> | RequestExceptionEnvelop | NotificationEnvelop<MessageId>;
|
|
171
|
+
//# sourceMappingURL=protocol.d.ts.map
|
package/lib/protocol.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export var MessageId;
|
|
2
|
+
(function (MessageId) {
|
|
3
|
+
/**
|
|
4
|
+
* 列出所有游戏房间。
|
|
5
|
+
* @sender client
|
|
6
|
+
*/
|
|
7
|
+
MessageId["listRooms"] = "listRooms";
|
|
8
|
+
/**
|
|
9
|
+
* 创建游戏房间。
|
|
10
|
+
* @sender client
|
|
11
|
+
*/
|
|
12
|
+
MessageId["createRoom"] = "createRoom";
|
|
13
|
+
/**
|
|
14
|
+
* 请求加入游戏。
|
|
15
|
+
* @sender client
|
|
16
|
+
*/
|
|
17
|
+
MessageId["requestJoinRoom"] = "requestJoinRoom";
|
|
18
|
+
/**
|
|
19
|
+
* 请求加入游戏响应。
|
|
20
|
+
* @sender server
|
|
21
|
+
*/
|
|
22
|
+
MessageId["requestJoinRoomResponse"] = "requestJoinResponse";
|
|
23
|
+
/**
|
|
24
|
+
* 玩家加入。
|
|
25
|
+
* @sender server
|
|
26
|
+
*/
|
|
27
|
+
MessageId["playerJoinRoom"] = "playerJoin";
|
|
28
|
+
/**
|
|
29
|
+
* 请求离开游戏。
|
|
30
|
+
* @sender client
|
|
31
|
+
*/
|
|
32
|
+
MessageId["requestLeaveRoom"] = "requestLeave";
|
|
33
|
+
/**
|
|
34
|
+
* 玩家离开。
|
|
35
|
+
* @sender server
|
|
36
|
+
*/
|
|
37
|
+
MessageId["playerLeaveRoom"] = "playerLeave";
|
|
38
|
+
/**
|
|
39
|
+
* 单播。
|
|
40
|
+
* @sender client
|
|
41
|
+
*/
|
|
42
|
+
MessageId["unicast"] = "unicast";
|
|
43
|
+
/**
|
|
44
|
+
* 广播。
|
|
45
|
+
* @sender client
|
|
46
|
+
*/
|
|
47
|
+
MessageId["broadcast"] = "broadcast";
|
|
48
|
+
/**
|
|
49
|
+
* 消息响应。
|
|
50
|
+
* @sender server
|
|
51
|
+
*/
|
|
52
|
+
MessageId["messageReceived"] = "messageReceived";
|
|
53
|
+
/**
|
|
54
|
+
* 服务器错误。
|
|
55
|
+
*/
|
|
56
|
+
MessageId["serverError"] = "serverError";
|
|
57
|
+
})(MessageId || (MessageId = {}));
|
|
58
|
+
export var ServerErrorCode;
|
|
59
|
+
(function (ServerErrorCode) {
|
|
60
|
+
ServerErrorCode[ServerErrorCode["unknown"] = 0] = "unknown";
|
|
61
|
+
})(ServerErrorCode || (ServerErrorCode = {}));
|
|
62
|
+
export var MessageEnvelopType;
|
|
63
|
+
(function (MessageEnvelopType) {
|
|
64
|
+
MessageEnvelopType[MessageEnvelopType["notification"] = 0] = "notification";
|
|
65
|
+
MessageEnvelopType[MessageEnvelopType["request"] = 1] = "request";
|
|
66
|
+
MessageEnvelopType[MessageEnvelopType["response"] = 2] = "response";
|
|
67
|
+
MessageEnvelopType[MessageEnvelopType["requestException"] = 3] = "requestException";
|
|
68
|
+
})(MessageEnvelopType || (MessageEnvelopType = {}));
|
|
69
|
+
//# sourceMappingURL=protocol.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@funfair-works/ggs-protocol",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib",
|
|
7
|
+
"!lib/**/*.map"
|
|
8
|
+
],
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"prepublishOnly": "pnpm exec tsc --build --clean && npm run build",
|
|
15
|
+
"build": "pnpm exec tsc -b",
|
|
16
|
+
"dev": "pnpm exec tsc -b -w"
|
|
17
|
+
}
|
|
18
|
+
}
|