-
Notifications
You must be signed in to change notification settings - Fork 16
/
AdminHideHandler.cs
58 lines (50 loc) · 1.97 KB
/
AdminHideHandler.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
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Net;
using EOLib.Net.Handlers;
namespace EOLib.PacketHandlers
{
[AutoMappedType]
public class AdminHideHandler : InGameOnlyPacketHandler
{
private readonly ICharacterRepository _characterRepository;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
public override PacketFamily Family => PacketFamily.AdminInteract;
public override PacketAction Action => PacketAction.Remove;
public AdminHideHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterRepository characterRepository,
ICurrentMapStateRepository currentMapStateRepository)
: base(playerInfoProvider)
{
_characterRepository = characterRepository;
_currentMapStateRepository = currentMapStateRepository;
}
public override bool HandlePacket(IPacket packet)
{
var id = packet.ReadShort();
if (id == _characterRepository.MainCharacter.ID)
_characterRepository.MainCharacter = Hidden(_characterRepository.MainCharacter);
else
{
if (_currentMapStateRepository.Characters.ContainsKey(id))
{
var character = _currentMapStateRepository.Characters[id];
var updatedCharacter = Hidden(character);
_currentMapStateRepository.Characters[id] = updatedCharacter;
}
else
{
_currentMapStateRepository.UnknownPlayerIDs.Add(id);
}
}
return true;
}
private static ICharacter Hidden(ICharacter input)
{
var renderProps = input.RenderProperties.WithIsHidden(true);
return input.WithRenderProperties(renderProps);
}
}
}