Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. /**
  2. * Copyright (c) 2017 MyBB Connector Filterscript
  3. *
  4. * This program is free software: you can redistribute it and/or modify it under the terms of the
  5. * GNU General Public License as published by the Free Software Foundation, either version 3 of the
  6. * License, or (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  9. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. * General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with this program.
  13. * If not, see <http://www.gnu.org/licenses/>.
  14. * Generated by Visual Studio Code 2016 - 2017.
  15. */
  16.  
  17. /*
  18. Credits:
  19.  
  20. XeonMaster - SA-MP Scripter
  21. BlueG(MySQL) - SA-MP Beta Tester
  22. Zeex(Zcmd) - SA-MP Scripter
  23. SA-MP Team - SA-MP Developer
  24. */
  25.  
  26. #define FILTERSCRIPT
  27.  
  28. // Includes:
  29. #include <a_samp>
  30. #include <a_mysql>
  31. #include <zcmd>
  32.  
  33. #if defined MAX_PLAYERS
  34. #undef MAX_PLAYERS
  35. #define MAX_PLAYERS 100
  36. #endif
  37.  
  38. // MySQL Informations:
  39. #define MySQL_Host "db4free.net" // MySQL Server that your server will connect to
  40. #define MySQL_User "yassine_sap2" // MySQL Username that server will use it to login into
  41. #define MySQL_Pass "yassine23" // MySQL Password of the username you entred up ^
  42. #define MySQL_Data "saplayground_2" // MySQL Database that your server will take informations from
  43. #define MySQL_Port 3307 // Port of your MySQL Server.
  44.  
  45. static MySQL:Database;
  46.  
  47. // Dialogs Ids:
  48. enum
  49. {
  50. DIALOG_MYBB_FORUM = 100,
  51. DIALOG_MYBB_TOPIC,
  52. DIALOG_MYBB_POSTR,
  53. DIALOG_MYBB_MESAG
  54. };
  55.  
  56. // Variables:
  57. new
  58. ForumIds[10],
  59. ThreadIds[20],
  60. lastid[MAX_PLAYERS],
  61. Timer[MAX_PLAYERS]
  62. ;
  63.  
  64. // Callbacks:
  65. public OnFilterScriptInit()
  66. {
  67. mysql_log(ALL);
  68.  
  69. new MySQLOpt:Port = mysql_init_options();
  70. mysql_set_option(Port, SERVER_PORT, MySQL_Port);
  71.  
  72. Database = mysql_connect(MySQL_Host, MySQL_User, MySQL_Pass, MySQL_Data, Port); // Connecting to the mysql server.
  73.  
  74. switch(mysql_errno())
  75. {
  76. case false: // Conencted to the database.
  77. {
  78. printf(" [Filterscript::MySQL]: Connection success to database `%s`", MySQL_Data);
  79. }
  80. case true: // fail to Connect to the database.
  81. {
  82. printf(" [Filterscript::MySQL]: Connection fail to database `%s`", MySQL_Data);
  83. printf(" [Filterscript::MySQL]: Info: %s@%s:%d | Pass: *******", MySQL_User, MySQL_Host, MySQL_Port);
  84. }
  85. }
  86. printf(" [Filterscript::System]: MyBB Connector has been loaded. Author: XeonMaster.");
  87. return 1;
  88. }
  89.  
  90. public OnFilterScriptExit()
  91. {
  92. mysql_close();
  93. for(new i = 0; i < GetMaxPlayers(); i++)
  94. {
  95. if(IsPlayerConnected(i) && !IsPlayerNPC(i))
  96. {
  97. ShowPlayerDialog(i, 9999999999, DIALOG_STYLE_MSGBOX, "", "", "", "");
  98. TogglePlayerControllable(i, false);
  99. KillTimer(Timer[i]);
  100. }
  101. }
  102. return 1;
  103. }
  104.  
  105. // Commands:
  106. CMD:forum(playerid)
  107. {
  108. print("Command is called");
  109. new query[45], Cache:getCache, rows = 0;
  110.  
  111. mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_forums` WHERE `open` = 1");
  112. getCache = mysql_query(Database, query);
  113. cache_get_row_count(rows);
  114.  
  115. if(rows != 0)
  116. {
  117. new forumname[24], string[120];
  118. for(new i = 0; i < rows; i++)
  119. {
  120. cache_get_value_name(i, "name", forumname, sizeof(forumname));
  121. cache_get_value_name_int(i, "fid", ForumIds[i]);
  122. format(string, sizeof(string), "%s\n", forumname);
  123. }
  124. ShowPlayerDialog(playerid, 959, DIALOG_STYLE_LIST, "{F81414}MyBB: {FFFFFF}Forum's", string, "SELECT", "CLOSE");
  125. }
  126. 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", "");
  127. cache_delete(getCache);
  128.  
  129. return 1;
  130. }
  131.  
  132. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  133. {
  134. switch(dialogid)
  135. {
  136. // Global forum checking...
  137. case 959:
  138. {
  139. if(!response) return 1;
  140.  
  141. lastid[playerid] = listitem;
  142.  
  143. new query[45], Cache:getCache, rows = 0;
  144.  
  145. mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_threads` WHERE `fid` = %d", ForumIds[listitem]);
  146. getCache = mysql_query(Database, query);
  147. cache_get_row_count(rows);
  148.  
  149. if(rows != 0)
  150. {
  151. new threadname[24], string[356], count = 0; // I don't know if its enough for you (356 cells)
  152. for(new i = 0; i < rows; i++)
  153. {
  154. if(count == 20) break;
  155. cache_get_value_name(i, "name", threadname, sizeof(threadname));
  156. cache_get_value_name_int(i, "tid", ThreadIds[i]);
  157. format(string, sizeof(string), "%s\n", threadname);
  158. count++;
  159. }
  160. ShowPlayerDialog(playerid, DIALOG_MYBB_TOPIC, DIALOG_STYLE_LIST, "{F81414}MyBB: {FFFFFF}Thread's", string, "SELECT", "GO BACK");
  161. }
  162. 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", "");
  163. cache_delete(getCache);
  164.  
  165. return 1;
  166. }
  167. case DIALOG_MYBB_TOPIC:
  168. {
  169. if(!response) return CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_FORUM, true, lastid[playerid], "\0");
  170.  
  171. lastid[playerid] = listitem;
  172.  
  173. new query[45], Cache:getCache, rows = 0;
  174.  
  175. mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_posts` WHERE `tid` = %d AND `visible` = 1", ThreadIds[listitem]);
  176. getCache = mysql_query(Database, query);
  177. cache_get_row_count(rows);
  178.  
  179. if(rows != 0)
  180. {
  181. new msg[300], string[356], username[24], count = 0; // I don't know if its enough for you (356 cells & 300 cells)
  182. for(new i = 0; i < rows; i++)
  183. {
  184. if(count == 3) break;
  185. cache_get_value_name(i, "username", username, sizeof(username));
  186. cache_get_value_name(i, "message", msg, sizeof(msg));
  187. format(string, sizeof(string), "Posted By: %s\n Message: %s\n\n", username, msg);
  188. count++;
  189. }
  190. cache_delete(getCache);
  191.  
  192. mysql_format(Database, query, sizeof(query), "SELECT * FROM `mybb_threads` WHERE `tid` = %d AND `closed` = 1", ThreadIds[listitem]);
  193. getCache = mysql_query(Database, query);
  194. cache_get_row_count(rows);
  195. if(rows == 0) ShowPlayerDialog(playerid, DIALOG_MYBB_POSTR, DIALOG_STYLE_INPUT, "{F81414}MyBB: {FFFFFF}Post's", string, "REPLY", "GO BACK");
  196. else ShowPlayerDialog(playerid, DIALOG_MYBB_POSTR, DIALOG_STYLE_INPUT, "{F81414}MyBB: {FFFFFF}Post's", string, "GO BACK", "");
  197. }
  198. 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", "");
  199. cache_delete(getCache);
  200.  
  201. return 1;
  202. }
  203. case DIALOG_MYBB_POSTR:
  204. {
  205. if(!response) return CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_TOPIC, response, lastid[playerid], "\0");
  206. ShowPlayerDialog(playerid, DIALOG_MYBB_POSTR+1, DIALOG_STYLE_INPUT, "{F81414}MyBB: {FFFFFF}Reply", "{FFFFFF}Please Post an write some text below:", "REPLY", "GO BACK");
  207. return 1;
  208. }
  209. case DIALOG_MYBB_POSTR+1:
  210. {
  211. if(!response) CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_TOPIC, true, lastid[playerid], "\0");
  212. new Cache:getCache, rows;
  213. getCache = mysql_query(Database, "SELECT MAX(pid) FROM `mybb_posts`");
  214. cache_get_row_count(rows);
  215.  
  216. new postid, string[756]; // I don't know if its enough for you! but msg of replying will be long so :)
  217. if(rows != 0)
  218. {
  219. cache_get_value_name_int(0, "pid", postid);
  220. }
  221. else
  222. {
  223. 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", "");
  224. cache_delete(getCache);
  225. return 1;
  226. }
  227. cache_delete(getCache);
  228.  
  229. new s, m, h, name[24];
  230. gettime(h, m, s);
  231. s = (h/120) + (m/60) + s;
  232.  
  233. GetPlayerName(playerid, name, sizeof(name));
  234. mysql_format(\
  235. Database, string, sizeof(string), \
  236. "INSERT INTO `mybb_posts`\
  237. (`pid`,`tid`,`replyto`,`fid`,`subject`,`icon`,`uid`,`username`,`dateline`,`message`,`ipaddress`,`includesig`,`smilieoff`,`edituid`,`edittime`,`editreason`,`visible`)\
  238. VALUES \
  239. (%d,%d,0,%d,'MyBB Connector: from ingame',0,-1,'%s',%d,'%s','Invalid',0,0,0,0,0,0)", \
  240. postid+1, ThreadIds[lastid[playerid]], ForumIds[lastid[playerid]], name, s, inputtext
  241. );
  242.  
  243. mysql_query(Database, string);
  244. 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", "", "");
  245. TogglePlayerControllable(playerid, true);
  246. Timer[playerid] = SetTimerEx("OnMyBBReplyPosted", 2000, false, "i", playerid);
  247. }
  248. }
  249. return 0;
  250. }
  251.  
  252. forward public OnMyBBReplyPosted(playerid);
  253. public OnMyBBReplyPosted(playerid)
  254. {
  255. ShowPlayerDialog(playerid, 9999999999, DIALOG_STYLE_MSGBOX, "", "", "", ""); // Hide any opened dialogs.
  256. TogglePlayerControllable(playerid, false);
  257. CallLocalFunction("OnDialogResponse" , "iiiis", playerid, DIALOG_MYBB_TOPIC, true, lastid[playerid], "\0");
  258. return 1;
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement