y_extra_users.inc 4.7 KB

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