Esempio n. 1
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void SetGMLevel(string[] obj)
        {
            int gmlevel = 0;

            if ((obj.Length != 3) || (!int.TryParse(obj[2], out gmlevel)))
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine("Syntax: setgm <username> <gmlevel>");
                Console.WriteLine("gmlevel range: 0 - 511");
                Colouring.Pop();
            }
            else
            {
                LoginDataDao.SetGM(obj[1], gmlevel);
                Colouring.Push(ConsoleColor.Green);
                Console.WriteLine("Successfully set GM Level " + gmlevel + " to account " + obj[1]);
                Colouring.Pop();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// </summary>
        /// <param name="parts">
        /// </param>
        private static void ShowOnlineCharacters(string[] parts)
        {
            if (zoneServer.IsRunning)
            {
                Colouring.Push(ConsoleColor.White);

                // TODO: Check all clients inside playfields
                lock (zoneServer.Clients)
                {
                    foreach (ZoneClient c in zoneServer.Clients)
                    {
                        Console.WriteLine(
                            "Character " + c.Character.Name + " online in PF " + c.Character.Playfield.Identity.Instance);
                    }
                }

                Colouring.Pop();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        private static bool InitializeGameFunctions()
        {
            try
            {
                Colouring.Push(ConsoleColor.Green);
                Console.WriteLine(
                    "{0} Game functions loaded",
                    FunctionCollection.Instance.NumberofRegisteredFunctions());
            }
            catch (Exception e)
            {
                LogUtil.ErrorException(e);
                Colouring.Pop();
                return(false);
            }

            Colouring.Pop();
            return(true);
        }
Esempio n. 4
0
        /*       /// <summary>
         *     /// </summary>
         *     /// <param name="args">
         *     /// </param>
         *     /// <exception cref="ArgumentNullException">
         *     /// </exception>
         *     private static void CommandLoop(string[] args)
         *     {
         *         // Hard coded, because we only use TCP connections
         *         const bool TCPEnable = true;
         *         const bool UDPEnable = false;
         *
         *         bool processedargs = false;
         *         string consoleCommand;
         *         ct.TextRead("login_consolecommands.txt");
         *         while (true)
         *         {
         *             if (!processedargs)
         *             {
         *                 if (args.Length == 1)
         *                 {
         *                     if (args[0].ToLower() == "/autostart")
         *                     {
         *                         ct.TextRead("autostart.txt");
         *                         loginServer.Start(TCPEnable, UDPEnable);
         *                     }
         *                 }
         *
         *                 processedargs = true;
         *             }
         *
         *             Console.Write(Environment.NewLine + "Server Command >>");
         *
         *             consoleCommand = Console.ReadLine();
         *
         *             while (consoleCommand.IndexOf("  ") > -1)
         *             {
         *                 consoleCommand = consoleCommand.Replace("  ", " ");
         *             }
         *
         *             consoleCommand = consoleCommand.Trim();
         *             switch (consoleCommand.ToLower())
         *             {
         *                 case "start":
         *                     if (loginServer.IsRunning)
         *                     {
         *                         Colouring.Push(ConsoleColor.Red);
         *                         ct.TextRead("loginisrunning.txt");
         *                         Colouring.Pop();
         *                         break;
         *                     }
         *
         *                     loginServer.Start(TCPEnable, UDPEnable);
         *                     break;
         *                 case "stop":
         *                     if (!loginServer.IsRunning)
         *                     {
         *                         Colouring.Push(ConsoleColor.Red);
         *                         ct.TextRead("loginisnotrunning.txt");
         *                         Colouring.Pop();
         *                         break;
         *                     }
         *
         *                     loginServer.Stop();
         *                     break;
         *                 case "exit":
         *                     Process.GetCurrentProcess().Kill();
         *                     break;
         *                 case "running":
         *                     if (loginServer.IsRunning)
         *                     {
         *                         // Console.WriteLine("Login Server is running");
         *                         ct.TextRead("loginisrunning.txt");
         *                         break;
         *                     }
         *
         *                     // Console.WriteLine("Login Server not running");
         *                     ct.TextRead("loginisnotrunning.txt");
         *                     break;
         *
         *                 case "help":
         *                     ct.TextRead("logincmdhelp.txt");
         *                     break;
         *                 case "help start":
         *                     ct.TextRead("helpstart.txt");
         *                     break;
         *                 case "help exit":
         *                     ct.TextRead("helpstop.txt");
         *                     break;
         *                 case "help running":
         *                     ct.TextRead("loginhelpcmdrunning.txt");
         *                     break;
         *                 case "help Adduser":
         *                     ct.TextRead("logincmdadduserhelp.txt");
         *                     break;
         *                 case "help setpass":
         *                     ct.TextRead("logincmdhelpsetpass.txt");
         *                     break;
         *                 case "debugnetwork":
         *                     DebugNetwork = !DebugNetwork;
         *                     Colouring.Push(ConsoleColor.Green);
         *                     if (DebugNetwork)
         *                     {
         *                         Console.WriteLine("Debugging of network traffic enabled");
         *                     }
         *                     else
         *                     {
         *                         Console.WriteLine("Debugging of network traffic disabled");
         *                     }
         *
         *                     Colouring.Pop();
         *                     break;
         *
         *                 default:
         *                     if (consoleCommand.ToLower().StartsWith("setgm"))
         *                     {
         *                         string[] parts = consoleCommand.Split(' ');
         *                         int gmlevel = 0;
         *                         if ((parts.Count() != 3) || (!Int32.TryParse(parts[2], out gmlevel)))
         *                         {
         *                             Console.WriteLine("Usage: setgm <username> <gmlevel>");
         *                             Console.WriteLine("gmlevel range: 0 - 511");
         *                         }
         *                         else
         *                         {
         *                             LoginDataDao.SetGM(parts[1], gmlevel);
         *                             break;
         *                         }
         *                     }
         *                     if (consoleCommand.ToLower().StartsWith("logoffchars"))
         *                     {
         *                         string[] parts = consoleCommand.Split(' ');
         *                         if (parts.Count() != 2)
         *                         {
         *                             Console.WriteLine("Usage: logoffchars <username>");
         *                         }
         *                         else
         *                         {
         *                             LoginDataDao.LogoffChars(parts[1]);
         *                             break;
         *                         }
         *                     }
         *                     else
         *
         *                         // This section handles the command for adding a user to the database
         *                         if (consoleCommand.ToLower().StartsWith("adduser"))
         *                         {
         *                             string[] parts = consoleCommand.Split(' ');
         *                             if (parts.Length < 9)
         *                             {
         *                                 Console.WriteLine(
         *                                     "Invalid command syntax." + Environment.NewLine + "Please use:"
         + Environment.NewLine
         + "Adduser <username> <password> <number of characters> <expansion> <gm level> <email> <FirstName> <LastName>");
         +                                 break;
         +                             }
         +
         +                             string username = parts[1];
         +                             string password = parts[2];
         +                             int numChars = 0;
         +                             try
         +                             {
         +                                 numChars = int.Parse(parts[3]);
         +                             }
         +                             catch
         +                             {
         +                                 Console.WriteLine("Error: <number of characters> must be a number (duh!)");
         +                                 break;
         +                             }
         +
         +                             int expansions = 0;
         +                             try
         +                             {
         +                                 expansions = int.Parse(parts[4]);
         +                             }
         +                             catch
         +                             {
         +                                 Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!");
         +                                 break;
         +                             }
         +
         +                             if (expansions < 0 || expansions > 2047)
         +                             {
         +                                 Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!");
         +                                 break;
         +                             }
         +
         +                             int gm = 0;
         +                             try
         +                             {
         +                                 gm = int.Parse(parts[5]);
         +                             }
         +                             catch
         +                             {
         +                                 Console.WriteLine("Error: <GM Level> must be number (duh!)");
         +                                 break;
         +                             }
         +
         +                             string email = parts[6];
         +                             if (email == null)
         +                             {
         +                                 email = string.Empty;
         +                             }
         +
         +                             if (!TestEmailRegex.TestEmail(email))
         +                             {
         +                                 Console.WriteLine(
         +                                     "Error: <Email> You must supply an email address for this account");
         +                                 break;
         +                             }
         +
         +                             string firstname = parts[7];
         +                             try
         +                             {
         +                                 if (firstname == null)
         +                                 {
         +                                     throw new ArgumentNullException();
         +                                 }
         +                             }
         +                             catch
         +                             {
         +                                 Console.WriteLine("Error: <FirstName> You must supply a first name for this accout");
         +                                 break;
         +                             }
         +
         +                             string lastname = parts[8];
         +                             try
         +                             {
         +                                 if (lastname == null)
         +                                 {
         +                                     throw new ArgumentNullException();
         +                                 }
         +                             }
         +                             catch
         +                             {
         +                                 Console.WriteLine("Error: <LastName> You must supply a last name for this account");
         +                                 break;
         +                             }
         +
         +                             DBLoginData login = new DBLoginData
         +                                                 {
         +                                                     Username = username,
         +                                                     AccountFlags = 0,
         +                                                     Allowed_Characters = numChars,
         +                                                     CreationDate = DateTime.Now,
         +                                                     Email = email,
         +                                                     Expansions = expansions,
         +                                                     FirstName = firstname,
         +                                                     LastName = lastname,
         +                                                     GM = gm,
         +                                                     Flags = 0,
         +                                                     Password =
         +                                                         new LoginEncryption().GeneratePasswordHash(
         +                                                             password)
         +                                                 };
         +                             try
         +                             {
         +                                 LoginDataDao.WriteLoginData(login);
         +                             }
         +                             catch (Exception ex)
         +                             {
         +                                 Console.WriteLine(
         +                                     "An error occured while trying to add a new user account:" + Environment.NewLine
         + "{0}",
         +                                     ex.Message);
         +                                 break;
         +                             }
         +
         +                             Console.WriteLine("User added successfully.");
         +                             break;
         +                         }
         +
         +                     // This function just hashes the string you enter using the loginencryption method
         +                     if (consoleCommand.ToLower().StartsWith("hash"))
         +                     {
         +                         string Syntax =
         +                             "The Syntax for this command is \"hash <String to hash>\" alphanumeric no spaces";
         +                         string[] parts = consoleCommand.Split(' ');
         +                         if (parts.Length != 2)
         +                         {
         +                             Console.WriteLine(Syntax);
         +                             break;
         +                         }
         +
         +                         string pass = parts[1];
         +                         var le = new LoginEncryption();
         +                         string hashed = le.GeneratePasswordHash(pass);
         +                         Console.WriteLine(hashed);
         +                         break;
         +                     }
         +
         +                     // sets the password for the given username
         +                     // Added by Andyzweb
         +                     // Still TODO add exception and error handling
         +                     if (consoleCommand.ToLower().StartsWith("setpass"))
         +                     {
         +                         string Syntax =
         +                             "The syntax for this command is \"setpass <account username> <newpass>\" where newpass is alpha numeric no spaces";
         +                         string[] parts = consoleCommand.Split(' ');
         +                         if (parts.Length != 3)
         +                         {
         +                             Console.WriteLine(Syntax);
         +                             break;
         +                         }
         +
         +                         string username = parts[1];
         +                         string newpass = parts[2];
         +                         var le = new LoginEncryption();
         +                         string hashed = le.GeneratePasswordHash(newpass);
         +
         +                         try
         +                         {
         +                             LoginDataDao.WriteNewPassword(
         +                                 new DBLoginData { Username = username, Password = hashed });
         +                         }
         +
         +                             // yeah this part here, some kind of exception handling for mysql errors
         +                         catch (Exception ex)
         +                         {
         +                             Console.WriteLine("Could not set new Password" + Environment.NewLine + ex.Message);
         +                             LogUtil.ErrorException(ex);
         +                         }
         +                     }
         +
         +                     ct.TextRead("login_consolecmdsdefault.txt");
         +                     break;
         +             }
         +         }
         +     }*/

        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        private static bool Initialize()
        {
            Console.WriteLine();
            Colouring.Push(ConsoleColor.Green);

            if (!InitializeLogAndBug())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorInitializingNLogNBug);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!InitializeServerInstance())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorInitializingEngine);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!CheckDatabase())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorInitializingDatabase);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!InitializeConsoleCommands())
            {
                Colouring.Pop();
                return(false);
            }

            Colouring.Pop();
            return(true);
        }
        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="message">
        /// </param>
        public void Handle(object sender, Message message)
        {
            var client           = (Client)sender;
            var userLoginMessage = (UserLoginMessage)message.Body;

            client.AccountName   = userLoginMessage.UserName;
            client.ClientVersion = userLoginMessage.ClientVersion;
            Colouring.Push(ConsoleColor.Green);
            Console.WriteLine(
                "Client '" + client.AccountName + "' connected using version '" + client.ClientVersion + "'");
            Colouring.Pop();

            var salt = new byte[0x20];
            var rand = new Random();

            rand.NextBytes(salt);

            var sb = new StringBuilder();

            for (int i = 0; i < 32; i++)
            {
                // 0x00 Breaks Things
                if (salt[i] == 0)
                {
                    salt[i] = 42; // So we change it to something nicer
                }

                sb.Append(salt[i].ToString("x2", CultureInfo.InvariantCulture));
            }

            client.ServerSalt = sb.ToString();
            var serverSaltMessage = new ServerSaltMessage {
                ServerSalt = salt
            };

            client.Send(0x00002B3F, serverSaltMessage);
        }
Esempio n. 6
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void SetPassword(string[] obj)
        {
            string Syntax =
                "The syntax for this command is \"setpass <account username> <newpass>\" where newpass is alpha numeric no spaces";

            if (obj.Length != 3)
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(Syntax);
                Colouring.Pop();
            }
            else
            {
                string username = obj[1];
                string newpass  = obj[2];
                var    le       = new LoginEncryption();
                string hashed   = le.GeneratePasswordHash(newpass);
                int    affected =
                    LoginDataDao.WriteNewPassword(new DBLoginData()
                {
                    Username = username, Password = hashed
                });
                if (affected == 0)
                {
                    Colouring.Push(ConsoleColor.Red);
                    Console.WriteLine("Could not set new password. Maybe username is wrong?");
                    Colouring.Pop();
                }
                else
                {
                    Colouring.Push(ConsoleColor.Green);
                    Console.WriteLine("New password is set.");
                    Colouring.Pop();
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// </summary>
        /// <param name="parts">
        /// </param>
        private static void ListAvailableScripts(string[] parts)
        {
            // list all available scripts, dont remove it since it does what it should
            Colouring.Push(ConsoleColor.White);
            Console.WriteLine(locales.ServerConsoleAvailableScripts + ":");

            string[] files = Directory.GetFiles(
                "Scripts" + Path.DirectorySeparatorChar,
                "*.cs",
                SearchOption.AllDirectories);
            if (files.Length == 0)
            {
                Console.WriteLine(locales.ServerConsoleNoScriptsFound);
                return;
            }

            Colouring.Push(ConsoleColor.Green);
            foreach (string s in files)
            {
                Console.WriteLine(s);
            }

            Colouring.Pop();
        }
Esempio n. 8
0
        /// <summary>
        /// Load items and Nanos into static lists
        /// </summary>
        /// <returns>
        /// true if ok
        /// </returns>
        private static bool LoadItemsAndNanos()
        {
            Colouring.Push(ConsoleColor.Green);
            try
            {
                Console.WriteLine(locales.ItemLoaderLoadedItems, ItemLoader.CacheAllItems());
            }
            catch (Exception e)
            {
                LogUtil.ErrorException(e);

                Colouring.Pop();
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorReadingItemsFile);
                Console.WriteLine(e.Message);
                Colouring.Pop();
                return(false);
            }

            Colouring.Pop();

            Colouring.Push(ConsoleColor.Green);
            try
            {
                Console.WriteLine(locales.NanoLoaderLoadedNanos, NanoLoader.CacheAllNanos());
                Console.WriteLine();
            }
            catch (Exception e)
            {
                LogUtil.ErrorException(e);

                Colouring.Pop();
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorReadingNanosFile);
                Console.WriteLine(e.Message);
                Colouring.Pop();
                return(false);
            }

            Colouring.Pop();

            Colouring.Push(ConsoleColor.Green);
            try
            {
                Console.WriteLine("Loaded {0} Playfields", PlayfieldLoader.CacheAllPlayfieldData());
                Console.WriteLine();
            }
            catch (Exception e)
            {
                LogUtil.ErrorException(e);

                Colouring.Pop();
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine("Error reading statels.dat");
                Console.WriteLine(e.Message);
                Colouring.Pop();
                return(false);
            }

            Colouring.Pop();

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Initializing methods go here
        /// </summary>
        /// <returns>
        /// true if ok
        /// </returns>
        private static bool Initialize()
        {
            Console.WriteLine();
            Colouring.Push(ConsoleColor.Green);

            if (!InitializeGameFunctions())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorInitializingGamefunctions);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!InitializeLogAndBug())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorInitializingNLogNBug);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!CheckZoneServerCreation())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorCreatingZoneServerInstance);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!ISComInitialization())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorInitializingISCom);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!InizializeTCPIP())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorTCPIPSetup);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            if (!Misc.CheckDatabase())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorInitializingDatabase);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            Colouring.Push(ConsoleColor.Green);
            if (!LoadItemsAndNanos())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorLoadingItemsNanos);
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            Colouring.Pop();

            Colouring.Push(ConsoleColor.Green);
            if (!LoadTradeSkills())
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine("No locale yet: Error reading trade skills");
                Colouring.Pop();
                Colouring.Pop();
                return(false);
            }

            Colouring.Pop();

            if (!InitializeConsoleCommands())
            {
                return(false);
            }

            Colouring.Pop();

            return(true);
        }
        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="message">
        /// </param>
        public void Handle(object sender, Message message)
        {
            var client = (Client)sender;
            var userCredentialsMessage = (UserCredentialsMessage)message.Body;
            var checkLogin             = new CheckLogin();

            if (checkLogin.IsLoginAllowed(client, userCredentialsMessage.UserName) == false)
            {
                Colouring.Push(ConsoleColor.Green);
                Console.WriteLine(
                    "Client '" + client.AccountName
                    + "' banned, not a valid username, or sent a malformed Authentication Packet");
                Colouring.Pop();

                client.Send(0x00001F83, new LoginErrorMessage {
                    Error = LoginError.InvalidUserNamePassword
                });
                client.Server.DisconnectClient(client);
                return;
            }

            if (checkLogin.IsLoginCorrect(client, userCredentialsMessage.Credentials) == false)
            {
                Colouring.Push(ConsoleColor.Green);
                Console.WriteLine("Client '" + client.AccountName + "' failed Authentication.");

                client.Send(0x00001F83, new LoginErrorMessage {
                    Error = LoginError.InvalidUserNamePassword
                });
                client.Server.DisconnectClient(client);
                Colouring.Pop();

                return;
            }

            int expansions        = 0;
            int allowedCharacters = 0;

            /* This checks your expansions and
             * number of characters allowed (num. of chars doesn't work)*/
            string sqlQuery = "SELECT `Expansions`,`Allowed_Characters` FROM `login` WHERE Username = '******'";
            DBLoginData loginData = LoginDataDao.GetByUsername(client.AccountName);

            expansions        = loginData.Expansions;
            allowedCharacters = loginData.Allowed_Characters;

            IEnumerable <LoginCharacterInfo> characters = from c in CharacterList.LoadCharacters(client.AccountName)
                                                          select
                                                          new LoginCharacterInfo
            {
                Unknown1 = 4,
                Id       = c.Id,
                PlayfieldProxyVersion = 0x61,
                PlayfieldId           =
                    new Identity {
                    Type = IdentityType.Playfield, Instance = c.Playfield
                },
                PlayfieldAttribute   = 1,
                ExitDoor             = 0,
                ExitDoorId           = Identity.None,
                Unknown2             = 1,
                CharacterInfoVersion = 5,
                CharacterId          = c.Id,
                Name       = c.Name,
                Breed      = (Breed)c.Breed,
                Gender     = (Gender)c.Gender,
                Profession = (Profession)c.Profession,
                Level      = c.Level,
                AreaName   = "area unknown",
                Status     = CharacterStatus.Active
            };
            var characterListMessage = new CharacterListMessage
            {
                Characters        = characters.ToArray(),
                AllowedCharacters = allowedCharacters,
                Expansions        = expansions
            };

            client.Send(0x0000615B, characterListMessage);
        }
Esempio n. 11
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        public static bool CheckDatabase()
        {
            string applicationFolder = Path.Combine(Directory.GetCurrentDirectory(), "SqlTables");

            string[] files = Directory.GetFiles(applicationFolder, "*.sql", SearchOption.TopDirectoryOnly);

            string errorMessage = string.Empty;

            try
            {
                using (IDbConnection conn = Connector.GetConnection())
                {
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            if (errorMessage != string.Empty)
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine("Error connecting to database");
                Console.WriteLine(errorMessage);
                Colouring.Pop();
                return(false);
            }

            errorMessage = string.Empty;
            string        fName          = string.Empty;
            List <string> tablesNotFound = new List <string>();

            try
            {
                using (IDbConnection conn = Connector.GetConnection())
                {
                    foreach (string sqlFile in files)
                    {
                        if (sqlFile != null)
                        {
                            fName = Path.GetFileNameWithoutExtension(sqlFile).ToLower();
                            if (!Exists(conn, fName))
                            {
                                tablesNotFound.Add(sqlFile);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            if (errorMessage != string.Empty)
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine("Error checking for table " + fName);
                Console.WriteLine(errorMessage);
                Colouring.Pop();
                return(false);
            }

            try
            {
                using (IDbConnection conn = Connector.GetConnection())
                {
                    if (tablesNotFound.Count > 0)
                    {
                        Colouring.Push(ConsoleColor.Red);
                        Console.Write("SQL Tables are not complete. Should they be created? (Y/N) ");
                        Colouring.Pop();

                        string answer = Console.ReadLine();
                        string sqlQuery;
                        if (answer.ToLower() == "y")
                        {
                            foreach (string sqlFile in tablesNotFound)
                            {
                                fName = Path.GetFileNameWithoutExtension(sqlFile);
                                long fileSize = new FileInfo(sqlFile).Length;
                                Colouring.Push(ConsoleColor.Green);
                                Console.Write("Table " + fName.PadRight(67) + "[  0%]");
                                Colouring.Pop();
                                if (fileSize > 10000)
                                {
                                    string[] queries = File.ReadAllLines(sqlFile);
                                    int      counter = 0;
                                    sqlQuery = string.Empty;
                                    string lastpercent = "0";
                                    while (counter < queries.Length)
                                    {
                                        if (queries[counter].IndexOf("INSERT INTO") == -1)
                                        {
                                            sqlQuery += queries[counter] + "\n";
                                        }
                                        else
                                        {
                                            counter--;
                                            break;
                                        }

                                        counter++;
                                    }
                                    try
                                    {
                                        conn.Execute(sqlQuery);
                                    }
                                    catch (Exception)
                                    {
                                        Console.WriteLine(sqlQuery);
                                        throw;
                                    }

                                    counter++;
                                    string buf1 = string.Empty;
                                    while (counter < queries.Length)
                                    {
                                        if (queries[counter].ToLower().Substring(0, 11) == "insert into")
                                        {
                                            break;
                                        }

                                        counter++;
                                    }

                                    if (counter < queries.Length)
                                    {
                                        buf1 = queries[counter].Substring(
                                            0,
                                            queries[counter].ToLower().IndexOf("values"));
                                        buf1 = buf1 + "VALUES ";
                                        StringBuilder Buffer = new StringBuilder(0, 1 * 1024 * 1024);
                                        while (counter < queries.Length)
                                        {
                                            if (Buffer.Length == 0)
                                            {
                                                Buffer.Append(buf1);
                                            }

                                            string part = string.Empty;
                                            while (counter < queries.Length)
                                            {
                                                if (queries[counter].Trim() != string.Empty)
                                                {
                                                    part =
                                                        queries[counter].Substring(
                                                            queries[counter].ToLower().IndexOf("values"));
                                                    part = part.Substring(part.IndexOf("("));  // from '(' to end
                                                    part = part.Substring(0, part.Length - 1); // Remove ';'
                                                    if (Buffer.Length + 1 + part.Length > 1024 * 1000)
                                                    {
                                                        Buffer.Remove(Buffer.Length - 2, 2);
                                                        Buffer.Append(";");
                                                        try
                                                        {
                                                            conn.Execute(Buffer.ToString());
                                                        }
                                                        catch (Exception)
                                                        {
                                                            Console.WriteLine(Buffer.ToString().Substring(0, 300));
                                                            throw;
                                                        }

                                                        Buffer.Clear();
                                                        Buffer.Append(buf1);
                                                        string lp2 =
                                                            Convert.ToInt32(
                                                                Math.Floor((double)counter / queries.Length * 100))
                                                            .ToString();
                                                        if (lp2 != lastpercent)
                                                        {
                                                            Console.Write(
                                                                "\rTable " + fName.PadRight(67) + "[" + lp2.PadLeft(3)
                                                                + "%]");
                                                            lastpercent = lp2;
                                                        }
                                                    }

                                                    Buffer.Append(part + ", ");
                                                }

                                                counter++;
                                            }

                                            Buffer.Remove(Buffer.Length - 2, 2);
                                            Buffer.Append(";");
                                            conn.Execute(Buffer.ToString());
                                            Buffer.Clear();
                                            string lp =
                                                Convert.ToInt32(Math.Floor((double)counter / queries.Length * 100))
                                                .ToString();
                                            if (lp != lastpercent)
                                            {
                                                Console.Write(
                                                    "\rTable " + fName.PadRight(67) + "[" + lp.PadLeft(3) + "%]");
                                                lastpercent = lp;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Colouring.Push(ConsoleColor.Green);
                                        Console.Write("\rTable " + fName.PadRight(67) + "[100%]");
                                        Colouring.Pop();
                                    }
                                }
                                else
                                {
                                    sqlQuery = File.ReadAllText(sqlFile);
                                    conn.Execute(sqlQuery);
                                    Colouring.Push(ConsoleColor.Green);
                                    Console.Write("\rTable " + fName.PadRight(67) + "[100%]");
                                    Colouring.Pop();
                                }

                                Console.WriteLine();
                            }
                        }

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                LogUtil.ErrorException(e);
                return(false);
            }

            return(true);
        }
Esempio n. 12
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void AddUser(string[] obj)
        {
            if (obj.Length == 1)
            {
                List <string> temp = new List <string>();
                temp.Add("adduser");

                while (true)
                {
                    Console.Write("Username: "******"Please enter a username (at least 6 chars)...");
                        continue;
                    }
                    if (CheckUsername(test))
                    {
                        temp.Add(test);
                        break;
                    }
                }

                while (true)
                {
                    Console.Write("Password: "******"Please enter a password (at least 6 chars) for your safety...");
                        continue;
                    }
                    temp.Add(test);
                    break;
                }

                while (true)
                {
                    Console.WriteLine("Number of character slots: ");
                    string test = Console.ReadLine();
                    if (IsNumber(test))
                    {
                        temp.Add(test);
                        break;
                    }
                }

                Console.WriteLine("Expansions: Enter 2047 for all expansions (i know you want that)");
                while (true)
                {
                    Console.Write("Expansions: ");
                    string test = Console.ReadLine();
                    if (IsNumber(test))
                    {
                        temp.Add(test);
                        break;
                    }
                }

                Console.WriteLine(
                    "GM-Level: Anything above 0 is GM, but there are differences. Full Client GM = 1 (using keyboard shortcuts) but for some items you have to be GM Level 511");
                while (true)
                {
                    Console.Write("GM-Level: ");
                    string test = Console.ReadLine();
                    if (IsNumber(test))
                    {
                        temp.Add(test);
                        break;
                    }
                }

                while (true)
                {
                    Console.WriteLine("E-Mail: ");
                    string test = Console.ReadLine();
                    if (TestEmailRegex.TestEmail(test))
                    {
                        temp.Add(test);
                        break;
                    }
                }

                Console.Write("First name: ");
                temp.Add(Console.ReadLine());

                Console.Write("Last name: ");
                temp.Add(Console.ReadLine());

                obj = temp.ToArray();
            }

            Colouring.Push(ConsoleColor.Red);
            bool argsOk = CheckAddUserParameters(obj);

            Colouring.Pop();

            if (!argsOk)
            {
                return;
            }

            DBLoginData login = new DBLoginData
            {
                Username          = obj[1],
                AccountFlags      = 0,
                AllowedCharacters = int.Parse(obj[3]),
                CreationDate      = DateTime.Now,
                Email             = obj[6],
                Expansions        = int.Parse(obj[4]),
                FirstName         = obj[7],
                LastName          = obj[8],
                GM       = int.Parse(obj[5]),
                Flags    = 0,
                Password = new LoginEncryption().GeneratePasswordHash(obj[2])
            };

            try
            {
                LoginDataDao.WriteLoginData(login);
            }
            catch (Exception ex)
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(
                    "An error occured while trying to add a new user account:" + Environment.NewLine + "{0}",
                    ex.Message);
                Colouring.Pop();
                return;
            }

            Colouring.Push(ConsoleColor.Green);
            Console.WriteLine("User added successfully.");
            Colouring.Pop();
        }
Esempio n. 13
0
        /// <summary>
        /// </summary>
        /// <param name="args">
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        private static void CommandLoop(string[] args)
        {
            // Hard coded, because we only use TCP connections
            const bool TCPEnable = true;
            const bool UDPEnable = false;

            bool processedargs = false;

            string consoleCommand;

            while (true)
            {
                if (!processedargs)
                {
                    if (args.Length == 1)
                    {
                        if (args[0].ToLower() == "/autostart")
                        {
                            Console.WriteLine(locales.ServerConsoleAutostart);
                            chatServer.Start(TCPEnable, UDPEnable);
                        }

                        processedargs = true;
                    }
                }

                Console.Write(Environment.NewLine + locales.ServerConsoleCommand + ">>");

                consoleCommand = Console.ReadLine();

                while (consoleCommand.IndexOf("  ") > -1)
                {
                    consoleCommand = consoleCommand.Replace("  ", " ");
                }

                consoleCommand = consoleCommand.Trim();
                switch (consoleCommand.ToLower())
                {
                case "start":
                    if (chatServer.IsRunning)
                    {
                        Colouring.Push(ConsoleColor.Red);
                        Console.WriteLine(locales.ServerConsoleServerIsRunning);
                        Colouring.Pop();
                        break;
                    }

                    if (Config.Instance.CurrentConfig.UseIRCRelay == true)
                    {
                        Console.WriteLine("Starting RelayBot. Version {0}", ProgramInfo.AssemblyVersion);

                        // Call the IRC Bot stuff here..
                        RelayBot ircbot = new RelayBot();

                        ircbot.Run(chatServer);
                        chatServer.Start(TCPEnable, UDPEnable);
                        break;
                    }

                    chatServer.Start(TCPEnable, UDPEnable);
                    break;

                case "stop":
                    if (!chatServer.IsRunning)
                    {
                        Colouring.Push(ConsoleColor.Red);
                        Console.WriteLine(locales.ServerConsoleServerIsNotRunning);
                        Colouring.Pop();
                        break;
                    }

                    chatServer.Stop();
                    break;

                case "exit":
                    return;

                case "running":
                    if (chatServer.IsRunning)
                    {
                        Console.WriteLine(locales.ServerConsoleServerIsRunning);
                        break;
                    }

                    Console.WriteLine(locales.ServerConsoleServerIsNotRunning);
                    break;

                case "help":
                    ct.TextRead("chatcmdhelp.txt");
                    break;

                case "help start":
                    Console.WriteLine(locales.ServerConsoleCommandHelp_start);
                    break;

                case "help exit":
                    Console.WriteLine(locales.ServerConsoleCommandHelp_stop);
                    break;

                case "help running":
                    ct.TextRead("chathelpcmdrunning.txt");
                    break;

                case "debugnetwork":
                    DebugNetwork = !DebugNetwork;
                    Colouring.Push(ConsoleColor.Green);
                    if (DebugNetwork)
                    {
                        Console.WriteLine("Debugging network functions enabled");
                    }
                    else
                    {
                        Console.WriteLine("Debugging network functions disabled");
                    }

                    Colouring.Pop();
                    break;
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// </summary>
        /// <param name="args">
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        private static void CommandLoop(string[] args)
        {
            // Hard coded, because we only use TCP connections
            const bool TCPEnable = true;
            const bool UDPEnable = false;

            bool processedargs = false;

            string consoleCommand;

            while (true)
            {
                if (!processedargs)
                {
                    if (args.Length == 1)
                    {
                        if (args[0].ToLower() == "/autostart")
                        {
                            Console.WriteLine(locales.ServerConsoleAutostart);
                            StartRelayBot();
                            chatServer.Start(TCPEnable, UDPEnable);
                        }

                        processedargs = true;
                    }
                }

                Console.Write(Environment.NewLine + locales.ServerConsoleCommand + ">>");

                consoleCommand = Console.ReadLine();

                while (consoleCommand.IndexOf("  ") > -1)
                {
                    consoleCommand = consoleCommand.Replace("  ", " ");
                }

                consoleCommand = consoleCommand.Trim();
                switch (consoleCommand.ToLower())
                {
                case "start":
                    if (chatServer.IsRunning)
                    {
                        Colouring.Push(ConsoleColor.Red);
                        Console.WriteLine(locales.ServerConsoleServerIsRunning);
                        Colouring.Pop();
                        break;
                    }

                    StartRelayBot();
                    chatServer.Start(TCPEnable, UDPEnable);
                    break;

                case "stop":
                    if (!chatServer.IsRunning)
                    {
                        Colouring.Push(ConsoleColor.Red);
                        Console.WriteLine(locales.ServerConsoleServerIsNotRunning);
                        Colouring.Pop();
                        break;
                    }

                    chatServer.Stop();
                    break;

                case "exit":
                    return;

                case "running":
                    if (chatServer.IsRunning)
                    {
                        Console.WriteLine(locales.ServerConsoleServerIsRunning);
                        break;
                    }

                    Console.WriteLine(locales.ServerConsoleServerIsNotRunning);
                    break;

                case "help":
                    ct.TextRead("chatcmdhelp.txt");
                    break;

                case "help start":
                    Console.WriteLine(locales.ServerConsoleCommandHelp_start);
                    break;

                case "help exit":
                    Console.WriteLine(locales.ServerConsoleCommandHelp_stop);
                    break;

                case "help running":
                    ct.TextRead("chathelpcmdrunning.txt");
                    break;

                case "debugnetwork":
                    LogUtil.Toggle(DebugInfoDetail.Network);
                    break;
                }
            }
        }