PDA

View Full Version : [PHP] Movechar


Magoth78
08-24-2005, 03:55 AM
Hello there,

After some time, I finally coded a simple PHP movechar script.
Once you have entered your charname and accountname, it will verify if the row matches and will send you to the safe point of the zone where your character is in.
Actually, you can't zone in an other zone than the actual one cause I've coded it so people don't use movechar as a cheat (on my server at least).

Here's the code: This is my 2nd php script so be cool if you see a lot of newbish code errors...


<?php

$host = 'your_host.com';
$dbuser = 'user';
$dbpass = 'password';
$db = 'dbname';

$link = mysql_connect($host, $dbuser, $dbpass)
OR die(mysql_error());

if (!mysql_select_db($db, $link))
{
echo 'Unable to connect to the database.';
echo mysql_errno($link) . ": " . mysql_error($link). "\n";
exit;
}


$charname = $_POST['charname'];
$accountname = $_POST['accountname'];


$query = mysql_query("SELECT zonename FROM empire.character_ WHERE name='$charname';");
if (!$query) {
die('Could not query:' . mysql_error());
}
$find_zonename = mysql_result($query, 0);
echo "Found zone is..... :<b> $find_zonename </b> \r\n <br>";

$query2 = mysql_query("SELECT zoneid FROM character_ WHERE zonename='$find_zonename' LIMIT 1;");
if (!$query2) {
die('Could not query:' . mysql_error());
}
$find_zoneid = mysql_result($query2, 0);


$query3 = mysql_query("SELECT name FROM account WHERE charname='$charname';");
if (!$query3) {
die('Could not query:' . mysql_error());
}
$find_accountname = mysql_result($query3, 0);


$query4 = mysql_query("SELECT safe_x FROM zone WHERE zoneidnumber='$find_zoneid';");
if (!$query4) {
die('Could not query:' . mysql_error());
}
$find_safex = mysql_result($query4, 0);

$query5 = mysql_query("SELECT safe_y FROM zone WHERE zoneidnumber='$find_zoneid';");
if (!$query5) {
die('Could not query:' . mysql_error());
}
$find_safey = mysql_result($query5, 0);


$query6 = mysql_query("SELECT safe_z FROM zone WHERE zoneidnumber='$find_zoneid';");
if (!$query6) {
die('Could not query:' . mysql_error());
}
$find_safez = mysql_result($query6, 0);


if($accountname != $find_accountname)
{
echo ("Account name matched with this char ... <b> Failed! </b> \r\n <br> <b> Verify your Character's name and your's Account's name!");
mysql_close($link);
exit;
}


if($accountname = $find_accountname)
{
echo ("Account name matched with this char ... <b> Ok! </b> \r\n <br>");
$charmove = mysql_query("UPDATE character_ SET zonename='$find_zonename', zoneid='$find_zoneid', x='$find_safex', y='$find_safey', z='$find_safez' WHERE name='$charname';");
if (!$charmove) {
die('Could not query:' . mysql_error());
}
echo ("Character moved to his actual zone safe point. \r\n");
mysql_close($link);
}

?>


And a simple html form:

<HTML>
<BODY>
<FORM METHOD="post" ACTION="char.php">
Character Name : <INPUT TYPE="text" SIZE="30" NAME="charname"><BR>
Account Name : <INPUT TYPE="text" SIZE="20" NAME="accountname"><BR>
<INPUT TYPE="submit" VALUE="Envoyer" NAME="valider">
</FORM>
</BODY>
</HTML>



Installed on empire and working fine.

Mag

mrea
08-24-2005, 04:02 AM
I haven't tested it, so I probably shouldn't say this yet :-P, but excellent job. I will definitely use this.

Magoth78
08-25-2005, 12:20 AM
Just a little fix on my code.

Instead of checking the AccountName for the Character, it will check the AccountID .
As noticed, in the Account table, you only have 1 character per account created, this is the first character. And you don't have the others created chars in the account table, it's why I fixed that by checking the character AccountID.



<?php

$host = 'your_host';
$dbuser = 'user';
$dbpass = 'password';
$db = 'dbname';

$link = mysql_connect($host, $dbuser, $dbpass)
OR die(mysql_error());

if (!mysql_select_db($db, $link))
{
echo 'Unable to connect to the database.';
echo mysql_errno($link) . ": " . mysql_error($link). "\n";
exit;
}

// Query
$charname = $_POST['charname'];
$accountname = $_POST['accountname'];


$query = mysql_query("SELECT zonename FROM empire.character_ WHERE name='$charname';");
if (!$query) {
die('Could not query:' . mysql_error());
}
$find_zonename = mysql_result($query, 0);
echo "Found zone is..... :<b> $find_zonename </b> \r\n <br>";

$query2 = mysql_query("SELECT zoneid FROM character_ WHERE zonename='$find_zonename' LIMIT 1;");
if (!$query2) {
die('Could not query:' . mysql_error());
}
$find_zoneid = mysql_result($query2, 0);


$query3 = mysql_query("SELECT account_id FROM character_ WHERE name='$charname';");
if (!$query3) {
die('Could not query:' . mysql_error());
}
$find_accountid = mysql_result($query3, 0);


$query3a = mysql_query("SELECT id FROM account WHERE name='$accountname';");
if (!$query3a) {
die('Could not query:' . mysql_error());
}
$verifyaccount_id = mysql_result($query3a, 0);


$query4 = mysql_query("SELECT safe_x FROM zone WHERE zoneidnumber='$find_zoneid';");
if (!$query4) {
die('Could not query:' . mysql_error());
}
$find_safex = mysql_result($query4, 0);


$query5 = mysql_query("SELECT safe_y FROM zone WHERE zoneidnumber='$find_zoneid';");
if (!$query5) {
die('Could not query:' . mysql_error());
}
$find_safey = mysql_result($query5, 0);


$query6 = mysql_query("SELECT safe_z FROM zone WHERE zoneidnumber='$find_zoneid';");
if (!$query6) {
die('Could not query:' . mysql_error());
}
$find_safez = mysql_result($query6, 0);
//echo $find_accountname;

if($find_accountid != $verifyaccount_id)
{
echo ("Account name matched with this char ... <b> Failed! </b> \r\n <br> <b> Verify your Character's name and your's Account's name!");
mysql_close($link);
exit;
}


if($find_accountid = $verifyaccount_id)
{
echo ("Account name matched with this char ... <b> Ok! </b> \r\n <br>");
$charmove = mysql_query("UPDATE character_ SET zonename='$find_zonename', zoneid='$find_zoneid', x='$find_safex', y='$find_safey', z='$find_safez' WHERE name='$charname';");
if (!$charmove) {
die('Could not query:' . mysql_error());
}
echo ("Character moved to his actual zone safe point. \r\n");
mysql_close($link);
}

?>


Enjoy,

Mag