case 'phpbb':
        $smilies = $integrationDatabase->select(array("{$forumTablePrefix}smilies" => 'code emoticonText, smiley_url emoticonFile'))->getAsArray(true);
        break;
    case 'vanilla':
        // TODO: Convert
        $smilies = $database->select(array($database->sqlPrefix . "emoticons" => 'emoticonText, emoticonFile'))->getAsArray(true);
        break;
    default:
        $smilies = array();
        break;
}
if (count($smilies)) {
    switch ($loginConfig['method']) {
        case 'phpbb':
            $forumUrlS = $loginConfig['url'] . 'images/smilies/';
            break;
        case 'vanilla':
            $forumUrlS = $installUrl;
            break;
        case 'vbulletin3':
        case 'vbulletin4':
            $forumUrlS = $loginConfig['url'];
            break;
    }
    foreach ($smilies as $smilie) {
        $smilies2[$smilie['emoticonText']] = $forumUrlS . $smilie['emoticonFile'];
    }
    $searchText2 = implode('|', $searchText);
}
$apiData = new apiData(array('getServerStatus' => array('activeUser' => array('userId' => (int) $user['userId'], 'userName' => $user['userName']), 'errStr' => $errStr, 'errDesc' => $errDesc, 'serverStatus' => array('fim_version' => FIM_VERSION, 'installedPlugins' => array(), 'installUrl' => $installUrl, 'parentalControls' => array('parentalEnabled' => $config['parentalEnabled'], 'parentalForced' => $config['parentalForced'], 'parentalAgeChangeable' => $config['parentalAgeChangeable'], 'parentalRegistrationAge' => $config['parentalRegistrationAge'], 'parentalFlags' => new apiOutputList($config['parentalFlags']), 'parentalAges' => new apiOutputList($config['parentalAges']), 'enableCensor' => $config['censorEnabled']), 'branding' => array('forumType' => $loginConfig['method'], 'forumUrl' => $loginConfig['url']), 'requestMethods' => array('poll' => true, 'serverSentEvents' => (bool) $config['serverSentEvents']), 'registrationPolicies' => array('ageRequired' => (bool) $config['ageRequired'], 'ageMinimum' => (int) $config['ageMinimum'], 'ageMaximum' => (int) $config['ageMaximum'], 'emailRequired' => (bool) $config['emailRequired']), 'fileUploads' => array('enabled' => (bool) $config['enableUploads'], 'generalEnabled' => (bool) $config['enableGeneralUploads'], 'maxAll' => (int) $config['uploadMaxFiles'], 'maxUser' => (int) $config['uploadMaxUserFiles'], 'chunkSize' => (int) $config['fileUploadChunkSize'], 'emptyFiles' => (bool) $config['allowEmptyFiles'], 'orphanFiles' => (bool) $config['allowOrphanFiles'], 'allowedExtensions' => new apiOutputList($config['allowedExtensions']), 'mimes' => new apiOutputList($config['uploadMimes']), 'extensionChanges' => $config['extensionChanges'], 'fileContainers' => $config['fileContainers'], 'mimeProofs' => $config['uploadMimeTypes'], 'sizeLimits' => $config['uploadSizeLimits']), 'rooms' => array('roomLengthMinimum' => (int) $config['roomLengthMinimum'], 'roomLengthMaximum' => (int) $config['roomLengthMaximum'], 'disableTopic' => (bool) $config['disableTopic'], 'officialRooms' => (bool) $config['officialRooms'], 'hiddenRooms' => (bool) $config['hiddenRooms']), 'defaultFormatting' => array('color' => $config['defaultFormattingColor'], 'font' => $config['defaultFormattingFont'], 'highlight' => $config['defaultFormattingHighlight'], 'bold' => $config['defaultFormattingBold'], 'italics' => $config['defaultFormattingItalics'], 'underline' => $config['defaultFormattingUnderline'], 'strikethrough' => $config['defaultFormattingStrikethrough'], 'overline' => $config['defaultFormattingOverline']), 'formatting' => array('fonts' => $config['fonts'], 'emoticons' => $smilies2), 'outputBuffer' => array('comressOutput' => (bool) $config['compressOutput']), 'phpVersion' => (double) phpversion()))));
echo $apiData->output();
    }
    $sessionHash = $database->createSession($user);
} elseif ($loginMethod === 'session') {
    $session = $database->getSessions(array('sessionHashes' => array($request['fim3_sessionHash'])))->getAsArray(false);
    if (!count($session)) {
        $database->lockoutIncrement();
        new fimError('invalidSession', 'Your session has expired. Please re-login.');
    } elseif ($session['userAgent'] !== $_SERVER['HTTP_USER_AGENT']) {
        // Require the UA match that of the one used to establish the session. Smart clients are encouraged to specify their own with their client name and version.
        $database->lockoutIncrement();
        new fimError('sessionMismatchBrowser', 'Your client or browser has changed. Please re-login.');
    } elseif ($session['sessionIp'] !== $_SERVER['REMOTE_ADDR']) {
        // This is a tricky one (in some instances, a user's IP may change throughout their session, especially over mobile), but generally the most certain to block any attempted forgeries. That said, IPs can, /theoretically/ be spoofed.
        $database->lockoutIncrement();
        new fimError('sessionMismatchIp', 'Your IP address has changed. Please re-login.');
    } else {
        $user = new fimUser($session);
        // Mostly identical, though a few additional properties do exist.
        if ($session['sessionTime'] < time() - $config['sessionRefresh']) {
            $database->refreshSession($session['sessionId']);
        }
        // If five minutes (or whatever $config[sessionTime is set to) have passed since the session has been generated, update it.
    }
}
/* API Output */
if ($apiRequest !== true && $streamRequest !== true && $ignoreLogin !== true && $hookLogin === false) {
    $apiData = new apiData();
    $apiData->replaceData(array('login' => array('sessionHash' => $sessionHash, 'anonId' => $user->anonId, 'defaultRoomId' => $user->defaultRoomId, 'userData' => array('userId' => $user->id, 'userName' => $user->name, 'userNameFormat' => $user->nameFormat, 'userGroupId' => $user->mainGroupId, 'socialGroupIds' => new apiOutputList($user->socialGroupIds), 'avatar' => $user->avatar, 'profile' => $user->profile, 'messageFormatting' => $user->messageFormatting, 'parentalFlags' => new apiOutputList($user->parentalFlags), 'parentalAge' => $user->parentalAge), 'permissions' => array('protected' => (bool) ($user->privs & ADMIN_PROTECTED), 'modPrivs' => (bool) ($user->privs & ADMIN_GRANT), 'modRooms' => (bool) ($user->privs & ADMIN_ROOMS), 'modPrivate' => (bool) ($user->privs & ADMIN_VIEW_PRIVATE), 'modUsers' => (bool) ($user->privs & ADMIN_USERS), 'modFiles' => (bool) ($user->privs & ADMIN_FILES), 'modCensor' => (bool) ($user->privs & ADMIN_CENSOR), 'view' => (bool) ($user->privs & USER_PRIV_VIEW), 'post' => (bool) ($user->privs & USER_PRIV_POST), 'changeTopic' => (bool) ($user->privs & USER_PRIV_TOPIC), 'createRooms' => (bool) ($user->privs & USER_PRIV_CREATE_ROOMS), 'privateRoomsFriends' => (bool) ($user->privs & USER_PRIV_PRIVATE_FRIENDS), 'privateRoomsAll' => (bool) ($user->privs & USER_PRIV_PRIVATE_ALL), 'roomsOnline' => (bool) ($user->privs & USER_PRIV_ACTIVE_USERS), 'postCounts' => (bool) ($user->privs & USER_PRIV_POST_COUNTS)))));
    die($apiData->output());
}
define('FIM_LOGINRUN', true);