/** Return return if this char is in the blocked system */ static bool InBlockedSystem(const wstring &wscCharname) { // An optimisation if we have no blocked systems. if (set_iBlockedSystem==0) return false; // If the char is logged in we can check in memory. uint iClientID=HkGetClientIdFromCharname(wscCharname); if (iClientID!=-1) { uint iSystem = 0; pub::Player::GetSystem(iClientID, iSystem); if (iSystem==set_iBlockedSystem) return true; return false; } // Have to check the charfile. wstring wscSystemNick; if (HkFLIniGet(wscCharname, L"system", wscSystemNick)!=HKE_OK) return false; uint iSystem = 0; pub::GetSystemID(iSystem, wstos(wscSystemNick).c_str()); if (iSystem==set_iBlockedSystem) return true; return false; }
bool HkAddCheaterLog(const wstring &wscCharname, const wstring &wscReason) { FILE *f = fopen(("./flhook_logs/flhook_cheaters.log"), "at"); if(!f) return false; CAccount *acc = HkGetAccountByCharname(wscCharname); wstring wscAccountDir = L"???"; wstring wscAccountID = L"???"; if(acc) { HkGetAccountDirName(acc, wscAccountDir); wscAccountID = HkGetAccountID(acc); } uint iClientID = HkGetClientIdFromCharname(wscCharname); wstring wscHostName = L"???"; wstring wscIp = L"???"; if(iClientID != -1) { wscHostName = ClientInfo[iClientID].wscHostname; HkGetPlayerIP(iClientID,wscIp); } time_t tNow = time(0); struct tm *stNow = localtime(&tNow); fprintf(f, "%.2d/%.2d/%.4d %.2d:%.2d:%.2d Possible cheating detected (%s) by %s(%s)(%s) [%s %s]\n", stNow->tm_mon + 1, stNow->tm_mday, stNow->tm_year + 1900, stNow->tm_hour, stNow->tm_min, stNow->tm_sec, wstos(wscReason).c_str(), wstos(wscCharname).c_str(), wstos(wscAccountDir).c_str(), wstos(wscAccountID).c_str(), wstos(wscHostName).c_str(), wstos(wscIp).c_str()); fclose(f); return true; }
uint HkGetClientIDFromArg(const wstring &wscArg) { uint client; if (HkResolveId(wscArg, client) == HKE_OK) return client; if (HkResolveShortCut(wscArg, client) == HKE_OK) return client; return HkGetClientIdFromCharname(wscArg); }
void CCmds::CmdGetClientId(const wstring &wscCharname) { RIGHT_CHECK(RIGHT_OTHER); uint iClientID = HkGetClientIdFromCharname(wscCharname); if(iClientID == -1) { hkLastErr = HKE_PLAYER_NOT_LOGGED_IN; PrintError(); return; } Print(L"clientid=%u\nOK\n", iClientID); }
/** Check for new or unread messages. */ void MailCheckLog(const wstring &wscCharname, const string &scExtension) { // Make sure the character is logged in. uint iClientID = HkGetClientIdFromCharname(wscCharname); if (iClientID==-1) return; // Get the target player's message file. string scFilePath = GetUserFilePath(wscCharname, scExtension); if (scFilePath.length()==0) return; // If there are unread messaging then inform the player int iUnreadMsgs = MailCountUnread(wscCharname, scExtension); if (iUnreadMsgs>0) { PrintUserCmdText(iClientID, L"You have %d unread messages. Type /mail to see your messages", iUnreadMsgs); } }
/** Show five messages from the specified starting position. */ void MailShow(const wstring &wscCharname, const string &scExtension, int iFirstMsg) { // Make sure the character is logged in. uint iClientID = HkGetClientIdFromCharname(wscCharname); if (iClientID==-1) return; // Get the target player's message file. string scFilePath = GetUserFilePath(wscCharname, scExtension); if (scFilePath.length()==0) return; int iLastMsg = iFirstMsg; for (int iMsgSlot = iFirstMsg, iMsgCount = 0; iMsgSlot<MAX_MAIL_MSGS && iMsgCount<5; iMsgSlot++, iMsgCount++) { wstring wscTmpMsg = IniGetWS(scFilePath, "Msgs", itos(iMsgSlot), L""); if (wscTmpMsg.length()==0) break; PrintUserCmdText(iClientID, L"#%02d %s", iMsgSlot, wscTmpMsg.c_str()); IniWrite(scFilePath, "MsgsRead", itos(iMsgSlot), "yes"); iLastMsg = iMsgSlot; } PrintUserCmdText(iClientID, L"Viewing #%02d-#%02d of %02d messages", iFirstMsg, iLastMsg, MailCount(wscCharname, scExtension)); }
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; }
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()); } } }
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; }