Beispiel #1
0
        /// <summary>
        /// Adds a server's posted snapshot into the Snapshot Processing Queue, which
        /// will process the snapshot as soon as possible. This method is Non-Blocking.
        /// </summary>
        /// <remarks>
        /// Any errors that occur during the actual import of the data will be
        /// logged inside the StatsDebug log
        /// </remarks>
        /// <param name="Data">The snapshot data provided by the server.</param>
        /// <param name="ServerAddress">The IP address of the server.</param>
        /// <exception cref="UnauthorizedAccessException">
        ///     Thrown if the Server IP is not authorized to post game data to this server
        /// </exception>
        /// <exception cref="InvalidDataException">
        ///     Thrown if the provided Snapshot data is not valid, and cannot be processed
        /// </exception>
        public static void QueueServerSnapshot(string Data, IPAddress ServerAddress)
        {
            // Make sure the server is authorized
            if (!IsAuthorizedGameServer(ServerAddress))
            {
                throw new UnauthorizedAccessException("Un-Authorised Gameserver (Ip: " + ServerAddress + ")");
            }

            // Create the Snapshot Object
            Snapshot Snap = new Snapshot(Data, ServerAddress);

            // Update this server in the Database
            using (StatsDatabase Database = new StatsDatabase())
            {
                // Try and grab the ID of this server
                int id = Database.ExecuteScalar <int>(
                    "SELECT COALESCE(id, -1), COUNT(id) FROM servers WHERE ip=@P0 AND port=@P1",
                    ServerAddress, Snap.ServerPort
                    );

                // New server?
                if (id < 0)
                {
                    InsertQueryBuilder builder = new InsertQueryBuilder(Database);
                    builder.SetTable("servers");
                    builder.SetField("ip", ServerAddress);
                    builder.SetField("port", Snap.ServerPort);
                    builder.SetField("prefix", Snap.ServerPrefix);
                    builder.SetField("name", Snap.ServerName);
                    builder.SetField("queryport", Snap.QueryPort);
                    builder.SetField("lastupdate", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                    builder.Execute();
                }
                else // existing
                {
                    UpdateQueryBuilder builder = new UpdateQueryBuilder(Database);
                    builder.SetTable("servers");
                    builder.SetField("prefix", Snap.ServerPrefix);
                    builder.SetField("name", Snap.ServerName);
                    builder.SetField("queryport", Snap.QueryPort);
                    builder.SetField("lastupdate", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                    builder.AddWhere("id", Comparison.Equals, id);
                    builder.Execute();
                }
            }

            // Add snapshot to Queue
            SnapshotQueue.Enqueue(Snap);
        }
        /// <summary>
        /// Updates an Account's information by ID
        /// </summary>
        /// <param name="Id">The Current Account ID</param>
        /// <param name="NewPid">New Account ID</param>
        /// <param name="NewNick">New Account Name</param>
        /// <param name="NewPassword">New Account Password, UN HASHED. Leave empty to not set a new password</param>
        /// <param name="NewEmail">New Account Email Address</param>
        public void UpdateUser(int Id, int NewPid, string NewNick, string NewPassword, string NewEmail)
        {
            UpdateQueryBuilder Query = new UpdateQueryBuilder("accounts", this);

            Query.SetField("id", NewPid);
            Query.SetField("name", NewNick);
            Query.SetField("email", NewEmail.ToLowerInvariant());
            Query.AddWhere("id", Comparison.Equals, Id);

            // Set new password if not empty
            if (!String.IsNullOrWhiteSpace(NewPassword))
            {
                Query.SetField("password", NewPassword.GetMD5Hash(false));
            }

            Query.Execute();
        }
        /// <summary>
        /// Save Button Click Event
        /// </summary>
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                using (StatsDatabase Driver = new StatsDatabase())
                {
                    bool Changes             = false;
                    UpdateQueryBuilder Query = new UpdateQueryBuilder("player", Driver);
                    int Rank = Int32.Parse(Player["rank"].ToString());

                    // Update clantag
                    if (Player["clantag"].ToString() != ClanTagBox.Text.Trim())
                    {
                        Player["clantag"] = ClanTagBox.Text.Trim();
                        Query.SetField("clantag", ClanTagBox.Text.Trim());
                        Changes = true;
                    }

                    // Update Rank
                    if (Rank != RankSelect.SelectedIndex)
                    {
                        if (Rank > RankSelect.SelectedIndex)
                        {
                            Query.SetField("decr", 1);
                            Query.SetField("chng", 0);
                        }
                        else
                        {
                            Query.SetField("decr", 0);
                            Query.SetField("chng", 1);
                        }

                        Player["rank"] = RankSelect.SelectedIndex;
                        Query.SetField("rank", RankSelect.SelectedIndex);
                        Changes = true;
                    }

                    // update perm ban status
                    if (Int32.Parse(Player["permban"].ToString()) != PermBanSelect.SelectedIndex)
                    {
                        Player["permban"] = PermBanSelect.SelectedIndex;
                        Query.SetField("permban", PermBanSelect.SelectedIndex);
                        Changes = true;
                    }

                    // If no changes made, just return
                    if (!Changes)
                    {
                        MessageBox.Show("Unable to save player because no changes were made.",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    // Preform Query
                    Query.AddWhere("id", Comparison.Equals, Pid);
                    Query.Execute();
                    this.Close();
                }
            }
            catch (DbConnectException Ex)
            {
                HttpServer.Stop();
                ExceptionForm.ShowDbConnectError(Ex);
                return;
            }
        }