private static void ExecuteCommand(PluginCommand pluginCommand) { if (!VoiceManager.IsEnabled || !VoiceManager.IsConnected || pluginCommand == default) { return; } VoiceManager._htmlWindow.ExecuteJs($"runCommand('{pluginCommand.Serialize()}')"); }
private void OnError(dynamic message) { PluginCommand pluginCommand = PluginCommand.Deserialize(message); if (pluginCommand.TryGetError(out PluginError pluginError)) { Debug.WriteLine($"[Salty Chat] Error: {pluginError.Error} - Message: {pluginError.Message}"); } }
private void OnMessage(dynamic message, dynamic cb) { PluginCommand pluginCommand = PluginCommand.Deserialize(message); if (pluginCommand.Command == Command.Ping && pluginCommand.ServerUniqueIdentifier == VoiceManager._serverUniqueIdentifier) { this.ExecuteCommand(new PluginCommand(VoiceManager._serverUniqueIdentifier)); cb(""); return; } if (!pluginCommand.TryGetState(out PluginState pluginState)) { cb(""); return; } if (pluginState.IsReady != VoiceManager._isIngame) { BaseScript.TriggerServerEvent(Event.SaltyChat_CheckVersion, pluginState.UpdateBranch, pluginState.Version); VoiceManager._isIngame = pluginState.IsReady; } if (pluginState.IsTalking != VoiceManager.IsTalking) { VoiceManager.IsTalking = pluginState.IsTalking; if (VoiceManager.IsTalking) { _ = Game.PlayerPed.Tasks.PlayFacialAnimation("face_human@gen_male@base", "mood_talking_normal"); } else { _ = Game.PlayerPed.Tasks.PlayFacialAnimation("face_human@gen_male@base", "mood_normal"); } BaseScript.TriggerEvent(Event.SaltyChat_TalkStateChanged, VoiceManager.IsTalking); } if (pluginState.IsMicrophoneMuted != VoiceManager.IsMicrophoneMuted) { VoiceManager.IsMicrophoneMuted = pluginState.IsMicrophoneMuted; BaseScript.TriggerEvent(Event.SaltyChat_MicStateChanged, VoiceManager.IsMicrophoneMuted); } if (pluginState.IsSoundMuted != VoiceManager.IsSoundMuted) { VoiceManager.IsSoundMuted = pluginState.IsSoundMuted; BaseScript.TriggerEvent(Event.SaltyChat_SoundStateChanged, VoiceManager.IsSoundMuted); } cb(""); }
private void ExecuteCommand(PluginCommand pluginCommand) { this.ExecuteCommand("runCommand", Util.ToJson(pluginCommand)); }
private void OnMessage(dynamic message, dynamic cb) { cb(""); PluginCommand pluginCommand = PluginCommand.Deserialize(message); if (pluginCommand.ServerUniqueIdentifier != this.ServerUniqueIdentifier) { return; } switch (pluginCommand.Command) { case Command.PluginState: { if (pluginCommand.TryGetPayload(out PluginState pluginState)) { BaseScript.TriggerServerEvent(Event.SaltyChat_CheckVersion, pluginState.Version); this.ExecuteCommand( new PluginCommand( Command.RadioTowerUpdate, this.ServerUniqueIdentifier, new RadioTower(this.RadioTowers) ) ); } break; } case Command.Reset: { this.IsIngame = false; this.InitializePlugin(); break; } case Command.Ping: { this.ExecuteCommand(new PluginCommand(this.ServerUniqueIdentifier)); break; } case Command.InstanceState: { if (pluginCommand.TryGetPayload(out InstanceState instanceState)) { this.IsIngame = instanceState.IsReady; } break; } case Command.SoundState: { if (pluginCommand.TryGetPayload(out SoundState soundState)) { if (soundState.IsMicrophoneMuted != this.IsMicrophoneMuted) { this.IsMicrophoneMuted = soundState.IsMicrophoneMuted; BaseScript.TriggerEvent(Event.SaltyChat_MicStateChanged, this.IsMicrophoneMuted); } if (soundState.IsMicrophoneEnabled != this.IsMicrophoneEnabled) { this.IsMicrophoneEnabled = soundState.IsMicrophoneEnabled; BaseScript.TriggerEvent(Event.SaltyChat_MicEnabledChanged, this.IsMicrophoneEnabled); } if (soundState.IsSoundMuted != this.IsSoundMuted) { this.IsSoundMuted = soundState.IsSoundMuted; BaseScript.TriggerEvent(Event.SaltyChat_SoundStateChanged, this.IsSoundMuted); } if (soundState.IsSoundEnabled != this.IsSoundEnabled) { this.IsSoundEnabled = soundState.IsSoundEnabled; BaseScript.TriggerEvent(Event.SaltyChat_SoundEnabledChanged, this.IsSoundEnabled); } } break; } case Command.TalkState: { if (pluginCommand.TryGetPayload(out TalkState talkState)) { this.SetPlayerTalking(talkState.Name, talkState.IsTalking); } break; } } }
private void OnMessage(dynamic message, dynamic cb) { PluginCommand pluginCommand = PluginCommand.Deserialize(message); if (pluginCommand.Command == Command.Ping && pluginCommand.ServerUniqueIdentifier == VoiceManager.ServerUniqueIdentifier) { this.ExecuteCommand(new PluginCommand(VoiceManager.ServerUniqueIdentifier)); cb(""); return; } else if (pluginCommand.Command == Command.Reset && pluginCommand.ServerUniqueIdentifier == VoiceManager.ServerUniqueIdentifier) { VoiceManager.IsIngame = false; this.InitializePlugin(); cb(""); return; } if (!pluginCommand.TryGetState(out PluginState pluginState)) { cb(""); return; } if (pluginState.IsReady != VoiceManager.IsIngame) { VoiceManager.IsIngame = pluginState.IsReady; if (VoiceManager.IsIngame) { BaseScript.TriggerServerEvent(Event.SaltyChat_CheckVersion, pluginState.UpdateBranch, pluginState.Version); this.ExecuteCommand( new PluginCommand( Command.RadioTowerUpdate, VoiceManager.ServerUniqueIdentifier, new RadioTower(VoiceManager.RadioTowers) ) ); } } if (pluginState.IsReady) { BaseScript.TriggerEvent(Event.SaltyChat_ConnectedToTeamspeak, pluginState.isReady); } else { BaseScript.TriggerEvent(Event.SaltyChat_ConnectedToTeamspeak, pluginState.isReady); } if (pluginState.IsTalking != VoiceManager.IsTalking) { VoiceManager.IsTalking = pluginState.IsTalking; BaseScript.TriggerEvent(Event.SaltyChat_TalkStateChanged, VoiceManager.IsTalking); BaseScript.TriggerServerEvent(Event.SaltyChat_IsTalking, VoiceManager.IsTalking); } if (pluginState.IsMicrophoneMuted != VoiceManager.IsMicrophoneMuted) { VoiceManager.IsMicrophoneMuted = pluginState.IsMicrophoneMuted; BaseScript.TriggerEvent(Event.SaltyChat_MicStateChanged, VoiceManager.IsMicrophoneMuted); } if (pluginState.IsSoundMuted != VoiceManager.IsSoundMuted) { VoiceManager.IsSoundMuted = pluginState.IsSoundMuted; BaseScript.TriggerEvent(Event.SaltyChat_SoundStateChanged, VoiceManager.IsSoundMuted); } cb(""); }
/// <summary> /// Plugin state update /// </summary> /// <param name="args">[0] - <see cref="PluginCommand"/> as json</param> public static void OnPluginMessage(object[] args) { PluginCommand pluginCommand = PluginCommand.Deserialize((string)args[0]); if (pluginCommand.Command == Command.Ping && VoiceManager._nextUpdate.AddSeconds(1) > DateTime.Now) { VoiceManager.ExecuteCommand(new PluginCommand(VoiceManager.ServerUniqueIdentifier)); return; } if (!pluginCommand.TryGetState(out PluginState pluginState)) { return; } if (pluginState.IsReady != VoiceManager._isIngame) { RAGE.Events.CallRemote(SaltyShared.Event.SaltyChat_CheckVersion, pluginState.UpdateBranch, pluginState.Version); VoiceManager._isIngame = pluginState.IsReady; } bool hasTalkingChanged = false; bool hasMicMutedChanged = false; bool hasSoundMutedChanged = false; if (pluginState.IsTalking != VoiceManager.IsTalking) { VoiceManager.IsTalking = pluginState.IsTalking; hasTalkingChanged = true; RAGE.Events.CallRemote(SaltyShared.Event.SaltyChat_IsTalking, VoiceManager.IsTalking); } if (pluginState.IsMicrophoneMuted != VoiceManager.IsMicrophoneMuted) { VoiceManager.IsMicrophoneMuted = pluginState.IsMicrophoneMuted; hasMicMutedChanged = true; } if (pluginState.IsSoundMuted != VoiceManager.IsSoundMuted) { VoiceManager.IsSoundMuted = pluginState.IsSoundMuted; hasSoundMutedChanged = true; } if (hasTalkingChanged) { VoiceManager.OnTalkingStateChange?.Invoke(new SoundEventArgs()); } if (hasMicMutedChanged) { VoiceManager.OnMicrophoneMuteStateChange?.Invoke(new SoundEventArgs()); } if (hasSoundMutedChanged) { VoiceManager.OnSoundMuteStateChange?.Invoke(new SoundEventArgs()); } if (hasTalkingChanged || hasMicMutedChanged || hasSoundMutedChanged) { VoiceManager.OnSoundStateChange?.Invoke(new SoundEventArgs()); } }
private void OnMessage(dynamic message, dynamic cb) { PluginCommand pluginCommand = PluginCommand.Deserialize(message); switch (pluginCommand.Command) { case Command.Ping: { if (pluginCommand.ServerUniqueIdentifier == VoiceManager.ServerUniqueIdentifier) { this.ExecuteCommand(new PluginCommand(VoiceManager.ServerUniqueIdentifier)); } break; } case Command.Reset: { VoiceManager.IsIngame = false; this.InitializePlugin(); break; } case Command.StateUpdate: { if (pluginCommand.TryGetPayload(out PluginState pluginState)) { if (pluginState.IsReady != VoiceManager.IsIngame) { VoiceManager.IsIngame = pluginState.IsReady; if (VoiceManager.IsIngame) { BaseScript.TriggerServerEvent(Event.SaltyChat_CheckVersion, pluginState.UpdateBranch, pluginState.Version); this.ExecuteCommand( new PluginCommand( Command.RadioTowerUpdate, VoiceManager.ServerUniqueIdentifier, new RadioTower(VoiceManager.RadioTowers) ) ); } } if (pluginState.IsTalking != VoiceManager.IsTalking) { VoiceManager.IsTalking = pluginState.IsTalking; this.SetPlayerTalking(VoiceManager.TeamSpeakName, VoiceManager.IsTalking); BaseScript.TriggerEvent(Event.SaltyChat_TalkStateChanged, VoiceManager.IsTalking); } if (pluginState.IsMicrophoneMuted != VoiceManager.IsMicrophoneMuted) { VoiceManager.IsMicrophoneMuted = pluginState.IsMicrophoneMuted; BaseScript.TriggerEvent(Event.SaltyChat_MicStateChanged, VoiceManager.IsMicrophoneMuted); } if (pluginState.IsSoundMuted != VoiceManager.IsSoundMuted) { VoiceManager.IsSoundMuted = pluginState.IsSoundMuted; BaseScript.TriggerEvent(Event.SaltyChat_SoundStateChanged, VoiceManager.IsSoundMuted); } } break; } case Command.TalkStateChange: { if (pluginCommand.TryGetPayload(out TalkState talkState)) { this.SetPlayerTalking(talkState.Name, talkState.IsTalking); } break; } } cb(""); }
private void OnMessage(dynamic message) { PluginCommand pluginCommand = PluginCommand.Deserialize(message); if (pluginCommand.Command == Command.Ping && pluginCommand.ServerUniqueIdentifier == VoiceManager._serverUniqueIdentifier) { this.ExecuteCommand(new PluginCommand(VoiceManager._serverUniqueIdentifier)); return; } if (!pluginCommand.TryGetState(out PluginState pluginState)) { return; } if (pluginState.IsReady != VoiceManager._isIngame) { BaseScript.TriggerServerEvent(Event.SaltyChat_CheckVersion, pluginState.UpdateBranch, pluginState.Version); VoiceManager._isIngame = pluginState.IsReady; } bool hasTalkingChanged = false; bool hasMicMutedChanged = false; bool hasSoundMutedChanged = false; if (pluginState.IsTalking != VoiceManager.IsTalking) { VoiceManager.IsTalking = pluginState.IsTalking; hasTalkingChanged = true; API.SetPlayerTalkingOverride(Game.Player.ServerId, VoiceManager.IsTalking); } if (pluginState.IsMicrophoneMuted != VoiceManager.IsMicrophoneMuted) { VoiceManager.IsMicrophoneMuted = pluginState.IsMicrophoneMuted; hasMicMutedChanged = true; } if (pluginState.IsSoundMuted != VoiceManager.IsSoundMuted) { VoiceManager.IsSoundMuted = pluginState.IsSoundMuted; hasSoundMutedChanged = true; } if (hasTalkingChanged) { BaseScript.TriggerEvent(Event.SaltyChat_TalkStateChanged, VoiceManager.IsTalking); } if (hasMicMutedChanged) { BaseScript.TriggerEvent(Event.SaltyChat_MicStateChanged, VoiceManager.IsMicrophoneMuted); } if (hasSoundMutedChanged) { BaseScript.TriggerEvent(Event.SaltyChat_SoundStateChanged, VoiceManager.IsSoundMuted); } }