diff --git a/db/patches/V1_6_62_03__multi_accounts.sql b/db/patches/V1_6_62_03__multi_accounts.sql new file mode 100644 index 000000000..2bbd25a1b --- /dev/null +++ b/db/patches/V1_6_62_03__multi_accounts.sql @@ -0,0 +1,14 @@ +-- Rename `account.account_id` to `account.login_id` +ALTER TABLE account CHANGE `account_id` `login_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT; + +-- Add `account_link_login` table +CREATE TABLE account_link_login ( + `account_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, + `login_id` smallint(6) unsigned NOT NULL, + PRIMARY KEY (`account_id`) +) ENGINE=MyISAM AUTO_INCREMENT=1; + +-- Fill in `account_link_login` from the rows of `account`, +-- setting account_id = login_id. +INSERT INTO account_link_login (account_id, login_id) +SELECT login_id, login_id as account_id FROM account; diff --git a/engine/Default/game_play.php b/engine/Default/game_play.php index 9fdeee033..3b3dd2088 100644 --- a/engine/Default/game_play.php +++ b/engine/Default/game_play.php @@ -8,9 +8,41 @@ $template->assign('Message',$var['msg']); } +// *************************************** +// ** Accounts +// *************************************** + +if (isset($var['switch_account_id'])) { + // Override default account (and do sanity checks) + $account = $account->getLinkedAccount($var['switch_account_id']); + SmrSession::updateAccount($account->getAccountID()); +} + +// Get linked accounts (order the current account first, for simplicity) +$linkedAccounts = $account->getLinkedAccountList(); +if (key($linkedAccounts) != $account->getAccountID()) { + $linkedAccounts = array_reverse($linkedAccounts); +} +$template->assign('AccountLabels', array_values($linkedAccounts)); + +if (count($linkedAccounts) == SmrAccount::MAX_LINKED_ACCOUNTS) { + end($linkedAccounts); + $otherAccountID = key($linkedAccounts); + $switchContainer = create_container('skeleton.php', 'game_play.php'); + $switchContainer['switch_account_id'] = $otherAccountID; +} else { + $switchContainer = create_container('skeleton.php', 'switch_account_create.php'); +} +$template->assign('SwitchAccountHREF', SmrSession::getNewHREF($switchContainer)); + + $template->assign('UserRankingLink',SmrSession::getNewHREF(create_container('skeleton.php', 'rankings_view.php'))); $template->assign('UserRankName',$account->getRankName()); +// *************************************** +// ** Play Game +// *************************************** + $games = array(); $games['Play'] = array(); $game_id_list = array(); diff --git a/engine/Default/switch_account_create.php b/engine/Default/switch_account_create.php new file mode 100644 index 000000000..e9425a5f4 --- /dev/null +++ b/engine/Default/switch_account_create.php @@ -0,0 +1,9 @@ +assign('PageTopic', 'Create Multi Account'); + +$container = create_container('switch_account_create_processing.php'); +$container['action'] = 'Create'; +$template->assign('CreateHREF', SmrSession::getNewHREF($container)); +$container['action'] = 'Link'; +$template->assign('LinkHREF', SmrSession::getNewHREF($container)); diff --git a/engine/Default/switch_account_create_processing.php b/engine/Default/switch_account_create_processing.php new file mode 100644 index 000000000..e48a96797 --- /dev/null +++ b/engine/Default/switch_account_create_processing.php @@ -0,0 +1,41 @@ +getLinkedAccountList()) >= SmrAccount::MAX_LINKED_ACCOUNTS) { + create_error('Cannot create another linked account!'); +} + +if ($var['action'] == 'Create') { + // Create a new multi account + $db->query('INSERT INTO account_link_login (login_id) VALUES ('.$account->getLoginID().')'); + $newAccountID = $db->getInsertID(); + + $container = create_container('skeleton.php', 'game_play.php'); + $container['switch_account_id'] = $newAccountID; + +} elseif ($var['action'] == 'Link') { + $login = $_REQUEST['multi_account_login']; + $password = $_REQUEST['multi_account_password']; + + // Link an existing multi account + $db->query('SELECT login_id FROM account ' . + 'WHERE login = '.$db->escapeString($login).' AND ' . + 'password = '.$db->escapeString(md5($password)).' LIMIT 1'); + if (!$db->nextRecord()) { + create_error('Could not find a matching account. If you believe this is an error, please contact an admin.'); + } + $multiLoginID = $db->getInt('login_id'); + + // Sanity check: multi ID > current ID + if ($multiLoginID <= $account->getLoginID()) { + create_error('Multi account must be newer than main account!'); + } + + // update the account_link_login to reflect the new login association + // For existing accounts login_id == account_id + $db->query('UPDATE account_link_login SET login_id='.$db->escapeNumber($account->getLoginID()).' WHERE account_id='.$db->escapeNumber($multiLoginID)); + + // delete the old login + $db->query('DELETE FROM account WHERE login_id='.$db->escapeNumber($multiLoginID)); + + +} diff --git a/htdocs/login_create.php b/htdocs/login_create.php index ba7fe6669..ce82050bc 100755 --- a/htdocs/login_create.php +++ b/htdocs/login_create.php @@ -31,7 +31,6 @@
Creating multiple logins is not allowed. - Click HERE for more information.