Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Copyright (c) 2017 MyBB Connector Filterscript
- *
- * This program is free software: you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program.
- * If not, see <http://www.gnu.org/licenses/>.
- * Generated by Visual Studio Code 2016 - 2017.
- */
- /*
- Credits:
- XeonMaster - SA-MP Scripter
- BlueG(MySQL) - SA-MP Beta Tester
- Zeex(Zcmd) - SA-MP Scripter
- SA-MP Team - SA-MP Developer
- */
- #define FILTERSCRIPT
- // Includes:
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- #if defined MAX_PLAYERS
- #undef MAX_PLAYERS
- #define MAX_PLAYERS 100
- #endif
- // MySQL Informations:
- #define MySQL_Host "db4free.net" // MySQL Server that your server will connect to
- #define MySQL_User "yassine_sap2" // MySQL Username that server will use it to login into
- #define MySQL_Pass "yassine23" // MySQL Password of the username you entred up ^
- #define MySQL_Data "saplayground_2" // MySQL Database that your server will take informations from
- #define MySQL_Port 3307 // Port of your MySQL Server.
- static MySQL:Database;
- // Dialogs Ids:
- enum
- {
- DIALOG_MYBB_FORUM = 100,
- DIALOG_MYBB_TOPIC,
- DIALOG_MYBB_POSTR,
- DIALOG_MYBB_MESAG
- };
- // Variables:
- new
- ForumIds[10],
- ThreadIds[20],
- lastid[MAX_PLAYERS],
- Timer[MAX_PLAYERS]
- ;
- // Callbacks:
- public OnFilterScriptInit()
- {
- mysql_log(ALL);
- new MySQLOpt:Port = mysql_init_options();
- mysql_set_option(Port, SERVER_PORT, MySQL_Port);
- Database = mysql_connect(MySQL_Host, MySQL_User, MySQL_Pass, MySQL_Data, Port); // Connecting to the mysql server.
- switch(mysql_errno())
- {
- case false: // Conencted to the database.
- {
- printf(" [Filterscript::MySQL]: Connection success to database `%s`", MySQL_Data);
- }
- case true: // fail to Connect to the database.
- {
- printf(" [Filterscript::MySQL]: Connection fail to database `%s`", MySQL_Data);
- printf(" [Filterscript::MySQL]: Info: %s@%s:%d | Pass: *******", MySQL_User, MySQL_Host, MySQL_Port);
- }
- }
- printf(" [Filterscript::System]: MyBB Connector has been loaded. Author: XeonMaster.");
- return 1;
- }
- public OnFilterScriptExit()
- {
- mysql_close();
- for(new i = 0; i < GetMaxPlayers(); i++)
- {
- if(IsPlayerConnected(i) && !IsPlayerNPC(i))
- {
- ShowPlayerDialog(i, 9999999999, DIALOG_STYLE_MSGBOX, "", "", "", "");
- TogglePlayerControllable(i, false);
- KillTimer(Timer[i]);
- }
- }
- return 1;
- }
- // Commands:
- CMD:forum(playerid)
- {
- print("Command is called");
- new query[45], Cache:getCache, rows = 0;
- mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_forums` WHERE `open` = 1");
- getCache = mysql_query(Database, query);
- cache_get_row_count(rows);
- if(rows != 0)
- {
- new forumname[24], string[120];
- for(new i = 0; i < rows; i++)
- {
- cache_get_value_name(i, "name", forumname, sizeof(forumname));
- cache_get_value_name_int(i, "fid", ForumIds[i]);
- format(string, sizeof(string), "%s\n", forumname);
- }
- ShowPlayerDialog(playerid, 959, DIALOG_STYLE_LIST, "{F81414}MyBB: {FFFFFF}Forum's", string, "SELECT", "CLOSE");
- }
- else ShowPlayerDialog(playerid, 950, DIALOG_STYLE_MSGBOX, "{F81414}MyBB: {FFFFFF}Forum's", "{FFFFFF}Sorry, there no forum's created at the moment, thank you.", "OK", "");
- cache_delete(getCache);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- // Global forum checking...
- case 959:
- {
- if(!response) return 1;
- lastid[playerid] = listitem;
- new query[45], Cache:getCache, rows = 0;
- mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_threads` WHERE `fid` = %d", ForumIds[listitem]);
- getCache = mysql_query(Database, query);
- cache_get_row_count(rows);
- if(rows != 0)
- {
- new threadname[24], string[356], count = 0; // I don't know if its enough for you (356 cells)
- for(new i = 0; i < rows; i++)
- {
- if(count == 20) break;
- cache_get_value_name(i, "name", threadname, sizeof(threadname));
- cache_get_value_name_int(i, "tid", ThreadIds[i]);
- format(string, sizeof(string), "%s\n", threadname);
- count++;
- }
- ShowPlayerDialog(playerid, DIALOG_MYBB_TOPIC, DIALOG_STYLE_LIST, "{F81414}MyBB: {FFFFFF}Thread's", string, "SELECT", "GO BACK");
- }
- else ShowPlayerDialog(playerid, DIALOG_MYBB_MESAG, DIALOG_STYLE_MSGBOX, "{F81414}MyBB: {FFFFFF}Thread's", "{FFFFFF}Sorry, there no thread's created at the moment, thank you.", "OK", "");
- cache_delete(getCache);
- return 1;
- }
- case DIALOG_MYBB_TOPIC:
- {
- if(!response) return CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_FORUM, true, lastid[playerid], "\0");
- lastid[playerid] = listitem;
- new query[45], Cache:getCache, rows = 0;
- mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_posts` WHERE `tid` = %d AND `visible` = 1", ThreadIds[listitem]);
- getCache = mysql_query(Database, query);
- cache_get_row_count(rows);
- if(rows != 0)
- {
- new msg[300], string[356], username[24], count = 0; // I don't know if its enough for you (356 cells & 300 cells)
- for(new i = 0; i < rows; i++)
- {
- if(count == 3) break;
- cache_get_value_name(i, "username", username, sizeof(username));
- cache_get_value_name(i, "message", msg, sizeof(msg));
- format(string, sizeof(string), "Posted By: %s\n Message: %s\n\n", username, msg);
- count++;
- }
- cache_delete(getCache);
- mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_threads` WHERE `tid` = %d AND `closed` = 1", ThreadIds[listitem]);
- getCache = mysql_query(Database, query);
- cache_get_row_count(rows);
- if(rows == 0) ShowPlayerDialog(playerid, DIALOG_MYBB_POSTR, DIALOG_STYLE_INPUT, "{F81414}MyBB: {FFFFFF}Post's", string, "REPLY", "GO BACK");
- else ShowPlayerDialog(playerid, DIALOG_MYBB_POSTR, DIALOG_STYLE_INPUT, "{F81414}MyBB: {FFFFFF}Post's", string, "GO BACK", "");
- }
- else ShowPlayerDialog(playerid, DIALOG_MYBB_MESAG, DIALOG_STYLE_MSGBOX, "{F81414}MyBB: {FFFFFF}Post's", "{FFFFFF}Sorry, there nothing posted in this topic at the moment, thank you.", "OK", "");
- cache_delete(getCache);
- return 1;
- }
- case DIALOG_MYBB_POSTR:
- {
- if(!response) return CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_TOPIC, response, lastid[playerid], "\0");
- ShowPlayerDialog(playerid, DIALOG_MYBB_POSTR+1, DIALOG_STYLE_INPUT, "{F81414}MyBB: {FFFFFF}Reply", "{FFFFFF}Please Post an write some text below:", "REPLY", "GO BACK");
- return 1;
- }
- case DIALOG_MYBB_POSTR+1:
- {
- if(!response) CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_TOPIC, true, lastid[playerid], "\0");
- new Cache:getCache, rows;
- getCache = mysql_query(Database, "SELECT MAX(pid) FROM `mybb_posts`");
- cache_get_row_count(rows);
- new postid, string[756]; // I don't know if its enough for you! but msg of replying will be long so :)
- if(rows != 0)
- {
- cache_get_value_name_int(0, "pid", postid);
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_MYBB_MESAG, DIALOG_STYLE_MSGBOX, "{F81414}MyBB: {FFFFFF}Relpy", "{FFFFFF}Sorry, seems there something wrrong in our database at moment, thank you.", "OK", "");
- cache_delete(getCache);
- return 1;
- }
- cache_delete(getCache);
- new s, m, h, name[24];
- gettime(h, m, s);
- s = (h/120) + (m/60) + s;
- GetPlayerName(playerid, name, sizeof(name));
- mysql_format(\
- Database, string, sizeof(string), \
- "INSERT INTO `mybb_posts`\
- (`pid`,`tid`,`replyto`,`fid`,`subject`,`icon`,`uid`,`username`,`dateline`,`message`,`ipaddress`,`includesig`,`smilieoff`,`edituid`,`edittime`,`editreason`,`visible`)\
- VALUES \
- (%d,%d,0,%d,'MyBB Connector: from ingame',0,-1,'%s',%d,'%s','Invalid',0,0,0,0,0,0)", \
- postid+1, ThreadIds[lastid[playerid]], ForumIds[lastid[playerid]], name, s, inputtext
- );
- mysql_query(Database, string);
- ShowPlayerDialog(playerid, DIALOG_MYBB_MESAG, DIALOG_STYLE_MSGBOX, "{F81414}MyBB: {FFFFFF}Reply", "{FFFFFF}Suceess: You'r reply has been posted! you will be redirect to it automaticly in few seconds", "", "");
- TogglePlayerControllable(playerid, true);
- Timer[playerid] = SetTimerEx("OnMyBBReplyPosted", 2000, false, "i", playerid);
- }
- }
- return 0;
- }
- forward public OnMyBBReplyPosted(playerid);
- public OnMyBBReplyPosted(playerid)
- {
- ShowPlayerDialog(playerid, 9999999999, DIALOG_STYLE_MSGBOX, "", "", "", ""); // Hide any opened dialogs.
- TogglePlayerControllable(playerid, false);
- CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_TOPIC, true, lastid[playerid], "\0");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement