Raised This Month: $32 Target: $400
 8% 

Can this code be optimized further?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 02-18-2019 , 20:02   Can this code be optimized further?
Reply With Quote #1

PHP Code:
/* Sublime AMXX Editor v2.2 */

#include <amxmodx>

#define PLUGIN  "LICENSE PLUGIN FIXED"
#define VERSION "1.0"
#define AUTHOR  "deprale"

new hostname64 ]
new 
hostip20 ]
new 
bool:Licensed

enum _
:ServerInfo
{
    
ServerName64 ],
    
ServerIP64 ]
}

new const 
g_ServerList[][ ServerInfo ] = 
{
    { 
"PUB.ALLSTAR.RU""127.0.0.1" },
    { 
"PUB2.ALLSTAR.RU""localhost" }
};

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
CheckLicense()
}

public 
CheckLicense()
{
    
get_cvar_string("hostname"hostname63)
    
get_cvar_string("ip"hostip19)

    for(new 
0sizeofg_ServerList ); i++)
    {
        if( !
equalihostnameg_ServerList][ ServerName ]) || !equalihostipg_ServerList][ ServerIP ]))
            
Licensed false

        
else {
        
Licensed true
        
break;
        }
    }

    switch(
Licensed) {
        case 
0:
        {
            
set_fail_state("[HOST-IP LICENSE] SOMETHING WENT WRONG!")
        }
        case 
1:
        {
            
server_print("[HOST-IP LICENSE] NAME (%s), IP (%s) - LICENSE SUCCESSFULLY VERIFIED!"hostnamehostip)
        }
    }

    return 
PLUGIN_HANDLED;

before anyone jumps to conclusions, YES I DO KNOW this is "useless" if someone really wants to crack it.
__________________
deprale is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-18-2019 , 20:38   Re: Can this code be optimized further?
Reply With Quote #2

Get server IP with get_user_ip(0, ...), not by cvars.
__________________








CrazY. is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 02-18-2019 , 23:05   Re: Can this code be optimized further?
Reply With Quote #3

Thanks, done!
__________________
deprale is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-19-2019 , 07:59   Re: Can this code be optimized further?
Reply With Quote #4

Add a break after lincesed = falsee

Use equal instead of equali

CheckING ip + port is much better than ip ,+;servername


CheckLicense function is no need to be a public and remove the returning in the function it's useless


Switch can also take boolean values
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-19-2019 at 08:04.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-19-2019 , 09:21   Re: Can this code be optimized further?
Reply With Quote #5

This type of plugin is against the rules. I assume you plan to hand out only the .amxx file after you're done, correct?
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-19-2019 , 11:03   Re: Can this code be optimized further?
Reply With Quote #6

The best optimization is deleting it entirely, it's useless and what is the purpose of developing useless code? People can just open the source file and remove your license check.

But the real question is what OciXCrom said. Are you going to provide the sma file?
If yes, you are free to add licensing, people will just delete the code and recompile.
If no, then you are breaking the license and this is not acceptable.
__________________

Last edited by HamletEagle; 02-19-2019 at 11:05.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-19-2019 , 11:18   Re: Can this code be optimized further?
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Code:
//Add a break after lincesed = falsee
The loop would then exit after checking the first server in g_ServerList[] if there was no match. The 'Licensed=false' code can be removed all together.
//Use equal instead of equali
He should only use equal on the IP, equali() is needed on the hostname.
//CheckING ip + port is much better than ip ,+;servername //CheckLicense function is no need to be a public and remove the returning in the function it's useless //Switch can also take boolean values
An if/else statement is more relevant for a bool
@deprale, I'm not sure if you want to require the hostname and IP match in the same row of g_ServerList[]. The below will require both hostname and IP match.
PHP Code:
CheckLicense()
{
    new 
szHost64 ] , szIP16 ] , bool:bLicensed;
    
    
get_cvar_string"hostname" szHost charsmaxszHost ) );
    
get_cvar_string"ip" szIP charsmaxszIP ) );
    
    for ( new 
sizeofg_ServerList ) ; i++ )
    {
        if ( 
equaliszHost g_ServerList][ ServerName ] ) && equalszIP g_ServerList][ ServerIP ] ) ) 
        {
            
bLicensed true;
            break;
        }
    }

    if ( !
bLicensed )
    {
        
set_fail_state"[HOST-IP LICENSE] SOMETHING WENT WRONG!" );
    }
    else
    {
        
server_print("[HOST-IP LICENSE] NAME (%s), IP (%s) - LICENSE SUCCESSFULLY VERIFIED!" szHost szIP );
    }

__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-19-2019 , 12:51   Re: Can this code be optimized further?
Reply With Quote #8

I agree with HamletEagle and Oxi. If this plugin is going to be distributed on these boards then the code is useless.
__________________
Bugsy is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 02-25-2019 , 02:03   Re: Can this code be optimized further?
Reply With Quote #9

Nah, this is a custom request by one of my friends Chill out guys, I already said it's useless in the original post, he didn't want any of his friends to steal the plugin from the FTP Server so they could move out on with their own community, as they have an agreement to never share the plugin with someone else so one of them suggested this.

Only the ORIGINAL owner will have the .sma, the rest won't have access to it, but they will have access to the FTP server and it's just the ORIGINAL owner's concern that someone might steal it!

I read the ToS of AmxModX and I'm fully aware it's not legal to "sell" plugins without the .sma itself!

EDIT: thanks everyone for the suggestions! learning something new everyday
__________________

Last edited by deprale; 02-25-2019 at 02:07.
deprale is offline
Mordekay
Squirrel of Fortune
Join Date: Apr 2006
Location: Germany
Old 02-25-2019 , 13:36   Re: Can this code be optimized further?
Reply With Quote #10

As said this protection is not really secure. If your server is running on linux you should better move the .amxx into another directory and only put a symlink into the plugins folder. This way all they could steal is the symlink
__________________

Mordekay is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:29.


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