Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Impostor with 6pak fork #327

Merged
merged 29 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8f40ec7
Add announcements
js6pak Dec 16, 2020
e17452e
Save hostname instead of ip address
js6pak Dec 16, 2020
4442067
Remove TODO
js6pak Dec 16, 2020
5301c9f
Make Game#Host nullable
js6pak Dec 16, 2020
2febb47
Refactor SetMurderedByAsync into MurderPlayer
js6pak Dec 16, 2020
bf623e8
Modded handshake
js6pak Dec 27, 2020
a89fa0a
Custom rpc api
js6pak Jan 19, 2021
7d5219b
CI
js6pak Jan 28, 2021
7bbe449
Rpc rework
js6pak Mar 1, 2021
a1284b4
Add movement api
js6pak Mar 1, 2021
6f9f095
Merge branch 'announcements' into reactor
js6pak Mar 1, 2021
fc751f9
Merge branch 'save-hostname' into reactor
js6pak Mar 1, 2021
41b8394
Merge branch 'fix-murder' into reactor
js6pak Mar 1, 2021
80c4d89
No one likes you
js6pak Mar 1, 2021
c09b86c
Replace ColorId, HatId, PetId, SkinId with their respective enums
js6pak Mar 1, 2021
a3a9de8
Remove SetInfectedAsync
js6pak Mar 1, 2021
dafbe3b
Merge branch 'host-nullable' into reactor
js6pak Mar 1, 2021
8025f8b
+enabled field for anti cheat
DatGuy1 Mar 1, 2021
684f385
Merge pull request #3 from DatGuy1/patch-1
js6pak Mar 1, 2021
89a6f3f
Add special include for System.IO.Pipelines
miniduikboot Mar 1, 2021
127f826
Merge pull request #6 from miniduikboot/fix/system-io-pipelines
js6pak Mar 1, 2021
cfe6765
Make build.cake github again
js6pak Mar 1, 2021
b0a1665
Fix replays
js6pak Mar 1, 2021
7ae1256
Bring appveyor back
js6pak Mar 1, 2021
f2c6104
Remove github action workflow
js6pak Mar 1, 2021
85e7f1c
Revert .gitignore
js6pak Mar 1, 2021
b7c86e0
Requested changes and rpc anticheat refactor
js6pak Mar 2, 2021
91b8ded
Remove github action workflow, again
js6pak Mar 2, 2021
014d893
Use validation methods in Deserialize
js6pak Mar 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/stale.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI
js6pak marked this conversation as resolved.
Show resolved Hide resolved

on:
push:

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.103

- name: Cake Action
run: |
dotnet tool restore
dotnet cake build.cake --bootstrap
dotnet cake build.cake --pack

- uses: actions/upload-artifact@v2
with:
path: ./build/*.zip
3 changes: 2 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#addin "nuget:?package=Cake.FileHelpers&Version=3.3.0"

var buildId = EnvironmentVariable("GITHUB_RUN_NUMBER") ?? EnvironmentVariable("APPVEYOR_BUILD_VERSION");
var buildRelease = EnvironmentVariable("APPVEYOR_REPO_TAG") == "true";
var buildVersion = FindRegexMatchGroupInFile("./src/Directory.Build.props", @"\<VersionPrefix\>(.*?)\<\/VersionPrefix\>", 1, System.Text.RegularExpressions.RegexOptions.None).Value;
var buildDir = MakeAbsolute(Directory("./build"));

Expand All @@ -11,7 +12,7 @@ var configuration = Argument("configuration", "Release");

var msbuildSettings = new DotNetCoreMSBuildSettings();

if (buildId != null) {
if (!buildRelease && buildId != null) {
msbuildSettings.Properties["VersionSuffix"] = new[] { "ci." + buildId };
buildVersion += "-ci." + buildId;
}
Expand Down
21 changes: 21 additions & 0 deletions src/Impostor.Api/Events/Announcements/IAnnouncementRequestEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,42 @@

namespace Impostor.Api.Events.Announcements
{
/// <summary>
/// Event fired after client requests a announcement.
/// </summary>
public interface IAnnouncementRequestEvent : IEvent
{
public interface IResponse
AeonLucid marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Gets or sets FreeWeekendState, currently unused by the client.
/// </summary>
public FreeWeekendState FreeWeekendState { get; set; }

/// <summary>
/// Gets or sets a value indicating whether announcement should be loaded from client's cache, can save some bytes.
/// </summary>
public bool UseCached { get; set; }

/// <summary>
/// Gets or sets announcement, should be null when <see cref="UseCached"/> is set to true.
/// </summary>
public Announcement? Announcement { get; set; }
}

/// <summary>
/// Gets client's last announcement id.
/// </summary>
public int Id { get; }

/// <summary>
/// Gets client's language.
/// </summary>
public Language Language { get; }

/// <summary>
/// Gets or sets plugin made response.
/// </summary>
public IResponse Response { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public interface IInnerCustomNetworkTransform : IInnerNetObject
/// </summary>
Vector2 Position { get; }

/// <summary>
/// Gets current object's velocity.
/// </summary>
Vector2 Velocity { get; }

/// <summary>
/// Snaps the current to the given position <see cref="IInnerPlayerControl"/>.
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion src/Impostor.Api/Unity/Mathf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ public static float Clamp01(float value)
/// <para>The interpolated float result between the two float values.</para>
/// </returns>
public static float Lerp(float a, float b, float t) => a + ((b - a) * Clamp01(t));

public static float ReverseLerp(float t)
{
return Clamp((t - -40f) / (40f - -40f), 0f, 1f);
}
}
}
}
9 changes: 2 additions & 7 deletions src/Impostor.Hazel/MessageWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public void Write(IInnerNetObject innerNetObject)

public void Write(Vector2 vector)
{
Write((ushort)(ReverseLerp(vector.X) * (double) ushort.MaxValue));
Write((ushort)(ReverseLerp(vector.Y) * (double) ushort.MaxValue));
Write((ushort)(Mathf.ReverseLerp(vector.X) * (double) ushort.MaxValue));
Write((ushort)(Mathf.ReverseLerp(vector.Y) * (double) ushort.MaxValue));
}

///
Expand Down Expand Up @@ -352,10 +352,5 @@ public void Dispose()
{
Recycle();
}

private static float ReverseLerp(float t)
{
return Mathf.Clamp((t - -40f) / (40f - -40f), 0f, 1f);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public void OnAnnouncementRequestEvent(IAnnouncementRequestEvent e)
{
if (e.Id == Id)
{
// Client already has announcement cached, lets just use that
e.Response.UseCached = true;
}
else
{
// Client is receiving this announcement for the first time, window will popup
e.Response.Announcement = new Announcement(Id, "Hello!");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Impostor.Server/Impostor.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- HACK: Some plugins depend on System.IO.Pipelines and expect the version to be 5.0.0.0, but .NET 5 only ships version 5.0.0.1. It is pretty hard to convince MSBuild to build against the correct DLL, so we special case it here. Remove once we move past .NET 5 -->
<PackageReference Include="System.IO.Pipelines" Version="5.0.0"/>
<PackageReference Include="System.IO.Pipelines" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
98 changes: 98 additions & 0 deletions src/Impostor.Server/Net/Inner/InnerNetObject.Anticheat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Threading.Tasks;
using Impostor.Api;
using Impostor.Api.Net;
using Impostor.Server.Net.Inner.Objects;

namespace Impostor.Server.Net.Inner
{
internal abstract partial class InnerNetObject
{
protected async ValueTask<bool> ValidateOwnership(CheatContext context, IClientPlayer sender)
{
if (!sender.IsOwner(this))
{
if (await sender.Client.ReportCheatAsync(context, $"Failed ownership check on {GetType().Name}"))
{
return false;
}
}

return true;
}

protected async ValueTask<bool> ValidateHost(CheatContext context, IClientPlayer sender)
{
if (!sender.IsHost)
{
if (await sender.Client.ReportCheatAsync(context, "Failed host check"))
{
return false;
}
}

return true;
}

protected async ValueTask<bool> ValidateTarget(CheatContext context, IClientPlayer sender, IClientPlayer? target)
{
if (target == null)
{
if (await sender.Client.ReportCheatAsync(context, "Failed target check"))
{
return false;
}
}

return true;
}

protected async ValueTask<bool> ValidateBroadcast(CheatContext context, IClientPlayer sender, IClientPlayer? target)
{
if (target != null)
{
if (await sender.Client.ReportCheatAsync(context, "Failed broadcast check"))
{
return false;
}
}

return true;
}

protected async ValueTask<bool> ValidateCmd(CheatContext context, IClientPlayer sender, IClientPlayer? target)
{
if (target == null || !target.IsHost)
{
if (await sender.Client.ReportCheatAsync(context, "Failed cmd check"))
{
return false;
}
}

return true;
}

protected async ValueTask<bool> ValidateImpostor(CheatContext context, IClientPlayer sender, InnerPlayerInfo playerInfo, bool value = true)
{
if (playerInfo.IsImpostor != value)
{
if (await sender.Client.ReportCheatAsync(context, "Failed impostor check"))
{
return false;
}
}

return true;
}

protected async ValueTask<bool> UnregisteredCall(CheatContext context, IClientPlayer sender)
{
if (await sender.Client.ReportCheatAsync(context, "Client sent unregistered call"))
{
return false;
}

return true;
}
}
}
80 changes: 4 additions & 76 deletions src/Impostor.Server/Net/Inner/InnerNetObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Impostor.Server.Net.Inner
{
internal abstract class InnerNetObject : GameObject, IInnerNetObject
internal abstract partial class InnerNetObject : GameObject, IInnerNetObject
{
private const int HostInheritId = -2;

Expand All @@ -27,81 +27,9 @@ public bool IsOwnedBy(IClientPlayer player)

public abstract ValueTask DeserializeAsync(IClientPlayer sender, IClientPlayer? target, IMessageReader reader, bool initialState);

protected async ValueTask<bool> TestRpc(ClientPlayer sender, ClientPlayer? target, RpcCalls call, Dictionary<RpcCalls, RpcInfo> rpcs)
{
if (call == RpcCalls.CustomRpc)
{
return true;
}

if (rpcs.TryGetValue(call, out var rpc))
{
if (rpc.CheckOwnership && !sender.IsOwner(this))
{
if (await sender.Client.ReportCheatAsync(call, $"Client sent {call} to an unowned {GetType().Name}"))
{
return false;
}
}

if (rpc.RequireHost && !sender.IsHost)
{
if (await sender.Client.ReportCheatAsync(call, $"Client attempted to send {call} as non-host"))
{
return false;
}
}

switch (rpc.TargetType)
{
case RpcTargetType.Target when target == null:
{
if (await sender.Client.ReportCheatAsync(call, $"Client sent {call} as a broadcast instead to specific player"))
{
return false;
}

break;
}

case RpcTargetType.Broadcast when target != null:
{
if (await sender.Client.ReportCheatAsync(call, $"Client sent {call} to a specific player instead of broadcast"))
{
return false;
}

break;
}

case RpcTargetType.Cmd when target == null || !target.IsHost:
{
if (await sender.Client.ReportCheatAsync(call, $"Client sent {call} to the wrong player"))
{
return false;
}

break;
}

case RpcTargetType.Both:
break;
}

return true;
}

if (await sender.Client.ReportCheatAsync(call, "Client sent unregistered call"))
{
return false;
}

return true;
}

public abstract ValueTask<bool> HandleRpc(ClientPlayer sender, ClientPlayer? target, RpcCalls call, IMessageReader reader);
public abstract ValueTask<bool> HandleRpcAsync(ClientPlayer sender, ClientPlayer? target, RpcCalls call, IMessageReader reader);

protected ValueTask HandleCustomRpc(IMessageReader reader, Game game)
protected ValueTask<bool> HandleCustomRpc(IMessageReader reader, Game game)
{
var lengthOrShortId = reader.ReadPackedInt32();

Expand All @@ -113,7 +41,7 @@ protected ValueTask HandleCustomRpc(IMessageReader reader, Game game)

// TODO handle custom rpcs

return default;
return ValueTask.FromResult(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ namespace Impostor.Server.Net.Inner.Objects.Components
{
internal partial class InnerCustomNetworkTransform : IInnerCustomNetworkTransform
{
public Vector2 Position => _targetSyncPosition;

public async ValueTask SnapToAsync(Vector2 position)
{
var minSid = (ushort)(_lastSequenceId + 5U);

// Snap in the server.
SnapTo(position, minSid);
await SnapToAsync(_game.GetClientPlayer(OwnerId), position, minSid);

// Broadcast to all clients.
using (var writer = _game.StartRpc(NetId, RpcCalls.SnapTo))
Expand Down