public static void Start(IPAddress bind)
 {
     ServerListReport   = new ServerListReport(bind, 27900);
     ServerListRetrieve = new ServerListRetrieve(bind, 28910);
     LoginMasterServer  = new LoginServerRetranslator(bind, 29900, 29901);
     ChatServer         = new ChatServerRetranslator(bind, 6667);
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Action <string, string> log = (category, message) => {
                lock (_lock) {
                    Log(String.Format("[{0}] {1}", category, message));
                }
            };

            Action <string, string> logError = (category, message) => {
                lock (_lock) {
                    LogError(String.Format("[{0}] {1}", category, message));
                }
            };

            IPAddress bind = IPAddress.Any;

            if (args.Length >= 1)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].Equals("+bind"))
                    {
                        if ((i >= args.Length - 1) || !IPAddress.TryParse(args[i + 1], out bind))
                        {
                            LogError("+bind value must be a valid IP Address to bind to!");
                        }
                    }
                    else if (args[i].Equals("+db"))
                    {
                        if ((i >= args.Length - 1))
                        {
                            LogError("+db value must be a path to the database");
                        }
                        else
                        {
                            LoginDatabase.Initialize(args[i + 1], log, logError);
                        }
                    }
                }
            }

            if (!LoginDatabase.IsInitialized())
            {
                LogError("Error initializing database, please confirm parameter +db is valid");
                LogError("Press any key to continue");
                Console.ReadKey();
                return;
            }

            CDKeyServer        cdKeyServer        = new CDKeyServer(bind, 29910, log, logError);
            ServerListReport   serverListReport   = new ServerListReport(bind, 27900, log, logError);
            ServerListRetrieve serverListRetrieve = new ServerListRetrieve(bind, 28910, serverListReport, log, logError);
            LoginServer        loginServer        = new LoginServer(bind, 29900, 29901, log, logError);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
        public static void Stop()
        {
            try
            {
                ServerListReport?.Dispose();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            finally
            {
                ServerListReport = null;
            }

            try
            {
                ServerListRetrieve?.Dispose();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            finally
            {
                ServerListRetrieve = null;
            }

            try
            {
                LoginMasterServer?.Dispose();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            finally
            {
                LoginMasterServer = null;
            }

            try
            {
                ChatServer?.Dispose();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            finally
            {
                ChatServer = null;
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Action <string, string> log = (category, message) => {
                lock (_lock) {
                    Log(String.Format("[{0}] {1}", category, message));
                }
            };

            Action <string, string> logError = (category, message) => {
                lock (_lock) {
                    LogError(String.Format("[{0}] {1}", category, message));
                }
            };

            bool   runLoginServer  = true;
            bool   runNatNegServer = true;
            bool   runCdKeyServer  = false;
            bool   runMasterServer = true;
            bool   runListServer   = true;
            string gameName        = null;

            IPAddress bind = IPAddress.Any;

            if (args.Length >= 1)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].Equals("+bind"))
                    {
                        if ((i >= args.Length - 1) || !IPAddress.TryParse(args[i + 1], out bind))
                        {
                            LogError("+bind value must be a valid IP Address to bind to!");
                        }
                    }
                    else if (args[i].Equals("+db"))
                    {
                        if ((i >= args.Length - 1))
                        {
                            LogError("+db value must be a path to the database");
                        }
                        else
                        {
                            LoginDatabase.Initialize(args[i + 1], log, logError);
                        }
                    }
                    else if (args[i].Equals("+game"))
                    {
                        if ((i >= args.Length - 1))
                        {
                            //gameName = "civ4bts";
                            Log("supported games: civ4, civ4bts, civ4btsjp");
                        }
                        else
                        {
                            gameName = args[i + 1];
                        }
                    }
                    else if (args[i].Equals("+servers"))
                    {
                        if ((i >= args.Length - 1))
                        {
                            LogError("+servers value must be a comma-separated list of server types (master,login,cdkey,list,natneg)");
                        }
                        else
                        {
                            List <string> serverTypes = args[i + 1].Split(char.Parse(",")).Select(s => { return(s.Trim().ToLower()); }).ToList();
                            runLoginServer  = serverTypes.IndexOf("login") >= 0;
                            runNatNegServer = serverTypes.IndexOf("natneg") >= 0;
                            runListServer   = serverTypes.IndexOf("list") >= 0;
                            runMasterServer = serverTypes.IndexOf("master") >= 0;
                            runCdKeyServer  = serverTypes.IndexOf("cdkey") >= 0;
                        }
                    }
                }
            }

            if (runLoginServer && !LoginDatabase.IsInitialized())
            {
                LogError("Error initializing login database, please confirm parameter +db is valid");
                LogError("Press any key to continue");
                Console.ReadKey();
                return;
            }

            if (runCdKeyServer)
            {
                CDKeyServer serverCdKey = new CDKeyServer(bind, 29910, log, logError);
            }
            ServerListRetrieve serverListRetrieve = null;

            if (runMasterServer)
            {
                ServerListReport serverListReport = new ServerListReport(bind, 27900, log, logError, gameName);
                if (runListServer)
                {
                    serverListRetrieve = new ServerListRetrieve(bind, 28910, serverListReport, log, logError);
                }
            }
            ServerNatNeg serverNatNeg = null;

            if (runNatNegServer)
            {
                serverNatNeg = new ServerNatNeg(bind, 27901, log, logError);
            }
            if (runLoginServer)
            {
                LoginServer serverLogin = new LoginServer(bind, 29900, 29901, log, logError);
            }

            while (true)
            {
//*
                string command = Console.ReadLine();

                Log("Executing command: " + command);
                if (command == "/nndclear" && serverNatNeg != null)
                {
                    serverNatNeg.clientsClear(true);
                }
                else if (command == "/nndshow" && serverNatNeg != null)
                {
                    serverNatNeg.clientsClear(false);
                }
                else if (command == "/list" && serverListRetrieve != null)
                {
                    serverListRetrieve.printSLinfo();
                }
                else if (command == "/quit")
                {
                    Log("Good bye");
                    serverListRetrieve.Dispose();

                    Environment.Exit(0);
                }
                else
                {
                    Log("Unknown command");
                }
                //*/

                /*
                 * ConsoleKeyInfo cki = Console.ReadKey(false);
                 * Console.Write("You pressed ");
                 * if ((cki.Modifiers & ConsoleModifiers.Alt) != 0) Console.Write("ALT+");
                 * if ((cki.Modifiers & ConsoleModifiers.Shift) != 0) Console.Write("SHIFT+");
                 * if ((cki.Modifiers & ConsoleModifiers.Control) != 0) Console.Write("CTL+");
                 * Console.WriteLine("{0} (character '{1}')", cki.Key, cki.KeyChar);
                 */
                Thread.Sleep(1000);
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Action <string, string> log = (category, message) => {
                lock (_lock) {
                    Log(String.Format("[{0}] {1}", category, message));
                }
            };

            Action <string, string> logError = (category, message) => {
                lock (_lock) {
                    LogError(String.Format("[{0}] {1}", category, message));
                }
            };

            Action <string, string> logGreen = (category, message) =>
            {
                lock (_lock)
                {
                    LogGreen(String.Format("[{0}] {1}", category, message));
                }
            };
            Action <string, string> logBlue = (category, message) =>
            {
                lock (_lock)
                {
                    LogBlue(String.Format("[{0}] {1}", category, message));
                }
            };

            bool runLoginServer  = true;
            bool runNatNegServer = true;
            bool runCdKeyServer  = false;
            bool runMasterServer = true;
            bool runListServer   = true;

            LogGreen("Use /help command to get server's attention");

            IPAddress bind = IPAddress.Any;

            if (args.Length >= 1)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].Equals("+bind"))
                    {
                        if ((i >= args.Length - 1) || !IPAddress.TryParse(args[i + 1], out bind))
                        {
                            LogError("+bind value must be a valid IP Address to bind to!");
                        }
                    }
                    else if (args[i].Equals("+db"))
                    {
                        if ((i >= args.Length - 1))
                        {
                            LogError("+db value must be a path to the database");
                        }
                        else
                        {
                            LoginDatabase.Initialize(args[i + 1], log, logError);
                        }
                    }
                    else if (args[i].Equals("+game"))
                    {
                        if ((i >= args.Length - 1))
                        {
                            //gameName = "civ4bts";
                            //Log("supported games: civ4, civ4bts, civ4btsjp");
                        }
                        else
                        {
                            gameName = args[i + 1];
                            //Program.gameNam1 = gameName;
                        }
                    }
                    else if (args[i].Equals("+servers"))
                    {
                        if ((i >= args.Length - 1))
                        {
                            LogError("+servers value must be a comma-separated list of server types (master,login,cdkey,list,natneg)");
                        }
                        else
                        {
                            List <string> serverTypes = args[i + 1].Split(char.Parse(",")).Select(s => { return(s.Trim().ToLower()); }).ToList();
                            runLoginServer  = serverTypes.IndexOf("login") >= 0;
                            runNatNegServer = serverTypes.IndexOf("natneg") >= 0;
                            runListServer   = serverTypes.IndexOf("list") >= 0;
                            runMasterServer = serverTypes.IndexOf("master") >= 0;
                            runCdKeyServer  = serverTypes.IndexOf("cdkey") >= 0;
                        }
                    }
                }
            }

            if (runLoginServer && !LoginDatabase.IsInitialized())
            {
                LogError("Error initializing login database, please confirm parameter +db is valid");
                LogError("Press any key to continue");
                Console.ReadKey();
                return;
            }

            if (runCdKeyServer)
            {
                CDKeyServer serverCdKey = new CDKeyServer(bind, 29910, log, logError);
            }
            if (runMasterServer)
            {
                ServerListReport serverListReport = new ServerListReport(bind, 27900, log, logError, gameName);
                if (runListServer)
                {
                    ServerListRetrieve serverListRetrieve = new ServerListRetrieve(bind, 28910 /*CHANGED FROM 28910*/, serverListReport, log, logError);
                }
            }
            if (runNatNegServer)
            {
                ServerNatNeg serverNatNeg = new ServerNatNeg(bind, 27901, log, logError);
            }
            if (runLoginServer)
            {
                LoginServer serverLogin = new LoginServer(bind, 29900, 29901, log, logError);
            }

            while (true)
            {
                string s = Console.ReadLine();
                if (s == "/help")
                {
                    LogBlue("type /list - to see current serverlist;");
                }
                else
                if (s == "/list")
                {
                    PRMasterServer.Servers.ServerListRetrieve.printSLinfo();
                }
                else
                if (s == "/decsht")
                {
                    PRMasterServer.Servers.ServerListRetrieve.DecodeShit();
                }                                                                                   //testing some stuff


                Thread.Sleep(500);
            }
        }