Esempio n. 1
0
        KSPIRC()
        {
            instance = this;

            GameObject.DontDestroyOnLoad(this);

            version = this.GetType().Assembly.GetName().Version.ToString();

            config = new IRCConfig();

            configWindow = new IRCConfigWindow(version, config);
            configWindow.configChangedEvent += configChanged;

            linkWindow        = new IRCLinkWindow(config);
            linkWindow.hidden = true;

            chatWindow = new IRCChatWindow(linkWindow, version, config);
            chatWindow.channelClosedEvent   += channelClosed;
            chatWindow.onUserCommandEntered += (e) => handleUserCommand(e.command);
            chatWindow.onShowConfigHandler  += showConfig;
            chatWindow.hidden = IRC_WINDOW_HIDDEN;

            initCommandHandlers();
            initUserCommandHandlers();

            client = new IRCClient();
            client.onCommandReceived            += (e) => handleServerCommand(e.command);
            client.onCommandSent                += (e) => logSendCommand(e.command);
            client.onConnect                    += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Connecting to server " + config.host + ":" + config.port + "...");
            client.onConnected                  += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Server connection established.");
            client.onSSLConnected               += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "SSL Server connection established.");
            client.onDisconnected               += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Disconnected from server.");
            client.onConnectionFailed           += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Connection failed to server.");
            client.onConnectionAttemptsExceeded += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Connection attempts exceeded. Change config before retrying.");
            client.onSSLCertificateError        += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "SSL Certificate error - use this server at your own risk.");

            if ((config.host != null) && (config.port > 0) && (config.nick != ""))
            {
                Debug.Log("Connecting to: " + config.host + ":" + config.port);
                configWindow.hidden = true;
                client.connect(config);
            }
            else
            {
                configWindow.hidden = false;
                chatWindow.addToChannel("IRC Plugin", "*", "IRC plugin not configured, not connecting to IRC server.");
                chatWindow.addToChannel("IRC Plugin", "*", "Edit config and confirm updates to connect.");
            }

            if (ToolbarManager.ToolbarAvailable)
            {
                windowButton             = ToolbarManager.Instance.add("irc", "irc");
                windowButton.TexturePath = "KSPIRC/button-regular";
                windowButton.ToolTip     = "IRC";
                windowButton.Visibility  = new GameScenesVisibility(GameScenes.CREDITS,
                                                                    GameScenes.EDITOR,
                                                                    GameScenes.FLIGHT,
                                                                    GameScenes.LOADING,
                                                                    GameScenes.LOADINGBUFFER,
                                                                    GameScenes.MAINMENU,
                                                                    GameScenes.PSYSTEM,
                                                                    GameScenes.SPACECENTER,
                                                                    GameScenes.TRACKSTATION);
                windowButton.OnClick += (e) => toggleChatWindow();
            }
            else
            {
                ApplicationLauncher.AppScenes scenes = ApplicationLauncher.AppScenes.ALWAYS;

                Texture toolbarButtonTexture = (Texture)GameDatabase.Instance.GetTexture("KSPIRC/button-regular", false);
                appLauncherButton = ApplicationLauncher.Instance.AddModApplication(onAppLaunchToggleOn,
                                                                                   onAppLaunchToggleOff,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   scenes,
                                                                                   toolbarButtonTexture);
            }
        }
Esempio n. 2
0
 private void logSendCommand(IRCCommand cmd)
 {
     if (config.debug)
     {
         chatWindow.addToChannel(DEBUG_CHANNEL_HANDLE, "CLIENT", cmd.ToString());
     }
 }