mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-20 01:46:11 +00:00
Added CustomNetworkTransform and VoteBanSystem
This commit is contained in:
1 parent
6c075a4827
commit
64f043767a
6 files changed
+160
-17
No files matched your search
@@ -1,22 +1,75 @@
|
||||
using Impostor.Server.Net.Messages;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Impostor.Server.Net.Messages;
|
||||
using Impostor.Shared.Innersloth;
|
||||
|
||||
namespace Impostor.Server.GameData.Objects.Components
|
||||
{
|
||||
public class InnerCustomNetworkTransform : InnerNetObject
|
||||
{
|
||||
private static readonly FloatRange XRange = new FloatRange(-40f, 40f);
|
||||
private static readonly FloatRange YRange = new FloatRange(-40f, 40f);
|
||||
|
||||
private ushort _lastSequenceId;
|
||||
private Vector2 _targetSyncPosition;
|
||||
private Vector2 _targetSyncVelocity;
|
||||
|
||||
public override void HandleRpc(byte callId, IMessageReader reader)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Serialize(IMessageWriter writer, bool initialState)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Deserialize(IMessageReader reader, bool initialState)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
if (initialState)
|
||||
{
|
||||
_lastSequenceId = reader.ReadUInt16();
|
||||
_targetSyncPosition = ReadVector2(reader);
|
||||
_targetSyncVelocity = ReadVector2(reader);
|
||||
|
||||
Console.WriteLine(_targetSyncPosition + " - " + _targetSyncVelocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSid = reader.ReadUInt16();
|
||||
if (!SidGreaterThan(newSid, _lastSequenceId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastSequenceId = newSid;
|
||||
_targetSyncPosition = ReadVector2(reader);
|
||||
_targetSyncVelocity = ReadVector2(reader);
|
||||
|
||||
// TODO: Snap / update position
|
||||
|
||||
Console.WriteLine(_targetSyncPosition + " - " + _targetSyncVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SidGreaterThan(ushort newSid, ushort prevSid)
|
||||
{
|
||||
var num = (ushort)(prevSid + (uint) short.MaxValue);
|
||||
|
||||
return (int) prevSid < (int) num
|
||||
? newSid > prevSid && newSid <= num
|
||||
: newSid > prevSid || newSid <= num;
|
||||
}
|
||||
|
||||
public static Vector2 ReadVector2(IMessageReader reader)
|
||||
{
|
||||
var v = (float) (int) reader.ReadUInt16() / 65535f;
|
||||
var v2 = (float) (int) reader.ReadUInt16() / 65535f;
|
||||
|
||||
var v3 = XRange.Lerp(v);
|
||||
var v4 = YRange.Lerp(v2);
|
||||
|
||||
return new Vector2(v3, v4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,49 @@
|
||||
using Impostor.Server.Net.Messages;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Impostor.Server.Net.Messages;
|
||||
|
||||
namespace Impostor.Server.GameData.Objects.Components
|
||||
{
|
||||
public class InnerVoteBanSystem : InnerNetObject
|
||||
{
|
||||
private readonly Dictionary<int, int[]> _votes;
|
||||
|
||||
public InnerVoteBanSystem()
|
||||
{
|
||||
_votes = new Dictionary<int, int[]>();
|
||||
}
|
||||
|
||||
public override void HandleRpc(byte callId, IMessageReader reader)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Serialize(IMessageWriter writer, bool initialState)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Deserialize(IMessageReader reader, bool initialState)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
var unknown = reader.ReadBoolean();
|
||||
if (unknown)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var v4 = reader.ReadInt32();
|
||||
|
||||
if (!_votes.TryGetValue(v4, out var v12))
|
||||
{
|
||||
v12 = new int[3];
|
||||
_votes[v4] = v12;
|
||||
}
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
v12[i] = reader.ReadPackedInt32();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Impostor.Server.GameData.Objects.Components;
|
||||
using System;
|
||||
using Impostor.Server.GameData.Objects.Components;
|
||||
using Impostor.Server.Games;
|
||||
using Impostor.Server.Net.Messages;
|
||||
|
||||
@@ -15,21 +16,33 @@ namespace Impostor.Server.GameData.Objects
|
||||
Components.Add(this);
|
||||
Components.Add(new InnerPlayerPhysics());
|
||||
Components.Add(new InnerCustomNetworkTransform());
|
||||
|
||||
PlayerId = byte.MaxValue;
|
||||
}
|
||||
|
||||
public bool IsNew { get; private set; }
|
||||
|
||||
public byte PlayerId { get; private set; }
|
||||
|
||||
public override void HandleRpc(byte callId, IMessageReader reader)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Serialize(IMessageWriter writer, bool initialState)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Deserialize(IMessageReader reader, bool initialState)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
// TODO: Might be unreliable, maybe we need to check if the length is 2 or 1.
|
||||
if (initialState)
|
||||
{
|
||||
IsNew = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
PlayerId = reader.ReadByte();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,16 +50,21 @@ namespace Impostor.Server.Net.State
|
||||
{
|
||||
case GameDataTag.DataFlag:
|
||||
{
|
||||
var objectNetId = reader.ReadPackedUInt32();
|
||||
Logger.Verbose("> Update {0}", objectNetId);
|
||||
if (_allObjectsFast.TryGetValue(reader.ReadPackedUInt32(), out var obj))
|
||||
{
|
||||
obj.Deserialize(reader, false);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GameDataTag.RpcFlag:
|
||||
{
|
||||
var objectNetId = reader.ReadPackedUInt32();
|
||||
var callId = reader.ReadByte();
|
||||
Logger.Verbose("> RPC {0} {1}", objectNetId, callId);
|
||||
if (_allObjectsFast.TryGetValue(reader.ReadPackedUInt32(), out var obj))
|
||||
{
|
||||
// obj.HandleRpc(reader.ReadByte(), reader);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Impostor.Shared.Unity;
|
||||
|
||||
namespace Impostor.Shared.Innersloth
|
||||
{
|
||||
public class FloatRange
|
||||
{
|
||||
private readonly float _min;
|
||||
private readonly float _max;
|
||||
|
||||
public FloatRange(float min, float max)
|
||||
{
|
||||
_min = min;
|
||||
_max = max;
|
||||
}
|
||||
|
||||
public float Lerp(float v) => Mathf.Lerp(this._min, this._max, v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Impostor.Shared.Unity
|
||||
{
|
||||
public static class Mathf
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>Clamps value between 0 and 1 and returns value.</para>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public static float Clamp01(float value)
|
||||
{
|
||||
if ((double) value < 0.0)
|
||||
return 0.0f;
|
||||
return (double) value > 1.0 ? 1f : value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Linearly interpolates between a and b by t.</para>
|
||||
/// </summary>
|
||||
/// <param name="a">The start value.</param>
|
||||
/// <param name="b">The end value.</param>
|
||||
/// <param name="t">The interpolation value between the two floats.</param>
|
||||
/// <returns>
|
||||
/// <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) * Mathf.Clamp01(t);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user