Skip to content
This repository has been archived by the owner on Sep 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #13 from SynapseSL/development
Browse files Browse the repository at this point in the history
Version 1.1.1
  • Loading branch information
moelrobi authored Aug 3, 2020
2 parents 26b3db3 + 483c218 commit 3f1ba8b
Show file tree
Hide file tree
Showing 48 changed files with 353 additions and 130 deletions.
11 changes: 11 additions & 0 deletions Synapse/Api/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using CommandSystem;
using Harmony;
using Mirror;
using Synapse.Api.Enums;
using Synapse.Api.Plugin;
Expand Down Expand Up @@ -53,6 +55,15 @@ public static void RaMessage(this CommandSender sender, string message, bool suc
sender.RaReply($"{Assembly.GetCallingAssembly().GetName().Name}#" + message, success, true, category);
}

public static CommandSender CommandSender(this ICommandSender sender) => sender as CommandSender;

public static Player GetPlayer(this ICommandSender sender)
{
return sender.CommandSender().SenderId == "SERVER CONSOLE" || sender.CommandSender().SenderId == "GAME CONSOLE"
? Player.Host
: Player.GetPlayer(sender.CommandSender().SenderId);
}

/// <summary>
/// Gives all players on the server with this Role
/// </summary>
Expand Down
36 changes: 33 additions & 3 deletions Synapse/Api/Map.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Synapse.Config;
using Mirror;
using Synapse.Config;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -36,6 +37,22 @@ public static List<Room> Rooms
}
}

public static string IntercomText
{
get => Server.Host.GetComponent<Intercom>().CustomContent;
set
{
var component = Server.Host.GetComponent<Intercom>();
if (string.IsNullOrEmpty(value))
{
component.CustomContent = null;
return;
}

component.CustomContent = value;
}
}

/// <summary>
/// How many generators are activated?
/// </summary>
Expand Down Expand Up @@ -100,7 +117,7 @@ public static Vector3 GetDoorPos(string doorName)
vector.x -= 1f;
}

if (FallDamage.CheckUnsafePosition(vector)) break;
if (FallDamage.CheckUnsafePosition(vector, false)) break;
if (b == 20) vector = Vector3.zero;
}

Expand Down Expand Up @@ -158,6 +175,19 @@ public static Vector3 GetRandomSpawnPoint(this RoleType type)
public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0)
=> Player.Host.Inventory.SetPickup(itemType, durability, position, rotation, sight, barrel, other);

public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0)
{
var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position,Quaternion.identity, 0, 0, 0);

GameObject gameObject = p.gameObject;
gameObject.transform.localScale = scale;

NetworkServer.UnSpawn(gameObject);
NetworkServer.Spawn(p.gameObject);

return p;
}

/// <summary>
/// Has the group the permission?
/// </summary>
Expand Down Expand Up @@ -192,6 +222,6 @@ public static bool IsGroupAllowed(string group, string permission)
/// </summary>
/// <param name="duration"></param>
/// <param name="onlyHeavy"></param>
public static void TurnOffAllLights(float duration, bool onlyHeavy = false) => Generator079.Generators[0].RpcCustomOverchargeForOurBeautifulModCreators(duration, onlyHeavy);
public static void TurnOffAllLights(float duration, bool onlyHeavy = false) => Generator079.Generators[0].ServerOvercharge(duration, onlyHeavy);
}
}
7 changes: 6 additions & 1 deletion Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Hints;
using Mirror;
using Mirror.LiteNetLib4Mirror;
using RemoteAdmin;
using Searching;
using Synapse.Api.Enums;
Expand Down Expand Up @@ -99,7 +100,9 @@ public CommandSender CommandSender
/// <summary>
/// The name of the player
/// </summary>
public string NickName { get => NicknameSync.Network_myNickSync; set => Hub.nicknameSync.Network_myNickSync = value; }
public string NickName { get => NicknameSync.Network_myNickSync; }

public string DisplayName { get => NicknameSync.DisplayName; set => NicknameSync.DisplayName = value; }

/// <summary>
/// The PlayerId of the player (The Id you can see in RemoteAdmin)
Expand Down Expand Up @@ -359,6 +362,8 @@ public Player Cuffer
/// </summary>
public Camera079 Camera { get => Hub.scp079PlayerScript.currentCamera; set => Hub.scp079PlayerScript?.RpcSwitchCamera(value.cameraId, false); }

public int Ping => LiteNetLib4MirrorServer.Peers[Connection.connectionId].Ping;

/// <summary>
/// The rotation float of the player
/// </summary>
Expand Down
42 changes: 41 additions & 1 deletion Synapse/Api/Plugin/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using System.IO;
using System;
using System.IO;
using System.Reflection;

using CommandSystem;

namespace Synapse.Api.Plugin
{
public abstract class Plugin
{
internal Assembly assembly;
/// <summary>
/// The Main Config from the current Server which all Plugins can use
/// </summary>
Expand Down Expand Up @@ -41,5 +46,40 @@ public string OwnPluginFolder
/// <summary>The Method ist always activated when the Server starts</summary>
/// <remarks>You can use it to hook Events</remarks>
public abstract void OnEnable();

public virtual void RegisterCommands()
{
foreach(var type in assembly.GetTypes())
{
if (type.GetInterface("ICommand") != typeof(ICommand)) continue;

if (!Attribute.IsDefined(type, typeof(CommandHandlerAttribute))) continue;

foreach(var attributeData in type.CustomAttributes)
{
try
{
if (attributeData.AttributeType != typeof(CommandHandlerAttribute)) continue;

var cmdtype = (Type)attributeData.ConstructorArguments?[0].Value;

var cmd = (ICommand)Activator.CreateInstance(type);

if (cmdtype == typeof(RemoteAdminCommandHandler))
Server.RaCommandHandler.RegisterCommand(cmd);

if (cmdtype == typeof(GameConsoleCommandHandler))
Server.GameCoreCommandHandler.RegisterCommand(cmd);

if (cmdtype == typeof(ClientCommandHandler))
Server.ClientCommandHandler.RegisterCommand(cmd);
}
catch (Exception e)
{
Log.Error($"Error occured while registering a command: {e}");
}
}
}
}
}
}
10 changes: 9 additions & 1 deletion Synapse/Api/Server.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Mirror;
using CommandSystem;
using Mirror;
using RemoteAdmin;
using System;
using System.Reflection;

Expand Down Expand Up @@ -61,6 +63,12 @@ public static BanPlayer BanPlayer

public static ServerConsole Console => ServerConsole.singleton;

public static RemoteAdminCommandHandler RaCommandHandler => CommandProcessor.RemoteAdminCommandHandler;

public static GameConsoleCommandHandler GameCoreCommandHandler => GameCore.Console.singleton.ConsoleCommandHandler;

public static ClientCommandHandler ClientCommandHandler => QueryProcessor.DotCommandHandler;


public static int GetMethodHash(Type invokeClass, string methodName) => invokeClass.FullName.GetStableHashCode() * 503 + methodName.GetStableHashCode();
}
Expand Down
2 changes: 1 addition & 1 deletion Synapse/Config/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ internal static void InitializeConfigs()

internal static void ReloadAllConfigs()
{
SynapseConfigs.ReloadConfig();
Plugin.Config = new YamlConfig(Files.ServerConfigFile);
SynapseConfigs.ReloadConfig();

foreach (var plugin in Synapse.plugins)
try
Expand Down
10 changes: 7 additions & 3 deletions Synapse/Events/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Synapse.Events.Classes;
using Synapse.Config;
using UnityEngine;
using System;

namespace Synapse.Events
{
Expand Down Expand Up @@ -34,9 +35,12 @@ private static void OnDoorInteract(DoorInteractEvent ev)
if (!ev.Player.Items.Any()) return;
foreach (var item in ev.Player.Items)
{
var itemPerms = ev.Player.Inventory.GetItemByID(item.id).permissions;
ev.Allow = itemPerms.Any(p =>
ev.Door.backwardsCompatPermissions.TryGetValue(p, out var flag) &&
var gameitem = ev.Player.Inventory.GetItemByID(item.id);

if (gameitem.permissions == null || gameitem.permissions.Length == 0) continue;

ev.Allow = gameitem.permissions.Any(p =>
Door.backwardsCompatPermissions.TryGetValue(p, out var flag) &&
ev.Door.PermissionLevels.HasPermission(flag));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static bool Prefix(PlayerInteract __instance, GameObject doorId)
{
var itemPerms = __instance._inv.GetItemByID(__instance._inv.curItem).permissions;
allowTheAccess = itemPerms.Any(p =>
door.backwardsCompatPermissions.TryGetValue(p, out var flag) &&
Door.backwardsCompatPermissions.TryGetValue(p, out var flag) &&
door.PermissionLevels.HasPermission(flag));
}
else allowTheAccess = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Synapse.Events.Patches
{
/**
[HarmonyPatch(typeof(Generator079), nameof(Generator079.Interact))]
public static class GeneratorTabletPatches
{
Expand Down Expand Up @@ -56,7 +57,7 @@ public static bool Prefix(Generator079 __instance, GameObject person, string com
return true;
}
}
}
}*/

[HarmonyPatch(typeof(Generator079), nameof(Generator079.OpenClose))]
public static class GeneratorDoorPatches
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using Harmony;
using Synapse.Api;
using UnityEngine;

namespace Synapse.Events.Patches
{
[HarmonyPatch(typeof(TeslaGate), nameof(TeslaGate.PlayersInRange))]
public static class TeslaTriggerEvent
{
public static void Postfix(TeslaGate __instance, bool hurtRange, ref List<PlayerStats> __result)
{
try
{
__result = new List<PlayerStats>();

foreach(var player in Player.GetAllPlayers())
{
var triggerable = true;

if (Vector3.Distance(__instance.transform.position,player.Position) < __instance.sizeOfTrigger && player.Role != RoleType.Spectator)
{
Events.InvokeTeslaTrigger(player, hurtRange, ref triggerable);

if (triggerable) __result.Add(player.GetComponent<PlayerStats>());
}
}
}
catch(Exception e)
{
Log.Error($"TriggerTeslaEvent error: {e}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,15 @@ public static void Prefix(PlayerStats __instance, ref PlayerStats.HitInfo info,
var player = go.GetPlayer();

Events.InvokePlayerHurtEvent(player, killer, ref info);
}
catch (Exception e)
{
Log.Error($"PlayerDamageEvent Error: {e}");
}
}

public static void Postfix(PlayerStats __instance, PlayerStats.HitInfo info, GameObject go)
{
try
{
var killer = __instance.GetPlayer();
var player = go.GetPlayer();
if (player.GodMode) return;

if (player.Role == RoleType.Spectator)
if (player.Health + player.ArtificialHealth - info.Amount <= 0)
Events.InvokePlayerDieEvent(player, killer, info);
}
catch (Exception e)
{
Log.Error($"PlayerDie Event Error: {e}");
Log.Error($"PlayerDamageEvent Error: {e}");
}
}
}
Expand Down
Loading

0 comments on commit 3f1ba8b

Please sign in to comment.