Advertisement
Papadopolis

phpbbForumIntegration 0.1

Jan 7th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.92 KB | None | 0 0
  1. /**
  2.     Notes:
  3.         [EN-UK]
  4.             - Unfortunately we can't beautify SQL inside strings, they accept only in-line codes.
  5.             - You're allowed to copy this filterscript without keeping my credits if you want so.
  6.             - THIS FILTERSCRIPT NEEDS BLUEG'S MYSQL PLUGIN TO WORK.
  7.             - If this filterscript doesn't work somehow, see mysql_error.txt file inside your server's scriptfiles directory.
  8.  
  9.         [PT-BR]
  10.             - Código completamente livre para ser copiado sem que seja mantido os créditos, afinal, não há como impedir BRs de BRear.
  11.             - Caso esta filterscript não funcione veja o log no arquivo mysql_error.txt dentro da pasta scriptfiles do servidor.
  12.             - Este filterscript precisa do MySQL plugin (por BlueG) para rodar.
  13. **/
  14.  
  15. /** <CHANGEIT> **/
  16. #define MYSQL_HOST  "" // MySQL IP host / IP do servidor MySQL
  17. #define MYSQL_USER  "" // MySQL username / Usuário MySQL
  18. #define MYSQL_PASS  "" // MySQL password / Senha MySQL
  19. #define MYSQL_DB    "" // MySQL database / Banco de dados MySQL
  20. #define MYSQL_FORUMTABLE_PREFIX "" // PhpBB table prefix / Prefixo das tabelas PhpBB
  21.  
  22. // Portuguese
  23. #define LANG_SERVER_MESSAGE "[FÓRUM] %s respondeu no tópico '%s'. Sessão: %s."
  24.  
  25. // English
  26. //#define LANG_SERVER_MESSAGE "[FORUM] %s answer at '%s' topic. Forum session: %s."
  27. /** </CHANGE IT> **/
  28.  
  29. #include <a_samp>
  30. #include <a_mysql>
  31.  
  32. new
  33.     lastPostId
  34. ;
  35.  
  36. forward MySqlConnect();
  37. forward checkNewPosts();
  38. forward getLastPostId();
  39.  
  40. public OnFilterScriptInit()
  41. {
  42.     print("\n--------------------------------------");
  43.     print(" in-game phpbb integration by Mandrakke ");
  44.     print(" Version 0.1 keep updated in: http://forum.sa-mp.com/showthread.php?t=486271");
  45.     print("--------------------------------------\n");
  46.  
  47.     MySqlConnect();
  48.  
  49.     lastPostId = getLastPostId();
  50.  
  51.     SetTimer("checkNewPosts", 5000, true);
  52.  
  53.     return 1;
  54. }
  55.  
  56. public OnFilterScriptExit()
  57. {
  58.     return 1;
  59. }
  60.  
  61. public checkNewPosts() {
  62.     new Query[512], username[64], forum_name[64], topic_title[64], serverMessage[256], post_idStr[64], post_id;
  63.  
  64.     format(Query, sizeof(Query), "select u.username, t.topic_title, f.forum_name, p.post_id from %sposts p  join %susers u on p.poster_id = u.user_id join %stopics t on t.topic_id = p.topic_id join %sforums f on f.forum_id = p.forum_id where p.post_id > %d order by p.post_time desc limit 0,10",
  65.         MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, lastPostId
  66.     );
  67.  
  68.     mysql_query(Query);
  69.     mysql_store_result();
  70.  
  71.     if(mysql_num_rows() > 0) {
  72.         while(mysql_retrieve_row()) {
  73.             mysql_fetch_field_row(username, "username");
  74.             mysql_fetch_field_row(forum_name, "forum_name");
  75.             mysql_fetch_field_row(topic_title, "topic_title");
  76.             mysql_fetch_field_row(post_idStr, "post_id"); post_id = strval(post_idStr);
  77.  
  78.             format(serverMessage, sizeof(serverMessage), LANG_SERVER_MESSAGE, username, topic_title, forum_name);
  79.             SendClientMessageToAll(0x00FF0000, serverMessage);
  80.  
  81.             if(post_id > lastPostId) {
  82.                 lastPostId = post_id;
  83.             }
  84.         }
  85.     }
  86.  
  87.     mysql_free_result();
  88.  
  89.     return 1;
  90. }
  91.  
  92. public getLastPostId() {
  93.     new Query[128], post_id[64];
  94.  
  95.     format(Query, sizeof(Query), "select p.post_id from %sposts p order by p.post_time desc limit 0,1", MYSQL_FORUMTABLE_PREFIX);
  96.     mysql_query(Query);
  97.     mysql_store_result();
  98.  
  99.     if(mysql_retrieve_row()) {
  100.         mysql_fetch_field_row(post_id, "post_id");
  101.     }
  102.  
  103.     mysql_free_result();
  104.  
  105.     return strval(post_id);
  106. }
  107.  
  108. public MySqlConnect() {
  109.     mysql_debug(0);
  110.     mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
  111. }
  112.  
  113. public OnQueryError( errorid, error[], resultid, extraid, callback[], query[], connectionHandle ) {
  114.     new Query[128];
  115.  
  116.     if(errorid!=1060 && errorid!=1062){
  117.         new hour,second,minute;
  118.         gettime(hour,minute,second);
  119.         new File:log=fopen("mysql_errors.txt",io_append);
  120.         format(Query,sizeof(Query),"[%d:%d:%d] Query: %s Erro: %d (%s)\r\n",hour,minute,second,query,errorid,error);
  121.         fwrite(log,Query);
  122.         fclose(log);
  123.     }
  124.  
  125.     return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement