Guest User

player_data

a guest
Dec 6th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include < amxmodx >
  2. #include < sqlx >
  3.  
  4. #define TABLE_NAME "player_info"
  5.  
  6. /* Database */
  7. new Host[] = ""
  8. new User[] = ""
  9. new Pass[] = ""
  10. new Db[] = ""
  11.  
  12. new MySQL_Query[ 512 ]
  13. new Handle:MySQL_Tuple
  14. new Handle:MySQL_Connection
  15.  
  16. public plugin_init( ) {
  17. register_plugin( "PlayerInfo", "v1", "???" )
  18. }
  19.  
  20. public client_putinserver( id )
  21. {
  22. MySQL_Load(id);
  23. }
  24.  
  25. public plugin_precache( )
  26. {
  27. MySQL_Tuple = SQL_MakeDbTuple( Host, User, Pass, Db )
  28. #if AMXX_VERSION_NUM >= 183
  29. SQL_SetCharset(MySQL_Tuple,"utf8");
  30. #endif
  31.  
  32. new ErrorCode
  33. MySQL_Connection = SQL_Connect( MySQL_Tuple, ErrorCode, MySQL_Query, charsmax( MySQL_Query ) )
  34.  
  35. if( MySQL_Connection == Empty_Handle )
  36. set_fail_state( MySQL_Query )
  37. formatex( MySQL_Query, charsmax( MySQL_Query ), "CREATE TABLE IF NOT EXISTS %s (id int NOT NULL AUTO_INCREMENT, username VARCHAR(128), steam_id VARCHAR(20), ip_adress VARCHAR(15), date DATE, time TIME, primary key (id) )", TABLE_NAME )
  38.  
  39. SQL_ThreadQuery( MySQL_Tuple, "SQL_TrashHandler", MySQL_Query )
  40. }
  41.  
  42. public MySQL_Load( id )
  43. {
  44. new szAuth[32];
  45. get_user_authid(id, szAuth, 31);
  46.  
  47. new Temp[ 1 ]
  48. Temp[ 0 ] = id
  49.  
  50. formatex( MySQL_Query, charsmax( MySQL_Query ), "SELECT `steam_id` FROM %s WHERE `steam_id` = '%s'", TABLE_NAME, szAuth )
  51. SQL_ThreadQuery( MySQL_Tuple, "Load_PlayerInfo", MySQL_Query, Temp, sizeof( Temp ) )
  52. }
  53.  
  54. public Load_PlayerInfo( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
  55. {
  56. if( FailState == TQUERY_CONNECT_FAILED ) { return PLUGIN_HANDLED; }
  57. else if( FailState == TQUERY_QUERY_FAILED ) { return PLUGIN_HANDLED; }
  58.  
  59. new id = Data[ 0 ]
  60.  
  61. if( !is_user_connected( id ) )
  62. return PLUGIN_HANDLED;
  63.  
  64. new szAuth[32], szName[32], szIP[23], currentTime[9], currentDate[11];
  65. get_user_authid(id, szAuth, 31);
  66. get_user_name(id, szName, 31);
  67. get_user_ip(id, szIP, 22, 1);
  68. get_time("%H:%M:%S", currentTime, 8)
  69. get_time("%Y/%m/%d", currentDate, 10)
  70.  
  71. if( SQL_NumResults( Query ) < 1 )
  72. {
  73. formatex( MySQL_Query, charsmax( MySQL_Query ), "INSERT INTO %s (`username`, `steam_id`, `ip_adress`, `date`, `time`) VALUES ('%s', '%s', '%s', '%s', '%s')", TABLE_NAME, szName, szAuth, szIP, currentDate, currentTime )
  74. SQL_ThreadQuery( MySQL_Tuple, "SQL_TrashHandler", MySQL_Query )
  75. }
  76. else {
  77. formatex( MySQL_Query, charsmax( MySQL_Query ), "UPDATE %s SET `date` = '%s', `time` = '%s' WHERE `steam_id` = '%s'", TABLE_NAME, currentDate, currentTime, szAuth )
  78. SQL_ThreadQuery( MySQL_Tuple, "SQL_TrashHandler", MySQL_Query )
  79. }
  80. return PLUGIN_CONTINUE;
  81. }
  82.  
  83. public SQL_TrashHandler( FailState,Handle:Query, Error[ ], Errcode,Data[ ], DataSize )
  84. {
  85. if( FailState == TQUERY_CONNECT_FAILED )
  86. return PLUGIN_HANDLED;
  87.  
  88. else if( FailState == TQUERY_QUERY_FAILED )
  89. return PLUGIN_HANDLED;
  90.  
  91. SQL_FreeHandle( Query )
  92. return PLUGIN_CONTINUE;
  93. }
  94.  
  95. public plugin_end( )
  96. {
  97. SQL_FreeHandle( MySQL_Connection )
  98. }
Add Comment
Please, Sign In to add comment