Bnc Interface
Dieser Schnipsel ist ein Prototyp für ein Bouncer Interface
für IRC.
|
Script: |
<?php
class psybnc {
var $fp = false;
var $server_ip;
var $server_port;
var $admin_ident;
var $admin_nick;
var $admin_pass;
var $get_string;
var $send_user;
var $send_pw;
var $send_vhost;
var $send_leavemsg;
var $send_addserver;
var $send_delserver;
var $send_channel;
var $send_msg;
#########################
# CONNECTEN + EINLOGGEN #
#########################
function connect($server_ip, $server_port,
$admin_ident, $admin_nick, $admin_pass) {
$this->fp
=
fsockopen($server_ip, $server_port);
$this->server_ip
= $server_ip;
$this->server_port
= $server_port;
$this->admin_ident
= $admin_ident;
$this->admin_nick
= $admin_nick;
$this->admin_pass
= $admin_pass;
if(!$this->fp) {
die
("Connection Fehler");
}else{
fputs($this->fp,"user
$admin_ident $admin_ident $admin_ident@ :$admin_nick\r\n");
fputs($this->fp,"nick
$admin_nick\r\n");
fputs($this->fp,"pass
$admin_pass\r\n");
}
#set_time_limit(10);
}
######################
# CONNECTION BEENDEN #
######################
function close() {
fputs($this->fp,
"QUIT\r\n");
fclose($this->fp);
}
##################
# DATEN AUSLESEN #
##################
function rData() {
$this->get_string
= "";
while($get_data =
fgets($this->fp, 512)) {
$cmd_temp = explode("
",$get_data);
if(sizeof($cmd_temp)>3)
{
$cmd_type=$cmd_temp[1];
if($cmd_type == "PRIVMSG") {
$temp_string = strstr($get_data, $this->admin_ident."
:");
$temp_string = substr( strstr($temp_string,
":") , 1);
$this->get_string = $this->get_string."<br>".$temp_string;
}
}
}
}
######################
# ALLE USER AUSLESEN #
######################
function BWHO() {
fputs($this->fp, "BWHO
\r\n");
}
##############
# USER ADDEN #
##############
function cmd_adduser($send_user) {
$this->send_user
= $send_user;
fputs($this->fp, "adduser $send_user
:$send_user\r\n");
}
################
# USER LÖSCHEN #
################
function cmd_deluser($send_user) {
$this->send_user
= $send_user;
fputs($this->fp, "deluser $send_user\r\n");
}
###################################
# ADMIN / EIGENES PASSWORT ÄNDERN #
###################################
function cmd_changepw($send_pw) {
$this->send_pw =
$send_pw;
fputs($this->fp,
"password $send_pw\r\n");
}
########################
# USER PASSWORT ÄNDERN #
########################
function cmd_changepw_user($send_user,
$send_pw) {
$this->send_user
= $send_user;
$this->send_pw =
$send_pw;
fputs($this->fp,
"password $send_user:$send_pw\r\n");
}
######################
# ADMIN STATUS GEBEN #
######################
function cmd_makeadmin($send_user) {
$this->send_user
= $send_user;
fputs($this->fp,
"madmin $send_user :$send_user\r\n");
}
##########################
# ADMIN STATUS WEGNEHMEN #
##########################
function cmd_makeuser($send_user) {
$this->send_user
= $send_user;
fputs($this->fp,
"unadmin $send_user\r\n");
}
###################
# VHOST FESTLEGEN #
###################
function cmd_vhost($send_vhost) {
$this->send_vhost
= $send_vhost;
fputs($this->fp,
"bvhost $send_vhost\r\n");
}
################
# server adden #
################
function
cmd_addserver($send_addserver) {
$this->send_addserver
= $send_addserver;
fputs($this->fp,
"addserver $send_addserver\r\n");
}
##################
# server löschen #
##################
function
cmd_delserver($send_delserver) {
$this->send_delserver
= $send_delserver;
fputs($this->fp,
"delserver $send_delserver\r\n");
}
#######################
# LEAVE MSG FESTLEGEN #
#######################
function cmd_leavemsg($send_leavemsg)
{
$this->send_leavemsg
= $send_leavemsg;
fputs($this->fp,
"leavemsg $send_leavemsg\r\n");
}
#################
# /JOIN CHANNEL #
#################
function cmd_join($send_channel) {
$this->send_channel
= $send_channel;
fputs($this->fp,
"join $send_channel\r\n");
}
#######################
# /JOIN AND SAY HELLO #
#######################
function cmd_joinhello($send_channel,
$send_msg) {
$this->send_channel
= $send_channel;
fputs($this->fp,
"join $send_channel\r\n");
fputs($this->fp,
"PRIVMSG $send_channel :$send_msg\r\n");
}
##################
# /LEAVE CHANNEL #
##################
function cmd_leave($send_channel) {
$this->send_channel
= $send_channel;
fputs($this->fp,
"part $send_channel\r\n");
}
###################
# /PLAYPRIVATELOG #
###################
function cmd_playprivatelog() {
fputs($this->fp,
"PLAYPRIVATELOG\r\n");
}
####################
# /ERASEPRIVATELOG #
####################
function cmd_eraseprivatelog() {
fputs($this->fp,
"ERASEPRIVATELOG\r\n");
}
}
?>
|
Beispiel für user/bnc adden:
Code: |
$bnc = new psybnc();
$bnc->connect("127.0.0.1","40000","root","root","passwort");
$bnc->cmd_adduser("peter");
$bnc->cmd_changepw_user("peter",
"peterpass");
$bnc->close();
|
Wenn man spassig ist, kann man auch noch die antwort
abfangen:
Code: |
$bnc->rData();
echo $bnc->get_string;
|
Oder den bnc einen Channel joinen und Hallo sagen lassen:
Code: |
$bnc->cmd_joinhello("#channel",
"hallo und bis später, euer peter");
$bnc->cmd_leave("#channel");
|
|
|