Advertisement
Guest User

Untitled

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