I am currently working on a website for my Dragon Nest private server and i thought i would give you guys some usefull queries and code for your own website!
Config.php
Login.php I have not yet coded in SESSION_START(), so this is up to you to figure that out.
Teleportplayer.php This teleports the player to the given X,Y and Z coordinates. I'm still working on this, might add features like teleport to other players and teleport to a list of towns.
Usersonline.php At the moment it shows the actual characters online, I will update this but I have no time at the moment
Index.php I'm working on this as i'm writing this and I will post a working website as soon as i am done. Although I will NOT decorate this site. I will only make a simple Admin panel thats about it.
Config.php
Code:
<?php
//Dont delete
error_reporting(E_ALL ^ E_NOTICE);
//Edit stuff below, to your server details
//Change "DNSVR01\SQLExpress" to your server, example: "SERVERNAME\SQLExpress"
$sqlsrv_host = "DNSVR01\SQLExpress";
$sqlsrv_db1 = array( "Database"=>"dnmembership");
$sqlsrv_db2 = array( "Database"=>"dngsm");
$sqlsrv_db3 = array( "Database"=>"dnserverlog");
$sqlsrv_db4 = array( "Database"=>"dnstaging");
$sqlsrv_db5 = array( "Database"=>"dnworld");
$conn1 = sqlsrv_connect( $sqlsrv_host, $sqlsrv_db1);
$conn2 = sqlsrv_connect( $sqlsrv_host, $sqlsrv_db2);
$conn3 = sqlsrv_connect( $sqlsrv_host, $sqlsrv_db3);
$conn4 = sqlsrv_connect( $sqlsrv_host, $sqlsrv_db4);
$conn5 = sqlsrv_connect( $sqlsrv_host, $sqlsrv_db5);
?>
Login.php I have not yet coded in SESSION_START(), so this is up to you to figure that out.
Code:
<?php
//include config for db and session
include('config.php');
//Set the username variabele
$username = $_POST['username'];
//This 'if' checks if a password reset for a username has been asked.
if ($_POST['tosetusername'] != ""){
//Set the username of the to-be changed user
$user = $_POST['tosetusername'];
//Query to get the id of the user that should get the password changed
//$conn1, this is a variabele from the config.php that creates db connection
$getid = sqlsrv_query($conn1,"SELECT AccountID FROM dnmembership.dbo.Accounts WHERE AccountName = '".$user."'");
//This sets the result of the query to an array. Only it will most likely result one row. Because of this you can ask for the answers immediately
$get = sqlsrv_fetch_array($getid,SQLSRV_FETCH_ASSOC);
//Store id to make next query shorter
$id = $get['AccountID'];
//Query of the password change. Speaks for itself
sqlsrv_query($conn1,"UPDATE dnmembership.dbo.Accounts SET
Passphrase = dnmembership.dbo.FN_HashPassphrase2('" . $_POST . "[tosetpassword]'," . $id . ") WHERE AccountID = " . $id);
}
//This is launched when a login call has been made
if($username != "") {
//Get the result query of the username
$getid = sqlsrv_query($conn1,"SELECT * FROM dnmembership.dbo.Accounts WHERE AccountName = '".$username."'");
//get result array Most likely will result a single row since a username probably is unique
$get = sqlsrv_fetch_array($getid,SQLSRV_FETCH_ASSOC);
//Catches possible problems with id's in the next query
if ($get[AccountID] == "") {
$tempId = 0;
} else{
$tempId = $get[AccountID];
}
//Get the password that is used for a specific user. It uses the post password and the id of the getid variabele. If succes it will result a row.
$getid = sqlsrv_query($conn1,"SELECT * FROM dnmembership.dbo.Accounts WHERE
Passphrase = dnmembership.dbo.FN_HashPassphrase2('" . $_POST . "[password]'," . $tempId . ")");
//Sets the result to an array. Will most likely give one or 0 rows
$get2 = sqlsrv_fetch_array($getid,SQLSRV_FETCH_ASSOC);
//Check if user is able to login
if(($get2['Passphrase'] == $get['Passphrase']) and ($get2['Passphrase'] != "")) {
//Do succes things, could be a message, session, or header for heavens sake
$error = "succes";
header('Location: index.php');
echo "LOGGEDIN";
} else {
//You didnt write the correct login, you noob. :3
$error = "You noob <3";
}
} else {
$error = "Could not login for given reasons";
}
echo $error;
?>
<h3>Login </h3>
<form class="login-form" action="login.php" method="post">
<input name="username" type="text" placeholder="Username" />
<input name="password" type="password" placeholder="Password" />
<br />
<button class="submit" type="submit" value="Log in">Log in</button>
</form>
<br />
<h3>Reset password</h3>
<form class="login-form" action="login.php" method="post">
<input name="tosetusername" type="text" placeholder="Username" />
<input name="tosetpassword" type="password" placeholder="Password" />
<br />
<button class="submit" type="submit" value="Reset">Reset</button>
</form>
<br />
Teleportplayer.php This teleports the player to the given X,Y and Z coordinates. I'm still working on this, might add features like teleport to other players and teleport to a list of towns.
Code:
Work in progress, ETA later today
Usersonline.php At the moment it shows the actual characters online, I will update this but I have no time at the moment
Code:
<?php
include 'config.php';
$query = sqlsrv_query($conn1, "
SELECT *
FROM dnmembership.[dbo].DNAuth
where CertifyingStep = 2"
);
$check = false;
$query2 = sqlsrv_query($conn1, "
SELECT *
From dnworld.[dbo].Guilds"
);
echo "<h3>Users online</h3><p>";
while($row = sqlsrv_fetch_array($query,SQLSRV_FETCH_ASSOC)){
$check = true;
echo $row['CharacterName']. '<br/>';
}
if(!$check){
echo "No users currently online";
}
?>
Index.php I'm working on this as i'm writing this and I will post a working website as soon as i am done. Although I will NOT decorate this site. I will only make a simple Admin panel thats about it.
Code:
Work in progress, ETA give me some time :3