Advertisement
Kaiquegabriel

Untitled

Jul 18th, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.92 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17. #include "otpch.h"
  18. #include "talkaction.h"
  19.  
  20. #include "iologindata.h"
  21. #include "ioban.h"
  22.  
  23. #include "player.h"
  24. #include "npc.h"
  25.  
  26. #include "house.h"
  27. #include "town.h"
  28.  
  29. #include "teleport.h"
  30. #include "status.h"
  31. #include "textlogger.h"
  32.  
  33. #include <boost/version.hpp>
  34. #ifdef __ENABLE_SERVER_DIAGNOSTIC__
  35. #include "outputmessage.h"
  36. #include "connection.h"
  37. #include "admin.h"
  38. #include "manager.h"
  39. #include "protocollogin.h"
  40. #include "protocolold.h"
  41. #endif
  42.  
  43. #include "configmanager.h"
  44. #include "game.h"
  45. #include "chat.h"
  46. #include "tools.h"
  47. #include "resources.h"
  48.  
  49. extern ConfigManager g_config;
  50. extern Game g_game;
  51. extern Chat g_chat;
  52. extern TalkActions* g_talkActions;
  53.  
  54. TalkActions::TalkActions():
  55. m_interface("TalkAction Interface")
  56. {
  57. m_interface.initState();
  58. defaultTalkAction = NULL;
  59. }
  60.  
  61. TalkActions::~TalkActions()
  62. {
  63. clear();
  64. }
  65.  
  66. void TalkActions::clear()
  67. {
  68. for(TalkActionsMap::iterator it = talksMap.begin(); it != talksMap.end(); ++it)
  69. delete it->second;
  70.  
  71. talksMap.clear();
  72. m_interface.reInitState();
  73.  
  74. delete defaultTalkAction;
  75. defaultTalkAction = NULL;
  76. }
  77.  
  78. Event* TalkActions::getEvent(const std::string& nodeName)
  79. {
  80. if(asLowerCaseString(nodeName) == "talkaction")
  81. return new TalkAction(&m_interface);
  82.  
  83. return NULL;
  84. }
  85.  
  86. bool TalkActions::registerEvent(Event* event, xmlNodePtr p, bool override)
  87. {
  88. TalkAction* talkAction = dynamic_cast<TalkAction*>(event);
  89. if(!talkAction)
  90. return false;
  91.  
  92. std::string strValue;
  93. if(readXMLString(p, "default", strValue) && booleanString(strValue))
  94. {
  95. if(!defaultTalkAction)
  96. defaultTalkAction = talkAction;
  97. else if(override)
  98. {
  99. delete defaultTalkAction;
  100. defaultTalkAction = talkAction;
  101. }
  102. else
  103. std::clog << "[Warning - TalkAction::registerEvent] You cannot define more than one default talkAction." << std::endl;
  104.  
  105. return true;
  106. }
  107.  
  108. if(!readXMLString(p, "separator", strValue) || strValue.empty())
  109. strValue = ";";
  110.  
  111. StringVec strVector = explodeString(talkAction->getWords(), strValue);
  112. for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it)
  113. {
  114. trimString(*it);
  115. talkAction->setWords(*it);
  116. if(talksMap.find(*it) != talksMap.end())
  117. {
  118. if(!override)
  119. {
  120. std::clog << "[Warning - TalkAction::registerEvent] Duplicate registered talkaction with words: " << (*it) << std::endl;
  121. continue;
  122. }
  123.  
  124. delete talksMap[(*it)];
  125. }
  126.  
  127. talksMap[(*it)] = new TalkAction(talkAction);
  128. }
  129.  
  130. delete talkAction;
  131. return true;
  132. }
  133.  
  134. bool TalkActions::onPlayerSay(Creature* creature, uint16_t channelId, const std::string& words, bool ignoreAccess)
  135. {
  136. std::string cmd[TALKFILTER_LAST], param[TALKFILTER_LAST];
  137. for(int32_t i = 0; i < TALKFILTER_LAST; ++i)
  138. cmd[i] = words;
  139.  
  140. std::string::size_type loc = words.find('"', 0);
  141. if(loc != std::string::npos)
  142. {
  143. cmd[TALKFILTER_QUOTATION] = std::string(words, 0, loc);
  144. param[TALKFILTER_QUOTATION] = std::string(words, (loc + 1), (words.size() - (loc - 1)));
  145. trimString(cmd[TALKFILTER_QUOTATION]);
  146. }
  147.  
  148. loc = words.find(" ", 0);
  149. if(loc != std::string::npos)
  150. {
  151. cmd[TALKFILTER_WORD] = std::string(words, 0, loc);
  152. param[TALKFILTER_WORD] = std::string(words, (loc + 1), (words.size() - (loc - 1)));
  153.  
  154. std::string::size_type spaceLoc = words.find(" ", ++loc);
  155. if(spaceLoc != std::string::npos)
  156. {
  157. cmd[TALKFILTER_WORD_SPACED] = std::string(words, 0, spaceLoc);
  158. param[TALKFILTER_WORD_SPACED] = std::string(words, (spaceLoc + 1), (words.size() - (spaceLoc - 1)));
  159. }
  160. }
  161.  
  162. TalkAction* talkAction = NULL;
  163. for(TalkActionsMap::iterator it = talksMap.begin(); it != talksMap.end(); ++it)
  164. {
  165. if(it->first == cmd[it->second->getFilter()] || (!it->second->isSensitive()
  166. && boost::algorithm::iequals(it->first, cmd[it->second->getFilter()])))
  167. {
  168. talkAction = it->second;
  169. break;
  170. }
  171. }
  172.  
  173. if(!talkAction && defaultTalkAction)
  174. talkAction = defaultTalkAction;
  175.  
  176. if(!talkAction || (talkAction->getChannel() != -1 && talkAction->getChannel() != channelId))
  177. return false;
  178.  
  179. Player* player = creature->getPlayer();
  180. if(player)
  181. {
  182. if(!player->canDoExAction())
  183. return false;
  184.  
  185. StringVec exceptions = talkAction->getExceptions();
  186. if((!ignoreAccess && std::find(exceptions.begin(), exceptions.end(), asLowerCaseString(
  187. player->getName())) == exceptions.end() && (talkAction->getAccess() > player->getAccess()
  188. || (talkAction->hasGroups() && !talkAction->hasGroup(player->getGroupId()))))
  189. || player->isAccountManager())
  190. {
  191. if(player->hasCustomFlag(PlayerCustomFlag_GamemasterPrivileges))
  192. {
  193. player->sendTextMessage(MSG_STATUS_SMALL, "You cannot execute this talkaction.");
  194. return true;
  195. }
  196.  
  197. return false;
  198. }
  199.  
  200. if(!player->hasCustomFlag(PlayerCustomFlag_GamemasterPrivileges))
  201. player->setNextExAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::CUSTOM_ACTIONS_DELAY_INTERVAL) - 10);
  202. }
  203.  
  204. if(talkAction->isLogged())
  205. {
  206. if(player)
  207. player->sendTextMessage(MSG_EVENT_ORANGE, words.c_str());
  208.  
  209. Logger::getInstance()->eFile("talkactions/" + creature->getName() + ".log", words, true);
  210. }
  211.  
  212. if(talkAction->isScripted())
  213. return (talkAction->executeSay(creature, cmd[talkAction->getFilter()], param[talkAction->getFilter()], channelId) != 0);
  214.  
  215. if(TalkFunction* function = talkAction->getFunction())
  216. return function(creature, cmd[talkAction->getFilter()], param[talkAction->getFilter()]);
  217.  
  218. return false;
  219. }
  220.  
  221. TalkAction::TalkAction(LuaInterface* _interface):
  222. Event(_interface)
  223. {
  224. m_function = NULL;
  225. m_filter = TALKFILTER_WORD;
  226. m_access = 0;
  227. m_channel = -1;
  228. m_logged = m_hidden = false;
  229. m_sensitive = true;
  230. }
  231.  
  232. TalkAction::TalkAction(const TalkAction* copy):
  233. Event(copy)
  234. {
  235. m_words = copy->m_words;
  236. m_function = copy->m_function;
  237. m_filter = copy->m_filter;
  238. m_access = copy->m_access;
  239. m_channel = copy->m_channel;
  240. m_logged = copy->m_logged;
  241. m_hidden = copy->m_hidden;
  242. m_sensitive = copy->m_sensitive;
  243. m_exceptions = copy->m_exceptions;
  244. m_groups = copy->m_groups;
  245. }
  246.  
  247. bool TalkAction::configureEvent(xmlNodePtr p)
  248. {
  249. std::string strValue;
  250. if(readXMLString(p, "words", strValue))
  251. m_words = strValue;
  252. else if(!readXMLString(p, "default", strValue) || !booleanString(strValue))
  253. {
  254. std::clog << "[Error - TalkAction::configureEvent] No words for TalkAction." << std::endl;
  255. return false;
  256. }
  257.  
  258. if(readXMLString(p, "filter", strValue))
  259. {
  260. std::string tmpStrValue = asLowerCaseString(strValue);
  261. if(tmpStrValue == "quotation")
  262. m_filter = TALKFILTER_QUOTATION;
  263. else if(tmpStrValue == "word")
  264. m_filter = TALKFILTER_WORD;
  265. else if(tmpStrValue == "word-spaced")
  266. m_filter = TALKFILTER_WORD_SPACED;
  267. else
  268. std::clog << "[Warning - TalkAction::configureEvent] Unknown filter for TalkAction: " << strValue << ", using default." << std::endl;
  269. }
  270.  
  271. int32_t intValue;
  272. if(readXMLInteger(p, "access", intValue))
  273. m_access = intValue;
  274.  
  275. if(readXMLString(p, "group", strValue) || readXMLString(p, "groups", strValue))
  276. {
  277. m_groups.clear();
  278. if(!parseIntegerVec(strValue, m_groups))
  279. std::clog << "[Warning - TalkAction::configureEvent] Invalid group(s) for TalkAction: " << strValue << std::endl;
  280. }
  281.  
  282. if(readXMLInteger(p, "channel", intValue))
  283. m_channel = intValue;
  284.  
  285. if(readXMLString(p, "logged", strValue) || readXMLString(p, "log", strValue))
  286. m_logged = booleanString(strValue);
  287.  
  288. if(readXMLString(p, "hidden", strValue) || readXMLString(p, "hide", strValue))
  289. m_hidden = booleanString(strValue);
  290.  
  291. if(readXMLString(p, "case-sensitive", strValue) || readXMLString(p, "casesensitive", strValue) || readXMLString(p, "sensitive", strValue))
  292. m_sensitive = booleanString(strValue);
  293.  
  294. if(readXMLString(p, "exception", strValue))
  295. m_exceptions = explodeString(asLowerCaseString(strValue), ";");
  296.  
  297. return true;
  298. }
  299.  
  300. bool TalkAction::loadFunction(const std::string& functionName)
  301. {
  302. m_functionName = asLowerCaseString(functionName);
  303. if(m_functionName == "housebuy")
  304. m_function = houseBuy;
  305. else if(m_functionName == "housesell")
  306. m_function = houseSell;
  307. else if(m_functionName == "housekick")
  308. m_function = houseKick;
  309. else if(m_functionName == "housedoorlist")
  310. m_function = houseDoorList;
  311. else if(m_functionName == "houseguestlist")
  312. m_function = houseGuestList;
  313. else if(m_functionName == "housesubownerlist")
  314. m_function = houseSubOwnerList;
  315. else if(m_functionName == "guildjoin")
  316. m_function = guildJoin;
  317. else if(m_functionName == "guildcreate")
  318. m_function = guildCreate;
  319. else if(m_functionName == "thingproporties")
  320. m_function = thingProporties;
  321. else if(m_functionName == "banishmentinfo")
  322. m_function = banishmentInfo;
  323. else if(m_functionName == "diagnostics")
  324. m_function = diagnostics;
  325. else if(m_functionName == "ghost")
  326. m_function = ghost;
  327. else if(m_functionName == "software")
  328. m_function = software;
  329. else
  330. {
  331. std::clog << "[Warning - TalkAction::loadFunction] Function \"" << m_functionName << "\" does not exist." << std::endl;
  332. return false;
  333. }
  334.  
  335. m_scripted = EVENT_SCRIPT_FALSE;
  336. return true;
  337. }
  338.  
  339. int32_t TalkAction::executeSay(Creature* creature, const std::string& words, std::string param, uint16_t channel)
  340. {
  341. //onSay(cid, words, param, channel)
  342. if(m_interface->reserveEnv())
  343. {
  344. trimString(param);
  345. ScriptEnviroment* env = m_interface->getEnv();
  346. if(m_scripted == EVENT_SCRIPT_BUFFER)
  347. {
  348. env->setRealPos(creature->getPosition());
  349. std::stringstream scriptstream;
  350. scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  351.  
  352. scriptstream << "local words = \"" << words << "\"" << std::endl;
  353. scriptstream << "local param = \"" << param << "\"" << std::endl;
  354. scriptstream << "local channel = " << channel << std::endl;
  355.  
  356. if(m_scriptData)
  357. scriptstream << *m_scriptData;
  358.  
  359. bool result = true;
  360. if(m_interface->loadBuffer(scriptstream.str()))
  361. {
  362. lua_State* L = m_interface->getState();
  363. result = m_interface->getGlobalBool(L, "_result", true);
  364. }
  365.  
  366. m_interface->releaseEnv();
  367. return result;
  368. }
  369. else
  370. {
  371. #ifdef __DEBUG_LUASCRIPTS__
  372. char desc[125];
  373. sprintf(desc, "%s - %s- %s", creature->getName().c_str(), words.c_str(), param.c_str());
  374. env->setEvent(desc);
  375. #endif
  376.  
  377. env->setScriptId(m_scriptId, m_interface);
  378. env->setRealPos(creature->getPosition());
  379.  
  380. lua_State* L = m_interface->getState();
  381. m_interface->pushFunction(m_scriptId);
  382. lua_pushnumber(L, env->addThing(creature));
  383.  
  384. lua_pushstring(L, words.c_str());
  385. lua_pushstring(L, param.c_str());
  386. lua_pushnumber(L, channel);
  387.  
  388. bool result = m_interface->callFunction(4);
  389. m_interface->releaseEnv();
  390. return result;
  391. }
  392. }
  393. else
  394. {
  395. std::clog << "[Error - TalkAction::executeSay] Call stack overflow." << std::endl;
  396. return 0;
  397. }
  398. }
  399.  
  400. bool TalkAction::houseBuy(Creature* creature, const std::string&, const std::string&)
  401. {
  402. Player* player = creature->getPlayer();
  403. if(!player || !g_config.getBool(ConfigManager::HOUSE_BUY_AND_SELL))
  404. return false;
  405.  
  406. const Position& pos = getNextPosition(player->getDirection(), player->getPosition());
  407. Tile* tile = g_game.getTile(pos);
  408. if(!tile)
  409. {
  410. player->sendCancel("You have to be looking at door of flat you would like to purchase.");
  411. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  412. return false;
  413. }
  414.  
  415. House* house = tile->getHouse();
  416. if(!house)
  417. {
  418. player->sendCancel("You have to be looking at door of flat you would like to purchase.");
  419. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  420. return false;
  421. }
  422.  
  423. if(!house->getDoorByPosition(pos))
  424. {
  425. player->sendCancel("You have to be looking at door of flat you would like to purchase.");
  426. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  427. return false;
  428. }
  429.  
  430. if(house->isBidded())
  431. {
  432. player->sendCancel("You cannot buy house which is currently bidded on an auction.");
  433. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  434. return false;
  435. }
  436.  
  437. if(!house->isGuild())
  438. {
  439. if(Houses::getInstance()->getHouseByPlayerId(player->getGUID()))
  440. {
  441. player->sendCancel("You already rent another house.");
  442. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  443. return false;
  444. }
  445.  
  446. uint16_t accountHouses = g_config.getNumber(ConfigManager::HOUSES_PER_ACCOUNT);
  447. if(accountHouses > 0 && Houses::getInstance()->getHousesCount(player->getAccount()) >= accountHouses)
  448. {
  449. char buffer[80];
  450. sprintf(buffer, "You may own only %d house%s per account.", accountHouses, (accountHouses != 1 ? "s" : ""));
  451.  
  452. player->sendCancel(buffer);
  453. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  454. return false;
  455. }
  456.  
  457. if(g_config.getBool(ConfigManager::HOUSE_NEED_PREMIUM) && !player->isPremium())
  458. {
  459. player->sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT);
  460. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  461. return false;
  462. }
  463.  
  464. uint32_t levelToBuyHouse = g_config.getNumber(ConfigManager::LEVEL_TO_BUY_HOUSE);
  465. if(player->getLevel() < levelToBuyHouse)
  466. {
  467. char buffer[90];
  468. sprintf(buffer, "You have to be at least Level %d to purchase a house.", levelToBuyHouse);
  469. player->sendCancel(buffer);
  470. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  471. return false;
  472. }
  473. }
  474. else
  475. {
  476. if(!player->getGuildId() || player->getGuildLevel() != GUILDLEVEL_LEADER)
  477. {
  478. player->sendCancel("You have to be at least a guild leader to purchase a hall.");
  479. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  480. return false;
  481. }
  482.  
  483. if(Houses::getInstance()->getHouseByGuildId(player->getGuildId()))
  484. {
  485. player->sendCancel("Your guild rents already another hall.");
  486. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  487. return false;
  488. }
  489. }
  490.  
  491. if(house->getOwner())
  492. {
  493. player->sendCancel("This flat is already owned by someone else.");
  494. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  495. return false;
  496. }
  497.  
  498. if((uint32_t)g_game.getMoney(player) < house->getPrice() || !g_game.removeMoney(player, house->getPrice()))
  499. {
  500. player->sendCancel("You do not have enough money.");
  501. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  502. return false;
  503. }
  504.  
  505. house->setOwnerEx(player->getGUID(), true);
  506. if(g_config.getBool(ConfigManager::HOUSE_SKIP_INIT_RENT))
  507. {
  508. uint32_t paidUntil = time(NULL);
  509. switch(Houses::getInstance()->getRentPeriod())
  510. {
  511. case RENTPERIOD_DAILY:
  512. paidUntil += 86400;
  513. break;
  514. case RENTPERIOD_WEEKLY:
  515. paidUntil += 7 * 86400;
  516. break;
  517. case RENTPERIOD_MONTHLY:
  518. paidUntil += 30 * 86400;
  519. break;
  520. case RENTPERIOD_YEARLY:
  521. paidUntil += 365 * 86400;
  522. break;
  523. default:
  524. break;
  525. }
  526.  
  527. house->setPaidUntil(paidUntil);
  528. house->setLastWarning(0);
  529. }
  530.  
  531. std::string ret = "You have successfully bought this ";
  532. if(house->isGuild())
  533. ret += "hall";
  534. else
  535. ret += "house";
  536.  
  537. ret += ", remember to leave money at ";
  538. if(house->isGuild())
  539. ret += "guild owner ";
  540.  
  541. if(g_config.getBool(ConfigManager::BANK_SYSTEM))
  542. ret += "bank or ";
  543.  
  544. ret += "depot of this town for rent.";
  545. player->sendTextMessage(MSG_INFO_DESCR, ret.c_str());
  546.  
  547. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  548. return false;
  549. }
  550.  
  551. bool TalkAction::houseSell(Creature* creature, const std::string&, const std::string& param)
  552. {
  553. Player* player = creature->getPlayer();
  554. if(!player || !g_config.getBool(ConfigManager::HOUSE_BUY_AND_SELL))
  555. return false;
  556.  
  557. House* house = Houses::getInstance()->getHouseByPlayerId(player->getGUID());
  558. if(!house && (!player->getGuildId() || !(house = Houses::getInstance()->getHouseByGuildId(player->getGuildId()))))
  559. {
  560. player->sendCancel("You do not rent any flat.");
  561. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  562. return false;
  563. }
  564.  
  565. if(house->isGuild() && player->getGuildLevel() != GUILDLEVEL_LEADER)
  566. {
  567. player->sendCancel("You have to be at least a guild leader to sell this hall.");
  568. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  569. return false;
  570. }
  571.  
  572. Tile* tile = g_game.getTile(player->getPosition());
  573. if(!tile || !tile->getHouseTile() || tile->getHouseTile()->getHouse() != house)
  574. {
  575. player->sendCancel("You have to be inside a house that you would like to sell.");
  576. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  577. return false;
  578. }
  579.  
  580. Player* tradePartner = NULL;
  581. ReturnValue ret = g_game.getPlayerByNameWildcard(param, tradePartner);
  582. if(ret != RET_NOERROR)
  583. {
  584. player->sendCancelMessage(ret);
  585. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  586. return false;
  587. }
  588.  
  589. if(tradePartner == player)
  590. {
  591. player->sendCancel("You cannot trade with yourself.");
  592. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  593. return false;
  594. }
  595.  
  596. if(!house->isGuild())
  597. {
  598. if(Houses::getInstance()->getHouseByPlayerId(tradePartner->getGUID()))
  599. {
  600. player->sendCancel("Trade player already rents another house.");
  601. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  602. return false;
  603. }
  604.  
  605. uint16_t housesPerAccount = g_config.getNumber(ConfigManager::HOUSES_PER_ACCOUNT);
  606. if(housesPerAccount > 0 && Houses::getInstance()->getHousesCount(tradePartner->getAccount()) >= housesPerAccount)
  607. {
  608. char buffer[100];
  609. sprintf(buffer, "Trade player has reached limit of %d house%s per account.", housesPerAccount, (housesPerAccount != 1 ? "s" : ""));
  610.  
  611. player->sendCancel(buffer);
  612. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  613. return false;
  614. }
  615.  
  616. if(!tradePartner->isPremium() && !g_config.getBool(ConfigManager::HOUSE_NEED_PREMIUM))
  617. {
  618. player->sendCancel("Trade player does not have a premium account.");
  619. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  620. return false;
  621. }
  622.  
  623. uint32_t levelToBuyHouse = g_config.getNumber(ConfigManager::LEVEL_TO_BUY_HOUSE);
  624. if(tradePartner->getLevel() < levelToBuyHouse)
  625. {
  626. char buffer[100];
  627. sprintf(buffer, "Trade player has to be at least Level %d to buy house.", levelToBuyHouse);
  628.  
  629. player->sendCancel(buffer);
  630. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  631. return false;
  632. }
  633. }
  634. else
  635. {
  636. if(!tradePartner->getGuildId() || tradePartner->getGuildLevel() != GUILDLEVEL_LEADER)
  637. {
  638. player->sendCancel("Trade player has to be at least a guild leader to buy a hall.");
  639. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  640. return false;
  641. }
  642.  
  643. if(Houses::getInstance()->getHouseByGuildId(tradePartner->getGuildId()))
  644. {
  645. player->sendCancel("Trade player's guild already rents another hall.");
  646. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  647. return false;
  648. }
  649. }
  650.  
  651. if(!Position::areInRange<3,3,0>(tradePartner->getPosition(), player->getPosition()))
  652. {
  653. player->sendCancel("Trade player is too far away.");
  654. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  655. return false;
  656. }
  657.  
  658. if(!Houses::getInstance()->payRent(player, house, 0))
  659. {
  660. player->sendCancel("You have to pay a pre-rent first.");
  661. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  662. return false;
  663. }
  664.  
  665. Item* transferItem = TransferItem::createTransferItem(house);
  666. player->transferContainer.__addThing(NULL, transferItem);
  667.  
  668. player->transferContainer.setParent(player);
  669. if(!g_game.internalStartTrade(player, tradePartner, transferItem))
  670. transferItem->onTradeEvent(ON_TRADE_CANCEL, player, NULL);
  671.  
  672. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  673. return false;
  674. }
  675.  
  676. bool TalkAction::houseKick(Creature* creature, const std::string&, const std::string& param)
  677. {
  678. Player* player = creature->getPlayer();
  679. if(!player)
  680. return false;
  681.  
  682. Player* targetPlayer = NULL;
  683. if(g_game.getPlayerByNameWildcard(param, targetPlayer) != RET_NOERROR)
  684. targetPlayer = player;
  685.  
  686. House* house = Houses::getInstance()->getHouseByPlayer(targetPlayer);
  687. if(!house || !house->kickPlayer(player, targetPlayer))
  688. {
  689. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  690. player->sendCancelMessage(RET_NOTPOSSIBLE);
  691. }
  692. else
  693. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  694.  
  695. return false;
  696. }
  697.  
  698. bool TalkAction::houseDoorList(Creature* creature, const std::string&, const std::string&)
  699. {
  700. Player* player = creature->getPlayer();
  701. if(!player)
  702. return false;
  703.  
  704. House* house = Houses::getInstance()->getHouseByPlayer(player);
  705. if(!house)
  706. {
  707. player->sendCancelMessage(RET_NOTPOSSIBLE);
  708. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  709. return false;
  710. }
  711.  
  712. Door* door = house->getDoorByPosition(getNextPosition(player->getDirection(), player->getPosition()));
  713. if(door && house->canEditAccessList(door->getDoorId(), player))
  714. {
  715. player->setEditHouse(house, door->getDoorId());
  716. player->sendHouseWindow(house, door->getDoorId());
  717. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  718. }
  719. else
  720. {
  721. player->sendCancelMessage(RET_NOTPOSSIBLE);
  722. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  723. }
  724.  
  725. return false;
  726. }
  727.  
  728. bool TalkAction::houseGuestList(Creature* creature, const std::string&, const std::string&)
  729. {
  730. Player* player = creature->getPlayer();
  731. if(!player)
  732. return false;
  733.  
  734. House* house = Houses::getInstance()->getHouseByPlayer(player);
  735. if(house && house->canEditAccessList(GUEST_LIST, player))
  736. {
  737. player->setEditHouse(house, GUEST_LIST);
  738. player->sendHouseWindow(house, GUEST_LIST);
  739. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  740. }
  741. else
  742. {
  743. player->sendCancelMessage(RET_NOTPOSSIBLE);
  744. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  745. }
  746.  
  747. return false;
  748. }
  749.  
  750. bool TalkAction::houseSubOwnerList(Creature* creature, const std::string&, const std::string&)
  751. {
  752. Player* player = creature->getPlayer();
  753. if(!player)
  754. return false;
  755.  
  756. House* house = Houses::getInstance()->getHouseByPlayer(player);
  757. if(house && house->canEditAccessList(SUBOWNER_LIST, player))
  758. {
  759. player->setEditHouse(house, SUBOWNER_LIST);
  760. player->sendHouseWindow(house, SUBOWNER_LIST);
  761. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  762. }
  763. else
  764. {
  765. player->sendCancelMessage(RET_NOTPOSSIBLE);
  766. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  767. }
  768.  
  769. return false;
  770. }
  771.  
  772. bool TalkAction::guildJoin(Creature* creature, const std::string&, const std::string& param)
  773. {
  774. Player* player = creature->getPlayer();
  775. if(!player || !g_config.getBool(ConfigManager::INGAME_GUILD_MANAGEMENT))
  776. return false;
  777.  
  778. std::string param_ = param;
  779. trimString(param_);
  780. if(!player->getGuildId())
  781. {
  782. uint32_t guildId;
  783. if(IOGuild::getInstance()->getGuildId(guildId, param_))
  784. {
  785. if(player->isGuildInvited(guildId))
  786. {
  787. IOGuild::getInstance()->joinGuild(player, guildId);
  788. player->sendTextMessage(MSG_EVENT_GUILD, "You have joined the guild.");
  789.  
  790. char buffer[80];
  791. sprintf(buffer, "%s has joined the guild.", player->getName().c_str());
  792. if(ChatChannel* guildChannel = g_chat.getChannel(player, CHANNEL_GUILD))
  793. guildChannel->talk("", MSG_CHANNEL_HIGHLIGHT, buffer);
  794. }
  795. else
  796. player->sendCancel("You are not invited to that guild.");
  797. }
  798. else
  799. player->sendCancel("There's no guild with that name.");
  800. }
  801. else
  802. player->sendCancel("You are already in a guild.");
  803.  
  804. return true;
  805. }
  806.  
  807. bool TalkAction::guildCreate(Creature* creature, const std::string&, const std::string& param)
  808. {
  809. Player* player = creature->getPlayer();
  810. if(!player || !g_config.getBool(ConfigManager::INGAME_GUILD_MANAGEMENT))
  811. return false;
  812.  
  813. if(player->getGuildId())
  814. {
  815. player->sendCancel("You are already in a guild.");
  816. return true;
  817. }
  818.  
  819. std::string param_ = param;
  820. trimString(param_);
  821. if(!isValidName(param_))
  822. {
  823. player->sendCancel("That guild name contains illegal characters, please choose another name.");
  824. return true;
  825. }
  826.  
  827. uint32_t minLength = g_config.getNumber(ConfigManager::MIN_GUILDNAME),
  828. maxLength = g_config.getNumber(ConfigManager::MAX_GUILDNAME);
  829. if(param_.length() < minLength)
  830. {
  831. player->sendCancel("That guild name is too short, please select a longer name.");
  832. return true;
  833. }
  834.  
  835. if(param_.length() > maxLength)
  836. {
  837. player->sendCancel("That guild name is too long, please select a shorter name.");
  838. return true;
  839. }
  840.  
  841. uint32_t guildId;
  842. if(IOGuild::getInstance()->getGuildId(guildId, param_))
  843. {
  844. player->sendCancel("There is already a guild with that name.");
  845. return true;
  846. }
  847.  
  848. const uint32_t levelToFormGuild = g_config.getNumber(ConfigManager::LEVEL_TO_FORM_GUILD);
  849. if(player->getLevel() < levelToFormGuild)
  850. {
  851. std::stringstream stream;
  852. stream << "You have to be at least Level " << levelToFormGuild << " to form a guild.";
  853. player->sendCancel(stream.str().c_str());
  854. return true;
  855. }
  856.  
  857. const int32_t premiumDays = g_config.getNumber(ConfigManager::GUILD_PREMIUM_DAYS);
  858. if(player->getPremiumDays() < premiumDays && !g_config.getBool(ConfigManager::FREE_PREMIUM))
  859. {
  860. std::stringstream stream;
  861. stream << "You need to have at least " << premiumDays << " premium days to form a guild.";
  862. player->sendCancel(stream.str().c_str());
  863. return true;
  864. }
  865.  
  866. player->setGuildName(param_);
  867. IOGuild::getInstance()->createGuild(player);
  868.  
  869. std::stringstream stream;
  870. stream << "You have formed guild \"" << param.c_str() << "\"!";
  871. player->sendTextMessage(MSG_EVENT_GUILD, stream.str().c_str());
  872. return true;
  873. }
  874.  
  875. bool TalkAction::thingProporties(Creature* creature, const std::string&, const std::string& param)
  876. {
  877. Player* player = creature->getPlayer();
  878. if(!player)
  879. return false;
  880.  
  881. const Position& pos = getNextPosition(player->getDirection(), player->getPosition());
  882. Tile* tile = g_game.getTile(pos);
  883. if(!tile)
  884. {
  885. player->sendTextMessage(MSG_STATUS_SMALL, "No tile found.");
  886. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  887. return true;
  888. }
  889.  
  890. Thing* thing = tile->getTopVisibleThing(creature);
  891. if(!thing)
  892. {
  893. player->sendTextMessage(MSG_STATUS_SMALL, "No object found.");
  894. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  895. return true;
  896. }
  897.  
  898. boost::char_separator<char> sep(" ");
  899. tokenizer tokens(param, sep);
  900.  
  901. std::string invalid;
  902. for(tokenizer::iterator it = tokens.begin(); it != tokens.end();)
  903. {
  904. std::string action = parseParams(it, tokens.end());
  905. toLowerCaseString(action);
  906. if(Item* item = thing->getItem())
  907. {
  908. if(action == "set" || action == "add" || action == "new")
  909. {
  910. std::string type = parseParams(it, tokens.end()), key = parseParams(it,
  911. tokens.end()), value = parseParams(it, tokens.end());
  912. if(type == "integer" || type == "number" || type == "int" || type == "num")
  913. item->setAttribute(key.c_str(), atoi(value.c_str()));
  914. else if(type == "float" || type == "double")
  915. item->setAttribute(key.c_str(), (float)atof(value.c_str()));
  916. else if(type == "bool" || type == "boolean")
  917. item->setAttribute(key.c_str(), booleanString(value));
  918. else
  919. item->setAttribute(key.c_str(), value);
  920. }
  921. else if(action == "erase" || action == "remove" || action == "delete")
  922. item->eraseAttribute(parseParams(it, tokens.end()).c_str());
  923. else if(action == "action" || action == "actionid" || action == "aid")
  924. {
  925. int32_t tmp = atoi(parseParams(it, tokens.end()).c_str());
  926. if(tmp > 0)
  927. item->setActionId(tmp);
  928. else
  929. item->resetActionId();
  930. }
  931. else if(action == "unique" || action == "uniqueid" || action == "uid")
  932. {
  933. int32_t tmp = atoi(parseParams(it, tokens.end()).c_str());
  934. if(tmp >= 1000 || tmp <= 0xFFFF)
  935. item->setUniqueId(tmp);
  936. }
  937. else if(action == "destination" || action == "position" || action == "pos"
  938. || action == "dest" || action == "location" || action == "loc") //TODO: doesn't work
  939. {
  940. if(Teleport* teleport = item->getTeleport())
  941. teleport->setDestination(Position(atoi(parseParams(it, tokens.end()).c_str()), atoi(
  942. parseParams(it, tokens.end()).c_str()), atoi(parseParams(it, tokens.end()).c_str())));
  943. }
  944. else
  945. {
  946. std::stringstream s;
  947. s << action << " (" << parseParams(it, tokens.end()) << ")";
  948. invalid += s.str();
  949. break;
  950. }
  951. }
  952. else if(Creature* _creature = thing->getCreature())
  953. {
  954. if(action == "health")
  955. _creature->changeHealth(atoi(parseParams(it, tokens.end()).c_str()));
  956. else if(action == "maxhealth")
  957. _creature->changeMaxHealth(atoi(parseParams(it, tokens.end()).c_str()));
  958. else if(action == "mana")
  959. _creature->changeMana(atoi(parseParams(it, tokens.end()).c_str()));
  960. else if(action == "maxmana")
  961. _creature->changeMaxMana(atoi(parseParams(it, tokens.end()).c_str()));
  962. else if(action == "basespeed")
  963. _creature->setBaseSpeed(atoi(parseParams(it, tokens.end()).c_str()));
  964. else if(action == "droploot")
  965. _creature->setDropLoot((lootDrop_t)atoi(parseParams(it, tokens.end()).c_str()));
  966. else if(action == "lossskill")
  967. _creature->setLossSkill(booleanString(parseParams(it, tokens.end())));
  968. else if(action == "storage")
  969. _creature->setStorage(parseParams(it, tokens.end()), parseParams(it, tokens.end()));
  970. else if(action == "cannotmove")
  971. {
  972. _creature->setNoMove(booleanString(parseParams(it, tokens.end())));
  973. _creature->onWalkAborted();
  974. }
  975. else if(action == "skull")
  976. {
  977. _creature->setSkull(getSkulls(parseParams(it, tokens.end())));
  978. g_game.updateCreatureSkull(_creature);
  979. }
  980. else if(action == "shield")
  981. {
  982. _creature->setShield(getShields(parseParams(it, tokens.end())));
  983. g_game.updateCreatureShield(_creature);
  984. }
  985. else if(action == "emblem")
  986. {
  987. _creature->setEmblem(getEmblems(parseParams(it, tokens.end())));
  988. g_game.updateCreatureEmblem(_creature);
  989. }
  990. else if(action == "speaktype")
  991. _creature->setSpeakType((MessageClasses)atoi(parseParams(it, tokens.end()).c_str()));
  992. else if(Player* _player = _creature->getPlayer())
  993. {
  994. if(action == "fyi")
  995. _player->sendFYIBox(parseParams(it, tokens.end()).c_str());
  996. else if(action == "tutorial")
  997. _player->sendTutorial(atoi(parseParams(it, tokens.end()).c_str()));
  998. else if(action == "guildlevel")
  999. _player->setGuildLevel((GuildLevel_t)atoi(parseParams(it, tokens.end()).c_str()));
  1000. else if(action == "guildrank")
  1001. _player->setRankId(atoi(parseParams(it, tokens.end()).c_str()));
  1002. else if(action == "guildnick")
  1003. _player->setGuildNick(parseParams(it, tokens.end()).c_str());
  1004. else if(action == "group")
  1005. {
  1006. uint16_t tmp = atoi(parseParams(it, tokens.end()).c_str());
  1007. if(tmp >= player->getGroupId())
  1008. {
  1009. invalid = "security failure - you can set only lower group than your own!";
  1010. break;
  1011. }
  1012. else
  1013. _player->setGroupId(tmp);
  1014. }
  1015. else if(action == "vocation")
  1016. _player->setVocation(atoi(parseParams(it, tokens.end()).c_str()));
  1017. else if(action == "sex" || action == "gender")
  1018. _player->setSex(atoi(parseParams(it, tokens.end()).c_str()));
  1019. else if(action == "town" || action == "temple")
  1020. {
  1021. if(Town* town = Towns::getInstance()->getTown(parseParams(it, tokens.end())))
  1022. {
  1023. _player->setMasterPosition(town->getPosition());
  1024. _player->setTown(town->getID());
  1025. }
  1026. }
  1027. else if(action == "marriage" || action == "partner")
  1028. _player->marriage = atoi(parseParams(it, tokens.end()).c_str());
  1029. else if(action == "balance")
  1030. _player->balance = atoi(parseParams(it, tokens.end()).c_str());
  1031. else if(action == "rates")
  1032. _player->rates[atoi(parseParams(it, tokens.end()).c_str())] = atof(
  1033. parseParams(it, tokens.end()).c_str());
  1034. else if(action == "idle")
  1035. _player->setIdleTime(atoi(parseParams(it, tokens.end()).c_str()));
  1036. else if(action == "stamina")
  1037. _player->setStaminaMinutes(atoi(parseParams(it, tokens.end()).c_str()));
  1038. else if(action == "capacity" || action == "cap")
  1039. _player->setCapacity(atoi(parseParams(it, tokens.end()).c_str()));
  1040. else if(action == "execute")
  1041. g_talkActions->onPlayerSay(_player, atoi(parseParams(it, tokens.end()).c_str()),
  1042. parseParams(it, tokens.end()), booleanString(parseParams(it, tokens.end())));
  1043. else if(action == "saving" || action == "save")
  1044. _player->switchSaving();
  1045. else
  1046. {
  1047. std::stringstream s;
  1048. s << action << " (" << parseParams(it, tokens.end()) << ")";
  1049. invalid += s.str();
  1050. break;
  1051. }
  1052. }
  1053. /*else if(Npc* _npc = _creature->getNpc())
  1054. {
  1055. }
  1056. else if(Monster* _monster = _creature->getMonster())
  1057. {
  1058. }*/
  1059. else
  1060. {
  1061. std::stringstream s;
  1062. s << action << " (" << parseParams(it, tokens.end()) << ")";
  1063. invalid += s.str();
  1064. break;
  1065. }
  1066. }
  1067. }
  1068.  
  1069. if(invalid.empty())
  1070. {
  1071. const SpectatorVec& list = g_game.getSpectators(pos);
  1072. SpectatorVec::const_iterator it;
  1073.  
  1074. Player* tmpPlayer = NULL;
  1075. for(it = list.begin(); it != list.end(); ++it)
  1076. {
  1077. if((tmpPlayer = (*it)->getPlayer()))
  1078. tmpPlayer->sendUpdateTile(tile, pos);
  1079. }
  1080.  
  1081. for(it = list.begin(); it != list.end(); ++it)
  1082. (*it)->onUpdateTile(tile, pos);
  1083. }
  1084. else
  1085. {
  1086. std::string tmp = "Following action was invalid: " + invalid;
  1087. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, tmp.c_str());
  1088. }
  1089.  
  1090. g_game.addMagicEffect(pos, MAGIC_EFFECT_WRAPS_GREEN);
  1091. return true;
  1092. }
  1093.  
  1094. bool TalkAction::banishmentInfo(Creature* creature, const std::string&, const std::string& param)
  1095. {
  1096. Player* player = creature->getPlayer();
  1097. if(!player)
  1098. return false;
  1099.  
  1100. StringVec params = explodeString(param, ",");
  1101. std::string what = "Account";
  1102. trimString(params[0]);
  1103.  
  1104. Ban ban;
  1105. ban.type = BAN_ACCOUNT;
  1106. if(params.size() > 1)
  1107. {
  1108. trimString(params[1]);
  1109. if(params[0].substr(0, 1) == "p")
  1110. {
  1111. what = "Character";
  1112. ban.type = BAN_PLAYER;
  1113. ban.param = PLAYERBAN_BANISHMENT;
  1114.  
  1115. ban.value = atoi(params[1].c_str());
  1116. if(!ban.value)
  1117. {
  1118. IOLoginData::getInstance()->getGuidByName(ban.value, params[1], true);
  1119. if(!ban.value)
  1120. ban.value = IOLoginData::getInstance()->getAccountIdByName(params[1]);
  1121. }
  1122. }
  1123. else
  1124. {
  1125. ban.value = atoi(params[1].c_str());
  1126. if(!ban.value)
  1127. {
  1128. IOLoginData::getInstance()->getAccountId(params[1], ban.value);
  1129. if(!ban.value)
  1130. ban.value = IOLoginData::getInstance()->getAccountIdByName(params[1]);
  1131. }
  1132. }
  1133. }
  1134. else
  1135. {
  1136. ban.value = atoi(params[0].c_str());
  1137. if(!ban.value)
  1138. {
  1139. IOLoginData::getInstance()->getAccountId(params[0], ban.value);
  1140. if(!ban.value)
  1141. ban.value = IOLoginData::getInstance()->getAccountIdByName(params[0]);
  1142. }
  1143. }
  1144.  
  1145. if(!ban.value)
  1146. {
  1147. toLowerCaseString(what);
  1148. player->sendCancel("Invalid " + what + (std::string)" name or id.");
  1149. return true;
  1150. }
  1151.  
  1152. if(!IOBan::getInstance()->getData(ban))
  1153. {
  1154. player->sendCancel("That player or account is not banished or deleted.");
  1155. return true;
  1156. }
  1157.  
  1158. bool deletion = ban.expires <= 0;
  1159. std::string admin = "Automatic ";
  1160. if(!ban.adminId)
  1161. admin += (deletion ? "deletion" : "banishment");
  1162. else
  1163. IOLoginData::getInstance()->getNameByGuid(ban.adminId, admin, true);
  1164.  
  1165. std::string end = "Banishment will be lifted at:\n";
  1166. if(deletion)
  1167. end = what + (std::string)" won't be undeleted";
  1168.  
  1169. std::stringstream ss;
  1170. ss << what.c_str() << " has been " << (deletion ? "deleted" : "banished") << " at:\n" << formatDateEx(ban.added, "%d %b %Y").c_str() << " by: " <<
  1171. admin.c_str() << ".\nThe comment given was:\n" << ban.comment.c_str() << ".\n" << end.c_str() << (deletion ? "." : formatDateEx(ban.expires).c_str()) << ".";
  1172.  
  1173. player->sendFYIBox(ss.str().c_str());
  1174. return true;
  1175. }
  1176.  
  1177. bool TalkAction::diagnostics(Creature* creature, const std::string&, const std::string&)
  1178. {
  1179. Player* player = creature->getPlayer();
  1180. if(!player)
  1181. return false;
  1182. #ifdef __ENABLE_SERVER_DIAGNOSTIC__
  1183.  
  1184. std::stringstream s;
  1185. s << "Server diagonostic:" << std::endl;
  1186. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, s.str());
  1187.  
  1188. s.str("");
  1189. s << "World:" << std::endl
  1190. << "--------------------" << std::endl
  1191. << "Player: " << g_game.getPlayersOnline() << " (" << Player::playerCount << ")" << std::endl
  1192. << "Npc: " << g_game.getNpcsOnline() << " (" << Npc::npcCount << ")" << std::endl
  1193. << "Monster: " << g_game.getMonstersOnline() << " (" << Monster::monsterCount << ")" << std::endl << std::endl;
  1194. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, s.str());
  1195.  
  1196. s.str("");
  1197. s << "Protocols:" << std::endl
  1198. << "--------------------" << std::endl
  1199. << "ProtocolGame: " << ProtocolGame::protocolGameCount << std::endl
  1200. << "ProtocolLogin: " << ProtocolLogin::protocolLoginCount << std::endl
  1201. #ifdef __OTADMIN__
  1202. << "ProtocolAdmin: " << ProtocolAdmin::protocolAdminCount << std::endl
  1203. #endif
  1204. << "ProtocolManager: " << ProtocolManager::protocolManagerCount << std::endl
  1205. << "ProtocolStatus: " << ProtocolStatus::protocolStatusCount << std::endl
  1206. << "ProtocolOld: " << ProtocolOld::protocolOldCount << std::endl << std::endl;
  1207. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, s.str());
  1208.  
  1209. s.str("");
  1210. s << "Connections:" << std::endl
  1211. << "--------------------" << std::endl
  1212. << "Active connections: " << Connection::connectionCount << std::endl
  1213. << "Total message pool: " << OutputMessagePool::getInstance()->getTotalMessageCount() << std::endl
  1214. << "Auto message pool: " << OutputMessagePool::getInstance()->getAutoMessageCount() << std::endl
  1215. << "Queued message pool: " << OutputMessagePool::getInstance()->getQueuedMessageCount() << std::endl
  1216. << "Free message pool: " << OutputMessagePool::getInstance()->getAvailableMessageCount() << std::endl;
  1217. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, s.str());
  1218.  
  1219. #else
  1220. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Command not available, please rebuild your software with -D__ENABLE_SERVER_DIAG__");
  1221. #endif
  1222. return true;
  1223. }
  1224.  
  1225. bool TalkAction::ghost(Creature* creature, const std::string&, const std::string&)
  1226. {
  1227. Player* player = creature->getPlayer();
  1228. if(!player)
  1229. return false;
  1230.  
  1231. if(player->hasFlag(PlayerFlag_CannotBeSeen))
  1232. {
  1233. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Command disabled for players with special, invisibility flag.");
  1234. return true;
  1235. }
  1236.  
  1237. SpectatorVec::iterator it;
  1238. SpectatorVec list = g_game.getSpectators(player->getPosition());
  1239. Player* tmpPlayer = NULL;
  1240.  
  1241. Condition* condition = NULL;
  1242. if((condition = player->getCondition(CONDITION_GAMEMASTER, CONDITIONID_DEFAULT, GAMEMASTER_INVISIBLE)))
  1243. {
  1244. player->sendTextMessage(MSG_INFO_DESCR, "You are visible again.");
  1245. IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), true);
  1246. for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
  1247. {
  1248. if((tmpPlayer = pit->second) && !tmpPlayer->canSeeCreature(player))
  1249. tmpPlayer->notifyLogIn(player);
  1250. }
  1251.  
  1252. for(it = list.begin(); it != list.end(); ++it)
  1253. {
  1254. if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
  1255. tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_TELEPORT);
  1256. }
  1257.  
  1258. player->removeCondition(condition);
  1259. g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_APPEAR);
  1260. }
  1261. else if((condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_GAMEMASTER, -1, 0, false, GAMEMASTER_INVISIBLE)))
  1262. {
  1263. player->addCondition(condition);
  1264. g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_DISAPPEAR);
  1265. for(it = list.begin(); it != list.end(); ++it)
  1266. {
  1267. if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
  1268. tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1269. }
  1270.  
  1271. for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
  1272. {
  1273. if((tmpPlayer = pit->second) && !tmpPlayer->canSeeCreature(player))
  1274. tmpPlayer->notifyLogOut(player);
  1275. }
  1276.  
  1277. IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), false);
  1278. if(player->isTrading())
  1279. g_game.internalCloseTrade(player);
  1280.  
  1281. player->clearPartyInvitations();
  1282. if(player->getParty())
  1283. player->getParty()->leave(player);
  1284.  
  1285. player->sendTextMessage(MSG_INFO_DESCR, "You are now invisible.");
  1286. }
  1287.  
  1288. return true;
  1289. }
  1290.  
  1291. bool TalkAction::software(Creature* creature, const std::string&, const std::string&)
  1292. {
  1293. Player* player = creature->getPlayer();
  1294. if(!player)
  1295. return false;
  1296.  
  1297. std::stringstream s;
  1298. s << "The " << SOFTWARE_NAME << " Version: (" << SOFTWARE_VERSION << "." << MINOR_VERSION << "." << PATCH_VERSION << ")" << std::endl;
  1299. s << REVISION_VERSION << std::endl;
  1300. s << "Codename: (" << SOFTWARE_CODENAME << ")" << std::endl << std::endl;
  1301. s << "Server Developers: " << SOFTWARE_DEVELOPERS << "." << std::endl;
  1302.  
  1303. player->sendTextMessage(MSG_EVENT_ADVANCE, s.str());
  1304.  
  1305. s.str("");
  1306. s << "Libraries:" << std::endl
  1307. << "--------------------" << std::endl
  1308. << "Platform: " << BOOST_PLATFORM << " for arch "
  1309. #if defined(__amd64__) || defined(_M_X64)
  1310. "64 Bits"
  1311. #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_)
  1312. "32 Bits"
  1313. #else
  1314. "unk"
  1315. #endif
  1316. << std::endl
  1317. << "Compiler: " << BOOST_COMPILER << std::endl
  1318. << "Boost: " << BOOST_VERSION << std::endl
  1319. << "ASIO: " << BOOST_ASIO_VERSION << std::endl
  1320. << "XML: " << XML_DEFAULT_VERSION << std::endl
  1321. << "Lua: " << LUA_VERSION << std::endl
  1322. << "Tibia Client Version: " << CLIENT_VERSION_STRING << std::endl;
  1323.  
  1324. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, s.str());
  1325. return true;
  1326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement