Advertisement
Papadopolis

phpbbForumIntegration 0.3

Mar 10th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.46 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. #define LANG_LOG_BAN_USER               "[FÓRUM] Moderador %s baniu o usuário '%s' com a razão: '%s'"
  25. #define LANG_LOG_BAN_IP                 "[FÓRUM] Moderador %s baniu o IP '%s' com a razão: '%s'"
  26. #define LANG_LOG_UNBAN_USER             "[FÓRUM] Moderador %s desbaniu o usuário '%s'"
  27. #define LANG_LOG_DELETE_POST            "[FÓRUM] Moderador %s deletou o post '%s' criado por '%s' na sessão '%s'"
  28. #define LANG_LOG_DELETE_SHADOW_TOPIC    "[FÓRUM] Moderador %s deletou o tópico fantasma '%s' na sessão '%s'"
  29. #define LANG_LOG_DELETE_TOPIC           "[FÓRUM] Moderador %s deletou o tópico '%s' criado por '%s' na sessão '%s'"
  30. #define LANG_LOG_LOCK                   "[FÓRUM] Moderador %s trancou o tópico '%s' na sessão '%s'"
  31. #define LANG_LOG_MERGE                  "[FÓRUM] Moderador %s juntou posts em um novo tópico '%s' na sessão '%s'"
  32. #define LANG_LOG_MOVE                   "[FÓRUM] Moderador %s moveu o tópico '%s' de '%s' para '%s'"
  33. #define LANG_LOG_POST_APPROVED          "[FÓRUM] Moderador %s aprovou o post '%s' do tópico '%s' na sessão '%s'"
  34. #define LANG_LOG_POST_DISAPPROVED       "[FÓRUM] Moderador %s desaprovou o post '%s' do tópico '%s' na sessão '%s' com a seguinte razão: '%s'"
  35. #define LANG_LOG_POST_EDITED            "[FÓRUM] Moderador %s editou o post '%s' do tópico '%s' '%s' escrito por '%s'"
  36. #define LANG_LOG_REPORT_CLOSED          "[FÓRUM] Moderador %s fechou a denúncia '%s' na sessão '%s'"
  37. #define LANG_LOG_TOPIC_APPROVED         "[FÓRUM] Moderador %s aprovou o tópico %s na sessão '%s'"
  38. #define LANG_LOG_TOPIC_DISAPPROVED      "[FÓRUM] Moderador %s desaprovou o tópico '%s' na sessão '%s' com a seguinte razão: %s"
  39. #define LANG_LOG_UNLOCK                 "[FÓRUM] Moderador %s destrancou o tópico '%s' na sessão '%s'"
  40. #define LANG_LOG_USER_WARNING           "[FÓRUM] Moderador %s deu uma advertência ao usuário %s"
  41. #define LANG_LOG_USER_LOCK              "[FÓRUM] Usuário %s trancou seu próprio tópico '%s'"
  42. #define LANG_LOG_BAN_EXCLUDE_USER       "[FÓRUM] Moderador %s retirou o usuário '%s' da lista de banidos com a razão: %s"
  43.  
  44. // English
  45. //#define LANG_SERVER_MESSAGE "[FORUM] %s answer at '%s' topic. Forum session: %s."
  46. //#define LANG_LOG_BAN_USER                 "[FORUM] Moderator %s banned user '%s' for reason: '%s'"
  47. //#define LANG_LOG_BAN_IP               "[FORUM] Moderator %s banned IP '%s' for reason: '%s'"
  48. //#define LANG_LOG_UNBAN_USER           "[FORUM] Moderator %s unbanned user '%s'"
  49. //#define LANG_LOG_DELETE_POST          "[FORUM] Moderator %s deleted post '%s' written by '%s' at session '%s'"
  50. //#define LANG_LOG_DELETE_SHADOW_TOPIC  "[FORUM] Moderator %s deleted shadow topic '%s' at session '%s'"
  51. //#define LANG_LOG_DELETE_TOPIC             "[FORUM] Moderator %s deleted topic '%s' written by '%s' at session '%s'"
  52. //#define LANG_LOG_LOCK                     "[FORUM] Moderador %s locked topic '%s' at session '%s'"
  53. //#define LANG_LOG_MERGE                    "[FORUM] Moderator %s merged posts into topic '%s' at session '%s'"
  54. //#define LANG_LOG_MOVE                     "[FORUM] Moderator %s moved topic '%s' from '%s' to '%s'"
  55. //#define LANG_LOG_POST_APPROVED            "[FORUM] Moderator %s approved post '%s' in topic '%s' at session '%s'"
  56. //#define LANG_LOG_POST_DISAPPROVED         "[FORUM] Moderator %s disapproved post '%s' in topic '%s' at session '%s' with the following reason: '%s'"
  57. //#define LANG_LOG_POST_EDITED          "[FORUM] Moderator %s edited post '%s' in topic '%s' at session '%s' written by '%s'"
  58. //#define LANG_LOG_REPORT_CLOSED            "[FORUM] Moderator %s closed report '%s' at session '%s'"
  59. //#define LANG_LOG_TOPIC_APPROVED       "[FORUM] Moderator %s approved topic %s at session '%s'"
  60. //#define LANG_LOG_TOPIC_DISAPPROVED        "[FORUM] Moderator %s disapproved topic %s at session '%s' with the following reason: %s"
  61. //#define LANG_LOG_UNLOCK               "[FORUM] Moderator %s unlocked topic '%s' at session '%s'"
  62. //#define LANG_LOG_USER_WARNING             "[FORUM] Moderator %s added warning to user %s"
  63. //#define LANG_LOG_USER_LOCK                "[FORUM] User %s locked own topic %s"
  64. //#define LANG_LOG_BAN_EXCLUDE_USER         "[FORUM] Moderator %s excluded user '%s' from ban for reason: %s"
  65. /** </CHANGE IT> **/
  66.  
  67. #include <a_samp>
  68. #include <a_mysql>
  69.  
  70. new
  71.     lastPostId,
  72.     lastAdminActionId,
  73.     dbConnectionHandle
  74. ;
  75.  
  76. forward MySqlConnect();
  77. forward checkNewPosts();
  78. forward getLastPostId();
  79. forward checkUpdates();
  80. forward checkAdminActions();
  81. forward getLastAdminActionId();
  82. forward initChecks();
  83.  
  84. public OnFilterScriptInit()
  85. {
  86.     print("\n--------------------------------------");
  87.     print(" in-game phpbb integration by Mandrakke ");
  88.     print(" Version 0.3 keep updated in: http://forum.sa-mp.com/showthread.php?p=2855241");
  89.     print("--------------------------------------\n");
  90.  
  91.     MySqlConnect();
  92.  
  93.     SetTimer("initChecks", 5000, false);
  94.  
  95.     return 1;
  96. }
  97.  
  98. public OnFilterScriptExit()
  99. {
  100.     return 1;
  101. }
  102.  
  103. public initChecks() {
  104.     getLastPostId();
  105.     getLastAdminActionId();
  106.  
  107.     SetTimer("checkUpdates", 3000, true);
  108. }
  109.  
  110. public checkUpdates() {
  111.     checkNewPosts();
  112.     checkAdminActions();
  113. }
  114.  
  115. public checkNewPosts() {
  116.     new Query[512];
  117.  
  118.     mysql_format(dbConnectionHandle, 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",
  119.         MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, lastPostId
  120.     );
  121.  
  122.     mysql_pquery(dbConnectionHandle, Query, "checkNewPosts_Callback", "");
  123.  
  124.     return 1;
  125. }
  126.  
  127. forward checkNewPosts_Callback();
  128. public checkNewPosts_Callback() {
  129.     new rows, row, fields, username[64], forum_name[64], topic_title[64], serverMessage[256], post_id;
  130.    
  131.     cache_get_data(rows, fields);
  132.  
  133.     if(rows > 0) {
  134.         while(row < rows) {
  135.             cache_get_field_content(row, "username", username);
  136.             cache_get_field_content(row, "forum_name", forum_name);
  137.             cache_get_field_content(row, "topic_title", topic_title);
  138.             post_id = cache_get_field_content_int(row, "post_id");
  139.  
  140.             format(serverMessage, sizeof(serverMessage), LANG_SERVER_MESSAGE, username, topic_title, forum_name);
  141.             SendClientMessageToAll(0x00FF0000, serverMessage);
  142.  
  143.             if(post_id > lastPostId) {
  144.                 lastPostId = post_id;
  145.             }
  146.            
  147.             ++row;
  148.         }
  149.     }
  150.  
  151.     return 1;
  152. }
  153.  
  154. public checkAdminActions() {
  155.     new Query[512];
  156.  
  157.     mysql_format(dbConnectionHandle, Query, sizeof(Query), "SELECT u.username, f.forum_name, t.topic_title, l.log_operation, l.log_data, l.log_id FROM %slog l join %stopics t on t.topic_id = l.topic_id join %sforums f on f.forum_id = l.forum_id join %susers u on u.user_id = l.user_id where l.log_type = 1 and l.log_id > %d order by l.log_time desc limit 0,10",
  158.         MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, lastAdminActionId
  159.     );
  160.  
  161.     mysql_pquery(dbConnectionHandle, Query, "checkAdminActions_Callback", "");
  162. }
  163.  
  164. forward checkAdminActions_Callback();
  165. public checkAdminActions_Callback() {
  166.     new rows, row, fields, serverMessage[256], username[64], forum_name[64], topic_title[64], log_operation[32], log_data[128], log_id, log_data_explode[7][64], log_data_info1[64], log_data_info2[64];
  167.  
  168.     cache_get_data(rows, fields);
  169.  
  170.     if(rows > 0) {
  171.         while(row < rows) {
  172.             cache_get_field_content(row, "username", username);
  173.             cache_get_field_content(row, "forum_name", forum_name);
  174.             cache_get_field_content(row, "topic_title", topic_title);
  175.             cache_get_field_content(row, "log_operation", log_operation);
  176.             cache_get_field_content(row, "log_data", log_data);
  177.             log_id = cache_get_field_content_int(row, "log_id");
  178.  
  179.             explode(log_data_explode, log_data, "\"");
  180.  
  181.             format(log_data_info1, sizeof(log_data_info1), "%s", log_data_explode[1]);
  182.             format(log_data_info2, sizeof(log_data_info2), "%s", log_data_explode[3]);
  183.  
  184.             if(strcmp(log_operation, "LOG_BAN_EXCLUDE_USER", true) == 0) {
  185.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_BAN_EXCLUDE_USER, username, log_data_info1, log_data_info2);
  186.             } else if(strcmp(log_operation, "LOG_BAN_USER", true) == 0) {
  187.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_BAN_USER, username, log_data_info1, log_data_info2);
  188.             } else if(strcmp(log_operation, "LOG_BAN_IP", true) == 0) {
  189.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_BAN_IP, username, log_data_info2, log_data_info1);
  190.             } else if(strcmp(log_operation, "LOG_UNBAN_USER", true) == 0) {
  191.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_UNBAN_USER, username, log_data_info1);
  192.             } else if(strcmp(log_operation, "LOG_DELETE_POST", true) == 0) {
  193.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_DELETE_POST, username, log_data_info1, log_data_info2, forum_name);
  194.             } else if(strcmp(log_operation, "LOG_DELETE_SHADOW_TOPIC", true) == 0) {
  195.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_DELETE_SHADOW_TOPIC, username, log_data_info1, forum_name);
  196.             } else if(strcmp(log_operation, "LOG_DELETE_TOPIC", true) == 0) {
  197.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_DELETE_TOPIC, username, log_data_info1, forum_name);
  198.             } else if(strcmp(log_operation, "LOG_LOCK", true) == 0 || strcmp(log_operation, "LOG_LOCK_POST", true) == 0) {
  199.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_LOCK, username, topic_title, forum_name);
  200.             } else if(strcmp(log_operation, "LOG_MERGE", true) == 0) {
  201.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_MERGE, username, topic_title);
  202.             } else if(strcmp(log_operation, "LOG_MOVE", true) == 0) {
  203.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_MOVE, username, topic_title, log_data_info1, log_data_info2);
  204.             } else if(strcmp(log_operation, "LOG_POST_APPROVED", true) == 0) {
  205.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_POST_APPROVED, username, log_data_info1, topic_title, forum_name);
  206.             } else if(strcmp(log_operation, "LOG_POST_DISAPPROVED", true) == 0) {
  207.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_POST_DISAPPROVED, username, log_data_info1, topic_title, forum_name, log_data_info2);
  208.             } else if(strcmp(log_operation, "LOG_POST_EDITED", true) == 0) {
  209.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_POST_EDITED, username, log_data_info1, topic_title, forum_name, log_data_info2);
  210.             } else if(strcmp(log_operation, "LOG_REPORT_CLOSED", true) == 0) {
  211.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_REPORT_CLOSED, username, log_data_info1, forum_name);
  212.             } else if(strcmp(log_operation, "LOG_TOPIC_APPROVED", true) == 0) {
  213.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_TOPIC_APPROVED, username, log_data_info1);
  214.             } else if(strcmp(log_operation, "LOG_TOPIC_DISAPPROVED", true) == 0) {
  215.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_TOPIC_DISAPPROVED, username, log_data_info1, forum_name, log_data_info2);
  216.             } else if(strcmp(log_operation, "LOG_UNLOCK", true) == 0) {
  217.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_UNLOCK, username, log_data_info1, forum_name);
  218.             } else if(strcmp(log_operation, "LOG_USER_WARNING", true) == 0) {
  219.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_USER_WARNING, username, log_data_info1);
  220.             } else if(strcmp(log_operation, "LOG_USER_LOCK", true) == 0) {
  221.                 format(serverMessage, sizeof(serverMessage), LANG_LOG_USER_LOCK, username, log_data_info1);
  222.             }
  223.  
  224.             if(strlen(serverMessage) > 0) {
  225.                 format(serverMessage, sizeof(serverMessage), "%s", serverMessage);
  226.                 SendClientMessageToAll(0x00FF0000, serverMessage);
  227.             }
  228.  
  229.             if(log_id > lastAdminActionId) {
  230.                 lastAdminActionId = log_id;
  231.             }
  232.         }
  233.     }
  234.  
  235.     return 1;
  236. }
  237.  
  238. public getLastPostId() {
  239.     new Query[128], post_id[64];
  240.  
  241.     mysql_format(dbConnectionHandle, Query, sizeof(Query), "select p.post_id from %sposts p order by p.post_time desc limit 0,1", MYSQL_FORUMTABLE_PREFIX);
  242.     new Cache:mysqlFetch = mysql_query(dbConnectionHandle, Query);
  243.  
  244.     if(cache_num_rows() > 0) {
  245.         cache_get_field_content(0, "post_id", post_id);
  246.     }
  247.  
  248.     cache_delete(mysqlFetch);
  249.  
  250.     lastPostId = strval(post_id);
  251. }
  252.  
  253. public getLastAdminActionId() {
  254.     new Query[128], log_id[64];
  255.  
  256.     mysql_format(dbConnectionHandle, Query, sizeof(Query), "select l.log_id from %slog l order by l.log_time desc limit 0,1", MYSQL_FORUMTABLE_PREFIX);
  257.     new Cache:mysqlFetch = mysql_query(dbConnectionHandle, Query);
  258.  
  259.     if(cache_num_rows() > 0) {
  260.         cache_get_field_content(0, "log_id", log_id);
  261.     }
  262.  
  263.     cache_delete(mysqlFetch);
  264.    
  265.     lastAdminActionId = strval(log_id);
  266. }
  267.  
  268. public MySqlConnect() {
  269.     mysql_debug(1);
  270.     dbConnectionHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
  271. }
  272.  
  273. public OnQueryError(errorid, error[], callback[], query[], connectionHandle) {
  274.     new Query[128];
  275.  
  276.     if(errorid!=1060 && errorid!=1062){
  277.         new hour,second,minute;
  278.         gettime(hour,minute,second);
  279.         new File:log=fopen("mysql_errors.txt",io_append);
  280.         format(Query,sizeof(Query),"[%d:%d:%d] Query: %s Erro: %d (%s)\r\n",hour,minute,second,query,errorid,error);
  281.         fwrite(log,Query);
  282.         fclose(log);
  283.     }
  284.  
  285.     return 0;
  286. }
  287.  
  288. stock explode(aExplode[][], const sSource[], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]){
  289.     new
  290.         iNode,
  291.         iPointer,
  292.         iPrevious = -1,
  293.         iDelimiter = strlen(sDelimiter);
  294.  
  295.     while(iNode < iVertices){
  296.         iPointer = strfind(sSource, sDelimiter, false, iPointer);
  297.  
  298.         if(iPointer == -1){
  299.             strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
  300.             break;
  301.         }
  302.         else {
  303.             strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
  304.         }
  305.  
  306.         iPrevious = (iPointer += iDelimiter);
  307.         ++iNode;
  308.     }
  309.     return iPrevious;
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement