Advertisement
Hauke

WBB Connect 1.4.1 - Filterscript

Aug 14th, 2011
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 25.27 KB | None | 0 0
  1. /* WBB Connect by Hauke Marquardt alias |-|auke - 08.05.2012
  2.  * Other credits:
  3.  * MySQL Plugin: G-sTyLeZzZ
  4.  * Encryption Plugin: Fro1sha
  5.  */
  6. /*
  7. License:
  8.         This code is free: you can redistribute it and/or modify
  9.         it under the terms of the GNU General Public License as published by
  10.         the Free Software Foundation, either version 3 of the License, or
  11.         (at your option) any later version.
  12.  
  13.         This code is distributed in the hope that it will be useful,
  14.         but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.         GNU General Public License for more details.
  17.  
  18.         You should have received a copy of the GNU General Public License
  19.         along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20.         You´re not allowed to copy any code from this, into your code without
  21.         naming authors name in credits!
  22. */
  23.  
  24. #include <a_samp>
  25. #include <a_http>
  26.  
  27. native sha1 ( const text[ ] , hesh[ ] );
  28. native mysql_fetch_int ( connectionHandle = 1 );
  29. native md5 ( const text[ ] , hesh[ ] );
  30. native mysql_debug ( enable = 1 );
  31. native mysql_num_rows ( connectionHandle = 1 );
  32. native mysql_close ( connectionHandle = 1 );
  33. native mysql_connect ( const host[ ] , const user[ ] , const database[ ] , const password[ ] );
  34. native mysql_ping ( connectionHandle = 1 );
  35. native mysql_fetch_row_format ( string[ ] , const delimiter[ ] = "|" , connectionHandle = 1 );
  36. native mysql_format ( connectionHandle , output[ ] , format[ ] , {Float,_}:... );
  37. native mysql_free_result ( connectionHandle = 1 );
  38. native mysql_query ( query[ ] , resultid = ( -1 ) , extraid = ( -1 ) , connectionHandle = 1 );
  39. native mysql_real_escape_string ( const source[ ] , destination[ ] , connectionHandle = 1 );
  40. native mysql_store_result ( connectionHandle = 1 );
  41. forward HTTPResponse ( index , response_code , data[ ] );
  42.  
  43. #define STORE_AND_FREE_RESULT mysql_query ( Query , -1 , -1 , MySQL[ Handle ] ); mysql_store_result ( MySQL[ Handle ] ); mysql_fetch_row_format ( Row , " " , MySQL[ Handle ] );mysql_free_result ( MySQL[ Handle ] );
  44.  
  45. #if !defined _h_library_norm_included
  46.     #define PAWN_TYPE_INT                   1
  47.     #define PAWN_TYPE_FLOAT                 2
  48.     #define PAWN_TYPE_ARRAY                 3
  49.     #define _h_library_norm_included
  50. #endif
  51.  
  52. #define WBB_USER_POSTS              0x0008
  53. #define WBB_USER_LAST_VISIT         0x0016
  54. #define WBB_USER_ACTIVATIO_CODE     0x0032
  55. #define WBB_USER_ACTIVITY_POINTS    0x0064
  56. #define WBB_USER_PROFILE_HITS       0x0128
  57. #define WBB_USER_UNREAD_PM          0x0256
  58.  
  59. forward _WBB_SetMySQLData ( _Server[ ] , _User[ ] , _Password[ ] , _Database[ ] , _InstallationCount );
  60. forward _WBB_IsValidUser ( wbbUsername[ ] );
  61. forward _WBB_CheckPassword ( wbbUsername[ ] , Password[ ] );
  62. forward _WBB_AddNewUser ( Username[ ] , Password[ ] , Email[ ] , ActivationState );
  63. forward _WBB_ActivateUser ( Username[ ] );
  64. forward _WBB_BanUser ( Username[ ] , Reason[ ] );
  65. forward _WBB_UnBanUser ( Username[ ] );
  66. forward _WBB_NewPrivateMessage ( Username[ ] , RecipientName[ ] , Subject[ ] , Message[ ] );
  67. forward _WBB_GetUserActivationState ( Username[ ] );
  68. forward _WBB_SetUserPassword ( Username[ ] , Password[ ] );
  69. forward _WBB_SetProfileField ( Username[ ] , Field[ ] , Value[ ] , Type );
  70. forward _WBB_GetProfileField ( Username[ ] , Field[ ] );
  71. forward _WBB_SendUserActivationMail ( Username[ ] , Sendername[ ] , Servername[ ] , ForumIndexURL[ ] );
  72. forward _WBB_AddPost ( Thread , Subject[ ] , Message[ ] , Username[ ] , BBCodes , HTML );
  73. forward _WBB_IsUserInGroup ( Username[ ] , GroupID );
  74. forward _WBB_SetUserToGroup ( Username[ ] , GroupID );
  75. forward _WBB_RemoveUserFromGroup ( Username[ ] , GroupID );
  76. forward _WBB_UpdateUserMail ( Username[ ] , Mail[ ] );
  77. forward _WBB_GetUserStats ( Username[ ] , Data );
  78. forward _WBB_CreateThread ( Board , Topic[ ] , Username[ ] , Disabled , Closed , Subject[ ] , Message[ ] , BBCodes , HTML );
  79.  
  80. enum MySQLData {
  81.     Handle,
  82.     Installation
  83. }
  84. new MySQL[ MySQLData ];
  85.  
  86. public _WBB_SetMySQLData ( _Server[ ] , _User[ ] , _Password[ ] , _Database[ ] , _InstallationCount ) {
  87.     mysql_debug ( 1 );
  88.     MySQL[ Installation ] = _InstallationCount;
  89.     MySQL[ Handle ] = mysql_connect ( _Server , _User , _Database , _Password );
  90.     return mysql_ping ( MySQL[ Handle ] ) == -1 ? false : true;
  91. }
  92.  
  93. public _WBB_IsValidUser ( wbbUsername[ ] )
  94.     return IsValidUser ( wbbUsername );
  95.    
  96. public _WBB_CheckPassword ( wbbUsername[ ] , Password[ ] )
  97.     return strcmp ( GetDoubleSaltedHash ( Password , GetUserData ( wbbUsername , "salt" ) ) , GetUserData ( wbbUsername , "Password" ) ) ? false : true;
  98.  
  99. public _WBB_AddNewUser ( Username[ ] , Password[ ] , Email[ ] , ActivationState ) {
  100.     if ( IsValidEmail ( Email ) )
  101.         return -1;
  102.     if ( IsValidUser ( Username ) )
  103.         return 0;
  104.     new Query[ 256 ] , Salt[ 64 ];
  105.     strcat ( Salt , CreateSalt ( ) );
  106.     mysql_format ( MySQL[ Handle ] , Query ,
  107.     "INSERT INTO `wcf%d_user` (username,email,password,salt,languageID,registrationDate,activationCode) VALUES ('%s','%s','%s','%s',1,%i,%i)" , MySQL[ Installation ] , Username , Email , GetDoubleSaltedHash ( Password , Salt ) , Salt , TimestampNow ( ) , ActivationState ? 0 : GenerateRandomValue ( ) );
  108.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  109.     AddUserToGroup ( Username , 1 );
  110.     if ( ActivationState )
  111.         AddUserToGroup ( Username , 3 );
  112.     return true;
  113. }
  114.  
  115. public _WBB_ActivateUser ( Username[ ] ) {
  116.     if ( !IsValidUser ( Username ) )
  117.         return 0;
  118.     if ( IsUserInGroup ( Username , 3 ) )
  119.         return -1;
  120.     else
  121.         return AddUserToGroup ( Username , 3 ) ? 1 : 0;
  122. }
  123.  
  124. public _WBB_BanUser ( Username[ ] , Reason[ ] ) {
  125.     if ( !IsValidUser ( Username ) )
  126.         return false;
  127.     SetUserData ( Username , "banned" , "1" , PAWN_TYPE_INT );
  128.     SetUserData ( Username , "banReason" , Reason );
  129.     return true;
  130. }
  131.  
  132. public _WBB_UnBanUser ( Username[ ] ) {
  133.     if ( !IsValidUser ( Username ) )
  134.         return false;
  135.     SetUserData ( Username , "banned" , "0" , PAWN_TYPE_INT );
  136.     new Query[ 128 ];
  137.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user` SET banReason = null WHERE username = '%s'" , MySQL[ Installation ] , Username );
  138.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  139.     return true;
  140. }
  141.  
  142. public _WBB_NewPrivateMessage ( Username[ ] , RecipientName[ ] , Subject[ ] , Message[ ] ) {
  143.     if ( !IsValidUser ( Username ) )
  144.         return -1;
  145.     if ( !IsValidUser ( RecipientName ) )
  146.         return 20;
  147.     new Query[ 512 ] , PMID[ 8 ] , Time = TimestampNow ( );
  148.     mysql_format ( MySQL[ Handle ] , Query ,
  149.     "INSERT INTO `wcf%d_pm` (userID,username,subject,message,time,saveInOutbox) VALUES (%i,'%s','%s','%s',%i,1)" , MySQL[ Installation ] , strval ( GetUserData ( Username , "userID" ) )  , Username , Subject  , Message , Time );
  150.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  151.     mysql_format ( MySQL[ Handle ] , Query , "SELECT pmID FROM `wcf%d_pm` WHERE time = %d AND username = '%s'" , MySQL[ Installation ] , Time , Username );
  152.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  153.     mysql_store_result ( MySQL[ Handle ] );
  154.     mysql_fetch_row_format ( PMID , " " , MySQL[ Handle ] );
  155.     mysql_free_result ( MySQL[ Handle ] );
  156.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_pm` SET parentPmID = pmID  WHERE pmID = %d" , MySQL[ Installation ] , strval ( PMID ) );
  157.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  158.     mysql_format ( MySQL[ Handle ] , Query ,
  159.     "INSERT IGNORE INTO `wcf%d_pm_to_user` (pmID,recipientID,recipient,userWasNotified) VALUES (%i,%i,'%s',0)" , MySQL[ Installation ] , strval ( PMID ) , strval ( GetUserData ( RecipientName , "userID" ) ) , RecipientName );
  160.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  161.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user` SET pmTotalCount = pmTotalCount + 1 WHERE username = '%s'" , MySQL[ Installation ] , RecipientName );
  162.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  163.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user` SET pmUnreadCount = pmUnreadCount + 1 WHERE username = '%s'" , MySQL[ Installation ] , RecipientName );
  164.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  165.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user` SET pmOutstandingNotification = pmOutstandingNotification + 1 WHERE username = '%s'" , MySQL[ Installation ] , RecipientName );
  166.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  167.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user` SET pmTotalCount = pmTotalCount + 1 WHERE username = '%s'" , MySQL[ Installation ] , Username );
  168.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  169.     mysql_format ( MySQL[ Handle ] , Query ,
  170.     "INSERT INTO `wcf%d_pm_hash` (pmID,time,messageHash) VALUES (%i,%i,'%s')" , MySQL[ Installation ] , strval ( PMID ) , Time , GetHash ( Message , GetWBBConfig ( "encryption_method" ) ) );
  171.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  172.     return 1;
  173. }
  174.  
  175. public _WBB_GetUserActivationState ( Username[ ] )
  176.     return IsUserInGroup ( Username , 3 );
  177.    
  178. public _WBB_SetUserPassword ( Username[ ] , Password[ ] ) {
  179.     if ( !IsValidUser ( Username ) )
  180.         return false;
  181.     new Salt[ 64 ];
  182.     strcat ( Salt , CreateSalt ( ) );
  183.     SetUserData ( Username , "password" , GetDoubleSaltedHash ( Password , Salt ) );
  184.     return SetUserData ( Username , "salt" , Salt );
  185. }
  186.  
  187. public _WBB_SetProfileField ( Username[ ] , Field[ ] , Value[ ] , Type ) {
  188.     if ( !IsValidUser ( Username ) )
  189.         return -1;
  190.     if ( !GetWBBOptionID ( Field ) )
  191.         return 0;
  192.     SetUserOption ( Username , GetWBBOptionID ( Field ) , Value , Type );
  193.     return 1;
  194. }
  195.  
  196. public _WBB_GetProfileField ( Username[ ] , Field[ ] ) {
  197.     if ( !IsValidUser ( Username ) )
  198.         return -1;
  199.     if ( !GetWBBOptionID ( Field ) )
  200.         return 0;
  201.     return GetUserOption ( Username , GetWBBOptionID ( Field ) );
  202. }
  203.  
  204. public _WBB_SendUserActivationMail ( Username[ ] , Sendername[ ] , Servername[ ] , ForumIndexURL[ ] ) {
  205.     if ( !IsValidUser ( Username ) )
  206.         return false;
  207.     return SendMail ( Username , Sendername , Servername , ForumIndexURL );
  208. }
  209.  
  210. public _WBB_AddPost ( Thread , Subject[ ] , Message[ ] , Username[ ] , BBCodes , HTML ) {
  211.     if ( !IsValidUser ( Username ) )
  212.         return false;
  213.     return AddPostToThread ( Thread , Subject , Message , Username , BBCodes , HTML , TimestampNow ( ) );
  214. }
  215.  
  216. public _WBB_IsUserInGroup ( Username[ ] , GroupID )
  217.     return IsValidUser ( Username ) ? IsUserInGroup ( Username , GroupID ) : -1;
  218.    
  219. public _WBB_SetUserToGroup ( Username[ ] , GroupID ) {
  220.     if ( !IsValidUser ( Username ) )
  221.         return false;
  222.     return AddUserToGroup ( Username , GroupID );
  223. }
  224.  
  225. public _WBB_RemoveUserFromGroup ( Username[ ] , GroupID ) {
  226.     if ( !IsValidUser ( Username ) )
  227.         return -1;
  228.     if ( !IsUserInGroup ( Username , GroupID ) )
  229.         return -2;
  230.     return RemoveUserFromGroup ( Username , GroupID ) ? 1 : 0;
  231. }
  232.  
  233. public _WBB_UpdateUserMail ( Username[ ] , Mail[ ] ) {
  234.     if ( !IsValidUser ( Username ) )
  235.         return false;
  236.     return SetUserData ( Username , "email" , Mail , PAWN_TYPE_ARRAY );
  237. }
  238.  
  239. public _WBB_GetUserStats ( Username[ ] , Data ) {
  240.     switch ( Data ) {
  241.         case WBB_USER_POSTS:
  242.             return strval ( GetUserWBBData ( Username , "posts" ) );
  243.         case WBB_USER_LAST_VISIT:
  244.             return strval ( GetUserWBBData ( Username , "boardLastVisitTime" ) );
  245.         case WBB_USER_ACTIVATIO_CODE:
  246.             return strval ( GetUserData ( Username , "activationCode" ) );
  247.         case WBB_USER_ACTIVITY_POINTS:
  248.             return strval ( GetUserData ( Username , "activityPoints" ) );
  249.         case WBB_USER_PROFILE_HITS:
  250.             return strval ( GetUserData ( Username , "profileHits" ) );
  251.         case WBB_USER_UNREAD_PM:
  252.             return strval ( GetUserData ( Username , "pmUnreadCount" ) );
  253.     }
  254.     return false;
  255. }
  256.  
  257. public _WBB_CreateThread ( Board , Topic[ ] , Username[ ] , Disabled , Closed , Subject[ ] , Message[ ] , BBCodes , HTML ) {
  258.     if ( !IsValidUser ( Username ) )
  259.         return false;
  260.     new Query[ 1536 ] , Keys[ 512 ] , Values[ 1024 ] , UserID = strval ( GetUserData ( Username , "userID" ) ) , Time = TimestampNow ( ) , Row[ 16 ] , ThreadID , PostID;
  261.     strcat ( Keys , "boardID,topic,languageID,userID,username,prefix,time,lastPostTime,lastPosterID,lastPoster,attachments,polls,isSticky,isAnnouncement,isClosed,isDisabled,everEnabled" );
  262.     format ( Values , sizeof Values , "%d,'%s',0,%d,'%s','',%d,%d,%d,'%s',0,0,0,0,%d,%d,0" , Board , Topic , UserID , Username , Time , Time , UserID , Username , Closed > 0 ? 1 : 0 , Disabled > 0 ? 1 : 0 );
  263.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wbb1_%d_thread` (%s) VALUES (%s)" , MySQL[ Installation ] , Keys , Values );
  264.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  265.     mysql_format ( MySQL[ Handle ] , Query , "SELECT threadID FROM `wbb1_%d_thread` WHERE boardID = %d AND time = %d" , MySQL[ Installation ] , Board , Time );
  266.     STORE_AND_FREE_RESULT
  267.     ThreadID = strval ( Row );
  268.     format ( Keys , sizeof Keys , "%s" , "threadID,subject,message,userID,username,time,attachments,enableSmilies,enableHtml,enableBBCodes,showSignature,pollID,ipAddress,isDisabled,everEnabled" );
  269.     format ( Values , sizeof Values , "%d,'%s','%s',%d,'%s',%d,0,0,%d,%d,0,0,'127.0.0.1',0,0" , ThreadID , Subject , Message , UserID , Username , Time , HTML > 0 ? 1 : 0 , BBCodes > 0 ? 1 : 0 );
  270.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wbb1_%d_post` (%s) VALUES (%s)" , MySQL[ Installation ] , Keys , Values );
  271.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  272.     mysql_format ( MySQL[ Handle ] , Query , "SELECT postID FROM `wbb1_%d_post` WHERE userID = %d AND time = %d" , MySQL[ Installation ] , UserID , Time );
  273.     STORE_AND_FREE_RESULT
  274.     PostID = strval ( Row );
  275.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wbb1_%d_user_last_post` (userID,postID,time) VALUES (%d,%d,%d)" , MySQL[ Installation ] , UserID , PostID , Time );
  276.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  277.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wbb1_%d_post_hash` (postID,messageHash,time) VALUES (%d,'%s',%d)" , MySQL[ Installation ] , PostID , GetHash ( Message , "md5" ) , Time );
  278.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  279.     mysql_format ( MySQL[ Handle ] , Query , "SELECT boardID FROM `wbb1_%d_thread` WHERE threadID = %d" , MySQL[ Installation ] , ThreadID );
  280.     STORE_AND_FREE_RESULT
  281.     mysql_format ( MySQL[ Handle ] , Query , "REPLACE INTO `wbb1_%d_board_last_post` (boardID,languageID,threadID) VALUES (%d,0,%d)" , MySQL[ Installation ] , strval ( Row ) , ThreadID );
  282.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  283.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wbb1_%d_thread` SET firstPostID = %d, firstPostPreview = 'WBB_Connect Message | © WBB_Connect by Hauke Marquardt' WHERE threadID = %d" , MySQL[ Installation ] , PostID , ThreadID );
  284.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  285.     return true;
  286. }
  287.  
  288. AddPostToThread ( Thread , Subject[ ] , Message[ ] , Username[ ] , BBCodes , HTML , Time ) {
  289.     new Query[ 1536 ] , Keys[ 512 ] , Values[ 1024 ] , Row[ 16 ] , UserID = strval ( GetUserData ( Username , "userID" ) );
  290.     strcat ( Keys , "threadID,subject,message,userID,username,time,attachments,enableSmilies,enableHtml,enableBBCodes,showSignature,pollID,ipAddress,isDisabled,everEnabled" );
  291.     format ( Values , sizeof Values , "%d,'%s','%s',%d,'%s',%d,0,0,%d,%d,0,0,'127.0.0.1',0,0" , Thread , Subject , Message , strval ( GetUserData ( Username , "userID" ) ) , Username , Time , HTML > 0 ? 1 : 0 , BBCodes > 0 ? 1 : 0 );
  292.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wbb1_%d_post` (%s) VALUES (%s)" , MySQL[ Installation ] , Keys , Values );
  293.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  294.     mysql_format ( MySQL[ Handle ] , Query , "SELECT postID FROM `wbb1_%d_post` WHERE userID = %d AND time = %d" , MySQL[ Installation ] , UserID , Time );
  295.     STORE_AND_FREE_RESULT
  296.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wbb1_%d_user_last_post` (userID,postID,time) VALUES (%d,%d,%d)" , MySQL[ Installation ] , UserID , strval ( Row ) , Time );
  297.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  298.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wbb1_%d_post_hash` (postID,messageHash,time) VALUES (%d,'%s',%d)" , MySQL[ Installation ] , strval ( Row ) , GetHash ( Message , "md5" ) , Time );
  299.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  300.     mysql_format ( MySQL[ Handle ] , Query , "SELECT boardID FROM `wbb1_%d_thread` WHERE threadID = %d" , MySQL[ Installation ] , Thread );
  301.     STORE_AND_FREE_RESULT
  302.     mysql_format ( MySQL[ Handle ] , Query , "REPLACE INTO `wbb1_%d_board_last_post` (boardID,languageID,threadID) VALUES (%d,0,%d)" , MySQL[ Installation ] , strval ( Row ) , Thread );
  303.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  304.     mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wbb1_%d_thread` SET replies = replies + 1, lastPostTime = %d, lastPosterID = %d, lastPoster = '%s' WHERE threadID = %d" , MySQL[ Installation ] , Time , UserID , Username , Thread );
  305.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  306.     return true;
  307. }
  308.  
  309. AddUserToGroup ( Username[ ] , GroupID ) {
  310.     new Query[ 256 ];
  311.     mysql_format ( MySQL[ Handle ] , Query , "INSERT INTO `wcf%d_user_to_groups` (userID,groupID) VALUES (%d,%d)" , MySQL[ Installation ] , strval ( GetUserData ( Username , "userID" ) ) , GroupID );
  312.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  313.     return 1;
  314. }
  315.  
  316. RemoveUserFromGroup ( Username[ ] , GroupID ) {
  317.     new Query[ 256 ];
  318.     mysql_format ( MySQL[ Handle ] , Query , "DELETE from `wcf%d_user_to_groups` WHERE userID = %d AND groupID = %d" , MySQL[ Installation ] , strval ( GetUserData ( Username , "userID" ) ) , GroupID );
  319.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  320.     return IsUserInGroup ( Username , GroupID ) ? false : true;
  321. }
  322.  
  323. SetUserData ( Username[ ] , Data[ ] , Value[ ] , Type = PAWN_TYPE_ARRAY ) {
  324.     new Query[ 128 ];
  325.     if ( Type == PAWN_TYPE_INT )
  326.         mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user` SET %s = %i WHERE username = '%s'" , MySQL[ Installation ] , Data , strval ( Value ) , Username );
  327.     else
  328.         mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user` SET %s = '%s' WHERE username = '%s'" , MySQL[ Installation ] , Data , Value , Username );
  329.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  330.     return true;
  331. }
  332.  
  333. IsUserInGroup ( Username[ ] , GroupID ) {
  334.     new Groups[ 16 ] , I , bool:InGroupState;
  335.     GetUserGroups ( Username , Groups );
  336.     while ( Groups[ I ] > 0 && !InGroupState ) {
  337.         if ( Groups[ I ] == GroupID )
  338.             InGroupState = true;
  339.         I++;
  340.     }
  341.     return InGroupState;
  342. }
  343.  
  344. GetUserGroups ( Username[ ] , Groups[ ] ) {
  345.     new Query[ 64 ] , Row[ 16 ] , I;
  346.     mysql_format ( MySQL[ Handle ] , Query , "SELECT groupID FROM `wcf%d_user_to_groups` WHERE userID = %d" , MySQL[ Installation ] , strval ( GetUserData ( Username , "userID" ) ) );
  347.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  348.     mysql_store_result ( MySQL[ Handle ] );
  349.     while ( I < mysql_num_rows( MySQL[ Handle ] ) ) {
  350.         mysql_fetch_row_format ( Row , " " , MySQL[ Handle ] );
  351.         Groups[ I ] = strval ( Row );
  352.         I++;
  353.     }
  354.     mysql_free_result ( MySQL[ Handle ] );
  355. }
  356.  
  357. GetUserData ( Username[ ] , Data[ ] ) {
  358.     new Query[ 64 ] , Row[ 64 ];
  359.     mysql_format ( MySQL[ Handle ] , Query , "SELECT %s FROM `wcf%d_user` WHERE username = '%s'" , Data , MySQL[ Installation ] , Username );
  360.     STORE_AND_FREE_RESULT
  361.     return Row;
  362. }
  363.  
  364. GetUserWBBData ( Username[ ] , Data[ ] ) {
  365.     new Query[ 64 ] , Row[ 64 ];
  366.     mysql_format ( MySQL[ Handle ] , Query , "SELECT %s FROM `wbb1_%d_user` WHERE userID = %d" , Data , MySQL[ Installation ] , strval ( GetUserData ( Username , "userID" ) ) );
  367.     STORE_AND_FREE_RESULT
  368.     return Row;
  369. }
  370.  
  371. IsValidUser ( Username[ ] ) {
  372.     new Query[ 128 ] , Row[ 6 ];
  373.     mysql_format ( MySQL[ Handle ] , Query , "SELECT userID FROM `wcf%d_user` WHERE username = '%s'" , MySQL[ Installation ] , Username );
  374.     STORE_AND_FREE_RESULT
  375.     return strval ( Row ) > 0 ? true : false;
  376. }
  377.  
  378. IsValidEmail ( Email[ ] ) {
  379.     new Query[ 128 ] , Row[ 6 ];
  380.     mysql_format ( MySQL[ Handle ] , Query , "SELECT userID FROM `wcf%d_user` WHERE email = '%s'" , MySQL[ Installation ] , Email );
  381.     STORE_AND_FREE_RESULT
  382.     return strval ( Row ) > 0 ? true : false;
  383. }
  384.  
  385. SetUserOption ( Username[ ] , OptionID , Value[ ] , Type ) {
  386.     new Query[ 128 ];
  387.     if ( Type == PAWN_TYPE_ARRAY )
  388.         mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user_option_value` SET userOption%d = '%s' WHERE userID = %d" , MySQL[ Installation ] , OptionID , Value , strval ( GetUserData ( Username , "userID" ) ) );
  389.     else
  390.         mysql_format ( MySQL[ Handle ] , Query , "UPDATE `wcf%d_user_option_value` SET userOption%d = %d WHERE userID = %d" , MySQL[ Installation ] , OptionID , strval(  Value ) , strval ( GetUserData ( Username , "userID" ) ) );
  391.     mysql_query ( Query , -1 , -1 , MySQL[ Handle ] );
  392. }
  393.  
  394. GetUserOption ( Username[ ] , OptionID ) {
  395.     new Row[ 64 ] , Query[ 64 ];
  396.     mysql_format ( MySQL[ Handle ] , Query , "SELECT userOption%d FROM `wcf%d_user_option_value` WHERE userID = %d" , OptionID , MySQL[ Installation ] , strval ( GetUserData ( Username , "userID" ) ) );
  397.     STORE_AND_FREE_RESULT
  398.     return strval ( Row );
  399. }
  400.  
  401. GetWBBOptionID ( Data[ ] ) {
  402.     new Row[ 64 ] , Query[ 64 ];
  403.     mysql_format ( MySQL[ Handle ] , Query , "SELECT optionID FROM `wcf%d_user_option` WHERE optionName = '%s'" , MySQL[ Installation ] , Data );
  404.     STORE_AND_FREE_RESULT
  405.     return strval ( Row );
  406. }
  407.  
  408. GetWBBConfig ( Data[ ] ) {
  409.     new Row[ 64 ] , Query[ 64 ];
  410.     if ( !strcmp ( "encrypt_before_salting" , Data ) )
  411.         mysql_format ( MySQL[ Handle ] , Query , "SELECT optionValue FROM `wcf%d_option` WHERE optionName = 'encryption_encrypt_before_salting'" , MySQL[ Installation ] );
  412.     else
  413.         mysql_format ( MySQL[ Handle ] , Query , "SELECT optionValue FROM `wcf%d_option` WHERE optionName = '%s'" , MySQL[ Installation ] , Data );
  414.     STORE_AND_FREE_RESULT
  415.     return Row;
  416. }
  417.  
  418. TimestampNow ( ) {
  419.     new String[ 16 ];
  420.     mysql_query ( "SELECT UNIX_TIMESTAMP(NOW())" , -1 , -1 , MySQL[ Handle ] );
  421.     mysql_store_result ( MySQL[ Handle ] );
  422.     mysql_fetch_row_format ( String , "|" , MySQL[ Handle ] );
  423.     mysql_free_result ( MySQL[ Handle ] );
  424.     return strval ( String );
  425. }
  426.  
  427. GenerateRandomValue ( ) {
  428.     new RandomValue;
  429.     while ( RandomValue < 100000000  )
  430.         RandomValue = random ( 999999999 );
  431.     return RandomValue;
  432. }
  433.  
  434. CreateSalt ( ) {
  435.     new Salt[ 64 ] , Code[ 10 ];
  436.     format ( Code , 10 , "%i" , GenerateRandomValue ( ) );
  437.     strcat ( Salt , GetHash ( Code , GetWBBConfig ( "encryption_method" ) ) );
  438.     return Salt;
  439. }
  440.  
  441. GetDoubleSaltedHash ( String[ ] , Salt[ ] ) {
  442.     new TempString[ 128 ] , HashedString[ 64 ];
  443.     strcat ( TempString , Salt );
  444.     strcat ( TempString , GetSaltedHash ( String , Salt ) );
  445.     format ( HashedString , 64 , GetHash ( TempString , GetWBBConfig ( "encryption_method" ) ) );
  446.     return HashedString;
  447. }
  448.  
  449. GetSaltedHash ( String[ ] , Salt[ ] ) {
  450.     new HashedString[ 128 ] , TempString[ 128 ];
  451.     if ( strval ( GetWBBConfig ( "encryption_enable_salting" ) ) > 0 ) {
  452.         if ( !strcmp ( GetWBBConfig ( "encryption_salt_position" ) , "before" ) )
  453.             strcat ( TempString , Salt );
  454.         if ( strval ( GetWBBConfig ( "encrypt_before_salting" ) ) > 0 )
  455.             strcat ( TempString , GetHash ( String , GetWBBConfig ( "encryption_method" ) ) );
  456.         else
  457.             strcat ( TempString , String );
  458.         if ( !strcmp ( GetWBBConfig ( "encryption_salt_position" ) , "after" ) )
  459.             strcat ( TempString , Salt );
  460.         strcat ( HashedString , GetHash ( TempString , GetWBBConfig ( "encryption_method" ) ) );
  461.     }
  462.     else
  463.         strcat ( HashedString , GetHash ( String , GetWBBConfig ( "encryption_method" ) ) );
  464.     return HashedString;
  465. }
  466.  
  467. GetHash ( Value[ ] , Method[ ] )
  468. {
  469.     new Hashed[ 128 ];
  470.     if ( !strcmp ( Method , "sha1" ) )
  471.         sha1 ( Value , Hashed );
  472.     if ( !strcmp ( Method , "md5" ) )
  473.         md5 ( Value , Hashed );
  474.     return Hashed;
  475. }
  476.  
  477. stock SendMail ( Username[ ] , Sendername[ ] , Servername[ ] , ForumIndexURL[ ] )
  478. {
  479.     new Post[ 2000 ] , Subject[ 128 ] , Message[ 1024 ] , DataAndLink[ 512 ] , Key[ 9 ];
  480.     format ( Key , 9 , "%d" , GenerateRandomValue ( ) );
  481.     SetUserData ( Username , "activationCode" , Key , PAWN_TYPE_INT );
  482.     format ( Subject , 128 , "Deine Aktivierung: %s" , Username );
  483.     format ( DataAndLink , 512 , "|t|tr|td Benutzernummer |/td|tdb: %s|/td|/tr|tr|td Aktivierungscode|/td|tdb: %s|/td|tr|/t" , GetUserData ( Username , "userID" ) , Key )/* ,"16873246" )*/;
  484.     format ( Message , 1000 , "Hallo %s,|nVielen Dank f|uer deine Registrierung bei %s.|n|nBitte klicke auf |l%s|quepage=Register|andaction=enable|diesen Link|/l, und aktiviere deinen Account mit folgenden Daten:%s|n|nMit freundlichen Gr|ue|ssen|nDein %s Team" , Username , Sendername , ForumIndexURL , DataAndLink , Sendername );
  485.     format ( Post , 2000 , "absender=%s&server=%s&adresse=%s&betreff=%s&nachricht=%s&html_allow=%i" , Sendername , Servername , GetUserData ( Username , "email" ) , Subject , Message , 1 );
  486.     HTTP ( 1234 , HTTP_POST , "www.1000zet.net/wbb_connect/mailsender.php" , Post , "HTTPResponse" );
  487.     return true;
  488. }
  489.  
  490. public HTTPResponse ( index , response_code , data[ ] )
  491.     if ( response_code == 200 )
  492.         if ( !strcmp ( data , "true" ) )
  493.             printf ( "Mail wurde erfolgreich gesendet!" );
  494.         else
  495.             printf ( "Schnittstellen Antwort: %s" , data );
  496.     else
  497.         print ( "Schnittstelle nicht gefunden" );
  498.  
  499. public OnFilterScriptInit()
  500. {
  501.     print("\n--------------------------------------");
  502.     print(" WBB Connect Filterscript by Hauke");
  503.     print("--------------------------------------\n");
  504.     return 1;
  505. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement