Guest User

Untitled

a guest
Apr 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.60 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <hamsandwich>
  4. #include <fakemeta>
  5. #include <sqlx>
  6.  
  7. #define PLUGIN "Creacion cuenta + pw"
  8. #define VERSION "1.2"
  9. #define AUTHOR ";SoNNy"
  10. #define AUTO_TEAM_JOIN_DELAY 0.1
  11.  
  12. #define DisabledChoiseMenu
  13.  
  14. new Connected[33]
  15. new cvar_password_prefijo
  16.  
  17. /*================================================================================
  18. [MySQLx Vars, other]
  19. =================================================================================*/
  20. new Handle:g_hTuple;
  21. new LogeadoUSR[33];
  22. new passwordSQl[33];
  23. new NickSQL[33];
  24. new passwordNEW[32]
  25. new mysqlx_host, mysqlx_user, mysqlx_db, mysqlx_pass;
  26.  
  27. /*================================================================================
  28. [Iniciacion Plugin]
  29. =================================================================================*/
  30. public plugin_init()
  31. {
  32. register_plugin(PLUGIN, VERSION, AUTHOR)
  33.  
  34. // Comandos en say
  35. register_clcmd("ingresar_password", "LoadCuenta")
  36. register_clcmd("_password", "crear_cuenta")
  37. register_message(get_user_msgid("ShowMenu"), "message_show_menu")
  38.  
  39. #if defined DisabledChoiseMenu
  40. register_clcmd("jointeam","cmdtopin")
  41. register_clcmd("chooseteam","cmdtopin")
  42. #endif
  43.  
  44. // PCVARS
  45. cvar_password_prefijo = register_cvar("account_password_prefijo", "_twbpw")
  46.  
  47. // Event
  48. register_forward( FM_ClientUserInfoChanged, "FWClientUserInfoChanged" )
  49. //register_event("TeamInfo", "HookJoinTeam", "a", "2!UNASSIGNED")
  50.  
  51. /*=================================================================================*/
  52. // SQLx cvars
  53. mysqlx_host = register_cvar ("gxm_host", "127.0.0.1");
  54. mysqlx_user = register_cvar ("gxm_user", "wamp");
  55. mysqlx_pass = register_cvar ("gxm_pass", "123456");
  56. mysqlx_db = register_cvar ("gxm_dbname", "xp");
  57. /*=================================================================================*/
  58. MySQLx_Init()
  59.  
  60. }
  61. /*=================================================================================*/
  62. #if defined DisabledChoiseMenu
  63. public cmdtopin(id)
  64. {
  65. static Team;
  66. Team = get_user_team(id)
  67.  
  68. if (Team == 3 || Team == 4)
  69. return PLUGIN_HANDLED;
  70.  
  71. if (LogeadoUSR[id])
  72. return PLUGIN_CONTINUE;
  73.  
  74. HookJoinTeam(id);
  75.  
  76. return PLUGIN_HANDLED_MAIN;
  77. }
  78. #endif
  79.  
  80. /*=================================================================================*/
  81. public client_putinserver(id)
  82. {
  83. LogeadoUSR[id] = 0;
  84. Connected[id] = 0
  85. passwordSQl[id] = 0;
  86. set_task(0.1, "cmdtopin", id)
  87. }
  88. public client_connect(id)
  89. {
  90. LogeadoUSR[id] = 0;
  91. Connected[id] = 0
  92. passwordSQl[id] = 0;
  93.  
  94. }
  95. /*=================================================================================*/
  96. public client_disconnect(id)
  97. {
  98. Connected[id] = 0
  99. }
  100. /*=================================================================================*/
  101. public FWClientUserInfoChanged( Index, Buffer )
  102. {
  103. if( !is_user_connected( Index ) )
  104. return FMRES_IGNORED;
  105.  
  106. static NickName[32], NickOld[32]; get_user_name( Index, NickOld, 31 )
  107. engfunc( EngFunc_InfoKeyValue, Buffer, "name", NickName, 31 ) // Si tampoco me confundo, esto obtiene el valor "name" de su setinfo.
  108.  
  109. if( equal( NickName, NickOld ) )
  110. return FMRES_IGNORED;
  111.  
  112. engfunc( EngFunc_SetClientKeyValue, Index, Buffer, "name", NickOld ) // Le volvemos a poner el nick viejo para que no se lo pueda cambiar.
  113.  
  114. client_cmd( Index, "name ^"%s^"; setinfo name ^"%s^"", NickOld, NickOld )
  115.  
  116. return FMRES_SUPERCEDE;
  117. }
  118. /*================================================================================
  119. [MENU Join]
  120. =================================================================================*/
  121. public HookJoinTeam(id)
  122. {
  123.  
  124. if(!is_user_connected(id))
  125. return FMRES_IGNORED
  126.  
  127. switch(CheckCuentaMenu(id))
  128. {
  129. case 0..3:
  130. {
  131. if(!Connected[id])
  132. {
  133. new Menu = menu_create("\yMenu de Login/Registro", "showMenuLoginReg")
  134. menu_additem(Menu, "\wloguearse" , "1", 0)
  135. menu_additem(Menu, "\wRegistrar Nueva Cuenta" , "2", 0)
  136.  
  137. menu_setprop(Menu,MPROP_EXITNAME,"Salir")
  138. menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL)
  139.  
  140. menu_display(id, Menu, 0)
  141. }
  142. }
  143. }
  144.  
  145. return PLUGIN_HANDLED
  146. }
  147. /*=================================================================================*/
  148. public showMenuLoginReg(id, Menu, item)
  149. {
  150. if (item == MENU_EXIT)
  151. {
  152. menu_destroy(Menu)
  153. return PLUGIN_HANDLED
  154. }
  155.  
  156. new iData[6];
  157. new iAccess;
  158. new iCallback;
  159. new iName[64];
  160. menu_item_getinfo(Menu, item, iAccess, iData, 5, iName, 63, iCallback)
  161.  
  162. switch (str_to_num(iData))
  163. {
  164. case 1:
  165. {
  166. client_cmd(id, "messagemode Ingresa_la_Contraseña");
  167. }
  168. case 2:
  169. {
  170. client_cmd(id, "messagemode Ingresa_la_Contraseña");
  171. }
  172. }
  173.  
  174. return PLUGIN_HANDLED
  175. }
  176.  
  177. /*================================================================================
  178. [Func Login y Create Cuenta]
  179. =================================================================================*/
  180. public crear_cuenta(id)
  181. {
  182. if(!is_user_connected(id))
  183. return PLUGIN_HANDLED
  184.  
  185. new say[300]
  186. // Obtenemos en un string lo que escribio como password
  187. read_args(say, charsmax(say))
  188. // Lo preparamos para analizar
  189. remove_quotes(say), trim(say)
  190. // Si solamente apreto enter lo omitiremos
  191. if(equal(say, ""))
  192. return PLUGIN_HANDLED
  193. // Verificamos que la password solo contenga una palabra
  194. if(contain(say, " ") != -1)
  195. {
  196. ChatColor(id, "!g[SYSACC]!y La contraseña no debe contener espacios")
  197. return PLUGIN_HANDLED
  198. }
  199.  
  200. copy(passwordSQl[id], charsmax(passwordSQl), say)
  201.  
  202. // Guardamos el nick en la variable 'name'
  203. get_user_name(id, NickSQL[id], charsmax(NickSQL))
  204.  
  205.  
  206. static szQuery[ 128 ], iData[ 1 ];
  207. new zwname[33]
  208. get_user_name(id,zwname,charsmax(zwname))
  209.  
  210. formatex( szQuery, 127, "SELECT `nick`, `password` FROM `account` WHERE ( `nick` = '%s' );", zwname );
  211.  
  212. iData[ 0 ] = id;
  213. SQL_ThreadQuery( g_hTuple, "QuerySelectData2", szQuery, iData, 1 );
  214. return PLUGIN_HANDLED
  215. }
  216.  
  217. public QuerySelectData2( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
  218. {
  219. if( iFailState == TQUERY_CONNECT_FAILED
  220. || iFailState == TQUERY_QUERY_FAILED )
  221. {
  222. log_amx( "%s", szError );
  223.  
  224. return;
  225. }
  226. else
  227. {
  228. new id = iData[ 0 ];
  229.  
  230. new prefijo[8]
  231.  
  232. if(SQL_NumResults(hQuery) < 1)
  233. {
  234. get_user_name(id, NickSQL[id], charsmax(NickSQL))
  235. SaveCuenta(id);
  236. get_pcvar_string(cvar_password_prefijo, prefijo, charsmax(prefijo))
  237. client_cmd(id, "setinfo %s %s", prefijo, passwordSQl[id])
  238. client_cmd(id, "writecfg config")
  239. ChatColor(id, "!g[SYSACC]!y Has sido registrado!. Nick: %s - Contraseña: %s", NickSQL[id], passwordSQl[id])
  240. engclient_cmd(id, "joinclass", "5");
  241. Connected[id] = 1
  242. LogeadoUSR[id] = 1;
  243. }
  244. else
  245. {
  246. ChatColor(id, "!g[SYSACC]!y El Nombre de usuario que esta intentando registrar ya existe.")
  247. }
  248. }
  249. }
  250. /*=================================================================================*/
  251.  
  252. /*=================================================================================*/
  253. CheckCuentaMenu(id)
  254. {
  255. if(!is_user_connected(id))
  256. return PLUGIN_HANDLED
  257.  
  258. if(!LogeadoUSR[id])
  259. {
  260. // Al no existir, cancelamos
  261. Connected[id] = 0;
  262. LogeadoUSR[id] = 0;
  263. return 0
  264. }
  265. if(!Connected[id])
  266. {
  267. Connected[id] = 0;
  268. LogeadoUSR[id] = 0;
  269. return 2
  270. }
  271.  
  272. return PLUGIN_HANDLED
  273. }
  274.  
  275. /*================================================================================
  276. [Auto Join]
  277. =================================================================================*/
  278. public message_show_menu(msgid, dest, id)
  279. {
  280. if(!is_user_connected(id))
  281. return PLUGIN_HANDLED
  282.  
  283. static team_select[] = "#Team_Select"
  284. static menu_text_code[sizeof team_select]
  285. get_msg_arg_string(4, menu_text_code, sizeof menu_text_code - 1)
  286. if (!equal(menu_text_code, team_select))
  287. return PLUGIN_CONTINUE
  288.  
  289. set_force_team_join_task(id, msgid)
  290.  
  291. return PLUGIN_HANDLED
  292. }
  293. /*=================================================================================*/
  294. set_force_team_join_task(id, menu_msgid)
  295. {
  296. if(!is_user_connected(id))
  297. return PLUGIN_HANDLED
  298.  
  299. static param_menu_msgid[2]
  300. param_menu_msgid[0] = menu_msgid
  301. set_task(AUTO_TEAM_JOIN_DELAY, "task_force_team_join", id, param_menu_msgid, sizeof param_menu_msgid)
  302. return PLUGIN_HANDLED;
  303. }
  304. /*=================================================================================*/
  305. public task_force_team_join(menu_msgid[], id)
  306. {
  307. if (get_user_team(id))
  308. return
  309.  
  310. force_team_join(id)
  311. }
  312.  
  313.  
  314. /*================================================================================
  315. [MySQLx]
  316. =================================================================================*/
  317. public MySQLx_Init()
  318. {
  319. new szHost[64], szUser[32], szPass[32], szDB[128];
  320.  
  321. get_pcvar_string( mysqlx_host, szHost, charsmax( szHost ) );
  322. get_pcvar_string( mysqlx_user, szUser, charsmax( szUser ) );
  323. get_pcvar_string( mysqlx_pass, szPass, charsmax( szPass ) );
  324. get_pcvar_string( mysqlx_db, szDB, charsmax( szDB ) );
  325.  
  326. g_hTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB );
  327.  
  328. }
  329. /*=================================================================================*/
  330. SaveCuenta(id)
  331. {
  332. if(!is_user_connected(id))
  333. return PLUGIN_HANDLED
  334.  
  335. static szQuery[ 128 ];
  336. formatex( szQuery, 127, "REPLACE INTO `account` (`nick`, `password`) VALUES ('%s', '%s');", NickSQL[id] , passwordSQl[id] );
  337. SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
  338.  
  339. return PLUGIN_HANDLED;
  340. }
  341. /*=================================================================================*/
  342.  
  343. public LoadCuenta(id)
  344. {
  345. if(!is_user_connected(id))
  346. return PLUGIN_HANDLED
  347.  
  348. new say[300]
  349.  
  350. read_args(say, charsmax(say))
  351. remove_quotes(say), trim(say)
  352.  
  353. if(equal(say, ""))
  354. return PLUGIN_HANDLED
  355.  
  356. if(contain(say, " ") != -1)
  357. {
  358. ChatColor(id, "!g[SYSACC]!y La contraseña no debe contener espacios.")
  359. return PLUGIN_HANDLED
  360. }
  361.  
  362. copy(passwordNEW[id], charsmax(passwordNEW), say)
  363.  
  364. static szQuery[ 128 ], iData[ 1 ];
  365. new zwname[33]
  366. get_user_name(id,zwname,charsmax(zwname))
  367.  
  368. formatex( szQuery, 127, "SELECT `nick`, `password` FROM `account` WHERE ( `nick` = '%s' );", zwname );
  369.  
  370. iData[ 0 ] = id;
  371. SQL_ThreadQuery( g_hTuple, "QuerySelectData", szQuery, iData, 1 );
  372. return PLUGIN_HANDLED
  373.  
  374. }
  375. /*=================================================================================*/
  376.  
  377. public QuerySelectData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
  378. {
  379.  
  380. if( iFailState == TQUERY_CONNECT_FAILED
  381. || iFailState == TQUERY_QUERY_FAILED )
  382. {
  383. log_amx( "%s", szError );
  384.  
  385. return PLUGIN_HANDLED;
  386. }
  387. else
  388. {
  389. new id = iData[ 0 ];
  390.  
  391. if(!is_user_connected(id))
  392. return PLUGIN_HANDLED;
  393.  
  394. new password2SQL[32];
  395. new ColPass = SQL_FieldNameToNum(hQuery, "password")
  396.  
  397. new name[32], prefijo[8]
  398. get_user_name(id, name, charsmax(name))
  399. get_pcvar_string(cvar_password_prefijo, prefijo, charsmax(prefijo))
  400.  
  401.  
  402.  
  403. if(SQL_NumResults(hQuery) > 0)
  404. {
  405. SQL_ReadResult(hQuery, ColPass, password2SQL, charsmax(password2SQL))
  406. //copy(passwordSQl[id], charsmax(passwordSQl), password2SQL)
  407.  
  408.  
  409. if(equali(password2SQL, passwordNEW[id]))
  410. {
  411. ChatColor(id, "!g[SYSACC]!y Contraseóa Aceptada. Bienvenido al servidor.")
  412. client_print(id, print_center, "Login Exitoso!")
  413. client_cmd(id, "setinfo ^"%s^" ^"%s^"",prefijo,password2SQL)
  414. client_cmd(id, "writecfg config")
  415. engclient_cmd(id, "joinclass", "5");
  416. Connected[id] = 1;
  417. LogeadoUSR[id] = 1;
  418. }
  419. else
  420. {
  421. client_cmd(id, "messagemode ingresar_password");
  422. ChatColor(id, "!g[SYSACC]!y Contraseóa Incorrecta. Escriba nuevamente su contraseóa")
  423. Connected[id] = 0;
  424. LogeadoUSR[id] = 0;
  425. HookJoinTeam(id);
  426. }
  427.  
  428. }
  429. else
  430. {
  431. // Al no existir, cancelamos
  432. ChatColor(id, "!g[SYSACC]!y La cuenta !team NO EXISTE!y Debes Registrarte!... Ingresa una Contrasenia para registrar nueva cuenta.");
  433. client_cmd(id, "messagemode _password");
  434. LogeadoUSR[id] = 0;
  435. }
  436. }
  437. return PLUGIN_HANDLED;
  438. }
  439. /*=================================================================================*/
  440. public QuerySetData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
  441. {
  442.  
  443. if( iFailState == TQUERY_CONNECT_FAILED
  444. || iFailState == TQUERY_QUERY_FAILED )
  445. {
  446. log_amx( "%s", szError );
  447. return;
  448. }
  449. }
  450.  
  451. /*================================================================================
  452. [Stocks]
  453. =================================================================================*/
  454. stock force_team_join(id)
  455. {
  456. if(!is_user_connected(id))
  457. return PLUGIN_HANDLED
  458.  
  459. static jointeam[] = "jointeam"
  460. engclient_cmd(id, jointeam, "5")
  461. HookJoinTeam(id)
  462.  
  463. return PLUGIN_HANDLED;
  464. }
  465. /*=================================================================================*/
  466. stock check_user_name(id, const name[32] = "")
  467. {
  468. new plrname[32]
  469.  
  470. if(equal(name, ""))
  471. {
  472. get_user_name(id, plrname, 31)
  473. }
  474. else
  475. {
  476. plrname = name
  477. }
  478. //load_cuentas(id)
  479. }
  480. /*=================================================================================*/
  481. stock ChatColor(const id, const input[], any:...)
  482. {
  483. new count = 1, players[32]
  484. static msg[191]
  485. vformat(msg, 190, input, 3)
  486.  
  487. replace_all(msg, 190, "!g", "^4") // Green Color
  488. replace_all(msg, 190, "!y", "^1") // Default Color
  489. replace_all(msg, 190, "!team", "^3") // Team Color
  490. replace_all(msg, 190, "!team2", "^0") // Team2 Color
  491.  
  492. if (id) players[0] = id; else get_players(players, count, "ch")
  493. {
  494. for (new i = 0; i < count; i++)
  495. {
  496. if (is_user_connected(players[i]))
  497. {
  498. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
  499. write_byte(players[i]);
  500. write_string(msg);
  501. message_end();
  502. }
  503. }
  504.  
  505. }
  506. }
  507. /*=================================================================================*/
Add Comment
Please, Sign In to add comment