public void OnPlayerConnected(GTANetworkAPI.Client client) { client.SetSharedData(SaltyShared.SharedData.Voice_TeamSpeakName, Guid.NewGuid().ToString()); client.SetSharedData(SaltyShared.SharedData.Voice_VoiceRange, 10f); client.TriggerEvent(SaltyShared.Event.Voice_Initialize, Voice.MinimumPluginVersion, Voice.SoundPack, Voice.IngameChannel, Voice.IngameChannel); }
public static void SetPlayerSendingOnRadioChannel(GTANetworkAPI.Client client, string radioChannel, bool isSending) { if (!Voice.RadioChannels.ContainsKey(radioChannel) || !Voice.RadioChannels[radioChannel].Contains(client)) { return; } if (isSending && !Voice.PlayersTalkingOnRadioChannels[radioChannel].Contains(client)) { Voice.PlayersTalkingOnRadioChannels[radioChannel].Add(client); foreach (GTANetworkAPI.Client radioClient in Voice.RadioChannels[radioChannel]) { radioClient.TriggerEvent(SaltyShared.Event.Voice_TalkingOnRadio, client.GetSharedData(SaltyShared.SharedData.Voice_TeamSpeakName), true); } } else if (!isSending && Voice.PlayersTalkingOnRadioChannels[radioChannel].Contains(client)) { Voice.PlayersTalkingOnRadioChannels[radioChannel].Remove(client); foreach (GTANetworkAPI.Client radioClient in Voice.RadioChannels[radioChannel]) { radioClient.TriggerEvent(SaltyShared.Event.Voice_TalkingOnRadio, client.GetSharedData(SaltyShared.SharedData.Voice_TeamSpeakName), false); } } }
/// <summary> /// Removes player from a specific radio channel /// </summary> /// <param name="client"></param> /// <param name="radioChannel"></param> public static void RemovePlayerRadioChannel(GTANetworkAPI.Client client, string radioChannel) { if (Voice.PlayersTalkingOnRadioChannels.ContainsKey(radioChannel) && Voice.PlayersTalkingOnRadioChannels[radioChannel].Contains(client)) { Voice.PlayersTalkingOnRadioChannels[radioChannel].Remove(client); if (Voice.PlayersTalkingOnRadioChannels[radioChannel].Count == 0) { Voice.PlayersTalkingOnRadioChannels.Remove(radioChannel); } foreach (GTANetworkAPI.Client radioClient in Voice.RadioChannels[radioChannel]) { radioClient.TriggerEvent(SaltyShared.Event.Voice_TalkingOnRadio, client.GetSharedData(SaltyShared.SharedData.Voice_TeamSpeakName), false); } } if (Voice.RadioChannels.ContainsKey(radioChannel) && Voice.RadioChannels[radioChannel].Contains(client)) { Voice.RadioChannels[radioChannel].Remove(client); if (Voice.RadioChannels[radioChannel].Count == 0) { Voice.RadioChannels.Remove(radioChannel); Voice.PlayersTalkingOnRadioChannels.Remove(radioChannel); } } }
/// <summary> /// Removes player from all radio channels /// </summary> /// <param name="client"></param> public static void RemovePlayerRadioChannel(GTANetworkAPI.Client client) { foreach (string radioChannel in Voice.GetRadioChannels(client)) { Voice.RemovePlayerRadioChannel(client, radioChannel); } }
public void OnSetRadioSpeaker(GTANetworkAPI.Client player, string toggleString) { bool toggle = String.Equals(toggleString, "true", StringComparison.OrdinalIgnoreCase); VoiceManager.SetRadioSpeaker(player, toggle); player.SendChatMessage("Speaker", $"The speaker is now {(toggle ? "on" : "off")}."); }
public static void SetRadioSpeaker(GTANetworkAPI.Client player, bool toggle) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } voiceClient.RadioSpeaker = toggle; }
public void OnPlayerConnected(GTANetworkAPI.Client client) { VoiceClient voiceClient = new VoiceClient(client, VoiceManager.GetTeamSpeakName(), SaltyShared.SharedData.VoiceRanges[1]); lock (VoiceManager._voiceClients) { VoiceManager._voiceClients.Add(client, voiceClient); } client.TriggerEvent(SaltyShared.Event.SaltyChat_Initialize, VoiceManager.ServerUniqueIdentifier, VoiceManager.RequiredUpdateBranch, VoiceManager.MinimumPluginVersion, VoiceManager.SoundPack, VoiceManager.IngameChannel, VoiceManager.IngameChannelPassword, voiceClient.TeamSpeakName); }
public void OnSetRadioChannel(GTANetworkAPI.Client client, string radioChannel) { if (String.IsNullOrWhiteSpace(radioChannel)) { return; } Voice.RemovePlayerRadioChannel(client); Voice.AddPlayerRadioChannel(client, radioChannel); client.TriggerEvent(SaltyShared.Event.Voice_SetRadioChannel, radioChannel); }
public static void LeaveRadioChannel(GTANetworkAPI.Client player) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } foreach (RadioChannel radioChannel in VoiceManager.RadioChannels.Where(r => r.IsMember(voiceClient))) { VoiceManager.LeaveRadioChannel(player, radioChannel.Name); } }
public void OnIsTalking(GTANetworkAPI.Client player, bool isTalking) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } foreach (VoiceClient client in VoiceManager.VoiceClients) { client.Player.TriggerEvent(SaltyShared.Event.SaltyChat_IsTalking, player.Handle.Value, isTalking); } }
public static bool TryGetVoiceClient(GTANetworkAPI.Client client, out VoiceClient voiceClient) { lock (VoiceManager._voiceClients) { if (VoiceManager._voiceClients.TryGetValue(client, out voiceClient)) { return(true); } } voiceClient = null; return(false); }
/// <summary> /// Returns all radio channels the client is currently in /// </summary> internal static List <string> GetRadioChannels(GTANetworkAPI.Client client) { List <string> radioChannels = new List <string>(); foreach (KeyValuePair <string, List <GTANetworkAPI.Client> > radioChannel in Voice.RadioChannels) { if (radioChannel.Value.Contains(client)) { radioChannels.Add(radioChannel.Key); } } return(radioChannels); }
public static void SendingOnRadio(GTANetworkAPI.Client player, string radioChannelName, bool isSending) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } RadioChannel radioChannel = VoiceManager.GetRadioChannel(radioChannelName, false); if (radioChannel == null || !radioChannel.IsMember(voiceClient)) { return; } radioChannel.Send(voiceClient, isSending); }
public void OnSetVoiceRange(GTANetworkAPI.Client player, float voiceRange) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } if (Array.IndexOf(SaltyShared.SharedData.VoiceRanges, voiceRange) >= 0) { voiceClient.VoiceRange = voiceRange; foreach (VoiceClient client in VoiceManager.VoiceClients) { client.Player.TriggerEvent(SaltyShared.Event.SaltyChat_UpdateClient, player.Handle.Value, voiceClient.TeamSpeakName, voiceClient.VoiceRange); } } }
/// <summary> /// Adds player to a radio channel /// </summary> /// <param name="client"></param> /// <param name="radioChannel"></param> public static void AddPlayerRadioChannel(GTANetworkAPI.Client client, string radioChannel) { if (Voice.RadioChannels.ContainsKey(radioChannel) && Voice.RadioChannels[radioChannel].Contains(client)) { return; } else if (Voice.RadioChannels.ContainsKey(radioChannel)) { Voice.RadioChannels[radioChannel].Add(client); } else { Voice.RadioChannels.Add(radioChannel, new List <GTANetworkAPI.Client> { client }); Voice.PlayersTalkingOnRadioChannels.Add(radioChannel, new List <GTANetworkAPI.Client>()); } }
public static void LeaveRadioChannel(GTANetworkAPI.Client player, string radioChannelName) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } RadioChannel radioChannel = VoiceManager.GetRadioChannel(radioChannelName, false); if (radioChannel != null) { radioChannel.RemoveMember(voiceClient); if (radioChannel.Members.Length == 0) { VoiceManager._radioChannels.Remove(radioChannel); } } }
public static void JoinRadioChannel(GTANetworkAPI.Client player, string radioChannelName) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } foreach (RadioChannel channel in VoiceManager.RadioChannels) { if (channel.IsMember(voiceClient)) { return; } } RadioChannel radioChannel = VoiceManager.GetRadioChannel(radioChannelName, true); radioChannel.AddMember(voiceClient); }
private void OnCheckVersion(GTANetworkAPI.Client player, string branch, string version) { if (!VoiceManager.TryGetVoiceClient(player, out VoiceClient voiceClient)) { return; } if (!VoiceManager.IsVersionAccepted(branch, version)) { player.Kick($"[Salty Chat] Required Branch: {VoiceManager.RequiredUpdateBranch} | Required Version: {VoiceManager.MinimumPluginVersion}"); return; } foreach (VoiceClient cl in VoiceManager.VoiceClients) { player.TriggerEvent(SaltyShared.Event.SaltyChat_UpdateClient, cl.Player.Handle.Value, cl.TeamSpeakName, cl.VoiceRange); cl.Player.TriggerEvent(SaltyShared.Event.SaltyChat_UpdateClient, voiceClient.Player.Handle.Value, voiceClient.TeamSpeakName, voiceClient.VoiceRange); } player.TriggerEvent(SaltyShared.Event.SaltyChat_UpdateRadioTowers, Newtonsoft.Json.JsonConvert.SerializeObject(VoiceManager.RadioTowers)); }
public void OnPlayerDisconnected(GTANetworkAPI.Client client, GTANetworkAPI.DisconnectionType disconnectionType, string reason) { VoiceClient voiceClient; lock (VoiceManager._voiceClients) { if (!VoiceManager._voiceClients.TryGetValue(client, out voiceClient)) { return; } VoiceManager._voiceClients.Remove(client); } foreach (RadioChannel radioChannel in VoiceManager.RadioChannels.Where(c => c.IsMember(voiceClient))) { radioChannel.RemoveMember(voiceClient); } foreach (VoiceClient cl in VoiceManager.VoiceClients) { cl.Player.TriggerEvent(SaltyShared.Event.SaltyChat_Disconnected, voiceClient.TeamSpeakName); } }
public void OnPlayerDisconnected(GTANetworkAPI.Client client) { Voice.RemovePlayerRadioChannel(client); }
public void OnPlayerTalkingOnRadio(GTANetworkAPI.Client client, string radioChannel, bool isSending) { Voice.SetPlayerSendingOnRadioChannel(client, radioChannel, isSending); }
public void OnSetVoiceRange(GTANetworkAPI.Client client, float voiceRange) { client.SetSharedData(SaltyShared.SharedData.Voice_VoiceRange, voiceRange); }
public VoiceClient(GTANetworkAPI.Client player, string teamSpeakName, float voiceRange) { this.Player = player; this.TeamSpeakName = teamSpeakName; this.VoiceRange = voiceRange; }
public void OnLeaveRadioChannel(GTANetworkAPI.Client player, string channelName) { VoiceManager.LeaveRadioChannel(player, channelName); player.SendChatMessage("Radio", $"You left channel \"{channelName}\"."); }