View Single Post
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 04-07-2015 , 21:36   Re: [Request] Report system
Reply With Quote #24

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
/*
Copyleft 2015 @ HamletEagle

ReportsSystem 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.

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 ReportsSystem; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <amxmisc>

#define PluginName    "ReportsSystem"
#define PluginVersion "1.0"
#define PluginAuthor  "HamletEagle"

enum _:ReportData
{
    
ReporterName[32],
    
ReportedName[32],
    
Reason[128]
}

enum _:Mode
{
    
ModeReasons,
    
ModeReports
}

const 
AdminFlag ADMIN_BAN

new Array:ArrayReasons
new Array:ArrayReports

new ReportedPlayer[33]
new 
ConfigsDirPath[80]
new 
ConfigFilePath[128]

new 
CvarReportLimit
new Float:FullReportTime[33]
public 
plugin_init()
{
    
register_plugin
    

    .
plugin_name PluginName,
    .
version     PluginVersion,
    .
author      PluginAuthor
    
)

    
register_clcmd("say /report_player""ClientCommand_Report")
    
register_clcmd("say_team /report_player""ClientCommand_Report")
    
register_concmd("amx_showreports""ClientCommand_ShowReports"AdminFlag)
    
register_concmd("amx_solvereport""ClientCommand_SolveReport"AdminFlag)
    
register_concmd("amx_clearreports""ClientCommand_ClearReports"AdminFlag)
    
    
CvarReportLimit register_cvar("amx_nextreport""10")
    
    
ArrayReasons ArrayCreate(128)
    
ArrayReports ArrayCreate(ReportData)

    
get_configsdir(ConfigsDirPathcharsmax(ConfigsDirPath))
    
ParseReasonsFile()
    
ParseReportsFile()
}

public 
plugin_end()
{
    
AddReportsToFile()
    
ArrayDestroy(ArrayReasons)
    
ArrayDestroy(ArrayReports)
}

public 
client_disconnect(id)
{
    new 
Size ArraySize(ArrayReports), Data[ReportData]
    for(new 
iSizei++)
    {
        
ArrayGetArray(ArrayReportsiData)
        if
        ( 
            
id == get_user_index(Data[ReporterName]) ||
            
id == get_user_index(Data[ReportedName])
        )
        {
            
ArrayDeleteItem(ArrayReportsi)
        }
    }
}

ParseReasonsFile()
{
    new const 
ReasonsFile[] = "report_reasons.ini"
    
formatex(ConfigFilePathcharsmax(ConfigFilePath), "%s/%s"ConfigsDirPathReasonsFile)
    
ReadFile(ConfigFilePathModeReasons)
}

ParseReportsFile()
{
    new const 
ReportsFile[] = "reports_list.ini"
    
formatex(ConfigFilePathcharsmax(ConfigFilePath), "%s/%s"ConfigsDirPathReportsFile)
    
ReadFile(ConfigFilePathModeReports)
}

AddReportsToFile()
{
    if(
file_exists(ConfigFilePath))
    {
        
delete_file(ConfigFilePath)
    }

    new 
FilePointer fopen(ConfigFilePath"wt"), Data[ReportData]
    if(
FilePointer)
    {
        new 
Size ArraySize(ArrayReports)
        for(new 
iSizei++)
        {
            
ArrayGetArray(ArrayReportsiData)
            
fprintf(FilePointer"%s %s %s^n"Data[ReporterName], Data[ReportedName], Data[Reason])
        }
        
fclose(FilePointer)
    }
}

ReadFile(File[], Mod)
{
    new 
FilePointer fopen(File"rt")
    if(
FilePointer)
    {
        new 
FileData[128], Data[ReportData]
        while(!
feof(FilePointer))
        {
            
fgets(FilePointerFileDatacharsmax(FileData))
            
trim(FileData)
            
            if(!
FileData[0] || FileData[0] == ';' || FileData[0] == '#' || FileData[0] == '/')
            {
                continue
            }
            
server_print("Reading from file: %s"FileData)
            switch(
Mod)
            {
                case 
ModeReasons:
                {
                    
server_print("Pushing to array")
                    
ArrayPushString(ArrayReasonsFileData)
                }
                case 
ModeReports:
                {
                    
parse
                    
(
                        
FileData
                        
Data[ReporterName], charsmax(Data[ReporterName]), 
                        
Data[ReportedName], charsmax(Data[ReportedName]),
                        
Data[Reason      ], charsmax(Data[Reason      ])
                    )
                    
                    
ArrayPushArray(ArrayReportsData)
                }
            }
        }
    }    
}

public 
ClientCommand_Report(id)
{
    new 
Float:GameTime get_gametime()
    if(
GameTime FullReportTime[id])
    {
        new 
ReportMenu menu_create("Report:""HandleReportMenu")

        new 
Players[32], PlayersNumindex
        get_players
(PlayersPlayersNum)

        new 
PlayerName[32], UserId[6]
        for(new 
0<= PlayersNumi++)
        {
            
index Players[i]
            
get_user_name(indexPlayerNamecharsmax(PlayerName))
            
num_to_str(get_user_userid(index), UserIdcharsmax(UserId))

            
menu_additem(ReportMenuPlayerNameUserId0)
        }

        
menu_display(idReportMenu0)
        
FullReportTime[id] = GameTime + (float(get_pcvar_num(CvarReportLimit)) * 60.0)
    }
    else
    {
        
client_print(idprint_chat"You must wait: %.1f in order to report again"FullReportTime[id] - GameTime)
    }
}

public 
ClientCommand_ShowReports(idlevelcid)
{
    if(!
cmd_access(idlevelcid0))
    {
        return 
1
    
}

    new 
Size ArraySize(ArrayReports), Data[ReportData]
    if(!
Size)
    {
        
console_print(id"There are no reports open")
    }
    else
    {
        for(new 
iSizei++)
        {
            
ArrayGetArray(ArrayReportsiData)
            
console_print(id"[ %i ]Reporter: %s^nReported: %s^nReason:%s",iData[ReporterName], Data[ReportedName], Data[Reason])
            
console_print(id"=========================================")
        }
        
console_print(id"Write amx_solvereport report_number to close it")
    }
    return 
1
}

public 
ClientCommand_SolveReport(idlevelcid)
{
    if(!
cmd_access(idlevelcid1))
    {
        return 
1
    
}

    new 
Argument[5], Data[ReportData], ArrayEntrySize ArraySize(ArrayReports)
    
read_argv(1Argumentcharsmax(Argument))

    
ArrayEntry str_to_num(Argument)
    if(
ArrayEntry >= Size || ArrayEntry 0)
    {
        
console_print(id"Report number is invalid. Valid range: 0 - %i"Size)
    }
    else
    {
        
ArrayGetArray(ArrayReportsArrayEntryData)
        
console_print(id"You closed the report with number %i"ArrayEntry)
        
client_print(0print_chat"%s reported %s for %s. Report is now closed"Data[ReporterName], Data[ReportedName], Data[Reason])

        
ArrayDeleteItem(ArrayReportsArrayEntry)
    }
    return 
1
}

public 
ClientCommand_ClearReports(idlevelcid)
{
    if(!
cmd_access(idlevelcid1))
    {
        return 
1
    
}

    
ArrayClear(ArrayReports)
    
console_print(id"You cleared all the reports")
    return 
1
}

public 
HandleReportMenu(idReportMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(ReportMenu)
        return 
    }

    new 
UserId[6], Name[32], AccessCallBack
    menu_item_getinfo
(ReportMenuitemAccessUserIdcharsmax(UserId), Namecharsmax(Name), CallBack)

    new 
IntUserId str_to_num(UserId)
    new 
Target find_player("k"IntUserId//get reported player index

    
if(Target)
    {
        
ReportedPlayer[id] = Target
        BuildReasonsMenu
(id)
    }
    else
    {
        
client_print(idprint_chat"Target could not be found %s"Name)
    }

    
menu_destroy(ReportMenu)
}

BuildReasonsMenu(id)
{
    new 
ReasonsMenu menu_create("Select a reason""HandleReasonsMenu")

    new 
Size ArraySize(ArrayReasons), HandleReason[128]
    for(new 
iSizei++)
    {
        
ArrayGetString(ArrayReasonsiHandleReasoncharsmax(HandleReason))
        
menu_additem(ReasonsMenuHandleReason""0)
    }
    
menu_display(idReasonsMenu0)
}

public 
HandleReasonsMenu(idReasonsMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(ReasonsMenu)
        return 
    }

    
//Get the reason for reporting
    
new HandleReason[128]
    
ArrayGetString(ArrayReasonsitemHandleReasoncharsmax(HandleReason))

    
AddReport(idReportedPlayer[id], HandleReason)

    
client_print(idprint_chat"Report was succesfully sent")
    
menu_destroy(ReasonsMenu)
}

AddReport(idTarget, const HandleReason[])
{
    new 
Data[ReportData]
    
get_user_name(idData[ReporterName], charsmax(Data[ReporterName]))
    
get_user_name(TargetData[ReportedName], charsmax(Data[ReportedName]))
    
copy(Data[Reason], charsmax(Data[Reason]), HandleReason)
    
ArrayPushArray(ArrayReportsData)

    new 
Players[32], Numindex
    get_players
(PlayersNum"c")
    for(new 
iNumi++)
    {
        
index Players[i]
        if(
get_user_flags(index) & AdminFlag)
        {
            
client_print(indexprint_center"A new report was send")
        }
    }

1 and 3 done. 2 is not possible(you can't know when server crashed). Please remind me, what should be fixed ?
I checked the code

little bugs:
- hostname server show in menu /report_player
- i think there no getting nothing in reports_list.ini
- add every 5-10 mins can open /report_player or if player can't open in same round
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun