69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using DiscordRPC;
|
|
using DiscordRPC.Logging;
|
|
using DiscordRPC.Message;
|
|
|
|
namespace MafiaGame
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
public App()
|
|
{
|
|
App.Instance = this;
|
|
}
|
|
|
|
public static App Instance;
|
|
|
|
private DiscordRpcClient _rpcClient;
|
|
|
|
public ServerConnection Connection;
|
|
|
|
public DiscordRpcClient GetRpcClient()
|
|
{
|
|
return _rpcClient;
|
|
}
|
|
|
|
private void App_OnStartup(object sender, StartupEventArgs e)
|
|
{
|
|
_rpcClient = new DiscordRpcClient("800016130097152000", autoEvents: true);
|
|
_rpcClient.RegisterUriScheme();
|
|
_rpcClient.Logger = new ConsoleLogger() { Level = LogLevel.Warning };
|
|
_rpcClient.OnJoinRequested += RpcClientOnOnJoinRequested;
|
|
_rpcClient.OnJoin += RpcClientOnOnJoin;
|
|
_rpcClient.SetSubscription(EventType.Join | EventType.JoinRequest);
|
|
_rpcClient.Initialize();
|
|
_rpcClient.SetPresence(new RichPresence()
|
|
{
|
|
State = "Запуск игры..."
|
|
});
|
|
|
|
Settings.Initialize();
|
|
Settings.Save();
|
|
}
|
|
|
|
private void RpcClientOnOnJoin(object sender, JoinMessage args)
|
|
{
|
|
string secret = args.Secret;
|
|
Connection = new ServerConnection(secret.Replace("/join", ""));
|
|
}
|
|
|
|
private void RpcClientOnOnJoinRequested(object sender, JoinRequestMessage args)
|
|
{
|
|
_rpcClient.Respond(args, true);
|
|
}
|
|
|
|
private void App_OnExit(object sender, ExitEventArgs e)
|
|
{
|
|
_rpcClient.Dispose();
|
|
}
|
|
}
|
|
} |