/*!
\brief Delete an account
\author Akron
\return true if account is deleted correctly, or false
\param name the account name
*/
bool cAccounts::RemoveAccount(std::string name)
{
	ACCOUNT_LIST_BY_NAME::iterator iter( accbyname.find( name ));
	ACCOUNT acc;
	if ( iter==accbyname.end() )
		return false;
	else
		acc = iter->second;
	
	if ( IsOnline(acc) )
	{
		unsigned int r = pointers::findCharBySerial(GetInWorld(acc))->getClient()->toInt();
		Network->Disconnect(r);
	}
	
	NxwCharWrapper acc_chars;
	GetAllChars( acc, acc_chars );
	for( acc_chars.rewind(); !acc_chars.isEmpty(); acc_chars++ )
	{
		P_CHAR pc = acc_chars.getChar();
		if(ISVALIDPC(pc))
			pc->Delete();
	}
	
	accbyname.erase( name );
	acctlist.erase( acc );
	SaveAccounts();
	return true;
}
/*!
\brief Create a new account
\return ACCOUNT the account id or INVALID if not created
\param username Username
\param password Password
*/
ACCOUNT cAccounts::CreateAccount(std::string username, std::string password)
{
	lastusedacctnum++;

	if ( accbyname.count(username) )	// if there's another account with this name..
		return INVALID;
	
	if (ServerScp::g_nUseAccountEncryption) { //xan : for account DES encryption :)
		char str[1000];
		strcpy(str,password.c_str());
		char *pwd = pwdcypher(str, -1);
		if (pwd!=NULL)
		{   //if pwd fails (any reason) use unencrypted pwd! :)
			str[0] = '!'; str[1] = '\0';
			strcat(str,pwd);
			safedelete(pwd); //xan : avoid a repetitive memory leak :)
			password.erase();
			password = str;    //someone with a bit of knowledge about STL strings.. plz chg this!
		}
	}


	cAccount account(lastusedacctnum);
	account.name = username;
	account.pass = password;
	safeInsert( account );
	unsavedaccounts++;
	if (unsavedaccounts >= saveratio)
		SaveAccounts();
	return account.number;
}
int SaveAll(void)
{
   Bool save_ok;
   int save_time;
   char save_name[MAX_PATH+FILENAME_MAX];
   char time_str[100];
   
   /* Note:  You must call GarbageCollect() right before SaveAll() */
   
/*
	 charlie: machine sets the local time from a time synch server
     its potentially dangerous, but only if the time has been changed
	 between either server startup or last save, which is unlikely to
	 have drifted by much, things will only start to freak out if the 
	 difference is more than say a minute behind, meaning the all the
	 timers will run for an extra minute.. its better this way as the 
	 time is going to be corrected every (currently) 4 hours , even
	 the worst PC clocks aren`t going to degrade that much in 4 hours
*/
     
   /* The current time is used as a suffix to the save filenames.  
      We make our own copy since the time functions use a static
      buffer. */
   save_time = GetTime();
   sprintf(time_str,"%i",save_time);
   
   save_ok = True;

   lprintf("Saving game (time stamp %s)...\n", time_str);
   
   sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),GAME_FILE_SAVE,time_str);
   if (SaveGame(save_name) == False)
      save_ok = False;

   sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),STRING_FILE_SAVE,time_str);
   if (SaveStrings(save_name) == False)
      save_ok = False;

   sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),ACCOUNT_FILE_SAVE,time_str);
   if (SaveAccounts(save_name) == False)
      save_ok = False;

   sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),DYNAMIC_RSC_FILE_SAVE,time_str);
   if (!SaveDynamicRsc(save_name))
      save_ok = False;

   if (save_ok)
      SaveControlFile(save_time);
   
   lprintf("Save game successful (time stamp %s).\n", time_str);

   if (save_ok)
      return save_time;

   return 0;
}
bool cAccount::ChangePassword(unsigned int number, string password)
{
	account_st* account = 0;
	if ( findByNumber( number, &account ) )
	{
		account->pass = password.c_str(); //stupid STL bug
		++unsavedaccounts;
		if (unsavedaccounts >= saveratio)
			SaveAccounts();
		return true;
	}
	return false;
}
/*!
\brief Change the Password
\return SI32 0 if ok, INVALID else
\param acctnum Account number
\param password new Password
*/
SI32 cAccounts::ChangePassword( ACCOUNT acctnum, std::string password)
{

	ACCOUNT_LIST::iterator iter( this->acctlist.find( acctnum ));
	if( iter!=this->acctlist.end() )
	{
		iter->second.changePassword( password );
		unsavedaccounts++;
		if (unsavedaccounts >= saveratio) SaveAccounts();
		return 0;
	}
	else
		return INVALID;
	
	
}
unsigned int cAccount::CreateAccount(const string& username, const string& password)
{
	++lastusedacctnum;
	account_st account;
	account.name = username;
	account.pass = password;
	account.ban = false;
	account.remoteadmin = false;
	account.number = lastusedacctnum;
	acctlist.insert(make_pair(username, account));
	acctnumbers_sp.insert( make_pair( account.number, username ) );
	++unsavedaccounts;
	if (unsavedaccounts >= saveratio)
		SaveAccounts();
	return account.number;
}
Exemple #7
0
					void GlooxProtocol::InitiateAccountRegistration ()
					{
						QString name = QInputDialog::getText (0,
								tr ("LeechCraft"),
								tr ("Enter new account name"));
						if (name.isEmpty ())
							return;

						GlooxAccount *account = new GlooxAccount (name, this);
						account->OpenConfigurationDialog ();

						Accounts_ << account;
						SaveAccounts ();

						emit accountAdded (account);

						account->ChangeState (IAccount::SOnline);
					}
/*!
\brief Destructor of cAccount
*/
cAccounts::~cAccounts()
{
	if (unsavedaccounts > 0)
		SaveAccounts();
}
cAccount::~cAccount(void)
{
	if (unsavedaccounts > 0)
		SaveAccounts();
}
Exemple #10
0
	bool CSettings::SaveSettings()
	{
		SimpleXml xml;
		mgr_.saveToXmlNode(xml.getRoot("ImageUploader").GetChild("Settings"));
#if !defined(IU_SERVERLISTTOOL) && !defined  (IU_CLI) && !defined(IU_SHELLEXT)
		SaveConvertProfiles(xml.getRoot("ImageUploader").GetChild("Settings").GetChild("Image").GetChild("Profiles"));
		SaveServerProfiles( xml.getRoot("ImageUploader").GetChild("Settings").GetChild("Uploading").GetChild("ServerProfiles") );
#endif
		SaveAccounts(xml.getRoot("ImageUploader").GetChild("Settings").GetChild("ServersParams"));
		//std::cerr << "Saving setting to "<< IuCoreUtils::WstringToUtf8((LPCTSTR)fileName_);
		xml.SaveToFile(fileName_);

#if !defined(IU_SERVERLISTTOOL) && !defined(IU_CLI)
		CRegistry Reg;
		Reg.SetRootKey(HKEY_CURRENT_USER);
		// if(ExplorerContextMenu)
		{
			bool canCreateRegistryKey = ( ExplorerContextMenu );
			if ( Reg.SetKey("Software\\Zenden.ws\\Image Uploader", canCreateRegistryKey ) ) {
				if ( ExplorerContextMenu ) {
					Reg.WriteBool( "ExplorerCascadedMenu", ExplorerCascadedMenu );
					Reg.WriteBool("ExplorerContextMenu", ExplorerContextMenu);
					Reg.WriteBool( "ExplorerVideoContextMenu", ExplorerVideoContextMenu );
					Reg.WriteString( "Language", Language );
				} else {
					Reg.DeleteValue("ExplorerCascadedMenu");
					Reg.DeleteValue("ExplorerContextMenu");
					Reg.DeleteValue("ExplorerVideoContextMenu");
					Reg.DeleteValue("Language");
				}
			}
		}
		/*else
		{
		   //Reg.DeleteKey("Software\\Zenden.ws\\Image Uploader");
		}*/
		EnableAutostartup(AutoStartup);

		if (SendToContextMenu_changed   || ExplorerContextMenu_changed) {
			AutoStartup_changed = false;
			BOOL b;
			if ( IsVista() && IsElevated(&b) != S_OK ) {
				// Start new elevated process 
				ApplyRegistrySettings();
			} else {
				// Process has already admin rights
				ApplyRegSettingsRightNow();
			}
		}

		ExplorerContextMenu_changed = false;
		SendToContextMenu_changed = false;

		if (ShowTrayIcon_changed)
		{
			ShowTrayIcon_changed = false;
			if (ShowTrayIcon)
			{
				if (!IsRunningFloatingWnd())
				{
					CmdLine.AddParam(_T("/tray"));
					floatWnd.CreateTrayIcon();
				}
			}
			else
			{
				HWND TrayWnd = FindWindow(0, _T("ImageUploader_TrayWnd"));
				if (TrayWnd) {
					::SendMessage( TrayWnd, WM_CLOSETRAYWND, 0, 0 );
				}
			}
		}
		else if (ShowTrayIcon)
		{
			HWND TrayWnd = FindWindow(0, _T("ImageUploader_TrayWnd"));
			if (TrayWnd)
				SendMessage(TrayWnd, WM_RELOADSETTINGS,  (floatWnd.m_hWnd) ? 1 : 0, (Settings.Hotkeys_changed) ? 0 : 1);
		}

		Settings.Hotkeys_changed  = false;
#endif
		return true;
	}