コード例 #1
0
ファイル: MySQLConnector.cs プロジェクト: SysVoid/Talky
        public static MySqlConnection GetConnection()
        {
            MySqlConnection connection;

            try
            {
                Dictionary<string, string> defaults = new Dictionary<string, string>();
                defaults.Add("connectionString", "datasource=localhost;port=3306;username=talky;password=talky;");
                defaults.Add("database", "talky");

                ConfigurationFile config = new ConfigurationFile("database");
                if (!config.Exists())
                {
                    config.Write(defaults);
                }

                string connectionString;
                string db;
                config.Values(defaults).TryGetValue("connectionString", out connectionString);
                config.Values(defaults).TryGetValue("database", out db);

                connection = new MySqlConnection(connectionString);
                connection.Open();
                connection.ChangeDatabase(db);

                return connection;
            } catch (MySqlException e)
            {
                Program.Instance.OHGODNO("Terminate!! Could not connect to MySQL!! Danger!! Danger!!", e);
                return null;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: SysVoid/Talky
        private Program(int port)
        {
            Instance = this;
            Port = port;

            Dictionary<string, string> defaults = new Dictionary<string, string>();
            defaults.Add("+lobby", "true,false");
            defaults.Add("+admins", "false,true");

            ConfigurationFile config = new ConfigurationFile("channels");
            if (!config.Exists())
            {
                config.Write(defaults);
            }

            IReadOnlyDictionary<string, string> channels = config.Values();

            foreach (string key in channels.Keys)
            {
                string channelName = key;
                if (!channelName.StartsWith("+"))
                {
                    channelName = "+" + channelName;
                }

                string settings;
                string[] splitSettings;
                channels.TryGetValue(key, out settings);
                splitSettings = settings.Split(new char[] { ',' }, 2);

                if (splitSettings.Length != 2)
                {
                    continue;
                }

                bool lobby = (splitSettings[0].Equals("true") ? true : false);
                bool locked = (splitSettings[1].Equals("true") ? true : false);

                if (lobby && _channelRepository.GetLobby() != null)
                {
                    continue;
                }

                if (_channelRepository.Get(channelName) != null)
                {
                    continue;
                }

                if (lobby)
                {
                    _channelRepository.Store(new LobbyChannel(channelName));
                } else
                {
                    _channelRepository.Store(new SystemChannel(channelName, locked));
                }
            }

            try
            {
                _commandManager.RegisterCommand(new CommandHelp());
                _commandManager.RegisterCommand(new CommandName());
                _commandManager.RegisterCommand(new CommandJoin());
                _commandManager.RegisterCommand(new CommandClist());
                _commandManager.RegisterCommand(new CommandCC());
                _commandManager.RegisterCommand(new CommandAuth());
                _commandManager.RegisterCommand(new CommandRegister());
                _commandManager.RegisterCommand(new CommandRole());
                _commandManager.RegisterCommand(new CommandKick());
                _commandManager.RegisterCommand(new CommandMute());
                _commandManager.RegisterCommand(new CommandChangePassword());
                _commandManager.RegisterCommand(new CommandMsg());
            } catch (CommandExistsException cEE)
            {
                Console.WriteLine(cEE.StackTrace);
                return;
            }

            Thread listenerThread = new Thread(new ThreadStart(ListenForClients));
            listenerThread.Start();

            Thread consoleThread = new Thread(new ThreadStart(ShowConsole));
            consoleThread.Start();

            Thread channelManagerThread = new Thread(new ThreadStart(MonitorChannels));
            channelManagerThread.Start();

            Thread activityMonitorThread = new Thread(new ThreadStart(MonitorActivity));
            activityMonitorThread.Start();
        }