Esempio n. 1
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        private static bool InizializeTCPIP()
        {
            int Port = Convert.ToInt32(ConfigReadWrite.Instance.CurrentConfig.ZonePort);

            try
            {
                if (ConfigReadWrite.Instance.CurrentConfig.ListenIP == "0.0.0.0")
                {
                    zoneServer.TcpEndPoint = new IPEndPoint(IPAddress.Any, Port);
                }
                else
                {
                    zoneServer.TcpEndPoint = new IPEndPoint(IPAddress.Parse(ConfigReadWrite.Instance.CurrentConfig.ListenIP), Port);
                }

                zoneServer.MaximumPendingConnections = 100;
            }
            catch (Exception e)
            {
                LogUtil.ErrorException(e);

                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ErrorIPAddressParseFailed);
                Console.Write(e.Message);
                Colouring.Pop();
                Console.ReadKey();

                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        private static bool InitializeLogAndBug()
        {
            try
            {
                // Setup and enable NLog logging to file
                LogUtil.SetupConsoleLogging(LogLevel.Debug);
                LogUtil.SetupFileLogging("${basedir}/LoginEngineLog.txt", LogLevel.Trace);

                // NBug initialization
                SettingsOverride.LoadCustomSettings("NBug.LoginEngine.config");
                Settings.WriteLogToDisk = true;
                AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException;
                TaskScheduler.UnobservedTaskException      += Handler.UnobservedTaskException;
            }
            catch (Exception e)
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine("Error occured while initalizing NLog/NBug");
                Console.WriteLine(e.Message);
                Colouring.Pop();
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void SetHash(string[] obj)
        {
            Colouring.Push(ConsoleColor.Red);

            if (obj.Length != 2)
            {
                Console.WriteLine("The Syntax for this command is \"hash <String to hash>\" alphanumeric no spaces");
                Colouring.Pop();
                return;
            }

            string pass   = obj[1];
            var    le     = new LoginEncryption();
            string hashed = le.GeneratePasswordHash(pass);

            Colouring.Pop();
            Console.Write("The Hash for password '");
            Colouring.Push(ConsoleColor.Green);
            Console.Write(obj[1]);
            Colouring.Pop();
            Console.Write("' is '");
            Colouring.Push(ConsoleColor.Green);
            Console.Write(hashed);
            Colouring.Pop();
            Console.WriteLine("'");
        }
Esempio n. 4
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)
            {
                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)
            {
                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)
            {
                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. 5
0
        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="message">
        /// </param>
        public void Handle(object sender, Message message)
        {
            var client = (Client)sender;
            var selectCharacterMessage = (SelectCharacterMessage)message.Body;

            var checkLogin = new CheckLogin();

            if (checkLogin.IsCharacterOnAccount(client, selectCharacterMessage.CharacterId) == false)
            {
                Colouring.Push(ConsoleColor.Green);
                Console.WriteLine(
                    "Client '" + client.AccountName + "' tried to log in as CharID "
                    + selectCharacterMessage.CharacterId + " but it is not on their account!");
                Colouring.Pop();

                // NV: Is this really what we want to send? Should find out sometime...
                client.Send(0x00001F83, new LoginErrorMessage {
                    Error = LoginError.InvalidUserNamePassword
                });
                client.Server.DisconnectClient(client);
                return;
            }

            if (OnlineDao.IsOnline(selectCharacterMessage.CharacterId).Online == 1)
            {
                Console.WriteLine(
                    "Client '" + client.AccountName
                    + "' is trying to login, but the requested character is already logged in.");
                client.Send(0x00001F83, new LoginErrorMessage {
                    Error = LoginError.AlreadyLoggedIn
                });
                client.Server.DisconnectClient(client);
                return;
            }

            OnlineDao.SetOnline(selectCharacterMessage.CharacterId);

            IPAddress zoneIpAdress;

            if (IPAddress.TryParse(ConfigReadWrite.Instance.CurrentConfig.ZoneIP, out zoneIpAdress) == false)
            {
                IPHostEntry zoneHost = Dns.GetHostEntry(ConfigReadWrite.Instance.CurrentConfig.ZoneIP);
                zoneIpAdress = zoneHost.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
            }

            var zoneRedirectionMessage = new ZoneInfoMessage
            {
                CharacterId     = selectCharacterMessage.CharacterId,
                ServerIpAddress = zoneIpAdress,
                ServerPort      =
                    (ushort)
                    ConfigReadWrite.Instance.CurrentConfig.ZonePort
            };

            client.Send(0x0000615B, zoneRedirectionMessage);
        }
Esempio n. 6
0
 /// <summary>
 /// </summary>
 private static void ShowCommandHelp()
 {
     Colouring.Push(ConsoleColor.White);
     Console.WriteLine(locales.ServerConsoleAvailableCommands);
     Console.WriteLine("---------------------------");
     Console.WriteLine(consoleCommands.HelpAll());
     Console.WriteLine("---------------------------");
     Console.WriteLine();
     Colouring.Pop();
 }
Esempio n. 7
0
        private static void StartServer(string[] obj)
        {
            if (chatServer.IsRunning)
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine(locales.ServerConsoleServerIsRunning);
                Colouring.Pop();
            }

            StartRelayBot();
            chatServer.Start(TcpEnable, UdpEnable);
        }
Esempio n. 8
0
 /// <summary>
 /// </summary>
 /// <param name="obj">
 /// </param>
 private static void StopServer(string[] obj)
 {
     if (!loginServer.IsRunning)
     {
         Colouring.Push(ConsoleColor.Red);
         Console.WriteLine(locales.ServerConsoleServerIsNotRunning);
         Colouring.Pop();
     }
     else
     {
         loginServer.Stop();
     }
 }
Esempio n. 9
0
 /// <summary>
 /// </summary>
 /// <param name="obj">
 /// </param>
 private static void LogoffCharacters(string[] obj)
 {
     if (obj.Length != 2)
     {
         Colouring.Push(ConsoleColor.Red);
         Console.WriteLine("Syntax: logoffchars <username>");
         Colouring.Pop();
     }
     else
     {
         LoginDataDao.LogoffChars(obj[1]);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void IsServerRunning(string[] obj)
        {
            Colouring.Push(ConsoleColor.White);
            if (loginServer.IsRunning)
            {
                Console.WriteLine(locales.ServerConsoleServerIsRunning);
            }
            else
            {
                Console.WriteLine(locales.ServerConsoleServerIsNotRunning);
            }

            Colouring.Pop();
        }
Esempio n. 11
0
 /// <summary>
 /// </summary>
 /// <param name="parts">
 /// </param>
 private static void StartServer(string[] parts)
 {
     if (loginServer.IsRunning)
     {
         Colouring.Push(ConsoleColor.Red);
         Console.WriteLine(locales.ServerConsoleServerIsRunning);
         Colouring.Pop();
     }
     else
     {
         // TODO: Add Sql Check.
         StartTheServer();
     }
 }
        /// <summary>
        /// Logs messages to the console.
        /// </summary>
        /// <param name="owner">
        /// Who or what to log as.
        /// </param>
        /// <param name="ownerColor">
        /// The color of the text the owner shows.
        /// </param>
        /// <param name="message">
        /// The message to display.
        /// </param>
        /// <param name="messageColor">
        /// The color to display the message in.
        /// </param>
        public static void LogScriptAction(
            string owner,
            ConsoleColor ownerColor,
            string message,
            ConsoleColor messageColor)
        {
            Colouring.Push(ownerColor);
            Console.Write(owner + " ");
            Colouring.Pop();

            Colouring.Push(messageColor);
            Console.Write(message + "\n");
            Colouring.Pop();
        }
Esempio n. 13
0
 /// <summary>
 /// </summary>
 /// <param name="parts">
 /// </param>
 private static void StartServer(string[] parts)
 {
     if (zoneServer.IsRunning)
     {
         Colouring.Push(ConsoleColor.Red);
         Console.WriteLine(locales.ServerConsoleServerIsRunning);
         Colouring.Pop();
     }
     else
     {
         // TODO: Add Sql Check.
         ScriptCompiler.Instance.Compile(false);
         StartTheServer();
     }
 }
Esempio n. 14
0
        /// <summary>
        /// </summary>
        /// <param name="parts">
        /// </param>
        private static void SetDebugGameFunctions(string[] parts)
        {
            DebugGameFunctions = !DebugGameFunctions;
            Colouring.Push(ConsoleColor.Green);
            if (DebugGameFunctions)
            {
                Console.WriteLine("Debugging Game functions enabled");
            }
            else
            {
                Console.WriteLine("Debugging Game functions disabled");
            }

            Colouring.Pop();
        }
Esempio n. 15
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void SetDebugNetwork(string[] obj)
        {
            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();
        }
Esempio n. 16
0
        /// <summary>
        /// </summary>
        /// <param name="parts">
        /// </param>
        private static void SetDebugZoning(string[] parts)
        {
            DebugZoning = !DebugZoning;
            Colouring.Push(ConsoleColor.Green);
            if (DebugZoning)
            {
                Console.WriteLine("Debugging of zoning enabled");
            }
            else
            {
                Console.WriteLine("Debugging of zoning disabled");
            }

            Colouring.Pop();
        }
Esempio n. 17
0
        /// <summary>
        /// </summary>
        /// <param name="parts">
        /// </param>
        private static void StartServer(string[] parts)
        {
            if (myServer.isRunning)
            {
                Colouring.Push(ConsoleColor.Red);
                Console.WriteLine("WebServer is running already.");

                Console.WriteLine(locales.ServerConsoleServerIsRunning);
                Colouring.Pop();
            }
            else
            {
                StartTheServer();
            }
        }
Esempio n. 18
0
 /// <summary>
 /// </summary>
 /// <param name="parts">
 /// </param>
 private static void StartServerMultipleScriptDlls(string[] parts)
 {
     // Multiple dll compile
     if (zoneServer.IsRunning)
     {
         Colouring.Push(ConsoleColor.Red);
         Console.WriteLine(locales.ServerConsoleServerIsRunning);
         Colouring.Pop();
     }
     else
     {
         // TODO: Add Sql Check.
         csc.Compile(true);
         StartTheServer();
     }
 }
Esempio n. 19
0
        /// <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("Error initializing WebServer.");

                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);
        }
Esempio n. 20
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void AddUser(string[] obj)
        {
            Colouring.Push(ConsoleColor.Red);
            bool argsOk = CheckAddUserParameters(obj);

            Colouring.Pop();

            if (!argsOk)
            {
                return;
            }

            DBLoginData login = new DBLoginData
            {
                Username           = obj[1],
                AccountFlags       = 0,
                Allowed_Characters = 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. 21
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. 22
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. 23
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();
            }
        }
        /// <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. 25
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. 26
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. 27
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);
        }
        /// <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. 29
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);
        }
Esempio n. 30
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();
        }