From: AeonLucid Date: Mon, 19 Oct 2020 10:55:26 +0000 (+0200) Subject: Remove Impostor.Shared X-Git-Tag: v1.2.2~96^2~67 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=61f50c6d41a549e5e18c1ec8a2bc0efcd807af34;p=rhonda%2Fimpostor.git Remove Impostor.Shared --- diff --git a/src/Impostor.Api/Events/Attributes/EventListenerAttribute.cs b/src/Impostor.Api/Events/Attributes/EventListenerAttribute.cs index c8b9360..a373946 100644 --- a/src/Impostor.Api/Events/Attributes/EventListenerAttribute.cs +++ b/src/Impostor.Api/Events/Attributes/EventListenerAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace Impostor.Server.Events +namespace Impostor.Api.Events { [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class EventListenerAttribute : Attribute diff --git a/src/Impostor.Api/Events/EventPriority.cs b/src/Impostor.Api/Events/EventPriority.cs index dbf506e..641f4aa 100644 --- a/src/Impostor.Api/Events/EventPriority.cs +++ b/src/Impostor.Api/Events/EventPriority.cs @@ -1,4 +1,4 @@ -namespace Impostor.Server.Events +namespace Impostor.Api.Events { public enum EventPriority { diff --git a/src/Impostor.Api/Events/Game/GameCreatedEvent.cs b/src/Impostor.Api/Events/Game/GameCreatedEvent.cs index a916227..dc96fae 100644 --- a/src/Impostor.Api/Events/Game/GameCreatedEvent.cs +++ b/src/Impostor.Api/Events/Game/GameCreatedEvent.cs @@ -1,6 +1,6 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; -namespace Impostor.Server.Events +namespace Impostor.Api.Events { /// /// Called whenever a new is created. diff --git a/src/Impostor.Api/Events/Game/GameDestroyedEvent.cs b/src/Impostor.Api/Events/Game/GameDestroyedEvent.cs index 5d32143..36fec11 100644 --- a/src/Impostor.Api/Events/Game/GameDestroyedEvent.cs +++ b/src/Impostor.Api/Events/Game/GameDestroyedEvent.cs @@ -1,6 +1,6 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; -namespace Impostor.Server.Events +namespace Impostor.Api.Events { /// /// Called whenever a new is destroyed. diff --git a/src/Impostor.Api/Events/Game/IGameEvent.cs b/src/Impostor.Api/Events/Game/IGameEvent.cs index 8d77c4b..4aacd18 100644 --- a/src/Impostor.Api/Events/Game/IGameEvent.cs +++ b/src/Impostor.Api/Events/Game/IGameEvent.cs @@ -1,6 +1,6 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; -namespace Impostor.Server.Events +namespace Impostor.Api.Events { public interface IGameEvent : IEvent { diff --git a/src/Impostor.Api/Events/Game/PlayerJoinedGameEvent.cs b/src/Impostor.Api/Events/Game/PlayerJoinedGameEvent.cs index 0a47f64..3c165aa 100644 --- a/src/Impostor.Api/Events/Game/PlayerJoinedGameEvent.cs +++ b/src/Impostor.Api/Events/Game/PlayerJoinedGameEvent.cs @@ -1,7 +1,7 @@ -using Impostor.Server.Games; -using Impostor.Server.Net; +using Impostor.Api.Games; +using Impostor.Api.Net; -namespace Impostor.Server.Events +namespace Impostor.Api.Events { public class PlayerJoinedGameEvent : IGameEvent { diff --git a/src/Impostor.Api/Events/Game/PlayerLeftGameEvent.cs b/src/Impostor.Api/Events/Game/PlayerLeftGameEvent.cs index e17c333..5947ff2 100644 --- a/src/Impostor.Api/Events/Game/PlayerLeftGameEvent.cs +++ b/src/Impostor.Api/Events/Game/PlayerLeftGameEvent.cs @@ -1,7 +1,7 @@ -using Impostor.Server.Games; -using Impostor.Server.Net; +using Impostor.Api.Games; +using Impostor.Api.Net; -namespace Impostor.Server.Events +namespace Impostor.Api.Events { public class PlayerLeftGameEvent : IGameEvent { diff --git a/src/Impostor.Api/Events/IEvent.cs b/src/Impostor.Api/Events/IEvent.cs index e9b3505..796898e 100644 --- a/src/Impostor.Api/Events/IEvent.cs +++ b/src/Impostor.Api/Events/IEvent.cs @@ -1,4 +1,4 @@ -namespace Impostor.Server.Events +namespace Impostor.Api.Events { public interface IEvent { diff --git a/src/Impostor.Api/Events/IEventCancelable.cs b/src/Impostor.Api/Events/IEventCancelable.cs index 75e2364..319f02a 100644 --- a/src/Impostor.Api/Events/IEventCancelable.cs +++ b/src/Impostor.Api/Events/IEventCancelable.cs @@ -1,4 +1,4 @@ -namespace Impostor.Server.Events +namespace Impostor.Api.Events { public interface IEventCancelable : IEvent { diff --git a/src/Impostor.Api/Events/IEventListener.cs b/src/Impostor.Api/Events/IEventListener.cs index 3e08c36..76392fc 100644 --- a/src/Impostor.Api/Events/IEventListener.cs +++ b/src/Impostor.Api/Events/IEventListener.cs @@ -1,4 +1,4 @@ -namespace Impostor.Server.Events +namespace Impostor.Api.Events { public interface IEventListener { diff --git a/src/Impostor.Api/Events/Managers/IEventManager.cs b/src/Impostor.Api/Events/Managers/IEventManager.cs index 11ae01d..a9d433b 100644 --- a/src/Impostor.Api/Events/Managers/IEventManager.cs +++ b/src/Impostor.Api/Events/Managers/IEventManager.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace Impostor.Server.Events.Managers +namespace Impostor.Api.Events.Managers { public interface IEventManager { diff --git a/src/Impostor.Api/Exceptions/ImpostorException.cs b/src/Impostor.Api/Exceptions/ImpostorException.cs index 9e9b8f7..188c50e 100644 --- a/src/Impostor.Api/Exceptions/ImpostorException.cs +++ b/src/Impostor.Api/Exceptions/ImpostorException.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.Serialization; -namespace Impostor.Server +namespace Impostor.Api { public class ImpostorException : Exception { diff --git a/src/Impostor.Api/Games/Extensions/GameManagerExtensions.cs b/src/Impostor.Api/Games/Extensions/GameManagerExtensions.cs index db173c2..1f4bd5d 100644 --- a/src/Impostor.Api/Games/Extensions/GameManagerExtensions.cs +++ b/src/Impostor.Api/Games/Extensions/GameManagerExtensions.cs @@ -1,8 +1,8 @@ using System.Linq; -using Impostor.Server.Games.Managers; -using Impostor.Shared.Innersloth.Data; +using Impostor.Api.Games.Managers; +using Impostor.Api.Innersloth.Data; -namespace Impostor.Server.Games +namespace Impostor.Api.Games { public static class GameManagerExtensions { diff --git a/src/Impostor.Api/Games/GameCode.cs b/src/Impostor.Api/Games/GameCode.cs index 0d1fd37..2c30e7e 100644 --- a/src/Impostor.Api/Games/GameCode.cs +++ b/src/Impostor.Api/Games/GameCode.cs @@ -1,7 +1,7 @@ using System; -using Impostor.Shared.Innersloth; +using Impostor.Api.Innersloth; -namespace Impostor.Server.Games +namespace Impostor.Api.Games { public readonly struct GameCode : IEquatable { diff --git a/src/Impostor.Api/Games/GameJoinError.cs b/src/Impostor.Api/Games/GameJoinError.cs index c4d7c6d..4889ea9 100644 --- a/src/Impostor.Api/Games/GameJoinError.cs +++ b/src/Impostor.Api/Games/GameJoinError.cs @@ -1,4 +1,4 @@ -namespace Impostor.Server.Games +namespace Impostor.Api.Games { public enum GameJoinError { diff --git a/src/Impostor.Api/Games/GameJoinResult.cs b/src/Impostor.Api/Games/GameJoinResult.cs index 40babeb..b33a2b6 100644 --- a/src/Impostor.Api/Games/GameJoinResult.cs +++ b/src/Impostor.Api/Games/GameJoinResult.cs @@ -1,8 +1,8 @@ using System; using System.Diagnostics.CodeAnalysis; -using Impostor.Server.Net; +using Impostor.Api.Net; -namespace Impostor.Server.Games +namespace Impostor.Api.Games { public readonly struct GameJoinResult { diff --git a/src/Impostor.Api/Games/IGame.cs b/src/Impostor.Api/Games/IGame.cs index dcd25a2..6de41f0 100644 --- a/src/Impostor.Api/Games/IGame.cs +++ b/src/Impostor.Api/Games/IGame.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; using System.Net; -using Impostor.Server.Net; -using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth; -using Impostor.Shared.Innersloth.Data; +using Impostor.Api.Innersloth; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; -namespace Impostor.Server.Games +namespace Impostor.Api.Games { public interface IGame { diff --git a/src/Impostor.Api/Games/Managers/IGameManager.cs b/src/Impostor.Api/Games/Managers/IGameManager.cs index d089772..10a05f0 100644 --- a/src/Impostor.Api/Games/Managers/IGameManager.cs +++ b/src/Impostor.Api/Games/Managers/IGameManager.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Impostor.Server.Games.Managers +namespace Impostor.Api.Games.Managers { public interface IGameManager { diff --git a/src/Impostor.Api/Impostor.Api.csproj b/src/Impostor.Api/Impostor.Api.csproj index 0e72d47..7a1d3bb 100644 --- a/src/Impostor.Api/Impostor.Api.csproj +++ b/src/Impostor.Api/Impostor.Api.csproj @@ -2,16 +2,11 @@ net5.0 - Impostor.Server - enable None ProjectRules.ruleset + 9 - - - - diff --git a/src/Impostor.Api/Innersloth/Data/AlterGameTags.cs b/src/Impostor.Api/Innersloth/Data/AlterGameTags.cs new file mode 100644 index 0000000..ee13ae2 --- /dev/null +++ b/src/Impostor.Api/Innersloth/Data/AlterGameTags.cs @@ -0,0 +1,7 @@ +namespace Impostor.Api.Innersloth.Data +{ + public enum AlterGameTags : byte + { + ChangePrivacy = 1 + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/Data/DisconnectReason.cs b/src/Impostor.Api/Innersloth/Data/DisconnectReason.cs new file mode 100644 index 0000000..e1a8e3a --- /dev/null +++ b/src/Impostor.Api/Innersloth/Data/DisconnectReason.cs @@ -0,0 +1,54 @@ +namespace Impostor.Api.Innersloth.Data +{ + public enum DisconnectReason + { + ExitGame = 0, + // The game you tried to join is full. + // Check with the host to see if you can join next round. + GameFull = 1, + // The game you tried to join already started. + // Check with the host to see if you can join next round. + GameStarted = 2, + // Could not find the game you're looking for. + GameMissing = 3, + IncorrectGame = 18, + // For these a message can be given, specifying an empty message shows + // "An unknown error disconnected you from the server." + CustomMessage1 = 4, + Custom = 8, + // CustomMessage3 = 11, + // CustomMessage4 = 12, + // CustomMessage5 = 13, + // CustomMessage6 = 14, + // CustomMessage7 = 15, + // You are running an older version of the game. + // Please update to play with others. + IncorrectVersion = 5, + // You cannot rejoin that room. + // You were banned + Banned = 6, + // You can rejoin if the room hasn't started + // You were kicked + Kicked = 7, + // You were banned for hacking. + // Please stop. + Hacking = 10, + Destroy = 16, + // You disconnected from the host. + // If this happens often, check your WiFi strength. + // + // You disconnected from the server. + // If this happens often, check your network strength. + // This may also be a server issue. + Error = 17, + // The server stopped this game. Possibly due to inactivity. + ServerRequest = 19, + // The Among Us servers are overloaded. + // Sorry! Please try again later! + ServerFull = 20, + FocusLostBackground = 207, + IntentionalLeaving = 208, + FocusLost = 209, + NewConnection = 210 + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/Data/GameKeywords.cs b/src/Impostor.Api/Innersloth/Data/GameKeywords.cs new file mode 100644 index 0000000..f3b37cc --- /dev/null +++ b/src/Impostor.Api/Innersloth/Data/GameKeywords.cs @@ -0,0 +1,19 @@ +using System; + +namespace Impostor.Api.Innersloth.Data +{ + [Flags] + public enum GameKeywords : uint + { + All = 0, + Other = 1, + Spanish = 2, + Korean = 4, + Russian = 8, + Portuguese = 16, + Arabic = 32, + Filipone = 64, + Polish = 128, + English = 256 + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/Data/GameStates.cs b/src/Impostor.Api/Innersloth/Data/GameStates.cs new file mode 100644 index 0000000..986e2d2 --- /dev/null +++ b/src/Impostor.Api/Innersloth/Data/GameStates.cs @@ -0,0 +1,10 @@ +namespace Impostor.Api.Innersloth.Data +{ + public enum GameStates : byte + { + NotStarted = 0, + Started = 1, + Ended = 2, + Destroyed = 3 + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/Data/MapFlags.cs b/src/Impostor.Api/Innersloth/Data/MapFlags.cs new file mode 100644 index 0000000..66e0c95 --- /dev/null +++ b/src/Impostor.Api/Innersloth/Data/MapFlags.cs @@ -0,0 +1,12 @@ +using System; + +namespace Impostor.Api.Innersloth.Data +{ + [Flags] + public enum MapFlags + { + Skeld = 1, + MiraHQ = 2, + Polus = 4 + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/FloatRange.cs b/src/Impostor.Api/Innersloth/FloatRange.cs new file mode 100644 index 0000000..c8a0824 --- /dev/null +++ b/src/Impostor.Api/Innersloth/FloatRange.cs @@ -0,0 +1,22 @@ +using Impostor.Api.Unity; + +namespace Impostor.Api.Innersloth +{ + public class FloatRange + { + private readonly float _min; + private readonly float _max; + + public FloatRange(float min, float max) + { + _min = min; + _max = max; + } + + public float Width => _max - _min; + + public float Lerp(float v) => Mathf.Lerp(_min, _max, v); + + public float ReverseLerp(float t) => Mathf.Clamp((t - _min) / Width, 0.0f, 1f); + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/GameCodeParser.cs b/src/Impostor.Api/Innersloth/GameCodeParser.cs new file mode 100644 index 0000000..9717cff --- /dev/null +++ b/src/Impostor.Api/Innersloth/GameCodeParser.cs @@ -0,0 +1,142 @@ +using System; +using System.Buffers.Binary; +using System.Linq; +using System.Security.Cryptography; +using System.Text; + +namespace Impostor.Api.Innersloth +{ + public static class GameCodeParser + { + private const string V2 = "QWXRTYLPESDFGHUJKZOCVBINMA"; + private static readonly int[] V2Map = { + 25, + 21, + 19, + 10, + 8, + 11, + 12, + 13, + 22, + 15, + 16, + 6, + 24, + 23, + 18, + 7, + 0, + 3, + 9, + 4, + 14, + 20, + 1, + 2, + 5, + 17 + }; + private static readonly RNGCryptoServiceProvider Random = new RNGCryptoServiceProvider(); + + public static string IntToGameName(int input) + { + // V2. + if (input < -1) + { + return IntToGameNameV2(input); + } + + // V1. + Span code = stackalloc byte[4]; + BinaryPrimitives.WriteInt32LittleEndian(code, input); +#if NETSTANDARD2_0 + return Encoding.UTF8.GetString(code.Slice(0, 4).ToArray()); +#else + return Encoding.UTF8.GetString(code.Slice(0, 4)); +#endif + } + + private static string IntToGameNameV2(int input) + { + var a = input & 0x3FF; + var b = (input >> 10) & 0xFFFFF; + + return new string(new [] + { + V2[a % 26], + V2[a / 26], + V2[b % 26], + V2[b / 26 % 26], + V2[b / (26 * 26) % 26], + V2[b / (26 * 26 * 26) % 26] + }); + } + + public static int GameNameToInt(string code) + { + var upper = code.ToUpperInvariant(); + if (upper.Any(x => !char.IsLetter(x))) + { + return -1; + } + + var len = code.Length; + if (len == 6) + { + return GameNameToIntV2(upper); + } + + if (len == 4) + { + return code[0] | ((code[1] | ((code[2] | (code[3] << 8)) << 8)) << 8); + } + + return -1; + } + + private static int GameNameToIntV2(string code) + { + var a = V2Map[code[0] - 65]; + var b = V2Map[code[1] - 65]; + var c = V2Map[code[2] - 65]; + var d = V2Map[code[3] - 65]; + var e = V2Map[code[4] - 65]; + var f = V2Map[code[5] - 65]; + + var one = (a + 26 * b) & 0x3FF; + var two = (c + 26 * (d + 26 * (e + 26 * f))); + + return (int) (one | ((two << 10) & 0x3FFFFC00) | 0x80000000); + } + + public static int GenerateCode(int len) + { + if (len != 4 && len != 6) + { + throw new ArgumentException("should be 4 or 6", nameof(len)); + } + + // Generate random bytes. +#if NETSTANDARD2_0 + var data = new byte[len]; +#else + Span data = stackalloc byte[len]; +#endif + Random.GetBytes(data); + + // Convert to their char representation. + Span dataChar = stackalloc char[len]; + for (var i = 0; i < len; i++) + { + dataChar[i] = V2[V2Map[data[i] % 26]]; + } + +#if NETSTANDARD2_0 + return GameNameToInt(new string(dataChar.ToArray())); +#else + return GameNameToInt(new string(dataChar)); +#endif + } + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/GameData/GameDataTag.cs b/src/Impostor.Api/Innersloth/GameData/GameDataTag.cs new file mode 100644 index 0000000..d5f3fc5 --- /dev/null +++ b/src/Impostor.Api/Innersloth/GameData/GameDataTag.cs @@ -0,0 +1,13 @@ +namespace Impostor.Api.Innersloth.GameData +{ + public static class GameDataTag + { + public const byte DataFlag = 1; + public const byte RpcFlag = 2; + public const byte SpawnFlag = 4; + public const byte DespawnFlag = 5; + public const byte SceneChangeFlag = 6; + public const byte ReadyFlag = 7; + public const byte ChangeSettingsFlag = 8; + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/GameOptionsData.cs b/src/Impostor.Api/Innersloth/GameOptionsData.cs new file mode 100644 index 0000000..cac6371 --- /dev/null +++ b/src/Impostor.Api/Innersloth/GameOptionsData.cs @@ -0,0 +1,104 @@ +using System; +using System.IO; +using Impostor.Api.Innersloth.Data; + +namespace Impostor.Api.Innersloth +{ + public class GameOptionsData + { + public byte Version { get; set; } + public byte MaxPlayers { get; set; } + public GameKeywords Keywords { get; set; } + public byte MapId { get; set; } + public float PlayerSpeedMod { get; set; } + public float CrewLightMod { get; set; } + public float ImpostorLightMod { get; set; } + public float KillCooldown { get; set; } + public int NumCommonTasks { get; set; } + public int NumLongTasks { get; set; } + public int NumShortTasks { get; set; } + public int NumEmergencyMeetings { get; set; } + public int EmergencyCooldown { get; set; } + public int NumImpostors { get; set; } + public bool GhostsDoTasks { get; set; } + public int KillDistance { get; set; } + public int DiscussionTime { get; set; } + public int VotingTime { get; set; } + public bool ConfirmImpostor { get; set; } + public bool VisualTasks { get; set; } + public bool IsDefaults { get; set; } + + public void Serialize(BinaryWriter writer, byte version) + { + writer.Write((byte) version); + writer.Write((byte) MaxPlayers); + writer.Write((uint) Keywords); + writer.Write((byte) MapId); + writer.Write((float) PlayerSpeedMod); + writer.Write((float) CrewLightMod); + writer.Write((float) ImpostorLightMod); + writer.Write((float) KillCooldown); + writer.Write((byte) NumCommonTasks); + writer.Write((byte) NumLongTasks); + writer.Write((byte) NumShortTasks); + writer.Write((int) NumEmergencyMeetings); + writer.Write((byte) NumImpostors); + writer.Write((byte) KillDistance); + writer.Write((uint) DiscussionTime); + writer.Write((uint) VotingTime); + writer.Write((bool) IsDefaults); + if (version > 1) + { + writer.Write((byte) EmergencyCooldown); + } + + if (version > 2) + { + writer.Write((bool) ConfirmImpostor); + writer.Write((bool) VisualTasks); + } + } + + public static GameOptionsData Deserialize(ReadOnlyMemory bytes) + { + // TODO: Remove memory allocation. + + using (var stream = new MemoryStream(bytes.ToArray())) + using (var reader = new BinaryReader(stream)) + { + var result = new GameOptionsData(); + + result.Version = reader.ReadByte(); + result.MaxPlayers = reader.ReadByte(); + result.Keywords = (GameKeywords) reader.ReadUInt32(); + result.MapId = reader.ReadByte(); + result.PlayerSpeedMod = reader.ReadSingle(); + result.CrewLightMod = reader.ReadSingle(); + result.ImpostorLightMod = reader.ReadSingle(); + result.KillCooldown = reader.ReadSingle(); + result.NumCommonTasks = reader.ReadByte(); + result.NumLongTasks = reader.ReadByte(); + result.NumShortTasks = reader.ReadByte(); + result.NumEmergencyMeetings = reader.ReadInt32(); + result.NumImpostors = reader.ReadByte(); + result.KillDistance = reader.ReadByte(); + result.DiscussionTime = reader.ReadInt32(); + result.VotingTime = reader.ReadInt32(); + result.IsDefaults = reader.ReadBoolean(); + + if (result.Version > 1) + { + result.EmergencyCooldown = reader.ReadByte(); + } + + if (result.Version > 2) + { + result.ConfirmImpostor = reader.ReadBoolean(); + result.VisualTasks = reader.ReadBoolean(); + } + + return result; + } + } + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/GameVersion.cs b/src/Impostor.Api/Innersloth/GameVersion.cs new file mode 100644 index 0000000..c11933e --- /dev/null +++ b/src/Impostor.Api/Innersloth/GameVersion.cs @@ -0,0 +1,10 @@ +namespace Impostor.Api.Innersloth +{ + public class GameVersion + { + public static int GetVersion(int year, int month, int day, int rev = 0) + { + return (year * 25000) + (month * 1800) + (day * 50) + rev; + } + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/RegionInfo.cs b/src/Impostor.Api/Innersloth/RegionInfo.cs new file mode 100644 index 0000000..c78978b --- /dev/null +++ b/src/Impostor.Api/Innersloth/RegionInfo.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.IO; + +namespace Impostor.Api.Innersloth +{ + public class RegionInfo + { + public RegionInfo(string name, string ping, IReadOnlyList servers) + { + Name = name; + Ping = ping; + Servers = servers; + } + + public string Name { get; } + public string Ping { get; } + public IReadOnlyList Servers { get; } + + public void Serialize(BinaryWriter writer) + { + writer.Write(0); + writer.Write(Name); + writer.Write(Ping); + writer.Write(Servers.Count); + + foreach (var server in Servers) + { + server.Serialize(writer); + } + } + + public static RegionInfo Deserialize(BinaryReader reader) + { + var unknown = reader.ReadInt32(); + var name = reader.ReadString(); + var ping = reader.ReadString(); + var servers = new List(); + var serverCount = reader.ReadInt32(); + + for (var i = 0; i < serverCount; i++) + { + servers.Add(ServerInfo.Deserialize(reader)); + } + + return new RegionInfo(name, ping, servers); + } + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/ServerInfo.cs b/src/Impostor.Api/Innersloth/ServerInfo.cs new file mode 100644 index 0000000..7785823 --- /dev/null +++ b/src/Impostor.Api/Innersloth/ServerInfo.cs @@ -0,0 +1,37 @@ +using System.IO; +using System.Net; + +namespace Impostor.Api.Innersloth +{ + public class ServerInfo + { + public string Name { get; } + public string Ip { get; } + public ushort Port { get; } + + public ServerInfo(string name, string ip, ushort port) + { + Name = name; + Ip = ip; + Port = port; + } + + public void Serialize(BinaryWriter writer) + { + writer.Write(Name); + writer.Write(IPAddress.Parse(Ip).GetAddressBytes()); + writer.Write(Port); + writer.Write(0); + } + + public static ServerInfo Deserialize(BinaryReader reader) + { + var name = reader.ReadString(); + var ip = new IPAddress(reader.ReadBytes(4)).ToString(); + var port = reader.ReadUInt16(); + var unknown = reader.ReadInt32(); + + return new ServerInfo(name, ip, port); + } + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Net/Extensions/GameMessageWriterExtensions.cs b/src/Impostor.Api/Net/Extensions/GameMessageWriterExtensions.cs index d995b5a..5f90bb5 100644 --- a/src/Impostor.Api/Net/Extensions/GameMessageWriterExtensions.cs +++ b/src/Impostor.Api/Net/Extensions/GameMessageWriterExtensions.cs @@ -1,8 +1,8 @@ using System; using System.Threading.Tasks; -using Impostor.Server.Net.Messages; +using Impostor.Api.Net.Messages; -namespace Impostor.Server.Net +namespace Impostor.Api.Net { public static class GameMessageWriterExtensions { diff --git a/src/Impostor.Api/Net/IClient.cs b/src/Impostor.Api/Net/IClient.cs index 0c508c4..137ace0 100644 --- a/src/Impostor.Api/Net/IClient.cs +++ b/src/Impostor.Api/Net/IClient.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Impostor.Server.Net +namespace Impostor.Api.Net { /// /// Represents a connected game client. diff --git a/src/Impostor.Api/Net/IClientPlayer.cs b/src/Impostor.Api/Net/IClientPlayer.cs index 4e4252f..bb28b84 100644 --- a/src/Impostor.Api/Net/IClientPlayer.cs +++ b/src/Impostor.Api/Net/IClientPlayer.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; -using Impostor.Server.Games; +using Impostor.Api.Games; -namespace Impostor.Server.Net +namespace Impostor.Api.Net { /// /// Represents a player in . diff --git a/src/Impostor.Api/Net/IConnection.cs b/src/Impostor.Api/Net/IConnection.cs index f619dfa..70edd01 100644 --- a/src/Impostor.Api/Net/IConnection.cs +++ b/src/Impostor.Api/Net/IConnection.cs @@ -1,8 +1,8 @@ using System.Net; -using Impostor.Server.Games; -using Impostor.Server.Net.Messages; +using Impostor.Api.Games; +using Impostor.Api.Net.Messages; -namespace Impostor.Server.Net +namespace Impostor.Api.Net { /// /// Represents the connection of the client. diff --git a/src/Impostor.Api/Net/LimboStates.cs b/src/Impostor.Api/Net/LimboStates.cs index 1812f5a..d6e66bd 100644 --- a/src/Impostor.Api/Net/LimboStates.cs +++ b/src/Impostor.Api/Net/LimboStates.cs @@ -1,6 +1,6 @@ using System; -namespace Impostor.Server.Net +namespace Impostor.Api.Net { [Flags] public enum LimboStates diff --git a/src/Impostor.Api/Net/Manager/IClientManager.cs b/src/Impostor.Api/Net/Manager/IClientManager.cs index 6405a65..92bf89f 100644 --- a/src/Impostor.Api/Net/Manager/IClientManager.cs +++ b/src/Impostor.Api/Net/Manager/IClientManager.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Impostor.Server.Net.Manager +namespace Impostor.Api.Net.Manager { public interface IClientManager { diff --git a/src/Impostor.Api/Net/Messages/IConnectionMessageWriter.cs b/src/Impostor.Api/Net/Messages/IConnectionMessageWriter.cs index 453eb7e..620046c 100644 --- a/src/Impostor.Api/Net/Messages/IConnectionMessageWriter.cs +++ b/src/Impostor.Api/Net/Messages/IConnectionMessageWriter.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Impostor.Server.Net.Messages +namespace Impostor.Api.Net.Messages { /// /// Represents the message writer for . diff --git a/src/Impostor.Api/Net/Messages/IGameMessageWriter.cs b/src/Impostor.Api/Net/Messages/IGameMessageWriter.cs index d1d769c..69c286c 100644 --- a/src/Impostor.Api/Net/Messages/IGameMessageWriter.cs +++ b/src/Impostor.Api/Net/Messages/IGameMessageWriter.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; -using Impostor.Server.Games; +using Impostor.Api.Games; -namespace Impostor.Server.Net.Messages +namespace Impostor.Api.Net.Messages { /// /// Represents the message writer for . diff --git a/src/Impostor.Api/Net/Messages/IMessage.cs b/src/Impostor.Api/Net/Messages/IMessage.cs index 854a0d2..a7eb63e 100644 --- a/src/Impostor.Api/Net/Messages/IMessage.cs +++ b/src/Impostor.Api/Net/Messages/IMessage.cs @@ -1,4 +1,4 @@ -namespace Impostor.Server.Net.Messages +namespace Impostor.Api.Net.Messages { public interface IMessage { diff --git a/src/Impostor.Api/Net/Messages/IMessageReader.cs b/src/Impostor.Api/Net/Messages/IMessageReader.cs index aeefcc6..99e2e4d 100644 --- a/src/Impostor.Api/Net/Messages/IMessageReader.cs +++ b/src/Impostor.Api/Net/Messages/IMessageReader.cs @@ -1,6 +1,6 @@ using System; -namespace Impostor.Server.Net.Messages +namespace Impostor.Api.Net.Messages { public interface IMessageReader { diff --git a/src/Impostor.Api/Net/Messages/IMessageWriter.cs b/src/Impostor.Api/Net/Messages/IMessageWriter.cs index add3154..eb009ab 100644 --- a/src/Impostor.Api/Net/Messages/IMessageWriter.cs +++ b/src/Impostor.Api/Net/Messages/IMessageWriter.cs @@ -1,8 +1,8 @@ using System; using System.Net; -using Impostor.Server.Games; +using Impostor.Api.Games; -namespace Impostor.Server.Net.Messages +namespace Impostor.Api.Net.Messages { /// /// Base message writer. diff --git a/src/Impostor.Api/Net/Messages/MessageType.cs b/src/Impostor.Api/Net/Messages/MessageType.cs index a350cb6..66335eb 100644 --- a/src/Impostor.Api/Net/Messages/MessageType.cs +++ b/src/Impostor.Api/Net/Messages/MessageType.cs @@ -1,4 +1,4 @@ -namespace Impostor.Server.Net.Messages +namespace Impostor.Api.Net.Messages { /// /// Specifies how a message should be sent between connections. diff --git a/src/Impostor.Api/Plugins/IPlugin.cs b/src/Impostor.Api/Plugins/IPlugin.cs index e5f8645..f66f112 100644 --- a/src/Impostor.Api/Plugins/IPlugin.cs +++ b/src/Impostor.Api/Plugins/IPlugin.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -using Impostor.Server.Events; +using Impostor.Api.Events; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -namespace Impostor.Server.Plugins +namespace Impostor.Api.Plugins { public interface IPlugin : IEventListener { diff --git a/src/Impostor.Api/Plugins/PluginBase.cs b/src/Impostor.Api/Plugins/PluginBase.cs index 5ef6cf3..cf64190 100644 --- a/src/Impostor.Api/Plugins/PluginBase.cs +++ b/src/Impostor.Api/Plugins/PluginBase.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -namespace Impostor.Server.Plugins +namespace Impostor.Api.Plugins { public class PluginBase : IPlugin { diff --git a/src/Impostor.Api/Unity/Mathf.cs b/src/Impostor.Api/Unity/Mathf.cs new file mode 100644 index 0000000..ed883c8 --- /dev/null +++ b/src/Impostor.Api/Unity/Mathf.cs @@ -0,0 +1,45 @@ +namespace Impostor.Api.Unity +{ + public static class Mathf + { + /// + /// Clamps the given value between the given minimum float and maximum float values. Returns the given value if it is within the min and max range. + /// + /// The floating point value to restrict inside the range defined by the min and max values. + /// The minimum floating point value to compare against. + /// The maximum floating point value to compare against. + /// + /// The float result between the min and max values. + /// + public static float Clamp(float value, float min, float max) + { + if ((double) value < (double) min) + value = min; + else if ((double) value > (double) max) + value = max; + return value; + } + + /// + /// Clamps value between 0 and 1 and returns value. + /// + /// + public static float Clamp01(float value) + { + if ((double) value < 0.0) + return 0.0f; + return (double) value > 1.0 ? 1f : value; + } + + /// + /// Linearly interpolates between a and b by t. + /// + /// The start value. + /// The end value. + /// The interpolation value between the two floats. + /// + /// The interpolated float result between the two float values. + /// + public static float Lerp(float a, float b, float t) => a + (b - a) * Mathf.Clamp01(t); + } +} \ No newline at end of file diff --git a/src/Impostor.Patcher/Impostor.Patcher.Shared/AmongUsModifier.cs b/src/Impostor.Patcher/Impostor.Patcher.Shared/AmongUsModifier.cs index 130a6a4..95f5524 100644 --- a/src/Impostor.Patcher/Impostor.Patcher.Shared/AmongUsModifier.cs +++ b/src/Impostor.Patcher/Impostor.Patcher.Shared/AmongUsModifier.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Gameloop.Vdf; using Gameloop.Vdf.Linq; using Impostor.Patcher.Shared.Events; -using Impostor.Shared.Innersloth; +using Impostor.Patcher.Shared.Innersloth; using ErrorEventArgs = Impostor.Patcher.Shared.Events.ErrorEventArgs; namespace Impostor.Patcher.Shared diff --git a/src/Impostor.Patcher/Impostor.Patcher.Shared/Impostor.Patcher.Shared.csproj b/src/Impostor.Patcher/Impostor.Patcher.Shared/Impostor.Patcher.Shared.csproj index 604bf31..e480870 100644 --- a/src/Impostor.Patcher/Impostor.Patcher.Shared/Impostor.Patcher.Shared.csproj +++ b/src/Impostor.Patcher/Impostor.Patcher.Shared/Impostor.Patcher.Shared.csproj @@ -6,7 +6,6 @@ - diff --git a/src/Impostor.Patcher/Impostor.Patcher.Shared/Innersloth/RegionInfo.cs b/src/Impostor.Patcher/Impostor.Patcher.Shared/Innersloth/RegionInfo.cs new file mode 100644 index 0000000..01b74d1 --- /dev/null +++ b/src/Impostor.Patcher/Impostor.Patcher.Shared/Innersloth/RegionInfo.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.IO; + +namespace Impostor.Patcher.Shared.Innersloth +{ + public class RegionInfo + { + public RegionInfo(string name, string ping, IReadOnlyList servers) + { + Name = name; + Ping = ping; + Servers = servers; + } + + public string Name { get; } + public string Ping { get; } + public IReadOnlyList Servers { get; } + + public void Serialize(BinaryWriter writer) + { + writer.Write(0); + writer.Write(Name); + writer.Write(Ping); + writer.Write(Servers.Count); + + foreach (var server in Servers) + { + server.Serialize(writer); + } + } + + public static RegionInfo Deserialize(BinaryReader reader) + { + var unknown = reader.ReadInt32(); + var name = reader.ReadString(); + var ping = reader.ReadString(); + var servers = new List(); + var serverCount = reader.ReadInt32(); + + for (var i = 0; i < serverCount; i++) + { + servers.Add(ServerInfo.Deserialize(reader)); + } + + return new RegionInfo(name, ping, servers); + } + } +} \ No newline at end of file diff --git a/src/Impostor.Patcher/Impostor.Patcher.Shared/Innersloth/ServerInfo.cs b/src/Impostor.Patcher/Impostor.Patcher.Shared/Innersloth/ServerInfo.cs new file mode 100644 index 0000000..7203c84 --- /dev/null +++ b/src/Impostor.Patcher/Impostor.Patcher.Shared/Innersloth/ServerInfo.cs @@ -0,0 +1,37 @@ +using System.IO; +using System.Net; + +namespace Impostor.Patcher.Shared.Innersloth +{ + public class ServerInfo + { + public string Name { get; } + public string Ip { get; } + public ushort Port { get; } + + public ServerInfo(string name, string ip, ushort port) + { + Name = name; + Ip = ip; + Port = port; + } + + public void Serialize(BinaryWriter writer) + { + writer.Write(Name); + writer.Write(IPAddress.Parse(Ip).GetAddressBytes()); + writer.Write(Port); + writer.Write(0); + } + + public static ServerInfo Deserialize(BinaryReader reader) + { + var name = reader.ReadString(); + var ip = new IPAddress(reader.ReadBytes(4)).ToString(); + var port = reader.ReadUInt16(); + var unknown = reader.ReadInt32(); + + return new ServerInfo(name, ip, port); + } + } +} \ No newline at end of file diff --git a/src/Impostor.Plugins.Debugger/DebugPlugin.cs b/src/Impostor.Plugins.Debugger/DebugPlugin.cs index 53c544a..3521a65 100644 --- a/src/Impostor.Plugins.Debugger/DebugPlugin.cs +++ b/src/Impostor.Plugins.Debugger/DebugPlugin.cs @@ -1,4 +1,4 @@ -using Impostor.Server.Plugins; +using Impostor.Api.Plugins; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Impostor.Plugins.Debugger/Pages/Index.razor b/src/Impostor.Plugins.Debugger/Pages/Index.razor index 7ca76ed..4d53b08 100644 --- a/src/Impostor.Plugins.Debugger/Pages/Index.razor +++ b/src/Impostor.Plugins.Debugger/Pages/Index.razor @@ -1,9 +1,9 @@ @page "/" -@using Impostor.Server.Events -@using Impostor.Server.Events.Managers -@using Impostor.Server.Games.Managers @implements IDisposable -@implements IEventListener +@using Impostor.Api.Events.Managers +@using Impostor.Api.Games.Managers +@using Impostor.Api.Events +@implements Impostor.Api.Events.IEventListener @inject IEventManager EventManager @inject IGameManager GameManager diff --git a/src/Impostor.Server/Events/EventHandler.cs b/src/Impostor.Server/Events/EventHandler.cs index 61ac4d8..e4582ca 100644 --- a/src/Impostor.Server/Events/EventHandler.cs +++ b/src/Impostor.Server/Events/EventHandler.cs @@ -1,4 +1,6 @@ -namespace Impostor.Server.Events +using Impostor.Api.Events; + +namespace Impostor.Server.Events { internal readonly struct EventHandler { diff --git a/src/Impostor.Server/Events/EventManager.cs b/src/Impostor.Server/Events/EventManager.cs index 69ceef5..05a3e70 100644 --- a/src/Impostor.Server/Events/EventManager.cs +++ b/src/Impostor.Server/Events/EventManager.cs @@ -4,7 +4,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; -using Impostor.Server.Events.Managers; +using Impostor.Api.Events; +using Impostor.Api.Events.Managers; using Microsoft.Extensions.DependencyInjection; namespace Impostor.Server.Events diff --git a/src/Impostor.Server/Events/RegisteredEventListener.cs b/src/Impostor.Server/Events/RegisteredEventListener.cs index d0021b3..80df9d8 100644 --- a/src/Impostor.Server/Events/RegisteredEventListener.cs +++ b/src/Impostor.Server/Events/RegisteredEventListener.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; +using Impostor.Api.Events; using Microsoft.Extensions.DependencyInjection; namespace Impostor.Server.Events diff --git a/src/Impostor.Server/Events/TemporaryEventRegister.cs b/src/Impostor.Server/Events/TemporaryEventRegister.cs index 834fe41..8bcb643 100644 --- a/src/Impostor.Server/Events/TemporaryEventRegister.cs +++ b/src/Impostor.Server/Events/TemporaryEventRegister.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Impostor.Api.Events; namespace Impostor.Server.Events { diff --git a/src/Impostor.Server/GameData/InnerNetObject.cs b/src/Impostor.Server/GameData/InnerNetObject.cs index 6f153ed..78ce960 100644 --- a/src/Impostor.Server/GameData/InnerNetObject.cs +++ b/src/Impostor.Server/GameData/InnerNetObject.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Net.Messages; +using Impostor.Api.Net.Messages; +using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData { diff --git a/src/Impostor.Server/GameData/Objects/Components/InnerCustomNetworkTransform.cs b/src/Impostor.Server/GameData/Objects/Components/InnerCustomNetworkTransform.cs index d3b5c05..c6804ed 100644 --- a/src/Impostor.Server/GameData/Objects/Components/InnerCustomNetworkTransform.cs +++ b/src/Impostor.Server/GameData/Objects/Components/InnerCustomNetworkTransform.cs @@ -1,6 +1,6 @@ using System.Numerics; -using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth; +using Impostor.Api.Innersloth; +using Impostor.Api.Net.Messages; using Microsoft.Extensions.Logging; namespace Impostor.Server.GameData.Objects.Components diff --git a/src/Impostor.Server/GameData/Objects/Components/InnerPlayerPhysics.cs b/src/Impostor.Server/GameData/Objects/Components/InnerPlayerPhysics.cs index edc01e0..df7f7aa 100644 --- a/src/Impostor.Server/GameData/Objects/Components/InnerPlayerPhysics.cs +++ b/src/Impostor.Server/GameData/Objects/Components/InnerPlayerPhysics.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Net.Messages; +using Impostor.Api.Net.Messages; +using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects.Components { diff --git a/src/Impostor.Server/GameData/Objects/Components/InnerVoteBanSystem.cs b/src/Impostor.Server/GameData/Objects/Components/InnerVoteBanSystem.cs index cd71ba7..9c3d5de 100644 --- a/src/Impostor.Server/GameData/Objects/Components/InnerVoteBanSystem.cs +++ b/src/Impostor.Server/GameData/Objects/Components/InnerVoteBanSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects.Components diff --git a/src/Impostor.Server/GameData/Objects/InnerGameData.PlayerInfo.cs b/src/Impostor.Server/GameData/Objects/InnerGameData.PlayerInfo.cs index 1283e2b..2abf5c8 100644 --- a/src/Impostor.Server/GameData/Objects/InnerGameData.PlayerInfo.cs +++ b/src/Impostor.Server/GameData/Objects/InnerGameData.PlayerInfo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects diff --git a/src/Impostor.Server/GameData/Objects/InnerGameData.TaskInfo.cs b/src/Impostor.Server/GameData/Objects/InnerGameData.TaskInfo.cs index 0f0a99c..e317bd2 100644 --- a/src/Impostor.Server/GameData/Objects/InnerGameData.TaskInfo.cs +++ b/src/Impostor.Server/GameData/Objects/InnerGameData.TaskInfo.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Net.Messages; +using Impostor.Api.Net.Messages; +using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects { diff --git a/src/Impostor.Server/GameData/Objects/InnerGameData.cs b/src/Impostor.Server/GameData/Objects/InnerGameData.cs index 87a196f..5e23d17 100644 --- a/src/Impostor.Server/GameData/Objects/InnerGameData.cs +++ b/src/Impostor.Server/GameData/Objects/InnerGameData.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; +using Impostor.Api.Games; +using Impostor.Api.Net.Messages; using Impostor.Server.GameData.Objects.Components; -using Impostor.Server.Games; using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects diff --git a/src/Impostor.Server/GameData/Objects/InnerLobbyBehaviour.cs b/src/Impostor.Server/GameData/Objects/InnerLobbyBehaviour.cs index d2533fa..bdfcdf4 100644 --- a/src/Impostor.Server/GameData/Objects/InnerLobbyBehaviour.cs +++ b/src/Impostor.Server/GameData/Objects/InnerLobbyBehaviour.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects diff --git a/src/Impostor.Server/GameData/Objects/InnerMeetingHud.cs b/src/Impostor.Server/GameData/Objects/InnerMeetingHud.cs index 12c1054..6fc30bc 100644 --- a/src/Impostor.Server/GameData/Objects/InnerMeetingHud.cs +++ b/src/Impostor.Server/GameData/Objects/InnerMeetingHud.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects diff --git a/src/Impostor.Server/GameData/Objects/InnerPlayerControl.cs b/src/Impostor.Server/GameData/Objects/InnerPlayerControl.cs index 5da19a9..821f495 100644 --- a/src/Impostor.Server/GameData/Objects/InnerPlayerControl.cs +++ b/src/Impostor.Server/GameData/Objects/InnerPlayerControl.cs @@ -1,6 +1,7 @@ using System; +using Impostor.Api.Games; +using Impostor.Api.Net.Messages; using Impostor.Server.GameData.Objects.Components; -using Impostor.Server.Games; using Impostor.Server.Net.Messages; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Impostor.Server/GameData/Objects/InnerShipStatus.cs b/src/Impostor.Server/GameData/Objects/InnerShipStatus.cs index 8662983..17f9931 100644 --- a/src/Impostor.Server/GameData/Objects/InnerShipStatus.cs +++ b/src/Impostor.Server/GameData/Objects/InnerShipStatus.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; namespace Impostor.Server.GameData.Objects diff --git a/src/Impostor.Server/Impostor.Server.csproj b/src/Impostor.Server/Impostor.Server.csproj index e045ac0..2737068 100644 --- a/src/Impostor.Server/Impostor.Server.csproj +++ b/src/Impostor.Server/Impostor.Server.csproj @@ -23,7 +23,6 @@ - diff --git a/src/Impostor.Server/Net/Client.cs b/src/Impostor.Server/Net/Client.cs index 25075d3..dec73df 100644 --- a/src/Impostor.Server/Net/Client.cs +++ b/src/Impostor.Server/Net/Client.cs @@ -1,12 +1,13 @@ using System; using System.Threading.Tasks; +using Impostor.Api.Games; +using Impostor.Api.Innersloth; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net.Messages; using Impostor.Server.Data; -using Impostor.Server.Games; using Impostor.Server.Net.Hazel; using Impostor.Server.Net.Manager; using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth; -using Impostor.Shared.Innersloth.Data; using Microsoft.Extensions.Logging; namespace Impostor.Server.Net diff --git a/src/Impostor.Server/Net/ClientBase.Api.cs b/src/Impostor.Server/Net/ClientBase.Api.cs index c227d9b..4b34987 100644 --- a/src/Impostor.Server/Net/ClientBase.Api.cs +++ b/src/Impostor.Server/Net/ClientBase.Api.cs @@ -1,4 +1,6 @@ -namespace Impostor.Server.Net +using Impostor.Api.Net; + +namespace Impostor.Server.Net { internal abstract partial class ClientBase : IClient { diff --git a/src/Impostor.Server/Net/ClientBase.cs b/src/Impostor.Server/Net/ClientBase.cs index 71baab4..ec2efcb 100644 --- a/src/Impostor.Server/Net/ClientBase.cs +++ b/src/Impostor.Server/Net/ClientBase.cs @@ -1,6 +1,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Hazel; using Impostor.Server.Net.Messages; using Impostor.Server.Net.State; diff --git a/src/Impostor.Server/Net/Hazel/HazelConnection.Api.cs b/src/Impostor.Server/Net/Hazel/HazelConnection.Api.cs index 324782d..c7056d2 100644 --- a/src/Impostor.Server/Net/Hazel/HazelConnection.Api.cs +++ b/src/Impostor.Server/Net/Hazel/HazelConnection.Api.cs @@ -1,4 +1,6 @@ -namespace Impostor.Server.Net.Hazel +using Impostor.Api.Net; + +namespace Impostor.Server.Net.Hazel { internal partial class HazelConnection : IConnection { diff --git a/src/Impostor.Server/Net/Hazel/HazelConnection.cs b/src/Impostor.Server/Net/Hazel/HazelConnection.cs index 390c3bf..e2694f8 100644 --- a/src/Impostor.Server/Net/Hazel/HazelConnection.cs +++ b/src/Impostor.Server/Net/Hazel/HazelConnection.cs @@ -2,6 +2,7 @@ using System.Net; using System.Threading.Tasks; using Hazel; +using Impostor.Api.Net.Messages; using Impostor.Server.Hazel.Messages; using Impostor.Server.Net.Hazel.Messages; using Impostor.Server.Net.Messages; diff --git a/src/Impostor.Server/Net/Hazel/Messages/BufferMessageReader.cs b/src/Impostor.Server/Net/Hazel/Messages/BufferMessageReader.cs index 3e560c7..8491835 100644 --- a/src/Impostor.Server/Net/Hazel/Messages/BufferMessageReader.cs +++ b/src/Impostor.Server/Net/Hazel/Messages/BufferMessageReader.cs @@ -2,6 +2,7 @@ using System.Buffers.Binary; using System.Runtime.CompilerServices; using System.Text; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; namespace Impostor.Server.Hazel.Messages diff --git a/src/Impostor.Server/Net/Hazel/Messages/HazelConnectionMessageWriter.cs b/src/Impostor.Server/Net/Hazel/Messages/HazelConnectionMessageWriter.cs index 1bde8f8..4c77514 100644 --- a/src/Impostor.Server/Net/Hazel/Messages/HazelConnectionMessageWriter.cs +++ b/src/Impostor.Server/Net/Hazel/Messages/HazelConnectionMessageWriter.cs @@ -1,4 +1,6 @@ using System.Threading.Tasks; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; using Impostor.Server.Net; using Impostor.Server.Net.Messages; diff --git a/src/Impostor.Server/Net/Hazel/Messages/HazelGameMessageWriter.cs b/src/Impostor.Server/Net/Hazel/Messages/HazelGameMessageWriter.cs index 2deddaf..3e4f6e2 100644 --- a/src/Impostor.Server/Net/Hazel/Messages/HazelGameMessageWriter.cs +++ b/src/Impostor.Server/Net/Hazel/Messages/HazelGameMessageWriter.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Hazel; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; using Impostor.Server.Net; using Impostor.Server.Net.Messages; using Impostor.Server.Net.State; diff --git a/src/Impostor.Server/Net/Hazel/Messages/HazelMessage.cs b/src/Impostor.Server/Net/Hazel/Messages/HazelMessage.cs index 32ad514..8799c48 100644 --- a/src/Impostor.Server/Net/Hazel/Messages/HazelMessage.cs +++ b/src/Impostor.Server/Net/Hazel/Messages/HazelMessage.cs @@ -1,5 +1,6 @@ using System; using Hazel; +using Impostor.Api.Net.Messages; using Impostor.Server.Hazel.Messages; using Impostor.Server.Net.Messages; diff --git a/src/Impostor.Server/Net/Hazel/Messages/HazelMessageWriter.cs b/src/Impostor.Server/Net/Hazel/Messages/HazelMessageWriter.cs index 0d40313..c43cdfb 100644 --- a/src/Impostor.Server/Net/Hazel/Messages/HazelMessageWriter.cs +++ b/src/Impostor.Server/Net/Hazel/Messages/HazelMessageWriter.cs @@ -1,7 +1,8 @@ using System; using System.Net; using Hazel; -using Impostor.Server.Games; +using Impostor.Api.Games; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; namespace Impostor.Server.Hazel.Messages diff --git a/src/Impostor.Server/Net/Manager/ClientManager.Api.cs b/src/Impostor.Server/Net/Manager/ClientManager.Api.cs index ba06596..6cbe5bf 100644 --- a/src/Impostor.Server/Net/Manager/ClientManager.Api.cs +++ b/src/Impostor.Server/Net/Manager/ClientManager.Api.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using Impostor.Api.Net; +using Impostor.Api.Net.Manager; namespace Impostor.Server.Net.Manager { diff --git a/src/Impostor.Server/Net/Manager/ClientManager.cs b/src/Impostor.Server/Net/Manager/ClientManager.cs index 23ee7bb..7a62fde 100644 --- a/src/Impostor.Server/Net/Manager/ClientManager.cs +++ b/src/Impostor.Server/Net/Manager/ClientManager.cs @@ -2,12 +2,14 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Impostor.Api.Innersloth; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; using Impostor.Server.Data; using Impostor.Server.Net.Factories; using Impostor.Server.Net.Hazel; using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth; -using Impostor.Shared.Innersloth.Data; using Microsoft.Extensions.Logging; namespace Impostor.Server.Net.Manager diff --git a/src/Impostor.Server/Net/Manager/GameManager.Api.cs b/src/Impostor.Server/Net/Manager/GameManager.Api.cs index 68b10cf..8ddb19b 100644 --- a/src/Impostor.Server/Net/Manager/GameManager.Api.cs +++ b/src/Impostor.Server/Net/Manager/GameManager.Api.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -using Impostor.Server.Games; -using Impostor.Server.Games.Managers; +using Impostor.Api.Games; +using Impostor.Api.Games.Managers; namespace Impostor.Server.Net.Manager { diff --git a/src/Impostor.Server/Net/Manager/GameManager.cs b/src/Impostor.Server/Net/Manager/GameManager.cs index 057c716..d05eac8 100644 --- a/src/Impostor.Server/Net/Manager/GameManager.cs +++ b/src/Impostor.Server/Net/Manager/GameManager.cs @@ -4,14 +4,15 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; +using Impostor.Api; +using Impostor.Api.Events; +using Impostor.Api.Events.Managers; +using Impostor.Api.Games; +using Impostor.Api.Innersloth; +using Impostor.Api.Innersloth.Data; using Impostor.Server.Data; -using Impostor.Server.Events; -using Impostor.Server.Events.Managers; -using Impostor.Server.Games; using Impostor.Server.Net.Redirector; using Impostor.Server.Net.State; -using Impostor.Shared.Innersloth; -using Impostor.Shared.Innersloth.Data; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Impostor.Server/Net/Messages/Message00HostGame.cs b/src/Impostor.Server/Net/Messages/Message00HostGame.cs index c1462e2..835424b 100644 --- a/src/Impostor.Server/Net/Messages/Message00HostGame.cs +++ b/src/Impostor.Server/Net/Messages/Message00HostGame.cs @@ -1,4 +1,5 @@ -using Impostor.Shared.Innersloth; +using Impostor.Api.Innersloth; +using Impostor.Api.Net.Messages; namespace Impostor.Server.Net.Messages { diff --git a/src/Impostor.Server/Net/Messages/Message01JoinGame.cs b/src/Impostor.Server/Net/Messages/Message01JoinGame.cs index 745d9f3..fb254b5 100644 --- a/src/Impostor.Server/Net/Messages/Message01JoinGame.cs +++ b/src/Impostor.Server/Net/Messages/Message01JoinGame.cs @@ -1,5 +1,6 @@ using System; -using Impostor.Shared.Innersloth.Data; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net.Messages; namespace Impostor.Server.Net.Messages { diff --git a/src/Impostor.Server/Net/Messages/Message04RemovePlayer.cs b/src/Impostor.Server/Net/Messages/Message04RemovePlayer.cs index bb06b63..e8e669e 100644 --- a/src/Impostor.Server/Net/Messages/Message04RemovePlayer.cs +++ b/src/Impostor.Server/Net/Messages/Message04RemovePlayer.cs @@ -1,4 +1,5 @@ -using Impostor.Shared.Innersloth.Data; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net.Messages; namespace Impostor.Server.Net.Messages { diff --git a/src/Impostor.Server/Net/Messages/Message07JoinedGame.cs b/src/Impostor.Server/Net/Messages/Message07JoinedGame.cs index 7fba0d7..d1957dc 100644 --- a/src/Impostor.Server/Net/Messages/Message07JoinedGame.cs +++ b/src/Impostor.Server/Net/Messages/Message07JoinedGame.cs @@ -1,4 +1,6 @@ -namespace Impostor.Server.Net.Messages +using Impostor.Api.Net.Messages; + +namespace Impostor.Server.Net.Messages { internal static class Message07JoinedGame { diff --git a/src/Impostor.Server/Net/Messages/Message10AlterGame.cs b/src/Impostor.Server/Net/Messages/Message10AlterGame.cs index ed3980a..eedf1bd 100644 --- a/src/Impostor.Server/Net/Messages/Message10AlterGame.cs +++ b/src/Impostor.Server/Net/Messages/Message10AlterGame.cs @@ -1,4 +1,5 @@ -using Impostor.Shared.Innersloth.Data; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net.Messages; namespace Impostor.Server.Net.Messages { diff --git a/src/Impostor.Server/Net/Messages/Message11KickPlayer.cs b/src/Impostor.Server/Net/Messages/Message11KickPlayer.cs index 9a9c209..4d36f20 100644 --- a/src/Impostor.Server/Net/Messages/Message11KickPlayer.cs +++ b/src/Impostor.Server/Net/Messages/Message11KickPlayer.cs @@ -1,4 +1,6 @@ -namespace Impostor.Server.Net.Messages +using Impostor.Api.Net.Messages; + +namespace Impostor.Server.Net.Messages { internal static class Message11KickPlayer { diff --git a/src/Impostor.Server/Net/Messages/Message12WaitForHost.cs b/src/Impostor.Server/Net/Messages/Message12WaitForHost.cs index 2f1cd03..67b75b9 100644 --- a/src/Impostor.Server/Net/Messages/Message12WaitForHost.cs +++ b/src/Impostor.Server/Net/Messages/Message12WaitForHost.cs @@ -1,4 +1,6 @@ -namespace Impostor.Server.Net.Messages +using Impostor.Api.Net.Messages; + +namespace Impostor.Server.Net.Messages { internal static class Message12WaitForHost { diff --git a/src/Impostor.Server/Net/Messages/Message13Redirect.cs b/src/Impostor.Server/Net/Messages/Message13Redirect.cs index 17ba12f..3b8a092 100644 --- a/src/Impostor.Server/Net/Messages/Message13Redirect.cs +++ b/src/Impostor.Server/Net/Messages/Message13Redirect.cs @@ -1,4 +1,5 @@ using System.Net; +using Impostor.Api.Net.Messages; namespace Impostor.Server.Net.Messages { diff --git a/src/Impostor.Server/Net/Messages/Message16GetGameListV2.cs b/src/Impostor.Server/Net/Messages/Message16GetGameListV2.cs index 86e7f28..da8f630 100644 --- a/src/Impostor.Server/Net/Messages/Message16GetGameListV2.cs +++ b/src/Impostor.Server/Net/Messages/Message16GetGameListV2.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; -using Impostor.Server.Games; -using Impostor.Shared.Innersloth; +using Impostor.Api.Games; +using Impostor.Api.Innersloth; +using Impostor.Api.Net.Messages; namespace Impostor.Server.Net.Messages { diff --git a/src/Impostor.Server/Net/Redirector/ClientRedirector.cs b/src/Impostor.Server/Net/Redirector/ClientRedirector.cs index c15f329..acdb9cf 100644 --- a/src/Impostor.Server/Net/Redirector/ClientRedirector.cs +++ b/src/Impostor.Server/Net/Redirector/ClientRedirector.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; +using Impostor.Api.Innersloth; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net.Messages; using Impostor.Server.Data; using Impostor.Server.Net.Hazel; using Impostor.Server.Net.Manager; using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth; -using Impostor.Shared.Innersloth.Data; using Serilog; using ILogger = Serilog.ILogger; diff --git a/src/Impostor.Server/Net/State/ClientPlayer.Api.cs b/src/Impostor.Server/Net/State/ClientPlayer.Api.cs index d1003e5..b8b48f5 100644 --- a/src/Impostor.Server/Net/State/ClientPlayer.Api.cs +++ b/src/Impostor.Server/Net/State/ClientPlayer.Api.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; +using Impostor.Api.Net; namespace Impostor.Server.Net.State { diff --git a/src/Impostor.Server/Net/State/ClientPlayer.cs b/src/Impostor.Server/Net/State/ClientPlayer.cs index 5967601..7d54f12 100644 --- a/src/Impostor.Server/Net/State/ClientPlayer.cs +++ b/src/Impostor.Server/Net/State/ClientPlayer.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Impostor.Api.Net; namespace Impostor.Server.Net.State { diff --git a/src/Impostor.Server/Net/State/Game.Api.cs b/src/Impostor.Server/Net/State/Game.Api.cs index 96ba18a..b90394f 100644 --- a/src/Impostor.Server/Net/State/Game.Api.cs +++ b/src/Impostor.Server/Net/State/Game.Api.cs @@ -1,4 +1,5 @@ -using Impostor.Server.Games; +using Impostor.Api.Games; +using Impostor.Api.Net; namespace Impostor.Server.Net.State { diff --git a/src/Impostor.Server/Net/State/Game.Data.cs b/src/Impostor.Server/Net/State/Game.Data.cs index d3577b3..aff5ce6 100644 --- a/src/Impostor.Server/Net/State/Game.Data.cs +++ b/src/Impostor.Server/Net/State/Game.Data.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Impostor.Api.Innersloth.GameData; +using Impostor.Api.Net.Messages; using Impostor.Server.GameData; using Impostor.Server.GameData.Objects; -using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth.GameData; using Microsoft.Extensions.DependencyInjection; namespace Impostor.Server.Net.State diff --git a/src/Impostor.Server/Net/State/Game.Incoming.cs b/src/Impostor.Server/Net/State/Game.Incoming.cs index fdc2e85..9a502b4 100644 --- a/src/Impostor.Server/Net/State/Game.Incoming.cs +++ b/src/Impostor.Server/Net/State/Game.Incoming.cs @@ -1,7 +1,9 @@ using System.Threading.Tasks; -using Impostor.Server.Games; +using Impostor.Api.Games; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth.Data; namespace Impostor.Server.Net.State { diff --git a/src/Impostor.Server/Net/State/Game.Outgoing.cs b/src/Impostor.Server/Net/State/Game.Outgoing.cs index 446668c..2fc4f3c 100644 --- a/src/Impostor.Server/Net/State/Game.Outgoing.cs +++ b/src/Impostor.Server/Net/State/Game.Outgoing.cs @@ -1,6 +1,8 @@ using System.Linq; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth.Data; namespace Impostor.Server.Net.State { diff --git a/src/Impostor.Server/Net/State/Game.State.cs b/src/Impostor.Server/Net/State/Game.State.cs index 710e62f..ab9dfbb 100644 --- a/src/Impostor.Server/Net/State/Game.State.cs +++ b/src/Impostor.Server/Net/State/Game.State.cs @@ -1,8 +1,10 @@ using System.Linq; using System.Threading.Tasks; -using Impostor.Server.Events; -using Impostor.Server.Net.Messages; -using Impostor.Shared.Innersloth.Data; +using Impostor.Api; +using Impostor.Api.Events; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; namespace Impostor.Server.Net.State { diff --git a/src/Impostor.Server/Net/State/Game.cs b/src/Impostor.Server/Net/State/Game.cs index 8e3549c..4654c34 100644 --- a/src/Impostor.Server/Net/State/Game.cs +++ b/src/Impostor.Server/Net/State/Game.cs @@ -4,15 +4,17 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; -using Impostor.Server.Events.Managers; -using Impostor.Server.Games; +using Impostor.Api.Events.Managers; +using Impostor.Api.Games; +using Impostor.Api.Innersloth; +using Impostor.Api.Innersloth.Data; +using Impostor.Api.Net; +using Impostor.Api.Net.Messages; using Impostor.Server.Hazel; using Impostor.Server.Hazel.Messages; using Impostor.Server.Net.Manager; using Impostor.Server.Net.Messages; using Impostor.Server.Net.Redirector; -using Impostor.Shared.Innersloth; -using Impostor.Shared.Innersloth.Data; using Serilog; using ILogger = Serilog.ILogger; diff --git a/src/Impostor.Server/Plugins/PluginLoader.cs b/src/Impostor.Server/Plugins/PluginLoader.cs index 4fc0997..8a1bcfc 100644 --- a/src/Impostor.Server/Plugins/PluginLoader.cs +++ b/src/Impostor.Server/Plugins/PluginLoader.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Loader; +using Impostor.Api.Plugins; using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.Extensions.Hosting; diff --git a/src/Impostor.Server/Program.cs b/src/Impostor.Server/Program.cs index 16d4c30..12c9588 100644 --- a/src/Impostor.Server/Program.cs +++ b/src/Impostor.Server/Program.cs @@ -1,8 +1,9 @@ using System; +using Impostor.Api.Events.Managers; +using Impostor.Api.Games.Managers; +using Impostor.Api.Net.Manager; using Impostor.Server.Data; using Impostor.Server.Events; -using Impostor.Server.Events.Managers; -using Impostor.Server.Games.Managers; using Impostor.Server.Hazel; using Impostor.Server.Net; using Impostor.Server.Net.Factories; diff --git a/src/Impostor.Shared/Impostor.Shared.csproj b/src/Impostor.Shared/Impostor.Shared.csproj deleted file mode 100644 index b63fd9f..0000000 --- a/src/Impostor.Shared/Impostor.Shared.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - netstandard2.0;netstandard2.1 - None - - - - - - - diff --git a/src/Impostor.Shared/Innersloth/Data/AlterGameTags.cs b/src/Impostor.Shared/Innersloth/Data/AlterGameTags.cs deleted file mode 100644 index c246183..0000000 --- a/src/Impostor.Shared/Innersloth/Data/AlterGameTags.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Impostor.Shared.Innersloth.Data -{ - public enum AlterGameTags : byte - { - ChangePrivacy = 1 - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs b/src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs deleted file mode 100644 index e2705b4..0000000 --- a/src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace Impostor.Shared.Innersloth.Data -{ - public enum DisconnectReason - { - ExitGame = 0, - // The game you tried to join is full. - // Check with the host to see if you can join next round. - GameFull = 1, - // The game you tried to join already started. - // Check with the host to see if you can join next round. - GameStarted = 2, - // Could not find the game you're looking for. - GameMissing = 3, - IncorrectGame = 18, - // For these a message can be given, specifying an empty message shows - // "An unknown error disconnected you from the server." - CustomMessage1 = 4, - Custom = 8, - // CustomMessage3 = 11, - // CustomMessage4 = 12, - // CustomMessage5 = 13, - // CustomMessage6 = 14, - // CustomMessage7 = 15, - // You are running an older version of the game. - // Please update to play with others. - IncorrectVersion = 5, - // You cannot rejoin that room. - // You were banned - Banned = 6, - // You can rejoin if the room hasn't started - // You were kicked - Kicked = 7, - // You were banned for hacking. - // Please stop. - Hacking = 10, - Destroy = 16, - // You disconnected from the host. - // If this happens often, check your WiFi strength. - // - // You disconnected from the server. - // If this happens often, check your network strength. - // This may also be a server issue. - Error = 17, - // The server stopped this game. Possibly due to inactivity. - ServerRequest = 19, - // The Among Us servers are overloaded. - // Sorry! Please try again later! - ServerFull = 20, - FocusLostBackground = 207, - IntentionalLeaving = 208, - FocusLost = 209, - NewConnection = 210 - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/Data/GameKeywords.cs b/src/Impostor.Shared/Innersloth/Data/GameKeywords.cs deleted file mode 100644 index daefefe..0000000 --- a/src/Impostor.Shared/Innersloth/Data/GameKeywords.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Impostor.Shared.Innersloth.Data -{ - [Flags] - public enum GameKeywords : uint - { - All = 0, - Other = 1, - Spanish = 2, - Korean = 4, - Russian = 8, - Portuguese = 16, - Arabic = 32, - Filipone = 64, - Polish = 128, - English = 256 - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/Data/GameStates.cs b/src/Impostor.Shared/Innersloth/Data/GameStates.cs deleted file mode 100644 index 7f165e9..0000000 --- a/src/Impostor.Shared/Innersloth/Data/GameStates.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Impostor.Shared.Innersloth.Data -{ - public enum GameStates : byte - { - NotStarted = 0, - Started = 1, - Ended = 2, - Destroyed = 3 - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/Data/MapFlags.cs b/src/Impostor.Shared/Innersloth/Data/MapFlags.cs deleted file mode 100644 index 49d730c..0000000 --- a/src/Impostor.Shared/Innersloth/Data/MapFlags.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Impostor.Shared.Innersloth.Data -{ - [Flags] - public enum MapFlags - { - Skeld = 1, - MiraHQ = 2, - Polus = 4 - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/FloatRange.cs b/src/Impostor.Shared/Innersloth/FloatRange.cs deleted file mode 100644 index fc68e2d..0000000 --- a/src/Impostor.Shared/Innersloth/FloatRange.cs +++ /dev/null @@ -1,22 +0,0 @@ -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 Width => _max - _min; - - public float Lerp(float v) => Mathf.Lerp(_min, _max, v); - - public float ReverseLerp(float t) => Mathf.Clamp((t - _min) / Width, 0.0f, 1f); - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/GameCodeParser.cs b/src/Impostor.Shared/Innersloth/GameCodeParser.cs deleted file mode 100644 index 86af88e..0000000 --- a/src/Impostor.Shared/Innersloth/GameCodeParser.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; -using System.Buffers.Binary; -using System.Linq; -using System.Security.Cryptography; -using System.Text; - -namespace Impostor.Shared.Innersloth -{ - public static class GameCodeParser - { - private const string V2 = "QWXRTYLPESDFGHUJKZOCVBINMA"; - private static readonly int[] V2Map = { - 25, - 21, - 19, - 10, - 8, - 11, - 12, - 13, - 22, - 15, - 16, - 6, - 24, - 23, - 18, - 7, - 0, - 3, - 9, - 4, - 14, - 20, - 1, - 2, - 5, - 17 - }; - private static readonly RNGCryptoServiceProvider Random = new RNGCryptoServiceProvider(); - - public static string IntToGameName(int input) - { - // V2. - if (input < -1) - { - return IntToGameNameV2(input); - } - - // V1. - Span code = stackalloc byte[4]; - BinaryPrimitives.WriteInt32LittleEndian(code, input); -#if NETSTANDARD2_0 - return Encoding.UTF8.GetString(code.Slice(0, 4).ToArray()); -#else - return Encoding.UTF8.GetString(code.Slice(0, 4)); -#endif - } - - private static string IntToGameNameV2(int input) - { - var a = input & 0x3FF; - var b = (input >> 10) & 0xFFFFF; - - return new string(new [] - { - V2[a % 26], - V2[a / 26], - V2[b % 26], - V2[b / 26 % 26], - V2[b / (26 * 26) % 26], - V2[b / (26 * 26 * 26) % 26] - }); - } - - public static int GameNameToInt(string code) - { - var upper = code.ToUpperInvariant(); - if (upper.Any(x => !char.IsLetter(x))) - { - return -1; - } - - var len = code.Length; - if (len == 6) - { - return GameNameToIntV2(upper); - } - - if (len == 4) - { - return code[0] | ((code[1] | ((code[2] | (code[3] << 8)) << 8)) << 8); - } - - return -1; - } - - private static int GameNameToIntV2(string code) - { - var a = V2Map[code[0] - 65]; - var b = V2Map[code[1] - 65]; - var c = V2Map[code[2] - 65]; - var d = V2Map[code[3] - 65]; - var e = V2Map[code[4] - 65]; - var f = V2Map[code[5] - 65]; - - var one = (a + 26 * b) & 0x3FF; - var two = (c + 26 * (d + 26 * (e + 26 * f))); - - return (int) (one | ((two << 10) & 0x3FFFFC00) | 0x80000000); - } - - public static int GenerateCode(int len) - { - if (len != 4 && len != 6) - { - throw new ArgumentException("should be 4 or 6", nameof(len)); - } - - // Generate random bytes. -#if NETSTANDARD2_0 - var data = new byte[len]; -#else - Span data = stackalloc byte[len]; -#endif - Random.GetBytes(data); - - // Convert to their char representation. - Span dataChar = stackalloc char[len]; - for (var i = 0; i < len; i++) - { - dataChar[i] = V2[V2Map[data[i] % 26]]; - } - -#if NETSTANDARD2_0 - return GameNameToInt(new string(dataChar.ToArray())); -#else - return GameNameToInt(new string(dataChar)); -#endif - } - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/GameData/GameDataTag.cs b/src/Impostor.Shared/Innersloth/GameData/GameDataTag.cs deleted file mode 100644 index 757ab5e..0000000 --- a/src/Impostor.Shared/Innersloth/GameData/GameDataTag.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Impostor.Shared.Innersloth.GameData -{ - public static class GameDataTag - { - public const byte DataFlag = 1; - public const byte RpcFlag = 2; - public const byte SpawnFlag = 4; - public const byte DespawnFlag = 5; - public const byte SceneChangeFlag = 6; - public const byte ReadyFlag = 7; - public const byte ChangeSettingsFlag = 8; - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/GameOptionsData.cs b/src/Impostor.Shared/Innersloth/GameOptionsData.cs deleted file mode 100644 index 375b6ee..0000000 --- a/src/Impostor.Shared/Innersloth/GameOptionsData.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.IO; -using Impostor.Shared.Innersloth.Data; - -namespace Impostor.Shared.Innersloth -{ - public class GameOptionsData - { - public byte Version { get; set; } - public byte MaxPlayers { get; set; } - public GameKeywords Keywords { get; set; } - public byte MapId { get; set; } - public float PlayerSpeedMod { get; set; } - public float CrewLightMod { get; set; } - public float ImpostorLightMod { get; set; } - public float KillCooldown { get; set; } - public int NumCommonTasks { get; set; } - public int NumLongTasks { get; set; } - public int NumShortTasks { get; set; } - public int NumEmergencyMeetings { get; set; } - public int EmergencyCooldown { get; set; } - public int NumImpostors { get; set; } - public bool GhostsDoTasks { get; set; } - public int KillDistance { get; set; } - public int DiscussionTime { get; set; } - public int VotingTime { get; set; } - public bool ConfirmImpostor { get; set; } - public bool VisualTasks { get; set; } - public bool IsDefaults { get; set; } - - public void Serialize(BinaryWriter writer, byte version) - { - writer.Write((byte) version); - writer.Write((byte) MaxPlayers); - writer.Write((uint) Keywords); - writer.Write((byte) MapId); - writer.Write((float) PlayerSpeedMod); - writer.Write((float) CrewLightMod); - writer.Write((float) ImpostorLightMod); - writer.Write((float) KillCooldown); - writer.Write((byte) NumCommonTasks); - writer.Write((byte) NumLongTasks); - writer.Write((byte) NumShortTasks); - writer.Write((int) NumEmergencyMeetings); - writer.Write((byte) NumImpostors); - writer.Write((byte) KillDistance); - writer.Write((uint) DiscussionTime); - writer.Write((uint) VotingTime); - writer.Write((bool) IsDefaults); - if (version > 1) - { - writer.Write((byte) EmergencyCooldown); - } - - if (version > 2) - { - writer.Write((bool) ConfirmImpostor); - writer.Write((bool) VisualTasks); - } - } - - public static GameOptionsData Deserialize(ReadOnlyMemory bytes) - { - // TODO: Remove memory allocation. - - using (var stream = new MemoryStream(bytes.ToArray())) - using (var reader = new BinaryReader(stream)) - { - var result = new GameOptionsData(); - - result.Version = reader.ReadByte(); - result.MaxPlayers = reader.ReadByte(); - result.Keywords = (GameKeywords) reader.ReadUInt32(); - result.MapId = reader.ReadByte(); - result.PlayerSpeedMod = reader.ReadSingle(); - result.CrewLightMod = reader.ReadSingle(); - result.ImpostorLightMod = reader.ReadSingle(); - result.KillCooldown = reader.ReadSingle(); - result.NumCommonTasks = reader.ReadByte(); - result.NumLongTasks = reader.ReadByte(); - result.NumShortTasks = reader.ReadByte(); - result.NumEmergencyMeetings = reader.ReadInt32(); - result.NumImpostors = reader.ReadByte(); - result.KillDistance = reader.ReadByte(); - result.DiscussionTime = reader.ReadInt32(); - result.VotingTime = reader.ReadInt32(); - result.IsDefaults = reader.ReadBoolean(); - - if (result.Version > 1) - { - result.EmergencyCooldown = reader.ReadByte(); - } - - if (result.Version > 2) - { - result.ConfirmImpostor = reader.ReadBoolean(); - result.VisualTasks = reader.ReadBoolean(); - } - - return result; - } - } - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/GameVersion.cs b/src/Impostor.Shared/Innersloth/GameVersion.cs deleted file mode 100644 index 7377b79..0000000 --- a/src/Impostor.Shared/Innersloth/GameVersion.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Impostor.Shared.Innersloth -{ - public class GameVersion - { - public static int GetVersion(int year, int month, int day, int rev = 0) - { - return (year * 25000) + (month * 1800) + (day * 50) + rev; - } - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/RegionInfo.cs b/src/Impostor.Shared/Innersloth/RegionInfo.cs deleted file mode 100644 index 90c6da1..0000000 --- a/src/Impostor.Shared/Innersloth/RegionInfo.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections.Generic; -using System.IO; - -namespace Impostor.Shared.Innersloth -{ - public class RegionInfo - { - public RegionInfo(string name, string ping, IReadOnlyList servers) - { - Name = name; - Ping = ping; - Servers = servers; - } - - public string Name { get; } - public string Ping { get; } - public IReadOnlyList Servers { get; } - - public void Serialize(BinaryWriter writer) - { - writer.Write(0); - writer.Write(Name); - writer.Write(Ping); - writer.Write(Servers.Count); - - foreach (var server in Servers) - { - server.Serialize(writer); - } - } - - public static RegionInfo Deserialize(BinaryReader reader) - { - var unknown = reader.ReadInt32(); - var name = reader.ReadString(); - var ping = reader.ReadString(); - var servers = new List(); - var serverCount = reader.ReadInt32(); - - for (var i = 0; i < serverCount; i++) - { - servers.Add(ServerInfo.Deserialize(reader)); - } - - return new RegionInfo(name, ping, servers); - } - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Innersloth/ServerInfo.cs b/src/Impostor.Shared/Innersloth/ServerInfo.cs deleted file mode 100644 index c76a7e4..0000000 --- a/src/Impostor.Shared/Innersloth/ServerInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.IO; -using System.Net; - -namespace Impostor.Shared.Innersloth -{ - public class ServerInfo - { - public string Name { get; } - public string Ip { get; } - public ushort Port { get; } - - public ServerInfo(string name, string ip, ushort port) - { - Name = name; - Ip = ip; - Port = port; - } - - public void Serialize(BinaryWriter writer) - { - writer.Write(Name); - writer.Write(IPAddress.Parse(Ip).GetAddressBytes()); - writer.Write(Port); - writer.Write(0); - } - - public static ServerInfo Deserialize(BinaryReader reader) - { - var name = reader.ReadString(); - var ip = new IPAddress(reader.ReadBytes(4)).ToString(); - var port = reader.ReadUInt16(); - var unknown = reader.ReadInt32(); - - return new ServerInfo(name, ip, port); - } - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Unity/Mathf.cs b/src/Impostor.Shared/Unity/Mathf.cs deleted file mode 100644 index e608bbb..0000000 --- a/src/Impostor.Shared/Unity/Mathf.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace Impostor.Shared.Unity -{ - public static class Mathf - { - /// - /// Clamps the given value between the given minimum float and maximum float values. Returns the given value if it is within the min and max range. - /// - /// The floating point value to restrict inside the range defined by the min and max values. - /// The minimum floating point value to compare against. - /// The maximum floating point value to compare against. - /// - /// The float result between the min and max values. - /// - public static float Clamp(float value, float min, float max) - { - if ((double) value < (double) min) - value = min; - else if ((double) value > (double) max) - value = max; - return value; - } - - /// - /// Clamps value between 0 and 1 and returns value. - /// - /// - public static float Clamp01(float value) - { - if ((double) value < 0.0) - return 0.0f; - return (double) value > 1.0 ? 1f : value; - } - - /// - /// Linearly interpolates between a and b by t. - /// - /// The start value. - /// The end value. - /// The interpolation value between the two floats. - /// - /// The interpolated float result between the two float values. - /// - public static float Lerp(float a, float b, float t) => a + (b - a) * Mathf.Clamp01(t); - } -} \ No newline at end of file diff --git a/src/Impostor.Shared/Utils/HexUtils.cs b/src/Impostor.Shared/Utils/HexUtils.cs deleted file mode 100644 index 04e497b..0000000 --- a/src/Impostor.Shared/Utils/HexUtils.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Text; - -namespace Impostor.Shared.Utils -{ - public static class HexUtils - { - public static string HexDump(byte[] bytes, int bytesPerLine = 16) - { - if (bytes == null) return ""; - int bytesLength = bytes.Length; - - char[] HexChars = "0123456789ABCDEF".ToCharArray(); - - int firstHexColumn = - 8 // 8 characters for the address - + 3; // 3 spaces - - int firstCharColumn = firstHexColumn - + bytesPerLine * 3 // - 2 digit for the hexadecimal value and 1 space - + (bytesPerLine - 1) / 8 // - 1 extra space every 8 characters from the 9th - + 2; // 2 spaces - - int lineLength = firstCharColumn - + bytesPerLine // - characters to show the ascii value - + Environment.NewLine.Length; // Carriage return and line feed (should normally be 2) - - char[] line = (new String(' ', lineLength - Environment.NewLine.Length) + Environment.NewLine).ToCharArray(); - int expectedLines = (bytesLength + bytesPerLine - 1) / bytesPerLine; - StringBuilder result = new StringBuilder(expectedLines * lineLength); - - for (int i = 0; i < bytesLength; i += bytesPerLine) - { - line[0] = HexChars[(i >> 28) & 0xF]; - line[1] = HexChars[(i >> 24) & 0xF]; - line[2] = HexChars[(i >> 20) & 0xF]; - line[3] = HexChars[(i >> 16) & 0xF]; - line[4] = HexChars[(i >> 12) & 0xF]; - line[5] = HexChars[(i >> 8) & 0xF]; - line[6] = HexChars[(i >> 4) & 0xF]; - line[7] = HexChars[(i >> 0) & 0xF]; - - int hexColumn = firstHexColumn; - int charColumn = firstCharColumn; - - for (int j = 0; j < bytesPerLine; j++) - { - if (j > 0 && (j & 7) == 0) hexColumn++; - if (i + j >= bytesLength) - { - line[hexColumn] = ' '; - line[hexColumn + 1] = ' '; - line[charColumn] = ' '; - } - else - { - byte b = bytes[i + j]; - line[hexColumn] = HexChars[(b >> 4) & 0xF]; - line[hexColumn + 1] = HexChars[b & 0xF]; - line[charColumn] = (b < 32 ? '·' : (char)b); - } - hexColumn += 3; - charColumn++; - } - result.Append(line); - } - return result.ToString(); - } - } -} \ No newline at end of file diff --git a/src/Impostor.Tests/GameCodeTests.cs b/src/Impostor.Tests/GameCodeTests.cs index 90ac515..93321e2 100644 --- a/src/Impostor.Tests/GameCodeTests.cs +++ b/src/Impostor.Tests/GameCodeTests.cs @@ -1,4 +1,4 @@ -using Impostor.Shared.Innersloth; +using Impostor.Api.Innersloth; using Xunit; namespace Impostor.Tests diff --git a/src/Impostor.Tests/Hazel/BufferMessageReaderTests.cs b/src/Impostor.Tests/Hazel/BufferMessageReaderTests.cs index 84cece6..840fde3 100644 --- a/src/Impostor.Tests/Hazel/BufferMessageReaderTests.cs +++ b/src/Impostor.Tests/Hazel/BufferMessageReaderTests.cs @@ -1,4 +1,5 @@ using Hazel; +using Impostor.Api.Net.Messages; using Impostor.Server.Net.Hazel.Messages; using Impostor.Server.Net.Messages; using Xunit; diff --git a/src/Impostor.sln b/src/Impostor.sln index dba3d7f..e621271 100644 --- a/src/Impostor.sln +++ b/src/Impostor.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30503.244 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Impostor.Shared", "Impostor.Shared\Impostor.Shared.csproj", "{1D109A96-FADF-41B9-A845-457A7A5C0C5A}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Impostor.Tests", "Impostor.Tests\Impostor.Tests.csproj", "{C1385C67-A7DD-46D2-80F6-FA428B85FB22}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{56DD9707-D811-4056-9E2C-8A9CC2479B07}" @@ -45,14 +43,6 @@ Global {1B0390AF-A4F3-4FE4-B093-708B0135C0B3}.Release|Any CPU.Build.0 = Release|Any CPU {1B0390AF-A4F3-4FE4-B093-708B0135C0B3}.Release|x86.ActiveCfg = Release|Any CPU {1B0390AF-A4F3-4FE4-B093-708B0135C0B3}.Release|x86.Build.0 = Release|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Debug|x86.ActiveCfg = Debug|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Debug|x86.Build.0 = Debug|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Release|Any CPU.Build.0 = Release|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Release|x86.ActiveCfg = Release|Any CPU - {1D109A96-FADF-41B9-A845-457A7A5C0C5A}.Release|x86.Build.0 = Release|Any CPU {C1385C67-A7DD-46D2-80F6-FA428B85FB22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C1385C67-A7DD-46D2-80F6-FA428B85FB22}.Debug|Any CPU.Build.0 = Debug|Any CPU {C1385C67-A7DD-46D2-80F6-FA428B85FB22}.Debug|x86.ActiveCfg = Debug|Any CPU