y_extra_users.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Include pretty much 90% of YSI in one fell swoop!
  2. //#include "..\y_users"
  3. #include "..\y_inline"
  4. loadtext core[ysi_players], core[ysi_extras], core[ysi_dialog];
  5. /**--------------------------------------------------------------------------**\
  6. <summary>
  7. Extra_DoLogin
  8. Commands: /login
  9. </summary>
  10. <param name="playerid">Player trying to log in.</param>
  11. <param name="string:pw[]">The password they entered.</param>
  12. <returns>
  13. -
  14. </returns>
  15. <remarks>
  16. Called when a player attempts to log in. If "pw" is empty (NULL) this
  17. prompts the user for a password with a dialog. If it isn't empty then it
  18. takes that as the password.
  19. </remarks>
  20. \**--------------------------------------------------------------------------**/
  21. stock Extra_DoLogin(playerid, string:pw[])
  22. {
  23. if (Player_IsLoggedIn(playerid))
  24. {
  25. Text_Send(playerid, $YSI_LOGIN_ALREADY);
  26. return 1;
  27. }
  28. else if (!Player_IsRegistered(playerid))
  29. {
  30. //Text_Send(playerid, $YSI_LOGIN_ALREADY);
  31. Text_Send(playerid, $YSI_LOGIN_NOTF);
  32. Extra_DoRegister(playerid, NULL);
  33. return 1;
  34. }
  35. if (!isnull(pw))
  36. {
  37. Player_TryLogin(playerid, pw);
  38. return 1;
  39. }
  40. inline Response(pid, dialogid, response, listitem, string:text0[])
  41. {
  42. #pragma unused pid, dialogid, listitem
  43. if (response)
  44. {
  45. Player_TryLogin(playerid, text0);
  46. }
  47. }
  48. Text_PasswordBox(playerid, using inline Response, $YSI_EXTRA_LOGIN_TITLE, $YSI_EXTRA_LOGIN_PROMPT, $DIALOG_OK, $DIALOG_CANCEL);
  49. return 1;
  50. }
  51. YCMD:login(playerid, params[], help)
  52. {
  53. if (help)
  54. {
  55. Text_Send(playerid, $YSI_LOGIN_HELP);
  56. }
  57. else
  58. {
  59. Extra_DoLogin(playerid, params);
  60. }
  61. return 1;
  62. }
  63. /**--------------------------------------------------------------------------**\
  64. <summary>
  65. Extra_DoRegister
  66. Command: /register
  67. </summary>
  68. <param name="playerid">Player trying to log in.</param>
  69. <param name="string:pw[]">The password they entered.</param>
  70. <returns>
  71. -
  72. </returns>
  73. <remarks>
  74. Called when a player attempts to register. If "pw" is empty (NULL) this
  75. prompts the user for a password with a dialog. If it isn't empty then it
  76. takes that as the password and asks for confirmation.
  77. Currently this only checks the length of the password for strength, it
  78. doesn't check other properties such as number/case/symbol mixes.
  79. </remarks>
  80. \**--------------------------------------------------------------------------**/
  81. stock Extra_DoRegister(playerid, string:pw[])
  82. {
  83. if (Player_IsLoggedIn(playerid))
  84. {
  85. Text_Send(playerid, $YSI_LOGIN_ALREADY);
  86. return 1;
  87. }
  88. else if (Player_IsRegistered(playerid))
  89. {
  90. //Text_Send(playerid, $YSI_LOGIN_ALREADY);
  91. Text_Send(playerid, $YSI_REG_TAKEN);
  92. Extra_DoLogin(playerid, NULL);
  93. return 1;
  94. }
  95. if (isnull(pw))
  96. {
  97. // Enter password.
  98. inline Response1(pid1, dialogid1, response1, listitem1, string:text1[])
  99. {
  100. #pragma unused listitem1, dialogid1, pid1
  101. if (response1)
  102. {
  103. switch (strlen(text1))
  104. {
  105. case 0:
  106. {
  107. Text_Send(playerid, $YSI_LOGIN_ENTER);
  108. }
  109. case 1:
  110. {
  111. if (isnull(text1)) Text_Send(playerid, $YSI_LOGIN_ENTER);
  112. else Text_Send(playerid, $YSI_LOGIN_LENGTH);
  113. }
  114. case 2 .. 5:
  115. {
  116. Text_Send(playerid, $YSI_LOGIN_LENGTH);
  117. }
  118. default:
  119. {
  120. // Can add code here to test the strength of the pass.
  121. Extra_DoRegister(playerid, text1);
  122. return 1;
  123. }
  124. }
  125. Extra_DoRegister(playerid, NULL);
  126. }
  127. }
  128. Text_PasswordBox(playerid, using inline Response1, $YSI_EXTRA_REGISTER_TITLE, $YSI_EXTRA_REGISTER_PROMPT, $DIALOG_OK, $DIALOG_CANCEL);
  129. }
  130. else
  131. {
  132. // Store the password localy in the function and get confirmation.
  133. new
  134. pass[32];
  135. strcpy(pass, pw);
  136. inline Response2(pid2, dialogid2, response2, listitem2, string:text2[])
  137. {
  138. #pragma unused listitem2, dialogid2, pid2
  139. if (response2)
  140. {
  141. switch (strlen(text2))
  142. {
  143. case 0:
  144. {
  145. Text_Send(playerid, $YSI_LOGIN_ENTER);
  146. }
  147. case 1:
  148. {
  149. if (isnull(text2)) Text_Send(playerid, $YSI_LOGIN_ENTER);
  150. else Text_Send(playerid, $YSI_LOGIN_LENGTH);
  151. }
  152. case 2 .. 5:
  153. {
  154. Text_Send(playerid, $YSI_LOGIN_LENGTH);
  155. }
  156. default:
  157. {
  158. if (strcmp(pass, text2))
  159. {
  160. Text_Send(playerid, $YSI_EXTRA_REGISTER_MISMATCH);
  161. }
  162. else
  163. {
  164. Player_TryRegister(playerid, text2);
  165. return 1;
  166. }
  167. }
  168. }
  169. // Try again.
  170. Extra_DoRegister(playerid, pass);
  171. }
  172. }
  173. Text_PasswordBox(playerid, using inline Response2, $YSI_EXTRA_REGISTER_TITLE, $YSI_EXTRA_CONFIRM_PROMPT, $DIALOG_OK, $DIALOG_CANCEL);
  174. }
  175. return 1;
  176. }
  177. YCMD:register(playerid, params[], help)
  178. {
  179. if (help)
  180. {
  181. Text_Send(playerid, $YSI_REGISTER_HELP);
  182. }
  183. else
  184. {
  185. Extra_DoRegister(playerid, params);
  186. }
  187. return 1;
  188. }