Beispiel #1
0
        private void IsConnect()
        {
            try
            {
                if (!Connection.Ping())
                {
                    Connection.Open();
                }

                if (Connection.State == ConnectionState.Broken || Connection.State == ConnectionState.Closed)
                {
                    _crash = true;
                    Log.Error("MySql", sLConsole.GetString("Sql connection crash."));
                    Log.Warning("MySql", sLConsole.GetString("Program shutting down!"));
                    SchumixBase.Quit(false);

                    foreach (var nw in INetwork.WriterList)
                    {
                        if (!nw.Value.IsNull())
                        {
                            nw.Value.WriteLine("QUIT :Sql connection crash.");
                        }
                    }

                    Thread.Sleep(1000);
                    sRuntime.Exit();
                }
            }
            catch (MySqlException m)
            {
                Crash(m, true, true);
            }
        }
Beispiel #2
0
 public SQLite(string file)
 {
     if (!Initialize(file))
     {
         Log.Error("SQLite", sLConsole.GetString("Error was handled when tried to connect to the database!"));
         SchumixBase.ServerDisconnect(false);
         Thread.Sleep(1000);
         sRuntime.Exit();
     }
     else
     {
         Log.Notice("SQLite", sLConsole.GetString("Successfully connected to the SQLite database."));
     }
 }
Beispiel #3
0
 public MySql(string host, int port, string username, string password, string database, string charset)
 {
     if (!Initialize(host, port, username, password, database, charset))
     {
         Log.Error("MySql", sLConsole.GetString("Error was handled when tried to connect to the database!"));
         SchumixBase.ServerDisconnect(false);
         Thread.Sleep(1000);
         sRuntime.Exit();
     }
     else
     {
         Log.Success("MySql", sLConsole.GetString("Successfully connected to the MySql database."));
     }
 }
Beispiel #4
0
        /// <summary>
        ///     Quit parancs függvénye.
        /// </summary>
        protected void HandleQuit(ConsoleMessage sConsoleMessage)
        {
            var text = sLManager.GetConsoleCommandTexts("quit");

            if (text.Length < 2)
            {
                Log.Error("Console", sLConsole.Translations("NoFound2"));
                return;
            }

            Log.Notice("Console", text[0]);
            SchumixBase.Quit();
            sIrcBase.Shutdown(text[1]);
        }
Beispiel #5
0
        /// <summary>
        /// Start listening.
        /// </summary>
        public void Socket()
        {
            Log.Notice("ClientSocket", sLConsole.GetString("Successfully started the ClientSocket."));
            Log.Notice("ClientSocket", sLConsole.GetString("Client connection from: {0}"), client.Client.RemoteEndPoint);
            var client_thread = new Thread(new ParameterizedThreadStart(ClientHandler));

            client_thread.Start(client);
            Thread.Sleep(50);

            var packet = new SchumixPacket();

            packet.Write <int>((int)Opcode.CMSG_REQUEST_AUTH);
            packet.Write <string>(SchumixBase.GetGuid().ToString());
            packet.Write <string>(sUtilities.Md5(_password));
            packet.Write <string>(SchumixBase.ServerIdentify);
            SendPacketToSCS(packet);
        }
Beispiel #6
0
        protected void HandleQuit(IRCMessage sIRCMessage)
        {
            if (!IsAdmin(sIRCMessage.Nick, sIRCMessage.Host, AdminFlag.Administrator))
            {
                return;
            }

            var text = sLManager.GetCommandTexts("quit", sIRCMessage.Channel, sIRCMessage.ServerName);

            if (text.Length < 2)
            {
                sSendMessage.SendChatMessage(sIRCMessage, sLConsole.Translations("NoFound2", sLManager.GetChannelLocalization(sIRCMessage.Channel, sIRCMessage.ServerName)));
                return;
            }

            sSendMessage.SendChatMessage(sIRCMessage, text[0]);
            SchumixBase.Quit();
            sIrcBase.Shutdown(string.Format(text[1], sIRCMessage.Nick));
        }
Beispiel #7
0
        /// <summary>
        ///     Indulási függvény.
        /// </summary>
        public SchumixBot()
        {
            try
            {
                Log.Notice("SchumixBot", sLConsole.GetString("Successfully started SchumixBot."));
                Log.Debug("SchumixBot", sLConsole.GetString("Network starting..."));

                string eserver = sIrcBase.FirstStart();
                sSchumixBase = new SchumixBase();
                sIrcBase.Start(eserver);

                Log.Debug("SchumixBot", sLConsole.GetString("Console starting..."));
                new ScriptManager(ScriptsConfig.Directory);
                new Console.Console(eserver);
            }
            catch (Exception e)
            {
                Log.Error("SchumixBot", sLConsole.GetString("Failure details: {0}"), e.Message);
            }
        }
        private void CloseHandler(SchumixPacket pck, string hst)
        {
            if (SchumixBase.ExitStatus)
            {
                return;
            }

            Log.Warning("CloseHandler", sLConsole.GetString("Connection closed!"));
            Log.Warning("CloseHandler", sLConsole.GetString("Program shutting down!"));
            SchumixBase.Quit();

            foreach (var nw in INetwork.WriterList)
            {
                if (!nw.Value.IsNull())
                {
                    nw.Value.WriteLine("QUIT :Server killed.");
                }
            }

            Thread.Sleep(1000);
            sRuntime.Exit();
        }
Beispiel #9
0
        public DatabaseManager()
        {
            byte x = 0;

            Log.Debug("DatabaseManager", sLConsole.GetString("Started the database loading."));

            if (SQLiteConfig.Enabled)
            {
                x++;
                sdatabase = new SQLite(SQLiteConfig.FileName);
            }

            if (MySqlConfig.Enabled)
            {
                x++;
                mdatabase = new MySql(MySqlConfig.Host, MySqlConfig.Port, MySqlConfig.User, MySqlConfig.Password, MySqlConfig.Database, MySqlConfig.Charset);
            }

            Log.Debug("DatabaseManager", sLConsole.GetString("Selecting the Database."));

            if (x == 0)
            {
                Log.LargeError(sLConsole.GetString("MAJOR ERROR"));
                Log.Error("DatabaseManager", sLConsole.GetString("Database type's is not selected!"));
                SchumixBase.ServerDisconnect(false);
                Thread.Sleep(1000);
                Environment.Exit(1);
            }
            else if (x == 2)
            {
                Log.LargeError(sLConsole.GetString("MAJOR ERROR"));
                Log.Error("DatabaseManager", sLConsole.GetString("2 Database are selected!"));
                SchumixBase.ServerDisconnect(false);
                Thread.Sleep(1000);
                Environment.Exit(1);
            }
        }
Beispiel #10
0
        public static void Shutdown(string Message, bool Crash = false)
        {
            System.Console.CursorVisible = true;

            if (!SchumixBot.sSchumixBase.IsNull())
            {
                bool e = false;
                foreach (var nw in sIrcBase.Networks)
                {
                    if (!sIrcBase.Networks[nw.Key].IsNull() && sIrcBase.Networks[nw.Key].Online)
                    {
                        e = true;
                    }
                }

                if (e)
                {
                    SchumixBase.Quit();
                }
                else
                {
                    sRuntime.Exit();
                }
            }
            else
            {
                sRuntime.Exit();
            }

            if (Crash && SchumixBase.ExitStatus)
            {
                return;
            }

            sIrcBase.Shutdown(Message);
        }
Beispiel #11
0
        private void Crash(SQLiteException s, bool logerror, bool c = false)
        {
            if (c)
            {
                _crash = true;
                Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message);
                Log.Warning("SQLite", sLConsole.GetString("Program shutting down!"));
                SchumixBase.Quit(false);

                foreach (var nw in INetwork.WriterList)
                {
                    if (!nw.Value.IsNull())
                    {
                        nw.Value.WriteLine("QUIT :Sql connection crash.");
                    }
                }

                Thread.Sleep(1000);
                sRuntime.Exit();
            }

            if (s.Message.Contains("Fatal error encountered during command execution."))
            {
                _crash = true;
                Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message);
                Log.Warning("SQLite", sLConsole.GetString("Program shutting down!"));
                SchumixBase.Quit(false);

                foreach (var nw in INetwork.WriterList)
                {
                    if (!nw.Value.IsNull())
                    {
                        nw.Value.WriteLine("QUIT :Sql connection crash.");
                    }
                }

                Thread.Sleep(1000);
                sRuntime.Exit();
            }

            if (s.Message.Contains("Timeout expired."))
            {
                _crash = true;
                Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message);
                Log.Warning("SQLite", sLConsole.GetString("Program shutting down!"));
                SchumixBase.Quit(false);

                foreach (var nw in INetwork.WriterList)
                {
                    if (!nw.Value.IsNull())
                    {
                        nw.Value.WriteLine("QUIT :Sql connection timeout.");
                    }
                }

                Thread.Sleep(1000);
                sRuntime.Exit();
            }

            if (logerror)
            {
                Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message);
            }
        }