Skip to content

Commit

Permalink
Merge pull request Impostor#372 from miniduikboot/2021.3.31
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak authored Apr 4, 2021
2 parents 4f53d3f + d801a36 commit c750c65
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WORKDIR /source
# Copy csproj and restore.
COPY src/Impostor.Server/Impostor.Server.csproj ./src/Impostor.Server/Impostor.Server.csproj
COPY src/Impostor.Api/Impostor.Api.csproj ./src/Impostor.Api/Impostor.Api.csproj
COPY src/Impostor.Hazel/Impostor.Hazel.csproj ./src/Impostor.Hazel/Impostor.Hazel.csproj
COPY src/Impostor.Hazel/Hazel/Hazel.csproj ./src/Impostor.Hazel/Hazel/Hazel.csproj

RUN case "$TARGETARCH" in \
amd64) NETCORE_PLATFORM='linux-x64';; \
Expand All @@ -21,7 +21,7 @@ RUN case "$TARGETARCH" in \
esac && \
dotnet restore -r "$NETCORE_PLATFORM" ./src/Impostor.Server/Impostor.Server.csproj && \
dotnet restore -r "$NETCORE_PLATFORM" ./src/Impostor.Api/Impostor.Api.csproj && \
dotnet restore -r "$NETCORE_PLATFORM" ./src/Impostor.Hazel/Impostor.Hazel.csproj
dotnet restore -r "$NETCORE_PLATFORM" ./src/Impostor.Hazel/Hazel/Hazel.csproj

# Copy everything else.
COPY src/. ./src/
Expand Down
2 changes: 1 addition & 1 deletion src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ csharp_new_line_between_query_expression_clauses = true
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_case_contents_when_block = false
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

Expand Down
1 change: 1 addition & 0 deletions src/Impostor.Api/Innersloth/MapSpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private MapSpawn(float spawnRadius, Vector2 initialSpawnCenter, Vector2 meetingS
[MapTypes.Skeld] = new MapSpawn(1.6f, new Vector2(-0.72f, 0.62f), new Vector2(-0.72f, 0.62f)),
[MapTypes.MiraHQ] = new MapSpawn(1.55f, new Vector2(-4.4f, 2.2f), new Vector2(24.043f, 1.72f)),
[MapTypes.Polus] = new MapSpawn(1f, new Vector2(16.64f, -2.46f), new Vector2(17.726f, -16.286f)),
[MapTypes.Airship] = new MapSpawn(0f, new Vector2(-0.66f, -0.5f), new Vector2(-0.66f, -0.5f)),
};

public float SpawnRadius { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Impostor.Api/Innersloth/MapTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum MapTypes : byte
Skeld = 0,
MiraHQ = 1,
Polus = 2,
Airship = 4,
}
}
34 changes: 34 additions & 0 deletions src/Impostor.Api/Innersloth/SystemTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,39 @@ public enum SystemTypes : byte
Specimens = 28,

BoilerRoom = 29,

VaultRoom = 30,

Cockpit = 31,

Armory = 32,

Kitchen = 33,

ViewingDeck = 34,

HallOfPortraits = 35,

CargoBay = 36,

Ventilation = 37,

Showers = 38,

Engine = 39,

Brig = 40,

MeetingRoom = 41,

Records = 42,

Lounge = 43,

GapRoom = 44,

MainHall = 45,

Medical = 46,
}
}
4 changes: 3 additions & 1 deletion src/Impostor.Api/Net/Inner/RpcCalls.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Impostor.Server.Net.Inner
namespace Impostor.Server.Net.Inner
{
public enum RpcCalls : byte
{
Expand Down Expand Up @@ -33,5 +33,7 @@ public enum RpcCalls : byte
RepairSystem = 28,
SetTasks = 29,
UpdateGameData = 30,
ClimbLadder = 31,
UsePlatform = 32,
}
}
17 changes: 17 additions & 0 deletions src/Impostor.Api/Net/Messages/Rpcs/Rpc31ClimbLadder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Impostor.Api.Net.Messages.Rpcs
{
public static class Rpc31ClimbLadder
{
public static void Serialize(IMessageWriter writer, byte ladderId, byte lastClimbLadderSid)
{
writer.Write(ladderId);
writer.Write(lastClimbLadderSid);
}

public static void Deserialize(IMessageReader reader, out byte ladderId, out byte lastClimbLadderSid)
{
ladderId = reader.ReadByte();
lastClimbLadderSid = reader.ReadByte();
}
}
}
13 changes: 13 additions & 0 deletions src/Impostor.Api/Net/Messages/Rpcs/Rpc32UsePlatform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Impostor.Api.Net.Messages.Rpcs
{
public static class Rpc32UsePlatform
{
public static void Serialize(IMessageWriter writer)
{
}

public static void Deserialize(IMessageReader reader)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ public override async ValueTask<bool> HandleRpcAsync(ClientPlayer sender, Client
{
case RpcCalls.EnterVent:
Rpc19EnterVent.Deserialize(reader, out ventId);
await _eventManager.CallAsync(new PlayerVentEvent(_game, sender, _playerControl, (VentLocation)ventId, true));
break;

case RpcCalls.ExitVent:
Rpc19EnterVent.Deserialize(reader, out ventId);
await _eventManager.CallAsync(new PlayerVentEvent(_game, sender, _playerControl, (VentLocation)ventId, false));
break;

case RpcCalls.ClimbLadder:
Rpc31ClimbLadder.Deserialize(reader, out byte ladderId, out byte lastClimbLadderSid);
break;

default:
return await UnregisteredCall(call, sender);
}

await _eventManager.CallAsync(new PlayerVentEvent(_game, sender, _playerControl, (VentLocation)ventId, call == RpcCalls.EnterVent));

return true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Impostor.Server/Net/Inner/Objects/InnerGameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public override async ValueTask DeserializeAsync(IClientPlayer sender, IClientPl
}
else
{
throw new NotImplementedException("This shouldn't happen, according to Among Us disassembly.");
// It'll send an message per dirty player
// throw new NotImplementedException("This shouldn't happen, according to Among Us disassembly.");
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ public override async ValueTask<bool> HandleRpcAsync(ClientPlayer sender, Client
return await HandleSetStartCounter(sender, sequenceId, startCounter);
}

case RpcCalls.UsePlatform:
{
if (!await ValidateOwnership(call, sender))
{
return false;
}

Rpc32UsePlatform.Deserialize(reader);
break;
}

default:
return await UnregisteredCall(call, sender);
}
Expand Down
30 changes: 6 additions & 24 deletions src/Impostor.Server/Net/Inner/Objects/InnerShipStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public InnerShipStatus(ILogger<InnerShipStatus> logger, Game game)
{
[SystemTypes.Electrical] = new SwitchSystem(),
[SystemTypes.MedBay] = new MedScanSystem(),
[SystemTypes.Reactor] = new ReactorSystemType(),
[SystemTypes.Reactor] = game.Options.Map == MapTypes.Airship ? new HeliSabotageSystemType() : new ReactorSystemType(),
[SystemTypes.LifeSupp] = new LifeSuppSystemType(),
[SystemTypes.Security] = new SecurityCameraSystemType(),
[SystemTypes.Comms] = new HudOverrideSystemType(),
Expand All @@ -56,31 +56,13 @@ public override async ValueTask DeserializeAsync(IClientPlayer sender, IClientPl
return;
}

if (initialState)
while (reader.Position < reader.Length)
{
// TODO: (_systems[SystemTypes.Doors] as DoorsSystemType).SetDoors();
foreach (var systemType in SystemTypeHelpers.AllTypes)
IMessageReader messageReader = reader.ReadMessage();
SystemTypes type = (SystemTypes)messageReader.Tag;
if (_systems.TryGetValue(type, out var value))
{
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);
}
}
value.Deserialize(messageReader, initialState);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public DoorsSystemType(IGame game)
MapTypes.Skeld => 13,
MapTypes.MiraHQ => 2,
MapTypes.Polus => 12,
MapTypes.Airship => 21, // TODO do the toilet doors count? 21 yes, 17 no
_ => throw new ArgumentOutOfRangeException(),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using Impostor.Api.Net.Messages;
using Microsoft.Extensions.Logging;

namespace Impostor.Server.Net.Inner.Objects.Systems.ShipStatus
{
public class HeliSabotageSystemType : ISystemType, IActivatable
{
public HeliSabotageSystemType()
{
Countdown = 10000f;
ActiveConsoles = new HashSet<Tuple<byte, byte>>();
CompletedConsoles = new HashSet<byte>();
}

public float Countdown { get; private set; }

public float Timer { get; private set; }

public HashSet<Tuple<byte, byte>> ActiveConsoles { get; }

public HashSet<byte> CompletedConsoles { get; }

public bool IsActive => Countdown < 10000.0;

public void Serialize(IMessageWriter writer, bool initialState)
{
throw new NotImplementedException();
}

public void Deserialize(IMessageReader reader, bool initialState)
{
Countdown = reader.ReadSingle();
Timer = reader.ReadSingle();
ActiveConsoles.Clear(); // TODO: Thread safety
CompletedConsoles.Clear(); // TODO: Thread safety

var activeCount = reader.ReadPackedUInt32();

for (var i = 0; i < activeCount; i++)
{
ActiveConsoles.Add(new Tuple<byte, byte>(reader.ReadByte(), reader.ReadByte()));
}

var completedCount = reader.ReadPackedUInt32();

for (var i = 0; i < completedCount; i++)
{
CompletedConsoles.Add(reader.ReadByte());
}
}
}
}
1 change: 1 addition & 0 deletions src/Impostor.Server/Net/State/Game.Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal partial class Game
typeof(InnerShipStatus), // HeadQuarters
typeof(InnerShipStatus), // PlanetMap
typeof(InnerShipStatus), // AprilShipStatus
typeof(InnerShipStatus), // Airship
};

private readonly List<InnerNetObject> _allObjects = new List<InnerNetObject>();
Expand Down

0 comments on commit c750c65

Please sign in to comment.