void CCmds::CmdGetCash(const wstring &wscCharname) { RIGHT_CHECK(RIGHT_CASH); int iCash; if(HKSUCCESS(HkGetCash(wscCharname, iCash))) Print(L"cash=%d\nOK\n", iCash); else PrintError(); }
void CCmds::CmdSetCash(const wstring &wscCharname, int iAmount) { RIGHT_CHECK(RIGHT_CASH); int iCash; if(HKSUCCESS(HkGetCash(wscCharname, iCash))) { HkAddCash(wscCharname, iAmount - iCash); CmdGetCash(wscCharname); } else PrintError(); }
void CCmds::CmdAddCashSec(const wstring &wscCharname, int iAmountCheck, int iAmount) { RIGHT_CHECK(RIGHT_CASH); int iCash; if(HKSUCCESS(HkGetCash(wscCharname, iCash))) { if(iCash != iAmountCheck) Print(L"ERR Security check failed\n"); else CmdAddCash(wscCharname, iAmount); } else PrintError(); }
/** Process a show cash command **/ bool GiveCash::UserCmd_ShowCash(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); if (!wscTargetCharname.length() || !wscCode.length()) { PrintUserCmdText(iClientID, L"ERR Invalid parameters"); PrintUserCmdText(iClientID, usage); return true; } CAccount *acc=HkGetAccountByCharname(wscTargetCharname); if (acc==0) { PrintUserCmdText(iClientID, L"ERR char does not exist"); 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; } int iCash = 0; if ((err = HkGetCash(wscTargetCharname, iCash)) != HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } PrintUserCmdText(iClientID, L"OK Account "+wscTargetCharname+L" has " + ToMoneyStr(iCash) + L" credits"); return true; }
bool UserCmd_BountyAddTo(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) { if (!bPluginEnabled) { PrintUserCmdText(iClientID, L"BountyTracker is disabled."); return true; } // Get the parameters from the user command. wstring wscName = GetParam(wscParam, L' ', 0); wstring wscCash = GetParam(wscParam, L' ', 1); wstring wscxTimes = GetParam(wscParam, L' ', 2); wscCash = ReplaceStr(wscCash, L".", L""); wscCash = ReplaceStr(wscCash, L",", L""); wscCash = ReplaceStr(wscCash, L"$", L""); wscCash = ReplaceStr(wscCash, L"e6", L"000000"); if (wscName == L"") { PrintUserCmdText(iClientID, L"ERR invalid name\n"); return false; } if (HkGetAccountByCharname(wscName) == 0) { PrintUserCmdText(iClientID, L"ERR Player does not exist"); return true; } if (wscCash == L"") { PrintUserCmdText(iClientID, L"ERR invalid cash amount\n"); return false; } if (stoi(wscCash) < 1000000) { PrintUserCmdText(iClientID, L"ERR bounty cannot be less than 1,000,000 s.c"); return true; } //get bounty BountyTargetInfo BTIat = mapBountyTargets[ToLower(wscName)]; //check if it is active if (!BTIat.active) { PrintUserCmdText(iClientID, L"ERR bounty not currently active"); return true; } //check user has enough money for the bounty int iCash; HkGetCash(stows(ToLower(wstos((wchar_t*)Players.GetActiveCharacterName(iClientID)))), iCash); if (iCash < (stoi(wscCash) * stoi(BTIat.xTimes))) { PrintUserCmdText(iClientID, L"ERR Not enough cash for bounty."); return true; } HkAddCash((wchar_t*)Players.GetActiveCharacterName(iClientID), 0 - (stoi(wscCash) * stoi(BTIat.xTimes))); if (deleteBountyCfg(BTIat)) { //ConPrint(L"bounty removed from cfg\n"); } else { ConPrint(L"BOUNTYTRACKER: Err removing from cfg. is server admin?\n"); } BTIat.Cash = itos(stoi(BTIat.Cash) + stoi(wscCash));//update cash bounty PrintUserCmdText(iClientID, L"Uploading to Neural Net..."); mapBountyTargets[ToLower(wscName)] = BTIat; if (appendBountyCfg(BTIat)) { //ConPrint(L"cfg saved\n"); } else { ConPrint(L"BOUNTYTRACKER: Err saving to cfg. is serevr admin?\n"); } PrintUserCmdText(iClientID, L"OK"); return true; }
bool UserCmd_BountyAdd(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) { if (!bPluginEnabled) { PrintUserCmdText(iClientID, L"BountyTracker is disabled."); return true; } // Get the parameters from the user command. wstring wscName = GetParam(wscParam, L' ', 0); wstring wscCash = GetParam(wscParam, L' ', 1); wstring wscxTimes = GetParam(wscParam, L' ', 2); wscCash = ReplaceStr(wscCash, L".", L""); wscCash = ReplaceStr(wscCash, L",", L""); wscCash = ReplaceStr(wscCash, L"$", L""); wscCash = ReplaceStr(wscCash, L"e6", L"000000");//because scientific notation is cool int iOnlineSecs; HkGetOnLineTime((wchar_t*)Players.GetActiveCharacterName(iClientID), iOnlineSecs); if (iOnlineSecs < 7200)// 7200 = 2hrs { PrintUserCmdText(iClientID, L"ERR Char is too new"); return true; } //you are not allowed to create a bounty. ERR rank too low (note, find out what a good rank should be to have access to this. no fresh chars can //create bounties. this way we can protect against creating random fresh accs, tranferring cash, and setting copious amounts of bounties. if (wscName == L"") { PrintUserCmdText(iClientID, L"ERR invalid name\n"); return false; } if (HkGetAccountByCharname(wscName) == 0) { PrintUserCmdText(iClientID, L"ERR Player does not exist"); return true; } if (mapBountyTargets[ToLower(wscName)].active) { PrintUserCmdText(iClientID, L"ERR Player already has an active bounty\n"); return true; } if (mapBountyTargets[ToLower(wscName)].lastTime != "") { if ((stoi(mapBountyTargets[ToLower(wscName)].lastTime) + 3600) > (int)time(0)) { PrintUserCmdText(iClientID, L"ERR Player is protected\n"); PrintUserCmdText(iClientID, stows(itos((stoi(mapBountyTargets[ToLower(wscName)].lastTime) + 3600) - (int)time(0))) + L"'s remaining"); return true; } } if (iClientID == HkGetClientIdFromCharname(stows(mapBountyTargets[ToLower(wscName)].lastIssuer)))//not too sure about this { PrintUserCmdText(iClientID, L"ERR You cannot double a bounty on this player\n"); return true; } if (wscCash == L"") { PrintUserCmdText(iClientID, L"ERR invalid cash amount\n"); return false; } if (wscxTimes == L"") { PrintUserCmdText(iClientID, L"ERR invalid contract limit\n"); return false; } if (stoi(wscCash) < 1000000) { PrintUserCmdText(iClientID, L"ERR bounty cannot be less than 1,000,000 s.c"); return true; } if (stoi(wscxTimes) < 0 || stoi(wscxTimes) > 5) { PrintUserCmdText(iClientID, L"ERR bounty contract limit cannot be less than 0 or more than 5"); return true; } BountyTargetInfo BTIa = mapBountyTargets[ToLower(wscName)]; //generate new bounty map values BTIa.Char = ToLower(wstos(wscName)); BTIa.Cash = wstos(wscCash); BTIa.xTimes = wstos(wscxTimes); BTIa.issuer = ToLower(wstos((wchar_t*)Players.GetActiveCharacterName(iClientID))); BTIa.lastIssuer = BTIa.issuer; BTIa.active = true; BTIa.lastTime = ""; BTIa.issueTime = itos((int)time(0)); //check user has enough money for the bounty int iCash; HkGetCash(stows(BTIa.issuer), iCash); if (iCash < (stoi(BTIa.Cash) * stoi(BTIa.xTimes))) { PrintUserCmdText(iClientID, L"ERR Not enough cash for bounty."); return true; } HkAddCash((wchar_t*)Players.GetActiveCharacterName(iClientID), 0 - (stoi(BTIa.Cash) * stoi(BTIa.xTimes))); PrintUserCmdText(iClientID, L"Uploading to Neural Net..."); mapBountyTargets[ToLower(wscName)] = BTIa; wstring PFwsTargetInfo; PFwsTargetInfo = L"Target: "; PFwsTargetInfo += ToLower(wscName); PFwsTargetInfo += L" Worth: "; PFwsTargetInfo += stows(BTIa.Cash); PFwsTargetInfo += L" Contracts Left: "; PFwsTargetInfo += stows(BTIa.xTimes); PFwsTargetInfo += L" Issuer: "; PFwsTargetInfo += stows(BTIa.issuer); PFwsTargetInfo += L" Issued: "; PFwsTargetInfo += stows(BTIa.issueTime); PrintUserCmdText(iClientID, PFwsTargetInfo); if (appendBountyCfg(BTIa)) { ConPrint(L"cfg saved\n"); } else { ConPrint(L"Err saving to cfg\n"); } PrintUserCmdText(iClientID, L"OK"); return true; }
/** 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; }
/** 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; }
/** Move a character from a remote account into this one. */ bool Rename::UserCmd_MoveChar(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) { HK_ERROR err; // Don't indicate an error if moving is disabled. if (!set_bEnableMoveChar) return false; // Indicate an error if the command does not appear to be formatted correctly // and stop processing but tell FLHook that we processed the command. if (wscParam.size()==0) { PrintUserCmdText(iClientID, L"ERR Invalid parameters"); PrintUserCmdText(iClientID, usage); return true; } uint iBaseID; pub::Player::GetBase(iClientID, iBaseID); if (!iBaseID) { PrintUserCmdText(iClientID, L"ERR Not in base"); return true; } // Get the target account directory. string scFile; wstring wscMovingCharname = Trim(GetParam(wscParam, L' ', 0)); if (!GetUserFilePath(scFile, wscMovingCharname, "-movechar.ini")) { PrintUserCmdText(iClientID, L"ERR Character does not exist"); return true; } // Check the move char code. wstring wscCode = Trim(GetParam(wscParam, L' ', 1)); wstring wscTargetCode = IniGetWS(scFile, "Settings", "Code", L""); if (!wscTargetCode.length() || wscTargetCode!=wscCode) { PrintUserCmdText(iClientID, L"ERR Move character access denied"); return true; } // Get the character name for this connection. wstring wscCharname = (const wchar_t*)Players.GetActiveCharacterName(iClientID); for (map<wstring, LockedShipsStruct>::iterator i = MapLockedShips.begin(); i != MapLockedShips.end(); ++i) { if ((i->first == wscMovingCharname) && (i->second.LockLevel > 0)) { PrintUserCmdText(iClientID, L"ERR This ship is locked. The FBI has been notified."); wstring spurdoip; HkGetPlayerIP(iClientID, spurdoip); AddLog("SHIPLOCK: Attempt to movechar locked ship %s from IP %s", wstos(wscMovingCharname).c_str(), wstos(spurdoip).c_str()); ConPrint(L"SHIPLOCK: Attempt to movechar locked ship %s from IP %s\n", wscMovingCharname.c_str(), spurdoip.c_str()); return true; } } // Prevent ships from banned accounts from being moved. if (IsBanned(wscMovingCharname)) { PrintUserCmdText(iClientID, L"ERR not permitted"); return true; } // Saving the characters forces an anti-cheat checks and fixes // up a multitude of other problems. HkSaveChar(wscCharname); HkSaveChar(wscMovingCharname); // 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 (set_iMoveCost>0 && iCash<set_iMoveCost) { PrintUserCmdText(iClientID, L"ERR Insufficient credits"); return true; } // Check there is room in this account. CAccount *acc=Players.FindAccountFromClientID(iClientID); if (acc->iNumberOfCharacters >= 7) { PrintUserCmdText(iClientID, L"ERR Too many characters in account"); return true; } // Copy character file into this account with a temp name. char szDataPath[MAX_PATH]; GetUserDataPath(szDataPath); string scAcctPath = string(szDataPath) + "\\Accts\\MultiPlayer\\"; wstring wscDir; wstring wscSourceDir; wstring wscSourceFile; if ((err = HkGetAccountDirName(wscCharname, wscDir))!=HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } if ((err = HkGetAccountDirName(wscMovingCharname, wscSourceDir))!=HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } if ((err = HkGetCharFileName(wscMovingCharname, wscSourceFile))!=HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } // Remove cash if we're charging for it. if (set_iMoveCost>0) HkAddCash(wscCharname, 0-set_iMoveCost); HkSaveChar(wscCharname); // Schedule the move MOVE o; o.wscDestinationCharname = wscCharname; o.wscMovingCharname = wscMovingCharname; o.scSourceFile = scAcctPath + wstos(wscSourceDir) + "\\" + wstos(wscSourceFile) + ".fl"; o.scDestFile = scAcctPath + wstos(wscDir) + "\\" + wstos(wscSourceFile) + ".fl"; o.scDestFileTemp = scAcctPath + wstos(wscDir) + "\\" + wstos(wscSourceFile) + ".fl.moving"; pendingMoves.push_back(o); // Delete the move code ::DeleteFileA(scFile.c_str()); // Kick HkKickReason(o.wscDestinationCharname, L"Moving character, please wait 10 seconds before reconnecting"); HkKickReason(o.wscMovingCharname, L"Moving character, please wait 10 seconds before reconnecting"); return true; }
bool UserCmd_RenameMe(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) { HK_ERROR err; // Don't indicate an error if moving is disabled. if (!set_bEnableRenameMe) return false; // Indicate an error if the command does not appear to be formatted correctly // and stop processing but tell FLHook that we processed the command. if (wscParam.size()==0) { PrintUserCmdText(iClientID, L"ERR Invalid parameters"); PrintUserCmdText(iClientID, usage); return true; } uint iBaseID; pub::Player::GetBase(iClientID, iBaseID); if (!iBaseID) { PrintUserCmdText(iClientID, L"ERR Not in base"); return true; } // If the new name contains spaces then flag this as an // error. wstring wscNewCharname = Trim(GetParam(wscParam, L' ', 0)); // Get the character name for this connection. wstring wscCharname = (const wchar_t*)Players.GetActiveCharacterName(iClientID); for (map<wstring, LockedShipsStruct>::iterator i = MapLockedShips.begin(); i != MapLockedShips.end(); ++i) { if ((i->first == wscCharname) && (i->second.LockLevel > 0)) { PrintUserCmdText(iClientID, L"ERR This ship is locked. The FBI has been notified."); wstring spurdoip; HkGetPlayerIP(iClientID, spurdoip); AddLog("SHIPLOCK: Attempt to rename locked ship %s from IP %s", wstos(wscCharname).c_str(), wstos(spurdoip).c_str()); ConPrint(L"SHIPLOCK: Attempt to rename locked ship %s from IP %s\n", wscCharname.c_str(), spurdoip.c_str()); return true; } } if (wscNewCharname.find(L" ")!=-1) { PrintUserCmdText(iClientID, L"ERR Space characters not allowed in name"); return true; } if (HkGetAccountByCharname(wscNewCharname)) { PrintUserCmdText(iClientID, L"ERR Name already exists"); return true; } if (wscNewCharname.length() > 23) { PrintUserCmdText(iClientID, L"ERR Name to long"); return true; } if (wscNewCharname.length() < MIN_CHAR_TAG_LEN) { PrintUserCmdText(iClientID, L"ERR Name to short"); return true; } if (set_bCharnameTags) { wstring wscPassword = Trim(GetParam(wscParam, L' ', 1)); for (std::map<wstring, TAG_DATA>::iterator i = mapTagToPassword.begin(); i != mapTagToPassword.end(); ++i) { if (wscNewCharname.find(i->first)==0 && i->second.rename_password.size() != 0) { if (!wscPassword.length()) { PrintUserCmdText(iClientID, L"ERR Name starts with an owned tag. Password is required."); return true; } else if (wscPassword != i->second.master_password && wscPassword != i->second.rename_password) { PrintUserCmdText(iClientID, L"ERR Name starts with an owned tag. Password is wrong."); return true; } // Password is valid for owned tag. break; } } } // Saving the characters forces an anti-cheat checks and fixes // up a multitude of other problems. HkSaveChar(wscCharname); if (!HkIsValidClientID(iClientID)) 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 (set_iRenameCost>0 && iCash<set_iRenameCost) { PrintUserCmdText(iClientID, L"ERR Insufficient credits"); return true; } // Read the last time a rename was done on this character wstring wscDir; if ((err = HkGetAccountDirName(wscCharname, wscDir))!=HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } string scRenameFile = scAcctPath + wstos(wscDir) + "\\" + "rename.ini"; int lastRenameTime = IniGetI(scRenameFile, "General", wstos(wscCharname), 0); // If a rename was done recently by this player then reject the request. // I know that time() returns time_t...shouldn't matter for a few years // yet. if ((lastRenameTime + 300) < (int)time(0)) { if ((lastRenameTime + set_iRenameTimeLimit) > (int)time(0)) { PrintUserCmdText(iClientID, L"ERR Rename time limit"); return true; } } char szDataPath[MAX_PATH]; GetUserDataPath(szDataPath); string scAcctPath = string(szDataPath) + "\\Accts\\MultiPlayer\\"; wstring wscSourceFile; if ((err = HkGetCharFileName(wscCharname, wscSourceFile))!=HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } wstring wscDestFile; if ((err = HkGetCharFileName(wscNewCharname, wscDestFile))!=HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } // Remove cash if we're charging for it. if (set_iRenameCost>0) HkAddCash(wscCharname, 0-set_iRenameCost); RENAME o; o.wscCharname = wscCharname; o.wscNewCharname = wscNewCharname; o.scSourceFile = scAcctPath + wstos(wscDir) + "\\" + wstos(wscSourceFile) + ".fl"; o.scDestFile = scAcctPath + wstos(wscDir) + "\\" + wstos(wscDestFile) + ".fl"; o.scDestFileTemp = scAcctPath + wstos(wscDir) + "\\" + wstos(wscSourceFile) + ".fl.renaming"; pendingRenames.push_back(o); HkKickReason(o.wscCharname, L"Updating character, please wait 10 seconds before reconnecting"); IniWrite(scRenameFile, "General", wstos(o.wscNewCharname), itos((int)time(0))); return true; }
bool UserCmd_MakeTag(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) { if (set_bCharnameTags) { // Indicate an error if the command does not appear to be formatted correctly // and stop processing but tell FLHook that we processed the command. if (wscParam.size()==0) { PrintUserCmdText(iClientID, L"ERR Invalid parameters"); PrintUserCmdText(iClientID, usage); return true; } uint iBaseID; pub::Player::GetBase(iClientID, iBaseID); if (!iBaseID) { PrintUserCmdText(iClientID, L"ERR Not in base"); return true; } wstring tag = GetParam(wscParam, ' ', 0); wstring pass = GetParam(wscParam, ' ', 1); wstring description = GetParamToEnd(wscParam, ' ', 2); if (tag.size() < MIN_CHAR_TAG_LEN) { PrintUserCmdText(iClientID, L"ERR Tag too short"); PrintUserCmdText(iClientID, usage); return true; } if (!pass.size()) { PrintUserCmdText(iClientID, L"ERR Password not set"); PrintUserCmdText(iClientID, usage); return true; } if (!description.size()) { PrintUserCmdText(iClientID, L"ERR Description not set"); PrintUserCmdText(iClientID, usage); return true; } // If this tag is in use then reject the request. for (std::map<wstring, TAG_DATA>::iterator i = mapTagToPassword.begin(); i != mapTagToPassword.end(); ++i) { if (tag.find(i->second.tag)==0 || i->second.tag.find(tag)==0) { PrintUserCmdText(iClientID, L"ERR Tag already exists or conflicts with existing tag"); return true; } } // Save character and exit if kicked on save. wstring wscCharname = (const wchar_t*)Players.GetActiveCharacterName(iClientID); HkSaveChar(wscCharname); if (HkGetClientIdFromCharname(wscCharname)==-1) return false; int iCash; HK_ERROR err; if ((err = HkGetCash(wscCharname, iCash)) != HKE_OK) { PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err)); return true; } if (set_iMakeTagCost>0 && iCash<set_iMakeTagCost) { PrintUserCmdText(iClientID, L"ERR Insufficient credits"); return true; } HkAddCash(wscCharname, 0-set_iMakeTagCost); // TODO: Try to check if any player is using this tag mapTagToPassword[tag].tag = tag; mapTagToPassword[tag].master_password = pass; mapTagToPassword[tag].rename_password = L""; mapTagToPassword[tag].last_access = (uint)time(0); mapTagToPassword[tag].description = description; PrintUserCmdText(iClientID, L"Created faction tag %s with master password %s", tag.c_str(), pass.c_str()); AddLog("NOTICE: Tag %s created by %s (%s)", wstos(tag).c_str(), wstos(wscCharname).c_str(), wstos(HkGetAccountIDByClientID(iClientID)).c_str()); SaveSettings(); return true; } return false; }