Guest User

Untitled

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