Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -1,34 +0,0 @@
#nullable enable
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.Utility
{
public static class GridTileLookupHelpers
{
/// <summary>
/// Helper that returns all entities in a turf very fast.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IEntity> GetEntitiesInTileFast(this TileRef turf, GridTileLookupSystem? gridTileLookup = null)
{
gridTileLookup ??= EntitySystem.Get<GridTileLookupSystem>();
return gridTileLookup.GetEntitiesIntersecting(turf.GridIndex, turf.GridIndices);
}
/// <summary>
/// Helper that returns all entities in a turf.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IEntity> GetEntitiesInTileFast(this Vector2i indices, GridId gridId, GridTileLookupSystem? gridTileLookup = null)
{
gridTileLookup ??= EntitySystem.Get<GridTileLookupSystem>();
return gridTileLookup.GetEntitiesIntersecting(gridId, indices);
}
}
}

View File

@@ -1,79 +0,0 @@
using System;
using System.Collections;
using System.Linq;
using System.Net;
using System.Net.Sockets;
namespace Content.Server.Utility
{
public static class IPAddressExt
{
// Taken from https://stackoverflow.com/a/56461160/4678631
public static bool IsInSubnet(this IPAddress address, string subnetMask)
{
var slashIdx = subnetMask.IndexOf("/", StringComparison.Ordinal);
if (slashIdx == -1)
{
// We only handle netmasks in format "IP/PrefixLength".
throw new NotSupportedException("Only SubNetMasks with a given prefix length are supported.");
}
// First parse the address of the netmask before the prefix length.
var maskAddress = IPAddress.Parse(subnetMask.Substring(0, slashIdx));
if (maskAddress.AddressFamily != address.AddressFamily)
{
// We got something like an IPV4-Address for an IPv6-Mask. This is not valid.
return false;
}
// Now find out how long the prefix is.
int maskLength = int.Parse(subnetMask.Substring(slashIdx + 1));
if (maskAddress.AddressFamily == AddressFamily.InterNetwork)
{
// Convert the mask address to an unsigned integer.
var maskAddressBits = BitConverter.ToUInt32(maskAddress.GetAddressBytes().Reverse().ToArray(), 0);
// And convert the IpAddress to an unsigned integer.
var ipAddressBits = BitConverter.ToUInt32(address.GetAddressBytes().Reverse().ToArray(), 0);
// Get the mask/network address as unsigned integer.
uint mask = uint.MaxValue << (32 - maskLength);
// https://stackoverflow.com/a/1499284/3085985
// Bitwise AND mask and MaskAddress, this should be the same as mask and IpAddress
// as the end of the mask is 0000 which leads to both addresses to end with 0000
// and to start with the prefix.
return (maskAddressBits & mask) == (ipAddressBits & mask);
}
if (maskAddress.AddressFamily == AddressFamily.InterNetworkV6)
{
// Convert the mask address to a BitArray.
var maskAddressBits = new BitArray(maskAddress.GetAddressBytes());
// And convert the IpAddress to a BitArray.
var ipAddressBits = new BitArray(address.GetAddressBytes());
if (maskAddressBits.Length != ipAddressBits.Length)
{
throw new ArgumentException("Length of IP Address and Subnet Mask do not match.");
}
// Compare the prefix bits.
for (int maskIndex = 0; maskIndex < maskLength; maskIndex++)
{
if (ipAddressBits[maskIndex] != maskAddressBits[maskIndex])
{
return false;
}
}
return true;
}
throw new NotSupportedException("Only InterNetworkV6 or InterNetwork address families are supported.");
}
}
}

View File

@@ -1,47 +0,0 @@
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
namespace Content.Server.Utility
{
public static class InventoryHelpers
{
public static bool SpawnItemInSlot(this InventoryComponent inventory, Slots slot, string prototype, bool mobCheck = false)
{
var entityManager = inventory.Owner.EntityManager;
var protoManager = IoCManager.Resolve<IPrototypeManager>();
var user = inventory.Owner;
// Let's do nothing if the owner of the inventory has been deleted.
if (user.Deleted)
return false;
// If we don't have that slot or there's already an item there, we do nothing.
if (!inventory.HasSlot(slot) || inventory.TryGetSlotItem(slot, out ItemComponent _))
return false;
// If the prototype in question doesn't exist, we do nothing.
if (!protoManager.HasIndex<EntityPrototype>(prototype))
return false;
// Let's spawn this first...
var item = entityManager.SpawnEntity(prototype, user.Transform.MapPosition);
// Helper method that deletes the item and returns false.
bool DeleteItem()
{
item.Delete();
return false;
}
// If this doesn't have an item component, then we can't do anything with it.
if (!item.TryGetComponent(out ItemComponent? itemComp))
return DeleteItem();
// We finally try to equip the item, otherwise we delete it.
return inventory.Equip(slot, itemComp, mobCheck) || DeleteItem();
}
}
}

View File

@@ -1,61 +0,0 @@
using Content.Shared.Interfaces;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Utility
{
public static class NotifyExtensions
{
/// <summary>
/// Pops up a message for every player around <see cref="source"/> to see,
/// except for <see cref="source"/> itself.
/// </summary>
/// <param name="source">The entity on which to popup the message.</param>
/// <param name="message">The message to show.</param>
/// <param name="playerManager">
/// The instance of player manager to use, will be resolved automatically
/// if null.
/// </param>
/// <param name="range">
/// The range in which to search for players, defaulting to one screen.
/// </param>
public static void PopupMessageOtherClients(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
{
playerManager ??= IoCManager.Resolve<IPlayerManager>();
var viewers = playerManager.GetPlayersInRange(source.Transform.Coordinates, range);
foreach (var viewer in viewers)
{
var viewerEntity = viewer.AttachedEntity;
if (viewerEntity == null || source == viewerEntity || viewer.AttachedEntity == null)
{
continue;
}
source.PopupMessage(viewer.AttachedEntity, message);
}
}
/// <summary>
/// Pops up a message at the given entity's location for everyone,
/// including itself, to see.
/// </summary>
/// <param name="source">The entity above which to show the message.</param>
/// <param name="message">The message to be seen.</param>
/// <param name="playerManager">
/// The instance of player manager to use, will be resolved automatically
/// if null.
/// </param>
/// <param name="range">
/// The range in which to search for players, defaulting to one screen.
/// </param>
public static void PopupMessageEveryone(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
{
source.PopupMessage(message);
source.PopupMessageOtherClients(message, playerManager, range);
}
}
}

View File

@@ -1,15 +0,0 @@
using Content.Shared.Interfaces;
namespace Content.Server.Utility
{
/// <summary>
/// Server implementation of IModuleManager.
/// Provides simple way for shared code to check if it's being run by
/// the client of the server.
/// </summary>
public class ServerModuleManager : IModuleManager
{
bool IModuleManager.IsClientModule => false;
bool IModuleManager.IsServerModule => true;
}
}

View File

@@ -1,50 +0,0 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.Server.Utility
{
public static class SnapgridHelper
{
public static void SnapToGrid(this IEntity entity, IEntityManager? entityManager = null, IMapManager? mapManager = null)
{
entity.Transform.Coordinates = entity.Transform.Coordinates.SnapToGrid(entityManager, mapManager);
}
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IEntityManager? entityManager = null, IMapManager? mapManager = null)
{
entityManager ??= IoCManager.Resolve<IEntityManager>();
mapManager ??= IoCManager.Resolve<IMapManager>();
var gridId = coordinates.GetGridId(entityManager);
var tileSize = 1f;
if (gridId.IsValid())
{
var grid = mapManager.GetGrid(gridId);
tileSize = grid.TileSize;
}
var localPos = coordinates.Position;
var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / 2f;
var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / 2f;
return new EntityCoordinates(coordinates.EntityId, x, y);
}
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IMapGrid grid)
{
var tileSize = grid.TileSize;
var localPos = coordinates.Position;
var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / 2f;
var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / 2f;
return new EntityCoordinates(coordinates.EntityId, x, y);
}
}
}

View File

@@ -1,14 +0,0 @@
#nullable enable
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.Utility
{
public static class UserInterfaceHelpers
{
public static BoundUserInterface? GetUIOrNull(this IEntity entity, object uiKey)
{
return entity.GetComponentOrNull<ServerUserInterfaceComponent>()?.GetBoundUserInterfaceOrNull(uiKey);
}
}
}