|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- using GamecraftModdingAPI.Events;
- using Svelto.ECS;
- using RobocraftX.Common;
-
- using Discord;
-
- namespace GamecraftRPC.Events
- {
- class GamePresenceHandler : SimpleEventHandlerEngine
- {
- public static readonly string HandlerName = "GamecraftRPCGamePresenceEventHandler";
-
- //private Discord.Discord discordRPC = null;
-
- public static void OnAdd(Discord.Discord discordRPC)
- {
- PresenceUtility.LastGameStart = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
-
- LobbyTransaction ltxn = discordRPC.GetLobbyManager().GetLobbyCreateTransaction();
- UserManager um = discordRPC.GetUserManager();
- um.OnCurrentUserUpdate += () =>
- {
- ltxn.SetOwner(um.GetCurrentUser().Id);
- ltxn.SetCapacity((uint)PresenceUtility.LobbySize);
- ltxn.SetType(LobbyType.Private);
- ltxn.SetMetadata("ownerSteamId", Steamworks.SteamClient.SteamId.AccountId.ToString());
- discordRPC.GetLobbyManager().CreateLobby(ltxn,
- (Result result, ref Lobby lobby) =>
- {
- GamecraftModdingAPI.Utility.Logging.LogDebug($"Lobby status: {result}");
- PresenceUtility.LobbyId = lobby.Id;
- PresenceUtility.GameSecret = lobby.Secret;
-
- });
- };
- Plugin.SetDiscordActivity(discordRPC, state: "In-Game", details: $"Editing {GameMode.SaveGameDetails.Name}", start: PresenceUtility.LastGameStart, partyId: PresenceUtility.PartyId.ToString(), partyCurrentSize: 1, partyMaxSize: PresenceUtility.LobbySize, debug: "GamePresence-OnAdd");
- }
-
- public GamePresenceHandler(Discord.Discord _discordRPC) : base((db) => { OnAdd(_discordRPC); }, (db) => { }, EventType.GameSwitchedTo, HandlerName)
- {
- //this.discordRPC = _discordRPC;
- }
- }
- }
|