Advertisement
Guest User

player5247x

a guest
May 22nd, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.53 KB | None | 0 0
  1.  case MANAGER_ACCOUNT: {
  2. Account account = IOLoginData::getInstance()->loadAccount(managerNumber);
  3. if(checkText(text, "cancel") || (checkText(text, "account") && !talkState[1]))
  4. {
  5. talkState[1] = true;
  6. for(int8_t i = 2; i <= 12; ++i)
  7. talkState[i] = false;
  8.  
  9.  
  10. msg << "Do you want to change your {password}, generate a {recovery key}, create a {character}, or {delete} an existing character?";
  11. }
  12. else if(checkText(text, "delete") && talkState[1])
  13. {
  14. talkState[1] = false;
  15. talkState[2] = true;
  16. msg << "Which character would you like to delete?";
  17. }
  18. else if(talkState[2])
  19. {
  20. std::string tmp = text;
  21. trimString(tmp);
  22. if(!isValidName(tmp, false))
  23. msg << "That name to contain invalid symbols, please try again.";
  24. else
  25. {
  26. talkState[2] = false;
  27. talkState[3] = true;
  28. managerString = tmp;
  29. msg << "Do you really want to delete the character {" << managerString << "}? {yes} or {no}";
  30. }
  31. }
  32. else if(checkText(text, "yes") && talkState[3])
  33. {
  34. switch(IOLoginData::getInstance()->deleteCharacter(managerNumber, managerString))
  35. {
  36. case DELETE_INTERNAL:
  37. msg << "An error occured while deleting your character. Either the character does not belong to you or it doesn't exist.";
  38. break;
  39.  
  40.  
  41. case DELETE_SUCCESS:
  42. msg << "Your character has been deleted.";
  43. break;
  44.  
  45.  
  46. case DELETE_HOUSE:
  47. msg << "Your character owns a house. You have to login and leave the house or pass it to someone else to complete.";
  48. break;
  49.  
  50.  
  51. case DELETE_LEADER:
  52. msg << "Your character is leader of a guild. You have to disband the guild or pass the leadership to someone else to complete.";
  53. break;
  54.  
  55.  
  56. case DELETE_ONLINE:
  57. msg << "Character with that name is currently online, to delete a character it has to be offline.";
  58. break;
  59. }
  60.  
  61.  
  62. talkState[1] = true;
  63. for(int8_t i = 2; i <= 12; ++i)
  64. talkState[i] = false;
  65. }
  66. else if(checkText(text, "no") && talkState[3])
  67. {
  68. talkState[1] = true;
  69. talkState[3] = false;
  70. msg << "Which character would you like to delete then?";
  71. }
  72. else if(checkText(text, "password") && talkState[1])
  73. {
  74. talkState[1] = false;
  75. talkState[4] = true;
  76. msg << "What would you like your password to be?";
  77. }
  78. else if(talkState[4])
  79. {
  80. std::string tmp = text;
  81. trimString(tmp);
  82. if(tmp.length() < 6)
  83. msg << "That password is too short, please select a longer one.";
  84. else if(!isValidPassword(tmp))
  85. msg << "Your password seems to contain invalid symbols, please choose another one.";
  86. else
  87. {
  88. talkState[4] = false;
  89. talkState[5] = true;
  90. managerString = tmp;
  91. msg << "{" << managerString << "} is it? {yes} or {no}?";
  92. }
  93. }
  94. else if(checkText(text, "yes") && talkState[5])
  95. {
  96. talkState[1] = true;
  97. for(int8_t i = 2; i <= 12; ++i)
  98. talkState[i] = false;
  99.  
  100.  
  101. IOLoginData::getInstance()->setPassword(managerNumber, managerString);
  102. msg << "Your password has been changed.";
  103. }
  104. else if(checkText(text, "no") && talkState[5])
  105. {
  106. talkState[1] = true;
  107. for(int8_t i = 2; i <= 12; ++i)
  108. talkState[i] = false;
  109.  
  110.  
  111. msg << "Ok, then not.";
  112. }
  113. else if(checkText(text, "character") && talkState[1])
  114. {
  115. if(account.charList.size() <= 10)
  116. {
  117. talkState[1] = false;
  118. talkState[6] = true;
  119. msg << "What would you like as your character name?";
  120. }
  121. else
  122. {
  123. talkState[1] = true;
  124. for(int8_t i = 2; i <= 12; ++i)
  125. talkState[i] = false;
  126.  
  127.  
  128. msg << "Your account has reached the limit of 10 characters, you should {delete} a character if you want to create a new one.";
  129. }
  130. }
  131. else if(talkState[6])
  132. {
  133. managerString = text;
  134. trimString(managerString);
  135. if(managerString.length() < 4)
  136. msg << "That name contains less than (4) characters, please select a longer name.";
  137. else if(managerString.length() > 25)
  138. msg << "That name is too long, please select a shorter one.";
  139. else if(!isValidName(managerString))
  140. msg << "Your name seems to contain invalid symbols, please choose another one.";
  141. else if(IOLoginData::getInstance()->playerExists(managerString, true))
  142. msg << "Player with that name already exists, please choose another one.";
  143. else
  144. {
  145. std::string tmp = asLowerCaseString(managerString);
  146. if(tmp.substr(0, 4) != "god " && tmp.substr(0, 3) != "cm " && tmp.substr(0, 3) != "gm ")
  147. {
  148. talkState[6] = false;
  149. talkState[7] = true;
  150. msg << "{" << managerString << "}, are you sure? {yes} or {no}";
  151. }
  152. else
  153. msg << "Your character is not a staff member, please choose another name.";
  154. }
  155. }
  156. else if(checkText(text, "no") && talkState[7])
  157. {
  158. talkState[6] = true;
  159. talkState[7] = false;
  160. msg << "What would you like your character name to be then?";
  161. }
  162. else if(checkText(text, "yes") && talkState[7])
  163. {
  164. talkState[7] = false;
  165. talkState[8] = true;
  166. msg << "Would you like to be a {male} or a {female}.";
  167. }
  168. else if(talkState[8] && (checkText(text, "female") || checkText(text, "male")))
  169. {
  170. talkState[8] = false;
  171. talkState[9] = true;
  172. if(checkText(text, "female"))
  173. {
  174. msg << "A female, are you sure? {yes} or {no}";
  175. managerSex = PLAYERSEX_FEMALE;
  176. }
  177. else
  178. {
  179. msg << "A male, are you sure? {yes} or {no}";
  180. managerSex = PLAYERSEX_MALE;
  181. }
  182. }
  183. else if(checkText(text, "no") && talkState[9])
  184. {
  185. talkState[8] = true;
  186. talkState[9] = false;
  187. msg << "Tell me then, would you like to be a {male} or a {female}?";
  188. }
  189. else if(checkText(text, "yes") && talkState[9])
  190. {
  191. if(g_config.getBool(ConfigManager::START_CHOOSEVOC))
  192. {
  193. talkState[9] = false;
  194. talkState[11] = true;
  195.  
  196.  
  197. std::vector<std::string> vocations;
  198. for(VocationsMap::iterator it = Vocations::getInstance()->getFirstVocation(); it != Vocations::getInstance()->getLastVocation(); ++it)
  199. {
  200. if(it->first == it->second->getFromVocation() && it->first != 0)
  201. vocations.push_back(it->second->getName());
  202. }
  203.  
  204.  
  205. msg << "What would you like to be... ";
  206. for(std::vector<std::string>::const_iterator it = vocations.begin(); it != vocations.end(); ++it)
  207. {
  208. if(it == vocations.begin())
  209. msg << "{" << *it << "}";
  210. else if(*it == *(vocations.rbegin()))
  211. msg << " or {" << *it << "}.";
  212. else
  213. msg << ", {" << *it << "}";
  214. }
  215. }
  216. else if(g_config.getBool(ConfigManager::START_CHOOSETOWN))
  217. {
  218. talkState[9] = false;
  219. talkState[13] = true;
  220.  
  221. bool firstPart = true;
  222. for(TownMap::const_iterator it = Towns::getInstance()->getFirstTown(); it != Towns::getInstance()->getLastTown(); ++it)
  223. {
  224. if(it->second->getID() < 100)
  225. {
  226. if(firstPart)
  227. {
  228. msg << "Where do you want to live... " << it->second->getName();
  229. firstPart = false;
  230. }
  231. else if(it->first - 1 != 0)
  232. msg << ", " << it->second->getName();
  233. else
  234. msg << " or " << it->second->getName() << ".";
  235. }
  236. }
  237. }
  238. else if(!IOLoginData::getInstance()->playerExists(managerString, true))
  239. {
  240. talkState[1] = true;
  241. for(int8_t i = 2; i <= 12; ++i)
  242. talkState[i] = false;
  243.  
  244.  
  245. if(IOLoginData::getInstance()->createCharacter(managerNumber, managerString, managerNumber2, (uint16_t)managerSex, managerNumber3))
  246. msg << "Your character {" << managerString << "} has been created.";
  247. else
  248. msg << "Your character couldn't be created, please contact with staff.";
  249. }
  250. else
  251. {
  252. talkState[6] = true;
  253. talkState[9] = false;
  254. msg << "Player with that name already exists, please choose another one.";
  255. }
  256. }
  257. else if(talkState[11])
  258. {
  259. for(VocationsMap::iterator it = Vocations::getInstance()->getFirstVocation(); it != Vocations::getInstance()->getLastVocation(); ++it)
  260. {
  261. if(checkText(text, asLowerCaseString(it->second->getName())) && it->first == it->second->getFromVocation() && it->first != 0)
  262. {
  263. msg << "So you would like to be " << it->second->getDescription() << ", {yes} or {no}?";
  264. managerNumber2 = it->first;
  265. talkState[11] = false;
  266. talkState[12] = true;
  267. }
  268. }
  269.  
  270. if(msg.str().length() == 17)
  271. msg << "I don't understand what vocation you would like to be... could you please repeat it?";
  272. }
  273. else if(checkText(text, "yes") && talkState[12])
  274. {
  275. if(g_config.getBool(ConfigManager::START_CHOOSETOWN))
  276. {
  277. talkState[12] = false;
  278. talkState[13] = true;
  279.  
  280. bool firstPart = true;
  281. for(TownMap::const_iterator it = Towns::getInstance()->getFirstTown(); it != Towns::getInstance()->getLastTown(); ++it)
  282. {
  283. if(it->second->getID() < 100)
  284. {
  285. if(firstPart)
  286. {
  287. msg << "Where do you want to live... " << it->second->getName();
  288. firstPart = false;
  289. }
  290. else if(it->first - 1 != 0)
  291. msg << ", " << it->second->getName();
  292. else
  293. msg << " or " << it->second->getName() << ".";
  294. }
  295. }
  296. }
  297. else if(!IOLoginData::getInstance()->playerExists(managerString, true))
  298. {
  299. talkState[1] = true;
  300. for(int8_t i = 2; i <= 12; ++i)
  301. talkState[i] = false;
  302.  
  303.  
  304. if(IOLoginData::getInstance()->createCharacter(managerNumber, managerString, managerNumber2, (uint16_t)managerSex, managerNumber3))                    
  305. msg << "Your character {" << managerString << "} has been created.";
  306. else
  307. msg << "Your character couldn't be created, please contact with staff.";
  308. }
  309. else
  310. {
  311. talkState[6] = true;
  312. talkState[9] = false;
  313. msg << "Player with that name already exists, please choose another one.";
  314. }
  315. }
  316. else if(checkText(text, "no") && talkState[12])
  317. {
  318. talkState[11] = true;
  319. talkState[12] = false;
  320. msg << "What would you like to be then?";
  321. }
  322. else if(talkState[13])
  323. {
  324. for(TownMap::const_iterator it = Towns::getInstance()->getFirstTown(); it != Towns::getInstance()->getLastTown(); it++)
  325. {
  326. std::string tmp = asLowerCaseString(it->second->getName());
  327. if(checkText(text, tmp) && it != Towns::getInstance()->getLastTown() && it->second->getID() < 100)
  328. {
  329. msg << "So do you want to live in " << it->second->getName() << ".. are you sure?";
  330. managerNumber3 = it->first;
  331. talkState[13] = false;
  332. talkState[14] = true;
  333. }
  334. }
  335.  
  336. if(msg.str().length() == 17)
  337. msg << "I don't understand where you would like to live... could you please repeat it?";
  338. }
  339. else if(checkText(text, "yes") && talkState[14])
  340. {
  341. if(!IOLoginData::getInstance()->playerExists(managerString, true))
  342. {
  343. talkState[1] = true;
  344. for(int8_t i = 2; i <= 14; i++)
  345. talkState[i] = false;
  346.  
  347. if(IOLoginData::getInstance()->createCharacter(managerNumber, managerString, managerNumber2, (uint16_t)managerSex, managerNumber3))
  348. msg << "Your character has been created.";
  349. else
  350. msg << "Your character couldn't be created, please try again.";
  351. }
  352. else
  353. {
  354. talkState[6] = true;
  355. talkState[9] = false;
  356. msg << "A player with that name already exists, please choose another name.";
  357. }
  358. }
  359. else if(checkText(text, "no") && talkState[14])
  360. {
  361. talkState[13] = true;
  362. talkState[14] = false;
  363. msg << "So where do you want to live?";
  364. }
  365. else if(checkText(text, "recovery key") && talkState[1])
  366. {
  367. talkState[1] = false;
  368. talkState[10] = true;
  369. msg << "Would you like to generate a recovery key? {yes} or {no}";
  370. }
  371. else if(checkText(text, "yes") && talkState[10])
  372. {
  373. if(account.recoveryKey != "0")
  374. msg << "Sorry, but you already have a recovery key. For security reasons I may not generate for you you a new one.";
  375. else
  376. {
  377. managerString = generateRecoveryKey(4, 4);
  378. IOLoginData::getInstance()->setRecoveryKey(managerNumber, managerString);
  379. msg << "Your recovery key is {" << managerString << "}.";
  380. }
  381.  
  382.  
  383. talkState[1] = true;
  384. for(int8_t i = 2; i <= 12; ++i)
  385. talkState[i] = false;
  386. }
  387. else if(checkText(text, "no") && talkState[10])
  388. {
  389. msg << "Ok, then not.";
  390. talkState[1] = true;
  391. for(int8_t i = 2; i <= 12; ++i)
  392. talkState[i] = false;
  393. }
  394. else
  395. msg << "Sorry, but I can't understand you, please try to repeat.";
  396.  
  397.  
  398. break;
  399. }
  400. case MANAGER_NEW:
  401. {
  402. if(checkText(text, "account") && !talkState[1])
  403. {
  404. msg << "What would you like your password to be?";
  405. talkState[1] = true;
  406. talkState[2] = true;
  407. }
  408. else if(talkState[2])
  409. {
  410. std::string tmp = text;
  411. trimString(tmp);
  412. if(tmp.length() < 6)
  413. msg << "That password is too short, please select a longer one.";
  414. else if(!isValidPassword(tmp))
  415. msg << "Your password seems to contain invalid symbols, please choose another one.";
  416. else
  417. {
  418. talkState[3] = true;
  419. talkState[2] = false;
  420. managerString = tmp;
  421. msg << "{" << managerString << "} is it? {yes} or {no}?";
  422. }
  423. }
  424. else if(checkText(text, "yes") && talkState[3])
  425. {
  426. if(g_config.getBool(ConfigManager::GENERATE_ACCOUNT_NUMBER))
  427. {
  428. do
  429. sprintf(managerChar, "%d%d%d%d%d%d%d", random_range(2, 9), random_range(2, 9), random_range(2, 9), random_range(2, 9), random_range(2, 9), random_range(2, 9), random_range(2, 9));
  430. while(IOLoginData::getInstance()->accountNameExists(managerChar));
  431.  
  432.  
  433. uint32_t id = (uint32_t)IOLoginData::getInstance()->createAccount(managerChar, managerString);
  434. if(id)
  435. {
  436. accountManager = MANAGER_ACCOUNT;
  437. managerNumber = id;
  438.  
  439.  
  440. noSwap = talkState[1] = false;
  441. msg << "Your account has been created, you may manage it now, but please remember your account name {"
  442. << managerChar << "} and password {" << managerString << "}!";
  443. }
  444. else
  445. msg << "Your account could not be created, please contact with staff.";
  446.  
  447.  
  448. for(int8_t i = 2; i <= 5; ++i)
  449. talkState[i] = false;
  450. }
  451. else
  452. {
  453. msg << "What would you like your account name to be?";
  454. talkState[3] = false;
  455. talkState[4] = true;
  456. }
  457. }
  458. else if(checkText(text, "no") && talkState[3])
  459. {
  460. talkState[2] = true;
  461. talkState[3] = false;
  462. msg << "What would you like your password to be then?";
  463. }
  464. else if(talkState[4])
  465. {
  466. std::string tmp = text;
  467. trimString(tmp);
  468. if(tmp.length() < 3)
  469. msg << "That account name is too short, please select a longer one.";
  470. else if(tmp.length() > 32)
  471. msg << "That account name is too long, please select a shorter one.";
  472. else if(!isValidAccountName(tmp))
  473. msg << "Your account name seems to contain invalid symbols, please choose another one.";
  474. else if(asLowerCaseString(tmp) == asLowerCaseString(managerString))
  475. msg << "Your account name cannot be same as password, please choose another one.";
  476. else
  477. {
  478. sprintf(managerChar, "%s", tmp.c_str());
  479. msg << "{" << managerChar << "}, is it? {yes} or {no}?";
  480. talkState[4] = false;
  481. talkState[5] = true;
  482. }
  483. }
  484. else if(checkText(text, "yes") && talkState[5])
  485. {
  486. if(!IOLoginData::getInstance()->accountNameExists(managerChar))
  487. {
  488. uint32_t id = (uint32_t)IOLoginData::getInstance()->createAccount(managerChar, managerString);
  489. if(id)
  490. {
  491. accountManager = MANAGER_ACCOUNT;
  492. managerNumber = id;
  493.  
  494.  
  495. noSwap = talkState[1] = false;
  496. msg << "Your account has been created, you may manage it now, but please remember your account name {"
  497. << managerChar << "} and password {" << managerString << "}!";
  498. }
  499. else
  500. msg << "Your account could not be created, please contact with staff.";
  501.  
  502.  
  503. for(int8_t i = 2; i <= 5; ++i)
  504. talkState[i] = false;
  505. }
  506. else
  507. {
  508. msg << "Account with that name already exists, please choose another one.";
  509. talkState[4] = true;
  510. talkState[5] = false;
  511. }
  512. }
  513. else if(checkText(text, "no") && talkState[5])
  514. {
  515. talkState[5] = false;
  516. talkState[4] = true;
  517. msg << "What would you like your account name to be then?";
  518. }
  519. else if(checkText(text, "recover") && !talkState[6])
  520. {
  521. talkState[6] = true;
  522. talkState[7] = true;
  523. msg << "What was your account name?";
  524. }
  525. else if(talkState[7])
  526. {
  527. managerString = text;
  528. if(IOLoginData::getInstance()->getAccountId(managerString, (uint32_t&)managerNumber))
  529. {
  530. talkState[7] = false;
  531. talkState[8] = true;
  532. msg << "What was your recovery key?";
  533. }
  534. else
  535. {
  536. msg << "Sorry, but account with name {" << managerString << "} does not exists.";
  537. talkState[6] = talkState[7] = false;
  538. }
  539. }
  540. else if(talkState[8])
  541. {
  542. managerString2 = text;
  543. if(IOLoginData::getInstance()->validRecoveryKey(managerNumber, managerString2) && managerString2 != "0")
  544. {
  545. sprintf(managerChar, "%s%d", g_config.getString(ConfigManager::SERVER_NAME).c_str(), random_range(100, 999));
  546. IOLoginData::getInstance()->setPassword(managerNumber, managerChar);
  547. msg << "Correct! Your new password is {" << managerChar << "}.";
  548. }
  549. else
  550. msg << "Sorry, but this key does not match to specified account.";
  551.  
  552.  
  553. talkState[7] = talkState[8] = false;
  554. }
  555. else
  556. msg << "Sorry, but I can't understand you, please try to repeat.";
  557.  
  558.  
  559. break;
  560. }
  561. default:
  562. return;
  563. break;
  564. }
  565.  
  566.  
  567. sendCreatureSay(this, MSG_NPC_FROM, msg.str());
  568. if(!noSwap)
  569. sendCreatureSay(this, MSG_NPC_FROM, "Hint: Type {account} to manage your account and if you want to start over then type {cancel}.");
  570. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement