db.Database.Register C# (CSharp) Method

Register() public method

public Register ( string uuid, string password, bool isGuest ) : Account
uuid string
password string
isGuest bool
return Account
        public Account Register(string uuid, string password, bool isGuest)
        {
            MySqlCommand cmd = CreateQuery();
            cmd.CommandText = "SELECT COUNT(id) FROM accounts WHERE uuid=@uuid;";
            cmd.Parameters.AddWithValue("@uuid", uuid);
            if ((int)(long)cmd.ExecuteScalar() > 0) return null;

            cmd = CreateQuery();
            cmd.CommandText =
                "INSERT INTO accounts(uuid, password, name, rank, namechosen, verified, guild, guildRank, guildFame, vaultCount, maxCharSlot, regTime, guest, banned, locked, ignored, bonuses, tags) VALUES(@uuid, SHA1(@password), @name, 0, 1, 0, 0, 0, @empty, 1, 2, @regTime, @guest, 0, @empty, @empty, @empty, @empty);";
            cmd.Parameters.AddWithValue("@uuid", uuid);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.AddWithValue("@name", uuid); //names[(uint)uuid.GetHashCode() % names.Length]);
            cmd.Parameters.AddWithValue("@guest", isGuest);
            cmd.Parameters.AddWithValue("@regTime", DateTime.Now);
            cmd.Parameters.AddWithValue("@empty", "");
            int v = cmd.ExecuteNonQuery();
            bool ret = v > 0;

            if (ret)
            {
                cmd = CreateQuery();
                cmd.CommandText = "SELECT last_insert_id();";
                int accId = Convert.ToInt32(cmd.ExecuteScalar());

                cmd = CreateQuery();
                cmd.CommandText =
                    "INSERT INTO stats(accId, fame, totalFame, credits, totalCredits) VALUES(@accId, 100, 100, 0, 0);";
                cmd.Parameters.AddWithValue("@accId", accId);
                cmd.ExecuteNonQuery();

                cmd = CreateQuery();
                cmd.CommandText = "INSERT INTO vaults(accId, items) VALUES(@accId, '-1, -1, -1, -1, -1, -1, -1, -1');";
                cmd.Parameters.AddWithValue("@accId", accId);
                cmd.ExecuteNonQuery();
            }
            return Verify(uuid, password);
        }

Usage Example

Exemplo n.º 1
0
 protected override void HandleRequest()
 {
     using (var db = new Database())
     {
         if (!IsUsername(Query["newGUID"])) WriteErrorLine("Invalid Username");
         else
         {
             if (db.HasUuid(Query["guid"]) && db.Verify(Query["guid"], "") != null)
             {
                 if (db.HasUuid(Query["newGUID"])) WriteErrorLine("Username is already taken");
                 else
                 {
                     var cmd = db.CreateQuery();
                     cmd.CommandText = "UPDATE accounts SET uuid=@newUuid, name=@newUuid, password=SHA1(@password), guest=FALSE WHERE uuid=@uuid, name=@name;";
                     cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                     cmd.Parameters.AddWithValue("@newUuid", Query["newGUID"]);
                     cmd.Parameters.AddWithValue("@password", Query["newPassword"]);
                     if (cmd.ExecuteNonQuery() > 0) Success();
                     else WriteErrorLine("Internal Error");
                 }
             }
             else
             {
                 if (db.Register(Query["newGUID"], Query["newPassword"], false) != null) Success();
                 else WriteErrorLine("Internal Error");
             }
         }
     }
 }
All Usage Examples Of db.Database::Register