forked from AlexJezior/TheFallenImmortals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
givegold.php
45 lines (41 loc) · 2.03 KB
/
givegold.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
session_name("icsession");
session_start();
include('db.php');
include('active.php');
$getchar = mysqli_query($conn, "SELECT * FROM characters WHERE id='".$_SESSION['userid']."'");
$char = mysqli_fetch_assoc($getchar);
$display = "";
if(isset($_POST['toUsername']) && isset($_POST['giveAmount']))
{
$to = $_POST['toUsername'];
$amount = $_POST['giveAmount'];
if(!ctype_digit($amount)){
$display .= "<center><font color=\'red\'>Invalid amount.</font></center>";
die();
}else{
if($char['gold'] < $amount)
{
$display .= "<center><font color=\'red\'>Not enough gold.</font></center>";
die();
}else{
$findCharacter = mysqli_query($conn, "SELECT * FROM characters WHERE username='".$to."'");
$countNumRows = mysqli_num_rows($findCharacter);
if($countNumRows == 0)
{
$display .= "<center><font color=\'red\'>No such character.</font></center>";
}else{
$to = mysqli_fetch_assoc($findCharacter);
$updateTo = mysqli_query($conn, "UPDATE characters SET gold=gold-'".$amount."' WHERE username='".$char['username']."'")or die("alert('Unable to remove gold. Tell admin.');");
$updateTo = mysqli_query($conn, "UPDATE characters SET gold=gold+'".$amount."' WHERE username='".$to['username']."'")or die("alert('Unable to add gold. Tell admin.');");
$display .= "<center><font color=\'green\'>You have given ".$to['username']." ".number_format($amount)." gold from your hand!</font></center>";
$datestamp = date("H:i:s");
$message = "<a href=\'javascript:toptell(\"".$char['username']."\");\'><font color=\'#FF7700\' style=\'text-decoration:none\'>".$char['username']."</font></a><font color=\'#FF7700\'> has given you ".number_format($amount)." gold from their hand.</font><br />";
$query = mysqli_query($conn, "INSERT INTO chatroom (`date`, `userlevel`, `username`, `to`, `message`) VALUES ('".$datestamp."', '4', 'PM', '".$to['username']."', '".$message."')")or die("alert('Unable to insert chat log. Tell the admin!');");
}
}
}
}
print("fillDiv('displayArea','".$display."');");
include('updatestats.php');
?>