/// <summary> /// Method to set the <see cref="mConnectionString"/> and <see cref="mConnection"/> /// <para>Also, the Connection will be Opened and Closed afterwards</para> /// </summary> public MysqlError Prepare() { MysqlError result = MysqlError.None; mConnectionString = String.Format("SERVER={0};PORT={1};UID={2};PASSWORD={3};DATABASE={4};", mServer, mPort, mUser, mPassword, mDatabase); mConnection = new MySqlConnection(mConnectionString); result = Open(); if (result == MysqlError.None) { result = Close(false); } return(result); }
public static bool Initialize() { MysqlError result = Mysql.Init(mConnectionHolder); switch (result) { case MysqlError.None: // all okay return(true); case MysqlError.OpenBeforeInit: case MysqlError.CanNotConnectToDB: case MysqlError.FailedToOpen: case MysqlError.UnknownOpen: case MysqlError.CloseBeforeInit: case MysqlError.CanNotDisconnectFromDB: case MysqlError.FailedToClose: case MysqlError.UnknownClose: default: return(false); } }
private int InitSql() { if (IsSqlInit == true) { return(1); } MySql = new MySqlWrapper("blubb-gaming.de", 3306, "shaiya_forum", "alone4ever", "shaiya_forum"); MysqlError error = MySql.Prepare(); switch (error) { case MysqlError.None: break; default: System.Diagnostics.Debug.WriteLine("SqlInit Fehler: " + error); System.Windows.Forms.MessageBox.Show("SqlInit Fehler!\n\n" + error); return(-1); } ResultTable table = MySql.Query("SELECT userID FROM wcf1_user WHERE username = '******' AND password = '******'", ForumUsername.MysqlEscape(), this.GetForumPass(ForumUsername, ForumPassword).MysqlEscape()); if (table.Rows.Count == 0) { return(0); } if (MySql.LastError != null) { System.Diagnostics.Debug.WriteLine(MySql.LastError); System.Windows.Forms.MessageBox.Show("SQL Fehler!\n\n" + MySql.LastError); return(-1); } ForumUserID = table.Rows[0]["userID"].GetInt32(); IsSqlInit = true; return(1); }
public static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); #endif AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); try { mThread = Thread.CurrentThread; mProcess = Process.GetCurrentProcess(); mAssembly = Assembly.GetEntryAssembly(); if (mThread != null) { mThread.Name = "Core Thread"; } Timer.TimerThread ttObj = new Timer.TimerThread(); mTimerThread = new Thread(new ThreadStart(ttObj.TimerMain)); mTimerThread.Name = "Timer Thread"; int width = Math.Min(100, Console.LargestWindowWidth - 2); Console.CursorVisible = false; Console.Clear(); Console.WindowLeft = Console.WindowTop = 0; if (Console.WindowWidth < width) { Console.WindowWidth = width; } LogoPrinter.PrefixColor = EConsoleColor.Blue; LogoPrinter.SufixColor = EConsoleColor.Blue; LogoPrinter.TextColor = EConsoleColor.Gray; LogoPrinter.PrintLogo(); Version ver = mAssembly.GetName().Version; CConsole.StatusLine("Shaiya.Extended Server - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); mConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent); SetConsoleCtrlHandler(mConsoleEventHandler, true); mAppConf = new ApplicationSettings(); mAppConf.ReadAll(); Stopwatch watch = Stopwatch.StartNew(); CConsole.Info("Connecting to SQL Server {0}...", mAppConf.Network["DB Server"]); mDatabase = new MySqlWrapper(mAppConf.Network["DB Server"], int.Parse(mAppConf.Network["DB Port"]), mAppConf.Network["DB User"], mAppConf.Network["DB Password"], mAppConf.Network["DB Database"]); MysqlError conRes = mDatabase.Prepare(); if (conRes != MysqlError.None) { CConsole.WriteLine(EConsoleColor.Error, " failed!"); throw new Exception("Failed to open Database Connection! Type: " + conRes.ToString()); } watch.Stop(); CConsole.WriteLine(EConsoleColor.Status, " done! Needed {0:F2} sec", watch.Elapsed.TotalSeconds); watch = null; ScriptDatabase.Initialize(@"Scripts\ScriptList.xml"); ScriptCompiler.Compile(AppDomain.CurrentDomain.BaseDirectory + Path.Combine(Settings.Default.MainConfDir, Settings.Default.ScriptAssemblies), true, true); World.Load(); // testing CallMethod ScriptCompiler.CallMethod("Initialize"); SocketPool.Create(); mSocketConnector = new SocketConnector(mAppConf.Network["Server IP"], mAppConf.Network.GetInt("Server Port")); PacketHandlers.Initialize(); // start Timer Thread mTimerThread.Start(); NetState.Initialize(); // finished Loading Events.InvokeServerStarted(); DateTime now, last = DateTime.Now; const int sampleInterval = 100; const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval); int sample = 0; while (mSignal.WaitOne()) { Timer.Slice(); mSocketConnector.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if (Slice != null) { Slice(); } // just for Diagnostics if ((++sample % sampleInterval) == 0) { now = DateTime.Now; mCyclesPerSecond[mCycleIndex++ % mCyclesPerSecond.Length] = ticksPerSecond / (now.Ticks - last.Ticks); last = now; } } } catch (Exception e) { CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true)); } }