changeset 1:7f01316130e8

Basic support for private messages in unrealircd proxy
author Ivo Smits <Ivo@UCIS.nl>
date Fri, 01 Apr 2011 17:02:41 +0200
parents dd81c38b513a
children 7e342a0a3b74
files client/debugclient.php unrealircdlink/unrealircdlink.php
diffstat 2 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/client/debugclient.php	Mon Feb 28 00:49:07 2011 +0100
+++ b/client/debugclient.php	Fri Apr 01 17:02:41 2011 +0200
@@ -27,6 +27,7 @@
 $server = '127.0.0.1:15387';
 
 $socket = stream_socket_client('tcp://'.$server) or die("Could not create socket\n");
+stream_set_timeout($socket, -1);
 $buffer = '';
 
 while (TRUE) {
--- a/unrealircdlink/unrealircdlink.php	Mon Feb 28 00:49:07 2011 +0100
+++ b/unrealircdlink/unrealircdlink.php	Fri Apr 01 17:02:41 2011 +0200
@@ -203,22 +203,34 @@
 }
 
 function udpmsg_process($ret) {
-	global $uchannels;
-	if (!isset($ret['CHN']) || !isset($ret['CMD']) || !isset($ret['USR'])) return;
-	if (!array_key_exists($ret['CHN'], $uchannels)) return;
-	$ch = $uchannels[$ret['CHN']];
+	global $uchannels, $config;
+	if (!isset($ret['CHN']) || !isset($ret['CMD']) || !isset($ret['USR']) || !array_key_exists($ret['CHN'], $uchannels)) {
+		$ch = NULL;
+	} else {
+		$ch = $uchannels[$ret['CHN']];
+	}
 	$net = isset($ret['NET']) ? $ret['NET'] : NULL;
 	switch ($ret['CMD']) {
 		case 'MSG':
-			if (!isset($ret['MSG'])) break;
+			if ($ch === NULL || !isset($ret['MSG'])) break;
 			$usr = udpmsg_join($ret['USR'], $ch, $net);
 			ircd_send(':'.$usr->iname.' PRIVMSG '.$ch->iname.' :'.preg_replace('/[\x00\x10-\x13]/', '', $ret['MSG']));
 			break;
+		case 'PMSG':
+			if (!isset($ret['DUSR']) || !isset($ret['MSG'])) break;
+			if (isset($ret['DNET']) && $ret['DNET'] != $config['udpmsg']['netname']) break;
+			$tousr = ircd_getuser($ret['DUSR'], FALSE);
+			if ($tousr === NULL) break;
+			$usr = udpmsg_getuser($ret['USR'], TRUE, $net, FALSE);
+			ircd_send(':'.$usr->iname.' PRIVMSG '.$tousr->iname.' :'.preg_replace('/[\x00\x10-\x13]/', '', $ret['MSG']));
+			break;
 		case 'ALIVE':
 		case 'JOIN':
+			if ($ch === NULL) break;
 			udpmsg_join($ret['USR'], $ch, $net, TRUE);
 			break;
 		case 'PART':
+			if ($ch === NULL) break;
 			udpmsg_part($ret['USR'], $ch);
 			break;
 		case 'NICK':
@@ -277,6 +289,7 @@
 	global $iusers, $config;
 	$nick = preg_replace('/[^a-zA-Z0-9\-_]/', '', $req);
 	if (!strlen($nick)) $nick = 'NoNick';
+	else if (strlen($nick) > 20) $nick = substr($nick, 0, 20);
 	switch ($config['ircd']['nick_format']) {
 		case 'plain': break;
 		case 'prefix': $nick = $config['ircd']['nick_prefix'].$nick; break;
@@ -331,10 +344,16 @@
 				ircd_send(':'.$bot_nick.' PRIVMSG '.$parts[0].' :We have '.count($GLOBALS['iusers']).' IRC users of which '.count($GLOBALS['uusers']).' UDPMSG users, and '.count($GLOBALS['ichannels']).' channels.');
 				break;
 			}
-			$ch = ircd_getchannel($parts[0]);
 			$usr = ircd_getuser($sendernick, FALSE);
-			if ($ch === NULL || $usr === NULL) break;
-			udpmsg_send(array('CMD' => 'MSG', 'CHN' => $ch->uname, 'MSG' => $parts[1], 'USR' => $usr->iname));
+			if ($parts[0][0] == '#') {
+				$ch = ircd_getchannel($parts[0]);
+				if ($ch === NULL || $usr === NULL) break;
+				udpmsg_send(array('CMD' => 'MSG', 'CHN' => $ch->uname, 'MSG' => $parts[1], 'USR' => $usr->iname));
+			} else {
+				$tousr = ircd_getuser($parts[0], FALSE);
+				if ($tousr === NULL || $usr === NULL) break;
+				udpmsg_send(array('CMD' => 'PMSG', 'DUSR' => $tousr->uname, 'MSG' => $parts[1], 'USR' => $usr->iname));
+			}
 			break;
 		case 'SAJOIN':
 		case 'SVSJOIN':