diff --git a/AudioPlayer.csproj b/AudioPlayer.csproj
index abd6461..903cf6c 100644
--- a/AudioPlayer.csproj
+++ b/AudioPlayer.csproj
@@ -12,6 +12,8 @@
v4.8
512
true
+
+
true
@@ -33,9 +35,9 @@
x64
-
+
@@ -78,6 +80,9 @@
packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.Permissions.dll
+
+ packages\LiteDB.5.0.21\lib\net45\LiteDB.dll
+
$(EXILED_REFERENCES)\Mirror.dll
@@ -92,6 +97,7 @@
.\lib\SCPSLAudioApi.dll
+
False
$(EXILED_REFERENCES)\UnityEngine.dll
diff --git a/Config.cs b/Config.cs
index 48f2f96..4f36f44 100644
--- a/Config.cs
+++ b/Config.cs
@@ -1,10 +1,6 @@
-using System;
-using System.Collections.Generic;
+using Exiled.API.Interfaces;
using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Exiled.API.Interfaces;
+using System.IO;
namespace AudioPlayer
{
@@ -13,17 +9,19 @@ public class Config : IConfig
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;
- public string AudioFilePath { get; set; } = "/home/container/.config/EXILED/Configs/audio";
+ public string AudioFilePath { get; set; } = Path.Combine(Exiled.API.Features.Paths.Configs, "audio");
- public bool PlayMtfSound { get; set; } = true;
+ public bool PlayMtfSound { get; set; } = false;
public string MtfSoundFilePath {get; set;} = "mtf.ogg";
- public bool PlayChaosSound { get; set; } = true;
+ public bool PlayChaosSound { get; set; } = false;
public string ChaosSoundFilePath {get; set;} = "chaos.ogg";
[Description("Do not put over 100 because it could break the VoiceChat for everyplayer and they'll have to restart SL")]
public float Volume {get; set;} = 20f;
+
+ public string DatabaseFilePath { get; set; } = Path.Combine(Exiled.API.Features.Paths.Configs, "audio/audioplayers.db");
}
}
diff --git a/FakeConnection.cs b/FakeConnection.cs
deleted file mode 100644
index ab1d654..0000000
--- a/FakeConnection.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using Exiled.API.Features;
-using Mirror;
-using System.Linq;
-
-namespace AudioPlayer
-{
- public class FakeConnection : NetworkConnectionToClient
- {
- public FakeConnection(int connectionId) : base(connectionId)
- {
-
- }
-
- public override string address
- {
- get
- {
- return "localhost";
- }
- }
-
- public override void Send(ArraySegment segment, int channelId = 0)
- {
- }
- public override void Disconnect()
- {
- }
- }
-}
diff --git a/Mute.cs b/Mute.cs
index b4bc5f3..b8fabb1 100644
--- a/Mute.cs
+++ b/Mute.cs
@@ -1,4 +1,4 @@
-using CommandSystem;
+using CommandSystem;
using Exiled.API.Features;
using System;
@@ -28,16 +28,35 @@ protected override bool ExecuteParent(ArraySegment arguments, ICommandSe
return false;
}
string plyID = ply.UserId;
- if (Plugin.instance.MutedAnnounce.Contains(plyID))
+ using (var playerRepo = new PlayerRepository(Plugin.instance.Config.DatabaseFilePath))
{
- Plugin.instance.MutedAnnounce.Remove(plyID);
+ PlayerDB playerdb = playerRepo.GetPlayerByUserId(plyID);
+ if (playerdb != null)
+ {
+ if (playerdb.Mute == 2)
+ {
+ Log.Info(playerdb.Mute);
+ playerdb.Mute = 1;
+ playerRepo.UpdatePlayer(playerdb);
+ Plugin.instance.MutedAnnounce.Remove(plyID);
+
+ }
+ else
+ {
+ playerdb.Mute = 2;
+ playerRepo.UpdatePlayer(playerdb);
+ Plugin.instance.MutedAnnounce.Add(plyID);
+ }
+ }
+ else
+ {
+ playerRepo.InsertPlayer(new PlayerDB() { UserId = plyID, Mute = 2 });
+ Plugin.instance.MutedAnnounce.Add(plyID);
+ }
+ playerdb = playerRepo.GetPlayerByUserId(plyID);
+ response = playerdb.Mute == 2 ? "You have muted the Facility Announce" : "You have unmuted the Facility Announce";
}
- else
- {
- Plugin.instance.MutedAnnounce.Add(plyID);
- }
- response = Plugin.instance.MutedAnnounce.Contains(plyID) ? "You have muted the Facility Announce": "You have unmuted the Facility Announce";
return true;
}
}
diff --git a/PlaySound.cs b/PlaySound.cs
index 8ee380f..0ec649c 100644
--- a/PlaySound.cs
+++ b/PlaySound.cs
@@ -1,16 +1,10 @@
-using System;
-using System.IO;
-using CommandSystem;
-using Exiled.API.Features;
+using CommandSystem;
using Exiled.Permissions.Extensions;
using SCPSLAudioApi.AudioCore;
-using UnityEngine;
-using MapGeneration;
-using PlayerRoles;
-using RemoteAdmin;
-using System.Linq;
+using System;
using System.Collections.Generic;
-using Mirror;
+using System.IO;
+using System.Linq;
namespace AudioPlayer
diff --git a/PlayerRepository.cs b/PlayerRepository.cs
new file mode 100644
index 0000000..3dd2693
--- /dev/null
+++ b/PlayerRepository.cs
@@ -0,0 +1,59 @@
+using LiteDB;
+using System;
+using System.IO;
+
+
+namespace AudioPlayer
+{
+ public class PlayerRepository : IDisposable
+ {
+ private readonly LiteDatabase _db;
+
+ public PlayerRepository(string databasePath)
+ {
+ var directory = Path.GetDirectoryName(databasePath);
+ if (!Directory.Exists(directory))
+ {
+ Directory.CreateDirectory(directory);
+ }
+
+ _db = new LiteDatabase(databasePath);
+
+ var players = _db.GetCollection("t_players");
+ players.EnsureIndex(x => x.UserId, true);
+
+ }
+
+ public PlayerDB GetPlayerByUserId(string userId)
+ {
+ var players = _db.GetCollection("t_players");
+ var player = players.FindOne(x => x.UserId == userId);
+ return player;
+ }
+
+ public void InsertPlayer(PlayerDB player)
+ {
+ var players = _db.GetCollection("t_players");
+ players.Insert(player);
+ }
+
+ public void UpdatePlayer(PlayerDB player)
+ {
+ var players = _db.GetCollection("t_players");
+ players.Update(player);
+ }
+
+ public void Dispose()
+ {
+ _db.Dispose();
+ }
+ }
+
+ public class PlayerDB
+ {
+ public int Id { get; set; }
+ public string UserId { get; set; }
+ public int Mute { get; set; }
+ }
+
+}
diff --git a/Plugin.cs b/Plugin.cs
index f6bc7f4..050049e 100644
--- a/Plugin.cs
+++ b/Plugin.cs
@@ -1,19 +1,16 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Exiled.API.Features;
-using Exiled.API.Interfaces;
-using Exiled.Events.Handlers;
-using Exiled.Events.EventArgs;
+using Exiled.API.Features;
+using Exiled.Events.EventArgs.Map;
+using Exiled.Events.EventArgs.Player;
using Exiled.Events.EventArgs.Server;
-using SCPSLAudioApi.AudioCore;
-using UnityEngine;
+using LiteDB;
using MEC;
using Mirror;
-using Exiled.Events.EventArgs.Map;
+using SCPSLAudioApi.AudioCore;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using UnityEngine;
namespace AudioPlayer
{
@@ -23,11 +20,11 @@ public class Plugin : Plugin
public override string Name => "AudioPlayer";
- public override Version Version => new Version(1, 3, 0);
+ public override Version Version => new Version(2, 0, 0);
public override string Prefix => "audioplayer";
- public static List AudioPlayers = new List();
+ public static List AudioPlayers = new List();
public static Plugin instance;
@@ -40,9 +37,10 @@ public override void OnEnabled()
Plugin.instance = this;
MutedAnnounce = new List();
Exiled.Events.Handlers.Server.RespawningTeam += OnRespawnTeam;
- SCPSLAudioApi.AudioCore.AudioPlayerBase.OnFinishedTrack += OnFinishedTrack;
+ SCPSLAudioApi.AudioCore.AudioPlayerBase.OnFinishedTrack += OnFinishedTrack;
Exiled.Events.Handlers.Map.AnnouncingNtfEntrance += OnNTFAnnounce;
Exiled.Events.Handlers.Server.RoundStarted += OnRoundStart;
+ Exiled.Events.Handlers.Player.Verified += OnVerified;
}
public override void OnDisabled()
@@ -54,26 +52,48 @@ public override void OnDisabled()
SCPSLAudioApi.AudioCore.AudioPlayerBase.OnFinishedTrack -= OnFinishedTrack;
Exiled.Events.Handlers.Map.AnnouncingNtfEntrance -= OnNTFAnnounce;
Exiled.Events.Handlers.Server.RoundStarted -= OnRoundStart;
+ Exiled.Events.Handlers.Player.Verified -= OnVerified;
}
private void OnRoundStart()
{
- AudioPlayers.Clear();
+ AudioPlayers.Clear();
+ }
+
+ private void OnVerified(VerifiedEventArgs ev)
+ {
+
+ using (var playerRepo = new PlayerRepository(Config.DatabaseFilePath))
+ {
+ PlayerDB playerdb = playerRepo.GetPlayerByUserId(ev.Player.UserId);
+ if (playerdb != null)
+ {
+ if (playerdb.Mute == 2 && !MutedAnnounce.Contains(ev.Player.UserId))
+ {
+ MutedAnnounce.Add(ev.Player.UserId);
+ }
+ }
+ else
+ {
+ playerRepo.InsertPlayer(new PlayerDB() { UserId = ev.Player.UserId, Mute = 1 });
+ }
+ }
}
private void OnNTFAnnounce(AnnouncingNtfEntranceEventArgs obj)
{
- if(Config.PlayMtfSound)
+ if (Config.PlayMtfSound)
obj.IsAllowed = false;
}
private void OnFinishedTrack(AudioPlayerBase playerBase, string track, bool directPlay, ref int nextQueuePos)
{
Stop(playerBase);
-
+
}
- public void Stop(AudioPlayerBase playerBase){
+ public void Stop(AudioPlayerBase playerBase)
+ {
var player = playerBase.Owner;
Log.Debug("Track Finished");
if (playerBase.CurrentPlay != null)
@@ -82,15 +102,15 @@ public void Stop(AudioPlayerBase playerBase){
playerBase.OnDestroy();
}
- if(player.gameObject != null)
+ if (player.gameObject != null)
{
player.gameObject.transform.position = new Vector3(-9999f, -9999f, -9999f);
Timing.CallDelayed(0.5f, () =>
{
NetworkServer.Destroy(player.gameObject);
});
- }
-
+ }
+
//NetworkConnectionToClient conn = player.connectionToClient;
//player.OnDestroy();
//CustomNetworkManager.TypedSingleton.OnServerDisconnect(conn);
@@ -100,16 +120,16 @@ public void Stop(AudioPlayerBase playerBase){
{
AudioPlayers.Remove(hub);
}
-
- foreach(var pla in AudioPlayers)
+
+ foreach (var pla in AudioPlayers)
{
var audioplayer = AudioPlayerBase.Get(pla);
- if(audioplayer.CurrentPlay == null)
+ if (audioplayer.CurrentPlay == null)
{
- AudioPlayers.Remove(pla);
- }
+ AudioPlayers.Remove(pla);
+ }
}
- }
+ }
private void OnRespawnTeam(RespawningTeamEventArgs ev)
{
@@ -123,22 +143,22 @@ private void OnRespawnTeam(RespawningTeamEventArgs ev)
else if (ev.NextKnownTeam == Respawning.SpawnableTeamType.ChaosInsurgency && Config.PlayChaosSound)
{
Log.Debug("Chaos");
-
+
PlaySound(Config.ChaosSoundFilePath, "Facility Announcement", 998, false);
}
}
public bool PlaySound(string soundName, string botName, int id, bool url)
{
- Log.Debug("playsound "+ id);
+ Log.Debug("playsound " + id);
foreach (var player in AudioPlayers)
{
Log.Debug("audioplayers: " + AudioPlayers.Count);
if (AudioPlayers.Any(x => x.nicknameSync.Network_myNickSync.Equals(botName) && AudioPlayerBase.Get(x).PlaybackCoroutine.IsRunning))
return false;
- }
+ }
- string fullPath = url ? soundName : Path.Combine(Config.AudioFilePath, soundName);
+ string fullPath = url ? soundName : Path.Combine(Config.AudioFilePath, soundName);
if (!File.Exists(fullPath) && !url)
{
return false;
@@ -146,7 +166,7 @@ public bool PlaySound(string soundName, string botName, int id, bool url)
var newPlayer = UnityEngine.Object.Instantiate(NetworkManager.singleton.playerPrefab);
Exiled.API.Features.Components.FakeConnection fakeConnection = new Exiled.API.Features.Components.FakeConnection(id);
var hubPlayer = newPlayer.GetComponent();
- NetworkServer.AddPlayerForConnection(fakeConnection, newPlayer);
+ NetworkServer.AddPlayerForConnection(fakeConnection, newPlayer);
hubPlayer.nicknameSync.Network_myNickSync = botName;
AudioPlayerBase audioPlayer = AudioPlayerBase.Get(hubPlayer);
@@ -173,7 +193,7 @@ public bool PlaySound(string soundName, string botName, int id, bool url)
if (!audioPlayerToStop.PlaybackCoroutine.IsRunning)
{
instance.Stop(audioPlayerToStop);
- }
+ }
}
return true;
diff --git a/README.md b/README.md
index 1e3cca3..a2e488d 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,12 @@
You will need the [SCPSLAudioAPI.dll](https://github.com/CedModV2/SCPSLAudioApi/releases) along with this plugin to work. Place it in the same folder as the AudioPlayer.dll
+This plugin has some dependecies you will find a zip archive named dependencies.zip inside the [release](https://github.com/Antoniofo/AudioPlayer/releases) you will have to put those two files in the `dependencies` folder indide the `Plugins` folder
+
You can install this plugin, download the [.dll](https://github.com/Antoniofo/AudioPlayer/releases) file and placing it in ``%AppData%\Roaming\EXILED\Plugins`` (Windows) or ``~/.config/EXILED/Plugins`` (Linux)
+Optional: You will need some audio files in the `audio` folder inside the Exiled `Config` folder named mtf.ogg and chaos.ogg for each respawn.
+
# How to use ?
@@ -18,7 +22,12 @@ Open your Remote Admin Console and write:
``audio``
-Usage: audio [audioName] [displayName] [[volume]]
+Usage: audio|audioplayer play/playurl/list/stop [filename]/[URL] [displayName]
+
+Note: the audio files need to meet the requirement for the SCPSLAudioApi:
+- .ogg format
+- mono
+- SampleRate of 48000
# Permission
diff --git a/packages.config b/packages.config
index feb7711..6f57ae6 100644
--- a/packages.config
+++ b/packages.config
@@ -1,4 +1,6 @@
+
+
\ No newline at end of file