Advertisement
Guest User

Player

a guest
May 22nd, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.23 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', request a 'recovery key', add a 'character', or 'delete' a 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 contains invalid characters, try to say your name again, you might have typed it wrong.";
  24. else
  25. {
  26. talkState[2] = false;
  27. talkState[3] = true;
  28. managerString = tmp;
  29. msg << "Do you really want to delete the character named " << managerString << "?";
  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. To make sure you really want to lose your house by deleting your character, you have to login and leave the house or pass it to someone else first.";
  48. break;
  49.  
  50.  
  51. case DELETE_LEADER:
  52. msg << "Your character is the leader of a guild. You need to disband or pass the leadership someone else to delete your character.";
  53. break;
  54.  
  55.  
  56. case DELETE_ONLINE:
  57. msg << "A 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 << "Tell me what character you want to delete.";
  71. }
  72. else if(checkText(text, "password") && talkState[1])
  73. {
  74. talkState[1] = false;
  75. talkState[4] = true;
  76. msg << "Tell me your new password please.";
  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, at least 6 digits are required. Please select a longer password.";
  84. else if(!isValidPassword(tmp))
  85. msg << "Your password contains invalid characters... please tell me another one.";
  86. else
  87. {
  88. talkState[4] = false;
  89. talkState[5] = true;
  90. managerString = tmp;
  91. msg << "Should '" << managerString << "' be your new password?";
  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 << "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 reach the limit of 15 players, you can '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 << "Your name you want is too short, please select a longer name.";
  137. else if(managerString.length() > 20)
  138. msg << "The name you want is too long, please select a shorter name.";
  139. else if(!isValidName(managerString))
  140. msg << "That name seems to contain invalid symbols, please choose another name.";
  141. else if(IOLoginData::getInstance()->playerExists(managerString, true))
  142. msg << "A player with that name already exists, please choose another name.";
  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?";
  151. }
  152. else
  153. msg << "Your character is not a staff member, please tell me another name!";
  154. }
  155. }
  156. else if(checkText(text, "no") && talkState[7])
  157. {
  158. talkState[6] = true;
  159. talkState[7] = false;
  160. msg << "What else would you like to name your character?";
  161. }
  162. else if(checkText(text, "yes") && talkState[7])
  163. {
  164. talkState[7] = false;
  165. talkState[8] = true;
  166. msg << "Should your character 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?";
  175. managerSex = PLAYERSEX_FEMALE;
  176. }
  177. else
  178. {
  179. msg << "A male, are you sure?";
  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... 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. bool firstPart = true;
  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. {
  202. if(firstPart)
  203. {
  204. msg << "What do you want to be... " << it->second->getDescription();
  205. firstPart = false;
  206. }
  207. else if(it->first - 1 != 0)
  208. msg << ", " << it->second->getDescription();
  209. else
  210. msg << " or " << it->second->getDescription() << ".";
  211. }
  212. }
  213. }
  214. else if(!IOLoginData::getInstance()->playerExists(managerString, true))
  215. {
  216. talkState[1] = true;
  217. for(int8_t i = 2; i <= 12; i++)
  218. talkState[i] = false;
  219.  
  220.  
  221. if(IOLoginData::getInstance()->createCharacter(managerNumber, managerString, managerNumber2, (uint16_t)managerSex))
  222. msg << "Your character has been created.";
  223. else
  224. msg << "Your character couldn't be created, please try again.";
  225. }
  226. else
  227. {
  228. talkState[6] = true;
  229. talkState[9] = false;
  230. msg << "A player with that name already exists, please choose another name.";
  231. }
  232. }
  233. else if(talkState[11])
  234. {
  235. for(VocationsMap::iterator it = Vocations::getInstance()->getFirstVocation(); it != Vocations::getInstance()->getLastVocation(); ++it)
  236. {
  237. std::string tmp = asLowerCaseString(it->second->getName());
  238. if(checkText(text, tmp) && it != Vocations::getInstance()->getLastVocation() && it->first == it->second->getFromVocation() && it->first != 0)
  239. {
  240. msg << "So you would like to be " << it->second->getDescription() << "... are you sure?";
  241. managerNumber2 = it->first;
  242. talkState[11] = false;
  243. talkState[12] = true;
  244. }
  245. }
  246.  
  247.  
  248. if(msg.str().length() == 17)
  249. msg << "I don't understand what vocation you would like to be... could you please repeat it?";
  250. }
  251. else if(checkText(text, "yes") && talkState[12])
  252. {
  253. if(!IOLoginData::getInstance()->playerExists(managerString, true))
  254. {
  255. talkState[1] = true;
  256. for(int8_t i = 2; i <= 12; i++)
  257. talkState[i] = false;
  258.  
  259.  
  260. if(IOLoginData::getInstance()->createCharacter(managerNumber, managerString, managerNumber2, (uint16_t)managerSex))
  261. msg << "Your character has been created.";
  262. else
  263. msg << "Your character couldn't be created, please try again.";
  264. }
  265. else
  266. {
  267. talkState[6] = true;
  268. talkState[9] = false;
  269. msg << "A player with that name already exists, please choose another name.";
  270. }
  271. }
  272. else if(checkText(text, "no") && talkState[12])
  273. {
  274. talkState[11] = true;
  275. talkState[12] = false;
  276. msg << "No? Then what would you like to be?";
  277. }
  278. else if(checkText(text, "recovery key") && talkState[1])
  279. {
  280. talkState[1] = false;
  281. talkState[10] = true;
  282. msg << "Would you like a recovery key?";
  283. }
  284. else if(checkText(text, "yes") && talkState[10])
  285. {
  286. if(account.recoveryKey != "0")
  287. msg << "Sorry, you already have a recovery key, for security reasons I may not give you a new one.";
  288. else
  289. {
  290. managerString = generateRecoveryKey(4, 4);
  291. IOLoginData::getInstance()->setRecoveryKey(managerNumber, managerString);
  292. msg << "Your recovery key is: " << managerString << ".";
  293. }
  294.  
  295.  
  296. talkState[1] = true;
  297. for(int8_t i = 2; i <= 12; i++)
  298. talkState[i] = false;
  299. }
  300. else if(checkText(text, "no") && talkState[10])
  301. {
  302. msg << "Then not.";
  303. talkState[1] = true;
  304. for(int8_t i = 2; i <= 12; i++)
  305. talkState[i] = false;
  306. }
  307. else
  308. msg << "Please read the latest message that I have specified, I don't understand the current requested action.";
  309.  
  310.  
  311. break;
  312. }
  313. case MANAGER_NEW:
  314. {
  315. if(checkText(text, "account") && !talkState[1])
  316. {
  317. msg << "What would you like your password to be?";
  318. talkState[1] = true;
  319. talkState[2] = true;
  320. }
  321. else if(talkState[2])
  322. {
  323. std::string tmp = text;
  324. trimString(tmp);
  325. if(tmp.length() < 6)
  326. msg << "That password is too short, at least 6 digits are required. Please select a longer password.";
  327. else if(!isValidPassword(tmp))
  328. msg << "Your password contains invalid characters... please tell me another one.";
  329. else
  330. {
  331. talkState[3] = true;
  332. talkState[2] = false;
  333. managerString = tmp;
  334. msg << managerString << " is it? 'yes' or 'no'?";
  335. }
  336. }
  337. else if(checkText(text, "yes") && talkState[3])
  338. {
  339. if(g_config.getBool(ConfigManager::GENERATE_ACCOUNT_NUMBER))
  340. {
  341. do
  342. 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));
  343. while(IOLoginData::getInstance()->accountNameExists(managerChar));
  344.  
  345.  
  346. uint32_t id = (uint32_t)IOLoginData::getInstance()->createAccount(managerChar, managerString);
  347. if(id)
  348. {
  349. accountManager = MANAGER_ACCOUNT;
  350. managerNumber = id;
  351.  
  352.  
  353. noSwap = talkState[1] = false;
  354. msg << "Your account has been created, you may manage it now, but remember your account name: '"
  355. << managerChar << "' and password: '" << managerString
  356. << "'! If the account name is too hard to remember, please note it somewhere.";
  357. }
  358. else
  359. msg << "Your account could not be created, please try again.";
  360.  
  361.  
  362. for(int8_t i = 2; i <= 5; i++)
  363. talkState[i] = false;
  364. }
  365. else
  366. {
  367. msg << "What would you like your account name to be?";
  368. talkState[3] = false;
  369. talkState[4] = true;
  370. }
  371. }
  372. else if(checkText(text, "no") && talkState[3])
  373. {
  374. talkState[2] = true;
  375. talkState[3] = false;
  376. msg << "What would you like your password to be then?";
  377. }
  378. else if(talkState[4])
  379. {
  380. std::string tmp = text;
  381. trimString(tmp);
  382. if(tmp.length() < 3)
  383. msg << "That account name is too short, at least 3 digits are required. Please select a longer account name.";
  384. else if(tmp.length() > 25)
  385. msg << "That account name is too long, not more than 25 digits are required. Please select a shorter account name.";
  386. else if(!isValidAccountName(tmp))
  387. msg << "Your account name contains invalid characters, please choose another one.";
  388. else if(asLowerCaseString(tmp) == asLowerCaseString(managerString))
  389. msg << "Your account name cannot be same as password, please choose another one.";
  390. else
  391. {
  392. sprintf(managerChar, "%s", tmp.c_str());
  393. msg << managerChar << ", are you sure?";
  394. talkState[4] = false;
  395. talkState[5] = true;
  396. }
  397. }
  398. else if(checkText(text, "yes") && talkState[5])
  399. {
  400. if(!IOLoginData::getInstance()->accountNameExists(managerChar))
  401. {
  402. uint32_t id = (uint32_t)IOLoginData::getInstance()->createAccount(managerChar, managerString);
  403. if(id)
  404. {
  405. accountManager = MANAGER_ACCOUNT;
  406. managerNumber = id;
  407.  
  408.  
  409. noSwap = talkState[1] = false;
  410. msg << "Your account has been created, you may manage it now, but remember your account name: '"
  411. << managerChar << "' and password: '" << managerString << "'!";
  412. }
  413. else
  414. msg << "Your account could not be created, please try again.";
  415.  
  416.  
  417. for(int8_t i = 2; i <= 5; i++)
  418. talkState[i] = false;
  419. }
  420. else
  421. {
  422. msg << "An account with that name already exists, please try another account name.";
  423. talkState[4] = true;
  424. talkState[5] = false;
  425. }
  426. }
  427. else if(checkText(text, "no") && talkState[5])
  428. {
  429. talkState[5] = false;
  430. talkState[4] = true;
  431. msg << "What else would you like as your account name?";
  432. }
  433. else if(checkText(text, "recover") && !talkState[6])
  434. {
  435. talkState[6] = true;
  436. talkState[7] = true;
  437. msg << "What was your account name?";
  438. }
  439. else if(talkState[7])
  440. {
  441. managerString = text;
  442. if(IOLoginData::getInstance()->getAccountId(managerString, (uint32_t&)managerNumber))
  443. {
  444. talkState[7] = false;
  445. talkState[8] = true;
  446. msg << "What was your recovery key?";
  447. }
  448. else
  449. {
  450. msg << "Sorry, but account with such name doesn't exists.";
  451. talkState[6] = talkState[7] = false;
  452. }
  453. }
  454. else if(talkState[8])
  455. {
  456. managerString2 = text;
  457. if(IOLoginData::getInstance()->validRecoveryKey(managerNumber, managerString2) && managerString2 != "0")
  458. {
  459. sprintf(managerChar, "%s%d", g_config.getString(ConfigManager::SERVER_NAME).c_str(), random_range(100, 999));
  460. IOLoginData::getInstance()->setPassword(managerNumber, managerChar);
  461. msg << "Correct! Your new password is: " << managerChar << ".";
  462. }
  463. else
  464. msg << "Sorry, but this key doesn't match to account you gave me.";
  465.  
  466.  
  467. talkState[7] = talkState[8] = false;
  468. }
  469. else
  470. msg << "Sorry, but I can't understand you, please try to repeat that.";
  471.  
  472.  
  473. break;
  474. }
  475. default:
  476. return;
  477. break;
  478. }
  479.  
  480.  
  481. sendTextMessage(MSG_STATUS_CONSOLE_BLUE, msg.str().c_str());
  482. if(!noSwap)
  483. sendTextMessage(MSG_STATUS_CONSOLE_ORANGE, "Hint: Type 'account' to manage your account and if you want to start over then type 'cancel'.");
  484.  
  485. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement