Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. /*
  2. Includes & Plugins:
  3. I-ZCMD 0.2.3.0: http://forum.sa-mp.com/showthread.php?t=576114
  4. MySQL R39-6: http://forum.sa-mp.com/showthread.php?t=56564 | https://github.com/pBlueG/SA-MP-MySQL/releases/tag/R39-6
  5. Streamer 2.9.0: http://forum.sa-mp.com/showthread.php?t=102865
  6. Foreach: http://forum.sa-mp.com/showthread.php?t=570868
  7. sscanf 2.8.2: http://forum.sa-mp.com/showthread.php?t=570927
  8.  
  9. All work completed in this script was with the help of iGetty:
  10. http://forum.sa-mp.com/member.php?u=105293
  11. https://www.youtube.com/channel/UCBWCX6AxNL7-O3xuvSKaG-A
  12.  
  13. This is the work of XXXXXXXXX, for the roleplay script.
  14. */
  15.  
  16. #include <a_samp>
  17. #include <zcmd>
  18. #include <a_mysql>
  19. #include <streamer>
  20. #include <foreach>
  21. #include <sscanf2>
  22.  
  23. #define Server:%0(%1) forward %0(%1); public %0(%1)
  24.  
  25. #define SQL_HOST = "localhost"
  26. #define SQL_USER = "root"
  27. #define SQL_DB = "rp"
  28. #define SQL_PASSWORD = ""
  29.  
  30. #define COLOR_WHITE 0xFFFFFF00
  31.  
  32. #define DIALOG_UNUSED 0
  33. #define DIALOG_REGISTER 1
  34. #define DIALOG_LOGIN 2
  35.  
  36. enum PLAYER_DATA
  37. {
  38. pSQLID,
  39. pAdminLevel
  40. }
  41.  
  42. // Global Variables
  43. new sqlConnection;
  44.  
  45.  
  46. // Player Variables
  47. new bool:LoggedIn[MAX_PLAYERS], PlayerData[MAX_PLAYERS][PLAYER_DATA];
  48.  
  49. main(){}
  50.  
  51. public OnGameModeInit()
  52. {
  53. mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_HTML);
  54. sqlConnection = mysql_connect("localhost", "root", "", "rp");
  55. return true;
  56. }
  57.  
  58. public OnGameModeExit()
  59. {
  60. mysql_close(sqlConnection);
  61. return true
  62. ;
  63. }
  64.  
  65. public OnPlayerConnect(playerid)
  66. {
  67. DefaultPlayerValues(playerid);
  68. DoesPlayerExist(playerid);
  69. return true;
  70. }
  71.  
  72. Server:DoesPlayerExist(playerid)
  73. {
  74. new query[128];
  75. mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM players WHERE Name = '%e' LIMIT 1", GetName(playerid));
  76. mysql_pquery(sqlConnection, query, "SQL_DoesPlayerExist", "i", playerid);
  77. return true;
  78. }
  79.  
  80. Server:SQL_DoesPlayerExist(playerid)
  81. {
  82. if(cache_num_rows(sqlConnection) != 0) // Exists
  83. {
  84. ShowLoginDialog(playerid, "");
  85. }
  86. else // Doesn't Exist
  87. {
  88. ShowRegisterDialog(playerid, "");
  89. }
  90. return true;
  91. }
  92.  
  93. Server:ShowLoginDialog(playerid, error[])
  94. {
  95. if(LoggedIn[playerid])return true;
  96. if(!strmatch(error, "")){
  97. SendClientMessage(playerid, COLOR_WHITE, error);
  98. }
  99.  
  100. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Scratch RP - Login", "Please enter your password to begin playing.", "Login", "Quit");
  101.  
  102. return true;
  103. }
  104.  
  105. Server:ShowRegisterDialog(playerid, error[])
  106. {
  107. if(LoggedIn[playerid])return true;
  108. if(!strmatch(error, "")){
  109. SendClientMessage(playerid, COLOR_WHITE, error);
  110. }
  111. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Scratch RP - Register", "Please enter your desired password below to begin playing", "Register", "Quit");
  112. return true;
  113. }
  114.  
  115.  
  116. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  117. {
  118. switch(dialogid)
  119. {
  120. case DIALOG_REGISTER:
  121. {
  122. if(!response)return Kick(playerid);
  123. if(strlen(inputtext) < 3 || strlen(inputtext) > 30){
  124. ShowRegisterDialog(playerid, "Password length must be above 3 characters AND below 30 characters long.");
  125. return true;
  126. }
  127.  
  128. new query[128];
  129. mysql_format(sqlConnection, query, sizeof(query), "INSERT INTO players (Name, Password, RegIP) VALUES('%e', sha1('%e%'), '%e')", GetName(playerid), inputtext, GetIP(playerid));
  130. mysql_pquery(sqlConnection, query, "SQL_OnAccountRegister", "i", playerid);
  131. }
  132. case DIALOG_LOGIN:
  133. {
  134. if(!response)return Kick(playerid);
  135.  
  136. if(strlen(inputtext) < 3 || strlen(inputtext) > 30) {
  137. ShowLoginDialog(playerid, "Password length must be above 3 characters AND below 30 characters long.");
  138. return true;
  139. }
  140.  
  141. new query[128];
  142. mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM players WHERE Name = '%e' AND Password = sha1('%e') LIMIT 1", GetName(playerid), inputtext);
  143. mysql_pquery(sqlConnection, query, "SQL_OnAccountLogin", "i", playerid);
  144. }
  145. }
  146. return false;
  147. }
  148.  
  149. Server:SQL_OnAccountLogin(playerid)
  150. {
  151. if(cache_num_rows() == 0) {
  152. ShowLoginDialog(playerid, "Incorrect password.");
  153. return true;
  154. }
  155. PlayerData[playerid][pSQLID] = cache_get_field_content_int(0, "id", sqlConnection);
  156. PlayerData[playerid][pAdminLevel] = cache_get_field_content_int(9, "AdminLevel", sqlConnection);
  157. new string[128];
  158. format(string, sizeof(string), "SQLID: %d | Admin: %d, PlayerData[playerid][pSQLID], PlayerData[playerid][pAdminLevel]");
  159. SendClientMessage(playerid, COLOR_WHITE, string);
  160. return true;
  161. }
  162.  
  163. Server:SQL_OnAccountRegister(playerid)
  164. {
  165. SendClientMessage(playerid, COLOR_WHITE, "You have successfully registered onto the server.");
  166. DefaultPlayerValues(playerid);
  167. PlayerData[playerid][pSQLID] = cache_insert_id();
  168. }
  169.  
  170. public OnPlayerDisconnect(playerid, reason)
  171. {
  172. DefaultPlayerValues(playerid);
  173. return true;
  174. }
  175.  
  176. public OnPlayerDeath(playerid, killerid, reason)
  177. {
  178. return true;
  179. }
  180.  
  181. public OnPlayerUpdate(playerid)
  182. {
  183. return true;
  184. }
  185.  
  186. Server:DefaultPlayerValues(playerid)
  187. {
  188. PlayerData[playerid][pSQLID] = 0;
  189. PlayerData[playerid][pAdminLevel] = 0;
  190. return true;
  191. }
  192.  
  193. // Stocks & Other Functions
  194.  
  195. GetIP(playerid)
  196. {
  197. new ip[20];
  198. GetPlayerIp(playerid, ip, sizeof(ip));
  199. return 1;
  200. }
  201.  
  202. GetName(playerid)
  203. {
  204. new name[MAX_PLAYER_NAME];
  205. GetPlayerName(playerid, name, sizeof(name));
  206. return name;
  207.  
  208. }
  209.  
  210. stock strmatch(const String1[], const String2[])
  211. {
  212. if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
  213. {
  214. return true;
  215. }
  216. else
  217. {
  218. return false;
  219. }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement