Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: ahmedzead on Feb 06, 2017, 01:47 PM

Title: how to be admin in my own server??
Post by: ahmedzead on Feb 06, 2017, 01:47 PM
hi all im new at programming so i dont know how to be admin in any server help pls :( :(
Title: Re: how to be admin in my own server??
Post by: Kewun on Feb 06, 2017, 01:50 PM
learn squirrel
code
code x2
look wiki
search scrripts
????
profit
Title: Re: how to be admin in my own server??
Post by: DizzasTeR on Feb 06, 2017, 02:49 PM
Quote from: Kewun on Feb 06, 2017, 01:50 PMlearn squirrel
code
code x2
look wiki
search scrripts
????
profit

Kindly don't post shit like this again.

@ahmedzead, To be admin in your server you firstly need a Account system. There are some released ones in the Released scripts section so you can try to look for it.
Title: Re: how to be admin in my own server??
Post by: Kewun on Feb 06, 2017, 03:52 PM
i was trying to help. i didnt post shit like you do
Title: Re: how to be admin in my own server??
Post by: EK.IceFlake on Feb 06, 2017, 04:32 PM
Quote from: Kewun on Feb 06, 2017, 03:52 PMi was trying to help. i didnt post shit like you do
Summoning @Shadow
Title: Re: how to be admin in my own server??
Post by: Eva on Feb 06, 2017, 04:35 PM
Quote from: Kewun on Feb 06, 2017, 03:52 PMi was trying to help. i didnt post shit like you do
Omg...
Title: Re: how to be admin in my own server??
Post by: Pasorzyt on Feb 06, 2017, 06:07 PM
the truth is that kewun was always right
Title: Re: how to be admin in my own server??
Post by: Xmair on Feb 06, 2017, 06:12 PM
The truth is you registered today and have no idea about this forum. (or you're kewun)
Title: Re: how to be admin in my own server??
Post by: iReaL on Feb 10, 2017, 01:39 AM
SIMPLE CODE FOR ADMIN XD


    if ( cmd == "YOUR CMD" )
    {
         if ( player.Name == "YOUR NAME FOR ACESS THE COMMAND" )
         {
                The function () // The command
         }
    }   else MessagePlayer( "YOU NO ARE ADMIN", player );


For more security on your server you can change the player.Name to
player.UniqueID , player.IP , player.UniqueID2 , or create one data base XD
Title: Re: how to be admin in my own server??
Post by: ℛḝξ☂ on Feb 10, 2017, 10:11 AM
player.Admin = true;
Title: Re: how to be admin in my own server??
Post by: vito on Feb 10, 2017, 11:02 AM
you can use your uid instead  making account system, maybe someone able to change his uid to your one and 'hack' your server, but i think nobody will do that.
Title: Re: how to be admin in my own server??
Post by: jWeb on Feb 10, 2017, 02:20 PM
Quote from: iReaL on Feb 10, 2017, 01:39 AMSIMPLE CODE FOR ADMIN XD


    if ( cmd == "YOUR CMD" )
    {
         if ( player.Name == "YOUR NAME FOR ACESS THE COMMAND" )
         {
                The function () // The command
         }
    }   else MessagePlayer( "YOU NO ARE ADMIN", player );


For more security on your server you can change the player.Name to
player.UniqueID , player.IP , player.UniqueID2 , or create one data base XD

So if I join with your name. Does that make me an admin on your server?

And also, how primitive that can be. If I want to use a different nickname, I have to search and edit the scripts and reboot the server.

This is the worst of the worst of the worst examples that could be given for something like this.
Title: Re: how to be admin in my own server??
Post by: iReaL on Feb 10, 2017, 03:11 PM
Quote from: jWeb on Feb 10, 2017, 02:20 PM
Quote from: iReaL on Feb 10, 2017, 01:39 AMSIMPLE CODE FOR ADMIN XD


    if ( cmd == "YOUR CMD" )
    {
         if ( player.Name == "YOUR NAME FOR ACESS THE COMMAND" )
         {
                The function () // The command
         }
    }   else MessagePlayer( "YOU NO ARE ADMIN", player );


For more security on your server you can change the player.Name to
player.UniqueID , player.IP , player.UniqueID2 , or create one data base XD

So if I join with your name. Does that make me an admin on your server?

And also, how primitive that can be. If I want to use a different nickname, I have to search and edit the scripts and reboot the server.

This is the worst of the worst of the worst examples that could be given for something like this.

Not the worst, the worst would be if the admin needs a level ()
I said that it can become more secure with the .uniqueID, .IP, and other commands.
Title: Re: how to be admin in my own server??
Post by: jWeb on Feb 10, 2017, 03:58 PM
Quote from: iReaL on Feb 10, 2017, 03:11 PMNot the worst, the worst would be if the admin needs a level ()
I said that it can become more secure with the .uniqueID, .IP, and other commands.

That implies you have a static IP address. And most people don't. As for the UID. Well, that can be stolen and replicated. Thus exposing you even further.
Title: Re: how to be admin in my own server??
Post by: vito on Feb 10, 2017, 04:56 PM
Quote from: jWeb on Feb 10, 2017, 03:58 PMAs for the UID. Well, that can be stolen and replicated.
Nobody will do that. Even if he will set password 123456 nobody will hack it. It's vcmp.
Title: Re: how to be admin in my own server??
Post by: iReaL on Feb 10, 2017, 05:07 PM
Quote from: vito on Feb 10, 2017, 04:56 PM
Quote from: jWeb on Feb 10, 2017, 03:58 PMAs for the UID. Well, that can be stolen and replicated.
Nobody will do that. Even if he will set password 123456 nobody will hack it. It's vcmp.

Yes...
Title: Re: how to be admin in my own server??
Post by: jWeb on Feb 10, 2017, 05:50 PM
Here you go. The simplest admin implementation I can think of. It uses a .txt file to store and load administrators based on their nicks. Uses a table with name->password as the key->value pair to represent the list of admins and be efficient when searching.

Load/save functions:
// ============================================================================
function LoadAdmins(filepath) {
    local f = file(filepath, "rb+"), t = {};
    while (f.eos() == null) {
        local name = "", pass = "", c = 0;
        for (c = f.readn('c'); c != '|' && f.eos() == null; c = f.readn('c')) {
            name += format("%c", c);
        }
        if (f.eos() != null) break;
        for (c = f.readn('c'); c != '\n' && f.eos() == null; c = f.readn('c')) {
            pass += format("%c", c);
        }
        if (f.eos() != null && c != '\n' && c != '\r') pass += format("%c", c);
        name = strip(name), pass = strip(pass);
        if (name.len() > 0 && pass.len() > 0) t.rawset(name, pass);
    }
    return t;
}

function SaveAdmins(adminlist, filepath) {
    local f = file(filepath, "wb+");
    foreach (name, pass in adminlist) {
        name = strip(name), pass = strip(pass);
        foreach (c in name) f.writen(c, 'c');
        f.writen('|', 'c');
        foreach (c in pass) f.writen(c, 'c');
        f.writen('\n', 'c');
    }
}


Helper functions:
// ============================================================================
function EncryptPassword(password) {
    return password; // INSERT YOUR HASHING METHOD HERE! ex: SHA256(password);
}
function AdminCheck(player) {
    if (player.IsAdmin == true) return true;
    MessagePlayer("You do not have the privilege to perform this action!", player);
    return false;
}

NOTE: I would suggest using the Hashing plugin to encrypt the passwords by updating the EncryptPassword() function accordingly. But that's your choice.

Load and save admins:
// ============================================================================
function onServerStart() {
    g_AdminList <- LoadAdmins("adminlist.txt");
}

function onServerStop() {
    SaveAdmins(g_AdminList, "adminlist.txt");
}

NOTE: Make sure you have a "adminlist.txt" file in the server folder.

And 3 simple commands to manage them:
// ============================================================================
function onPlayerCommand(player, cmd, args) {
    args  = strip(args);
    switch (cmd) {
        // ====================================================================
        case "getadmin": {
            if (player.IsAdmin == true) MessagePlayer("You are already an administrator", player);
            else if (args.len() <= 0) {
                MessagePlayer("Syntax: cmd <password>", player);
                return;
            }
            else if (g_AdminList.rawin(player.Name)) {
                local pass = g_AdminList.rawget(player.Name), args = EncryptPassword(args);
                if (pass != args)
                    MessagePlayer("Wrong administrator password", player);
                else {
                    player.IsAdmin = true;
                    MessagePlayer("You are now recognized as administrator", player);
                }
            }
        } break;
        // ====================================================================
        case "setadmin": {
            if (!AdminCheck(player)) return;
            else if (args.len() <= 0) {
                MessagePlayer("Syntax: cmd <player_id> <password>", player);
                return;
            }
            local sep = args.find(" ");
            if (sep == null) {
                MessagePlayer("Syntax: cmd <player_id> <password>", player);
                return;
            }
            local player_id = null;
            try {
                player_id = args.slice(0, sep).tointeger();
            } catch (e) {
                MessagePlayer("Invalid player id", player);
                return;
            }
            local admin = FindPlayer(player_id)
            if (admin == null) {
                MessagePlayer("No such player on the server", player);
                return;
            }
            local password = null;
            try {
                password = strip(args.slice(sep + 1).tostring());
            } catch(e) {
                MessagePlayer("Invalid or missing password", player);
                return;
            }
            if (password.len() <= 0) {
                MessagePlayer("Invalid or empty password", player);
                return;
            }
            g_AdminList.rawset(admin.Name, EncryptPassword(password));
            admin.IsAdmin = true;
            MessagePlayer("Successfully included (" + admin.Name + ") into administrators", player);
        } break;
        // ====================================================================
        case "unsetadmin": {
            if (!AdminCheck(player)) return;
            else if (args.len() <= 0) {
                MessagePlayer("Syntax: cmd <admin_name>", player);
                return;
            } else if (g_AdminList.rawin(args)) {
                g_AdminList.rawdelete(args);
                local admin = FindPlayer(args);
                if (admin != null) admin.IsAdmin = false;
                MessagePlayer("Successfully excluded (" + admin.Name + ") from administrators", player);
            } else MessagePlayer("No administrator named (" + args + ")", player);
        } break;
    }
}

When a player switches to admin mode. It simple sets the player.IsAdmin property to true. So if (player.IsAdmin == true) then that player is an admin. Other wise it's just a regular player.

I'm not sure how you can get more simple than this.
Title: Re: how to be admin in my own server??
Post by: Cool on Feb 10, 2017, 06:29 PM
@jweb I think You dont know he is totally new thats why no one geting interest in it Wait for hiss Next error
:D
Title: Re: how to be admin in my own server??
Post by: Eva on Feb 10, 2017, 06:34 PM
Quote from: vito on Feb 10, 2017, 04:56 PM
Quote from: jWeb on Feb 10, 2017, 03:58 PMAs for the UID. Well, that can be stolen and replicated.
Nobody will do that. Even if he will set password 123456 nobody will hack it. It's vcmp.
I wouldnt count on it.