Password Protection Script

Discussion in 'Server and Client Scripting' started by Astruvis, Jun 6, 2010.

  1. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Script v1.0
    Will be included in my scripts with the next version, does not contain other features.

    Code (javascript):
    1.  
    2. ({
    3. serverStartUp : function() {
    4.     this.afterNewMessage("Script Check: OK");
    5.     return; }
    6. ,
    7. afterNewMessage : function (message) {
    8.     if (message == "Script  Check: OK") {
    9.         if  (typeof password == 'undefined') {
    10.             password = new Array(); }
    11.         if  (typeof serverpass == 'undefined')  {
    12.             serverpass = ''; }
    13.         if  (typeof numUsers == 'undefined') {
    14.             numUsers = 0;}
    15.         }
    16.     }
    17. ,
    18. afterLogIn : function(src) {
    19.     numUsers += 1;
    20.     password[src] = sys.getVal('pass:'+sys.name(src));
    21.     if (serverpass != password[src] && serverpass != '')  {
    22.         sys.sendMessage(src,'~~Server~~:  The server is password protected, please enter the password using /pass  password.'); }
    23.     else {
    24.         sys.sendAll('~~Server~~: '+sys.name(src)+' has joined!'); }
    25.     return; }
    26. ,
    27. afterLogOut : function (src) {
    28.     numUsers -= 1; }
    29. ,
    30. beforeChatMessage: function(src, message)  {
    31.     sys.stopEvent();
    32.     if ((message[0] == '/' || message[0] == '!') &&  message.length > 1) {
    33.         print("Command -- " +  sys.name(src)  + ": " +  message);
    34.         var  command;
    35.         var  commandData;
    36.         var  pos = message.indexOf(' ');
    37.         if  (pos != -1) {
    38.             command =  message.substring(1, pos).toLowerCase();
    39.             commandData =  message.substr(pos+1); }
    40.          else  {
    41.             command =  message.substr(1).toLowerCase(); }
    42.         var  tar = sys.id(commandData);
    43.         if  (command == "pass" ||  command == "password") {
    44.             sys.saveVal('pass:'+sys.name(src),commandData);
    45.             password[src] = commandData;
    46.             if  (serverpass != password[src]  && serverpass != '') {
    47.                 sys.sendMessage(src,'~~Server~~:  Bad password, please enter the password using /pass password.');  }
    48.             else  {
    49.                 sys.sendAll('~~Server~~: '+sys.name(src)+' has joined!'); }
    50.             return; }
    51.         if  (command == "setpass" ||  command == "setpassword" && sys.auth(src) >= 2) {
    52.             sys.saveVal('pass:'+sys.name(src),commandData);
    53.             password[src] = commandData;
    54.             serverpass =  commandData;
    55.             sys.sendAll('~~Server~~: The password was changed by '+sys.name(src)+', please enter  the password using /pass password.');
    56.             return; }
    57.         if  (command == "removepass" ||  command == "removepassword" && sys.auth(src) >= 2) {
    58.             sys.removeVal('pass:'+sys.name(src));
    59.             password[src] = '';
    60.             serverpass = '';
    61.             sys.sendAll('~~Server~~: The password was removed by '+sys.name(src)+'.');
    62.             return; }
    63.         return;}
    64.     if (serverpass != password[src] && serverpass != '' &&  sys.auth(src) == 0) {
    65.         sys.sendMessage(src,'~~Server~~:  Please enter the password using /pass password.');
    66.         return; }
    67.     var  cnt = numUsers;
    68.     var  user = 0;
    69.     var  xx = sys.name(src) +': ' +  message;
    70.     print(xx);
    71.     while(user < cnt)
    72.         {
    73.         if  (sys.loggedIn(user) == true) {
    74.             if  (serverpass == password[user]  || serverpass == '' ||  sys.auth(user) > 0) {
    75.                 sys.sendMessage(user,xx); }
    76.             } else {
    77.             cnt += 1;}
    78.         user += 1; }
    79.     return; }
    80. })
     
    Last edited by a moderator: Jun 7, 2010
  2. Akusu

    Akusu Guest

    I honestly don't see what you're doing to blind the person. Odd...

    Nevermind. You're intercepting the sendAll()... that's kind of. Ugly. At least it works though.
     
  3. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    You call my scripts ugly?
    I couldn't even tell what on earth you were doing in yours, at least you can understand mine... <.<
     
  4. Akusu

    Akusu Guest

    Meh. It took me a while to figure out where it was in yours.

    Half of the complexity in mine is caused by javascript's handling of the "this" keyword which was preventing me from making the before chat message function unaffected by what commands were available.

    Edit: BTW, I was calling the solution ugly, not your script as a whole. It doesn't speak to your skills a programmer or anything like that.

    If you're sensing ruffled feathers though, it's that I don't appreciate someone declaring my code deprecated. (Depreciation is devaluing, not the same thing.)
     
    Last edited by a moderator: Jun 6, 2010
  5. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    this.bla() is kinda stupid how it works, but I've found that just writing bla() w/o this. seems to work in most cases.

    Btw, when an HTML tag is replaced, it is considered "depreciated". Im using it in a technical sense.

    Though one thing you should avoid is calling too many functions unless you need the use of an if return if return thing, I found that it makes things a lot more simple.

    The blind loop can handle a lot of sends at once, 100/second is not a problem for me.
     
    Last edited: Jun 6, 2010
  6. Akusu

    Akusu Guest

    Yeah, the technical term is "deprecated". No i.

    Calling functions isn't a bad thing either.
     
  7. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Lol I didn't even know those were 2 different words. <.<
    Well, calling functions isn't bad, but it makes it more complex imo.
    I think functions should only be called if you use it in the same place several times and its quite coplex, or if you need a value, etc.
    My script isn't a good example of that, since I have a function that calls sys.removeval()... <.<
     
  8. Tickle

    Tickle New Member

    Joined:
    May 17, 2010
    Messages:
    24
    Likes Received:
    0
    There's just so much unnecessary things done here, it's not even funny. We have to develop some type of standard to how to separate scriptable methods and in-program methods.

    If we want more scripting side, I suggest a bare-bones program that only refers to scripts to execute commands, such as sending messages, determining message color, ect.

    But if we actually wanted a more standard program, we would have mostly program, and very few things to do with the scripts.

    Right now, our scripts are trying to become the program, and trying to vouce for the features of it. We need to either open up scripting more, or simply close it so that only marginal commands are called to give a different aesthetic feel to each server.
     
  9. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    I strongly disagree. Scripting takes some of the load off of the programmer, and gives a touch of personality to the server.

    Scripting is open enough, any noob can start scripting, I didn't even know the javascript syntax when I started.
    And I have a major concern, if coyotte did it, it would say: +PASSWORDBOT: Password is incorrect.
     
  10. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    I think it'd be great if the auth was just part of the script with an 'Auth options' just adding appropriate code to the script. For example, making the right click menu an event and then just have an add function to add certain commands to it. So in Auth options, you could make any number of auth groups and give them default commands that will be converted into the functions in the script under that right click event. You would also need an event that triggers after the auth options is saved so that the variables containing the members of the auth groups are reset based on those options. And also, a way for the auth options to interpret the code you've added without using it.
     
  11. Tickle

    Tickle New Member

    Joined:
    May 17, 2010
    Messages:
    24
    Likes Received:
    0
    How do you disagree when I'm putting up two sides of an issue?

    Or are you disagreeing with the fact that there could be improvements to scripting openness?