[Server Scripting] Changeauth command

Discussion in 'Server and Client Scripting' started by Kase, Sep 26, 2014.

  1. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    Hey

    I'm trying to make it to that people can't change my (Kase) and Neos auth below what its currently at. Other than at the the command should other normally.
    Code (text):
    1.     if (command == "changeauth" || command == "changeauths") {
    2.         var pos = commandData.indexOf(' ');
    3.         if (pos == -1) return;
    4.         var newauth = commandData.substring(0, pos), name = commandData.substr(pos+1), tar = sys.id(name), silent = command == "changeauths";
    5.         if (newauth > 0 && !sys.dbRegistered(name)) {
    6.             normalbot.sendMessage(src, "This person is not registered");
    7.             normalbot.sendMessage(tar, "Please register, before getting auth");
    8.             return;
    9.         }
    10.         if (sys.dbIp(tar) === "Kase", "Neos") {
    11.             var newauth = commandData.substring(0, pos), name = commandData.substr(pos+1), tar = sys.id(name), silent = command == "changeauths";
    12.             if (newauth < sys.auth(name)) {
    13.             normalbot.sendMessage(src, "You do not have permission to change the auth of " + name + ".");
    14.             else sys.changeDbAuth(name, newauth);
    15.             if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    16.             else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    17.             return;
    18.         }
    19.         if (tar !== undefined) sys.changeAuth(tar, newauth);
    20.         else sys.changeDbAuth(name, newauth);
    21.         if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    22.         else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    23.         return;
    24.     }
    This is what I have tried to do. When I try to change auth it says "You do not have permission to change the auth of " + name + "." It happens with everyone I try to change the auth off.

    Also, how can you make commands only usable by some people, using IP or name to Identity them?
     
    Last edited: Sep 26, 2014
  2. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    The if (sys.dbIp tar line is completely wrong. I don't know what you're attempting there.

    For the latter question, just look at eval in the po server scripts
     
  3. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    Thanks for the reply Moogle. On that line I'm trying to see if the target of the changeauth commands is Kase or Neos. It the someone is trying to change the auth to lower than its what is now, it stops the event, if its higer, it continues with the event. That whole part is there to stop people trying to change our auth to lower than what its is.

    How can I fix that line? And is that the only thing wrong with the code?
     
    Last edited: Sep 26, 2014
  4. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    I made some changes to the code. I don't the the error I got before, but "if (sys.ip(tar) === "Kase", "Neos")" is wrong because it fails to recognize that function.

    Code (text):
    1.     if (command == "changeauth" || command == "changeauths") {
    2.         var pos = commandData.indexOf(' ');
    3.         if (pos == -1) return;
    4.         var newauth = commandData.substring(0, pos), name = commandData.substr(pos+1), tar = sys.id(name), silent = command == "changeauths";
    5.         if (newauth > 0 && !sys.dbRegistered(name)) {
    6.             normalbot.sendMessage(src, "This person is not registered");
    7.             normalbot.sendMessage(tar, "Please register, before getting auth");
    8.             return;
    9.         }
    10.         if (sys.ip(tar) === "Kase", "Neos") {
    11.             var newauth = commandData.substring(0, pos), name = commandData.substr(pos+1), tar = sys.id(name), silent = command == "changeauths";
    12.             if (newauth < sys.auth(name)) {
    13.             normalbot.sendMessage(src, "You do not have permission to change the auth of " + name + ".");
    14.             return;
    15.             }
    16.             if (tar !== undefined) sys.changeAuth(tar, newauth);
    17.             else sys.changeDbAuth(name, newauth);
    18.             if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    19.             else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    20.             return;
    21.             }
    22.         if (tar !== undefined) sys.changeAuth(tar, newauth);
    23.         else sys.changeDbAuth(name, newauth);
    24.         if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    25.         else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    26.         return;
    27.     }
    *Note
    Its more likely to be something like commandData instead of sys.ip(tar)

    Tried this code as well. It more likely to be something like this.
    Code (text):
    1.  
    2.     if (command == "changeauth" || command == "changeauths") {
    3.         var pos = commandData.indexOf(' ');
    4.         if (pos == -1) return;
    5.         var newauth = commandData.substring(0, pos), name = commandData.substr(pos+1), tar = sys.id(name), silent = command == "changeauths";
    6.         if (newauth > 0 && !sys.dbRegistered(name)) {
    7.             normalbot.sendMessage(src, "This person is not registered");
    8.             normalbot.sendMessage(tar, "Please register, before getting auth");
    9.             return;
    10.         }
    11.         if (commandData === "Kase" || "Neos") {
    12.             var newauth = commandData.substring(0, pos), name = commandData.substr(pos+1), tar = sys.id(name), silent = command == "changeauths";
    13.             if (newauth < 3) {
    14.             normalbot.sendMessage(src, "You do not have permission to change the auth of " + name + ".",);
    15.             return;
    16.             }
    17.             if (newauth > 3) {
    18.             if (tar !== undefined) sys.changeAuth(tar, newauth);
    19.             else sys.changeDbAuth(name, newauth);
    20.             if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    21.             else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    22.             return;
    23.             }
    24.         }
    25.         if (tar !== undefined) sys.changeAuth(tar, newauth);
    26.         else sys.changeDbAuth(name, newauth);
    27.         if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    28.         else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    29.         return;
    30.     }
    31.  
    :frown:
     
    Last edited: Sep 26, 2014
  5. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    Alright nearly there.
    Code (text):
    1.     if (command == "changeauth" || command == "changeauths") {
    2.         var pos = commandData.indexOf(' ');
    3.         if (pos == -1) return;
    4.         var newauth = commandData.substring(0, pos), name = commandData.substr(pos+1), tar = sys.id(name), silent = command == "changeauths";
    5.         if (newauth > 0 && !sys.dbRegistered(name)) {
    6.             normalbot.sendMessage(src, "This person is not registered");
    7.             normalbot.sendMessage(tar, "Please register, before getting auth");
    8.             return;
    9.         }
    10.         if (commandData === "Kase" || "Neos") {
    11.             if (newauth < 3) {
    12.             normalbot.sendMessage(src, "You do not have permission to change the auth of " + name + ".");
    13.             return;
    14.             }
    15.             if (newauth > 3) {
    16.             sys.changeDbAuth(name, newauth);
    17.             if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    18.             else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    19.             return;
    20.             }
    21.         }
    22.         if (tar !== undefined) sys.changeAuth(tar, newauth);
    23.         else sys.changeDbAuth(name, newauth);
    24.         if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    25.         else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    26.         return;
    27.     }
    Now I no one can change the auth to more than less than 3. But it applies to everyone, not just Kase and Neos, it should only apply to Kase and Neos. I still want to be able to change the auth of others to less than 3.
     
    Last edited: Sep 26, 2014
  6. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    commandData === "Naos"
    On phone so can't help too much until I get home

    Actually you want to do name === "kase" || name === "neos"
     
    Last edited: Sep 26, 2014
  7. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    That's cool. I'll finish this of tomorrow.

    But what do you mean by that?
     
  8. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    Phone typing bad. Edited post to correct. Bottom line.
     
  9. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    Go it working.
    I tried "if (name === "Kase" || Name === "Neos")" but it didn't work so I tried "if (commandData.substring(pos+1) === "Kase" || commandData.substring(pos+1) === "Neos")" and it worked.
    Final code is
    Code (text):
    1.     if (command == "changeauth" || command == "changeauths") {
    2.         var pos = commandData.indexOf(' ');
    3.         if (pos == -1) return;
    4.         var newauth = commandData.substring(0, pos), name = commandData.substring(pos+1), tar = sys.id(name), silent = command == "changeauths";
    5.         if (newauth > 0 && !sys.dbRegistered(name)) {
    6.             normalbot.sendMessage(src, "This person is not registered");
    7.             normalbot.sendMessage(tar, "Please register, before getting auth");
    8.             return;
    9.         }
    10.         if (commandData.substring(pos+1) === "Kase" || commandData.substring(pos+1) === "Neos") {
    11.             if (newauth < 3) {
    12.             normalbot.sendMessage(src, "You do not have permission to change the auth of " + name + " below Owner.");
    13.             return;
    14.             }
    15.             if (newauth > 3) {
    16.             sys.changeAuth(tar, newauth);
    17.             sys.changeDbAuth(name, newauth);
    18.             if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    19.             else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    20.             return;
    21.             }
    22.         }
    23.         if (tar !== undefined) sys.changeAuth(tar, newauth);
    24.         else sys.changeDbAuth(name, newauth);
    25.         if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    26.         else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    27.         return;
    28.     }
    Thanks for your help Moogle. :grin:
     
  10. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    And for my other question, is this right:
    Code (text):
    1.     if (sys.ip(src) == sys.dbIp("Kase") || sys.name(src).toLowerCase() == "Neos") {
    2.         if (command == "imp") {
    3.             SESSION.users(src).impersonation = commandData;
    4.             normalbot.sendMessage(src, "Now you are " + SESSION.users(src).impersonation + "!", channel);
    5.             return;
    6.         }
    7.         if (command == "impoff") {
    8.            delete SESSION.users(src).impersonation;
    9.            normalbot.sendMessage(src, "Now you are yourself!", channel);
    10.            return;
    11.         }
    12.     }
     
    Last edited: Sep 26, 2014
  11. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    It didn't work because the names need to be written in lowercase. Like "kase" not "Kase". This also makes it case insensitive. At the moment it's not case insensitive.
     
  12. Kase

    Kase Member

    Joined:
    Mar 12, 2014
    Messages:
    148
    Likes Received:
    3
    "if (name === "kase" || name="neos")" wasn't case insensitive (I tested it). "if (name.toLowerCase() === "kase" || name.toLowerCase() ==="neos")" worked.
    Code (text):
    1.     if (command == "changeauth" || command == "changeauths") {
    2.         var pos = commandData.indexOf(' ');
    3.         if (pos == -1) return;
    4.         var newauth = commandData.substring(0, pos), name = commandData.substring(pos+1), tar = sys.id(name), silent = command == "changeauths";
    5.         if (newauth > 0 && !sys.dbRegistered(name)) {
    6.             normalbot.sendMessage(src, "This person is not registered");
    7.             normalbot.sendMessage(tar, "Please register, before getting auth");
    8.             return;
    9.         }
    10.         if (name.toLowerCase() === "kase" || name.toLowerCase() === "neos") {
    11.             if (newauth < 3) {
    12.             normalbot.sendMessage(src, "You do not have permission to change the auth of " + name + " below Owner.");
    13.             return;
    14.             }
    15.             if (newauth > 3) {
    16.             sys.changeAuth(tar, newauth);
    17.             sys.changeDbAuth(name, newauth);
    18.             if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    19.             else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    20.             return;
    21.             }
    22.         }
    23.         if (tar !== undefined) sys.changeAuth(tar, newauth);
    24.         else sys.changeDbAuth(name, newauth);
    25.         if (!silent) normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth);
    26.         else normalbot.sendAll("" + sys.name(src) + " changed auth of " + name + " to " + newauth, staffchannel);
    27.         return;
    28.     }
    And is this right:
    Code (text):
    1.     if (sys.ip(src) == sys.dbIp("kase") || sys.name(src).toLowerCase() == "neos") {
    2.         if (command == "imp") {
    3.             SESSION.users(src).impersonation = commandData;
    4.             normalbot.sendMessage(src, "Now you are " + SESSION.users(src).impersonation + "!", channel);
    5.             return;
    6.         }
    7.         if (command == "impoff") {
    8.            delete SESSION.users(src).impersonation;
    9.            normalbot.sendMessage(src, "Now you are yourself!", channel);
    10.            return;
    11.         }
    12.     }
    Don't think it is.