예제 #1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            dbConnection = new SQLDatabase( );

            // The expanded nodes arraylist tracks the expanded and collapsed nodes
            // of the tree view.
            ExpandedNodes = new ArrayList( );

            // We must maintain the expanded nodes across the session...
            if (Session["ExpandedNodes"] == null)
            {
                Session["ExpandedNodes"] = ExpandedNodes;
            }

            dbConnection.DataSource = "user id=" + DBUserName + ";password="******";Data Source=" + SQLServer + ";Initial Catalog="
                                      + dbConnection.InitialCatalog;

            // Connect to the database...
            dbConnection.Connect(dbConnection.DataSource);

            // Put user code to initialize the page here
            UserNameLabel.Text = userName;

            Permissions userPermissions = dbConnection.RetrieveUser(dbConnection.GetUserIDFromExternalID(userName)).PermissionSettings;

            AddNewTestButton.Enabled         = userPermissions.CreateTests;
            DeleteArea.Enabled               = userPermissions.DeleteAreas;
            AddArea.Enabled                  = userPermissions.CreateAreas;
            AreaTestsGrid.Columns[2].Visible = userPermissions.DeleteTests;
            AreaTestsGrid.Columns[0].Visible = userPermissions.ModifyTests;

            this.PopulateTreeview( );
        }
예제 #2
0
        public String GetPhrase(Int32 i32IdResource, Boolean blnIsStatic, ref Boolean blnRetVal)
        {
            String strRetVal = String.Empty;

            try
            {
                SQLDatabase DBConnection = new SQLDatabase(ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString());
                if (DBConnection == null)
                {
                    blnRetVal = false;
                    return(String.Empty);
                }

                DBConnection.Connect();

                ResorceManager Function = new ResorceManager(DBConnection, System.Web.HttpContext.Current.Session);
                if (Function == null)
                {
                    blnRetVal = false;
                    return(String.Empty);
                }

                if (blnIsStatic)
                {
                    Function.SelectStaticPhrase(i32IdResource, ref strRetVal);
                }
                else
                {
                    Function.SelectPhrase(i32IdResource, ref strRetVal);
                }

                DBConnection.Disconnect();

                if (strRetVal == String.Empty)
                {
                    SessionLanguage Language = (SessionLanguage)System.Web.HttpContext.Current.Session["SessionLanguage"];

                    String strError = String.Format("Missing data for phrase witch IdResource = {0} and IdLanguage = {1}!", i32IdResource, Language.GetLanguage());
                    blnRetVal = false;

                    Global.ErrorMessage(strError, System.Web.HttpContext.Current);
                    return("No data for this phrase!");
                }
            }
            catch (SQLException Ex)
            {
                Global.ErrorMessage(Ex, System.Web.HttpContext.Current);
                blnRetVal = false;
                return(Ex.Message);
            }
            catch (NullReferenceException Ex)
            {
                Global.ErrorMessage(Ex, System.Web.HttpContext.Current);
                blnRetVal = false;
                return(Ex.Message);
            }

            return(strRetVal);
        }
예제 #3
0
        /// <summary>
        /// Constructor: Sets up a database connection and loads all the Test run information into
        /// memory for fast and easy access.
        /// </summary>
        public RunQueue( )
        {
            // First, setup a connection to the database...
            dbConnection = new SQLDatabase( );

            dbConnection.Connect( );

            // First thing we need to do is load all the RunItems...
            RunItems = RetrieveTestScheduleInformation( );
        }
예제 #4
0
        protected Boolean DeleteByLivePhrase()
        {
            SharedResorceManagerPool.WaitOne();

            try
            {
                SQLDatabase DBConnection = new SQLDatabase(ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString());
                if (DBConnection == null)
                {
                    return(false);
                }

                DBConnection.Connect();

                ResorceManager rsMenager = new ResorceManager(DBConnection);
                if (rsMenager == null)
                {
                    return(false);
                }

                DataSet dsLanguages = null;
                rsMenager.ListAllLanguages(out dsLanguages);
                DBConnection.Disconnect();

                DateTime IsLiveTime = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)).ToLocalTime();

                Int32     IdLanguage = 0;
                DataRow[] RowPhrases;
                foreach (DataRow row in dsLanguages.Tables["Languages"].Rows)
                {
                    IdLanguage = Convert.ToInt32(row["IdLanguage"]);

                    RowPhrases = dsPhrases.Tables["tblPhrases"].Select(String.Format("IdLanguage = {0} AND DateTimeLive <= #{1:s}#", IdLanguage, IsLiveTime));
                    foreach (DataRow RowPhrase in RowPhrases)
                    {
                        RowPhrase.Delete();
                    }

                    dsPhrases.Tables["tblPhrases"].AcceptChanges();
                }
            }
            catch (Exception Ex)
            {
                Global.ErrorMessage(Ex, System.Web.HttpContext.Current);
                return(false);
            }
            finally
            {
                SharedResorceManagerPool.ReleaseMutex();
            }

            return(true);
        }
예제 #5
0
        public static Boolean GetPhrase(Int32 i32IdResource, Byte IdLanguage, Boolean blnIsStatic, ref String strRetVal)
        {
            try
            {
                SQLDatabase DBConnection = new SQLDatabase(ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString());
                if (DBConnection == null)
                {
                    return(false);
                }

                DBConnection.Connect();

                ResorceManager Function = new ResorceManager(DBConnection);
                if (Function == null)
                {
                    return(false);
                }
                ;

                if (blnIsStatic)
                {
                    Function.SelectStaticPhraseByLanguage(i32IdResource, IdLanguage, ref strRetVal);
                }
                else
                {
                    Function.SelectPhraseByLanguage(i32IdResource, IdLanguage, ref strRetVal);
                }

                DBConnection.Disconnect();

                if (strRetVal == String.Empty)
                {
                    String strError = String.Format("Missing data for phrase witch IdResource = {0} and IdLanguage = {1}!", i32IdResource, IdLanguage);
                    strRetVal = "No data for this phrase!";

                    Global.ErrorMessage(strError, System.Web.HttpContext.Current);
                    return(false);
                }
            }
            catch (SQLException Ex)
            {
                Global.ErrorMessage(Ex, System.Web.HttpContext.Current);
                return(false);
            }
            catch (NullReferenceException Ex)
            {
                Global.ErrorMessage(Ex, System.Web.HttpContext.Current);
                return(false);
            }
            return(true);
        }
예제 #6
0
 /// <summary>
 /// Select the database if exists. Return success.
 /// </summary>
 /// <param name="name">Database unique name</param>
 public static bool ConnectToDatabase(string SilkroadName)
 {
     if (Pk2Extractor.DirectoryExists(SilkroadName))
     {
         Database = new SQLDatabase(Pk2Extractor.GetDatabasePath(SilkroadName));
         bool connected = Database.Connect();
         if (connected)
         {
             DataManager.SilkroadName = SilkroadName;
         }
         return(connected);
     }
     return(false);
 }
예제 #7
0
파일: Global.cs 프로젝트: 2MASX-DevTeam/BCG
        protected String SelectUserCulture(Int32 IdLanguage)
        {
            String UserCulture = String.Empty;

            try
            {
                SQLDatabase DBConnection = new SQLDatabase(ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString());
                DBConnection.Connect();

                ResorceManager ResManager = new ResorceManager(DBConnection);
                DataSet        dsLanguage = null;
                ResManager.SelectLanguage(IdLanguage, out dsLanguage);

                UserCulture = dsLanguage.Tables["tblLanguages"].Rows[0]["Culture"].ToString();
                DBConnection.Disconnect();
            }
            catch (Exception Ex)
            {
                Global.ErrorMessage(Ex, Context);
                return("en-US");
            }

            return(UserCulture);
        }
예제 #8
0
        private static void AddUser( )
        {
            string externalAccount   = null;
            bool   userAlreadyExists = false;

            Console.WriteLine("\nADD USER: "******"\n");
            Console.WriteLine("To add a user, you must associate the username with an external");
            Console.WriteLine("account on the local machine or on a domain server. To do this,");
            Console.WriteLine("enter the username as \"DOMAIN\\USERNAME\" or as \"MACHINE\\USERNAME\"\n");
            Console.Write("External Account: ");

            // Read in the external user account to use...
            externalAccount = Console.ReadLine( );

            Permissions permissions = new Permissions( );

            Console.WriteLine("\nNow, permissions for this user must be set.\n");
            Console.Write("Allow to Create Tests [y/n]? ");
            permissions.CreateTests = ConvertResponseToBool(Console.ReadLine( ));

            Console.Write("Allow to Delete Tests [y/n]? ");
            permissions.DeleteTests = ConvertResponseToBool(Console.ReadLine( ));

            Console.Write("Allow to Modify Tests [y/n]? ");
            permissions.ModifyTests = ConvertResponseToBool(Console.ReadLine( ));

            Console.Write("Allow to Create Areas [y/n]? ");
            permissions.CreateAreas = ConvertResponseToBool(Console.ReadLine( ));

            Console.Write("Allow to Delete Areas [y/n]? ");
            permissions.DeleteAreas = ConvertResponseToBool(Console.ReadLine( ));

            Console.Write("Allow to Modify Areas [y/n]? ");
            permissions.ModifyAreas = ConvertResponseToBool(Console.ReadLine( ));

            User user = new User( );

            user.PermissionSettings = permissions;
            user.ExternID           = externalAccount.ToUpper( );
            user.Name = UserName.ToUpper( );

            Console.WriteLine("\n**YOU ENTERED**");
            PrintUserInformation(user);
            Console.Write("\nDoes the above information look correct [y/n]?");

            try
            {
                if (ConvertResponseToBool(Console.ReadLine( )))
                {
                    SQLDatabase dbConnection = new SQLDatabase( );
                    dbConnection.Connect( );

                    try
                    {
                        dbConnection.GetUserIDFromName(user.Name);

                        userAlreadyExists = true;
                    }
                    catch (Exception)
                    {
                        // this is the SUCCESS case...
                    }

                    if (userAlreadyExists)
                    {
                        throw new Exception("User Already Exists!");
                    }

                    dbConnection.AddUser(user);
                    dbConnection.Disconnect( );

                    Console.WriteLine("\nTHE USER WAS ADDED SUCCESSFULLY");
                }
                else
                {
                    Console.WriteLine("\nPLEASE RUN THE TOOL AGAIN WITH THE PROPER INFORMATION");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("\nERROR: The user could not be added because the user already exists, or");
                Console.WriteLine("you do not have access to the sql database.");
            }
        }
예제 #9
0
        /// <summary>
        /// Try to generate the database.
        /// </summary>
        public void ThreadGenerateData()
        {
            Log("Opening Pk2 file using " + (tbxBlowfishKey.Text != "" ? "blowfish key: " + tbxBlowfishKey.Text : "default blowfish key"));
            LogState("Opening Pk2 file...");
            try
            {
                pk2 = new Pk2Reader(MediaPk2Path, tbxBlowfishKey.Text);
            }
            catch
            {
                Log("Error opening Pk2 file. Possibly wrong blowfish key");
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }
            Log("Pk2 file opened!");
            LogState();

            // Fill info to Main GUI
            Window w = Window.Get;

            try
            {
                Log("Extracting Silkroad Version");
                LogState("Extracting...");
                // Reading
                Packet p = new Packet(0, false, false, pk2.GetFileBytes("SV.T"));
                p.Lock();
                int    dataLength = p.ReadInt();
                byte[] dataBuffer = p.ReadByteArray(dataLength);
                // Decoding
                Blowfish bf = new Blowfish();
                bf.Initialize(Encoding.ASCII.GetBytes("SILKROADVERSION"), 0, dataLength);
                byte[] dataDecoded = bf.Decode(dataBuffer);
                this.Version = uint.Parse(Encoding.ASCII.GetString(dataDecoded, 0, 4));
            }
            catch (Exception ex)
            {
                Log("Extracting error, the version cannot be readed. " + ex.Message);
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }

            try
            {
                Log("Extracting Locale & Gateway");
                LogState("Extracting...");
                // Reading
                Packet p = new Packet(0, false, false, pk2.GetFileBytes("DIVISIONINFO.TXT"));
                p.Lock();
                this.Locale = p.ReadByte();
                byte divisionCount = p.ReadByte();
                for (int i = 0; i < divisionCount; i++)
                {
                    string DivisionName = p.ReadString(p.ReadInt());
                    p.ReadByte();                     // 0

                    byte gatewayCount = p.ReadByte();
                    Gateways = new System.Collections.Generic.List <string>(gatewayCount);
                    for (int j = 0; j < gatewayCount; j++)
                    {
                        string gatewayHost = p.ReadString(p.ReadInt());
                        p.ReadByte();                         // 0

                        Gateways.Add(gatewayHost);
                    }
                }
            }
            catch (Exception ex)
            {
                Log("Extracting error, gateways cannot be readed. " + ex.Message);
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }

            try
            {
                Log("Extracting Gateport");
                LogState("Extracting...");
                // Reading
                Packet p = new Packet(0, false, false, pk2.GetFileBytes("GATEPORT.TXT"));
                p.Lock();

                string test = p.ReadString(p.RemainingRead());
                this.Gateport = ushort.Parse(test);
            }
            catch (Exception ex)
            {
                Log("Extracting error, the gateport cannot be readed. " + ex.Message);
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }

            // Updating database
            Log("Creating Database...");
            string dbPath = GetDatabasePath(SilkroadName);

            if (File.Exists(dbPath))
            {
                LogState("Deleting old database");
                if (!WinAPI.FileTryDelete(dbPath))
                {
                    // Deleting issues
                    Log("The database from \"" + SilkroadName + "\" is being used by another program. Please, close all the bots and try again!");
                    LogState("Error");
                    btnStart.InvokeIfRequired(() => {
                        btnStart.Font = new Font(btnStart.Font, FontStyle.Regular);
                    });
                    return;
                }
            }
            // Creating the database
            LogState("Creating database");
            db = new SQLDatabase(dbPath);
            if (!db.Create())
            {
                Log("Error creating the database. Please, close all the bots and try again!");
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Font = new Font(btnStart.Font, FontStyle.Regular);
                });
                return;
            }
            Log("Database has been created!");

            // Create connection
            LogState("Connecting to database");
            if (!db.Connect())
            {
                Log("Database connection error!");
                Log("Error");
                return;
            }
            LogState("Connected");

            // Generating database
            Log("Generating database (this may take a while)");
            SetLanguageIndex();
            Log("Loading name references...");
            LoadNameReferences();
            Log("Loading & Adding text references...");
            LoadTextReferences();
            AddTextReferences();
            Log("Adding Items...");
            AddItems();
            Log("Adding Magic options...");
            AddMagicOptions();
            Log("Adding Characters & Mobs...");
            AddModels();
            Log("Adding Masteries & Skills...");
            AddMasteries();
            AddSkills();
            Log("Adding Exp. & Levels...");
            AddLevelExperience();
            Log("Adding Shops...");
            AddShops();
            Log("Loading Teleport references");
            LoadTeleportData();
            Log("Adding Teleports & Structures...");
            AddTeleportBuildings();
            AddTeleportLinks();
            Log("Adding Regions...");
            AddRegions();
            Log("Database has been generated correctly!");

            Log("Creating Item icons...");
            AddItemIcons();
            Log("Creating Skill icons...");
            AddSkillIcons();
            if (this.cbxMinimap.Checked)
            {
                Log("Creating minimap images to the bot folder...");
                AddMinimap();
            }

            Log("All has been generated succesfully, Enjoy! :)");
            db.Close();
            pk2.Close();
            pk2.Dispose();
            LogState("Closing Pk2 file...");
            Thread.Sleep(1000);

            WinAPI.InvokeIfRequired(this, () => {
                this.DialogResult = DialogResult.OK;
                this.Activate();
                this.Close();
            });
        }