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 #16 from SynapseSL/development
Browse files Browse the repository at this point in the history
v.1.2.0
  • Loading branch information
moelrobi authored Aug 13, 2020
2 parents 24ac13e + 74c8ad4 commit d67476c
Show file tree
Hide file tree
Showing 27 changed files with 500 additions and 109 deletions.
28 changes: 27 additions & 1 deletion Synapse/Api/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class Map
/// <summary>
/// Gives you a list of all lifts
/// </summary>
public static List<Lift> Lifts => Object.FindObjectsOfType<Lift>().ToList();
public static List<Lift> Lifts => Server.GetObjectsOf<Lift>();

private static Broadcast BroadcastComponent => Player.Host.GetComponent<Broadcast>();

Expand Down Expand Up @@ -175,6 +175,32 @@ 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 WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vector3 size)
{
GameObject bench =
Object.Instantiate(
NetworkManager.singleton.spawnPrefabs.Find(p => p.gameObject.name == "Work Station"));
Offset offset = new Offset();
offset.position = position;
offset.rotation = rotation;
offset.scale = Vector3.one;
bench.gameObject.transform.localScale = size;

NetworkServer.Spawn(bench);
bench.GetComponent<WorkStation>().Networkposition = offset;
bench.AddComponent<WorkStationUpgrader>();

return bench.GetComponent<WorkStation>();
}

public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = "World")
{
Server.Host.GetComponent<RagdollManager>().SpawnRagdoll(
Position, Quaternion.identity, Vector3.zero, (int)role,
new PlayerStats.HitInfo(1000f, killer, DamageTypes.Falldown, 1)
, false, killer, killer, 1);
}

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);
Expand Down
40 changes: 39 additions & 1 deletion Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public Room Room
get
{
var playerPos = Position;
var end = playerPos - new Vector3(0f, 10f, 0f);
var end = playerPos - new Vector3(0f, 30f, 0f);
var flag = Physics.Linecast(playerPos, end, out var rayCastHit, -84058629);

if (!flag || rayCastHit.transform == null)
Expand Down Expand Up @@ -393,6 +393,11 @@ public Player Cuffer

public string UnitName { get => ClassManager.NetworkCurUnitName; set => ClassManager.NetworkCurUnitName = value; }

/// <summary>
/// If the Client sends a DnT Signal, useful for storing data
/// </summary>
public bool DoNotTrack => ServerRoles.DoNotTrack;

//Methods
/// <summary>
/// Kicks the player
Expand Down Expand Up @@ -511,6 +516,8 @@ public void InstantBroadcast(ushort time, string message)
/// <param name="other"></param>
public void GiveItem(ItemType itemType, float duration = float.NegativeInfinity, int sight = 0, int barrel = 0, int other = 0) => Hub.inventory.AddNewItem(itemType, duration, sight, barrel, other);

public void DropAllItems() => Inventory.ServerDropAll();

public void DropItem(Inventory.SyncItemInfo item)
{
Inventory.SetPickup(item.id, item.durability, Position, Inventory.camera.transform.rotation, item.modSight, item.modBarrel, item.modOther);
Expand Down Expand Up @@ -579,5 +586,36 @@ public void SendToServer(ushort port)
Connection.Send(msg);
NetworkWriterPool.Recycle(writer);
}

public void DimScreen()
{
var component = RoundSummary.singleton;
var writer = NetworkWriterPool.GetWriter();
var msg = new RpcMessage
{
netId = component.netId,
componentIndex = component.ComponentIndex,
functionHash = Server.GetMethodHash(typeof(RoundSummary), "RpcDimScreen"),
payload = writer.ToArraySegment()
};
Connection.Send(msg);
NetworkWriterPool.Recycle(writer);
}

public void ShakeScreen(bool achieve = false)
{
var component = Warhead.Controller;
var writer = NetworkWriterPool.GetWriter();
writer.WriteBoolean(achieve);
var msg = new RpcMessage
{
netId = component.netId,
componentIndex = component.ComponentIndex,
functionHash = Server.GetMethodHash(typeof(AlphaWarheadController), "RpcShake"),
payload = writer.ToArraySegment()
};
Connection.Send(msg);
NetworkWriterPool.Recycle(writer);
}
}
}
5 changes: 4 additions & 1 deletion Synapse/Api/Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public abstract class Plugin
// ReSharper disable once NotAccessedField.Global
public static YamlConfig Config;

[Obsolete("Please use public override void ReloadConfigs() now!")]
public delegate void OnConfigReload();
[Obsolete("Please use public override void ReloadConfigs() now!")]
public event OnConfigReload ConfigReloadEvent;
internal void InvokeConfigReloadEvent() => ConfigReloadEvent?.Invoke();

// ReSharper disable once UnusedAutoPropertyAccessor.Global
public Translation Translation { get; internal set; }
Expand Down Expand Up @@ -81,5 +82,7 @@ public virtual void RegisterCommands()
}
}
}

public virtual void ReloadConfigs() => ConfigReloadEvent.Invoke();
}
}
5 changes: 4 additions & 1 deletion Synapse/Api/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ namespace Synapse.Api
{
public static class Round
{
[Obsolete("Please use RoundLength")]
public static TimeSpan RoundLenght => RoundStart.RoundLenght;

public static DateTime StartedTime => DateTime.Now - RoundLenght;
public static TimeSpan RoundLength => RoundStart.RoundLenght;

public static DateTime StartedTime => DateTime.Now - RoundLength;

public static bool IsStarted => RoundSummary.RoundInProgress();

Expand Down
4 changes: 4 additions & 0 deletions Synapse/Api/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Mirror;
using RemoteAdmin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Synapse.Api
Expand Down Expand Up @@ -70,6 +72,8 @@ public static BanPlayer BanPlayer
public static ClientCommandHandler ClientCommandHandler => QueryProcessor.DotCommandHandler;


public static List<TObject> GetObjectsOf<TObject>() where TObject : UnityEngine.Object => UnityEngine.Object.FindObjectsOfType<TObject>().ToList();

public static int GetMethodHash(Type invokeClass, string methodName) => invokeClass.FullName.GetStableHashCode() * 503 + methodName.GetStableHashCode();
}
}
70 changes: 70 additions & 0 deletions Synapse/Commands/KeyPressCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using CommandSystem;
using Synapse.Api;
using System;
using System.Linq;
using UnityEngine;

namespace Synapse.Commands
{
[CommandHandler(typeof(ClientCommandHandler))]
public class KeyPressCommand : ICommand
{
public string Command { get; } = "keypress";

public string[] Aliases { get; } = new string[]
{
"kp",
"key",
"keybind"
};

public string Description { get; } = "A Command for the KeyPressEvent from Synapse!";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string respone)
{
if (sender.GetPlayer() == Server.Host)
{
respone = "Nope the Console cant use this!";
return false;
}

if (arguments.Count < 1)
{
respone = "Use .key sync in order to sync your binds and use all Features of the Plugins!";
return false;
}

switch (arguments.FirstOrDefault().ToUpper())
{
case "SYNC":
var component = sender.GetPlayer().ClassManager;
foreach(var key in (KeyCode[])Enum.GetValues(typeof(KeyCode)))
component.TargetChangeCmdBinding(component.connectionToClient, key, $".key send {(int)key}");

respone = "All Keys was synced!";
return true;

case "SEND":
if(!Enum.TryParse<KeyCode>(arguments.ElementAt(1), out var key2))
{
respone = "Invalid KeyBind! If they are binded by Synapse please report this!";
return false;
}

try
{
Events.Events.InvokeKeyPressEvent(sender.GetPlayer(), key2);
}
catch (Exception e)
{
Log.Error($"KeyPressEvent Error: {e} ");
}
respone = "Key was accepted";
return true;
default:
respone = "Use .key sync in order to sync your binds and use all Features of the Plugins!";
return false;
}
}
}
}
42 changes: 42 additions & 0 deletions Synapse/Commands/PluginInfoCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using CommandSystem;
using System;
using System.Linq;

namespace Synapse.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
[CommandHandler(typeof(GameConsoleCommandHandler))]
[CommandHandler(typeof(ClientCommandHandler))]
public class PluginInfoCommand : ICommand
{
public string Command { get; } = "plugin";

public string[] Aliases { get; } = new string[]
{
"plugininfo",
"pi"
};

public string Description { get; } = "Gives you Informations about a Plugin";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string respone)
{
if (arguments.Count < 1)
{
respone = "You also have to enter a plugin name: plugin ExamplePlugin";
return false;
}

foreach(var plugin in Synapse.Plugins)
if (plugin.Name.ToLower().Contains(arguments.FirstOrDefault().ToLower()))
{
respone = $"The Plugin {plugin.Name} Version {plugin.Version} was created by {plugin.Author} and was made for Synapse v.{plugin.SynapseMajor}.{plugin.SynapseMinor}.{plugin.SynapsePatch}" +
$"\nPlugin Description: {plugin.Description}";
return true;
}

respone = "No Plugin with such a name was found!";
return false;
}
}
}
32 changes: 32 additions & 0 deletions Synapse/Commands/PluginsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using CommandSystem;
using System;

namespace Synapse.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
[CommandHandler(typeof(GameConsoleCommandHandler))]
[CommandHandler(typeof(ClientCommandHandler))]
public class PluginsCommand : ICommand
{
public string Command { get; } = "plugins";

public string[] Aliases { get; } = new string[]
{
"pl",
};

public string Description { get; } = "Gives you all Plugins installed on the Server";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string respone)
{
var msg = "\nAll Plugins:";
foreach(var plugin in Synapse.Plugins)
{
msg += $"\n{plugin.Name} Version: {plugin.Version} by {plugin.Author}";
}

respone = msg;
return true;
}
}
}
34 changes: 34 additions & 0 deletions Synapse/Commands/ReloadConfigsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using CommandSystem;
using Synapse.Api;
using Synapse.Config;
using System;

namespace Synapse.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class ReloadConfigsCommand : ICommand
{
public string Command { get; } = "reloadconfigs";

public string[] Aliases { get; } = new string[]
{
"rc",
"reloadc"
};

public string Description { get; } = "A Command to Relaod the Configs of Synapse";

public bool Execute(ArraySegment<string> arguments,ICommandSender sender,out string respone)
{
if (!sender.GetPlayer().CheckPermission("sy.reload.configs"))
{
respone = "You have no Permission for Reload Configs";
return false;
}

ConfigManager.ReloadAllConfigs();
respone = "Configs Reloaded!";
return true;
}
}
}
34 changes: 34 additions & 0 deletions Synapse/Commands/ReloadPermissionsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using CommandSystem;
using Synapse.Api;
using Synapse.Config;
using System;

namespace Synapse.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class ReloadPermissionsCommand : ICommand
{
public string Command { get; } = "reloadpermissions";

public string[] Aliases { get; } = new string[]
{
"rp",
"reloadp"
};

public string Description { get; } = "A Command to Relaod the Permissions of Synapse";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string respone)
{
if (!sender.GetPlayer().CheckPermission("sy.reload.permission"))
{
respone = "You have no Permission for Reload Permissions";
return false;
}

PermissionReader.ReloadPermission();
respone = "Permissions Reloaded!";
return true;
}
}
}
2 changes: 1 addition & 1 deletion Synapse/Config/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static void ReloadAllConfigs()
foreach (var plugin in Synapse.plugins)
try
{
plugin.InvokeConfigReloadEvent();
plugin.ReloadConfigs();
}
catch (Exception e)
{
Expand Down
4 changes: 0 additions & 4 deletions Synapse/Events/Classes/ConsoleCommandEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ public class ConsoleCommandEvent
public Player Player { get; internal set; }

public string Command { get; internal set; }

public string ReturnMessage { get; set; }

public string Color { get; set; }
}
}
Loading

0 comments on commit d67476c

Please sign in to comment.