-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSonoranService.cs
107 lines (93 loc) · 3.05 KB
/
SonoranService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Security;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using Newtonsoft.Json;
using PoliceMP.Core.Shared;
using PoliceMP.Core.Shared.Constants;
using PoliceMP.Server.Services.Interfaces;
using RestSharp;
namespace PoliceMP.Server.Services
{
public class SonoranService : ISonoranService
{
private readonly string _communityId = "COMMUNITYIDHERE";
private readonly string _apiKey = "APIKEYHERE";
private readonly string _baseUri = "https://api.sonorancad.com";
private readonly ILogger<SonoranService> _logger;
private readonly IFeatureService _featureService;
public SonoranService(ILogger<SonoranService> logger, IFeatureService featureService)
{
_logger = logger;
_featureService = featureService;
}
public async Task SendPanicEvent(Player player)
{
var steamId = player.Identifiers[Identifiers.Steam];
var serverId = 1;
if (_featureService.IsFeatureEnabled("sonoran_prodono"))
{
serverId = 2;
}
if (_featureService.IsFeatureEnabled("sonoran_dev"))
{
serverId = 3;
}
if (string.IsNullOrEmpty(steamId))
{
_logger.Debug("ERROR: SteamID Null!");
return;
}
var data = new
{
apiId = $"{steamId}",
isPanic = true,
};
var jsonData = JsonConvert.SerializeObject(data);
var body = new
{
id = _communityId,
key = _apiKey,
serverId = serverId,
type = "UNIT_PANIC",
data = jsonData
};
var client = new RestClient($"{_baseUri}");
var requestUri = $"/emergency/unit_panic";
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
var request = new RestRequest(requestUri, Method.POST)
{
RequestFormat = DataFormat.Json
};
request.AddJsonBody(new
{
id = _communityId,
key = _apiKey,
serverId = serverId,
type = "UNIT_PANIC",
data = new []
{
new
{
apiId = steamId,
isPanic = true
}
}
});
var response = client.Post(request);
if (serverId == 3)
{
// Dev Server
_logger.Debug($"Content: {response.Content}");
}
}
}
}