Beispiel #1
0
        public IActionResult Signin(Login login)
        {
            // Cria uma conexão com o banco de dados para signin
            LoginDatabase ld = new LoginDatabase();

            // Verifica se o login já existe
            if (ld.Login(login) == null)
            {
                // Insere o login no banco de dados,
                // diz que o script foi executado,
                // avisa o usuario do sucesso
                ld.Inserir(login);
                ViewBag.checks       = true;
                ViewBag.mensagemSign = $"Usuário cadastrado com sucesso! Id = {ld.Login(login).Id}";
                return(View());
            }
            else
            {
                // Diz que o script foi executado existe
                // avisa o usuario do erro
                ViewBag.checks       = true;
                ViewBag.mensagemSign = "Usuário já existe";
                return(View());
            }
        }
Beispiel #2
0
        public void CreateAccount(string username, string password)
        {
            if (Accounts.SingleOrDefault(ac => ac.username == username) != null)
            {
                Log.Print(LogType.Debug, "Account '" + username + "' was not created because it already exists!");
                return;
            }

            var shaPassHash = CalculateShaPassHash(username, password);

            Accounts.Add(new account()
            {
                username        = username,
                sha_pass_hash   = password,
                last_ip         = "0.0.0.0",
                active_realm_id = 0,
                email           = "",
                expansion       = 0,
                failed_logins   = 0,
                gmlevel         = 0,
                joindate        = DateTime.Now,
                last_login      = DateTime.Now,
                locale          = 0,
                locked          = 0,
                mutetime        = 0,
                s          = null,
                sessionkey = null,
                v          = null
            });

            LoginDatabase.SaveChanges();

            Log.Print(LogType.Debug, "Account '" + username + "' created!");
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public ClusterServer()
        {
            Console.WriteLine("Test if port 28000 is in use...");
            if (PortChecker.IsPortAvailable(28000))
            {
                Console.WriteLine("Port 28000 is already in use - You can only run one login server on one computer");
                return;
            }

            Rijndael.Initiate();

            Config = new ClusterServerConfig("Resources/Config/Cluster.ini");

            int loginPort = (int)Config.GetSetting("LoginPort");

            Console.WriteLine("Test if port {0} is in use...", loginPort.ToString());
            if (PortChecker.IsPortAvailable(loginPort))
            {
                Console.WriteLine("Port {0} is already in use - You can only run one login server on one computer", loginPort);
                return;
            }

            int receivePort = (int)Config.GetSetting("InterserverPort");

            Console.WriteLine("Search open port for interserver connection...");
            while (PortChecker.IsPortAvailable(receivePort))
            {
                Console.WriteLine("Port {0} not available", receivePort.ToString());
                receivePort += 1;
            }

            LoginDatabase   = new LoginDatabase(Config);
            ClusterDatabase = new ClusterDatabase(Config);
            if (ClusterDatabase.Connection.CheckConnection() && LoginDatabase.Connection.CheckConnection())
            {
                Console.WriteLine("Connecting to login server...");

                LoginConnector = new LoginConnector(loginPort.ToString(), receivePort.ToString());
                LoginConnector.StartListening();

                // Let's wait a bit to let the subscriber and publisher socket to connect
                Thread.Sleep(500);
                RegisterClusterRequest request = new RegisterClusterRequest((uint)Config.GetSetting("ClusterId"), (string)Config.GetSetting("ClusterAuthorizationPassword"), (string)Config.GetSetting("ClusterAddress"), receivePort.ToString(), LoginConnector.PublisherSocket);

                LoginConnector.OnClusterRequestSuccesful += new LoginConnector.RequestSuccesfulHandler(OnRegisterClusterRequestSuccesful);
            }
        }
Beispiel #5
0
        public LoginServer()
        {
            Console.WriteLine("Test if port 23000 is in use...");
            if (PortChecker.IsPortAvailable(23000))
            {
                Console.WriteLine("Port 23000 is already in use - You can only run one cluster on one computer");
                return;
            }

            Config = new LoginServerConfig("Resources/Config/Login.ini");

            int loginPort = (int)Config.GetSetting("LoginPort");

            Console.WriteLine("Test if port {0} is in use...", loginPort.ToString());
            if (PortChecker.IsPortAvailable(loginPort))
            {
                Console.WriteLine("Port {0} is already in use - You can only run one login server on one computer", loginPort);
                return;
            }

            LoginDatabase = new LoginDatabase(Config);
            if (LoginDatabase.Connection.CheckConnection())
            {
                Rijndael.Initiate();

                this.m_ClusterConnector = new ClusterConnector(loginPort.ToString());
                this.m_ClusterConnector.StartListening();

                ClusterManager = new ClusterManager();
                Console.WriteLine("Listening for cluster servers...");

                this.m_ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                this.m_ClientSocket.Bind(new IPEndPoint(IPAddress.Any, 23000));
                this.m_ClientSocket.Listen(100);
                ClientManager = new ClientManager();

                Thread acceptClientsThread = new Thread(() => ClientManager.AcceptUsers(this.m_ClientSocket));
                acceptClientsThread.Start();

                Thread processClientsThread = new Thread(() => ClientManager.ProcessUsers());
                processClientsThread.Start();

                Console.WriteLine("Listening for clients...");
            }
        }
Beispiel #6
0
        public IActionResult Login(Login login)
        {
            // Cria uma conexão com o banco de dados para login
            LoginDatabase ld = new LoginDatabase();

            // Verifica se o login existe
            if (ld.Login(login) != null)
            {
                // Salva as informações em uma variável e na sessão
                Login logado = ld.Login(login);
                HttpContext.Session.SetString("Email", logado.Email);
                HttpContext.Session.SetString("Senha", logado.Senha);
                HttpContext.Session.SetInt32("Id", logado.Id);

                // Retorna para a página inicial
                return(RedirectToAction("Index"));
            }
            else
            {
                // Avisa o usuario que o login está errado
                ViewBag.mensagemLogin = "******";
                return(View());
            }
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
 public LoginController()
 {
     database = new LoginDatabase();
 }
Beispiel #10
0
        public static void Main(string[] args)
        {
            LoginDatabase loginDatabase = new LoginDatabase();

            CreateWebHostBuilder(args).UseUrls("http://localhost:9001").Build().Run();
        }