public void Connect() { if (!gameObject.activeInHierarchy) { return; } if (!File.Exists(_ircConnectionSettings.SettingsPath)) { AddTextToHoldable("The settings file does not exist. Trying to create it now."); try { File.WriteAllText(_ircConnectionSettings.SettingsPath, JsonConvert.SerializeObject(new TwitchPlaysService.ModSettingsJSON(), Formatting.Indented)); AddTextToHoldable("Settings file successfully created. Configure it now. Open up the Mod manager holdable, and select Open mod settins folder."); } catch (Exception ex) { AddTextToHoldable(ex, "Settings file did not exist and could not be created:"); } return; } try { _settings = JsonConvert.DeserializeObject <TwitchPlaysService.ModSettingsJSON>(File.ReadAllText(_ircConnectionSettings.SettingsPath)); if (_settings == null) { AddTextToHoldable("[IRC:Connect] Failed to read connection settings from mod settings."); return; } UserNickName = _settings.userName.Replace("#", ""); ChannelName = _settings.channelName.Replace("#", ""); _settings.authToken = _settings.authToken.ToLowerInvariant(); _settings.channelName = ChannelName.ToLowerInvariant(); _settings.userName = UserNickName.ToLowerInvariant(); _settings.serverName = _settings.serverName.ToLowerInvariant(); if (!IsAuthTokenValid(_settings.authToken) || !IsUsernameValid(_settings.channelName) || !IsUsernameValid(_settings.userName) || string.IsNullOrEmpty(_settings.serverName) || _settings.serverPort < 1 || _settings.serverPort > 65535) { AddTextToHoldable("[IRC:Connect] Your settings file is not configured correctly.\nThe following items need to be configured:\n"); if (!IsAuthTokenValid(_settings.authToken)) { AddTextToHoldable("AuthToken - Be sure oauth: is included.\n- Retrieve from https://twitchapps.com/tmi/"); } if (!IsUsernameValid(_settings.userName)) { AddTextToHoldable("userName"); } if (!IsUsernameValid(_settings.channelName)) { AddTextToHoldable("channelName"); } if (string.IsNullOrEmpty(_settings.serverName)) { AddTextToHoldable("serverName - Most likely to be irc.twitch.tv"); } if (_settings.serverPort < 1 || _settings.serverPort > 65535) { AddTextToHoldable("serverPort - Most likely to be 6667"); } AddTextToHoldable("\nOpen up the Mod manager holdable, and select Open mod settins folder."); return; } } catch (Exception ex) { AddTextToHoldable(ex, "[IRC:Connect] Failed to read connection settings from mod settings due to an exception:"); return; } _keepConnnectionAlive = KeepConnectionAlive(); StartCoroutine(_keepConnnectionAlive); }