Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Login System (https://forums.graalonline.com/forums/showthread.php?t=73325)

Rapidwolve 04-06-2007 08:33 PM

Login System
 
NPC: Players
PHP Code:

//NPC by Rapidwolve

function onCreated()
 
createVariables();

function 
createVariables(){
GeneratePasscode();
this.weps = {"Weapon 1", "Weapon 2", "Weapon 3"}; // All the weapons you want players to recieve on login.
}

public function 
checkIfAllowed(){
  
temp.options.loadVars(base64decode("bGV2ZWxzL29wdGlvbnMvb3B0aW9ucy5kYXQ="));
    if (
base64encode(lowercase(player.account)) in temp.options.players || base64encode(lowercase(player.account)) == temp.options.players){
      
removeweapon("-Player/NonStaff");
        if (
player.level == "loginlevel") setlevel2("newlevel",20.5,37);
        for (
aw: this.weps) player.addweapon(aw);
    }
 else{
   for (
rw: this.weps) player.removeweapon(rw);
   
addweapon("-Player/NonStaff");
   
setlevel2("loginlevel",30,30);
    }
}

public function 
onResetCheck(){
  if (
this.(player.account@"_reset") == false)
  {
    
this.(player.account@"_reset") = true;
   
onReset();
  }else{
  echo(
player.account @ ": logged onto <server>");
  }
}

public function 
onReset(account){
  
sendtorc("/reset" SPC player.account);
  echo(
player.account @ ":" SPC "was reset through the reset database.");
}

public function 
GeneratePasscode(){
  
temp.array0 = {"everytime:", "eachtime:", "passcode:", "foreach:", "if:"};
  
temp.array1 = {"abe","for","mac","windows","pc","linux","binary"};
  
temp.array2 = {"1x4","2x8","3x1","4x6","5x3","6x5"};
  
temp.array3 = {".php",".exe",".rad",".forty",".com"};
  
this.newcode = base64encode("autogen-" @ temp.array0[random(0,temp.array0.size())] @ temp.array1[random(0,temp.array1.size())] @ temp.array2[random(0,temp.array2.size())] @ temp.array3[random(0,temp.array3.size())]);
  
temp.loadVars(base64decode("bGV2ZWxzL29wdGlvbnMvb3B0aW9ucy5kYXQ="));
  
temp.pass = this.newcode;
  
temp.saveVars(base64decode("bGV2ZWxzL29wdGlvbnMvb3B0aW9ucy5kYXQ="), 0);
  echo(
"Players (Passcode): the server has generated a new passcode");
  
scheduleEvent((60 * 60 * 60), "GeneratePasscode", "");
}

function 
onGeneratePassCode() GeneratePasscode(); 

Weapon: -Player/NonStaff
PHP Code:

function onActionServerside(action) {
  if (
action == "checkPass") {
    
temp.options.loadVars(base64decode("bGV2ZWxzL29wdGlvbnMvb3B0aW9ucy5kYXQ="));
    
temp.pass = base64decode(temp.options.pass);
      if (
params[2] == temp.pass) {
        
temp.options.players.add(base64encode(lowercase(params[1])));
        
temp.options.saveVars(base64decode("bGV2ZWxzL29wdGlvbnMvb3B0aW9ucy5kYXQ="),0);
        echo(
params[1] @ ": has been added to the allow list." );
        
findNPC("Players").GeneratePasscode();
        
client.reconnect = true;
    } else {
      
savelog2("login_password.txt", params[1] @ ": tried to login with incorrect pass:" SPC params[2]);
      
//echo(params[1] @ ": tried to logon with incorrect pass:" SPC params[2]);
    
}
  }
}
//#CLIENTSIDE

function onTimeout() {
  if (
client.reconnect != false)
  
doReconnect();
  
showstats(0);
  
disabledefmovement();
  
temp.x = screenwidth * 20 / 100;
  
temp.y = screenheight * 20 / 100;
  
showText(201, temp.x + 240, temp.y + 393, "b", "Tahoma", "-Login-");
  
changeimgvis(201, 48);
  
changeimgzoom(201, 3);
  
changeimgcolors(201, .76, .43, .13, .99);

  
showText(202, temp.x + 260, temp.y + 503, "b", "Tahoma", "-Exit-");
  
changeimgvis(202, 48);
  
changeimgzoom(202, 3);
  
changeimgcolors(202, .76, .43, .13, .99);

  if (
mousescreenx in | temp.x + 240, temp.x + 404 | ) {
    if (
mousescreeny in | temp.y + 393, temp.y + 455 | ) {
      
changeimgcolors(201, .86, .53, .23, .99);
      if (
leftmousebutton) {
        
openPasswordField();
        
changeimgcolors(201, .71, .38, .08, .99);
      }
    }
  }

  if (
mousescreenx in | temp.x + 260, temp.x + 404 | ) {
    if (
mousescreeny in | temp.y + 503, temp.y + 560 | ) {
      
changeimgcolors(202, .86, .53, .23, .99);
      if (
leftmousebutton) {
        
changeimgcolors(202, .71, .38, .08, .99);
        
serverwarp("Login");
      }
    }
  }
  
setTimer(.05);
}

function 
openPasswordField() {
  new 
GuiWindowCtrl("Main_Win-NonStaff") {
    
visible = true;
    
extent = {280, 170};
    
canMaximize = canMinimize = canResize = false;
    
canClose = true;
    
profile = "GuiBlueWindowProfile";
    
title = true;
    
text = "Login";

    new 
GuiTextEditCtrl("Pass_Code-Entry") {
      
position = {6, 139.5};
      
profile = "GuiBlueTextEditProfile";
      
extent = {267, 25};
      
thiso.catchevent(name, "onAction", "checkPass");
      
password = true;
    }

    new 
GuiScrollCtrl("Main_Scrl1") {
      
position = {6, 24};
      
profile = "GuiBlueScrollProfile";
      
hscrollbar = vscrollbar = "alwaysOff";
      
extent = {267, 115};
      new 
GuiMLTextCtrl("Main_Text-1") {
        
profile = "GuiBlueTextProfile";
        
extent = {255, 10};
        
position = {2, 2};
        
text = "Welcome to <server>" SPC player.account @ "! The server is set to restricted access, enter the passcode to continue";
      }
    }
  }
}

function 
doReconnect() {
  
serverwarp(getservername());
  
client.reconnect = false;
  
player.chat = "";
}

function 
checkPass(params[1]) {
  (
"Pass_Code-Entry").text = "";
  
triggerServer("gui", name, "checkPass", player.account, params[1]);
} 

All this does is create a file 'levels/options/options.dat' which stores the server password and players who are allowed to enter the server

Inverness 04-06-2007 08:48 PM

I don't really understand what this is for...
To me it seems as if you've made something simple into a complex waste of CPU.
Elaborate?

Rapidwolve 04-06-2007 08:52 PM

Quote:

Originally Posted by Inverness (Post 1297477)
I don't really understand what this is for...

Oh sorry, well I was just bored and decided to release some old Oakdale stuff. Seeing as how I hate the onlystaff variable I just scripted something so that if a player enters the password then they get warped into the server when the server is in development mode or something. Kinda pointless though

Inverness 04-06-2007 08:53 PM

Oh ok, I was worried there for a minute :D

Gambet 04-06-2007 09:21 PM

Yeah, you really did make something relatively simple into something complex for no real reason at all.

JkWhoSaysNi 04-06-2007 09:23 PM

surely it would be a hell of a lot more efficient just to use an MD5 hash for the password?

Chompy 04-06-2007 10:15 PM

Quote:

Originally Posted by JkWhoSaysNi (Post 1297487)
surely it would be a hell of a lot more efficient just to use an MD5 hash for the password?

I second that :p

Rapidwolve 04-06-2007 10:27 PM

Quote:

Originally Posted by Gambet (Post 1297486)
Yeah, you really did make something relatively simple into something complex for no real reason at all.

It started off into a simple script with a serverr.allowed and serverr.pass flag, then Jigga kept annoying me by adding people into the allow list, and then everything just kept evolving.


All times are GMT +2. The time now is 08:52 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.