Add Discord Rich Presence
This commit is contained in:
@@ -61,6 +61,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
bool addBotOnMapLoad;
|
||||
bool disableTeamChat;
|
||||
bool teamChat;
|
||||
bool updateDiscordStatus = true;
|
||||
|
||||
readonly string chatLineSound = ChromeMetrics.Get<string>("ChatLineSound");
|
||||
|
||||
@@ -116,6 +117,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
orderManager.AddChatLine += AddChatLine;
|
||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||
Game.LobbyInfoChanged += UpdateDiscordStatus;
|
||||
Game.BeforeGameStart += OnGameStart;
|
||||
Game.ConnectionStateChanged += ConnectionStateChanged;
|
||||
|
||||
@@ -462,6 +464,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
orderManager.AddChatLine -= AddChatLine;
|
||||
Game.LobbyInfoChanged -= UpdateCurrentMap;
|
||||
Game.LobbyInfoChanged -= UpdatePlayerList;
|
||||
Game.LobbyInfoChanged -= UpdateDiscordStatus;
|
||||
Game.BeforeGameStart -= OnGameStart;
|
||||
Game.ConnectionStateChanged -= ConnectionStateChanged;
|
||||
}
|
||||
@@ -743,9 +746,56 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList();
|
||||
}
|
||||
|
||||
void UpdateDiscordStatus()
|
||||
{
|
||||
var mapTitle = map.Title;
|
||||
var numberOfPlayers = 0;
|
||||
var slots = 0;
|
||||
|
||||
if (!skirmishMode)
|
||||
{
|
||||
foreach (var kv in orderManager.LobbyInfo.Slots)
|
||||
{
|
||||
if (kv.Value.Closed)
|
||||
continue;
|
||||
|
||||
slots++;
|
||||
var client = orderManager.LobbyInfo.ClientInSlot(kv.Key);
|
||||
|
||||
if (client != null)
|
||||
numberOfPlayers++;
|
||||
}
|
||||
}
|
||||
|
||||
if (updateDiscordStatus)
|
||||
{
|
||||
string secret = null;
|
||||
if (orderManager.LobbyInfo.GlobalSettings.Dedicated)
|
||||
{
|
||||
var endpoint = orderManager.Endpoint.GetConnectEndPoints().First();
|
||||
secret = string.Concat(endpoint.Address, "|", endpoint.Port);
|
||||
}
|
||||
|
||||
var state = skirmishMode ? DiscordState.InSkirmishLobby : DiscordState.InMultiplayerLobby;
|
||||
DiscordService.UpdateStatus(state, mapTitle, secret, numberOfPlayers, slots);
|
||||
|
||||
updateDiscordStatus = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!skirmishMode)
|
||||
DiscordService.UpdatePlayers(numberOfPlayers, slots);
|
||||
DiscordService.UpdateDetails(mapTitle);
|
||||
}
|
||||
}
|
||||
|
||||
void OnGameStart()
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
|
||||
var state = skirmishMode ? DiscordState.PlayingSkirmish : DiscordState.PlayingMultiplayer;
|
||||
DiscordService.UpdateStatus(state);
|
||||
|
||||
onStart();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user