| 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
|