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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Impostor.Api;
using Impostor.Api.Innersloth;
using Impostor.Api.Net;
using Impostor.Api.Net.Inner.Objects;
using Impostor.Api.Net.Messages;
using Impostor.Server.Net.Inner.Objects.Systems;
using Impostor.Server.Net.Inner.Objects.Systems.ShipStatus;
using Impostor.Server.Net.State;
using Microsoft.Extensions.Logging;
namespace Impostor.Server.Net.Inner.Objects
{
internal class InnerShipStatus : InnerNetObject, IInnerShipStatus
{
private readonly ILogger<InnerShipStatus> _logger;
private readonly Game _game;
private readonly Dictionary<SystemTypes, ISystemType> _systems;
public InnerShipStatus(ILogger<InnerShipStatus> logger, Game game)
{
_logger = logger;
_game = game;
_systems = new Dictionary<SystemTypes, ISystemType>
{
[SystemTypes.Electrical] = new SwitchSystem(),
[SystemTypes.MedBay] = new MedScanSystem(),
[SystemTypes.Reactor] = new ReactorSystemType(),
[SystemTypes.LifeSupp] = new LifeSuppSystemType(),
[SystemTypes.Security] = new SecurityCameraSystemType(),
[SystemTypes.Comms] = new HudOverrideSystemType(),
[SystemTypes.Doors] = new DoorsSystemType(_game),
};
_systems.Add(SystemTypes.Sabotage, new SabotageSystemType(new[]
{
(IActivatable)_systems[SystemTypes.Comms],
(IActivatable)_systems[SystemTypes.Reactor],
(IActivatable)_systems[SystemTypes.LifeSupp],
(IActivatable)_systems[SystemTypes.Electrical],
}));
Components.Add(this);
}
public override ValueTask HandleRpc(ClientPlayer sender, ClientPlayer? target, RpcCalls call,
IMessageReader reader)
{
switch (call)
{
case RpcCalls.CloseDoorsOfType:
{
if (target == null || !target.IsHost)
{
throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CloseDoorsOfType)} to wrong destinition, must be host");
}
if (!sender.Character.PlayerInfo.IsImpostor)
{
throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CloseDoorsOfType)} as crewmate");
}
var systemType = (SystemTypes)reader.ReadByte();
break;
}
case RpcCalls.RepairSystem:
{
if (target == null || !target.IsHost)
{
throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.RepairSystem)} to wrong destinition, must be host");
}
var systemType = (SystemTypes)reader.ReadByte();
if (systemType == SystemTypes.Sabotage && !sender.Character.PlayerInfo.IsImpostor)
{
throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.RepairSystem)} for {systemType} as crewmate");
}
var player = reader.ReadNetObject<InnerPlayerControl>(_game);
var amount = reader.ReadByte();
// TODO: Modify data (?)
break;
}
default:
{
_logger.LogWarning("{0}: Unknown rpc call {1}", nameof(InnerShipStatus), call);
break;
}
}
return default;
}
public override bool Serialize(IMessageWriter writer, bool initialState)
{
throw new NotImplementedException();
}
public override void Deserialize(IClientPlayer sender, IClientPlayer? target, IMessageReader reader, bool initialState)
{
if (!sender.IsHost)
{
throw new ImpostorCheatException($"Client attempted to send data for {nameof(InnerShipStatus)} as non-host");
}
if (target != null)
{
throw new ImpostorCheatException($"Client attempted to send {nameof(InnerShipStatus)} data to a specific player, must be broadcast");
}
if (initialState)
{
// TODO: (_systems[SystemTypes.Doors] as DoorsSystemType).SetDoors();
foreach (var systemType in SystemTypeHelpers.AllTypes)
{
if (_systems.TryGetValue(systemType, out var system))
{
system.Deserialize(reader, true);
}
}
}
else
{
var count = reader.ReadPackedUInt32();
foreach (var systemType in SystemTypeHelpers.AllTypes)
{
// TODO: Not sure what is going on here, check.
if ((count & 1 << (int)(systemType & (SystemTypes.ShipTasks | SystemTypes.Doors))) != 0L)
{
if (_systems.TryGetValue(systemType, out var system))
{
system.Deserialize(reader, false);
}
}
}
}
}
}
}
|