Ejemplo n.º 1
0
        /// <summary>
        /// Loads admins into a DS
        ///</summary>
        /// <param name="admins">
        /// The admin KVs to load from
        /// </param>
        /// <param name="ds">
        /// The dataset to load to
        /// </param>
        private void LoadAdminsToDS(KVItem admins, dsAdmins ds)
        {
            // Make sure the root section is admins
            if (admins.key == "Admins")
            {
                // Create admin rows for each admin
                foreach (KVItem adm in admins.subItems)
                {
                    // Create the row
                    dsAdmins.dtAdminsRow row = ds.dtAdmins.NewdtAdminsRow();

                    // Set the name
                    row.name = adm.key;

                    foreach (KVItem item in adm.subItems)
                    {
                        // Find where this value is supposed
                        // to go
                        switch (item.key.ToLower())
                        {
                        case "auth":
                            row.authType = item.value.ToLower();
                            break;

                        case "identity":
                            row.identity = item.value;
                            break;

                        case "group":
                            row.group = item.value;
                            break;

                        case "immunity":
                            row.immunity = Decimal.Parse(item.value);
                            break;

                        case "flags":
                            row.flags = item.value.ToLower();
                            break;

                        default:
                            break;
                        }
                    }

                    // Add the row
                    ds.dtAdmins.AdddtAdminsRow(row);
                }
            }
            else
            {
                // User tried to load an invalid admin file
                MessageBox.Show("Invalid admins.cfg.", "Invalid File",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Prompt the user to pick an input file
            if (ofdMain.ShowDialog() == DialogResult.OK)
            {
                // admins.cfg
                if (ofdMain.FilterIndex == 1)
                {
                    try
                    {
                        // Load the admins
                        KVItem admins = KVParser.ReadFromFile(ofdMain.FileName);

                        // If we loaded admins into the KVs,
                        // load them into the dataset
                        if (admins != null)
                        {
                            LoadAdminsToDS(admins, _dsAdmins);
                        }

                        // Select the admins tab
                        tcMain.SelectedTab = tpAdmin;
                    }

                    catch (Exception ex)
                    {
                        // Let the user know something went wrong
                        ErrorHandler.ShowError(ex);
                    }
                }

                // admin_groups.cfg
                else if (ofdMain.FilterIndex == 2)
                {
                    // Load the groups
                    KVItem groups = KVParser.ReadFromFile(ofdMain.FileName);

                    // If we loaded groups into the KVs,
                    // load them into the dataset
                    if (groups != null)
                    {
                        LoadGroupsToDS(groups, _dsGroups);
                    }

                    // Select the groups tab
                    tcMain.SelectedTab = tpGroup;
                }
            }
        }
Ejemplo n.º 3
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Set the filter
            if (tcMain.SelectedTab == tpAdmin)
                sfdMain.Filter = FILTER_ADMIN;
            else
                sfdMain.Filter = FILTER_GROUP;

            // Prompt the user to save the file
            if (sfdMain.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // admins.cfg
                    if (sfdMain.Filter == FILTER_ADMIN)
                    {
                        // Create the root section
                        KVItem admins = new KVItem();
                        admins.key = "Admins";

                        foreach (dsAdmins.dtAdminsRow row in _dsAdmins.dtAdmins)
                        {
                            // Create the admin
                            KVItem currentAdmin = new KVItem(row.name, null);

                            // Set the the auth and identity
                            currentAdmin.subItems.Add(new KVItem("auth", row.authType));
                            currentAdmin.subItems.Add(new KVItem("identity", row.identity));

                            // Make sure group isn't empty before creating the KV pair
                            if (row.group != null && row.group.Trim() != "")
                                currentAdmin.subItems.Add(new KVItem("group", row.group));

                            // Set the immunity and flags
                            currentAdmin.subItems.Add(new KVItem("immunity",
                                                          ((int)row.immunity).ToString()));
                            currentAdmin.subItems.Add(new KVItem("flags", row.flags));

                            // Add the admin
                            admins.subItems.Add(currentAdmin);
                        }

                        // Save the file
                        KVParser.WriteToFile(admins, sfdMain.FileName);
                    }

                    // admin_groups.cfg
                    else if (sfdMain.Filter == FILTER_GROUP)
                    {
                        // Create the root section
                        KVItem groups = new KVItem();
                        groups.key = "Groups";

                        // Add all the groups
                        foreach (dsGroups.dtGroupsRow groupRow in _dsGroups.dtGroups)
                        {
                            KVItem currentGroup = new KVItem();
                            currentGroup.key = groupRow.name;

                            // Set the KVs
                            currentGroup.subItems.Add
                                (new KVItem("flags", groupRow.flags));
                            currentGroup.subItems.Add
                                (new KVItem("immunity", ((int)groupRow.immunity).ToString()));

                            // Get the override rows
                            DataRow[] overrides = groupRow.GetChildRows(_dsGroups.Relations[0]);

                            // Does this group have overrides?
                            if (overrides.Length > 0)
                            {
                                // Yes, add the overrides section
                                KVItem ovrSection = new KVItem();
                                ovrSection.key = "Overrides";

                                // Add each override
                                foreach (DataRow row in overrides)
                                {
                                    // Get a typed version of the row
                                    dsGroups.dtOverridesRow ovrRow = (dsGroups.dtOverridesRow)row;

                                    // Create the KV pair
                                    ovrSection.subItems.Add(new KVItem(ovrRow.key, ovrRow.value));
                                }

                                // Add the override section
                                currentGroup.subItems.Add(ovrSection);
                            }

                            // Add the group
                            groups.subItems.Add(currentGroup);
                        }

                        // Save the file
                        KVParser.WriteToFile(groups, sfdMain.FileName);
                    }
                }

                catch (StrongTypingException ex)
                {
                    if (ex.Message.Contains("name"))
                        MessageBox.Show("You must enter a name.",
                                        "Missing Name", MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);

                    else if (ex.Message.Contains("identity"))
                        MessageBox.Show("You must enter an identity.",
                                        "Missing Identity", MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);

                    else if (ex.Message.Contains("key"))
                        MessageBox.Show("You must enter a command / command group.",
                                     "Missing Command / Command Group",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Warning);

                }

                catch (Exception ex)
                {
                    // Let the user know something went wrong
                    ErrorHandler.ShowError(ex);
                }
            }
        }
Ejemplo n.º 4
0
        private void LoadGroupsToDS(KVItem groups, dsGroups ds)
        {
            if (groups.key == "Groups")
            {
                foreach (KVItem grp in groups.subItems)
                {
                    // Create the groups row
                    dsGroups.dtGroupsRow groupRow =
                        _dsGroups.dtGroups.NewdtGroupsRow();

                    // Set the name
                    groupRow.name = grp.key;

                    // Add the group row
                    ds.dtGroups.AdddtGroupsRow(groupRow);

                    // Get the kv pairs
                    foreach (KVItem subitem in grp.subItems)
                    {
                        // What key is this?
                        switch (subitem.key.ToLower())
                        {
                            case "flags":
                                groupRow.flags = subitem.value.ToLower();
                                break;

                            case "immunity":
                                groupRow.immunity = Decimal.Parse(subitem.value);
                                break;

                            case "overrides":
                                foreach (KVItem ovr in subitem.subItems)
                                {
                                    // Create the override row and attach it to
                                    // the group row
                                    dsGroups.dtOverridesRow ovrRow =
                                        _dsGroups.dtOverrides.NewdtOverridesRow();
                                    ovrRow.dtGroupsRow = groupRow;

                                    // Save the key and value
                                    ovrRow.key = ovr.key;
                                    ovrRow.value = ovr.value.ToLower();

                                    // Add the row
                                    ds.dtOverrides.AdddtOverridesRow(ovrRow);
                                }
                                break;

                            default:
                                break;
                        }
                    }
                }
            }
            else
            {
                // User tried to load an invalid group file
                MessageBox.Show("Invalid admin_groups.cfg.", "Invalid File",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads admins into a DS
        ///</summary>
        /// <param name="admins">
        /// The admin KVs to load from
        /// </param>
        /// <param name="ds">
        /// The dataset to load to
        /// </param>
        private void LoadAdminsToDS(KVItem admins, dsAdmins ds)
        {
            // Make sure the root section is admins
            if (admins.key == "Admins")
            {
                // Create admin rows for each admin
                foreach (KVItem adm in admins.subItems)
                {
                    // Create the row
                    dsAdmins.dtAdminsRow row = ds.dtAdmins.NewdtAdminsRow();

                    // Set the name
                    row.name = adm.key;

                    foreach (KVItem item in adm.subItems)
                    {
                        // Find where this value is supposed
                        // to go
                        switch (item.key.ToLower())
                        {
                            case "auth":
                                row.authType = item.value.ToLower();
                                break;

                            case "identity":
                                row.identity = item.value;
                                break;

                            case "group":
                                row.group = item.value;
                                break;

                            case "immunity":
                                row.immunity = Decimal.Parse(item.value);
                                break;

                            case "flags":
                                row.flags = item.value.ToLower();
                                break;

                            default:
                                break;
                        }
                    }

                    // Add the row
                    ds.dtAdmins.AdddtAdminsRow(row);
                }
            }
            else
            {
                // User tried to load an invalid admin file
                MessageBox.Show("Invalid admins.cfg.", "Invalid File",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 6
0
        private void LoadGroupsToDS(KVItem groups, dsGroups ds)
        {
            if (groups.key == "Groups")
            {
                foreach (KVItem grp in groups.subItems)
                {
                    // Create the groups row
                    dsGroups.dtGroupsRow groupRow =
                        _dsGroups.dtGroups.NewdtGroupsRow();

                    // Set the name
                    groupRow.name = grp.key;

                    // Add the group row
                    ds.dtGroups.AdddtGroupsRow(groupRow);

                    // Get the kv pairs
                    foreach (KVItem subitem in grp.subItems)
                    {
                        // What key is this?
                        switch (subitem.key.ToLower())
                        {
                        case "flags":
                            groupRow.flags = subitem.value.ToLower();
                            break;

                        case "immunity":
                            groupRow.immunity = Decimal.Parse(subitem.value);
                            break;

                        case "overrides":
                            foreach (KVItem ovr in subitem.subItems)
                            {
                                // Create the override row and attach it to
                                // the group row
                                dsGroups.dtOverridesRow ovrRow =
                                    _dsGroups.dtOverrides.NewdtOverridesRow();
                                ovrRow.dtGroupsRow = groupRow;

                                // Save the key and value
                                ovrRow.key   = ovr.key;
                                ovrRow.value = ovr.value.ToLower();

                                // Add the row
                                ds.dtOverrides.AdddtOverridesRow(ovrRow);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            else
            {
                // User tried to load an invalid group file
                MessageBox.Show("Invalid admin_groups.cfg.", "Invalid File",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 7
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Set the filter
            if (tcMain.SelectedTab == tpAdmin)
            {
                sfdMain.Filter = FILTER_ADMIN;
            }
            else
            {
                sfdMain.Filter = FILTER_GROUP;
            }

            // Prompt the user to save the file
            if (sfdMain.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // admins.cfg
                    if (sfdMain.Filter == FILTER_ADMIN)
                    {
                        // Create the root section
                        KVItem admins = new KVItem();
                        admins.key = "Admins";

                        foreach (dsAdmins.dtAdminsRow row in _dsAdmins.dtAdmins)
                        {
                            // Create the admin
                            KVItem currentAdmin = new KVItem(row.name, null);

                            // Set the the auth and identity
                            currentAdmin.subItems.Add(new KVItem("auth", row.authType));
                            currentAdmin.subItems.Add(new KVItem("identity", row.identity));

                            // Make sure group isn't empty before creating the KV pair
                            if (row.group != null && row.group.Trim() != "")
                            {
                                currentAdmin.subItems.Add(new KVItem("group", row.group));
                            }

                            // Set the immunity and flags
                            currentAdmin.subItems.Add(new KVItem("immunity",
                                                                 ((int)row.immunity).ToString()));
                            currentAdmin.subItems.Add(new KVItem("flags", row.flags));

                            // Add the admin
                            admins.subItems.Add(currentAdmin);
                        }

                        // Save the file
                        KVParser.WriteToFile(admins, sfdMain.FileName);
                    }

                    // admin_groups.cfg
                    else if (sfdMain.Filter == FILTER_GROUP)
                    {
                        // Create the root section
                        KVItem groups = new KVItem();
                        groups.key = "Groups";

                        // Add all the groups
                        foreach (dsGroups.dtGroupsRow groupRow in _dsGroups.dtGroups)
                        {
                            KVItem currentGroup = new KVItem();
                            currentGroup.key = groupRow.name;

                            // Set the KVs
                            currentGroup.subItems.Add
                                (new KVItem("flags", groupRow.flags));
                            currentGroup.subItems.Add
                                (new KVItem("immunity", ((int)groupRow.immunity).ToString()));

                            // Get the override rows
                            DataRow[] overrides = groupRow.GetChildRows(_dsGroups.Relations[0]);

                            // Does this group have overrides?
                            if (overrides.Length > 0)
                            {
                                // Yes, add the overrides section
                                KVItem ovrSection = new KVItem();
                                ovrSection.key = "Overrides";

                                // Add each override
                                foreach (DataRow row in overrides)
                                {
                                    // Get a typed version of the row
                                    dsGroups.dtOverridesRow ovrRow = (dsGroups.dtOverridesRow)row;

                                    // Create the KV pair
                                    ovrSection.subItems.Add(new KVItem(ovrRow.key, ovrRow.value));
                                }

                                // Add the override section
                                currentGroup.subItems.Add(ovrSection);
                            }

                            // Add the group
                            groups.subItems.Add(currentGroup);
                        }

                        // Save the file
                        KVParser.WriteToFile(groups, sfdMain.FileName);
                    }
                }

                catch (StrongTypingException ex)
                {
                    if (ex.Message.Contains("name"))
                    {
                        MessageBox.Show("You must enter a name.",
                                        "Missing Name", MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                    }

                    else if (ex.Message.Contains("identity"))
                    {
                        MessageBox.Show("You must enter an identity.",
                                        "Missing Identity", MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                    }

                    else if (ex.Message.Contains("key"))
                    {
                        MessageBox.Show("You must enter a command / command group.",
                                        "Missing Command / Command Group",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                    }
                }

                catch (Exception ex)
                {
                    // Let the user know something went wrong
                    ErrorHandler.ShowError(ex);
                }
            }
        }