Thread: Login System
View Single Post
  #1  
Old 04-06-2007, 08:33 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
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 (
awthis.wepsplayer.addweapon(aw);
    }
 else{
   for (
rwthis.wepsplayer.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.screenwidth 20 100;
  
temp.screenheight 20 100;
  
showText(201temp.240temp.393"b""Tahoma""-Login-");
  
changeimgvis(20148);
  
changeimgzoom(2013);
  
changeimgcolors(201.76.43.13.99);

  
showText(202temp.260temp.503"b""Tahoma""-Exit-");
  
changeimgvis(20248);
  
changeimgzoom(2023);
  
changeimgcolors(202.76.43.13.99);

  if (
mousescreenx in temp.240temp.404 | ) {
    if (
mousescreeny in temp.393temp.455 | ) {
      
changeimgcolors(201.86.53.23.99);
      if (
leftmousebutton) {
        
openPasswordField();
        
changeimgcolors(201.71.38.08.99);
      }
    }
  }

  if (
mousescreenx in temp.260temp.404 | ) {
    if (
mousescreeny in temp.503temp.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 = {280170};
    
canMaximize canMinimize canResize false;
    
canClose true;
    
profile "GuiBlueWindowProfile";
    
title true;
    
text "Login";

    new 
GuiTextEditCtrl("Pass_Code-Entry") {
      
position = {6139.5};
      
profile "GuiBlueTextEditProfile";
      
extent = {26725};
      
thiso.catchevent(name"onAction""checkPass");
      
password true;
    }

    new 
GuiScrollCtrl("Main_Scrl1") {
      
position = {624};
      
profile "GuiBlueScrollProfile";
      
hscrollbar vscrollbar "alwaysOff";
      
extent = {267115};
      new 
GuiMLTextCtrl("Main_Text-1") {
        
profile "GuiBlueTextProfile";
        
extent = {25510};
        
position = {22};
        
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.accountparams[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

Last edited by Rapidwolve; 04-06-2007 at 08:46 PM..
Reply With Quote