dfx 0.0.1 → 0.0.2
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/DiscordREST/types.js +6 -0
- package/DiscordREST/types.js.map +1 -0
- package/DiscordWS/index.js +2 -0
- package/DiscordWS/index.js.map +1 -0
- package/README.md +3 -0
- package/WS/index.js +71 -0
- package/WS/index.js.map +1 -0
- package/discord-api-docs/index.js +1 -0
- package/mod.js.map +1 -0
- package/package.json +6 -1
- package/types.js +1563 -0
- package/types.js.map +1 -0
- package/websocket.js +11 -0
- package/websocket.js.map +1 -0
- package/.gitmodules +0 -3
- package/.prettierrc.json +0 -4
- package/discord-api-docs/.eslintrc.json +0 -10
- package/discord-api-docs/.gitattributes +0 -11
- package/discord-api-docs/.github/ISSUE_TEMPLATE/api-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/config.yml +0 -20
- package/discord-api-docs/.github/ISSUE_TEMPLATE/developer-site-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/message-components-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/slash-command-bug-report.yml +0 -49
- package/discord-api-docs/.github/workflows/test.yaml +0 -45
- package/discord-api-docs/.prettierignore +0 -1
- package/discord-api-docs/.prettierrc.json +0 -15
- package/discord-api-docs/CODE_OF_CONDUCT.md +0 -75
- package/discord-api-docs/CONTRIBUTING.md +0 -16
- package/discord-api-docs/README.md +0 -35
- package/discord-api-docs/docs/Change_Log.md +0 -474
- package/discord-api-docs/docs/Intro.md +0 -48
- package/discord-api-docs/docs/Legal.md +0 -154
- package/discord-api-docs/docs/Policy.md +0 -81
- package/discord-api-docs/docs/Reference.md +0 -476
- package/discord-api-docs/docs/Store_Distribution_Agreement.md +0 -179
- package/discord-api-docs/docs/dispatch/Branches_and_Builds.md +0 -654
- package/discord-api-docs/docs/dispatch/Dispatch_and_You.md +0 -17
- package/discord-api-docs/docs/dispatch/Error_Codes.md +0 -26
- package/discord-api-docs/docs/dispatch/Field_Values.md +0 -48
- package/discord-api-docs/docs/dispatch/List_of_Commands.md +0 -315
- package/discord-api-docs/docs/game_and_server_management/Alpha_and_Beta_Testing.md +0 -52
- package/discord-api-docs/docs/game_and_server_management/How_to_Get_Your_Game_on_Discord.md +0 -110
- package/discord-api-docs/docs/game_and_server_management/Special_Channels.md +0 -38
- package/discord-api-docs/docs/game_sdk/Achievements.md +0 -405
- package/discord-api-docs/docs/game_sdk/Activities.md +0 -561
- package/discord-api-docs/docs/game_sdk/Applications.md +0 -237
- package/discord-api-docs/docs/game_sdk/Discord.md +0 -443
- package/discord-api-docs/docs/game_sdk/Discord_Voice.md +0 -289
- package/discord-api-docs/docs/game_sdk/Images.md +0 -196
- package/discord-api-docs/docs/game_sdk/Lobbies.md +0 -1639
- package/discord-api-docs/docs/game_sdk/Networking.md +0 -377
- package/discord-api-docs/docs/game_sdk/Overlay.md +0 -195
- package/discord-api-docs/docs/game_sdk/Relationships.md +0 -234
- package/discord-api-docs/docs/game_sdk/SDK_Starter_Guide.md +0 -310
- package/discord-api-docs/docs/game_sdk/Storage.md +0 -312
- package/discord-api-docs/docs/game_sdk/Store.md +0 -555
- package/discord-api-docs/docs/game_sdk/Users.md +0 -178
- package/discord-api-docs/docs/interactions/Application_Commands.md +0 -1069
- package/discord-api-docs/docs/interactions/Message_Components.md +0 -454
- package/discord-api-docs/docs/interactions/Receiving_and_Responding.md +0 -372
- package/discord-api-docs/docs/interactions/Slash_Commands.md +0 -3
- package/discord-api-docs/docs/resources/Application.md +0 -82
- package/discord-api-docs/docs/resources/Audit_Log.md +0 -223
- package/discord-api-docs/docs/resources/Channel.md +0 -1267
- package/discord-api-docs/docs/resources/Emoji.md +0 -122
- package/discord-api-docs/docs/resources/Guild.md +0 -1157
- package/discord-api-docs/docs/resources/Guild_Scheduled_Event.md +0 -273
- package/discord-api-docs/docs/resources/Guild_Template.md +0 -148
- package/discord-api-docs/docs/resources/Invite.md +0 -150
- package/discord-api-docs/docs/resources/Stage_Instance.md +0 -106
- package/discord-api-docs/docs/resources/Sticker.md +0 -164
- package/discord-api-docs/docs/resources/User.md +0 -205
- package/discord-api-docs/docs/resources/Voice.md +0 -55
- package/discord-api-docs/docs/resources/Webhook.md +0 -281
- package/discord-api-docs/docs/rich_presence/Best_Practices.md +0 -88
- package/discord-api-docs/docs/rich_presence/FAQ.md +0 -45
- package/discord-api-docs/docs/rich_presence/How_To.md +0 -302
- package/discord-api-docs/docs/rich_presence/Launch_Checklist.md +0 -46
- package/discord-api-docs/docs/topics/Certified_Devices.md +0 -200
- package/discord-api-docs/docs/topics/Community_Resources.md +0 -98
- package/discord-api-docs/docs/topics/Gateway.md +0 -1600
- package/discord-api-docs/docs/topics/OAuth2.md +0 -427
- package/discord-api-docs/docs/topics/Opcodes_and_Status_Codes.md +0 -306
- package/discord-api-docs/docs/topics/Permissions.md +0 -229
- package/discord-api-docs/docs/topics/RPC.md +0 -1597
- package/discord-api-docs/docs/topics/Rate_Limits.md +0 -126
- package/discord-api-docs/docs/topics/Teams.md +0 -80
- package/discord-api-docs/docs/topics/Threads.md +0 -163
- package/discord-api-docs/docs/topics/Voice_Connections.md +0 -282
- package/discord-api-docs/images/API_center.gif +0 -0
- package/discord-api-docs/images/ask-to-join.gif +0 -0
- package/discord-api-docs/images/available-published.png +0 -0
- package/discord-api-docs/images/button-styles.png +0 -0
- package/discord-api-docs/images/certified-device.png +0 -0
- package/discord-api-docs/images/command-with-groups-subcommands-parameters.png +0 -0
- package/discord-api-docs/images/command-with-groups-subcommands.png +0 -0
- package/discord-api-docs/images/command.png +0 -0
- package/discord-api-docs/images/cpp-files-sdk.png +0 -0
- package/discord-api-docs/images/create-store-channel.png +0 -0
- package/discord-api-docs/images/deferred-example.png +0 -0
- package/discord-api-docs/images/desktop-select.png +0 -0
- package/discord-api-docs/images/game-overlay-sdk-invite.gif +0 -0
- package/discord-api-docs/images/game-overlay-sdk-voice-settings.png +0 -0
- package/discord-api-docs/images/game-overlay-sdk-voice-widget.png +0 -0
- package/discord-api-docs/images/gift-code-creation.png +0 -0
- package/discord-api-docs/images/lib-linked-sdk.png +0 -0
- package/discord-api-docs/images/message-command.png +0 -0
- package/discord-api-docs/images/mobile-select.png +0 -0
- package/discord-api-docs/images/previous-new-server-background.png +0 -0
- package/discord-api-docs/images/rp-actionable.png +0 -0
- package/discord-api-docs/images/rp-all-fields.png +0 -0
- package/discord-api-docs/images/rp-bad-art.png +0 -0
- package/discord-api-docs/images/rp-good-art.png +0 -0
- package/discord-api-docs/images/rp-legend.png +0 -0
- package/discord-api-docs/images/rp-long-strings.png +0 -0
- package/discord-api-docs/images/rp-non-actionable.png +0 -0
- package/discord-api-docs/images/rp-not-all-fields.png +0 -0
- package/discord-api-docs/images/rp-profile-example-1.png +0 -0
- package/discord-api-docs/images/rp-profile-example-2.png +0 -0
- package/discord-api-docs/images/rp-short-strings.png +0 -0
- package/discord-api-docs/images/server-banner-example.png +0 -0
- package/discord-api-docs/images/server-banner-margin-top.png +0 -0
- package/discord-api-docs/images/sku-management.png +0 -0
- package/discord-api-docs/images/snowflake.png +0 -0
- package/discord-api-docs/images/snowflake_original_size.png +0 -0
- package/discord-api-docs/images/spectate.gif +0 -0
- package/discord-api-docs/images/team-2fa.png +0 -0
- package/discord-api-docs/images/team-make-app.png +0 -0
- package/discord-api-docs/images/team-page.png +0 -0
- package/discord-api-docs/images/transfer-app-to-team.png +0 -0
- package/discord-api-docs/images/user-command.png +0 -0
- package/discord-api-docs/package-lock.json +0 -3186
- package/discord-api-docs/package.json +0 -38
- package/discord-api-docs/tsconfig.eslint.json +0 -4
- package/discord-api-docs/tsconfig.json +0 -19
- package/tsconfig.json +0 -24
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
# Networking
|
|
2
|
-
|
|
3
|
-
> info
|
|
4
|
-
> Need help with the SDK? Talk to us in the [Discord Developers Server](https://discord.gg/discord-developers)!
|
|
5
|
-
|
|
6
|
-
> danger
|
|
7
|
-
> Selling SKUs on Discord is now deprecated, and will be discontinued on March 1, 2022. [Read here for more info.](https://support-dev.discord.com/hc/en-us/articles/4414590563479)
|
|
8
|
-
|
|
9
|
-
A note before starting: this documentation covers the "low layer" networking level of the Discord GameSDK. What that means is that using the network manager directly affords you the flexibility to update routes, open channels, and handle events directly emitted by the SDK. If you're looking for something a bit easier and faster to integrate, we recommend that you check out the networking wrapper around our lobby documentation: [Integrated Networking](#DOCS_GAME_SDK_LOBBIES/integrated-networking)
|
|
10
|
-
|
|
11
|
-
Need a networking layer? Have a networking layer! This manager handles all things packets so you can get data from player to player and make your multiplayer...work. It:
|
|
12
|
-
|
|
13
|
-
- Functions as a connection-oriented, TCP-like API, but over UDP!
|
|
14
|
-
- Supports "reliable" and "unreliable" connections
|
|
15
|
-
- Packets with loot in them always get there, but player positioning can be eventually consistent
|
|
16
|
-
- Features P2P-like connections, but routed through Discord's high-end server infrastructure
|
|
17
|
-
- All the benefits of direct connections, without the IP leaks!
|
|
18
|
-
- Is encrypted!
|
|
19
|
-
|
|
20
|
-
An important note to make here is that our networking layer **is not peer-to-peer**. Discord has always promised that we will not leak your IP, and we promise to keep it that way. Though it seems like you are connected directly to another user, it routes through Discord's servers in the middle, ensuring both security and robust networking thanks to our servers.
|
|
21
|
-
|
|
22
|
-
## GetPeerId
|
|
23
|
-
|
|
24
|
-
Get the networking peer ID for the current user, allowing other users to send packets to them.
|
|
25
|
-
|
|
26
|
-
Returns a `UInt64`.
|
|
27
|
-
|
|
28
|
-
###### Parameters
|
|
29
|
-
|
|
30
|
-
None
|
|
31
|
-
|
|
32
|
-
###### Example
|
|
33
|
-
|
|
34
|
-
```cs
|
|
35
|
-
var myPeerId = networkManager.GetPeerId();
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Flush
|
|
39
|
-
|
|
40
|
-
Flushes the network. Run this at the end of your game's loop, once you've finished sending all you need to send. In Unity, for example, stick this in `LateUpdate()`.
|
|
41
|
-
|
|
42
|
-
Returns `void`.
|
|
43
|
-
|
|
44
|
-
###### Parameters
|
|
45
|
-
|
|
46
|
-
None
|
|
47
|
-
|
|
48
|
-
###### Example
|
|
49
|
-
|
|
50
|
-
```cs
|
|
51
|
-
void LateUpdate()
|
|
52
|
-
{
|
|
53
|
-
networkManager.Flush();
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## OpenChannel
|
|
58
|
-
|
|
59
|
-
Opens a channel to a user with their given peer ID on the given channel number.
|
|
60
|
-
|
|
61
|
-
Unreliable channels—`reliable = false`—should be used for loss-tolerant data, like player positioning in the world. Reliable channels—`reliable = true`—should be used for data that _must_ get to the user, like loot drops!
|
|
62
|
-
|
|
63
|
-
Returns `void`.
|
|
64
|
-
|
|
65
|
-
###### Parameters
|
|
66
|
-
|
|
67
|
-
| name | type | description |
|
|
68
|
-
| --------- | ------ | ---------------------------------------------------- |
|
|
69
|
-
| peerId | UInt64 | the peerId of the user to connect to |
|
|
70
|
-
| channelId | byte | the channel on which to connect |
|
|
71
|
-
| reliable | bool | whether the channel should be unreliable or reliable |
|
|
72
|
-
|
|
73
|
-
###### Example
|
|
74
|
-
|
|
75
|
-
```cs
|
|
76
|
-
var userId = 53908232506183680;
|
|
77
|
-
var lobbyId = 290926798626357250;
|
|
78
|
-
|
|
79
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.peer_id");
|
|
80
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
81
|
-
var peerId = System.Convert.ToUInt64(rawPeerId);
|
|
82
|
-
networkManager.OpenChannel(peerId, 0, false);
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## OpenPeer
|
|
86
|
-
|
|
87
|
-
Opens a network connection to another Discord user.
|
|
88
|
-
|
|
89
|
-
Returns `void`.
|
|
90
|
-
|
|
91
|
-
###### Parameters
|
|
92
|
-
|
|
93
|
-
| name | type | description |
|
|
94
|
-
| ------ | ------ | -------------------------------------------- |
|
|
95
|
-
| peerId | UInt64 | the peerId of the user to connect to |
|
|
96
|
-
| route | string | the route the user is currently broadcasting |
|
|
97
|
-
|
|
98
|
-
###### Example
|
|
99
|
-
|
|
100
|
-
```cs
|
|
101
|
-
var userId = 53908232506183680;
|
|
102
|
-
var lobbyId = 290926798626357250;
|
|
103
|
-
|
|
104
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.peer_id");
|
|
105
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
106
|
-
var peerId = System.Convert.ToUInt64(rawPeerId);
|
|
107
|
-
var route = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.route");
|
|
108
|
-
networkManager.OpenPeer(peerId, route);
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## UpdatePeer
|
|
112
|
-
|
|
113
|
-
Updates the network connection to another Discord user. You'll want to call this when notified that the route for a user to which you are connected has changed, most likely from a lobby member update event.
|
|
114
|
-
|
|
115
|
-
Returns `void`.
|
|
116
|
-
|
|
117
|
-
###### Parameters
|
|
118
|
-
|
|
119
|
-
| name | type | description |
|
|
120
|
-
| ------ | ------ | -------------------------- |
|
|
121
|
-
| peerId | UInt64 | the user's peerId |
|
|
122
|
-
| route | string | the new route for the user |
|
|
123
|
-
|
|
124
|
-
###### Example
|
|
125
|
-
|
|
126
|
-
```cs
|
|
127
|
-
lobbyManager.OnMemberUpdate += (lobbyId, userId) =>
|
|
128
|
-
{
|
|
129
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.peer_id");
|
|
130
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
131
|
-
var peerId = System.Convert.ToUInt64(rawPeerId);
|
|
132
|
-
var newRoute = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.route");
|
|
133
|
-
networkManager.UpdatePeer(peerId, newRoute);
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## SendMessage
|
|
138
|
-
|
|
139
|
-
Sends data to a given peer ID through the given channel.
|
|
140
|
-
|
|
141
|
-
Returns `void`.
|
|
142
|
-
|
|
143
|
-
###### Parameters
|
|
144
|
-
|
|
145
|
-
| name | type | description |
|
|
146
|
-
| --------- | ------ | ------------------------------- |
|
|
147
|
-
| peerId | UInt64 | the peer id to connect to |
|
|
148
|
-
| channelId | byte | the channel on which to connect |
|
|
149
|
-
| data | byte[] | the data to send |
|
|
150
|
-
|
|
151
|
-
###### Example
|
|
152
|
-
|
|
153
|
-
```cs
|
|
154
|
-
var userId = 53908232506183680;
|
|
155
|
-
var lobbyId = 290926798626357250;
|
|
156
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.peer_id");
|
|
157
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
158
|
-
var peerId = System.Convert.ToUInt64(rawPeerId);
|
|
159
|
-
|
|
160
|
-
byte[] lootDrops = GameEngine.GetLootData();
|
|
161
|
-
networkManager.SendMessage(peerId, 1, lootDrops);
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## CloseChannel
|
|
165
|
-
|
|
166
|
-
Close the connection to a given user by peerId on the given channel.
|
|
167
|
-
|
|
168
|
-
Returns `void`.
|
|
169
|
-
|
|
170
|
-
###### Parameters
|
|
171
|
-
|
|
172
|
-
| name | type | description |
|
|
173
|
-
| --------- | ------ | ----------------------------------------- |
|
|
174
|
-
| peerId | UInt64 | the peerId of the user to disconnect from |
|
|
175
|
-
| channelId | byte | the route to close |
|
|
176
|
-
|
|
177
|
-
###### Example
|
|
178
|
-
|
|
179
|
-
```cs
|
|
180
|
-
var userId = 53908232506183680;
|
|
181
|
-
var lobbyId = 290926798626357250;
|
|
182
|
-
|
|
183
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.peer_id");
|
|
184
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
185
|
-
var peerId = System.Convert.ToUInt64(rawPeerId);
|
|
186
|
-
networkManager.CloseChannel(peerId, 0);
|
|
187
|
-
Console.WriteLine("Channel {0} to {1} closed", 0, peerId);
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## ClosePeer
|
|
191
|
-
|
|
192
|
-
Disconnects the network session to another Discord user.
|
|
193
|
-
|
|
194
|
-
Returns `void`.
|
|
195
|
-
|
|
196
|
-
###### Parameters
|
|
197
|
-
|
|
198
|
-
| name | type | description |
|
|
199
|
-
| ------ | ------ | ----------------- |
|
|
200
|
-
| peerId | UInt64 | the user's peerId |
|
|
201
|
-
|
|
202
|
-
###### Example
|
|
203
|
-
|
|
204
|
-
```cs
|
|
205
|
-
var userId = 53908232506183680;
|
|
206
|
-
var lobbyId = 290926798626357250;
|
|
207
|
-
|
|
208
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "metadata.peer_id");
|
|
209
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
210
|
-
var peerId = System.Convert.ToUInt64(rawPeerId);
|
|
211
|
-
networkManager.ClosePeer(peerId);
|
|
212
|
-
Console.WriteLine("Connection to {0} closed", peerId);
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
## OnMessage
|
|
216
|
-
|
|
217
|
-
Fires when you receive data from another user. This callback will only fire if you already have an open channel with the user sending you data. Make sure you're running `RunCallbacks()` in your game loop, or you'll never get data!
|
|
218
|
-
|
|
219
|
-
###### Parameters
|
|
220
|
-
|
|
221
|
-
| name | type | description |
|
|
222
|
-
| --------- | ------ | -------------------------- |
|
|
223
|
-
| peerId | UInt64 | the peer id of the sender |
|
|
224
|
-
| channelId | byte | the channel it was sent on |
|
|
225
|
-
| data | byte[] | the data sent |
|
|
226
|
-
|
|
227
|
-
###### Example
|
|
228
|
-
|
|
229
|
-
```cs
|
|
230
|
-
networkManager.OnMessage += (peerId, channel, data) =>
|
|
231
|
-
{
|
|
232
|
-
var stringData = Encoding.UTF8.GetString(data);
|
|
233
|
-
Console.WriteLine("Message from {0}: {1}", peerId, stringData)
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
## OnRouteUpdate
|
|
238
|
-
|
|
239
|
-
Fires when your networking route has changed. You should broadcast to other users to whom you are connected that this has changed, probably by updating your lobby member metadata for others to receive.
|
|
240
|
-
|
|
241
|
-
###### Parameters
|
|
242
|
-
|
|
243
|
-
| name | type | description |
|
|
244
|
-
| ----- | ------ | ------------------------- |
|
|
245
|
-
| route | string | the new route to the user |
|
|
246
|
-
|
|
247
|
-
###### Example
|
|
248
|
-
|
|
249
|
-
```cs
|
|
250
|
-
networkManager.OnRouteUpdate += route =>
|
|
251
|
-
{
|
|
252
|
-
var currentUser = userManager.GetCurrentUser();
|
|
253
|
-
var lobbyId = 290926798626357250;
|
|
254
|
-
|
|
255
|
-
var txn = lobbyManager.GetMemberUpdateTransaction(lobbyId, currentUser.Id);
|
|
256
|
-
txn.SetMetadata("route", route);
|
|
257
|
-
lobbyManager.UpdateMember(lobbyId, currentUser.Id, txn, (result) =>
|
|
258
|
-
{
|
|
259
|
-
// Who needs error handling anyway
|
|
260
|
-
Console.WriteLine(result);
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
## Flush vs RunCallbacks
|
|
266
|
-
|
|
267
|
-
A quick note here may be helpful for the two functions that should be called continuously in your game loop: `discord.RunCallbacks()` and `networkManager.Flush()`. `RunCallbacks()` pumps the SDK's event loop, sending any newly-received data down the SDK tubes to your game. For this reason, you should call it at the beginning of your game loop; that way, any new data is handled immediately by callbacks you've registered. In Unity, for example, this goes in `Update()`.
|
|
268
|
-
|
|
269
|
-
`Flush()` is specific to the network manager. It actually _writes_ the packets out to the stream. You should call this at the _end_ of your game loop as a way of saying "OK, I'm done with networking stuff, go send all the stuff to people who need it". In Unity, for example, this goes in `LateUpdate()`.
|
|
270
|
-
|
|
271
|
-
## Connecting to Each Other
|
|
272
|
-
|
|
273
|
-
This manager is built around the concept of routes between players, and then channels on those routes. Player A opens a route to Player B. This route will change, most commonly if the user's external IP address changes. As that route changes, the player will receive `OnRouteUpdate` events. They should then alert other lobby members that their route has changed by updating their lobbymetadata. Other lobby members will see those updates from the `OnLobbyMemberUpdate` event, and can call `UpdateRoute()` accordingly. A user's route could change frequently, so architect your system anticipating frequent route changes and updates.
|
|
274
|
-
|
|
275
|
-
Once Player A has a route open to Player B, Player A then opens a channel to Player B, and Player B does the same to Player A. Channels are the pipes down which data is actually sent. These two users can now send data back and forth to each other with `SendMessage()` and receive it with `OnMessage`.
|
|
276
|
-
|
|
277
|
-
In order to properly send and receive data between A and B, both users need to have **the same type of channel** open to each other **on the same channel number**. If A has Reliable Channel 4 open to B, B also needs Reliable Channel 4 open to A.
|
|
278
|
-
|
|
279
|
-
## Example: Connecting to Another Player in a Lobby
|
|
280
|
-
|
|
281
|
-
```cs
|
|
282
|
-
var discord = new Discord.Discord(clientId, (UInt64)Discord.CreateFlags.Default);
|
|
283
|
-
|
|
284
|
-
// Join a lobby with another user in it
|
|
285
|
-
// Get their peer id, and connect to them
|
|
286
|
-
|
|
287
|
-
var networkManager = discord.GetNetworkManager();
|
|
288
|
-
var lobbyManager = discord.GetLobbyManager();
|
|
289
|
-
var userManager = discord.GetUserManager();
|
|
290
|
-
|
|
291
|
-
Discord.User currentUser;
|
|
292
|
-
var otherUserPeerId;
|
|
293
|
-
var lobbyId;
|
|
294
|
-
|
|
295
|
-
// Get yourself
|
|
296
|
-
currentUser = userManager.GetCurrentUser();
|
|
297
|
-
|
|
298
|
-
// This will fire once you connect to the lobby
|
|
299
|
-
// Telling you which route is yours
|
|
300
|
-
networkManager.OnRouteUpdate += route =>
|
|
301
|
-
{
|
|
302
|
-
var txn = lobbyManager.GetMemberUpdateTransaction(lobbyId, currentUser.Id);
|
|
303
|
-
txn.SetMetadata("route", route);
|
|
304
|
-
lobbyManager.UpdateMember(lobbyId, currentUser.Id, txn, (result =>
|
|
305
|
-
{
|
|
306
|
-
// Who needs error handling anyway
|
|
307
|
-
Console.WriteLine(result);
|
|
308
|
-
}))
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// When other users get new routes, they'll update their metadata
|
|
312
|
-
// Fetch it and update their route
|
|
313
|
-
lobbyManager.OnMemberUpdate += (lobbyId, userId) =>
|
|
314
|
-
{
|
|
315
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "peer_id");
|
|
316
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
317
|
-
var peerId = System.Convert.ToUInt64(rawPeerId);
|
|
318
|
-
var newRoute = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "route");
|
|
319
|
-
lobbyManager.UpdatePeer(peerId, newRoute);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Connect to lobby with an id of 12345 and a secret of "password"
|
|
323
|
-
// This may occur in a generated lobby search, when a user needs to input a password to connect
|
|
324
|
-
lobbyManager.ConnectLobby(12345, "password", (Discord.Result x, ref Discord.Lobby lobby) =>
|
|
325
|
-
{
|
|
326
|
-
lobbyId = lobby.Id;
|
|
327
|
-
|
|
328
|
-
// Add our own peer id to our lobby member metadata
|
|
329
|
-
// So other users can get it to connect to us
|
|
330
|
-
var localPeerId = Convert.ToString(networkManager.GetPeerId());
|
|
331
|
-
var txn = lobbyManager.GetMemberUpdateTransaction(lobby.Id, currentUser.Id);
|
|
332
|
-
txn.SetMetadata("peer_id", localPeerId);
|
|
333
|
-
lobbyManager.UpdateMember(lobby.Id, currentUser.Id, txn, (result) =>
|
|
334
|
-
{
|
|
335
|
-
// Who needs error handling anyway
|
|
336
|
-
Console.WriteLine(result);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
// Get the first member in the lobby, assuming someone is already there
|
|
340
|
-
var memberId = lobbyManager.GetMemberUserId(lobby.Id, 0);
|
|
341
|
-
|
|
342
|
-
// Get their peer id and route from their metadata, added previously
|
|
343
|
-
var rawPeerId = lobbyManager.GetMemberMetadataValue(lobbyId, userId, "peer_id");
|
|
344
|
-
// Metadata is stored as a string, so we need to make it an integer for OpenChannel
|
|
345
|
-
otherUserPeerId = System.Convert.ToUInt64(rawPeerId);
|
|
346
|
-
var otherRoute = lobbyManager.GetMemberMetadataValue(lobby.Id, memberId, "route");
|
|
347
|
-
|
|
348
|
-
// Connect to them
|
|
349
|
-
networkManager.OpenPeer(otherUserPeerId, otherRoute);
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Open an unreliable channel to the user on channel 0
|
|
354
|
-
// And a reliable one on channel 1
|
|
355
|
-
networkManager.OpenChannel(otherUserPeerId, 0, false);
|
|
356
|
-
networkManager.OpenChannel(otherUserPeerId, 1, true);
|
|
357
|
-
|
|
358
|
-
// An important data packet from our game engine
|
|
359
|
-
byte[] data = GameEngine.GetImportantData();
|
|
360
|
-
|
|
361
|
-
// Determine if that data is about Player Loot Drops, if so send it on reliable, if not send it on unreliable
|
|
362
|
-
if (isDataAboutPlayerLootDrops(data))
|
|
363
|
-
{
|
|
364
|
-
// This is important and has to get there
|
|
365
|
-
// Send over reliable channel
|
|
366
|
-
networkManager.SendMessage(otherUserPeerId, 1, data);
|
|
367
|
-
}
|
|
368
|
-
else
|
|
369
|
-
{
|
|
370
|
-
// This is eventually consistent data, like the player's position in the world
|
|
371
|
-
// It can be sent over the unreliable channel
|
|
372
|
-
networkManager.SendMessage(otherUserPeerId, 0, data);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// Done; ship it!
|
|
376
|
-
networkManager.Flush();
|
|
377
|
-
```
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
# Overlay
|
|
2
|
-
|
|
3
|
-
> info
|
|
4
|
-
> Need help with the SDK? Talk to us in the [Discord Developers Server](https://discord.gg/discord-developers)!
|
|
5
|
-
|
|
6
|
-
> danger
|
|
7
|
-
> Selling SKUs on Discord is now deprecated, and will be discontinued on March 1, 2022. [Read here for more info.](https://support-dev.discord.com/hc/en-us/articles/4414590563479)
|
|
8
|
-
|
|
9
|
-
> warn
|
|
10
|
-
> The overlay is only supported on Windows for DirectX or OpenGL games. Linux, Mac, and games using Vulkan are not supported. [Click here for more info.](https://support.discord.com/hc/en-us/articles/217659737-Games-Overlay-101)
|
|
11
|
-
|
|
12
|
-
Discord comes with an awesome built-in overlay, and you may want to make use of it for your game. This manager will help you do just that! It:
|
|
13
|
-
|
|
14
|
-
- Gives you the current state of the overlay for the user
|
|
15
|
-
- Locked, enabled, unlocked, open, closed, etc.
|
|
16
|
-
- Allows you to change that state
|
|
17
|
-
|
|
18
|
-
## Data Models
|
|
19
|
-
|
|
20
|
-
###### ActivityActionType Enum
|
|
21
|
-
|
|
22
|
-
| name | value |
|
|
23
|
-
| -------- | ----- |
|
|
24
|
-
| Join | 1 |
|
|
25
|
-
| Spectate | 2 |
|
|
26
|
-
|
|
27
|
-
## IsEnabled
|
|
28
|
-
|
|
29
|
-
Check whether the user has the overlay enabled or disabled. If the overlay is disabled, all the functionality in this manager will still work. The calls will instead focus the Discord client and show the modal there instead.
|
|
30
|
-
|
|
31
|
-
Returns a `bool`.
|
|
32
|
-
|
|
33
|
-
###### Parameters
|
|
34
|
-
|
|
35
|
-
None
|
|
36
|
-
|
|
37
|
-
###### Example
|
|
38
|
-
|
|
39
|
-
```cs
|
|
40
|
-
if (!overlaymanager.IsEnabled())
|
|
41
|
-
{
|
|
42
|
-
Console.WriteLine("Overlay is not enabled. Modals will be shown in the Discord client instead");
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## IsLocked
|
|
47
|
-
|
|
48
|
-
Check if the overlay is currently locked or unlocked
|
|
49
|
-
|
|
50
|
-
###### Parameters
|
|
51
|
-
|
|
52
|
-
None
|
|
53
|
-
|
|
54
|
-
###### Example
|
|
55
|
-
|
|
56
|
-
```cs
|
|
57
|
-
if (overlayManager.IsLocked())
|
|
58
|
-
{
|
|
59
|
-
overlayManager.SetLocked(true, (res) =>
|
|
60
|
-
{
|
|
61
|
-
Console.WriteLine("Input in the overlay is now accessible again");
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## SetLocked
|
|
67
|
-
|
|
68
|
-
Locks or unlocks input in the overlay. Calling `SetLocked(true);` will also close any modals in the overlay or in-app from things like IAP purchase flows and disallow input.
|
|
69
|
-
|
|
70
|
-
Returns `Discord.Result` via callback.
|
|
71
|
-
|
|
72
|
-
###### Parameters
|
|
73
|
-
|
|
74
|
-
| name | type | description |
|
|
75
|
-
| ------ | ---- | -------------------------- |
|
|
76
|
-
| locked | bool | lock or unlock the overlay |
|
|
77
|
-
|
|
78
|
-
###### Example
|
|
79
|
-
|
|
80
|
-
```cs
|
|
81
|
-
overlayManager.SetLocked(true, (res) =>
|
|
82
|
-
{
|
|
83
|
-
Console.WriteLine("Overlay has been locked and modals have been closed");
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## OpenActivityInvite
|
|
88
|
-
|
|
89
|
-
Opens the overlay modal for sending game invitations to users, channels, and servers. If you do not have a valid activity with all the required fields, this call will error. See [Activity Action Field Requirements](#DOCS_GAME_SDK_ACTIVITIES/activity-action-field-requirements) for the fields required to have join and spectate invites function properly.
|
|
90
|
-
|
|
91
|
-
Returns a `Discord.Result` via callback.
|
|
92
|
-
|
|
93
|
-
###### Parameters
|
|
94
|
-
|
|
95
|
-
| name | type | description |
|
|
96
|
-
| ---- | ------------------ | --------------------------- |
|
|
97
|
-
| type | ActivityActionType | what type of invite to send |
|
|
98
|
-
|
|
99
|
-
###### Example
|
|
100
|
-
|
|
101
|
-
```cs
|
|
102
|
-
overlayManager.OpenActivityInvite(Discord.ActivityActionType.Join, (result) =>
|
|
103
|
-
{
|
|
104
|
-
if (result == Discord.Result.Ok)
|
|
105
|
-
{
|
|
106
|
-
Console.WriteLine("User is now inviting others to play!");
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## OpenGuildInvite
|
|
112
|
-
|
|
113
|
-
Opens the overlay modal for joining a Discord guild, given its invite code. An invite code for a server may look something like `fortnite` for a verified server—the full invite being `discord.gg/fortnite`—or something like `rjEeUJq` for a non-verified server, the full invite being `discord.gg/rjEeUJq`.
|
|
114
|
-
|
|
115
|
-
Returns a `Discord.Result` via callback. Note that a successful `Discord.Result` response does not necessarily mean that the user has joined the guild. If you want more granular control over and knowledge about users joining your guild, you may want to look into implementing the [`guilds.join` OAuth2 scope in an authorization code grant](#DOCS_TOPICS_OAUTH2/authorization-code-grant) in conjunction with the [Add Guild Members](#DOCS_RESOURCES_GUILD/add-guild-member) endpoint.
|
|
116
|
-
|
|
117
|
-
###### Parameters
|
|
118
|
-
|
|
119
|
-
| name | type | description |
|
|
120
|
-
| ---- | ------ | -------------------------- |
|
|
121
|
-
| code | string | an invite code for a guild |
|
|
122
|
-
|
|
123
|
-
###### Example
|
|
124
|
-
|
|
125
|
-
```cs
|
|
126
|
-
overlayManager.OpenGuildInvite("rjEeUJq", (result) =>
|
|
127
|
-
{
|
|
128
|
-
if (result == Discord.Result.Ok)
|
|
129
|
-
{
|
|
130
|
-
Console.WriteLine("Invite was valid.");
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
## OpenVoiceSettings
|
|
136
|
-
|
|
137
|
-
Opens the overlay widget for voice settings for the currently connected application. These settings are unique to each user within the context of your application. That means that a user can have different favorite voice settings for each of their games!
|
|
138
|
-
|
|
139
|
-

|
|
140
|
-
|
|
141
|
-
Also, when connected to a lobby's voice channel, the overlay will show a widget that allows users to locally mute, deafen, and adjust the volume of others.
|
|
142
|
-
|
|
143
|
-

|
|
144
|
-
|
|
145
|
-
Returns a `Discord.Result` via callback.
|
|
146
|
-
|
|
147
|
-
###### Parameters
|
|
148
|
-
|
|
149
|
-
None
|
|
150
|
-
|
|
151
|
-
###### Example
|
|
152
|
-
|
|
153
|
-
```cs
|
|
154
|
-
overlayManager.OpenVoiceSettings((result) =>
|
|
155
|
-
{
|
|
156
|
-
if (result == Discord.Result.Ok)
|
|
157
|
-
{
|
|
158
|
-
Console.WriteLine("Overlay is open to the voice settings for your application/")
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## OnToggle
|
|
164
|
-
|
|
165
|
-
Fires when the overlay is locked or unlocked (a.k.a. opened or closed)
|
|
166
|
-
|
|
167
|
-
###### Parameters
|
|
168
|
-
|
|
169
|
-
| name | type | description |
|
|
170
|
-
| ------ | ---- | ------------------------------------- |
|
|
171
|
-
| locked | bool | is the overlay now locked or unlocked |
|
|
172
|
-
|
|
173
|
-
###### Example
|
|
174
|
-
|
|
175
|
-
overlayManager.OnToggle += overlayLock =>
|
|
176
|
-
{
|
|
177
|
-
Console.WriteLine("Overlay Locked: {0}", overlayLock);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
## Example: Activate Overlay Invite Modal
|
|
181
|
-
|
|
182
|
-
```cs
|
|
183
|
-
var discord = new Discord.Discord(clientId, Discord.CreateFlags.Default);
|
|
184
|
-
var overlayManager = discord.GetOverlayManager();
|
|
185
|
-
|
|
186
|
-
// Invite users to join your game
|
|
187
|
-
overlayManager.OpenActivityInvite(ActivityActionType.Join, (result) =>
|
|
188
|
-
{
|
|
189
|
-
Console.WriteLine("Overlay is now open!");
|
|
190
|
-
})
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
And that invite modal looks like this!
|
|
194
|
-
|
|
195
|
-

|