restart

06/28/2010 00:25 daniel7851109#1
how can i make my server auto restart i already tried i made and effort

Code:
public static void RSSTART()
        {
            MyThread CompanionThread = new MyThread();
            CompanionThread.Execute += new Execute(CompanionThread_Execute);
            CompanionThread.Start(100);
            MyThread ServerStuff = new MyThread();
            ServerStuff.Execute += new Execute(ServerStuff_Execute);
            ServerStuff.Start(100);
            MyThread MobThread = new MyThread();
            MobThread.Execute += new Execute(MobThread_Execute);
            MobThread.Start(100);
            World.MobsStart = true;
            Game.Character[] BaseCharacters = new Character[World.H_Chars.Count];
            World.H_Chars.Values.CopyTo(BaseCharacters, 0);

            NewestCOServer.Main.AuthWorker.Listener.Close();
            NewestCOServer.Main.GameWorker.Listener.Close();
            EndSession = true;
            try
            {
                foreach (Game.Character C in BaseCharacters)
                {
                    try
                    {
                        if (C.Loc.Map == 1021)
                        {
                            C.Teleport(1021, 50, 50);
                            C.MyClient.Disconnect();
                            Console.WriteLine(C.Name + " has logged off successfuly.");
                        }
                        else
                        {
                            C.Teleport(1002, 400, 400);
                            C.MyClient.Disconnect();
                            Console.WriteLine(C.Name + " has logged off successfuly.");
                        }
                    }
                    catch { continue; }
                }
            }
            catch { }
            Database.SaveKOs();
            Console.WriteLine("KOs saved.");
            Database.SaveEmpire();
            Console.WriteLine("Empire saved.");
            Features.Guilds.SaveGuilds();
            Console.WriteLine("Guilds saved.");
            Features.SkillsClass.Save();
            Console.WriteLine("Skills saved.");

            MobThread.Close();
            ServerStuff.Close();
            CompanionThread.Close();
            Database.Dispose();
            Console.WriteLine("Database disposed.");
            System.Diagnostics.Process.Start("CoSX.exe");
            Environment.Exit(0);
        }

Now open mythread.cs
find:
            interval = Interval;
            T = new Thread(new ThreadStart(Run));
            T.Start();

under it put:
System.Timers.Timer RSTimer = new System.Timers.Timer(1000.0);
                RSTimer.Start();
                RSTimer.Elapsed += delegate { RStart(); };
                System.Timers.Timer ARSTimer = new System.Timers.Timer(1000.0);
                ARSTimer.Start();
                ARSTimer.Elapsed += delegate { ARStart(); };
                System.Timers.Timer BRSTimer = new System.Timers.Timer(1000.0);
                BRSTimer.Start();
                BRSTimer.Elapsed += delegate { BRStart(); };
                System.Timers.Timer CRSTimer = new System.Timers.Timer(1000.0);
                CRSTimer.Start();
                CRSTimer.Elapsed += delegate { CRStart(); };
                System.Timers.Timer GWTimer = new System.Timers.Timer(1000.0);
                GWTimer.Start();

Now any place in the mythread.cs put:
        public static bool RSend = false;
        public static bool ARSend = false;
        public static bool BRSend = false;
        public static bool CRSend = false;
        public static bool DRSend = false;
        public static bool ERSend = false;
        public static bool RESTARTEREN = false;

under that u putted put:
        private static void CTFBCast(string msg)
        {
            foreach (Character Char in World.H_Chars.Values)
            {
                Char.MyClient.AddSend(Packets.ChatMessage(0, "[CTF]", "All", msg, 2011, 0));
                Char.MyClient.EndSend();
            }
        }
        public static void RStart()
        {
            if (DateTime.Now.Minute == 02 && RSend == false && DateTime.Now.Hour == 03 || DateTime.Now.Minute == 02 && RSend == false && DateTime.Now.Hour == 15 || DateTime.Now.Minute == 02 && RSend == false && DateTime.Now.Hour == 09 || DateTime.Now.Minute == 02 && RSend == false && DateTime.Now.Hour == 21)
            {
                CTFBCast("[AUTORESTART]Server Restart in 3Minutes.");
                RSend = true;
            }
        }
        public static void ARStart()
        {
            if (DateTime.Now.Minute == 03 && ARSend == false && DateTime.Now.Hour == 03 || DateTime.Now.Minute == 03 && ARSend == false && DateTime.Now.Hour == 15 || DateTime.Now.Minute == 03 && ARSend == false && DateTime.Now.Hour == 09 || DateTime.Now.Minute == 03 && ARSend == false && DateTime.Now.Hour == 21)
            {
                CTFBCast("[AUTORESTART]Server Restart in 2Minutes.");
                ARSend = true;
            }
        }
        public static void BRStart()
        {
            if (DateTime.Now.Minute == 04 && DateTime.Now.Hour == 03 && BRSend == false || DateTime.Now.Minute == 04 && DateTime.Now.Hour == 15 && BRSend == false || DateTime.Now.Minute == 04 && DateTime.Now.Hour == 09 && BRSend == false || DateTime.Now.Minute == 04 && DateTime.Now.Hour == 21 && BRSend == false)
            {
                CTFBCast("[AUTORESTART]Server Restart in 1Minute.");
                BRSend = true;
            }
        }
        public static void CRStart()
        {
            if (DateTime.Now.Minute == 05 && DateTime.Now.Hour == 03 && RESTARTEREN == false || DateTime.Now.Minute == 05 && DateTime.Now.Hour == 15 && RESTARTEREN == false || DateTime.Now.Minute == 05 && DateTime.Now.Hour == 09 && RESTARTEREN == false || DateTime.Now.Minute == 05 && DateTime.Now.Hour == 21 && RESTARTEREN == false)
            {
                RESTARTEREN = true;
                CTFBCast("[AUTORESTART]Restart have started. All things will be closed in 120 Seconds. Restart takes 2-5Minutes.");
                Thread.Sleep(120000);
                Program.RSSTART();
            }
        }
        public static void RRRStart()
        {
                RESTARTEREN = true;
                CTFBCast("Restart have started. All things will be closed in 65 Seconds. The server thread will sleep untill. Restart takes 2-5Minutes.");
                Thread.Sleep(65000);
                Program.RSSTART();
        }
06/28/2010 00:52 pro4never#2
Umm well ideallly i'd do a seperate program so you can reopen the program after.


What i would do is write a BASIC connection system. Have the new restarter program connect to the mmain server whenever you want the restart code to run. Then in gserver have the connection code for on client connect to save everything, disconect ppll (maybe warn them too) and then close the server.

Restarter side, confirmm it's been closed (by attempting a connection to it) and then either

A: if closed, start it up again

B: if not closed (con responds and or proc shows in list of running processes) force a close (no save remember so be generous with your times) and then restart it after.


It's not a big project to code but something you may want to research just a tad first so you do it properly.

i'd suggest googling sockets in c# (sync would mae sense) and some on closing/finding running processes and launching programs. It's all quite basic though.