thankyou
Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!
Echelon v2 is not yet officially released! If you cannot get this dev-version installed, revert to version 1 as available in our download section.

Author Topic: Adding the kick command - PHP Help!  (Read 2841 times)

Offline Kellithe

  • Jr. Member
  • **
  • Posts: 34
    • RoC
Adding the kick command - PHP Help!
« on: October 26, 2013, 11:44:20 PM »
Hey guys. On our servers we have rules for our admins, an order of events before they can ban someone. They have to:

Warn the person in ingame chat (can do it with echelon talkback)
Kick the person (Can NOT do it with echelon)
Tempban them for 30 minutes (can do it on client detail page)
And then finally permanent ban (can do it on client detail page)

As you can see, we can do everything we need to but kick the person. So I decided to see if I could fix this. Here's what I did:

In the clientdetails.php I changed lines 170-179 to read from this:
Code: [Select]
	  <td align="right"class="tabelkop">
    Comment
  </td>
<td><br>
<form name=textinput method="Post" Action="admin/textadd.php?id=<?php echo $row_rs_clientinfo['id']; ?>">
<input type="text" value="Enter new comment" Name="comment">
<input type="hidden" value="<?php echo $game; ?>" Name="game">
<input type="submit" name="submit1" value="update">
</form>
  </td>

To this:
Code: [Select]
	  <td align="right"class="tabelkop">
    Comment
    <br><br>
    Kick
  </td>
<td><br>
<form name=textinput method="Post" Action="admin/textadd.php?id=<?php echo $row_rs_clientinfo['id']; ?>">
<input type="text" value="Enter new comment" size="50" Maxlength="50" Name="comment">
<input type="hidden" value="<?php echo $game; ?>" Name="game">
<input type="submit" name="submit1" value="Update">
</form>
<form name=textinput method="Post" Action="admin/kick.php?id=<?php echo $row_rs_clientinfo['id']; ?>&pbid=<?php echo $row_rs_clientinfo['pbid']; ?>&clientname=<?php echo urlencode($row_rs_clientinfo['name']); ?>&client_ip=<?php echo $row_rs_clientinfo['ip']; ?>&game=<?php echo $game;?>">
<input type="text" value="Kicked by an Echelon WebAdmin" size="50" Maxlength="50" Name="reason">
<input type="hidden" value="<?php echo $game; ?>" Name="game">
<input type="submit" name="submit4" value="Kick">
</form>
  </td>

Then I created a file in the admin directory called kick.php (which was just a copy of tempban.php with a few changes). The code for it is:
Code: [Select]
<?php include "../ctracker.php"; ?>
<?php // Next line sets the echelon userlevel for this page. 1=superadmins - 2=admins - 3=moderators
$requiredlevel = 1;
require_once('../Connections/inc_config.php');
require_once('../login/inc_authorize.php');
require_once('../Connections/b3connect.php');
require_once('rcon.php');

$id = "0";
$pbid = "0";
$clientname = "Unknown";
$client_ip = "0.0.0.0";
$reason = "Kicked by an Echelon WebAdmin. (" . $_SESSION['xlradmin'] . ")";
$type = "Kick";
$redirectto = "../clients.php";

if (isset($_GET['id'])) {
$id = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
if (isset($_GET['pbid'])) {
$pbid = (get_magic_quotes_gpc()) ? $_GET['pbid'] : addslashes($_GET['pbid']);
}
if (isset($_GET['clientname'])) {
$clientname = (get_magic_quotes_gpc()) ? $_GET['clientname'] : addslashes($_GET['clientname']);
}
if (isset($_GET['client_ip'])) {
$client_ip = (get_magic_quotes_gpc()) ? $_GET['client_ip'] : addslashes($_GET['client_ip']);
}
if (isset($_GET['type'])) {
$type = (get_magic_quotes_gpc()) ? $_GET['type'] : addslashes($_GET['type']);
}
if (isset($_POST['reason'])) {
$reason = (get_magic_quotes_gpc()) ? $_POST['reason'] : addslashes($_POST['reason']);
  $reason .= " (by " . $_SESSION['xlradmin'] . ")";
}
if (isset($_SERVER['HTTP_REFERER'])) {
$redirectto = (get_magic_quotes_gpc()) ? $_SERVER['HTTP_REFERER'] : addslashes($_SERVER['HTTP_REFERER']);
}

// Insert code to update databasefield inactive in banstable to 1
$sql = "INSERT IGNORE INTO `penalties` (`id`, `type`, `duration`, `inactive`, `admin_id`, `time_add`, `time_edit`, `time_expire`, `reason`, `keyword`, `client_id`) VALUES ('', 'Kick', '0', '0', '0', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', '$reason', '', $id)";
mysql_select_db($database_b3connect, $b3connect);
mysql_query($sql, $b3connect);


// Rcon Kick [player_name] [reason]
$strippedcname = preg_replace('`\[[^\]]*\]`','',$clientname);
$command = "kick" . " " . $strippedcname . " " . $reason;
rcon ($command);

$redirect = "Location: " .  $redirectto;
header ($redirect);

?>

So, this MOSTLY works. It adds a kick command on the client details page just under the comment button. This doesn't (currently) check for user level, so levels 1 2 and 3 can see it.

The part I'm having problem with is at the end of the kick.php file. Specifically, this code:
Code: [Select]
// Rcon Kick [player_name] [reason]
$strippedcname = preg_replace('`\[[^\]]*\]`','',$clientname);
$command = "kick" . " " . $strippedcname . " " . $reason;
rcon ($command);

I had to add the line to strip clan tags from the name so when it goes to kick them (this is in Black Ops) it doesnt do 'rcon kick [clantag]nameofperson' which fails. So as I was saying, it partly works - it will kick the person, but it won't give the reason.

However, if I change the $command = "kick" to "say", then it will say in game 'Personsname Reason'

So it's passing the $reason along to the $command, and it works with the say command, just not kick. Maybe it's a syntax issue, I don't know. Hopefully I explained what's happening.

Any ideas?

Offline Kellithe

  • Jr. Member
  • **
  • Posts: 34
    • RoC
Re: Adding the kick command - PHP Help!
« Reply #1 on: October 28, 2013, 06:55:46 PM »
Good news/bad news!

Good news: I figured it out, I had to change the $command =  line to the following:

Code: [Select]
$command = "kick" . " " . '"' . $strippedcname . '"' . " " . '"' . $reason . '"';

Bad news: Unfortunately... the rcon kick command is actually a 5min temporary ban. To kick without banning you have to use clientkick but there's no way to get their client id from echelon (at least, no easy way for me to code it in) as that's beyond the limit of my ability.

Ah well.

 


Rate this page +1 at Google Search