Created
July 18, 2019 00:57
-
-
Save msciotti/973cbc0cc253a59488a6cd068f816c1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code is client #1. All is unity examples | |
public void OnClick() | |
{ | |
var lobbyManager = discord.GetLobbyManager(); | |
lobbyManager.SendNetworkMessage(lobby.Id, 363446008341987328, 0, System.Text.Encoding.UTF8.GetBytes("Sup")); | |
} | |
void OnEnable() | |
{ | |
Debug.Log("Discord: init"); | |
callbackCalls = 0; | |
discord = new Discord.Discord(clientId, (UInt64)Discord.CreateFlags.Default); | |
discord.SetLogHook(Discord.LogLevel.Debug, (level, message) => | |
{ | |
Debug.Log(string.Format("Log[{0}] {1}", level, message)); | |
}); | |
var userManager = discord.GetUserManager(); | |
userManager.OnCurrentUserUpdate += CurrentUserCallback; | |
var lobbyManager = discord.GetLobbyManager(); | |
lobbyManager.OnNetworkMessage += (lobbyId, userId, channelId, data) => | |
{ | |
var message = System.Text.Encoding.UTF8.GetString(data); | |
Debug.Log("User is " + userId); | |
Debug.Log(message); | |
}; | |
var txn = lobbyManager.GetLobbyCreateTransaction(); | |
txn.SetCapacity(2); | |
lobbyManager.CreateLobby(txn, (Discord.Result result, ref Discord.Lobby lobby) => | |
{ | |
_lobbyId = lobby.Id; | |
Debug.Log(lobbyManager.GetLobbyActivitySecret(lobby.Id)); | |
lobbyManager.ConnectNetwork(lobby.Id); | |
lobbyManager.OpenNetworkChannel(lobby.Id, 0, true); | |
}); | |
} | |
void LateUpdate() | |
{ | |
var lobbyManager = discord.GetLobbyManager(); | |
lobbyManager.FlushNetwork(); | |
} | |
void Update() | |
{ | |
discord.RunCallbacks(); | |
} | |
------ | |
// This is client #2 | |
void OnEnable() | |
{ | |
Debug.Log("Discord: init"); | |
callbackCalls = 0; | |
System.Environment.SetEnvironmentVariable("DISCORD_INSTANCE_ID", "1"); | |
discord = new Discord.Discord(clientId, (UInt64)Discord.CreateFlags.Default); | |
discord.SetLogHook(Discord.LogLevel.Debug, (level, message) => | |
{ | |
Debug.Log(string.Format("Log[{0}] {1}", level, message)); | |
}); | |
var userManager = discord.GetUserManager(); | |
userManager.OnCurrentUserUpdate += CurrentUserCallback; | |
var lobbyManager = discord.GetLobbyManager(); | |
lobbyManager.OnNetworkMessage += (lobbyId, userId, channelId, data) => | |
{ | |
var message = System.Text.Encoding.UTF8.GetString(data); | |
Debug.Log("User is " + userId); | |
Debug.Log(message); | |
}; | |
lobbyManager.ConnectLobbyWithActivitySecret("601214929147789312:cc288206d3263aa9", (Discord.Result result, ref Discord.Lobby lobby) => | |
{ | |
lobbyManager.ConnectNetwork(lobby.Id); | |
lobbyManager.OpenNetworkChannel(lobby.Id, 0, true); | |
lobbyManager.SendNetworkMessage(lobby.Id, 53908232506183680, 0, System.Text.Encoding.UTF8.GetBytes("Sup")); | |
Debug.Log("Sent message"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment