-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAceController.cs
70 lines (64 loc) · 2.4 KB
/
AceController.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
using System.Collections.Generic;
using System.Linq;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using PoliceMP.Core.Server.Communications.Interfaces;
using PoliceMP.Core.Server.Networking;
using PoliceMP.Shared.Constants;
using PoliceMP.Shared.Models;
using System.Threading.Tasks;
using PoliceMP.Client.Services.Interfaces;
using PoliceMP.Shared.Enums;
using PoliceMP.Shared.Constants.States;
using PoliceMP.Server.Extensions;
namespace PoliceMP.Server.Controllers
{
public class AceController : Controller
{
private readonly IServerCommunicationsManager _comms;
private readonly PlayerList _playerList;
private readonly IPermissionService _perms;
public AceController(IServerCommunicationsManager comms, PlayerList playerList, IPermissionService perms)
{
_comms = comms;
_playerList = playerList;
_perms = perms;
_comms.OnRequest(ServerEvents.FetchUserAces, FetchUserAces);
_comms.On<UserRole>(ServerEvents.SendUserRole, OnReceieveUserRole);
//_comms.OnRequest<int, UserRole>(ServerEvents.FetchUserRoleByNetId, FetchUserRoleByNetId);
}
// private Task<UserRole> FetchUserRoleByNetId(Player player, int networkId)
// {
// var target = _playerList[networkId];
//
// UserRole userRole = target?.State.Get(PlayerStates.CurrentRole);
//
// if (userRole == null)
// {
// return Task.FromResult(new UserRole
// {
// Branch = UserBranch.Police,
// Division = UserDivision.Ert
// });
// }
//
// return Task.FromResult(userRole);
// }
private void OnReceieveUserRole(Player player, UserRole userRole)
{
if (player.Character == null) return;
player.State.Set<UserRole>(PlayerStates.CurrentRole, userRole, true);
}
private async Task<UserRole> FetchUserRoleByNetId(Player player, int networkId)
{
var target = _playerList.ToList().FirstOrDefault(p => p.Character?.NetworkId == networkId);
var userRole = await _perms.GetUserRole(target);
return userRole;
}
private async Task<UserAces> FetchUserAces(Player player)
{
var userAces = await _perms.GetUserAces(player);
return userAces;
}
}
}