Пример #1
0
 /// <summary>
 /// Writes names to DB after a name change
 /// </summary>
 public bool WriteNames()
 {
     mySql.SqlUpdate("UPDATE `characters` SET `Name` = '" + characterName + "', `FirstName` = '" +
                     characterFirstName + "', `LastName` = '" + characterLastName + "' WHERE `ID` = " + "'" +
                     characterId + "'");
     return(true);
 }
Пример #2
0
 /// <summary>
 /// Write Heading to Sql Table
 /// </summary>
 public void WriteHeadingToSql()
 {
     SqlWrapper sqlWrapper = new SqlWrapper();
     sqlWrapper.SqlUpdate(
         "UPDATE " + this.GetSqlTablefromDynelType() + " SET HeadingX="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", this.Heading.x) + ", HeadingY="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", this.Heading.y) + ", HeadingZ="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", this.Heading.z) + ", HeadingW="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", this.Heading.w) + " WHERE ID="
         + this.Id.ToString() + ";");
 }
Пример #3
0
        /// <summary>
        /// Write Coordinates to Sql Table
        /// </summary>
        public virtual void WriteCoordinatesToSql()
        {
            SqlWrapper sqlWrapper = new SqlWrapper();

            sqlWrapper.SqlUpdate(
                "UPDATE " + this.GetSqlTablefromDynelType() + " SET playfield=" + this.PlayField.ToString() + ", X="
                + String.Format(CultureInfo.InvariantCulture, "'{0}'", this.Coordinates.x) + ", Y="
                + String.Format(CultureInfo.InvariantCulture, "'{0}'", this.Coordinates.y) + ", Z="
                + String.Format(CultureInfo.InvariantCulture, "'{0}'", this.Coordinates.z) + " WHERE ID="
                + this.Id.ToString() + ";");
        }
Пример #4
0
        /// <summary>
        /// Switch item placements
        /// TODO: catch exceptions
        /// </summary>
        /// <param name="cli">Client</param>
        /// <param name="fromPlacement">From location</param>
        /// <param name="toPlacement">To location</param>
        public void SwitchItems(int fromPlacement, int toPlacement)
        {
            lock (this)
            {
                SqlWrapper mySql = new SqlWrapper();
                InventoryEntries afrom = this.GetInventoryAt(fromPlacement);
                InventoryEntries ato = this.GetInventoryAt(toPlacement);
                if (afrom != null)
                {
                    afrom.Placement = toPlacement;
                }
                if (ato != null)
                {
                    ato.Placement = fromPlacement;
                }

                mySql.SqlUpdate(
                    "UPDATE " + this.GetSqlTablefromDynelType() + "inventory SET placement=255 where (ID="
                    + this.Id.ToString() + ") AND (placement=" + fromPlacement.ToString() + ")");
                mySql.SqlUpdate(
                    "UPDATE " + this.GetSqlTablefromDynelType() + "inventory SET placement=" + fromPlacement.ToString()
                    + " where (ID=" + this.Id.ToString() + ") AND (placement=" + toPlacement.ToString() + ")");
                mySql.SqlUpdate(
                    "UPDATE " + this.GetSqlTablefromDynelType() + "inventory SET placement=" + toPlacement.ToString()
                    + " where (ID=" + this.Id.ToString() + ") AND (placement=255)");
            }

            // If its a switch from or to equipment pages then recalculate the skill modifiers
            if ((fromPlacement < 64) || (toPlacement < 64))
            {
                this.CalculateSkills();
            }
        }
Пример #5
0
        private static void Main(string[] args)
        {
            #region Console Texts...
            Console.Title = "CellAO " + AssemblyInfoclass.Title + " Console. Version: " + AssemblyInfoclass.Description
                + " " + AssemblyInfoclass.AssemblyVersion + " " + AssemblyInfoclass.Trademark;

            ConsoleText ct = new ConsoleText();
            ct.TextRead("main.txt");
            Console.WriteLine("Loading " + AssemblyInfoclass.Title + "...");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("[OK]");
            Console.ResetColor();
            #endregion

            //Sying helped figure all this code out, about 5 yearts ago! :P
            bool processedargs = false;
            loginLoginServer = new LoginServer();
            loginLoginServer.EnableTCP = true;
            loginLoginServer.EnableUDP = false;
            try
            {
                loginLoginServer.TcpIP = IPAddress.Parse(Config.Instance.CurrentConfig.ListenIP);
            }
            catch
            {
                ct.TextRead("ip_config_parse_error.txt");
                Console.ReadKey();
                return;
            }
            loginLoginServer.TcpPort = Convert.ToInt32(Config.Instance.CurrentConfig.LoginPort);

            #region NLog
            LoggingConfiguration config = new LoggingConfiguration();
            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
            consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
            FileTarget fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);
            fileTarget.FileName = "${basedir}/LoginEngineLog.txt";
            fileTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
            LoggingRule rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget);
            config.LoggingRules.Add(rule1);
            LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
            config.LoggingRules.Add(rule2);
            LogManager.Configuration = config;
            #endregion

            #region NBug
            SettingsOverride.LoadCustomSettings("NBug.LoginEngine.Config");
            NBug.Settings.WriteLogToDisk = true;
            AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException;
            TaskScheduler.UnobservedTaskException += Handler.UnobservedTaskException;
            //TODO: ADD More Handlers.
            #endregion

            loginLoginServer.MaximumPendingConnections = 100;

            #region Console Commands
            //Andyzweb: Added checks for start and stop
            //also added a running command to return status of the server
            //and added Console.Write("\nServer Command >>"); to login server
            string consoleCommand;
            ct.TextRead("login_consolecommands.txt");
            while (true)
            {
                if (!processedargs)
                {
                    if (args.Length == 1)
                    {
                        if (args[0].ToLower() == "/autostart")
                        {
                            ct.TextRead("autostart.txt");
                            ThreadMgr.Start();
                            loginLoginServer.Start();
                        }
                    }
                    processedargs = true;
                }
                Console.Write("\nServer Command >>");

                consoleCommand = Console.ReadLine();
                string temp = "";
                while (temp != consoleCommand)
                {
                    temp = consoleCommand;
                    consoleCommand = consoleCommand.Replace("  ", " ");
                }
                consoleCommand = consoleCommand.Trim();
                switch (consoleCommand.ToLower())
                {
                    case "start":
                        if (loginLoginServer.Running)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            ct.TextRead("loginisrunning.txt");
                            Console.ResetColor();
                            break;
                        }
                        ThreadMgr.Start();
                        loginLoginServer.Start();
                        break;
                    case "stop":
                        if (!loginLoginServer.Running)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            ct.TextRead("loginisnotrunning.txt");
                            Console.ResetColor();
                            break;
                        }
                        ThreadMgr.Stop();
                        loginLoginServer.Stop();
                        break;
                    case "exit":
                        Process.GetCurrentProcess().Kill();
                        break;
                    case "running":
                        if (loginLoginServer.Running)
                        {
                            //Console.WriteLine("Login Server is running");
                            ct.TextRead("loginisrunning.txt");
                            break;
                        }
                        //Console.WriteLine("Login Server not running");
                        ct.TextRead("loginisnotrunning.txt");
                        break;

                        #region Help Commands....
                    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;
                        #endregion

                    default:

                        #region Adduser
                        //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.\nPlease use:\nAdduser <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(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;
                            }

                            const string FormatString =
                                "INSERT INTO `login` (`CreationDate`, `Flags`,`AccountFlags`,`Username`,`Password`,`Allowed_Characters`,`Expansions`, `GM`, `Email`, `FirstName`, `LastName`) VALUES "
                                + "(NOW(), '0', '0', '{0}', '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}');";

                            LoginEncryption le = new LoginEncryption();

                            string hashedPassword = le.GeneratePasswordHash(password);

                            string sql = String.Format(
                                FormatString,
                                username,
                                hashedPassword,
                                numChars,
                                expansions,
                                gm,
                                email,
                                firstname,
                                lastname);
                            SqlWrapper sqlWrapper = new SqlWrapper();
                            try
                            {
                                sqlWrapper.SqlInsert(sql);
                            }
                            catch (MySqlException ex)
                            {
                                switch (ex.Number)
                                {
                                    case 1062: //duplicate entry for key
                                        Console.WriteLine("A user account with this username already exists.");
                                        break;
                                    default:
                                        Console.WriteLine(
                                            "An error occured while trying to add a new user account:\n{0}", ex.Message);
                                        break;
                                }
                                break;
                            }
                            Console.WriteLine("User added successfully.");
                            break;
                        }
                        #endregion

                        #region Hashpass
                        //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];
                            LoginEncryption le = new LoginEncryption();
                            string hashed = le.GeneratePasswordHash(pass);
                            Console.WriteLine(hashed);
                            break;
                        }
                        #endregion

                        #region setpass
                        //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];
                            LoginEncryption le = new LoginEncryption();
                            string hashed = le.GeneratePasswordHash(newpass);
                            string formatString;
                            formatString = "UPDATE `login` SET Password = '******' WHERE login.Username = '******'";

                            string sql = String.Format(formatString, hashed, username);

                            SqlWrapper updt = new SqlWrapper();
                            try
                            {
                                updt.SqlUpdate(sql);
                            }
                                //yeah this part here, some kind of exception handling for mysql errors
                            catch
                            {
                            }
                        }
                        #endregion

                        ct.TextRead("login_consolecmdsdefault.txt");
                        break;
                }
            }
            #endregion
        }
            public static bool func_do(Character ch, AOFunctions func, bool dolocalstats, bool tosocialtab, int placement, bool doreqs)
            {
                int c;
                int r;
                Character chartarget = (Character)Misc.FindDynel.FindDynelByID(ch.Target.Type, ch.Target.Instance);
                Boolean reqs_met;
                Character ftarget = null;
                int statval;
                Boolean reqresult;
                if (ch != null)
                {
                    for (c = 0; c < func.TickCount; c++)
                    {
                        reqs_met = true;
                        int childop = -1;
                        if (!doreqs)
                        {
                            for (r = 0; r < func.Requirements.Count; r++)
                            {
                                switch (func.Requirements[r].Target)
                                {
                                    case itemtarget_user:
                                        ftarget = ch;
                                        break;
                                    case itemtarget_wearer:
                                        ftarget = ch;
                                        break;
                                    case itemtarget_target:
                                        ftarget = chartarget;
                                        break;
                                    case itemtarget_fightingtarget:
                                        // Fighting target
                                        break;
                                    case itemtarget_self:
                                        ftarget = ch;
                                        break;
                                    case itemtarget_selectedtarget:
                                        ftarget = chartarget;
                                        break;
                                }
                                if (ftarget == null)
                                {
                                    reqs_met = false;
                                    return false;
                                }
                                statval = ftarget.Stats.Get(func.Requirements[r].Statnumber);
                                switch (func.Requirements[r].Operator)
                                {
                                    case operator_and:
                                        reqresult = ((statval & func.Requirements[r].Value) != 0);
                                        break;
                                    case operator_or:
                                        reqresult = ((statval | func.Requirements[r].Value) != 0);
                                        break;
                                    case operator_equalto:
                                        reqresult = (statval == func.Requirements[r].Value);
                                        break;
                                    case operator_lessthan:
                                        reqresult = (statval < func.Requirements[r].Value);
                                        break;
                                    case operator_greaterthan:
                                        reqresult = (statval > func.Requirements[r].Value);
                                        break;
                                    case operator_unequal:
                                        reqresult = (statval != func.Requirements[r].Value);
                                        break;
                                    case operator_true:
                                        reqresult = (statval != 0);
                                        break;
                                    case operator_false:
                                        reqresult = (statval == 0);
                                        break;
                                    case operator_bitand:
                                        reqresult = ((statval & func.Requirements[r].Value) != 0);
                                        break;
                                    case operator_bitor:
                                        reqresult = ((statval | func.Requirements[r].Value) != 0);
                                        break;
                                    default:
                                        reqresult = true;
                                        break;
                                }

                                switch (childop)
                                {
                                    case operator_and:
                                        reqs_met &= reqresult;
                                        break;
                                    case operator_or:
                                        reqs_met |= reqresult;
                                        break;
                                    case -1:
                                        reqs_met = reqresult;
                                        break;
                                    default:
                                        break;
                                }
                                childop = func.Requirements[r].ChildOperator;
                            }
                        }

                        if (!reqs_met)
                        {
                            return reqs_met;
                        }

                        switch (func.FunctionType)
                        {
                            // Set new Texture
                            case ItemHandler.functiontype_texture:
                                SqlWrapper ms = new SqlWrapper();
                                if (!tosocialtab)
                                {
                                    ms.SqlUpdate("Update " + ch.getSQLTablefromDynelType() + " set Textures" + func.Arguments[1].ToString() + "=" + func.Arguments[0].ToString() + " WHERE ID=" + ch.ID.ToString());
                                    AOTextures ao = new AOTextures((int)func.Arguments[1], (int)func.Arguments[0]);
                                    ch.Textures.Add(ao);
                                }
                                else
                                {
                                    int texnum = Int32.Parse(func.Arguments[1].ToString());
                                    int texval = Int32.Parse(func.Arguments[0].ToString());
                                    if (ch.SocialTab.ContainsKey(texnum))
                                    {
                                        ch.SocialTab[texnum] = texval;
                                    }
                                    else
                                    {
                                        ch.SocialTab.Add(texnum, texval);
                                    }
                                    ch.SaveSocialTab();
                                }

                                break;
                            // Set Headmesh
                            case ItemHandler.functiontype_headmesh:
                                if (!tosocialtab)
                                {
                                    ch.Stats.HeadMesh.StatModifier = (Int32)((Int32)func.Arguments[1] - ch.Stats.HeadMesh.StatBaseValue); // Headmesh
                                    ch.MeshLayer.AddMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], 0);
                                }
                                else
                                {
                                    if (ch.SocialTab.ContainsKey(ch.Stats.HeadMesh.StatNumber))
                                    {
                                        ch.SocialTab[ch.Stats.HeadMesh.StatNumber] = (Int32)func.Arguments[0];
                                        ch.SocialMeshLayer.AddMesh(0, (Int32)func.Arguments[0], (Int32)func.Arguments[1], 0);
                                    }
                                    else
                                    {
                                        ch.SocialTab.Add(ch.Stats.HeadMesh.StatNumber, (Int32)func.Arguments[0]);
                                        ch.SocialMeshLayer.AddMesh(0, (Int32)func.Arguments[0], (Int32)func.Arguments[1], 0);
                                    }
                                    ch.SaveSocialTab();
                                }
                                break;
                            // Set Shouldermesh
                            case ItemHandler.functiontype_shouldermesh:
                                if ((placement == 19) || (placement == 51))
                                {
                                    if (!tosocialtab)
                                    {
                                        ch.Stats.ShoulderMeshRight.Set((Int32)func.Arguments[1]);
                                        ch.Stats.ShoulderMeshLeft.Set((Int32)func.Arguments[1]);
                                        ch.MeshLayer.AddMesh(3, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                        ch.MeshLayer.AddMesh(4, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                    }
                                    else
                                    {
                                        ch.SocialMeshLayer.AddMesh(3, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                        ch.SocialMeshLayer.AddMesh(4, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                    }
                                }
                                else
                                {
                                    if (!tosocialtab)
                                    {
                                        if (placement == 20)
                                        {
                                            ch.Stats.ShoulderMeshLeft.Set((Int32)func.Arguments[1]);
                                            ch.MeshLayer.AddMesh(3, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                        }
                                        if (placement == 22)
                                        {
                                            ch.Stats.ShoulderMeshLeft.Set((Int32)func.Arguments[1]);
                                            ch.MeshLayer.AddMesh(4, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                        }
                                    }
                                    else
                                    {
                                        if (placement == 52)
                                        {
                                            ch.Stats.ShoulderMeshRight.Set((Int32)func.Arguments[1]);
                                            ch.SocialMeshLayer.AddMesh(3, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                        }
                                        if (placement == 54)
                                        {
                                            ch.Stats.ShoulderMeshLeft.Set((Int32)func.Arguments[1]);
                                            ch.SocialMeshLayer.AddMesh(4, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                        }
                                    }


                                }
                                break;
                            // Set Backmesh
                            case ItemHandler.functiontype_backmesh:
                                if (!tosocialtab)
                                {
                                    ch.Stats.BackMesh.Set((Int32)func.Arguments[0]); // Shouldermesh
                                    ch.MeshLayer.AddMesh(5, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                else
                                {
                                    ch.SocialMeshLayer.AddMesh(5, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                break;
                            // Set Hairmesh
                            case ItemHandler.functiontype_hairmesh:
                                if (!tosocialtab)
                                {
                                    ch.Stats.HairMesh.Set((Int32)func.Arguments[0]); // HairMesh
                                    ch.MeshLayer.AddMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                else
                                {
                                    ch.SocialMeshLayer.AddMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                break;
                            case ItemHandler.functiontype_attractormesh:
                                if (!tosocialtab)
                                {
                                    ch.Stats.HairMesh.Set((Int32)func.Arguments[0]); // HairMesh
                                    ch.MeshLayer.AddMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                else
                                {
                                    ch.SocialMeshLayer.AddMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                break;
                            case ItemHandler.functiontype_modify:
                                // TODO: req check for OE
                                if (dolocalstats)
                                {
                                    if (!tosocialtab)
                                    {
                                        ch.Stats.SetModifier((Int32)func.Arguments[0], ch.Stats.GetModifier((Int32)func.Arguments[0]) + (Int32)func.Arguments[1]);
                                    }
                                }
                                break;
                            case ItemHandler.functiontype_modifypercentage:
                                // TODO: req check for OE
                                if (dolocalstats)
                                {
                                    if (!tosocialtab)
                                    {
                                        ch.Stats.SetPercentageModifier((Int32)func.Arguments[0], ch.Stats.GetPercentageModifier((Int32)func.Arguments[0]) + (Int32)func.Arguments[1]);
                                    }
                                }
                                break;
                            case ItemHandler.functiontype_uploadnano:
                                ch.UploadNano((Int32)func.Arguments[0]);
                                Packets.UploadNanoupdate.Send(ch, 53019, (Int32)func.Arguments[0]);
                                break;
                            case ItemHandler.functiontype_shophash:
                                // Do nothing, it's covered in 
                                break;
                            default:
                                break;
                        }
                    }
                }
                return false;
            }
Пример #7
0
        /// <summary>
        /// Switch item placements
        /// TODO: catch exceptions
        /// </summary>
        /// <param name="cli">Client</param>
        /// <param name="_from">From location</param>
        /// <param name="_to">To location</param>
        public void switchItems(Client cli, int _from, int _to)
        {
            lock (cli)
            {
                SqlWrapper mySql = new SqlWrapper();
                InventoryEntries afrom = getInventoryAt(_from);
                InventoryEntries ato = getInventoryAt(_to);
                if (afrom != null)
                {
                    afrom.Placement = _to;
                }
                if (ato != null)
                {
                    ato.Placement = _from;
                }

                mySql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + "inventory SET placement=255 where (ID=" + cli.Character.ID.ToString() + ") AND (placement=" + _from.ToString() + ")");
                mySql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + "inventory SET placement=" + _from.ToString() + " where (ID=" + cli.Character.ID.ToString() + ") AND (placement=" + _to.ToString() + ")");
                mySql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + "inventory SET placement=" + _to.ToString() + " where (ID=" + cli.Character.ID.ToString() + ") AND (placement=255)");
            }

            // If its a switch from or to equipment pages then recalculate the skill modifiers
            if ((_from < 64) || (_to < 64))
            {
                CalculateSkills();
            }
        }
 public new void AddToDB()
 {
     SqlWrapper Sql = new SqlWrapper();
     Sql.SqlInsert("INSERT INTO " + getSQLTablefromDynelType() + " (ID, Playfield) VALUES (" + ID.ToString() + "," + PlayField.ToString() + ")");
     writeCoordinatestoSQL();
     writeHeadingtoSQL();
     Sql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + " SET TemplateID=" + TemplateID.ToString() + ", Hash='" + HASH + "' WHERE ID=" + ID.ToString() + " AND playfield=" + PlayField.ToString());
 }
 public static void SetOnline(int id)
 {
     SqlWrapper sql = new SqlWrapper();
     sql.SqlUpdate("UPDATE characters SET Online = 1 WHERE ID = " + id + ";");
 }
Пример #10
0
        public static void lintels()
        {
            SqlWrapper ms = new SqlWrapper();
            List<lintel> doors = new List<lintel>();
            lintel ll;
            ms.SqlRead("SELECT * FROM doors");

            #region MySql
            if (ms.ismysql)
            {
                while (ms.myreader.Read())
                {
                    ll = new lintel();
                    ll.ID = ms.myreader.GetInt32("ID");
                    ll.X = ms.myreader.GetFloat("X");
                    ll.Y = ms.myreader.GetFloat("Y");
                    ll.Z = ms.myreader.GetFloat("Z");
                    ll.HZ = ms.myreader.GetFloat("HZ");
                    ll.frompf = ms.myreader.GetInt32("playfield");
                    ll.topf = ms.myreader.GetInt32("toplayfield");
                    ll.toid = ms.myreader.GetInt32("toid");
                    ll.proxy = ms.myreader.GetInt32("proxy");
                    doors.Add(ll);
                }
                ms.myreader.Close();
                ms.mcc.Close();
                ms.mcc.Dispose();
            }
            #endregion

            #region MsSql
            if (ms.ismssql)
            {
                while (ms.sqlreader.Read())
                {
                    ll = new lintel();
                    ll.ID = ms.sqlreader.GetInt32(0);
                    ll.X = ms.sqlreader.GetFloat(1);
                    ll.Y = ms.sqlreader.GetFloat(2);
                    ll.Z = ms.sqlreader.GetFloat(3);
                    ll.HZ = ms.sqlreader.GetFloat(4);
                    ll.frompf = ms.sqlreader.GetInt32(5);
                    ll.topf = ms.sqlreader.GetInt32(6);
                    ll.toid = ms.sqlreader.GetInt32(7);
                    ll.proxy = ms.sqlreader.GetInt32(8);
                    doors.Add(ll);
                }
                ms.sqlreader.Close();
                ms.sqlcc.Close();
                ms.sqlcc.Dispose();
            }
            #endregion

            #region PostgreSql
            if (ms.isnpgsql)
            {
                while (ms.npgreader.Read())
                {
                    ll = new lintel();
                    ll.ID = ms.npgreader.GetInt32(0);
                    ll.X = ms.npgreader.GetFloat(1);
                    ll.Y = ms.npgreader.GetFloat(2);
                    ll.Z = ms.npgreader.GetFloat(3);
                    ll.HZ = ms.npgreader.GetFloat(4);
                    ll.frompf = ms.npgreader.GetInt32(5);
                    ll.topf = ms.npgreader.GetInt32(6);
                    ll.toid = ms.npgreader.GetInt32(7);
                    ll.proxy = ms.npgreader.GetInt32(8);
                    doors.Add(ll);
                }
                ms.npgreader.Close();
                ms.npgcc.Close();
                ms.npgcc.Dispose();
            }
            #endregion

            bool found;
            foreach (lintel l1 in doors)
            {
                found = false;
                foreach (lintel l2 in doors)
                {
                    if (l1.ID != l2.ID)
                    {
                        if (l1.topf != 0)
                        {
                            if ((l1.frompf == l2.topf) && (l1.topf == l2.frompf))
                            {
                                found = true;
                                l1.toid = l2.ID;
                                ms.SqlUpdate(
                                    "UPDATE doors set toid=" + l2.ID.ToString() + " where id=" + l1.ID.ToString());
                                Console.WriteLine(l1.ID.ToString());
                            }
                            else if ((l1.topf == l2.frompf) && (l2.topf == 0))
                            {
                                l1.toid = l2.ID;
                                ms.SqlUpdate(
                                    "UPDATE doors set toid=" + l2.ID.ToString() + " where id=" + l1.ID.ToString());
                                Console.WriteLine(l1.ID.ToString());
                            }
                        }
                    }
                }
                if (!found)
                {
                    ms.SqlUpdate("UPDATE doors SET proxy=1 where ID=" + l1.ID.ToString());
                }
            }
        }
 public static void UpdateDoorHeading(Client cli)
 {
     SqlWrapper ms = new SqlWrapper();
     Doors door = DoorinRange(cli.Character.PlayField, cli.Character.Coordinates, 4.0f);
     if (door == null)
     {
         cli.SendChatText("No door in range to align");
         return;
     }
     cli.SendChatText(
         string.Format("Door {0} Heading before: {1} {2} {3} {4}", door.ID, door.hX, door.hY, door.hZ, door.hW));
     AOCoord a = new AOCoord
         {
             x = cli.Character.Coordinates.x - door.Coordinates.x,
             y = cli.Character.Coordinates.y - door.Coordinates.y,
             z = cli.Character.Coordinates.z - door.Coordinates.z
         };
     Quaternion q = new Quaternion(a.x, a.y, a.z, 0);
     cli.SendChatText(string.Format("Door {0} Heading now: {1} {2} {3} {4}", door.ID, q.x, q.y, q.z, q.w));
     ms.SqlUpdate(
         "UPDATE doors SET HX=" + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.x) + ", HY="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.y) + ", HZ="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.z) + ", HW="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.w) + " WHERE ID=" + door.ID + ";");
     door.hX = (float)q.x;
     door.hY = (float)q.y;
     door.hZ = (float)q.z;
     door.hW = (float)q.w;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="client"></param>
        /// <param name="startInSL"></param>
        /// <param name="charid"></param>
        public void SendNameToStartPlayfield(Client client, bool startInSL, Int32 charid)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);
            SqlWrapper ms = new SqlWrapper();

            /* set startplayfield */
            string sqlUpdate = "UPDATE `characters` set ";

            if (startInSL)
            {
                sqlUpdate += "`playfield`=4001,`X`=850,`Y`=43,`Z`=565 ";
            }
            else
            {
                sqlUpdate += "`playfield`=4582,`X`=939,`Y`=20,`Z`=732 ";
            }
            sqlUpdate += " where `ID` = " + charid;

            ms.SqlUpdate(sqlUpdate);

            writer.Write(
                new byte[]
                    {
                        0xDF, 0xDF, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, /* msg size - 2 byte */
                        0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0xff, /* possible timecode */
                        0x00, 0x00, 0x00, 0x11 /* answer 0x11, char_id */
                    });
            writer.Write(IPAddress.HostToNetworkOrder(charid));
            writer.Write(new byte[] { 0xb0, 0xd2, 0xff, 0xff }); /* unknown */
            writer.Flush();
            stream.Capacity = (int)stream.Length;
            byte[] reply = stream.GetBuffer();
            writer.Close();
            stream.Dispose();
            /* insert size */
            byte[] packetlength = BitConverter.GetBytes(reply.Length);
            reply[7] = packetlength[0];

            /* send response */
            client.Send(reply);
        }
Пример #13
0
 public new void writeCoordinatestoSQL()
 {
     SqlWrapper Sql = new SqlWrapper();
     Sql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + " SET playfield=" + PlayField.ToString() + ", X=" +
         String.Format(System.Globalization.CultureInfo.InvariantCulture, "'{0}'", Coordinates.x) + ", Y=" +
         String.Format(System.Globalization.CultureInfo.InvariantCulture, "'{0}'", Coordinates.y) + ", Z=" +
         String.Format(System.Globalization.CultureInfo.InvariantCulture, "'{0}'", Coordinates.z) + " WHERE ID=" + ID.ToString() + ";");
 }
Пример #14
0
        public void writeMainStatstoSQL()
        {
            string sqlquery = "UPDATE " + getSQLTablefromDynelType() + " SET Name='" + AddSlashes(Name) + "'";
            foreach (AOTextures at in Textures)
            {
                sqlquery += ",Textures" + at.place.ToString() + "=" + at.Texture.ToString();
            }
            sqlquery += " WHERE ID="+ID.ToString();

            SqlWrapper Sql = new SqlWrapper();
            Sql.SqlUpdate(sqlquery);
        }
Пример #15
0
        static void Main(string[] args)
        {
            #region Console Texts...


            Console.Title = "CellAO " + AssemblyInfoclass.Title + " Console. Version: " + AssemblyInfoclass.Description + " " + AssemblyInfoclass.AssemblyVersion;
            ConsoleText ct = new ConsoleText();
            ct.TextRead("main.txt");
            Console.WriteLine("Loading " + AssemblyInfoclass.Title + "...");
            if (ismodified())
            {
                Console.WriteLine("Your " + AssemblyInfoclass.Title + " was compiled from modified source code.");
            }
            else
            if (ismixed())
            {
                Console.WriteLine("Your " + AssemblyInfoclass.Title + " uses mixed SVN revisions.");
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("[OK]");
            Console.ResetColor();

            #endregion
            //Sying helped figure all this code out, about 5 yearts ago! :P
            bool processedargs = false;
            LoginServer           = new Server();
            LoginServer.EnableTCP = true;
            LoginServer.EnableUDP = false;
            try { LoginServer.TcpIP = IPAddress.Parse(ConfigReadWrite.Instance.CurrentConfig.ListenIP); }
            catch { ct.TextRead("ip_config_parse_error.txt"); Console.ReadKey(); return; }
            LoginServer.TcpPort = Convert.ToInt32(ConfigReadWrite.Instance.CurrentConfig.LoginPort);

            #region NLog

            LoggingConfiguration config        = new LoggingConfiguration();
            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
            consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
            FileTarget fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);
            fileTarget.FileName = "${basedir}/LoginEngineLog.txt";
            fileTarget.Layout   = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
            LoggingRule rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget);
            config.LoggingRules.Add(rule1);
            LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
            config.LoggingRules.Add(rule2);
            LogManager.Configuration = config;

            #endregion

            LoginServer.MaximumPendingConnections = 100;

            #region Console Commands
            //Andyzweb: Added checks for start and stop
            //also added a running command to return status of the server
            //and added Console.Write("\nServer Command >>"); to login server
            string consoleCommand;
            ct.TextRead("login_consolecommands.txt");
            while (true)
            {
                if (!processedargs)
                {
                    if (args.Length == 1)
                    {
                        if (args[0].ToLower() == "/autostart")
                        {
                            ct.TextRead("autostart.txt");
                            ThreadMgr.Start();
                            LoginServer.Start();
                        }
                    }
                    processedargs = true;
                }
                Console.Write("\nServer Command >>");

                consoleCommand = Console.ReadLine();
                string temp = "";
                while (temp != consoleCommand)
                {
                    temp           = consoleCommand;
                    consoleCommand = consoleCommand.Replace("  ", " ");
                }
                consoleCommand = consoleCommand.Trim();
                switch (consoleCommand.ToLower())
                {
                case "start":
                    if (LoginServer.Running)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        ct.TextRead("loginisrunning.txt");
                        Console.ResetColor();
                        break;
                    }
                    ThreadMgr.Start();
                    LoginServer.Start();
                    break;

                case "stop":
                    if (!LoginServer.Running)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        ct.TextRead("loginisnotrunning.txt");
                        Console.ResetColor();
                        break;
                    }
                    ThreadMgr.Stop();
                    LoginServer.Stop();
                    break;

                case "exit":
                    Process.GetCurrentProcess().Kill();
                    break;

                case "running":
                    if (LoginServer.Running)
                    {
                        //Console.WriteLine("Login Server is running");
                        ct.TextRead("loginisrunning.txt");
                        break;
                    }
                    //Console.WriteLine("Login Server not running");
                    ct.TextRead("loginisnotrunning.txt");
                    break;

                    #region Help Commands....
                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;

                    #endregion
                default:

                    #region Adduser
                    //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.\nPlease use:\nAdduser <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]);
                            if (expansions < 0 || expansions > 2047)
                            {
                                throw new Exception();
                            }
                        }
                        catch { 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].ToString();
                        try
                        {
                            if (email == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch { Console.WriteLine("Error: <Email> You must supply an email address for this account"); break; }
                        string firstname = parts[7].ToString();
                        try
                        {
                            if (firstname == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch { Console.WriteLine("Error: <FirstName> You must supply a first name for this accout"); break; }
                        string lastname = parts[8].ToString();
                        try
                        {
                            if (lastname == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch { Console.WriteLine("Error: <LastName> You must supply a last name for this account"); break; }

                        string formatString;
                        formatString = "INSERT INTO `login` (`CreationDate`, `Flags`,`AccountFlags`,`Username`,`Password`,`Allowed_Characters`,`Expansions`, `GM`, `Email`, `FirstName`, `LastName`) VALUES " + "(NOW(), '0', '0', '{0}', '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}');";

                        LoginEncryption le = new LoginEncryption();

                        string hashedPassword = le.GeneratePasswordHash(password);

                        string sql =
                            String.Format(formatString,
                                          username, hashedPassword, numChars, expansions, gm, email, firstname, lastname);
                        AO.Core.SqlWrapper wrp = new AO.Core.SqlWrapper();
                        try
                        {
                            wrp.SqlInsert(sql);
                        }
                        catch (MySql.Data.MySqlClient.MySqlException ex)
                        {
                            switch (ex.Number)
                            {
                            case 1062:         //duplicate entry for key
                                Console.WriteLine("A user account with this username already exists.");
                                break;

                            default:
                                Console.WriteLine("An error occured while trying to add a new user account:\n{0}", ex.Message);
                                break;
                            }
                            break;
                        }
                        Console.WriteLine("User added successfully.");
                        break;
                    }
                    #endregion

                    #region Hashpass
                    //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];
                        LoginEncryption le     = new LoginEncryption();
                        string          hashed = le.GeneratePasswordHash(pass);
                        Console.WriteLine(hashed);
                        break;
                    }
                    #endregion

                    #region setpass
                    //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];
                        LoginEncryption le       = new LoginEncryption();
                        string          hashed   = le.GeneratePasswordHash(newpass);
                        string          formatString;
                        formatString = "UPDATE `login` SET Password = '******' WHERE login.Username = '******'";

                        string sql =
                            String.Format(formatString, hashed, username);

                        AO.Core.SqlWrapper updt = new AO.Core.SqlWrapper();
                        try
                        {
                            updt.SqlUpdate(sql);
                        }
                        //yeah this part here, some kind of exception handling for mysql errors
                        catch { }
                    }
                    #endregion

                    ct.TextRead("login_consolecmdsdefault.txt");
                    break;
                }
            }
            #endregion
        }
Пример #16
0
 /// <summary>
 /// Write Textures to Sql Table
 /// </summary>
 public void WriteTexturesToSql()
 {
     SqlWrapper sqlWrapper = new SqlWrapper();
     int count;
     string upd = "";
     for (count = 0; count < this.Textures.Count; count++)
     {
         upd += "textures" + this.Textures[count].place.ToString() + "="
                + this.Textures[count].Texture.ToString();
         if (count < this.Textures.Count - 1)
         {
             upd += ", ";
         }
     }
     sqlWrapper.SqlUpdate(
         "UPDATE " + this.GetSqlTablefromDynelType() + " SET " + upd + " WHERE ID=" + this.Id.ToString() + ";");
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="client"></param>
        public static void Read(byte[] packet, Client client)
        {
            PacketReader reader = new PacketReader(packet);

            Header header = reader.PopHeader();
            reader.PopByte();
            byte cmd = reader.PopByte();
            Identity target = reader.PopIdentity();
            int unknown = reader.PopInt();
            string cmdStr = "";
            byte CmdByte = 0;

            #region cmd args
            switch (cmd)
            {
                case 1:
                case 7:
                case 9:
                case 13:
                case 17:
                case 19:
                case 20:
                case 21:
                case 23:
                case 24:
                case 25:
                case 26:
                case 27:
                case 28:
                    short cmdStrLen = reader.PopShort();
                    cmdStr = reader.PopString(cmdStrLen);
                    break;
                case 10:
                    CmdByte = reader.PopByte();
                    break;
                default:
                    break;
            }
            reader.Finish();
            #endregion

            SqlWrapper ms = new SqlWrapper();
            DataTable dt;

            #region cmd handlers
            switch (cmd)
            {
                    #region /org create <name>
                case 1:
                    {
                        // org create
                        /* client wants to create organization
                         * name of org is CmdStr
                         */

                        string sqlQuery = "SELECT * FROM organizations WHERE Name='" + cmdStr + "'";
                        string guildName = null;
                        uint orgID = 0;
                        dt = ms.ReadDatatable(sqlQuery);
                        if (dt.Rows.Count > 0)
                        {
                            guildName = (string)dt.Rows[0]["Name"];
                        }

                        if (guildName == null)
                        {
                            client.SendChatText("You have created the guild: " + cmdStr);

                            string currentDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            string sqlQuery2 =
                                "INSERT INTO organizations (Name, creation, LeaderID, GovernmentForm) VALUES ('"
                                + cmdStr + "', '" + currentDate + "', '" + client.Character.Id + "', '0')";
                            ms.SqlInsert(sqlQuery2);
                            string sqlQuery3 = "SELECT * FROM organizations WHERE Name='" + cmdStr + "'";
                            dt = ms.ReadDatatable(sqlQuery3);
                            if (dt.Rows.Count > 0)
                            {
                                orgID = (UInt32)dt.Rows[0]["ID"];
                            }

                            // Make sure the order of these next two lines is not swapped -NV
                            client.Character.Stats.ClanLevel.Set(0);
                            client.Character.OrgId = orgID;
                            break;
                        }
                        else
                        {
                            client.SendChatText("This guild already <font color=#DC143C>exists</font>");
                            break;
                        }
                    }
                    #endregion

                    #region /org ranks
                case 2:
                    // org ranks
                    //Displays Org Rank Structure.
                    /* Select governingform from DB, Roll through display from GovForm */
                    if (client.Character.OrgId == 0)
                    {
                        client.SendChatText("You're not in an organization!");
                        break;
                    }
                    string ranksSql = "SELECT GovernmentForm FROM organizations WHERE ID = " + client.Character.OrgId;
                    int governingForm = -1;
                    dt = ms.ReadDatatable(ranksSql);
                    if (dt.Rows.Count > 0)
                    {
                        governingForm = (Int32)dt.Rows[0]["GovernmentForm"];
                    }
                    client.SendChatText("Current Rank Structure: " + GetRankList(governingForm));
                    break;
                    #endregion

                    #region /org contract
                case 3:
                    // org contract
                    break;
                    #endregion

                    #region unknown org command 4
                case 4:
                    Console.WriteLine("Case 4 Started");
                    break;
                    #endregion

                    #region /org info
                case 5:
                    {
                        Client tPlayer = null;
                        if ((tPlayer = FindClient.FindClientById(target.Instance)) != null)
                        {
                            string orgDescription = "", orgObjective = "", orgHistory = "", orgLeaderName = "";
                            int orgGoverningForm = 0, orgLeaderID = 0;
                            dt = ms.ReadDatatable("SELECT * FROM organizations WHERE ID=" + tPlayer.Character.OrgId);

                            if (dt.Rows.Count > 0)
                            {
                                orgDescription = (string)dt.Rows[0]["Description"];
                                orgObjective = (string)dt.Rows[0]["Objective"];
                                orgHistory = (string)dt.Rows[0]["History"];
                                orgGoverningForm = (Int32)dt.Rows[0]["GovernmentForm"];
                                orgLeaderID = (Int32)dt.Rows[0]["LeaderID"];
                            }

                            dt = ms.ReadDatatable("SELECT Name FROM characters WHERE ID=" + orgLeaderID);
                            if (dt.Rows.Count > 0)
                            {
                                orgLeaderName = (string)dt.Rows[0][0];
                            }

                            string textGovForm = null;
                            if (orgGoverningForm == 0)
                            {
                                textGovForm = "Department";
                            }
                            else if (orgGoverningForm == 1)
                            {
                                textGovForm = "Faction";
                            }
                            else if (orgGoverningForm == 2)
                            {
                                textGovForm = "Republic";
                            }
                            else if (orgGoverningForm == 3)
                            {
                                textGovForm = "Monarchy";
                            }
                            else if (orgGoverningForm == 4)
                            {
                                textGovForm = "Anarchism";
                            }
                            else if (orgGoverningForm == 5)
                            {
                                textGovForm = "Feudalism";
                            }
                            else
                            {
                                textGovForm = "Department";
                            }
                            string orgRank = GetRank(orgGoverningForm, tPlayer.Character.Stats.ClanLevel.StatBaseValue);
                            PacketWriter packetWriter = new PacketWriter();
                            packetWriter.PushBytes(new byte[] { 0xDF, 0xDF });
                            packetWriter.PushShort(10);
                            packetWriter.PushShort(1);
                            packetWriter.PushShort(0);
                            packetWriter.PushInt(3086);
                            packetWriter.PushInt(client.Character.Id);
                            packetWriter.PushInt(0x64582A07);
                            packetWriter.PushIdentity(50000, tPlayer.Character.Id);
                            packetWriter.PushByte(0);
                            packetWriter.PushByte(2); // OrgServer case 0x02 (Org Info)
                            packetWriter.PushInt(0);
                            packetWriter.PushInt(0);
                            packetWriter.PushInt(0xDEAA); // Type (org)
                            packetWriter.PushUInt(tPlayer.Character.OrgId); // org ID
                            packetWriter.PushShort((short)tPlayer.Character.OrgName.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(tPlayer.Character.OrgName));
                            packetWriter.PushShort((short)orgDescription.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgDescription));
                            packetWriter.PushShort((short)orgObjective.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgObjective));
                            packetWriter.PushShort((short)orgHistory.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgHistory));
                            packetWriter.PushShort((short)textGovForm.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(textGovForm));
                            packetWriter.PushShort((short)orgLeaderName.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgLeaderName));
                            packetWriter.PushShort((short)orgRank.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgRank));
                            packetWriter.Push3F1Count(0);
                            byte[] reply = packetWriter.Finish();

                            client.SendCompressed(reply);
                        }
                    }
                    break;
                    #endregion

                    #region /org disband
                case 6:
                    break;
                    #endregion

                    #region /org startvote <text> <duration> <entries>
                case 7:
                    // org startvote <"text"> <duration(minutes)> <entries>
                    // arguments (<text> <duration> and <entries>) are in CmdStr
                    break;
                    #endregion

                    #region /org vote info
                case 8:
                    // org vote info
                    break;
                    #endregion

                    #region /org vote <entry>
                case 9:
                    // <entry> is CmdStr
                    break;
                    #endregion

                    #region /org promote
                case 10:
                    {
                        // some arg in CmdByte. No idea what it is

                        //create the target namespace t_promote
                        Client toPromote = null;
                        string promoteSql = "";
                        int targetOldRank = -1;
                        int targetNewRank = -1;
                        int newPresRank = -1;
                        int oldPresRank = 0;
                        if ((toPromote = FindClient.FindClientById(target.Instance)) != null)
                        {
                            //First we check if target is in the same org as you
                            if (toPromote.Character.OrgId != client.Character.OrgId)
                            {
                                //not in same org
                                client.SendChatText("Target is not in your organization!");
                                break;
                            }
                            //Target is in same org, are you eligible to promote?  Promoter Rank has to be TargetRank-2 or == 0
                            if ((client.Character.Stats.ClanLevel.Value
                                 == (toPromote.Character.Stats.ClanLevel.Value - 2))
                                || (client.Character.Stats.ClanLevel.Value == 0))
                            {
                                //Promoter is eligible. Start the process

                                //First we get the details about the org itself
                                promoteSql = "SELECT * FROM organizations WHERE ID = " + client.Character.OrgId;
                                dt = ms.ReadDatatable(promoteSql);

                                int promoteGovForm = -1;
                                string promotedToRank = "";
                                string demotedFromRank = "";

                                if (dt.Rows.Count > 0)
                                {
                                    promoteGovForm = (Int32)dt.Rows[0]["GovernmentForm"];
                                }

                                //Check if new rank == 0, if so, demote promoter
                                if ((targetOldRank - 1) == 0)
                                {
                                    /* This is a bit more complex.  Here we need to promote new president first
                                         * then we go about demoting old president
                                         * finally we set the new leader in Sql
                                         * Reset OrgName to set changes
                                         */

                                    // Set new President's Rank
                                    targetOldRank = toPromote.Character.Stats.ClanLevel.Value;
                                    targetNewRank = targetOldRank - 1;
                                    promotedToRank = GetRank(promoteGovForm, (uint)targetNewRank);
                                    toPromote.Character.Stats.ClanLevel.Set(targetNewRank);
                                    // Demote the old president
                                    oldPresRank = client.Character.Stats.ClanLevel.Value;
                                    newPresRank = oldPresRank + 1;
                                    demotedFromRank = GetRank(promoteGovForm, (uint)newPresRank);
                                    client.Character.Stats.ClanLevel.Set(newPresRank);
                                    //Change the leader id in Sql
                                    string newLeadSql = "UPDATE organizations SET LeaderID = " + toPromote.Character.Id
                                                        + " WHERE ID = " + toPromote.Character.OrgId;
                                    ms.SqlUpdate(newLeadSql);
                                    client.SendChatText(
                                        "You've passed leadership of the organization to: " + toPromote.Character.Name);
                                    toPromote.SendChatText(
                                        "You've been promoted to the rank of " + promotedToRank + " by "
                                        + client.Character.Name);
                                    break;
                                }
                                else
                                {
                                    //Just Promote
                                    targetOldRank = toPromote.Character.Stats.ClanLevel.Value;
                                    targetNewRank = targetOldRank - 1;
                                    promotedToRank = GetRank(promoteGovForm, (uint)targetNewRank);
                                    toPromote.Character.Stats.ClanLevel.Set(targetNewRank);
                                    client.SendChatText(
                                        "You've promoted " + toPromote.Character.Name + " to " + promotedToRank);
                                    toPromote.SendChatText(
                                        "You've been promoted to the rank of " + promotedToRank + " by "
                                        + client.Character.Name);
                                }
                            }
                            else
                            {
                                //Promoter not eligible to promote
                                client.SendChatText(
                                    "Your Rank is not high enough to promote " + toPromote.Character.Name);
                                break;
                            }
                        }
                        break;
                    }
                    #endregion

                    #region /org demote
                case 11:
                    // demote target player
                    //create the target namespace t_demote
                    Client toDemote = null;
                    string demoteSql = "";
                    int targetCurRank = -1;
                    int targetNewerRank = -1;
                    if ((toDemote = FindClient.FindClientById(target.Instance)) != null)
                    {
                        //First we check if target is in the same org as you
                        if (toDemote.Character.OrgId != client.Character.OrgId)
                        {
                            //not in same org
                            client.SendChatText("Target is not in your organization!");
                            break;
                        }
                        //Target is in same org, are you eligible to demote?  Promoter Rank has to be TargetRank-2 or == 0
                        if ((client.Character.Stats.GMLevel.Value == (toDemote.Character.Stats.ClanLevel.Value - 2))
                            || (client.Character.Stats.ClanLevel.Value == 0))
                        {
                            //Promoter is eligible. Start the process

                            //First we get the details about the org itself
                            demoteSql = "SELECT GovernmentForm FROM organizations WHERE ID = " + client.Character.OrgId;
                            dt = ms.ReadDatatable(demoteSql);
                            int demoteGovForm = -1;
                            string demotedToRank = "";
                            if (dt.Rows.Count > 0)
                            {
                                demoteGovForm = (Int32)dt.Rows[0]["GovernmentForm"];
                            }

                            //Check whether new rank would be lower than lowest for current govform
                            if ((targetCurRank + 1) > GetLowestRank(demoteGovForm))
                            {
                                client.SendChatText("You can't demote character any lower!");
                                break;
                            }
                            targetCurRank = toDemote.Character.Stats.GMLevel.Value;
                            targetNewerRank = targetCurRank + 1;
                            demotedToRank = GetRank(demoteGovForm, (uint)targetNewerRank);
                            toDemote.Character.Stats.ClanLevel.Set(targetNewerRank);
                            client.SendChatText("You've demoted " + toDemote.Character.Name + " to " + demotedToRank);
                            toDemote.SendChatText(
                                "You've been demoted to the rank of " + demotedToRank + " by " + client.Character.Name);
                            break;
                        }
                        else
                        {
                            //Promoter not eligible to promote
                            client.SendChatText("Your Rank is not high enough to demote " + toDemote.Character.Name);
                            break;
                        }
                    }
                    break;
                    #endregion

                    #region unknown org command 12
                case 12:
                    Console.WriteLine("Case 12 Started");
                    break;
                    #endregion

                    #region /org kick <name>
                case 13:
                    // kick <name> from org
                    // <name> is CmdStr

                    //create the t_player Client namespace, using CmdStr to find character id, in replacement of target.Instance
                    uint kickedFrom = client.Character.OrgId;
                    string kickeeSql = "SELECT * FROM characters WHERE Name = '" + cmdStr + "'";
                    int kickeeId = 0;
                    dt = ms.ReadDatatable(kickeeSql);
                    if (dt.Rows.Count > 0)
                    {
                        kickeeId = (Int32)dt.Rows[0]["ID"];
                    }

                    Client targetPlayer = null;
                    if ((targetPlayer = FindClient.FindClientById(kickeeId)) != null)
                    {
                        //Check if CmdStr is actually part of the org
                        uint kickeeOrgId = targetPlayer.Character.OrgId;
                        if (kickeeOrgId != client.Character.OrgId)
                        {
                            //Not part of Org. break out.
                            client.SendChatText(cmdStr + "is not a member of your organization!");
                            break;
                        }

                        //They are part of the org, so begin the processing...
                        //First we check if the player is online...
                        string onlineSql = "SELECT online FROM characters WHERE ID = " + client.Character.Id;
                        dt = ms.ReadDatatable(onlineSql);
                        int onlineStatus = 0;
                        if (dt.Rows.Count > 0)
                        {
                            onlineStatus = (Int32)dt.Rows[0][0];
                        }

                        if (onlineStatus == 0)
                        {
                            //Player isn't online. Org Kicks are processed in a different method
                            // TODO: Offline Org KICK
                            break;
                        }

                        //Player is online. Start the kick.
                        targetPlayer.Character.Stats.ClanLevel.Set(0);
                        targetPlayer.Character.OrgId = 0;
                        string kickedFromSql = "SELECT Name FROM organizations WHERE ID = " + client.Character.OrgId;
                        dt = ms.ReadDatatable(kickedFromSql);
                        string kickedFromName = "";
                        if (dt.Rows.Count > 0)
                        {
                            kickedFromName = (string)dt.Rows[0][0];
                        }
                        targetPlayer.SendChatText("You've been kicked from the organization " + kickedFromName);
                    }
                    // TODO: Offline Org KICK
                    break;
                    #endregion

                    #region /org invite
                case 14:
                    {
                        Client tPlayer = null;
                        if ((tPlayer = FindClient.FindClientById(target.Instance)) != null)
                        {
                            PacketWriter writer = new PacketWriter();
                            writer.PushBytes(new byte[] { 0xDF, 0xDF });
                            writer.PushShort(10);
                            writer.PushShort(1);
                            writer.PushShort(0);
                            writer.PushInt(3086); //Sender
                            writer.PushInt(tPlayer.Character.Id); //Receiver
                            writer.PushInt(0x64582A07); //Packet ID
                            writer.PushIdentity(50000, tPlayer.Character.Id); //Target Identity
                            writer.PushByte(0);
                            writer.PushByte(5); //OrgServer Case 0x05 (Invite)
                            writer.PushInt(0);
                            writer.PushInt(0);
                            writer.PushIdentity(0xDEAA, (int)client.Character.OrgId); // Type (org)
                            writer.PushShort((short)client.Character.OrgName.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(client.Character.OrgName));
                            writer.PushInt(0);
                            byte[] reply = writer.Finish();

                            tPlayer.SendCompressed(reply);
                        }
                    }
                    break;
                    #endregion

                    #region Org Join
                case 15:
                    {
                        //target.Instance holds the OrgID of the Org wishing to be joined.
                        int orgIdtoJoin = target.Instance;
                        string JoinSql = "SELECT * FROM organizations WHERE ID = '" + orgIdtoJoin + "' LIMIT 1";
                        int gov_form = 0;
                        dt = ms.ReadDatatable(JoinSql);
                        if (dt.Rows.Count > 0)
                        {
                            gov_form = (Int32)dt.Rows[0]["GovernmentForm"];
                        }

                        // Make sure the order of these next two lines is not swapped -NV
                        client.Character.Stats.ClanLevel.Set(GetLowestRank(gov_form));
                        client.Character.OrgId = (uint)orgIdtoJoin;
                    }
                    break;
                    #endregion

                    #region /org leave
                case 16:
                    // org leave
                    // TODO: Disband org if it was leader that left org. -Suiv-
                    // I don't think a Disband happens if leader leaves. I don't think leader -can- leave without passing lead to another
                    // Something worth testing on Testlive perhaps ~Chaz
                    // Just because something happens on TL, doesnt mean its a good idea. Really tbh id prefer it if you had to explicitly type /org disband to disband rather than /org leave doing it... -NV
                    // Agreeing with NV.  Org Leader can't leave without passing lead on.  org disband requires /org disband to specifically be issued, with a Yes/No box.
                    string LeaveSql = "SELECT * FROM organizations WHERE ID = " + client.Character.OrgId;
                    int govern_form = 0;
                    dt = ms.ReadDatatable(LeaveSql);
                    if (dt.Rows.Count > 0)
                    {
                        govern_form = (Int32)dt.Rows[0]["GovernmentForm"];
                    }

                    if ((client.Character.Stats.ClanLevel.Value == 0) && (govern_form != 4))
                    {
                        client.SendChatText(
                            "Organization Leader cannot leave organization without Disbanding or Passing Leadership!");
                    }
                    else
                    {
                        client.Character.OrgId = 0;
                        client.SendChatText("You left the guild");
                    }
                    break;
                    #endregion

                    #region /org tax | /org tax <tax>
                case 17:
                    // gets or sets org tax
                    // <tax> is CmdStr
                    // if no <tax>, then just send chat text with current tax info

                    if (cmdStr == null)
                    {
                        client.SendChatText("The current organization tax rate is: ");
                        break;
                    }
                    else
                    {
                        break;
                    }
                    #endregion

                    #region /org bank
                case 18:
                    {
                        // org bank
                        dt = ms.ReadDatatable("SELECT * FROM organizations WHERE ID=" + client.Character.OrgId);
                        if (dt.Rows.Count > 0)
                        {
                            UInt64 bank_credits = (UInt64)dt.Rows[0]["Bank"];
                            client.SendChatText("Your bank has " + bank_credits + " credits in its account");
                        }
                    }
                    break;
                    #endregion

                    #region /org bank add <cash>
                case 19:
                    {
                        if (client.Character.OrgId == 0)
                        {
                            client.SendChatText("You are not in an organisation.");

                            break;
                        }

                        // org bank add <cash>
                        int minuscredits_fromplayer = Convert.ToInt32(cmdStr);
                        int characters_credits = client.Character.Stats.Cash.Value;

                        if (characters_credits < minuscredits_fromplayer)
                        {
                            client.SendChatText("You do not have enough Credits");
                        }
                        else
                        {
                            int total_Creditsspent = characters_credits - minuscredits_fromplayer;
                            client.Character.Stats.Cash.Set(total_Creditsspent);

                            ms.SqlUpdate(
                                "UPDATE `organizations` SET `Bank` = `Bank` + " + minuscredits_fromplayer
                                + " WHERE `ID` = " + client.Character.OrgId);
                            client.SendChatText("You have donated " + minuscredits_fromplayer + " to the organization");
                        }
                    }

                    break;
                    #endregion

                    #region /org bank remove <cash>
                case 20:
                    // org bank remove <cash>
                    // <cash> is CmdStr
                    // player wants to take credits from org bank
                    // only leader can do that
                    if ((client.Character.Stats.ClanLevel.Value != 0) || (client.Character.OrgId == 0))
                    {
                        client.SendChatText("You're not the leader of an Organization");
                        break;
                    }
                    int removeCredits = Convert.ToInt32(cmdStr);
                    long orgBank = 0;
                    dt = ms.ReadDatatable("SELECT Bank FROM organizations WHERE ID = " + client.Character.OrgId);
                    if (dt.Rows.Count > 0)
                    {
                        orgBank = (Int64)dt.Rows[0][0];
                    }
                    if (removeCredits > orgBank)
                    {
                        client.SendChatText("Not enough credits in Organization Bank!");
                        break;
                    }
                    else
                    {
                        long neworgbank = orgBank - removeCredits;
                        int existingcreds = 0;
                        existingcreds = client.Character.Stats.Cash.Value;
                        int newcreds = existingcreds + removeCredits;
                        ms.SqlUpdate(
                            "UPDATE organizations SET Bank = " + neworgbank + " WHERE ID = " + client.Character.OrgId);
                        client.Character.Stats.Cash.Set(newcreds);
                        client.SendChatText("You've removed " + removeCredits + " credits from the organization bank");
                    }
                    break;
                    #endregion

                    #region /org bank paymembers <cash>
                case 21:
                    // <cash> is CmdStr
                    // give <cash> credits to every org member
                    // credits are taken from org bank
                    // only leader can do it
                    break;
                    #endregion

                    #region /org debt
                case 22:
                    // send player text about how big is his/her tax debt to org
                    break;
                    #endregion

                    #region /org history <text>
                case 23:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org history <history text>
                            ms.SqlUpdate(
                                "UPDATE organizations SET history = '" + cmdStr + "' WHERE ID = '"
                                + client.Character.OrgId + "'");
                            client.SendChatText("History Updated");
                        }
                        else
                        {
                            client.SendChatText("You must be the Organization Leader to perform this command!");
                        }
                    }
                    break;
                    #endregion

                    #region /org objective <text>
                case 24:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org objective <objective text>
                            ms.SqlUpdate(
                                "UPDATE organizations SET objective = '" + cmdStr + "' WHERE ID = '"
                                + client.Character.OrgId + "'");
                            client.SendChatText("Objective Updated");
                        }
                        else
                        {
                            client.SendChatText("You must be the Organization Leader to perform this command!");
                        }
                    }
                    break;
                    #endregion

                    #region /org description <text>
                case 25:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org description <description text>
                            ms.SqlUpdate(
                                "UPDATE organizations SET description = '" + cmdStr + "' WHERE ID = '"
                                + client.Character.OrgId + "'");
                            client.SendChatText("Description Updated");
                        }
                        else
                        {
                            client.SendChatText("You must be the Organization Leader to perform this command!");
                        }
                    }
                    break;
                    #endregion

                    #region /org name <text>
                case 26:
                    {
                        // org name <name>
                        /* Renames Organization
                         * Checks for Existing Orgs with similar name to stop crash
                         * Chaz
                         */
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            string SqlQuery26 = "SELECT * FROM organizations WHERE Name LIKE '" + cmdStr + "' LIMIT 1";
                            string CurrentOrg = null;
                            dt = ms.ReadDatatable(SqlQuery26);
                            if (dt.Rows.Count > 0)
                            {
                                CurrentOrg = (string)dt.Rows[0]["Name"];
                            }

                            if (CurrentOrg == null)
                            {
                                string SqlQuery27 = "UPDATE organizations SET Name = '" + cmdStr + "' WHERE ID = '"
                                                    + client.Character.OrgId + "'";
                                ms.SqlUpdate(SqlQuery27);
                                client.SendChatText("Organization Name Changed to: " + cmdStr);

                                // Forces reloading of org name and the like
                                // XXXX TODO: Make it reload for all other members in the org
                                client.Character.OrgId = client.Character.OrgId;
                                break;
                            }
                            else
                            {
                                client.SendChatText("An Organization already exists with that name");
                                break;
                            }
                        }
                        else
                        {
                            client.SendChatText("You must be the organization leader to perform this command!");
                        }
                        break;
                    }
                    #endregion

                    #region /org governingform <text>
                case 27:
                    {
                        // org governingform <form>
                        /* Current Governing Forms:
                         * Department, Faction, Republic, Monarchy, Anarchism, Feudalism
                         */
                        //Check on whether your President or not
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            //first we drop the case on the input, just to be sure.
                            Int32 GovFormNum = -1;
                            if (cmdStr == null)
                            {
                                //list gov forms
                                client.SendChatText(
                                    "List of Accepted Governing Forms is: department, faction, republic, monarchy, anarchism, feudalism");
                                break;
                            }
                            //was correct input passed?
                            switch (cmdStr.ToLower())
                            {
                                case "department":
                                    GovFormNum = 0;
                                    break;
                                case "faction":
                                    GovFormNum = 1;
                                    break;
                                case "republic":
                                    GovFormNum = 2;
                                    break;
                                case "monarchy":
                                    GovFormNum = 3;
                                    break;
                                case "anarchism":
                                    GovFormNum = 4;
                                    break;
                                case "feudalism":
                                    GovFormNum = 5;
                                    break;
                                default:
                                    client.SendChatText(cmdStr + " Is an invalid Governing Form!");
                                    client.SendChatText(
                                        "Accepted Governing Forms are: department, faction, republic, monarchy, anarchism, feudalism");
                                    break;
                            }
                            if (GovFormNum != -1)
                            {
                                ms.SqlUpdate(
                                    "UPDATE organizations SET GovernmentForm = '" + GovFormNum + "' WHERE ID = '"
                                    + client.Character.OrgId + "'");
                                foreach (int currentCharId in OrgMisc.GetOrgMembers(client.Character.OrgId, true))
                                {
                                    client.Character.Stats.ClanLevel.Set(GetLowestRank(GovFormNum));
                                }
                                client.SendChatText("Governing Form is now: " + cmdStr);
                                break;
                            }
                        }
                        else
                        {
                            //Haha! You're not the org leader!
                            client.SendChatText("You must be the Org Leader to perform this command");
                            break;
                        }
                    }
                    break;
                    #endregion

                    #region /org stopvote <text>
                case 28:
                    // <text> is CmdStr
                    break;
                    #endregion

                    #region unknown command
                default:
                    break;
                    #endregion
            }
            #endregion

            reader.Finish();
        }
        //static CharStatus()
        //{
        //    SetAllOffline();
        //}

        public void SetAllOffline()
        {
            SqlWrapper sql = new SqlWrapper();
            sql.SqlUpdate("UPDATE characters SET Online = 0");
            sql.sqlclose();
        }
Пример #19
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool WriteName()
 {
     mySql.SqlUpdate("UPDATE `mobspawns` SET `Name` = " + mobName + " WHERE ID= '" + mobId + "'");
     return(true);
 }
 public void SetOffline(int charID)
 {
     SqlWrapper sql = new SqlWrapper();
     sql.SqlUpdate("UPDATE characters SET Online = 0 WHERE ID = " + charID + ";");
     sql.sqlclose();
 }
Пример #21
0
 /// <summary>
 /// Write names to database
 /// </summary>
 /// <returns>true for success</returns>
 public bool WriteNames()
 {
     SqlWrapper Sql = new SqlWrapper();
     try
     {
         Sql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + " SET `Name` = '" + Name + "', `FirstName` = '" + FirstName + "', `LastName` = '" + LastName + "' WHERE `ID` = " + "'" + ID + "'");
     }
     catch
     {
         return false;
     }
     return true;
 }
            public static bool func_revert(Character ch, AOFunctions func, bool fromsocialtab, int placement)
            {
                int c;

                if (ch != null)
                {
                    for (c = 0; c < func.TickCount; c++)
                    {
                        switch (func.FunctionType)
                        {
                            case ItemHandler.functiontype_texture:
                                // Todo: check for second Arm item
                                SqlWrapper ms = new SqlWrapper();
                                if (!fromsocialtab)
                                {
                                    ms.SqlUpdate("Update " + ch.getSQLTablefromDynelType() + " set Textures" + func.Arguments[1].ToString() + "=0 WHERE ID=" + ch.ID.ToString() + " AND Textures" + func.Arguments[1].ToString() + "=" + func.Arguments[0].ToString());
                                    int ct = ch.Textures.Count - 1;
                                    while (ct >= 0)
                                    {
                                        if (ch.Textures[ct].place == (int)func.Arguments[1])
                                        {
                                            ch.Textures.RemoveAt(ct);
                                            break;
                                        }
                                        ct--;
                                    }
                                }
                                else
                                {
                                    if (ch.SocialTab.ContainsKey((Int32)func.Arguments[1]))
                                    {
                                        ch.SocialTab[(Int32)func.Arguments[1]] = 0;
                                    }
                                    else
                                    {
                                        ch.SocialTab.Add((Int32)func.Arguments[1], 0);
                                    }
                                }
                                break;
                            case ItemHandler.functiontype_headmesh:
                                if (!fromsocialtab)
                                {
                                    ch.Stats.HeadMesh.StatModifier = 0;
                                    ch.MeshLayer.RemoveMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                else
                                {
                                    ch.SocialMeshLayer.RemoveMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                // Reverting the Head modification
                                break;
                            case ItemHandler.functiontype_shouldermesh:
                                // TODO: check for second shoulder item
                                if (!fromsocialtab)
                                {
                                    if (placement == 19)
                                    {
                                        ch.MeshLayer.RemoveMesh(4, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                        ch.MeshLayer.RemoveMesh(3, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                    }
                                    if (placement == 20) // Right
                                    {
                                        ch.Stats.ShoulderMeshRight.Set(0); // Shouldermesh Right
                                        ch.MeshLayer.RemoveMesh(3, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                    }
                                    if (placement == 22) // Left
                                    {
                                        ch.Stats.ShoulderMeshLeft.Set(0); // Shouldermesh Left
                                        ch.MeshLayer.RemoveMesh(4, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                    }
                                }
                                else
                                {
                                    if (placement == 52) // Right
                                    {
                                        ch.SocialMeshLayer.RemoveMesh(3, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                    }
                                    if (placement == 54) // Left
                                    {
                                        ch.SocialMeshLayer.RemoveMesh(4, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                    }
                                }
                                break;
                            case ItemHandler.functiontype_backmesh:
                                if (!fromsocialtab)
                                {
                                    ch.Stats.BackMesh.Set(0); // Backmesh
                                    ch.MeshLayer.RemoveMesh(5, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                else
                                {
                                    ch.SocialMeshLayer.RemoveMesh(5, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                break;
                            case ItemHandler.functiontype_attractormesh:
                                if (!fromsocialtab)
                                {
                                    ch.Stats.HairMesh.Set(0); // Attractormesh
                                    ch.MeshLayer.RemoveMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                else
                                {
                                    if (ch.SocialTab.ContainsKey(32))
                                    {
                                        ch.SocialTab[32] = 0;
                                    }
                                    else
                                    {
                                        ch.SocialTab.Add(32, 0);
                                    }
                                    ch.SocialMeshLayer.RemoveMesh(0, (Int32)func.Arguments[1], (Int32)func.Arguments[0], Misc.MeshLayers.GetLayer(placement));
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
                return false;
            }