Exemple #1
0
	/** Process a set cash code command */
	bool GiveCash::UserCmd_SetCashCode(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) 
	{
		wstring wscCharname = (const wchar_t*) Players.GetActiveCharacterName(iClientID);
		string scFile;
		if (!GetUserFilePath(scFile, wscCharname, "-givecash.ini"))
			return true;

		wstring wscCode = GetParam(wscParam, L' ', 0);

		if (!wscCode.size())
		{
			PrintUserCmdText(iClientID, L"ERR Invalid parameters");
			PrintUserCmdText(iClientID, usage);
		}
		else if (wscCode==L"none")
		{
			IniWriteW(scFile, "Settings", "Code", L"");
			PrintUserCmdText(iClientID, L"OK Account code cleared");
		}
		else
		{
			IniWriteW(scFile, "Settings", "Code", wscCode);
			PrintUserCmdText(iClientID, L"OK Account code set to "+wscCode);
		}
		return true;
	}
Exemple #2
0
	/** Process a set the move char code command */
	bool Rename::UserCmd_SetMoveCharCode(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage)
	{
		// Don't indicate an error if moving is disabled.
		if (!set_bEnableMoveChar)
			return false;

		if (wscParam.size()==0)
		{
			PrintUserCmdText(iClientID, L"ERR Invalid parameters");
			PrintUserCmdText(iClientID, usage);
			return true;
		}

		wstring wscCharname = (const wchar_t*) Players.GetActiveCharacterName(iClientID);
		string scFile;
		if (!GetUserFilePath(scFile, wscCharname, "-movechar.ini"))
		{
			PrintUserCmdText(iClientID, L"ERR Character does not exist");
			return true;
		}

		wstring wscCode = Trim(GetParam(wscParam, L' ', 0));
		if (wscCode==L"none")
		{
			IniWriteW(scFile, "Settings", "Code", L"");
			PrintUserCmdText(iClientID, L"OK Movechar code cleared");
		}
		else
		{
			IniWriteW(scFile, "Settings", "Code", wscCode);
			PrintUserCmdText(iClientID, L"OK Movechar code set to "+wscCode);
		}
		return true;
	}
	bool PlayerInfo::UserCmd_SetInfo(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage)
	{
		uint iPara = ToInt(GetParam(wscParam, ' ', 0));
		const wstring &wscCommand = GetParam(wscParam, ' ', 1);
		const wstring &wscMsg = GetParamToEnd(wscParam, ' ', 2);

		string scFilePath = GetUserFilePath(Players.GetActiveCharacterName(iClientID), "-info.ini");
		if (scFilePath.length()==0)
			return false;

		if (iPara > 0 && iPara <= MAX_PARAGRAPHS && wscCommand == L"a")
		{
			int length = CurrLength(scFilePath) + wscMsg.length();
			if (length > MAX_CHARACTERS)
			{
				PrintUserCmdText(iClientID, L"ERR Too many characters. Limit is %d", MAX_CHARACTERS);
				return false;
			}

			wstring wscNewMsg = IniGetLongWS(scFilePath, "Info", itos(iPara), L"") + XMLText(wscMsg);
			IniWriteW(scFilePath, "Info", itos(iPara), wscNewMsg);
			PrintUserCmdText(iClientID, L"OK %d/%d characters used", length, MAX_CHARACTERS);
		}
		else if (iPara > 0 && iPara <= MAX_PARAGRAPHS && wscCommand == L"d")
		{
			IniWriteW(scFilePath, "Info", itos(iPara), L"");
			PrintUserCmdText(iClientID, L"OK");		
		}
		else
		{
			PrintUserCmdText(iClientID, L"ERR Invalid parameters");
			PrintUserCmdText(iClientID, L"/setinfo <paragraph> <command> <text>");
			PrintUserCmdText(iClientID, L"|  <paragraph> The paragraph number in the range 1-%d", MAX_PARAGRAPHS);
			PrintUserCmdText(iClientID, L"|  <command> The command to perform on the paragraph, 'a' for append, 'd' for delete");
		}

		return true;
	}
/* copy pasta from playercntl as to provide independance*/
bool MailSend(const wstring &wscCharname, const string &scExtension, const wstring &wscMsg)
{
	// Get the target player's message file.
	string scFilePath = GetUserFilePath(wscCharname, scExtension);
	if (scFilePath.length() == 0)
		return false;

	// Move all mail up one slot starting at the end. We automatically
	// discard the oldest messages.
	for (int iMsgSlot = MAX_MAIL_MSGS - 1; iMsgSlot>0; iMsgSlot--)
	{
		wstring wscTmpMsg = IniGetWS(scFilePath, "Msgs", itos(iMsgSlot), L"");
		IniWriteW(scFilePath, "Msgs", itos(iMsgSlot + 1), wscTmpMsg);

		bool bTmpRead = IniGetB(scFilePath, "MsgsRead", itos(iMsgSlot), false);
		IniWrite(scFilePath, "MsgsRead", itos(iMsgSlot + 1), (bTmpRead ? "yes" : "no"));
	}

	// Write message into the slot
	IniWriteW(scFilePath, "Msgs", "1", GetTimeString(set_bLocalTime) + L" " + wscMsg);
	IniWrite(scFilePath, "MsgsRead", "1", "no");
	return true;
}
Exemple #5
0
	/**
		Delete a message
	*/
	bool MailDel(const wstring &wscCharname, const string &scExtension, int iMsg)
	{
		// Get the target player's message file.
		string scFilePath = GetUserFilePath(wscCharname, scExtension);
		if (scFilePath.length()==0)
			return false;

		// Move all mail down one slot starting at the deleted message to overwrite it
		for (int iMsgSlot = iMsg; iMsgSlot<MAX_MAIL_MSGS; iMsgSlot++)
		{
			wstring wscTmpMsg = IniGetWS(scFilePath, "Msgs", itos(iMsgSlot+1), L"");
			IniWriteW(scFilePath, "Msgs", itos(iMsgSlot), wscTmpMsg);

			bool bTmpRead = IniGetB(scFilePath, "MsgsRead", itos(iMsgSlot+1), false);
			IniWrite(scFilePath, "MsgsRead", itos(iMsgSlot), (bTmpRead?"yes":"no"));
		}
		return true;
	}
Exemple #6
0
	/// Set the move char code for all characters in the account
	void Rename::AdminCmd_SetAccMoveCode(CCmds* cmds, const wstring &wscCharname, const wstring &wscCode)
	{
		// Don't indicate an error if moving is disabled.
		if (!set_bEnableMoveChar)
			return;

		if (!(cmds->rights & RIGHT_SUPERADMIN))
		{
			cmds->Print(L"ERR No permission\n");
			return;
		}

		wstring wscDir;
		if (HkGetAccountDirName(wscCharname, wscDir)!=HKE_OK)
		{
			cmds->Print(L"ERR Charname not found\n");
			return;
		}

		if (wscCode.length()==0)
		{
			cmds->Print(L"ERR Code too small, set to none to clear.\n");
			return;
		}

		// Get the account path.
		char szDataPath[MAX_PATH];
		GetUserDataPath(szDataPath);
		string scPath = string(szDataPath) + "\\Accts\\MultiPlayer\\" + wstos(wscDir) + "\\*.fl";

		// Open the directory iterator.
		WIN32_FIND_DATA FindFileData; 
		HANDLE hFileFind = FindFirstFile(scPath.c_str(), &FindFileData);
		if (hFileFind==INVALID_HANDLE_VALUE)
		{
			cmds->Print(L"ERR Account directory not found\n");
			return;
		}

		// Iterate it
		do
		{
			string scCharfile = FindFileData.cFileName;
			string scMoveCodeFile = string(szDataPath) + "\\Accts\\MultiPlayer\\" + wstos(wscDir) + "\\"
				+ scCharfile.substr(0,scCharfile.size()-3) + "-movechar.ini";
			if (wscCode==L"none")
			{
				IniWriteW(scMoveCodeFile, "Settings", "Code", L"");
				cmds->Print(L"OK Movechar code cleared on "+stows(scCharfile)+L"\n");
			}
			else
			{
				IniWriteW(scMoveCodeFile, "Settings", "Code", wscCode);
				cmds->Print(L"OK Movechar code set to "+wscCode +L" on "+stows(scCharfile)+L"\n");
			}
		}
		while (FindNextFile(hFileFind, &FindFileData));
		FindClose(hFileFind); 

		cmds->Print(L"OK\n");
	}
Exemple #7
0
	void Timer()
	{
		// Every 100 seconds expire unused tags and save the tag database
		/* uint curr_time = (uint)time(0);
		if (curr_time % 100)
		{
			for (std::map<wstring, TAG_DATA>::iterator i = mapTagToPassword.begin(); i != mapTagToPassword.end(); ++i)
			{
				if (i->second.last_access < (curr_time - (3600 * 24 * 30)))
				{
					mapTagToPassword.erase(i);
					break;
				}
			}
			SaveSettings();
		} */

		// Check for pending renames and execute them. We do this on a timer so that the
		// player is definitely not online when we do the rename.
		while (pendingRenames.size())
		{
			RENAME o = pendingRenames.front();
			if (HkGetClientIdFromCharname(o.wscCharname)!=-1)
				return;
			
			pendingRenames.pop_front();

			CAccount *acc = HkGetAccountByCharname(o.wscCharname);
			
			// Delete the character from the existing account, create a new character with the
			// same name in this account and then copy over it with the save character file.
			try
			{
				if (!acc)
					throw "no acc";

				HkLockAccountAccess(acc, true);
				HkUnlockAccountAccess(acc);

				// Move the char file to a temporary one.
				if (!::MoveFileExA(o.scSourceFile.c_str(), o.scDestFileTemp.c_str(),
					MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH))
					throw "move src to temp failed";
			
				// Decode the char file, update the char name and re-encode it.
				// Add a space to the value so the ini file line looks like "<key> = <value>"
				// otherwise Ioncross Server Operator can't decode the file correctly
				flc_decode(o.scDestFileTemp.c_str(), o.scDestFileTemp.c_str());
				IniWriteW(o.scDestFileTemp, "Player", "Name", o.wscNewCharname);
				if (!set_bDisableCharfileEncryption)
				{
					flc_encode(o.scDestFileTemp.c_str(), o.scDestFileTemp.c_str());
				}

				// Create and delete the character
				HkDeleteCharacter(acc, o.wscCharname);
				HkNewCharacter(acc, o.wscNewCharname);

				// Move files around
				if (!::MoveFileExA(o.scDestFileTemp.c_str(), o.scDestFile.c_str(),
					MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH))
					throw "move failed";
				if (::PathFileExistsA(o.scSourceFile.c_str()))
					throw "src still exists";
				if (!::PathFileExistsA(o.scDestFile.c_str()))
					throw "dest does not exist";

				// The rename worked. Log it and save the rename time.
				AddLog("NOTICE: User rename %s to %s (%s)",wstos(o.wscCharname).c_str(),wstos(o.wscNewCharname).c_str(), wstos(HkGetAccountID(acc)).c_str());
			}
			catch (char *err)
			{
				AddLog("ERROR: User rename failed (%s) from %s to %s (%s)", err, wstos(o.wscCharname).c_str(),wstos(o.wscNewCharname).c_str(), wstos(HkGetAccountID(acc)).c_str());
			}
		}

		while (pendingMoves.size())
		{
			MOVE o = pendingMoves.front();
			if (HkGetClientIdFromCharname(o.wscDestinationCharname)!=-1)
				return;
			if (HkGetClientIdFromCharname(o.wscMovingCharname)!=-1)
				return;
			
			pendingMoves.pop_front();

			CAccount *acc = HkGetAccountByCharname(o.wscDestinationCharname);
			CAccount *oldAcc = HkGetAccountByCharname(o.wscMovingCharname);

			// Delete the character from the existing account, create a new character with the
			// same name in this account and then copy over it with the save character file.
			try
			{
				HkLockAccountAccess(acc, true);
				HkUnlockAccountAccess(acc);

				HkLockAccountAccess(oldAcc, true);
				HkUnlockAccountAccess(oldAcc);

				// Move the char file to a temporary one.
				if (!::MoveFileExA(o.scSourceFile.c_str(), o.scDestFileTemp.c_str(),
					MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH))
					throw "move src to temp failed";

				// Create and delete the character
				HkDeleteCharacter(oldAcc, o.wscMovingCharname);
				HkNewCharacter(acc, o.wscMovingCharname);

				// Move files around
				if (!::MoveFileExA(o.scDestFileTemp.c_str(), o.scDestFile.c_str(),
					MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH))
					throw "move failed";
				if (::PathFileExistsA(o.scSourceFile.c_str()))
					throw "src still exists";
				if (!::PathFileExistsA(o.scDestFile.c_str()))
					throw "dest does not exist";

				// The move worked. Log it.
				AddLog("NOTICE: Character %s moved from %s to %s",
					wstos(o.wscMovingCharname).c_str(),
					wstos(HkGetAccountID(oldAcc)).c_str(),
					wstos(HkGetAccountID(acc)).c_str());

			}
			catch (char *err)
			{
				AddLog("ERROR: Character %s move failed (%s) from %s to %s",
					wstos(o.wscMovingCharname).c_str(), err,
					wstos(HkGetAccountID(oldAcc)).c_str(),
					wstos(HkGetAccountID(acc)).c_str());
			}
		}
	}