Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.18 KB | None | 0 0
  1. #include <a_samp>
  2. #include <mysql>
  3.  
  4. #define DIALOG_LOGIN 100
  5. #define DIALOG_REGISTER 101
  6. #define SERVERNAME "Server"
  7. //=====Colors====
  8. #define cGREEN 0x33AA33AA
  9. #define cRED 0xAA3333AA
  10. #define cYELLOW 0xFFFF00AA
  11. #define cLIGHTBLUE 0x33CCFFAA
  12. #define cORANGE 0xFF9900AA
  13.  
  14. enum pInfo
  15. {
  16. Id,
  17. username[25],
  18. Password[50],
  19. CallSign[8],
  20. Admin,
  21. VIP,
  22. Money,
  23. Score,
  24. Banned,
  25. Reason[100],
  26. PlayerIP[20],
  27. LoggedIn
  28. }
  29.  
  30.  
  31. new PlayerInfo[MAX_PLAYERS][pInfo];
  32.  
  33. public OnPlayerConnect(playerid)
  34. {
  35. if(CheckUser(playerid))
  36. {
  37. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, SERVERNAME, "Please enter your password to login", "Login", "Cancel");
  38. }
  39.  
  40.  
  41. else
  42. {
  43. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, SERVERNAME, "Please enter a password to register", "Register", "Cancel");
  44. }
  45. }
  46.  
  47. //========Dialogs=======
  48.  
  49. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  50. {
  51. if(dialogid == DIALOG_LOGIN)
  52. {
  53. if(CheckUserLogin(playerid,inputtext))
  54. {
  55. LoginUser(playerid);
  56. }
  57. else
  58. {
  59. Kick(playerid);
  60. }
  61. }
  62. return 0;
  63. }
  64.  
  65. //======= Stocks========
  66. stock GetName(playerid)
  67. {
  68. new pName[MAX_PLAYER_NAME];
  69. GetPlayerName(playerid, pName, sizeof(pName));
  70. return pName;
  71. }
  72.  
  73. stock CheckUser(playerid)
  74. {
  75. new Query[200]; format(Query, sizeof(Query), "SELECT * FROM users WHERE username = '%s';",GetName(playerid));
  76. mysql_query(Query);
  77. mysql_store_result();
  78. if(mysql_num_rows()) return 1;
  79. return 0;
  80. }
  81.  
  82. stock LoginUser(playerid)
  83. {
  84. new Query[200]; format(Query, sizeof(Query), "SELECT * FROM users WHERE username = '%s';",GetName(playerid));
  85. mysql_query(Query);
  86. mysql_store_result();
  87. if(mysql_fetch_row(Query,"|")) {
  88. sscanf(Query, "p<|>e<is[25]s[50]s[8]iiiiiiiiiiiiis[100]iii>", PlayerInfo[playerid]);
  89. }
  90. PlayerInfo[playerid][LoggedIn] = 1;
  91. GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
  92. SetPlayerScore(playerid, PlayerInfo[playerid][Score]);
  93. SendClientMessage(playerid, cGREEN, "Successfully logged in.");
  94. GetPlayerIp(playerid, PlayerInfo[playerid][PlayerIP], 20);
  95. }
  96.  
  97. stock CheckUserLogin(playerid, password[])
  98. {
  99. new Query[200]; format(Query, sizeof(Query), "SELECT * FROM users WHERE username = '%s' AND password = MD5('%s');",GetName(playerid), password);
  100. mysql_query(Query);
  101. mysql_store_result();
  102. if(mysql_num_rows()) return 1;
  103. return 0;
  104. }
  105.  
  106. //=======sscanf=======
  107. stock sscanf(string[], format[], {Float,_}:...)
  108. {
  109. #if defined isnull
  110. if (isnull(string))
  111. #else
  112. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  113. #endif
  114. {
  115. return format[0];
  116. }
  117. #pragma tabsize 4
  118. new
  119. formatPos = 0,
  120. stringPos = 0,
  121. paramPos = 2,
  122. paramCount = numargs(),
  123. delim = ' ';
  124. while (string[stringPos] && string[stringPos] <= ' ')
  125. {
  126. stringPos++;
  127. }
  128. while (paramPos < paramCount && string[stringPos])
  129. {
  130. switch (format[formatPos++])
  131. {
  132. case '\0':
  133. {
  134. return 0;
  135. }
  136. case 'i', 'd':
  137. {
  138. new
  139. neg = 1,
  140. num = 0,
  141. ch = string[stringPos];
  142. if (ch == '-')
  143. {
  144. neg = -1;
  145. ch = string[++stringPos];
  146. }
  147. do
  148. {
  149. stringPos++;
  150. if ('0' <= ch <= '9')
  151. {
  152. num = (num * 10) + (ch - '0');
  153. }
  154. else
  155. {
  156. return -1;
  157. }
  158. }
  159. while ((ch = string[stringPos]) > ' ' && ch != delim);
  160. setarg(paramPos, 0, num * neg);
  161. }
  162. case 'h', 'x':
  163. {
  164. new
  165. num = 0,
  166. ch = string[stringPos];
  167. do
  168. {
  169. stringPos++;
  170. switch (ch)
  171. {
  172. case 'x', 'X':
  173. {
  174. num = 0;
  175. continue;
  176. }
  177. case '0' .. '9':
  178. {
  179. num = (num << 4) | (ch - '0');
  180. }
  181. case 'a' .. 'f':
  182. {
  183. num = (num << 4) | (ch - ('a' - 10));
  184. }
  185. case 'A' .. 'F':
  186. {
  187. num = (num << 4) | (ch - ('A' - 10));
  188. }
  189. default:
  190. {
  191. return -1;
  192. }
  193. }
  194. }
  195. while ((ch = string[stringPos]) > ' ' && ch != delim);
  196. setarg(paramPos, 0, num);
  197. }
  198. case 'c':
  199. {
  200. setarg(paramPos, 0, string[stringPos++]);
  201. }
  202. case 'f':
  203. {
  204.  
  205. new changestr[16], changepos = 0, strpos = stringPos;
  206. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  207. {
  208. changestr[changepos++] = string[strpos++];
  209. }
  210. changestr[changepos] = '\0';
  211. setarg(paramPos,0,_:floatstr(changestr));
  212. }
  213. case 'p':
  214. {
  215. delim = format[formatPos++];
  216. continue;
  217. }
  218. case '\'':
  219. {
  220. new
  221. end = formatPos - 1,
  222. ch;
  223. while ((ch = format[++end]) && ch != '\'') {}
  224. if (!ch)
  225. {
  226. return -1;
  227. }
  228. format[end] = '\0';
  229. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  230. {
  231. if (format[end + 1])
  232. {
  233. return -1;
  234. }
  235. return 0;
  236. }
  237. format[end] = '\'';
  238. stringPos = ch + (end - formatPos);
  239. formatPos = end + 1;
  240. }
  241. case 'u':
  242. {
  243. new
  244. end = stringPos - 1,
  245. id = 0,
  246. bool:num = true,
  247. ch;
  248. while ((ch = string[++end]) && ch != delim)
  249. {
  250. if (num)
  251. {
  252. if ('0' <= ch <= '9')
  253. {
  254. id = (id * 10) + (ch - '0');
  255. }
  256. else
  257. {
  258. num = false;
  259. }
  260. }
  261. }
  262. if (num && IsPlayerConnected(id))
  263. {
  264. setarg(paramPos, 0, id);
  265. }
  266. else
  267. {
  268. #if !defined foreach
  269. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  270. #define __SSCANF_FOREACH__
  271. #endif
  272. string[end] = '\0';
  273. num = false;
  274. new
  275. name[MAX_PLAYER_NAME];
  276. id = end - stringPos;
  277. foreach (Player, playerid)
  278. {
  279. GetPlayerName(playerid, name, sizeof (name));
  280. if (!strcmp(name, string[stringPos], true, id))
  281. {
  282. setarg(paramPos, 0, playerid);
  283. num = true;
  284. break;
  285. }
  286. }
  287. if (!num)
  288. {
  289. setarg(paramPos, 0, INVALID_PLAYER_ID);
  290. }
  291. string[end] = ch;
  292. #if defined __SSCANF_FOREACH__
  293. #undef foreach
  294. #undef __SSCANF_FOREACH__
  295. #endif
  296. }
  297. stringPos = end;
  298. }
  299. case 's', 'z':
  300. {
  301. new
  302. i = 0,
  303. ch;
  304. if (format[formatPos])
  305. {
  306. while ((ch = string[stringPos++]) && ch != delim)
  307. {
  308. setarg(paramPos, i++, ch);
  309. }
  310. if (!i)
  311. {
  312. return -1;
  313. }
  314. }
  315. else
  316. {
  317. while ((ch = string[stringPos++]))
  318. {
  319. setarg(paramPos, i++, ch);
  320. }
  321. }
  322. stringPos--;
  323. setarg(paramPos, i, '\0');
  324. }
  325. default:
  326. {
  327. continue;
  328. }
  329. }
  330. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  331. {
  332. stringPos++;
  333. }
  334. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  335. {
  336. stringPos++;
  337. }
  338. paramPos++;
  339. }
  340. do
  341. {
  342. if ((delim = format[formatPos++]) > ' ')
  343. {
  344. if (delim == '\'')
  345. {
  346. while ((delim = format[formatPos++]) && delim != '\'') {}
  347. }
  348. else if (delim != 'z')
  349. {
  350. return delim;
  351. }
  352. }
  353. }
  354. while (delim > ' ');
  355. return 0;
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement