SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 13/12/2016, 01:19 AM   #1
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 293
Reputation: 134
Default od_server_password.inc - Make your mode not work without a password.

PHP Code:
#if defined _INC_od_server_password
    #endinput
#endif
#define _INC_od_server_password

#include <od_stdio>

#define OD_PASSWORD_OnGameModeInit Password_Check

static OD_PASSWORD_Strip(str[]) {
    new 
0;
    new 
0;
    while (
str[i] != 0) {
        if (
str[i] > 32) {
            
str[j] = str[i];
            ++
j;
        }
        ++
i;
    }
    
str[j] = 0;
}

bool:Password_Check(bool:hang false) {
    
#if defined OD_PASSWORD
        
IO_Write("Write the password to run the mode (on Windows press enter first).");
        
IO_NewLine();
        
IO_Flush();
        new 
pass[32];
        
IO_Read(pass);
        
OD_PASSWORD_Strip(pass);
        new 
hash[128];
        
SHA256_PassHash(pass"od_server_password.inc"hash128);
        if (
strcmp(hashOD_PASSWORD) != 0) {
            while (
hang) {
                
IO_Read(pass);
            }
            return 
false;
        }
        return 
true;
    
#else
        
IO_Write("You do not have a password.  Write to get the code (on Windows press enter first).");
        
IO_NewLine();
        
IO_Flush();
        new 
pass[32];
        
IO_Read(pass);
        
OD_PASSWORD_Strip(pass);
        new 
hash[128];
        
SHA256_PassHash(pass"od_server_password.inc"hash128);
        if (
strlen(pass) == 0) {
            
IO_Write("Password was empty");            
            
IO_NewLine();
        }
        
IO_Write("#define OD_PASSWORD \"");
        
IO_Write(hash);
        
IO_Write("\" // \"");
        
IO_Write(pass);
        
IO_Write("\"");
        
IO_NewLine();
        
IO_Flush();
        return 
false;
    
#endif

It can make your server not be stolen. When it starts you must type the password in the console, or the mode will not start. If you have no password, the server will make the code for your password.

Make a password example:

PHP Code:
#include <a_samp>
#include <od_server_password>
#include <od_scroll_text>
#include <od_progress_bar>

main()
{
}

public 
OnGameModeInit()
{
    if (
Password_Check(false)) {
        
IO_NewLine();
        
IO_Write("SERVER LOADING...");
        
IO_NewLine();
        
ProgressBar_Up(50);
        
ProgressBar_Done();
        
IO_NewLine();
        
IO_Flush();
    } else {
        
IO_NewLine();
        
#if defined OD_PASSWORD
            
Scroll_Dynamic("YOU CAN NOT USE THIS SCRIPT!!!"70100"---: "" :---");
        
#else
            
Scroll_Dynamic("Copy #define OD_PASSWORD to your mode..."70100"---: "" :---");
        
#endif
    
}
    return 
1;



Use a password example:

PHP Code:
#define OD_PASSWORD "AAF0630BDBB3DFE04DED48AEBF688838C6797F6AF02C656B75F10DF5F08AA1BC" // "changeme"

#include <a_samp>
#include <od_server_password>
#include <od_scroll_text>
#include <od_progress_bar>

main()
{
}

public 
OnGameModeInit()
{
    if (
Password_Check(false)) {
        
IO_NewLine();
        
IO_Write("SERVER LOADING...");
        
IO_NewLine();
        
ProgressBar_Up(50);
        
ProgressBar_Done();
        
IO_NewLine();
        
IO_Flush();
    } else {
        
IO_NewLine();
        
#if defined OD_PASSWORD
            
Scroll_Dynamic("YOU CAN NOT USE THIS SCRIPT!!!"70100"---: "" :---");
        
#else
            
Scroll_Dynamic("Copy #define OD_PASSWORD to your mode..."70100"---: "" :---");
        
#endif
    
}
    return 
1;

Correct:



Wrong disables everything (even ctrl-c doesn't work):



Put:

PHP Code:
    Password_Check(true); 
For no wrong message and no CPU use on wrong password (just makes the mode not work).

To make work on Linux type:

PHP Code:
ln -/dev/tty ./scriptfiles/CON 
Uses od_stdio.inc:

http://forum.sa-mp.com/showthread.ph...22#post3812622

Example uses od_scroll_text.inc and od_progress_bar.inc:

http://forum.sa-mp.com/showthread.ph...87#post3812687
http://forum.sa-mp.com/showthread.ph...29#post3812629

Last edited by OneDay; 04/04/2017 at 02:21 PM.
OneDay is offline   Reply With Quote
Old 13/12/2016, 11:19 AM   #2
Marines
Little Clucker
 
Marines's Avatar
 
Join Date: Oct 2016
Location: Republic of Vietnam
Posts: 5
Reputation: 10
Default Re: od_server_password.inc

Wow. Very nice include, i love it.
+Rep
Marines is offline   Reply With Quote
Old 13/12/2016, 11:20 AM   #3
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,071
Reputation: 281
Default Re: od_server_password.inc

Dope
__________________

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning
Eoussama is offline   Reply With Quote
Old 14/12/2016, 10:05 PM   #4
tysanio
Big Clucker
 
tysanio's Avatar
 
Join Date: May 2012
Location: At my House Duh..
Posts: 125
Reputation: 17
Default Re: od_server_password.inc

nice one!
__________________

Did i ever tell you the définitions of insanity?
tysanio is offline   Reply With Quote
Old 22/12/2016, 07:43 PM   #5
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 293
Reputation: 134
Default Re: od_server_password.inc

Quote:
Originally Posted by Marines View Post
Wow. Very nice include, i love it.
+Rep
Quote:
Originally Posted by Eoussama View Post
Dope
Quote:
Originally Posted by tysanio View Post
nice one!
Thanks
OneDay is offline   Reply With Quote
Old 04/04/2017, 02:09 PM   #6
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 293
Reputation: 134
Default Re: od_server_password.inc

updated with fixed hooks
nice functions names
works on Linux with:

PHP Code:
ln -/dev/tty ./scriptfiles/CON 
OneDay is offline   Reply With Quote
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



All times are GMT. The time now is 09:56 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.