예제 #1
0
void *
CWinFileReceivePipe::Run()
{
	long dataLen=0, startData=0;
	short good=0;
	HANDLE dataRef;
	
	dataRef = CreateFile(mXI->filepath, GENERIC_WRITE, 0, NIL, OPEN_ALWAYS,
							FILE_FLAG_WRITE_THROUGH, NIL);
	if(dataRef == INVALID_HANDLE_VALUE)
		goto error;
	if(!mXI->pipe->DoPipeEnded())
	{
		WriteFork(dataRef, startData, -1);
		if(mXI->bytesTotal && !mXI->fatalErr && mXI->setEOF)
			SetEndOfFile(dataRef);
		CloseHandle(dataRef);
		if(!mXI->pipe->DoPipeAborted())
		{
			good=1;
		}
		LogTransfer(mXI, 0, good);
	}
	mXI->pipe->DoAckEndPipe();
	return (void *)1L;
error:
	mXI->fatalErr=1;	// needs improved error checking
	mXI->pipe->DoAbortPipe();
	return (void *)1L;
}
예제 #2
0
void *
CWinFileSendPipe::Run()
{
	HANDLE fileRef;
	long pipePos=0;
	
	fileRef = CreateFile(mXI->filepath, GENERIC_READ, FILE_SHARE_READ, NIL, OPEN_EXISTING, 0, NIL);
	if(fileRef == INVALID_HANDLE_VALUE)
		goto error;
startSend:
	SetFilePointer(fileRef, pipePos, NIL, FILE_BEGIN); // ***** check this
	ReadFork(fileRef, 0, 0, mXI->bytesTotal);
	CloseHandle(fileRef);
	if(mXI->pipe->DoEndPipe(&pipePos))
		goto startSend;
	LogTransfer(mXI, 1, (mXI->fatalErr==0));
	return (void *)1L;
error:
	mXI->fatalErr=1;
	mXI->pipe->DoAbortPipe();
	return (void *)1L;
}
예제 #3
0
	/** Process a draw cash command **/
	bool GiveCash::UserCmd_DrawCash(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) 
	{
		// The last error.
		HK_ERROR err;

		// Get the current character name
		wstring wscCharname = (const wchar_t*) Players.GetActiveCharacterName(iClientID);

		// Get the parameters from the user command.
		wstring wscTargetCharname = GetParam(wscParam, L' ', 0);
		wstring wscCode = GetParam(wscParam, L' ', 1);
		wstring wscCash = GetParam(wscParam, L' ', 2);
		wscCash = ReplaceStr(wscCash, L".", L"");
		wscCash = ReplaceStr(wscCash, L",", L"");
		wscCash = ReplaceStr(wscCash, L"$", L"");
		int cash = ToInt(wscCash);
		if (!wscTargetCharname.length() || !wscCode.length() || cash<=0)
		{
			PrintUserCmdText(iClientID, L"ERR Invalid parameters");
			PrintUserCmdText(iClientID, usage);
			return true;
		}

		CAccount *iTargetAcc=HkGetAccountByCharname(wscTargetCharname);
		if (iTargetAcc==0)
		{
			PrintUserCmdText(iClientID, L"ERR char does not exist");
			return true;	
		}

		int secs = 0;
		HkGetOnLineTime(wscTargetCharname, secs);
		if (secs<set_iMinTime)
		{
			PrintUserCmdText(iClientID, L"ERR insufficient time online");
			return true;
		}

		if (InBlockedSystem(wscCharname) || InBlockedSystem(wscTargetCharname))
		{
			PrintUserCmdText(iClientID, L"ERR cash transfer blocked");
			return true;
		}

		string scFile;
		if (!GetUserFilePath(scFile, wscTargetCharname, "-givecash.ini"))
			return true;

		wstring wscTargetCode = IniGetWS(scFile, "Settings", "Code", L"");
		if (!wscTargetCode.length() || wscTargetCode!=wscCode)
		{
			PrintUserCmdText(iClientID, L"ERR cash account access denied");
			return true;
		}

		if (cash<set_iMinTransfer || cash<0) {
			PrintUserCmdText(iClientID, L"ERR Transfer too small, minimum transfer "+ToMoneyStr(set_iMinTransfer)+L" credits");
			return true;
		}

		int tCash = 0;
		if ((err = HkGetCash(wscTargetCharname, tCash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		if (tCash<cash)
		{
			PrintUserCmdText(iClientID, L"ERR Insufficient credits");
			return true;
		}

		// Check the adding this cash to this player will not
		// exceed the maximum ship value.
		float fTargetValue = 0.0f;
		if (HKGetShipValue(wscCharname, fTargetValue) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		if ((fTargetValue + cash) > 2000000000.0f)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer will exceed credit limit");
			return true;
		}

		// Calculate the new cash
		int iExpectedCash = 0;
		if ((err = HkGetCash(wscCharname, iExpectedCash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		iExpectedCash += cash;

		// Do an anticheat check on the receiving ship first.
		if (HkAntiCheat(iClientID) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer failed");							
			AddLog("NOTICE: Possible cheating when drawing %s credits from %s (%s) to %s (%s)",
				wstos(ToMoneyStr(cash)).c_str(),
				wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
				wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());				
			return true;
		}
		HkSaveChar(iClientID);


		uint targetClientId = HkGetClientIdFromCharname(wscTargetCharname);
		if (targetClientId != -1)
		{
			if (ClientInfo[iClientID].iTradePartner || ClientInfo[targetClientId].iTradePartner)
			{
				PrintUserCmdText(iClientID, L"ERR Trade window open");
				AddLog("NOTICE: Trade window open when drawing %s credits from %s (%s) to %s (%s) %u %u",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
					iClientID, targetClientId);			
				return true;
			}
		}

		// Remove cash from target character
		if ((err = HkAddCash(wscTargetCharname, 0-cash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}

		if (targetClientId!=-1 && !HkIsInCharSelectMenu(targetClientId))
		{		
			if (HkAntiCheat(targetClientId) != HKE_OK)
			{
				PrintUserCmdText(iClientID, L"ERR Transfer failed");						
				AddLog("NOTICE: Possible cheating when drawing %s credits from %s (%s) to %s (%s)",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());				
				return true;
			}
			HkSaveChar(targetClientId);
		}

		// Add cash to this player
		if ((err = HkAddCash(wscCharname, cash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}

		if (HkAntiCheat(iClientID) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer failed");			
			AddLog("NOTICE: Possible cheating when drawing %s credits from %s (%s) to %s (%s)",
				wstos(ToMoneyStr(cash)).c_str(),
				wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
				wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());				
			return true;
		}
		HkSaveChar(iClientID);
		
		// Check that receiving player has the correct ammount of cash.
		int iCurrCash;
		if ((err = HkGetCash(wscCharname, iCurrCash)) != HKE_OK
			|| iCurrCash != iExpectedCash)
		{
			AddLog("ERROR: Cash transfer error when drawing %s credits from %s (%s) to %s (%s) current %s credits expected %s credits ",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
					wstos(ToMoneyStr(iCurrCash)).c_str(), wstos(ToMoneyStr(iExpectedCash)).c_str());
			PrintUserCmdText(iClientID, L"ERR Transfer failed");
		}

		// If the target player is online then send them a message saying
		// telling them that they've received transfered cash.
		wstring msg = L"You have transferred " + ToMoneyStr(cash) + L" credits to " + wscCharname;
		if (targetClientId!=-1 && !HkIsInCharSelectMenu(targetClientId))
		{
			PrintUserCmdText(targetClientId, L"%s", msg.c_str());
		}
		// Otherwise we assume that the character is offline so we record an entry
		// in the character's givecash.ini. When they come online we inform them
		// of the transfer. The ini is cleared when ever the character logs in.
		else
		{
			LogTransfer(wscTargetCharname, msg);
		}

		AddLog("NOTICE: Draw %s credits from %s (%s) to %s (%s)",
			wstos(ToMoneyStr(cash)).c_str(),
			wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
			wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());

		// A friendly message explaining the transfer.
		msg = GetTimeString(set_bLocalTime) + L": You have drawn " + ToMoneyStr(cash) + L" credits from " + wscTargetCharname;
		PrintUserCmdText(iClientID, L"%s", msg.c_str());
		return true;
	}
예제 #4
0
	/** Process a give cash command */
	bool GiveCash::UserCmd_GiveCash(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) 
	{
		// The last error.
		HK_ERROR err;

		// Get the current character name
		wstring wscCharname = (const wchar_t*) Players.GetActiveCharacterName(iClientID);

		// Get the parameters from the user command.
		wstring wscTargetCharname = GetParam(wscParam, L' ', 0);
		wstring wscCash = GetParam(wscParam, L' ', 1);
		wstring wscAnon = GetParam(wscParam, L' ', 2);
		wscCash = ReplaceStr(wscCash, L".", L"");
		wscCash = ReplaceStr(wscCash, L",", L"");
		wscCash = ReplaceStr(wscCash, L"$", L"");
		int cash = ToInt(wscCash);
		if ((!wscTargetCharname.length() || cash<=0) || (wscAnon.size() && wscAnon!=L"anon"))
		{
			PrintUserCmdText(iClientID, L"ERR Invalid parameters");
			PrintUserCmdText(iClientID, usage);
			return true;
		}

		bool bAnon = false;
		if (wscAnon==L"anon")
			bAnon = true;

		if (HkGetAccountByCharname(wscTargetCharname)==0)
		{
			PrintUserCmdText(iClientID, L"ERR char does not exist");
			return true;	
		}

		int secs = 0;
		HkGetOnLineTime(wscCharname, secs);
		if (secs<set_iMinTime)
		{
			PrintUserCmdText(iClientID, L"ERR insufficient time online");
			return true;
		}

		if (InBlockedSystem(wscCharname) || InBlockedSystem(wscTargetCharname))
		{
			PrintUserCmdText(iClientID, L"ERR cash transfer blocked");
			return true;	
		}

		// Read the current number of credits for the player
		// and check that the character has enough cash.
		int iCash = 0;
		if ((err = HkGetCash(wscCharname, iCash)) != HKE_OK) {
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		if (cash<set_iMinTransfer || cash<0) {
			PrintUserCmdText(iClientID, L"ERR Transfer too small, minimum transfer "+ToMoneyStr(set_iMinTransfer)+L" credits");
			return true;
		}
		if (iCash<cash)
		{
			PrintUserCmdText(iClientID, L"ERR Insufficient credits");
			return true;
		}

		// Prevent target ship from becoming corrupt.
		float fTargetValue = 0.0f;
		if (HKGetShipValue(wscTargetCharname, fTargetValue) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		if ((fTargetValue + cash) > 2000000000.0f)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer will exceed credit limit");
			return true;
		}

		// Calculate the new cash
		int iExpectedCash = 0;
		if ((err = HkGetCash(wscTargetCharname, iExpectedCash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Get cash failed err="+HkErrGetText(err));
			return true;
		}
		iExpectedCash += cash;

		// Do an anticheat check on the receiving character first.
		uint targetClientId = HkGetClientIdFromCharname(wscTargetCharname);
		if (targetClientId!=-1 && !HkIsInCharSelectMenu(targetClientId))
		{
			if (HkAntiCheat(targetClientId) != HKE_OK)
			{
				PrintUserCmdText(iClientID, L"ERR Transfer failed");			
				AddLog("NOTICE: Possible cheating when sending %s credits from %s (%s) to %s (%s)",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str());		
				return true;
			}
			HkSaveChar(targetClientId);
		}
		
		if (targetClientId != -1)
		{
			if (ClientInfo[iClientID].iTradePartner || ClientInfo[targetClientId].iTradePartner)
			{
				PrintUserCmdText(iClientID, L"ERR Trade window open");
				AddLog("NOTICE: Trade window open when sending %s credits from %s (%s) to %s (%s) %u %u",
						wstos(ToMoneyStr(cash)).c_str(),
						wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
						wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
						iClientID, targetClientId);
				return true;
			}
		}

		// Remove cash from current character and save it checking that the
		// save completes before allowing the cash to be added to the target ship.
		if ((err = HkAddCash(wscCharname, 0-cash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Remove cash failed err="+HkErrGetText(err));
			return true;
		}

		if (HkAntiCheat(iClientID) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer failed");			
			AddLog("NOTICE: Possible cheating when sending %s credits from %s (%s) to %s (%s)",
				wstos(ToMoneyStr(cash)).c_str(),
				wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
				wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str());			
			return true;
		}
		HkSaveChar(iClientID);

		// Add cash to target character
		if ((err = HkAddCash(wscTargetCharname, cash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Add cash failed err="+HkErrGetText(err));
			return true;
		}

		targetClientId = HkGetClientIdFromCharname(wscTargetCharname);
		if (targetClientId!=-1 && !HkIsInCharSelectMenu(targetClientId))
		{
			if (HkAntiCheat(targetClientId) != HKE_OK)
			{
				PrintUserCmdText(iClientID, L"ERR Transfer failed");			
				AddLog("NOTICE: Possible cheating when sending %s credits from %s (%s) to %s (%s)",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str());		
				return true;
			}
			HkSaveChar(targetClientId);
		}		

      
		// Check that receiving character has the correct ammount of cash.
		int iCurrCash;
		if ((err = HkGetCash(wscTargetCharname, iCurrCash)) != HKE_OK
			|| iCurrCash != iExpectedCash)
		{
			AddLog("ERROR: Cash transfer error when sending %s credits from %s (%s) to %s (%s) current %s credits expected %s credits ",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
					wstos(ToMoneyStr(iCurrCash)).c_str(), wstos(ToMoneyStr(iExpectedCash)).c_str());
			PrintUserCmdText(iClientID, L"ERR Transfer failed");
			return true;
		}

		// If the target player is online then send them a message saying
		// telling them that they've received the cash.
		wstring msg = L"You have received " + ToMoneyStr(cash) + L" credits from " + ((bAnon)?L"anonymous":wscCharname);
		if (targetClientId!=-1 && !HkIsInCharSelectMenu(targetClientId))
		{
			PrintUserCmdText(targetClientId, L"%s", msg.c_str());
		}
		// Otherwise we assume that the character is offline so we record an entry
		// in the character's givecash.ini. When they come online we inform them
		// of the transfer. The ini is cleared when ever the character logs in.
		else
		{
			wstring msg = L"You have received " + ToMoneyStr(cash) + L" credits from " + ((bAnon)?L"anonymous":wscCharname);
			LogTransfer(wscTargetCharname, msg);
		}

		AddLog("NOTICE: Send %s credits from %s (%s) to %s (%s)",
			wstos(ToMoneyStr(cash)).c_str(),
			wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
			wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str());

		// A friendly message explaining the transfer.
		msg = L"You have sent " + ToMoneyStr(cash) + L" credits to " + wscTargetCharname;
		if (bAnon)
			msg += L" anonymously";
		PrintUserCmdText(iClientID, L"%s", msg.c_str());
		return true;
	}