Advertisement
Guest User

player5247

a guest
May 22nd, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.98 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() <= 15)
  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 15 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() < 3)
  136. msg << "That name is too short, please select a longer one.";
  137. else if(managerString.length() > 30)
  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(!IOLoginData::getInstance()->playerExists(managerString, true))
  217. {
  218. talkState[1] = true;
  219. for(int8_t i = 2; i <= 12; ++i)
  220. talkState[i] = false;
  221.  
  222.  
  223. if(IOLoginData::getInstance()->createCharacter(managerNumber, managerString, managerNumber2, (uint16_t)managerSex))
  224. msg << "Your character {" << managerString << "} has been created.";
  225. else
  226. msg << "Your character couldn't be created, please contact with staff.";
  227. }
  228. else
  229. {
  230. talkState[6] = true;
  231. talkState[9] = false;
  232. msg << "Player with that name already exists, please choose another one.";
  233. }
  234. }
  235. else if(talkState[11])
  236. {
  237. for(VocationsMap::iterator it = Vocations::getInstance()->getFirstVocation(); it != Vocations::getInstance()->getLastVocation(); ++it)
  238. {
  239. if(checkText(text, asLowerCaseString(it->second->getName())) &&
  240. it->first == it->second->getFromVocation() && it->first != 0)
  241. {
  242. msg << "So you would like to be " << it->second->getDescription() << ", {yes} or {no}?";
  243. managerNumber2 = it->first;
  244. talkState[11] = false;
  245. talkState[12] = true;
  246. }
  247. }
  248. }
  249. else if(checkText(text, "yes") && talkState[12])
  250. {
  251. if(!IOLoginData::getInstance()->playerExists(managerString, true))
  252. {
  253. talkState[1] = true;
  254. for(int8_t i = 2; i <= 12; ++i)
  255. talkState[i] = false;
  256.  
  257.  
  258. if(IOLoginData::getInstance()->createCharacter(managerNumber, managerString, managerNumber2, (uint16_t)managerSex))
  259. msg << "Your character {" << managerString << "} has been created.";
  260. else
  261. msg << "Your character couldn't be created, please contact with staff.";
  262. }
  263. else
  264. {
  265. talkState[6] = true;
  266. talkState[9] = false;
  267. msg << "Player with that name already exists, please choose another one.";
  268. }
  269. }
  270. else if(checkText(text, "no") && talkState[12])
  271. {
  272. talkState[11] = true;
  273. talkState[12] = false;
  274. msg << "What would you like to be then?";
  275. }
  276. else if(checkText(text, "recovery key") && talkState[1])
  277. {
  278. talkState[1] = false;
  279. talkState[10] = true;
  280. msg << "Would you like to generate a recovery key? {yes} or {no}";
  281. }
  282. else if(checkText(text, "yes") && talkState[10])
  283. {
  284. if(account.recoveryKey != "0")
  285. msg << "Sorry, but you already have a recovery key. For security reasons I may not generate for you you a new one.";
  286. else
  287. {
  288. managerString = generateRecoveryKey(4, 4);
  289. IOLoginData::getInstance()->setRecoveryKey(managerNumber, managerString);
  290. msg << "Your recovery key is {" << managerString << "}.";
  291. }
  292.  
  293.  
  294. talkState[1] = true;
  295. for(int8_t i = 2; i <= 12; ++i)
  296. talkState[i] = false;
  297. }
  298. else if(checkText(text, "no") && talkState[10])
  299. {
  300. msg << "Ok, then not.";
  301. talkState[1] = true;
  302. for(int8_t i = 2; i <= 12; ++i)
  303. talkState[i] = false;
  304. }
  305. else
  306. msg << "Sorry, but I can't understand you, please try to repeat.";
  307.  
  308.  
  309. break;
  310. }
  311. case MANAGER_NEW:
  312. {
  313. if(checkText(text, "account") && !talkState[1])
  314. {
  315. msg << "What would you like your password to be?";
  316. talkState[1] = true;
  317. talkState[2] = true;
  318. }
  319. else if(talkState[2])
  320. {
  321. std::string tmp = text;
  322. trimString(tmp);
  323. if(tmp.length() < 6)
  324. msg << "That password is too short, please select a longer one.";
  325. else if(!isValidPassword(tmp))
  326. msg << "Your password seems to contain invalid symbols, please choose another one.";
  327. else
  328. {
  329. talkState[3] = true;
  330. talkState[2] = false;
  331. managerString = tmp;
  332. msg << "{" << managerString << "} is it? {yes} or {no}?";
  333. }
  334. }
  335. else if(checkText(text, "yes") && talkState[3])
  336. {
  337. if(g_config.getBool(ConfigManager::GENERATE_ACCOUNT_NUMBER))
  338. {
  339. do
  340. 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));
  341. while(IOLoginData::getInstance()->accountNameExists(managerChar));
  342.  
  343.  
  344. uint32_t id = (uint32_t)IOLoginData::getInstance()->createAccount(managerChar, managerString);
  345. if(id)
  346. {
  347. accountManager = MANAGER_ACCOUNT;
  348. managerNumber = id;
  349.  
  350.  
  351. noSwap = talkState[1] = false;
  352. msg << "Your account has been created, you may manage it now, but please remember your account name {"
  353. << managerChar << "} and password {" << managerString << "}!";
  354. }
  355. else
  356. msg << "Your account could not be created, please contact with staff.";
  357.  
  358.  
  359. for(int8_t i = 2; i <= 5; ++i)
  360. talkState[i] = false;
  361. }
  362. else
  363. {
  364. msg << "What would you like your account name to be?";
  365. talkState[3] = false;
  366. talkState[4] = true;
  367. }
  368. }
  369. else if(checkText(text, "no") && talkState[3])
  370. {
  371. talkState[2] = true;
  372. talkState[3] = false;
  373. msg << "What would you like your password to be then?";
  374. }
  375. else if(talkState[4])
  376. {
  377. std::string tmp = text;
  378. trimString(tmp);
  379. if(tmp.length() < 3)
  380. msg << "That account name is too short, please select a longer one.";
  381. else if(tmp.length() > 32)
  382. msg << "That account name is too long, please select a shorter one.";
  383. else if(!isValidAccountName(tmp))
  384. msg << "Your account name seems to contain invalid symbols, please choose another one.";
  385. else if(asLowerCaseString(tmp) == asLowerCaseString(managerString))
  386. msg << "Your account name cannot be same as password, please choose another one.";
  387. else
  388. {
  389. sprintf(managerChar, "%s", tmp.c_str());
  390. msg << "{" << managerChar << "}, is it? {yes} or {no}?";
  391. talkState[4] = false;
  392. talkState[5] = true;
  393. }
  394. }
  395. else if(checkText(text, "yes") && talkState[5])
  396. {
  397. if(!IOLoginData::getInstance()->accountNameExists(managerChar))
  398. {
  399. uint32_t id = (uint32_t)IOLoginData::getInstance()->createAccount(managerChar, managerString);
  400. if(id)
  401. {
  402. accountManager = MANAGER_ACCOUNT;
  403. managerNumber = id;
  404.  
  405.  
  406. noSwap = talkState[1] = false;
  407. msg << "Your account has been created, you may manage it now, but please remember your account name {"
  408. << managerChar << "} and password {" << managerString << "}!";
  409. }
  410. else
  411. msg << "Your account could not be created, please contact with staff.";
  412.  
  413.  
  414. for(int8_t i = 2; i <= 5; ++i)
  415. talkState[i] = false;
  416. }
  417. else
  418. {
  419. msg << "Account with that name already exists, please choose another one.";
  420. talkState[4] = true;
  421. talkState[5] = false;
  422. }
  423. }
  424. else if(checkText(text, "no") && talkState[5])
  425. {
  426. talkState[5] = false;
  427. talkState[4] = true;
  428. msg << "What would you like your account name to be then?";
  429. }
  430. else if(checkText(text, "recover") && !talkState[6])
  431. {
  432. talkState[6] = true;
  433. talkState[7] = true;
  434. msg << "What was your account name?";
  435. }
  436. else if(talkState[7])
  437. {
  438. managerString = text;
  439. if(IOLoginData::getInstance()->getAccountId(managerString, (uint32_t&)managerNumber))
  440. {
  441. talkState[7] = false;
  442. talkState[8] = true;
  443. msg << "What was your recovery key?";
  444. }
  445. else
  446. {
  447. msg << "Sorry, but account with name {" << managerString << "} does not exists.";
  448. talkState[6] = talkState[7] = false;
  449. }
  450. }
  451. else if(talkState[8])
  452. {
  453. managerString2 = text;
  454. if(IOLoginData::getInstance()->validRecoveryKey(managerNumber, managerString2) && managerString2 != "0")
  455. {
  456. sprintf(managerChar, "%s%d", g_config.getString(ConfigManager::SERVER_NAME).c_str(), random_range(100, 999));
  457. IOLoginData::getInstance()->setPassword(managerNumber, managerChar);
  458. msg << "Correct! Your new password is {" << managerChar << "}.";
  459. }
  460. else
  461. msg << "Sorry, but this key does not match to specified account.";
  462.  
  463.  
  464. talkState[7] = talkState[8] = false;
  465. }
  466. else
  467. msg << "Sorry, but I can't understand you, please try to repeat.";
  468.  
  469.  
  470. break;
  471. }
  472. default:
  473. return;
  474. break;
  475. }
  476.  
  477.  
  478. sendCreatureSay(this, MSG_NPC_FROM, msg.str());
  479. if(!noSwap)
  480. sendCreatureSay(this, MSG_NPC_FROM, "Hint: Type {account} to manage your account and if you want to start over then type {cancel}.");
  481. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement