Estoy desarrollando un webchat puramente en php.
Logro conectarme, pero tengo un par de problemas:
No logro que la informacion (lo que habla cada uno) aparezca al final, solo logro que aparezca cuando termina el script.
No se como hacer la "cajita" para que uno hable, se hacer formularios y todo, pero tendria que empezar denuevo el script cada vez que le doy "enviar"
Desde ya muchas gracias,
Koz
PD: Si es posible todo en php mejor, pero si tengo que agregar otro lenguaje lo agregare sin problemas
EDIT:
el codigo:
Código PHP:
Ver original<?php
/* --- Varibles and Config Info --- */
'server' => 'irc.toribash.com',
'port' => 6667,
'name' => 'Kozbot',
'nick' => 'Kozzy',
'channel' => '#koz',
'logging' => false,
'warning' => false,
);
// mysql
if (!$link) {
}
if (!$db_selected) {
}
/* --- IRCBot Class --- */
class IRCBot {
//This is going to hold our TCP/IP connection
var $socket;
//This is going to hold all of the messages both server and client
//var $logging = true;
/*
Construct item, opens the server connection, logs the bot in
@param array
*/
function __construct($config)
{
$this->socket = fsockopen($config['server'], $config['port']); $this->login($config);
$this->main($config);
}
/*
Logs the bot in on the server
@param array
*/
function login($config)
{
$this->send_data('USER', $config['nick'].' KozEnko '.$config['nick'].' :'.$config['name']);
$this->send_data('NICK', $config['nick']);
$this->join_channel($config['channel']);
if($config['logging']) {
$logfile = fopen("$date-log.html","a"); fwrite($logfile,"<br/>**************** Logging Started at $time ****************<br/>");
//Warn that logging has been enabled
if($config['warning']) {
$this->send_data('PRIVMSG '.$config['channel'].' :', "Chat Logging has been [Enabled]");
}
}
}
/*
This is the workhorse function, grabs the data from the server and displays on the browser
*/
function main($config)
{
$data = fgets($this->socket, 256);
$mensaje_base = strstr($data, ':'); $mensaje_basee = substr($mensaje_base, 1); $mensajee = strstr($mensaje_basee, ':'); $mensaje = substr($mensajee, 1);
if($this->ex[0] == 'PING')
{
$this->send_data('PONG', $this->ex[0]); //Plays ping-pong with the server to stay connected.
}
//Logs the chat
if($config['logging'])
{
$logtxt = $this->filter_log($this->ex[1], $this->ex[2], $this->ex[0], $this->get_msg($this->ex)); //Gets human readable text from irc data
if($logtxt != null) { //Writes to log if it is a message
$logfile = fopen("$date-log.html","a"); fwrite($logfile,"$logtxt<br />"); }
}
$this->main($config);
}
/* --- IRCBot Class's Functions --- */
function filter_log($type, $chan, $nick, $msg) {
$nick = ltrim($nick, ":");
if($type == "PRIVMSG") {
return date("[H:i]")." <".$nick."> ".$msg; }
return null ;
}
function get_msg($n) {
$message = "";
for($i=$n; $i <= (count($this->ex)); $i++) { $message .= $this->ex[$i]." "; } return $message;
}
function send_data($cmd, $msg = null) {
if($msg != null) {
fputs($this->socket, $cmd.' '.$msg."\r\n"); echo '<strong>'.$cmd.' '.$msg.'</strong><br />';
} else {
fputs($this->socket, $cmd."\r\n"); echo '<strong>'.$cmd.'</strong><br />';
}
}l
}
$bot = new IRCBot($config);
?>