• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

AAC Znote Adding Free Premium Days On New Account Creation. (Very Detailed)

SlayingWorld

Active Member
Joined
Jan 23, 2014
Messages
156
Reaction score
37
Location
USA
Hello, i've used the search function but the results are outdated, and im not that very familiar with SQL commands.


Mission: Give out 30 days of free premium to new accounts.

Problem: Znote ACC Maker updates "znote_accounts" instead of the "accounts" table. Cant just insert the "premdays => '30'" in the array because that section is not valid in the znote_accounts.


Currently Using:
Latest Version of Znote from
Znote/ZnoteAAC (https://github.com/Znote/ZnoteAAC)


Just a basic question, whats the SQL command that i need to update my "premdays" with 30 days on the account_id that was created.


I have tried editing register.php from:

PHP:
//Register
        if ($config['ServerEngine'] !== 'OTHIRE') {
            $register_data = array(
                'name'        =>    $_POST['username'],
                'password'    =>    $_POST['password'],
                'email'        =>    $_POST['email'],
                'created'    =>    time(),
                'ip'        =>    getIPLong(),
                'flag'        =>     $_POST['flag']
            );
        } else {
            $register_data = array(
                'id'        =>    $_POST['username'],
                'password'    =>    $_POST['password'],
                'email'        =>    $_POST['email'],
                'created'    =>    time(),
                'ip'        =>    getIPLong(),
                'flag'        =>     $_POST['flag']
             );
        }

to:
PHP:
//Register
        if ($config['ServerEngine'] !== 'OTHIRE') {
            $register_data = array(
                'name'        =>    $_POST['username'],
                'password'    =>    $_POST['password'],
                'email'        =>    $_POST['email'],
                'created'    =>    time(),
                'ip'        =>    getIPLong(),
                'flag'        =>     $_POST['flag'],
                'premdays'  => '30'
            );
        } else {
            $register_data = array(
                'id'        =>    $_POST['username'],
                'password'    =>    $_POST['password'],
                'email'        =>    $_POST['email'],
                'created'    =>    time(),
                'ip'        =>    getIPLong(),
                'flag'        =>     $_POST['flag'],
                'premdays'  => '30'
            );
        }

adding the:
PHP:
'premdays' => '30'
in the array does not work because whenever you create a new account the Znote Acc Maker updates the znote_accounts table in that php file not the accounts file.


Heres what my phpMyAdmin tables look:

znoteprob.png


I tried messing with this section of the code, but since im pretty bad with SQL Database commands i cant figure it out:
PHP:
// Authenticate user, fetch user id and activation key
    $auid = (isset($_GET['u']) && (int)$_GET['u'] > 0) ? (int)$_GET['u'] : false;
    $akey = (isset($_GET['k']) && (int)$_GET['k'] > 0) ? (int)$_GET['k'] : false;
    // Find a match
    $user = mysql_select_single("SELECT `id`, `active`, `active_email` FROM `znote_accounts` WHERE `account_id`='$auid' AND `activekey`='$akey' LIMIT 1;");
    if ($user !== false) {
        $user = (int) $user['id'];
        $active = (int) $user['active'];
        $active_email = (int) $user['active_email'];
        // Enable the account to login
        if ($active == 0 || $active_email == 0) {
            mysql_update("UPDATE `znote_accounts` SET `active`='1', `active_email`='1' WHERE `id`= $user LIMIT 1;");
        }
        echo '<h1>Congratulations!</h1> <p>Your account has been created. You may now login to create a character.</p>';
    } else {
        echo '<h1>Authentication failed</h1> <p>Either the activation link is wrong, or your account is already activated.</p>';
    }
} else {
    if (empty($_POST) === false && empty($errors) === true) {
        if ($config['log_ip']) {
            znote_visitor_insert_detailed_data(1);
        }

        //Register

I tried adding a :
PHP:
mysql_update("UPDATE `accounts` SET `premdays`='30' WHERE `id`= $user LIMIT 1;");

and placed it here:

PHP:
// Authenticate user, fetch user id and activation key
    $auid = (isset($_GET['u']) && (int)$_GET['u'] > 0) ? (int)$_GET['u'] : false;
    $akey = (isset($_GET['k']) && (int)$_GET['k'] > 0) ? (int)$_GET['k'] : false;
    // Find a match
    $user = mysql_select_single("SELECT `id`, `active`, `active_email` FROM `znote_accounts` WHERE `account_id`='$auid' AND `activekey`='$akey' LIMIT 1;");
    if ($user !== false) {
        $user = (int) $user['id'];
        $active = (int) $user['active'];
        $active_email = (int) $user['active_email'];
        // Enable the account to login
        if ($active == 0 || $active_email == 0) {
            mysql_update("UPDATE `znote_accounts` SET `active`='1', `active_email`='1' WHERE `id`= $user LIMIT 1;");
            mysql_update("UPDATE `accounts` SET `premdays`='30' WHERE `id`= $user LIMIT 1;");
        }
        echo '<h1>Congratulations!</h1> <p>Your account has been created. You may now login to create a character.</p>';
    } else {
        echo '<h1>Authentication failed</h1> <p>Either the activation link is wrong, or your account is already activated.</p>';
    }
} else {
    if (empty($_POST) === false && empty($errors) === true) {
        if ($config['log_ip']) {
            znote_visitor_insert_detailed_data(1);
        }

        //Register

But it just bugs out and the page does not even load.
 
Last edited:
Solution
Ugh, I feel icky. You made me look at PHP code.

Maybe try editing the function that data package in your first code block is being sent to?

Here: Znote/ZnoteAAC (https://github.com/Znote/ZnoteAAC/blob/d5749700fc8d88b83a609158ce477676167cbc26/engine/function/users.php#L1241)

You can see right here where it is using accounts and not something with a prefix of znote
You could a direct MySQL call to add the premium days there, directly after it. Creating accounts is not something that happens at a fast enough rate to bother with giving any thought to trying to integrate that into the creation query. All that buys you is upgrading hassle later.
Ugh, I feel icky. You made me look at PHP code.

Maybe try editing the function that data package in your first code block is being sent to?

Here: Znote/ZnoteAAC (https://github.com/Znote/ZnoteAAC/blob/d5749700fc8d88b83a609158ce477676167cbc26/engine/function/users.php#L1241)

You can see right here where it is using accounts and not something with a prefix of znote
You could a direct MySQL call to add the premium days there, directly after it. Creating accounts is not something that happens at a fast enough rate to bother with giving any thought to trying to integrate that into the creation query. All that buys you is upgrading hassle later.
 
Solution
Ugh, I feel icky. You made me look at PHP code.

Maybe try editing the function that data package in your first code block is being sent to?

Here: Znote/ZnoteAAC (https://github.com/Znote/ZnoteAAC/blob/d5749700fc8d88b83a609158ce477676167cbc26/engine/function/users.php#L1241)

You can see right here where it is using accounts and not something with a prefix of znote
You could a direct MySQL call to add the premium days there, directly after it. Creating accounts is not something that happens at a fast enough rate to bother with giving any thought to trying to integrate that into the creation query. All that buys you is upgrading hassle later.
Awesome! Was trying to find that function being called.
Ill get this working as soon as i get out of work, ill post solution for anyone looking for this.
 
Out of work, got it working.

If someone needs a solution for this go to your users.php it should be here UniServerZ\www\engine\function

Find this part of the code where it makes the function
PHP:
// CREATE ACCOUNT
function user_create_account($register_data, $maildata) {
    array_walk($register_data, 'array_sanitize');
    
    if (config('ServerEngine') == 'TFS_03' && config('salt') === true) {
        $register_data['salt'] = generate_recovery_key(18);
        $register_data['password'] = sha1($register_data['salt'].$register_data['password']);
    } else $register_data['password'] = sha1($register_data['password']);
    
    $ip = $register_data['ip'];
    $created = $register_data['created'];
    $flag = $register_data['flag'];
    
    unset($register_data['ip']);
    unset($register_data['created']);
    unset($register_data['flag']);
    
    if (config('ServerEngine') == 'TFS_10') $register_data['creation'] = $created;
    $fields = '`'. implode('`, `', array_keys($register_data)) .'`';
    $data = '\''. implode('\', \'', $register_data) .'\'';

    mysql_insert("INSERT INTO `accounts` ($fields) VALUES ($data)");
    
    $account_id = (isset($register_data['name'])) ? user_id($register_data['name']) : user_id($register_data['id']);
    $activeKey = rand(100000000,999999999);
    $active = ($maildata['register']) ? 0 : 1;
    mysql_insert("INSERT INTO `znote_accounts` (`account_id`, `ip`, `created`, `active`, `active_email`, `activekey`, `flag`) VALUES ('$account_id', '$ip', '$created', '$active', '0', '$activeKey', '$flag')");
    
    if ($maildata['register']) {

        $thisurl = config('site_url') . "$_SERVER[REQUEST_URI]";
        $thisurl .= "?authenticate&u=".$account_id."&k=".$activeKey;

        $mailer = new Mail($maildata);

        $title = "Please authenticate your account at $_SERVER[HTTP_HOST].";
        
        $body = "<h1>Please click on the following link to authenticate your account:</h1>";
        $body .= "<p><a href='$thisurl'>$thisurl</a></p>";
        $body .= "<p>Thank you for registering and enjoy your stay at $maildata[fromName].</p>";
        $body .= "<hr><p>I am an automatic no-reply e-mail. Any emails sent back to me will be ignored.</p>";
        
        $mailer->sendMail($register_data['email'], $title, $body, $register_data['name']);
    }
}

Add this line of code: (You can change the "30" to as many premium days you want to give on account creation
PHP:
$register_data['premdays'] ='30';

Right under this part:
PHP:
if (config('ServerEngine') == 'TFS_10') $register_data['creation'] = $created;


Should look like this:
PHP:
// CREATE ACCOUNT
function user_create_account($register_data, $maildata) {
    array_walk($register_data, 'array_sanitize');
    
    if (config('ServerEngine') == 'TFS_03' && config('salt') === true) {
        $register_data['salt'] = generate_recovery_key(18);
        $register_data['password'] = sha1($register_data['salt'].$register_data['password']);
    } else $register_data['password'] = sha1($register_data['password']);
    
    $ip = $register_data['ip'];
    $created = $register_data['created'];
    $flag = $register_data['flag'];
    
    unset($register_data['ip']);
    unset($register_data['created']);
    unset($register_data['flag']);
    
    if (config('ServerEngine') == 'TFS_10') $register_data['creation'] = $created;
    $register_data['premdays'] ='30';
    $fields = '`'. implode('`, `', array_keys($register_data)) .'`';
    $data = '\''. implode('\', \'', $register_data) .'\'';

    mysql_insert("INSERT INTO `accounts` ($fields) VALUES ($data)");
    
    $account_id = (isset($register_data['name'])) ? user_id($register_data['name']) : user_id($register_data['id']);
    $activeKey = rand(100000000,999999999);
    $active = ($maildata['register']) ? 0 : 1;
    mysql_insert("INSERT INTO `znote_accounts` (`account_id`, `ip`, `created`, `active`, `active_email`, `activekey`, `flag`) VALUES ('$account_id', '$ip', '$created', '$active', '0', '$activeKey', '$flag')");
    
    if ($maildata['register']) {

        $thisurl = config('site_url') . "$_SERVER[REQUEST_URI]";
        $thisurl .= "?authenticate&u=".$account_id."&k=".$activeKey;

        $mailer = new Mail($maildata);

        $title = "Please authenticate your account at $_SERVER[HTTP_HOST].";
        
        $body = "<h1>Please click on the following link to authenticate your account:</h1>";
        $body .= "<p><a href='$thisurl'>$thisurl</a></p>";
        $body .= "<p>Thank you for registering and enjoy your stay at $maildata[fromName].</p>";
        $body .= "<hr><p>I am an automatic no-reply e-mail. Any emails sent back to me will be ignored.</p>";
        
        $mailer->sendMail($register_data['email'], $title, $body, $register_data['name']);
    }
}
 
If someone needs a solution

Bro, let me introduce you to the DIFF.

Instead of explaining all that, you can present it like this:


In ./www/engine/function/users.php under function user_create_account($register_data, $maildata) {
Diff:
     unset($register_data['created']);
     unset($register_data['flag']);

     if (config('ServerEngine') == 'TFS_10') $register_data['creation'] = $created;
+    $register_data['premdays'] ='30';
     $fields = '`'. implode('`, `', array_keys($register_data)) .'`';
     $data = '\''. implode('\', \'', $register_data) .'\'';

     mysql_insert("INSERT INTO `accounts` ($fields) VALUES ($data)");

     $account_id = (isset($register_data['name'])) ? user_id($register_data['name']) : user_id($register_data['id']);

Unambiguous, easier to produce, easier to consume. Isn't that lovely? Your post would have been 1/7th the size for the same info. It's why I campaigned for the inclusion of Diff as part of my effort for the new block of commonly used languages in the codetag lang dropdown that's deployed here now.

The only real trick to producing a diff manually, as they are typically machine generated, is to know your code editors block-select commands, because you start by adding a space in front of every line. Those represent "context" lines. Then you replace that space with - or + depending on whether the line represented was originally there and now removed, or freshly added.

For example, in Sublime Text 3 on Linux, to produce this I simply followed this procedure to first select the first column of many lines:
  1. Put cursor at the beginning of the line where you wish to start.
  2. Press SHIFT and hold.
  3. RightClick where the text cursor is and hold.
  4. Drag mouse cursor down and the text cursor will begin to span multiple lines.
  5. When you've grown the selection to as many lines as you want, unhold-RightClick, unhold-SHIFT.
(And I believe this same exact procedure works across a lot of different editors, and OSes. If not your procedure is still likely to be very similiar.) Then I pressed space! Then I dropped back to regular cursor and simply replaced the space in front of the premdays line with a + to represent that it is a change of a newly added line. Then I truncated the rest of the code, leaving what I believe to be enough context to find this location in the code even if it changes over time, and also leaving the function name line, cutting that into the clipboard, to be used as a header. Then it was a matter of tossing that into a diff codeblock, and prefacing the codeblock with a line stating which file this is, in an inline code block, and what function it's under, pasting that from before, in an inline codeblock.

Writing this explanation of the process took about 50 times longer than actually doing it. 😁

There is even a lovely shortcut for inline code blocks here: The backtick. The other character on the Tilde key in a typical American keyboard. Simply book-end your code block with this character, presented with its keymate tilde:
~`
Rich (BB code):
Simply book-end your `code block` with this character
👆

Block Select for common editors:
Notepad++
VS Code
Sublime 3
 
Last edited:
Back
Top