protected function _postSave()
 {
     parent::_postSave();
     // update sourcebans if we updated the groups
     if ($this->get('option_id') == 'AWickham_SourceBansSync_Groups') {
         if (is_array(unserialize($this->get('option_value'))) && !array_key_exists('newInstall', unserialize($this->get('option_value')))) {
             // create a group model
             $xfUserGroupModel = XenForo_Model::create('XenForo_Model_UserGroup');
             // create a user model
             $xfUserModel = XenForo_Model::create('XenForo_Model_User');
             // create an admin model
             $sbAdminModel = new AWickham_SourceBansSync_Model_SourceBans_Admin();
             // delete the users out of sourcebans that don't exist in xenforo
             $sbAdmins = $sbAdminModel->fetchAll();
             foreach ($sbAdmins as $sbAdmin) {
                 $xfUser = $xfUserModel->getUserBySteamId($sbAdmin['authid']);
                 if (!$xfUser || !$xfUserModel->getSourceBansGroups($xfUser, unserialize($this->get('option_value')))) {
                     $sbAdminModel->delete($xfUser['user_id'], $sbAdmin['authid']);
                 }
             }
             // loop through all the groups
             foreach (unserialize($this->get('option_value')) as $userGroupId => $sbGroups) {
                 //$userGroup = $userGroupModel->getUserGroupById($userGroupId);
                 $users = $xfUserGroupModel->getUserIdsInUserGroup($userGroupId);
                 foreach ($users as $user => $inGroup) {
                     $identities = $xfUserModel->getIdentities($user);
                     // pay attention to this user, they have a steam id
                     if ($identities && array_key_exists('Steam', $identities)) {
                         // check to see if the user exists in source bans
                         $sbUser = $sbAdminModel->fetchBySteamId($identities['Steam']);
                         // get the user
                         $xfUser = $xfUserModel->getFullUserById($user);
                         // figure out the groups
                         list($gid, $srvGroupsId, $serverGroupId) = $xfUserModel->getSourceBansGroups($xfUser, unserialize($this->get('option_value')));
                         // add the user to source bans
                         if (!$sbUser) {
                             if ($gid && $srvGroupsId && $serverGroupId) {
                                 // add the user
                                 $insertValues = array('user' => $xfUser['username'], 'email' => $xfUser['email'], 'authid' => $identities['Steam'], 'password' => XenForo_Application::generateRandomString(8), 'gid' => $gid, 'srvgroups_id' => $srvGroupsId, 'server_group_id' => $serverGroupId, 'validate' => '', 'extraflags' => 0);
                                 $sbAdminModel->insert($xfUser['user_id'], $insertValues);
                             }
                         } else {
                             if (!$gid || !$srvGroupsId || !$serverGroupId) {
                                 // remove the user from source bans
                                 $sbAdminModel->delete($xfUser, $identities['Steam']);
                             } else {
                                 $updateArray = array('user' => $xfUser['username'], 'email' => $xfUser['email'], 'gid' => $gid, 'srvgroups_id' => $srvGroupsId, 'server_group_id' => $serverGroupId);
                                 $sbAdminModel->update($identities['Steam'], $updateArray);
                             }
                         }
                     }
                 }
             }
         }
         // rehash the sourcebans servers
         AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
     }
 }
 protected function _postSave()
 {
     parent::_postSave();
     // get the source bans admin model
     $sbAdminModel = new AWickham_SourceBansSync_Model_SourceBans_Admin();
     $xfUserModel = XenForo_Model::create('XenForo_Model_User');
     $xfUserExternalModel = XenForo_Model::create('XenForo_Model_UserExternal');
     // get the user's new identities
     $identities = unserialize($this->get('identities'));
     // only do this if the steam id is set
     if ($identities && array_key_exists('steam', $identities)) {
         // check to see if the user exists in source bans
         $sbUser = $sbAdminModel->fetchBySteamId($xfUserModel->toSteamId($this->_currentSteamId));
         // add the user to source bans
         if (!$sbUser) {
             // figure out the groups
             list($gid, $srvgroups_id, $serverGroupId) = $xfUserModel->getSourceBansGroups($this, XenForo_Application::get('options')->AWickham_SourceBansSync_Groups);
             if ($gid && $srvgroups_id && $serverGroupId) {
                 // add the user
                 $insertValues = array('user' => $this->get('username'), 'email' => $this->get('email'), 'authid' => $xfUserModel->toSteamId($identities['steam']['provider_key']), 'password' => XenForo_Application::generateRandomString(8), 'gid' => $gid, 'srvgroups_id' => $srvgroups_id, 'server_group_id' => $serverGroupId, 'validate' => '', 'extraflags' => 0);
                 $sbAdminModel->insert($this->get('user_id'), $insertValues);
                 // rehash the sourcebans servers
                 AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
             }
         } else {
             // update the user if anything we care about changed
             if ($this->isChanged('user_group_id') || $this->isChanged('secondary_group_ids') || $this->isChanged('email') || $this->isChanged('username') || array_key_exists('steam', $this->_identities) && $this->_identities['steam'] != $identities['steam']) {
                 // figure out the groups
                 list($gid, $srvgroups_id, $serverGroupId) = $xfUserModel->getSourceBansGroups($this, XenForo_Application::get('options')->AWickham_SourceBansSync_Groups);
                 if (!$gid || !$srvgroups_id || !$serverGroupId) {
                     // remove the user from source bans
                     $sbAdminModel->delete($this->get('user_id'), $xfUserModel->toSteamId($this->_currentSteamId));
                 } else {
                     $updateArray = array('user' => $this->get('username'), 'email' => $this->get('email'), 'authid' => $xfUserModel->toSteamId($identities['steam']['provider_key']), 'gid' => $gid, 'srvgroups_id' => $srvgroups_id, 'server_group_id' => $serverGroupId);
                     $sbAdminModel->update($xfUserModel->toSteamId($this->_currentSteamId), $updateArray);
                 }
                 // rehash the sourcebans servers
                 AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
             }
         }
     }
 }