This repository has moved! Please check out the latest version at the new location https://git.exmods.org/NGnius/GameSDKcraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

51 lines
2.0KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GamecraftModdingAPI.Events;
  7. using Svelto.ECS;
  8. using RobocraftX.Common;
  9. using Discord;
  10. namespace GamecraftRPC.Events
  11. {
  12. class GamePresenceHandler : SimpleEventHandlerEngine
  13. {
  14. public static readonly string HandlerName = "GamecraftRPCGamePresenceEventHandler";
  15. //private Discord.Discord discordRPC = null;
  16. public static void OnAdd(Discord.Discord discordRPC)
  17. {
  18. PresenceUtility.LastGameStart = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
  19. LobbyTransaction ltxn = discordRPC.GetLobbyManager().GetLobbyCreateTransaction();
  20. UserManager um = discordRPC.GetUserManager();
  21. um.OnCurrentUserUpdate += () =>
  22. {
  23. ltxn.SetOwner(um.GetCurrentUser().Id);
  24. ltxn.SetCapacity((uint)PresenceUtility.LobbySize);
  25. ltxn.SetType(LobbyType.Private);
  26. ltxn.SetMetadata("ownerSteamId", Steamworks.SteamClient.SteamId.AccountId.ToString());
  27. discordRPC.GetLobbyManager().CreateLobby(ltxn,
  28. (Result result, ref Lobby lobby) =>
  29. {
  30. GamecraftModdingAPI.Utility.Logging.LogDebug($"Lobby status: {result}");
  31. PresenceUtility.LobbyId = lobby.Id;
  32. PresenceUtility.GameSecret = lobby.Secret;
  33. });
  34. };
  35. 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");
  36. }
  37. public GamePresenceHandler(Discord.Discord _discordRPC) : base((db) => { OnAdd(_discordRPC); }, (db) => { }, EventType.GameSwitchedTo, HandlerName)
  38. {
  39. //this.discordRPC = _discordRPC;
  40. }
  41. }
  42. }