AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   limit rcon server access (https://forums.alliedmods.net/showthread.php?t=257200)

HamletEagle 04-17-2015 05:52

Re: limit rcon server access
 
Not a module, but a pawn plugin. See this as an experimental plugin and test by yourself.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <orpheu>
#include <orpheu_advanced>

new HandleUserIp[35]

new 
Trie:HandleIpTrie

public plugin_precache()
{
    
HandleIpTrie TrieCreate()
    if(
HandleIpTrie == Invalid_Trie)
    {
        
set_fail_state("Failed to create trie")
    }

    new const 
FileName[] = "rcon_ip_acces.ini"
    
new HandlePath[95]; get_configsdir(HandlePathcharsmax(HandlePath))
    
format(HandlePathcharsmax(HandlePath), "%s/%s"HandlePathFileName)
    
    new 
FilePointer fopen(HandlePath"rt")
    if(
FilePointer)
    {
        new 
FileData[40]
        while(!
feof(FilePointer))
        {
            
fgets(FilePointerFileDatacharsmax(FileData))
            
trim(FileData)
            
            if(!
FileData[0] || FileData[0] == '#' || FileData[0] == '/')
            {
                continue
            }
            
            
TrieSetCell(HandleIpTrieFileData0)
        }
    }
    
    
OrpheuRegisterHook(OrpheuGetFunction("SV_Rcon"), "OnSV_Rcon"OrpheuHookPre)
}

public 
OrpheuHookReturn:OnSV_Rcon(Pointer)
{
    new 
LocalIp[10]
    
OrpheuGetBytesAtAddress(PointerLocalIpcharsmax(LocalIp))
    
    if(
LocalIp[0] == 3)
    {
        
formatex(HandleUserIpcharsmax(HandleUserIp), "%i.%i.%i.%i"LocalIp[4], LocalIp[5], LocalIp[6], LocalIp[7])
        if(!
TrieKeyExists(HandleIpTrieHandleUserIp))
        {
            
log_amx("Blocked rcon attemp from: %s"HandleUserIp)
            return 
OrpheuSupercede
        
}
        
        
log_amx("Allowed rcon attemp from: %s"HandleUserIp)
        return 
OrpheuIgnored
    
}
    return 
OrpheuIgnored
    
    
}

public 
plugin_end()
{
    
TrieDestroy(HandleIpTrie)


Signature(put into addons/amxmodx/configs/orpheu/functions)
Code:

{
        "name" : "SV_Rcon",
        "library" : "engine",
        "arguments" :
        [
                {
                        "type" : "pointer"
                }
        ],
        "identifiers":
        [
                {
                        "os" : "windows",
                        "value" : [0x55,0x8B,0xEC,0x81,0xEC,0x04,0x06,0x00,0x00,0x53,0x56,0x57]
                },
                {
                        "os" : "linux",
                        "value" : "SV_Rcon"
                }
        ]
}

Create in addons/amxmodx/configs a file called rcon_ip_acces.ini. Write there the ip that can acces rcon, without port.

Green0Turtle 04-21-2015 02:57

Re: limit rcon server access
 
Great job
Can you add a feature to prevent flooding? (max blocked rcon attempt)

Green0Turtle 11-05-2015 15:06

Re: limit rcon server access
 
Quote:

Originally Posted by Green0Turtle (Post 2288541)
Great job
Can you add a feature to prevent flooding? (max blocked rcon attempt)

@HamletEagle

KORD_12.7 11-07-2015 04:25

Re: limit rcon server access
 
HamletEagle, dear plugin approver, there is no need to destroy arrays/tries on plugin end :D

HamletEagle 11-07-2015 06:07

Re: limit rcon server access
 
Quote:

Originally Posted by KORD_12.7 (Post 2360661)
HamletEagle, dear plugin approver, there is no need to destroy arrays/tries on plugin end :D

KORD_12.7, dear user, there is no problem in destroying them, and it's a good practice(not only about tries, but about all handles). You should always free what you used when you no longer need it, and given that memory is reused after map change you can waste memory(at least in amxx < 183). Ask Arkshine if you want to know about the changes in the dev versions.

KORD_12.7 11-07-2015 09:08

Re: limit rcon server access
 
HamletEagle, dear plugin approver, pls sorry, i'm just a newbie.


All times are GMT -4. The time now is 14:17.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.