Advertisement
Garey

Report System

Mar 11th, 2019
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.80 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3.  
  4.  
  5. /* ================================================================================================
  6.                 Vars, Defines, Const
  7.   ================================================================================================*/
  8.  
  9. #define MIN_CARACTERES 10
  10.  
  11. new const ReportFile[ ] = "reports.txt";
  12. new const CommandMessageMode[ ] = "Details";
  13. new const Commands[ ][ ] = { "say /report" , "say /dokladvai" };
  14. new const ReportOptions[ ][ ] = { "Verbal Abuse" , "Cheating" , "Hiding", "Running", "Other" };
  15. new const banMinutes[] = { 0, 5, 10, 15, 20, 30, 60, 120, 600 };
  16.  
  17. new MaxPlayers;
  18. new inMessageMode[ 33 ], OptionSelected[ 33 ] , PlayerIDSelected[ 33 ] , UserIDSelected[ 33 ],
  19. PlayerDetails[ 33 ][ 128 ], PlayerMinutesBan[ 33 ], Reportes[ 33 ], Name[ 33 ][ 32 ], Authid[ 33 ][ 35 ];
  20.  
  21. /* ================================================================================================
  22.                 Main Forwards
  23.   ================================================================================================*/
  24.  
  25. public plugin_init()
  26. {
  27.     register_plugin( "Reports", "1.0", "trans" );
  28.    
  29.     static k;
  30.     for( k = 0 ; k < sizeof Commands ; ++k )
  31.         register_clcmd( Commands[ k ] , "clcmdReport" );
  32.        
  33.     register_clcmd( CommandMessageMode , "cmdDetails" );
  34.     register_clcmd( "say /rewrite", "cmdRewrite" );
  35.     register_clcmd( "say /players", "cmdPlayers" );
  36.    
  37.     MaxPlayers = get_maxplayers();
  38. }
  39.  
  40. public client_putinserver( index )
  41. {
  42.     get_user_name( index, Name[index], 31 );
  43.     get_user_authid( index, Authid[index], 34 );
  44.    
  45.     ResetVars( index );
  46. }
  47.  
  48. public client_infochanged( index )
  49. {
  50.     get_user_info( index, "name", Name[index], 31 );
  51. }
  52.  
  53. /* ================================================================================================
  54.                     Clcmds
  55.   ================================================================================================*/
  56.  
  57. public clcmdReport( index )
  58. {
  59.     if( Reportes[ index ] )
  60.     {
  61.         client_print( index, print_center, "*** Only one report per map is allowed ***" );
  62.         return PLUGIN_HANDLED;
  63.     }
  64.    
  65.    
  66.     static menu, k;
  67.     menu = menu_create( " \wSelect option:", "menu_report" );
  68.    
  69.     for( k = 0 ; k < sizeof ReportOptions ; ++k )
  70.         menu_additem( menu , ReportOptions[k] , "" );
  71.    
  72.     menu_display( index , menu );
  73.     return PLUGIN_HANDLED;
  74. }
  75.  
  76. public menu_report( index , menu , item )
  77. {
  78.     if( item == MENU_EXIT )
  79.     {
  80.         menu_destroy( menu );
  81.         return PLUGIN_HANDLED;
  82.     }
  83.    
  84.    
  85.     OptionSelected[ index ] = item;
  86.     cmdPlayers( index );
  87.    
  88.     menu_destroy( menu );
  89.     return PLUGIN_HANDLED;
  90. }
  91.  
  92. public cmdRewrite( index )
  93. {
  94.     if( !inMessageMode[ index ] )
  95.     {
  96.         client_print( index, print_chat, "You have not completed the report!" );
  97.         client_print( index, print_chat, "To redo the report, type, /report " );
  98.         return PLUGIN_HANDLED;
  99.     }
  100.        
  101.     client_cmd( index , "messagemode ^"%s^"", CommandMessageMode );
  102.     return PLUGIN_HANDLED;
  103. }
  104.  
  105. public cmdDetails( index )
  106. {
  107.     if( !inMessageMode[ index ] )
  108.     {
  109.         client_print( index, print_center, "*** NO PERMISSION ***" );
  110.         return PLUGIN_HANDLED;
  111.     }
  112.    
  113.    
  114.     read_args( PlayerDetails[ index ], 127 );
  115.     remove_quotes( PlayerDetails[ index ] ) ;
  116.     trim( PlayerDetails[ index ] );
  117.    
  118.     if( !is_valid_msg(index) )
  119.     {
  120.         client_print( index , print_chat , " Your message contains errors" );
  121.         client_print( index , print_chat , " If you want to rewrite, type / rewrite" );
  122.         PlayerDetails[ index ] = "^0";
  123.         return PLUGIN_HANDLED;
  124.     }
  125.    
  126.     SendReport(index);
  127.     return PLUGIN_HANDLED;
  128. }
  129.  
  130. /* ================================================================================================
  131.                     Menus
  132.   ================================================================================================*/
  133.  
  134.  
  135.  
  136.  /*
  137.  
  138.         Players Menu
  139.        
  140. */
  141.  
  142.  
  143. public cmdPlayers( index )
  144. {
  145.     static IDS[20], menu, i;
  146.     menu = menu_create(" \wSelect who you want to report:", "menu_players" );
  147.    
  148.     for( i = 1 ; i <= MaxPlayers ; ++i )
  149.     {
  150.         if( !is_user_connected(i) || i == index ) continue;
  151.        
  152.         formatex( IDS , charsmax(IDS) , "%d %d" , i , get_user_userid(i) )     
  153.         menu_additem( menu , Name[i] , IDS );
  154.     }
  155.    
  156.     menu_display( index , menu );  
  157. }
  158.  
  159. public menu_players( index , menu , item )
  160. {
  161.     if( item == MENU_EXIT )
  162.     {
  163.         menu_destroy( menu );
  164.         return PLUGIN_HANDLED;
  165.     }
  166.    
  167.     static varsinuso, buffer[12], szid[3], szuserid[9];
  168.     menu_item_getinfo(menu, item, varsinuso, buffer, charsmax(buffer), _, _, varsinuso);   
  169.     parse(buffer, szid, charsmax(szid), szuserid, charsmax(szuserid));
  170.    
  171.     PlayerIDSelected[ index ] = str_to_num(szid);
  172.     UserIDSelected[ index ] = str_to_num(szuserid);
  173.    
  174.     if( !is_user_connected( PlayerIDSelected[ index ] )
  175.     || UserIDSelected[ index ] != get_user_userid( PlayerIDSelected[index]) )
  176.     {
  177.         client_print( index , print_chat, " The player has disconnected. (%d)", PlayerIDSelected[ index ] );
  178.         return PLUGIN_HANDLED;
  179.     }
  180.    
  181.    
  182.     inMessageMode[ index ] = true;
  183.     client_cmd( index , "messagemode ^"%s^"", CommandMessageMode );
  184.    
  185.     menu_destroy( menu );
  186.     return PLUGIN_HANDLED;
  187. }
  188.  
  189. /*
  190.  
  191.         Send Report to admin ( Menu )
  192.        
  193. */
  194.  
  195. SendReport(index)
  196. {
  197.     static i, menu, String[ 300 ], ASD[ 20 ];
  198.    
  199.     formatex( String, charsmax( String ), " \y%s \whas reported \y%s^n\wReason:\y %s", Name[index], Name[ PlayerIDSelected[index] ], ReportOptions[ OptionSelected[index] ] );
  200.     menu = menu_create( String , "menu_adm" );
  201.    
  202.     formatex( ASD, 19, "%d %d", index, get_user_userid(index) );
  203.     menu_additem( menu , "\wSee Details" ,  ASD );
  204.     menu_additem( menu , "\rTake actions" , ASD );
  205.    
  206.     menu_additem( menu , "\yIgnore^n", "3" );
  207.    
  208.     for( i = 1 ; i <= MaxPlayers ; ++i )
  209.     {
  210.         if( !is_user_connected(i) || !is_user_admin(i) ) continue;
  211.        
  212.         menu_display( i , menu );
  213.     }
  214.    
  215.     CreateLog( index );
  216.     Reportes[ index ] = true;
  217. }
  218.  
  219. public menu_adm( index , menu , item )
  220. {
  221.     if( item == MENU_EXIT || item == 2 )
  222.     {
  223.         menu_destroy( menu );
  224.         return PLUGIN_HANDLED;
  225.     }
  226.    
  227.     static varsinuso, buffer[12], szid[3], szuserid[9], playerid, userid;
  228.     menu_item_getinfo(menu, item, varsinuso, buffer, charsmax(buffer), _, _, varsinuso);   
  229.     parse(buffer, szid, charsmax(szid), szuserid, charsmax(szuserid));
  230.    
  231.     playerid = str_to_num(szid);
  232.     userid = str_to_num(szuserid);
  233.    
  234.     if( !is_user_connected( playerid )
  235.     || userid != get_user_userid( playerid ) )
  236.     {
  237.         client_print( index , print_chat, "The player who made the report has disconnected. (%d)", playerid );
  238.         return PLUGIN_HANDLED;
  239.     }
  240.    
  241.     PlayerIDSelected[ index ] = PlayerIDSelected[ playerid ];
  242.     UserIDSelected[ index ] = UserIDSelected[ playerid ];
  243.     OptionSelected[ index ] = OptionSelected[ playerid ];
  244.    
  245.    
  246.     switch( item )
  247.     {
  248.         case 0:
  249.         {
  250.             static String[ 3500 ], Ip[2][20], len; len = 0
  251.             get_user_ip( playerid , Ip[0], 19, 1 );
  252.             get_user_ip( PlayerIDSelected[index] , Ip[1], 19, 1 );
  253.    
  254.             len += formatex( String[len], sizeof String-len, "<!doctype html>\
  255.             <html>\
  256.             <head>\
  257.             <title>Reports</title>\
  258.             </head>\
  259.             <body bgcolor=^"000000^">\
  260.             <h1><span style=^"color:#00FF00;^">Report</span></h1>\
  261.             <p><span style=^"color:#FF0000;^"><strong>====================================================</strong></span></p>\
  262.             <p>&nbsp;</p>" );
  263.            
  264.             len += formatex( String[len], sizeof String-len, "<p><span style=^"color:#40E0D0;^">%s</span>\
  265.             <span style=^"color:#FFF0F5;^">(</span><span style=^"color:#40E0D0;^">%s</span>\
  266.             <span style=^"color:#FFF0F5;^">)(</span><span style=^"color:#40E0D0;^">%s</span>", Name[playerid], Ip[0], Authid[playerid] );
  267.            
  268.            
  269.             len += formatex( String[len], sizeof String-len,"<span style=^"color:#FFF0F5;^">)</span><span style=^"color:#00FF00;^">Ha reportado a </span>\
  270.             <span style=^"color:#40E0D0;^">%s</span>\
  271.             <span style=^"color:#FFF0F5;^">(</span><span style=^"color:#40E0D0;^">%s</span>", Name[PlayerIDSelected[index]], Ip[1] );
  272.            
  273.             len += formatex( String[len], sizeof String-len,"<span style=^"color:#FFF0F5;^">)(</span><span style=^"color:#40E0D0;^">%s</span>\
  274.             <span style=^"color:#FFF0F5;^">)</span></p>",
  275.             Authid[PlayerIDSelected[index]] );
  276.            
  277.             len += formatex(String[len], sizeof String-len, "<p>&nbsp;</p>\
  278.             <p><span style=^"color:#00FF00;^">Reason</span>:\
  279.             <span style=^"color:#40E0D0;^">%s</span></p>", ReportOptions[ OptionSelected[ index ] ]  );
  280.            
  281.             len += formatex(String[len], sizeof String-len, "<p><span style=^"color:#00FF00;^">More Info:</span></p><p>&nbsp;</p>\
  282.             <p><span style=^"color:#FF0000;^"><strong>============================\
  283.             ========================</strong></span></p><p>&nbsp;</p>" );
  284.            
  285.             len += formatex(String[len], sizeof String-len, "<p><span style=^"color:#00FF00;^">%s</span></p><p>&nbsp;</p>\
  286.             <p><span style=^"color:#FF0000;^"><strong>====================================================</strong></span></p>",
  287.             PlayerDetails[ index ]);
  288.            
  289.             len += formatex( String[len], sizeof String-len, "</body></html>" );
  290.            
  291.             show_motd( index, String, "Report" );
  292.             showMenuBan( index );
  293.         }
  294.         case 1: showMenuBan( index );
  295.     }
  296.    
  297.     ResetVars( playerid ); 
  298.     menu_destroy( menu );
  299.     return PLUGIN_HANDLED;
  300. }
  301.  
  302. /*
  303.  
  304.         Menu Sancion
  305.        
  306. */
  307.  
  308. showMenuBan( index )
  309. {
  310.     static menu, String[128];
  311.     formatex( String, 127, "\wChoose the option to apply to:^n^t^t^t^t\y%s", Name[ PlayerIDSelected[index] ] );
  312.     menu = menu_create( String , "menu_handler" );
  313.    
  314.     menu_additem( menu , "Send warning^n^t^t\dA MOTD opens with the warning^n", "1" );
  315.     menu_additem( menu , "Ban^n^t^t\dYou set the minutes for the ban length^n^n", "2" );
  316.     menu_additem( menu , "Kick", "3" );
  317.    
  318.     menu_display( index , menu );  
  319. }
  320.  
  321. public menu_handler( index , menu , item )
  322. {
  323.     switch( item )
  324.     {
  325.         case 0:
  326.         {
  327.             SendAdvert( index );
  328.            
  329.             client_print( index, print_chat, "A warning was sent to %s", Name[PlayerIDSelected[index]] );
  330.         }
  331.         case 1: ShowMenuMinutes( index );
  332.         case 2: client_cmd( index, "amx_kick ^"%s^" ^"%s^"", Name[PlayerIDSelected[index]], ReportOptions[ OptionSelected[index] ]);
  333.        
  334.         case MENU_EXIT: { menu_destroy( menu ); return PLUGIN_HANDLED; }
  335.     }
  336.    
  337.     menu_destroy( menu );
  338.     return PLUGIN_HANDLED;
  339. }
  340.  
  341. /*
  342.  
  343.         Choose Minutes Ban
  344.        
  345. */     
  346.  
  347. ShowMenuMinutes( index )
  348. {
  349.     static i, String[128], menuban; menuban = menu_create( "\wBan length?", "menu_ban" );
  350.            
  351.     for( i = 0; i < sizeof banMinutes; ++i)
  352.     {
  353.         if( i == 0 )
  354.             formatex( String, charsmax( String ), "\rPermanent" );
  355.         else
  356.             formatex( String, charsmax( String ), "%d minutes", banMinutes[i] );
  357.                    
  358.         menu_additem( menuban, String, "" );
  359.     }
  360.            
  361.     menu_display( index , menuban );
  362. }
  363.  
  364. public menu_ban( index, menu, item )
  365. {
  366.     if( item != MENU_EXIT )
  367.     {
  368.         PlayerMinutesBan[ index ] = banMinutes[item];
  369.         ShowConfirmMenu( index );
  370.     }
  371.        
  372.    
  373.     menu_destroy( menu );
  374.     return PLUGIN_HANDLED;
  375. }
  376.  
  377. /*
  378.  
  379.         Ban Confirm Menu
  380.        
  381. */     
  382.  
  383. ShowConfirmMenu( index )
  384. {
  385.     static menu, String[128], minutes[50];
  386.     if( PlayerMinutesBan[index] == 0 )
  387.         formatex( minutes, charsmax(minutes), "\rPermanent" );
  388.     else
  389.         formatex( minutes, charsmax(minutes), "\r%d minutes", PlayerMinutesBan[index] );
  390.        
  391.     formatex( String, charsmax( String ), " \wAre you sure?^n\y\dBan \y%s %s", Name[ PlayerIDSelected[index] ], minutes );
  392.     menu = menu_create( String, "menu_confirm" );
  393.    
  394.     menu_additem( menu, "Yes, I'm sure^n", "1" );
  395.     menu_additem( menu, "No, change ban time", "2" );
  396.     menu_additem( menu, "No, just warn him", "3" );
  397.    
  398.     menu_display( index, menu );
  399. }
  400.  
  401. public menu_confirm( index , menu , item )
  402. {
  403.     switch( item )
  404.     {
  405.         case 0:
  406.         {
  407.             client_cmd( index, "amx_banip ^"%s^" ^"%d^" ^"%s^"",
  408.             Name[ PlayerIDSelected[index] ], PlayerMinutesBan[ index ], ReportOptions[ OptionSelected[index] ] );
  409.             ResetVars( index );
  410.         }
  411.         case 1: ShowMenuMinutes( index );
  412.         case 2:
  413.         {
  414.             SendAdvert( index );
  415.             client_print( index, print_chat, "A warning was sent to %s", Name[PlayerIDSelected[index]] );
  416.             ResetVars(index);
  417.         }
  418.        
  419.         case MENU_EXIT:
  420.         {
  421.             menu_destroy( menu );
  422.             ResetVars(index);
  423.             return PLUGIN_HANDLED;
  424.         }
  425.     }
  426.    
  427.     menu_destroy( menu );
  428.     return PLUGIN_HANDLED;         
  429. }
  430.  
  431. /*
  432.  
  433.         Stocks 'N Internal Functions
  434.        
  435. */     
  436.  
  437. SendAdvert( index )
  438. {
  439.     static String[ 2500 ], len; len = 0;
  440.            
  441.     len += formatex( String[len], sizeof String-len, "<!doctype html><html><head>\
  442.     <title>Warning</title></head><body bgcolor=^"#000000^">\
  443.     <h1 style=^"text-align: center;^"><span style=^"color:#FF0000;^">Warning</span></h1>");
  444.            
  445.     len += formatex( String[len], sizeof String-len, "<p><span style=^"color:#00FF00;^">====================================================</span></p>\
  446.     <p><span style=^"color:#FFF0F5;^">The admin</span><span style=^"color:#00FF00;^"> </span><span style=^"color:#FF0000;^">%s</span><span style=^"color:#00FF00;^">", Name[index] );
  447.            
  448.     len += formatex( String[len], sizeof String-len, "</span><span style=^"color:#FFF0F5;^">has sent you a</span><span style=^"color:#00FF00;^"> </span><span style=^"color:#B22222;^">warning</span>\
  449.     <span style=^"color:#FFF0F5;^">, because there has been a report &nbsp;</span></p><p><span style=^"color:#FFF0F5;^">on you.</span></p>");
  450.            
  451.     len += formatex( String[len], sizeof String-len, "<p>&nbsp;</p><p><span style=^"color:#FFF0F5;^">Reason:</span><span style=^"color:#00FF00;^">\
  452.     </span><span style=^"color:#FF0000;^">%s</span></p>\
  453.     <p><span style=^"color:#00FF00;^">====================================================</span></p>"
  454.     , ReportOptions[ OptionSelected[index] ]  );
  455.            
  456.     len += formatex( String[len], sizeof String-len, "</body></html>");
  457.            
  458.     show_motd( PlayerIDSelected[index], String, "Advertencia" );
  459. }
  460.  
  461. CreateLog( index )
  462. {
  463.     static String[ 512 ], Name[2][32], Ip[2][20], authid[2][35];
  464.     get_user_name( index , Name[0], 31 );
  465.     get_user_name( PlayerIDSelected[index] , Name[1], 31 );
  466.     get_user_ip( index , Ip[0], 19, 1 );
  467.     get_user_ip( PlayerIDSelected[index] , Ip[1], 19, 1 );
  468.     get_user_authid( index, authid[0], 34 );
  469.     get_user_authid( PlayerIDSelected[index], authid[1], 34 );
  470.    
  471.     formatex( String, charsmax(String), "^n^n%s <%s><%s> You have reported %s <%s><%s> Reason: %s^nMore info:^n%s^n==========================",
  472.     Name[0], Ip[0], authid[0], Name[1], Ip[1], authid[1], ReportOptions[ OptionSelected[index] ], PlayerDetails[index] );
  473.    
  474.     log_to_file( ReportFile, String );
  475. }
  476.  
  477. ResetVars( index )
  478. {
  479.     inMessageMode[ index ] = Reportes[ index ] = false;
  480.     OptionSelected[ index ] = -1;
  481.     PlayerIDSelected[ index ] = UserIDSelected[ index ] = PlayerMinutesBan[index] = 0;
  482.     PlayerDetails[ index ][0] = EOS;
  483. }
  484.  
  485. stock is_valid_msg(index)
  486. {
  487.     if ( strlen( PlayerDetails[index] ) < MIN_CARACTERES )
  488.         return false;
  489.        
  490.     if( containi( PlayerDetails[index], "%" ) != -1 )
  491.         return false;
  492.        
  493.     if( !is_user_connected(PlayerIDSelected[index]) || UserIDSelected[ index ] != get_user_userid( PlayerIDSelected[index]) )
  494.         return false;
  495.    
  496.     return true;
  497. }
  498. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  499. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3082\\ f0\\ fs16 \n\\ par }
  500. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement