private static void ClaimViewOrPin(TwitchModule module, string user, bool isWhisper, bool view, bool pin) { if (isWhisper) { IRCConnection.SendMessage($"Sorry {user}, claiming modules is not allowed in whispers", user, false); return; } var result = module.ClaimModule(user); IRCConnection.SendMessage(result.Second); if (result.First && view) { module.ViewPin(user, pin); } }
/// <summary> /// Join the Channel selected to the Current Server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listChannels_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e) { int s = listChannels.SelectedIndex; if (s == -1) { return; } IRCConnection c = _parent.InputPanel.CurrentConnection; if (c != null) { _parent.ParseOutGoingCommand(c, "/join " + listChannels.Items[s].ToString()); } }
public bool TryMatch(IRCConnection connection, string input) { Match match = _matchingRegex.Match(input); if (match.Success) { _action(connection, match.Groups); if (LogLine) { UnityEngine.Debug.LogFormat("[IRC:Read] {0}", input); } return(true); } return(false); }
public static void FillEdgework(string user, bool isWhisper) { if (!UserAccess.HasAccess(user, AccessLevel.Mod, true) && !TwitchPlaySettings.data.EnableFilledgeworkForEveryone && !TwitchPlaySettings.data.AnarchyMode) { return; } foreach (var bomb in TwitchGame.Instance.Bombs) { var str = bomb.FillEdgework(); if (bomb.BombID == TwitchGame.Instance._currentBomb) { IRCConnection.SendMessage(TwitchPlaySettings.data.BombEdgework, user, !isWhisper, str); } } }
public static IEnumerator Edgework([Group(1)] string edge, string user, bool isWhisper) { if (TwitchPlaySettings.data.EnableEdgeworkCommand || TwitchPlaySettings.data.AnarchyMode) { return(TwitchGame.Instance.Bombs[TwitchGame.Instance._currentBomb == -1 ? 0 : TwitchGame.Instance._currentBomb].ShowEdgework(edge)); } else { string edgework = TwitchGame.Instance.Bombs.Count == 1 ? TwitchGame.Instance.Bombs[0].EdgeworkText.text : TwitchGame.Instance.Bombs.Select(bomb => $"{bomb.BombID} = {bomb.EdgeworkText.text}").Join(" //// "); IRCConnection.SendMessage(TwitchPlaySettings.data.BombEdgework, user, !isWhisper, edgework); return(null); } }
public static void UnclaimSpecific([Group(1)] string unclaimWhat, string user, bool isWhisper) { var strings = unclaimWhat.SplitFull(' ', ',', ';'); var modules = strings.Length == 0 ? null : TwitchGame.Instance.Modules.Where(md => !md.Solved && !md.Hidden && md.PlayerName == user && strings.Any(str => str.EqualsIgnoreCase(md.Code))).ToArray(); if (modules == null || modules.Length == 0) { IRCConnection.SendMessage($"@{user}, no such module.", user, !isWhisper); return; } foreach (var module in modules) { module.SetUnclaimed(); } }
public static bool IsAuthorizedDefuser(string userNickName, bool isWhisper, bool silent = false) { if (userNickName.EqualsAny("Bomb Factory", TwitchPlaySettings.data.TwitchPlaysDebugUsername) || Instance.Bombs.Any(x => x.BombName == userNickName)) { return(true); } bool result = !TwitchPlaySettings.data.EnableWhiteList || UserAccess.HasAccess(userNickName, AccessLevel.Defuser, true); if (!result && !silent) { IRCConnection.SendMessage(string.Format(TwitchPlaySettings.data.TwitchPlaysDisabled, userNickName), userNickName, !isWhisper); } return(result); }
public static void Unclaim(TwitchModule module, string user, [Group(1)] string cmd) { var result = module.UnclaimModule(user); // If UnclaimModule responds with a null message, someone tried to unclaim a module that no one has claimed but they were waiting to claim. // It's a valid command and they were removed from the queue but no message is sent. if (result.Second != null) { IRCConnection.SendMessage(result.Second); } if (result.First && cmd.Contains("v")) { TwitchGame.ModuleCameras?.UnviewModule(module); } }
public static void ListUnsolved(string user, bool isWhisper) { if (TwitchGame.Instance.Bombs.All(b => b.IsSolved)) { // If the command is issued while the winning fanfare is playing. IRCConnection.SendMessage("All bombs already solved!", user, !isWhisper); return; } IEnumerable <string> unsolved = TwitchGame.Instance.Modules .Where(module => !module.Solved && GameRoom.Instance.IsCurrentBomb(module.BombID) && !module.Hidden) .Shuffle().Take(3) .Select(module => $"{module.HeaderText} ({module.Code}) - {(module.PlayerName == null ? "Unclaimed" : "Claimed by " + module.PlayerName)}") .ToList(); IRCConnection.SendMessage(unsolved.Any() ? $"Unsolved Modules: {unsolved.Join(", ")}" : "There are no unsolved modules on this bomb that aren't hidden.", user, !isWhisper); }
public static void DeleteQueuedPlayer([Group(1)] string callUser, string user) { if (string.IsNullOrEmpty(callUser)) { IRCConnection.SendMessageFormat("@{0}, please specify a call to remove!", user); } else if (!TwitchGame.Instance.CallingPlayers.Keys.Contains(user)) { IRCConnection.SendMessageFormat("@{0}, @{1} has not called!", user, callUser); } else { TwitchGame.Instance.CallingPlayers.Remove(callUser); IRCConnection.SendMessageFormat("@{0}, removed @{1}'s call.", user, callUser); TwitchGame.Instance.CallUpdate(true); } }
public static void Vote(string user, bool vote) { if (!Active) { IRCConnection.SendMessage($"{user}, there is no vote currently in progress."); return; } if (Voters.ContainsKey(user) && Voters[user] == vote) { IRCConnection.SendMessage($"{user}, you've already voted {(vote ? "yes" : "no")}."); return; } Voters[user] = vote; IRCConnection.SendMessage($"{user} voted {(vote ? "yes" : "no")}."); }
public static void RemoveVote(string user) { if (!Active) { IRCConnection.SendMessage($"{user}, there is no vote currently in progress."); return; } if (!Voters.ContainsKey(user)) { IRCConnection.SendMessage($"{user}, you haven't voted."); return; } Voters.Remove(user); IRCConnection.SendMessage($"{user} has removed their vote."); }
private void InvokeCommand <TObj>(IRCMessage msg, string cmdStr, TObj extraObject, params Type[] commandTypes) { Match m = null; foreach (var cmd in commandTypes.SelectMany(t => GetCommands(t)).OrderBy(cmd => cmd.Attr.Regex == null)) { if (cmd.Attr.Regex == null || (m = Regex.Match(cmdStr, cmd.Attr.Regex, RegexOptions.IgnoreCase)).Success) { if (AttemptInvokeCommand(cmd, msg, cmdStr, m, extraObject)) { return; } } } IRCConnection.SendMessage("@{0}, I don’t recognize that command.", msg.UserNickName, !msg.IsWhisper, msg.UserNickName); }
public User(string nick, IRCConnection connection) { if (connection != null) { this.connection = connection; Level = new bool[connection.ServerSetting.StatusModes[0].Length]; for (int i = 0; i < this.Level.Length; i++) { if (nick.StartsWith(connection.ServerSetting.StatusModes[1][i].ToString())) { this.Level[i] = true; nick = nick.Substring(1); } } } nickName = nick; }
public static IEnumerator Zoom(TwitchModule module, string user, [Group(1)] float?duration) { MusicPlayer musicPlayer = null; var delay = duration ?? 2; delay = Math.Max(2, delay); module.Solver._zoom = true; if (delay >= 15) { musicPlayer = MusicPlayer.StartRandomMusic(); } var zoomCoroutine = TwitchGame.ModuleCameras?.ZoomCamera(module, 1); if (zoomCoroutine != null) { while (zoomCoroutine.MoveNext()) { yield return(zoomCoroutine.Current); } } yield return(new WaitForSecondsWithCancel(delay, false, module.Solver)); if (CoroutineCanceller.ShouldCancel) { CoroutineCanceller.ResetCancel(); IRCConnection.SendMessage($"Sorry @{user}, your request to hold up the bomb for {delay} seconds has been cut short."); } if (musicPlayer != null) { musicPlayer.StopMusic(); } var unzoomCoroutine = TwitchGame.ModuleCameras?.UnzoomCamera(module, 1); if (unzoomCoroutine != null) { while (unzoomCoroutine.MoveNext()) { yield return(unzoomCoroutine.Current); } } }
public FormDCCFileAccept(IRCConnection connection, string nick, string host, string port, string ip, string file, uint fileSize, bool resume, uint filePos) { //for normal dcc connections InitializeComponent(); labelUser.Text = nick + "@" + host + " is trying to send you a file"; labelFile.Text = file + " (" + fileSize.ToString() + " bytes)"; _connection = connection; _nick = nick; _host = host; _port = port; _ip = ip; _file = file; _fileSize = fileSize; _filePos = filePos; _resume = resume; }
public static IEnumerator Retry(string user, bool isWhisper) { if (!TwitchGame.RetryAllowed) { IRCConnection.SendMessage(TwitchPlaySettings.data.RetryModeOrProfileChange, user, isWhisper); return(DoButton(Object.FindObjectOfType <ResultPage>().ContinueButton)); } if (!TwitchPlaySettings.data.EnableRetryButton) { IRCConnection.SendMessage(TwitchPlaySettings.data.RetryInactive, user, isWhisper); return(DoButton(Object.FindObjectOfType <ResultPage>().ContinueButton)); } else { TwitchPlaySettings.SetRetryReward(); return(DoButton(Object.FindObjectOfType <ResultPage>().RetryButton)); } }
/// <summary> /// Join the Channel selected to the Current Server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonJoin_Click(object sender, EventArgs e) { //join the channel selected int s = listChannels.SelectedIndex; if (s == -1) { return; } IRCConnection c = _parent.InputPanel.CurrentConnection; if (c != null) { _parent.ParseOutGoingCommand(c, "/join " + listChannels.Items[s].ToString()); } _parent.FocusInputBox(); }
private void Start() { _gameInfo = GetComponent<KMGameInfo>(); _gameInfo.OnStateChange += OnStateChange; _modSettings = GetComponent<KMModSettings>(); ModSettingsJSON settings = JsonConvert.DeserializeObject<ModSettingsJSON>(_modSettings.Settings); if (settings == null) { Debug.LogError("[TwitchPlays] Failed to read connection settings from mod settings."); return; } DebugMode = (settings.debug == true); _ircConnection = new IRCConnection(settings.authToken, settings.userName, settings.channelName, settings.serverName, settings.serverPort); _ircConnection.Connect(); _coroutineCanceller = new CoroutineCanceller(); _coroutineQueue = GetComponent<CoroutineQueue>(); _coroutineQueue.coroutineCanceller = _coroutineCanceller; logUploader = GetComponent<LogUploader>(); logUploader.ircConnection = _ircConnection; urlHelper = GetComponent<UrlHelper>(); urlHelper.ChangeMode(settings.shortUrls == true); _leaderboard = new Leaderboard(); _leaderboard.LoadDataFromFile(); SetupResponder(bombMessageResponder); SetupResponder(postGameMessageResponder); SetupResponder(missionMessageResponder); SetupResponder(miscellaneousMessageResponder); bombMessageResponder.leaderboard = _leaderboard; postGameMessageResponder.leaderboard = _leaderboard; miscellaneousMessageResponder.leaderboard = _leaderboard; bombMessageResponder.parentService = this; }
private void SetupChatSimulator() { chatSimulator.SetActive(TwitchPlaySettings.data.TwitchPlaysDebugEnabled); var num = MouseControls.SCREEN_BOUNDARY_PERCENT * Screen.height + 5; chatSimulator.transform.position = new Vector3(num, num, 0); var messageInput = chatSimulator.Traverse <InputField>("MessageInput"); var sendButton = chatSimulator.Traverse <Button>("SendButton"); messageInput.onEndEdit.AddListener(_ => { if (Input.GetKey(KeyCode.Return)) { sendButton.onClick.Invoke(); messageInput.ActivateInputField(); } }); sendButton.onClick.AddListener(() => { var message = messageInput.text; if (string.IsNullOrEmpty(message)) { return; } if (message.Equals(DebugSequence)) { TwitchPlaySettings.data.TwitchPlaysDebugEnabled = !TwitchPlaySettings.data.TwitchPlaysDebugEnabled; TwitchPlaySettings.WriteDataToFile(); chatSimulator.SetActive(TwitchPlaySettings.data.TwitchPlaysDebugEnabled); } else { IRCConnection.SetDebugUsername(); IRCConnection.SendMessage(message); IRCConnection.ReceiveMessage(IRCConnection.Instance.UserNickName, IRCConnection.Instance.CurrentColor, message); } messageInput.text = ""; }); }
private bool HandleKey(string[] modulesBefore, IEnumerable <string> modulesAfter, FieldInfo keyTurned, FieldInfo otherKeyTurned, FieldInfo beforeKeyField, MethodInfo onKeyTurn, FieldInfo animatorField) { if (!GetValue(ActivatedField) || GetValue(keyTurned)) { return(false); } KMBombInfo bombInfo = Module.BombComponent.GetComponent <KMBombInfo>(); KMBombModule bombModule = Module.BombComponent.GetComponent <KMBombModule>(); KMAudio bombAudio = Module.BombComponent.GetComponent <KMAudio>(); Animator keyAnimator = (Animator)animatorField.GetValue(Module.BombComponent.GetComponent(ComponentType)); if (TwitchPlaySettings.data.EnforceSolveAllBeforeTurningKeys && modulesAfter.Any(x => bombInfo.GetSolvedModuleNames().Count(x.Equals) != bombInfo.GetSolvableModuleNames().Count(x.Equals))) { keyAnimator.SetTrigger("WrongTurn"); bombAudio.PlaySoundAtTransform("WrongKeyTurnFK", Module.transform); bombModule.HandleStrike(); return(false); } beforeKeyField.SetValue(null, TwitchPlaySettings.data.DisableTurnTheKeysSoftLock ? new string[0] : modulesBefore); onKeyTurn.Invoke(Module.BombComponent.GetComponent(ComponentType), null); if (GetValue(keyTurned)) { //Check to see if any forbidden modules for this key were solved. if (TwitchPlaySettings.data.DisableTurnTheKeysSoftLock && bombInfo.GetSolvedModuleNames().Any(modulesBefore.Contains)) { bombModule.HandleStrike(); //If so, Award a strike for it. } if (!GetValue(otherKeyTurned)) { return(false); } int modules = bombInfo.GetSolvedModuleNames().Count(x => RightAfterA.Contains(x) || LeftAfterA.Contains(x)); TwitchPlaySettings.AddRewardBonus((2 * modules * OtherModes.ScoreMultiplier).RoundToInt()); IRCConnection.SendMessage($"Reward increased by {modules * 2} for defusing module !{Code} ({bombModule.ModuleDisplayName})."); } else { keyAnimator.SetTrigger("WrongTurn"); bombAudio.PlaySoundAtTransform("WrongKeyTurnFK", Module.transform); } return(false); }
private bool ConnectDisconnect() { Audio.PlaySound(KMSoundOverride.SoundEffect.ButtonPress, transform); if (IRCConnection.Instance == null) { return(false); } if (IRCConnection.Instance.State == IRCConnectionState.Disconnected) { IRCConnection.Connect(); } else { IRCConnection.Disconnect(); } return(false); }
public static void CallAllQueuedCommands(string user, bool isWhisper) { if (TwitchGame.Instance.CommandQueue.Count == 0) { IRCConnection.SendMessage($"{user}, the queue is empty.", user, !isWhisper); return; } // Take a copy of the list in case executing one of the commands modifies the command queue var allCommands = TwitchGame.Instance.CommandQueue.ToList(); TwitchGame.Instance.CommandQueue.Clear(); TwitchGame.ModuleCameras?.SetNotes(); foreach (var call in allCommands) { IRCConnection.SendMessageFormat("Calling {0}: {1}", call.Message.UserNickName, call.Message.Text); IRCConnection.ReceiveMessage(call.Message); } }
public static void ListCalledPlayers() { int totalCalls = TwitchGame.Instance.CallingPlayers.Count; if (totalCalls == 0) { IRCConnection.SendMessageFormat("No calls have been made."); return; } string[] __calls = TwitchGame.Instance.CallingPlayers.Values.ToArray(); string[] __callPlayers = TwitchGame.Instance.CallingPlayers.Keys.ToArray(); string builder = ""; for (int j = 0; j < __calls.Length; j++) { builder = builder + ((j == 0) ? "@" : ", @") + __callPlayers[j] + ": " + (string.IsNullOrEmpty(__calls[j]) ? "Next queued command" : __calls[j]); } IRCConnection.SendMessageFormat("These players have already called: {0}", builder); }
public static void Take(TwitchModule module, string user, bool isWhisper) { if (isWhisper) { IRCConnection.SendMessageFormat("Sorry {0}, taking modules is not allowed in whispers.", user); } else if (TwitchPlaySettings.data.AnarchyMode) { IRCConnection.SendMessageFormat("Sorry {0}, taking modules is not allowed in anarchy mode.", user); } // Attempt to take over from another user else if (module.PlayerName != null && user != module.PlayerName) { module.AddToClaimQueue(user); if (module.TakeInProgress == null) { IRCConnection.SendMessageFormat(TwitchPlaySettings.data.TakeModule, module.PlayerName, user, module.Code, module.HeaderText); module.TakeInProgress = module.TakeModule(); module.StartCoroutine(module.TakeInProgress); } else { IRCConnection.SendMessageFormat(TwitchPlaySettings.data.TakeInProgress, user, module.Code, module.HeaderText); } } // Module is already claimed by the same user else if (module.PlayerName != null) { if (!module.PlayerName.Equals(user)) { module.AddToClaimQueue(user); } IRCConnection.SendMessageFormat(TwitchPlaySettings.data.ModuleAlreadyOwned, user, module.Code, module.HeaderText); } // Module is not claimed at all: just claim it else { IRCConnection.SendMessage(module.ClaimModule(user).Second); } }
public static void Elapsed(object _ = null, ElapsedEventArgs __ = null) { if (!Active) { return; } Countdown.Enabled = false; int yesVotes = Voters.Count(pair => pair.Value); if (yesVotes >= Voters.Count * (TwitchPlaySettings.data.MinimumYesVotes[ActionType] / 100f)) { actionDict[ActionType](); Clear(); return; } IRCConnection.SendMessage("Voting ended with a result of no."); Clear(); }
public static IEnumerator Revert() { var previousBuild = new DirectoryInfo(Path.Combine(TwitchPlaysService.DataFolder, "Previous Build")); if (!previousBuild.Exists) { IRCConnection.SendMessage("There is no previous version of Twitch Plays to revert to."); yield break; } IRCConnection.SendMessage("Reverting to the previous Twitch Plays build and restarting."); DirectoryInfo modFolder = new DirectoryInfo(GetModFolder()); modFolder.Delete(true); previousBuild.MoveToSafe(modFolder); GlobalCommands.RestartGame(); }
public static void CancelTake(TwitchModule module, string user, bool isWhisper) { if (module.TakeInProgress == null) { IRCConnection.SendMessage($"@{user}, there are no takeover attempts on module {module.Code} ({module.HeaderText}).", user, !isWhisper); return; } if (!UserAccess.HasAccess(user, AccessLevel.Mod, true) && module.TakeUser != user) { IRCConnection.SendMessage($"@{user}, if you’re not a mod, you can only cancel your own takeover attempts."); return; } // Cancel the takeover attempt IRCConnection.SendMessage($"{module.TakeUser}’s takeover of module {module.Code} ({module.HeaderText}) was cancelled by {user}."); module.StopCoroutine(module.TakeInProgress); module.TakeInProgress = null; module.TakeUser = null; }
public static void Status(TwitchBomb bomb, string user, bool isWhisper) { int currentReward = TwitchPlaySettings.GetRewardBonus(); if (OtherModes.TimeModeOn) { IRCConnection.SendMessage(string.Format(TwitchPlaySettings.data.BombStatusTimeMode, bomb.GetFullFormattedTime, bomb.GetFullStartingTime, OtherModes.GetAdjustedMultiplier(), bomb.BombSolvedModules, bomb.BombSolvableModules, currentReward), user, !isWhisper); } else if (OtherModes.VSModeOn) { IRCConnection.SendMessage(string.Format(TwitchPlaySettings.data.BombStatusVsMode, bomb.GetFullFormattedTime, bomb.GetFullStartingTime, OtherModes.goodHealth, OtherModes.evilHealth, currentReward), user, !isWhisper); } else { IRCConnection.SendMessage(string.Format(TwitchPlaySettings.data.BombStatus, bomb.GetFullFormattedTime, bomb.GetFullStartingTime, bomb.StrikeCount, bomb.StrikeLimit, bomb.BombSolvedModules, bomb.BombSolvableModules, currentReward), user, !isWhisper); } }
public static void Assign(TwitchModule module, string user, [Group(1)] string targetUser) { if (TwitchPlaySettings.data.AnarchyMode) { IRCConnection.SendMessageFormat("Sorry {0}, assigning modules is not allowed in anarchy mode.", user); return; } if (module.TakeInProgress != null) { module.StopCoroutine(module.TakeInProgress); module.TakeInProgress = null; } module.PlayerName = targetUser; module.RemoveFromClaimQueue(user); module.CanClaimNow(user, true, true); module.SetBannerColor(module.ClaimedBackgroundColour); IRCConnection.SendMessageFormat(TwitchPlaySettings.data.AssignModule, module.Code, module.PlayerName, user, module.HeaderText); }
public void StartServer() { listener.Start(); connection = new IRCConnection("localhost", 6667); serverSideClient = listener.AcceptTcpClient(); }