Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Notes:
- [EN-UK]
- - Unfortunately we can't beautify SQL inside strings, they accept only in-line codes.
- - You're allowed to copy this filterscript without keeping my credits if you want so.
- - THIS FILTERSCRIPT NEEDS BLUEG'S MYSQL PLUGIN TO WORK.
- - If this filterscript doesn't work somehow, see mysql_error.txt file inside your server's scriptfiles directory.
- [PT-BR]
- - Código completamente livre para ser copiado sem que seja mantido os créditos, afinal, não há como impedir BRs de BRear.
- - Caso esta filterscript não funcione veja o log no arquivo mysql_error.txt dentro da pasta scriptfiles do servidor.
- - Este filterscript precisa do MySQL plugin (por BlueG) para rodar.
- **/
- /** <CHANGEIT> **/
- #define MYSQL_HOST "" // MySQL IP host / IP do servidor MySQL
- #define MYSQL_USER "" // MySQL username / Usuário MySQL
- #define MYSQL_PASS "" // MySQL password / Senha MySQL
- #define MYSQL_DB "" // MySQL database / Banco de dados MySQL
- #define MYSQL_FORUMTABLE_PREFIX "" // PhpBB table prefix / Prefixo das tabelas PhpBB
- // Portuguese
- #define LANG_SERVER_MESSAGE "[FÓRUM] %s respondeu no tópico '%s'. Sessão: %s."
- // English
- //#define LANG_SERVER_MESSAGE "[FORUM] %s answer at '%s' topic. Forum session: %s."
- /** </CHANGE IT> **/
- #include <a_samp>
- #include <a_mysql>
- new
- lastPostId
- ;
- forward MySqlConnect();
- forward checkNewPosts();
- forward getLastPostId();
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" in-game phpbb integration by Mandrakke ");
- print(" Version 0.1 keep updated in: http://forum.sa-mp.com/showthread.php?t=486271");
- print("--------------------------------------\n");
- MySqlConnect();
- lastPostId = getLastPostId();
- SetTimer("checkNewPosts", 5000, true);
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public checkNewPosts() {
- new Query[512], username[64], forum_name[64], topic_title[64], serverMessage[256], post_idStr[64], post_id;
- 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",
- MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, MYSQL_FORUMTABLE_PREFIX, lastPostId
- );
- mysql_query(Query);
- mysql_store_result();
- if(mysql_num_rows() > 0) {
- while(mysql_retrieve_row()) {
- mysql_fetch_field_row(username, "username");
- mysql_fetch_field_row(forum_name, "forum_name");
- mysql_fetch_field_row(topic_title, "topic_title");
- mysql_fetch_field_row(post_idStr, "post_id"); post_id = strval(post_idStr);
- format(serverMessage, sizeof(serverMessage), LANG_SERVER_MESSAGE, username, topic_title, forum_name);
- SendClientMessageToAll(0x00FF0000, serverMessage);
- if(post_id > lastPostId) {
- lastPostId = post_id;
- }
- }
- }
- mysql_free_result();
- return 1;
- }
- public getLastPostId() {
- new Query[128], post_id[64];
- format(Query, sizeof(Query), "select p.post_id from %sposts p order by p.post_time desc limit 0,1", MYSQL_FORUMTABLE_PREFIX);
- mysql_query(Query);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- mysql_fetch_field_row(post_id, "post_id");
- }
- mysql_free_result();
- return strval(post_id);
- }
- public MySqlConnect() {
- mysql_debug(0);
- mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
- }
- public OnQueryError( errorid, error[], resultid, extraid, callback[], query[], connectionHandle ) {
- new Query[128];
- if(errorid!=1060 && errorid!=1062){
- new hour,second,minute;
- gettime(hour,minute,second);
- new File:log=fopen("mysql_errors.txt",io_append);
- format(Query,sizeof(Query),"[%d:%d:%d] Query: %s Erro: %d (%s)\r\n",hour,minute,second,query,errorid,error);
- fwrite(log,Query);
- fclose(log);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement