Advertisement
Guest User

Untitled

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