fork(2) download
  1. #if defined filterscript
  2. -=-=-=-=-=-=-=-=-=-=-=..::" [s74] Registration System"::..-=-==-=-=-=-=-=-=-=-=-
  3. /*
  4. CREATOR:
  5. • RastaOrecha ( JM_Millers)
  6. > Facebook: http://w...content-available-to-author-only...k.com/sweed74
  7.   &&
  8. • FanHamMer
  9. > Skype: fanhammer
  10.  
  11. RUSSIAN MADAFAKA SCRIPTER COMMUNITI EBAT LOPATOI ANAL SEX VODKA DUDKA BALALAIKA
  12. ______________________________
  13. */
  14.  
  15. " _¶____________________._ "
  16. " /________\\___/___________|] "
  17. " /__==O__________________/ "
  18. " ), ---.(_\\(_) /; "
  19. " //_¤_)/ "
  20. " //_¤_// "
  21. " //_¤_// "
  22. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. #endif
  24.  
  25. /*CREATE TABLE `SREG`.`users` (
  26. `Name` VARCHAR( 24 ) NOT NULL ,
  27. `Key` VARCHAR( 16 ) NOT NULL ,
  28. `Money` INT( 10 ) NOT NULL ,
  29. `Admin` INT( 3 ) NOT NULL ,
  30. `Skin` INT( 3 ) NOT NULL
  31. ) ENGINE = MYISAM ;*/
  32.  
  33. // s74`Registration System by RastaOrecha
  34.  
  35. #tryinclude a_samp
  36. #tryinclude a_mysql
  37.  
  38. #file "s74`Registration"
  39.  
  40. #undef MAX_PLAYERS
  41. #define MAX_PLAYERS (50) // !!! MAX_PLAYERS
  42. #assert MAX_PLAYERS >(0)
  43.  
  44. ////////////////////////////////////////////////////////////////////////////////
  45. #define VECTOR (0) // Change to 1 to use loop optimization players
  46. #if VECTOR == 1
  47. #tryinclude Vectoral
  48. static players;
  49. #define foreach(%0) for(new %0, d, x = cvector_g_size(players); d != x; %0 &= 0, %0 += cvector_g_get(players, d++))
  50. #endif
  51. ////////////////////////////////////////////////////////////////////////////////
  52.  
  53. #define SPAWN_X (0.0)
  54. #define SPAWN_Y (0.0)
  55. #define SPAWN_Z (7.0)
  56. #define SPAWN_A (90.0)
  57.  
  58. #define SQL_HOST "localhost"
  59. #define SQL_USER "root"
  60. #define SQL_DB "SREG" //DataBase
  61. #define SQL_PASS ""
  62. #define SQL_TABLE "users" //
  63. #define SQL_DEBUG (0)
  64.  
  65. #define @ERR "[ERROR]"
  66. #define @OK "[OK]"
  67. #define col:: col_
  68.  
  69. #define VERSION (1)
  70.  
  71. #define d_none (0)
  72. #define d_reg (1)
  73. #define d_log (2)
  74.  
  75. #define col_lbl "{7DAEFF}"
  76. #define col_gld "{FFD700}"
  77.  
  78. //MACRO
  79. #define GN(%0) pInfo[%0][Name]
  80.  
  81. enum InfoPlayers{Name[24]};
  82.  
  83. static
  84. handle,
  85. pInfo[MAX_PLAYERS][InfoPlayers]
  86. ;
  87. public OnFilterScriptInit()
  88. {
  89. print("\n--------------------------------------"), \
  90. printf("s74`Register_System" # ...v1... "started"), \
  91. print("--------------------------------------\n");
  92.  
  93. handle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
  94. if mysql_ping()== 1 *then
  95. printf("MySQL " #@OK);
  96. else
  97. printf("MySQL " #@ERR);
  98.  
  99. #if VECTOR == 1
  100. players = cvector_g();
  101. #endif
  102. return true;
  103. }
  104.  
  105. public OnFilterScriptExit()
  106. {
  107. #if VECTOR == 1
  108. foreach(i)
  109. {
  110. SaveAccount(i);
  111. }
  112. cvector_g_clear(players);
  113. #else
  114. for(new i = GetMaxPlayers()-1; i != -1; --i)
  115. {
  116. SaveAccount(i);
  117. }
  118. #endif
  119. mysql_close(handle), \
  120. printf("MySQL" ", close");
  121. return true;
  122. }
  123.  
  124. public OnPlayerConnect(playerid)
  125. {
  126. #if VECTOR == 1
  127. cvector_g_push_back(players, playerid);
  128. #endif
  129. static query[70];
  130. GetPlayerName(playerid, pInfo[playerid][Name], MAX_PLAYER_NAME), \
  131. format(query,70, "select * from "#SQL_TABLE" where `Name`='%s'", GN(playerid)), \
  132. mysql_function_query(handle, query, true, "RegisterCheck", "d", playerid);
  133. return true;
  134. }
  135.  
  136. forward RegisterCheck(playerid);
  137. public RegisterCheck(playerid)
  138. {
  139. static rows, fields, str[93];
  140. cache_get_data(rows, fields);
  141. if rows *then
  142. format(str, 91,"Hello %s\n\
  143. Please, enter a password in the fields below to "#col::gld"login", GN(playerid)), \
  144. ShowPlayerDialog(playerid, d_log, DIALOG_STYLE_INPUT, ""#col::gld"Login", str, "Ok", "Cancel");
  145. else
  146. format(str, 93,"Hello %s\n\
  147. Please, enter a password in the fields below to "#col::gld"register", GN(playerid)), \
  148. ShowPlayerDialog(playerid, d_reg, DIALOG_STYLE_INPUT, ""#col::lbl"Registration", str, "Next", "Cancel");
  149. return true;
  150. }
  151. public OnPlayerDisconnect(playerid, reason)
  152. {
  153. #if VECTOR == 1
  154. cvector_g_remove(players, cvector_g_find(players, playerid));
  155. #endif
  156. SaveAccount(playerid);
  157. return true;
  158. }
  159.  
  160. public OnPlayerSpawn(playerid)
  161. {
  162. return true;
  163. }
  164.  
  165. public OnPlayerText(playerid, text[])
  166. {
  167.  
  168. if(GetPVarInt(playerid, "Logged") == 0) return false;
  169. return true;
  170. }
  171.  
  172. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  173. {
  174. static lstr[93];
  175. static query[100];
  176. switch(dialogid)
  177. {
  178. case d_log:
  179. {
  180. if !response *then return Kick(playerid);
  181. if !strlen(inputtext) *then
  182. return format(lstr, 91,"Hello %s\nPlease, enter a password in the fields below to "#col::gld"login", GN(playerid)), \
  183. ShowPlayerDialog(playerid, d_log, DIALOG_STYLE_INPUT, ""#col::gld"Login", lstr, "Ok", "Cancel");
  184.  
  185. format(query,100,"select * from "SQL_TABLE" where `Name`='%s' and `Key`='%s'", GN(playerid), inputtext), \
  186. mysql_function_query(handle, query, true, "Login", "d", playerid);
  187. }
  188. case d_reg:
  189. {
  190. if !response *then return Kick(playerid);
  191. if strlen(inputtext) < 3 || strlen(inputtext) > 16 *then
  192. return SendClientMessage(playerid, -1, "The password must be at least 3 and no more than 16 characters"), \
  193. format(lstr, 93,"Hello %s\nPlease, enter a password in the fields below to "#col::gld"register", GN(playerid)), \
  194. ShowPlayerDialog(playerid, d_reg, DIALOG_STYLE_INPUT, ""#col::lbl"Registration", lstr, "Next", "Cancel");
  195.  
  196. format(query, 90, "INSERT INTO "SQL_TABLE" (`Name`,`Key`) VALUES ('%s','%s')", GN(playerid), inputtext), \
  197. mysql_function_query(handle, query, false, "Register", "d", playerid);
  198. }
  199. }
  200. return true;
  201. }
  202.  
  203. forward Login(playerid);
  204. public Login(playerid)
  205. {
  206. static rows, fields;
  207. cache_get_data(rows, fields);
  208. if rows *then
  209. {
  210. GivePlayerMoney(playerid, cache_get_field_int(0, "Money", handle)), \
  211. SetPVarInt(playerid, "Admin", cache_get_field_int(0, "Admin", handle)), \
  212. SetPVarInt(playerid, "Logged", 1), \
  213. SetSpawnInfo(playerid,-1,cache_get_field_int(0, "Skin", handle), SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0,0, 0,0, 0,0), \
  214. SpawnPlayer(playerid), \
  215. SendClientMessage(playerid, -1, "[»] You have successfully logged in"), \
  216. PlayerPlaySound(playerid, 41603, 0.0, 0.0, 0.0);
  217. }
  218. else
  219. {
  220. if GetPVarInt(playerid, "WrongPassword") > 2 *then return Kick(playerid);
  221. SetPVarInt(playerid, "WrongPassword", GetPVarInt(playerid, "WrongPassword") + 1);
  222. new lstr[78];
  223. format(lstr, 78,"Wrong password (%i/3)\nPlease, enter a password in the fields below to "#col::gld"login", GetPVarInt(playerid, "WrongPassword")), \
  224.   ShowPlayerDialog(playerid, d_log, DIALOG_STYLE_INPUT, ""#col::gld"Login", lstr, "Ok", "Cancel"), \
  225.   PlayerPlaySound(playerid, 4203, 0.0, 0.0, 0.0);
  226. return true;
  227. }
  228. return true;
  229. }
  230.  
  231. forward Register(playerid);
  232. public Register(playerid)
  233. {
  234. static rand;
  235. rand = 1 + random(299);
  236. SendClientMessage(playerid, -1, "Welcome to the server, you have successfully registered"), \
  237. SetPlayerSkin(playerid, rand), \
  238. SetPVarInt(playerid, "Logged", 1), \
  239. SetSpawnInfo(playerid,-1,rand, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0,0, 0,0, 0,0), \
  240. SpawnPlayer(playerid), \
  241. PlayerPlaySound(playerid, 21001, 0.0, 0.0, 0.0);
  242. return true;
  243. }
  244.  
  245. SaveAccount(playerid)
  246. {
  247. if(GetPVarInt(playerid, "Logged") == 1)
  248. {
  249. static query[130];
  250. format(query, 130, "UPDATE "SQL_TABLE" SET `Money`='%d',`Admin`='%d',`Skin`='%d' WHERE `Name`='%s'",
  251. GetPlayerMoney(playerid), GetPVarInt(playerid, "Admin"), GetPlayerSkin(playerid), GN(playerid)), \
  252. mysql_query(query, -1, -1, handle);
  253. }
  254. return true;
  255. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty