[mw-devel] MW3 r1331 - trunk/webclient

arthur at sucs.org arthur at sucs.org
Wed Feb 13 11:52:15 GMT 2013


Author: arthur
Date: 2013-02-13 11:52:15 +0000 (Wed, 13 Feb 2013)
New Revision: 1331

Added:
   trunk/webclient/config.php
Modified:
   trunk/webclient/poll.php
   trunk/webclient/say.js
   trunk/webclient/send.php
   trunk/webclient/startup.php
Log:
fixes the webclient code


Added: trunk/webclient/config.php
===================================================================
--- trunk/webclient/config.php	                        (rev 0)
+++ trunk/webclient/config.php	2013-02-13 11:52:15 UTC (rev 1331)
@@ -0,0 +1,10 @@
+<?php
+
+$poller_bin = "/usr/lib/mw/mwpoll";
+$poller_path = "/var/run/mw/mwpoll.";
+
+/* Fix these paths to your local test copy for test mode  e.g. */
+//$poller_bin = "/home/life/arthur/work/mw/trunk/src/webclient/mwpoll -h localhost:9991";
+//$poller_path = "/home/life/arthur/work/mw/trunk/src/mwtest/run/mw/mwpoll.";
+
+?>

Modified: trunk/webclient/poll.php
===================================================================
--- trunk/webclient/poll.php	2013-02-13 11:47:19 UTC (rev 1330)
+++ trunk/webclient/poll.php	2013-02-13 11:52:15 UTC (rev 1331)
@@ -1,4 +1,7 @@
 <?
+
+require_once("config.php");
+
 if (isset($_COOKIE['mwsess'])) {
 	$data = unserialize($_COOKIE['mwsess']);
 	$sess = (int)$data['pid'];
@@ -8,7 +11,7 @@
 	$auth = trim(@$_REQUEST['auth']);
 }
 
-$path = "/var/run/mw/mwpoll.".$sess;
+$path = $poller_path.$sess;
 
 header("Content-type: application/json; charset=utf-8");
 

Modified: trunk/webclient/say.js
===================================================================
--- trunk/webclient/say.js	2013-02-13 11:47:19 UTC (rev 1330)
+++ trunk/webclient/say.js	2013-02-13 11:52:15 UTC (rev 1331)
@@ -25,6 +25,93 @@
 		} else {
 			for (one in msg) {
 				switch (msg[one].state) {
+				case "SAYR":
+					// decode the json message
+					var detail = JSON.parse(msg[one].text);
+
+					var body = detail.text;
+					// make a crude approximation of the old message styles
+					switch (detail.type) {
+						case "say":
+							body = msg[one].username + ": " + detail.text;
+							break;
+						case "raw":
+							body = detail.text;
+							break;
+						case "emote":
+							switch (detail.plural){
+								case 1:
+									body = msg[one].username + "'s " + detail.text;
+									break;
+								case 2:
+									body = msg[one].username + "' " + detail.text;
+									break;
+								case 3:
+									body = msg[one].username + "'d " + detail.text;
+									break;
+								case 4:
+									body = msg[one].username + "'ll " + detail.text;
+									break;
+								default:
+									body = msg[one].username + " " + detail.text;
+									break;
+							}
+							break;
+						case "notsayto":
+							body = msg[one].username + " says (-" + detail.exclude + "): " + detail.text;
+							break;
+						default:
+							body = msg[one].username + " " + detail.text;
+							break;
+					}
+
+					/* Escape HTML characters */
+					var escapedMsg = body.replace(/&/g, "&");
+					escapedMsg = escapedMsg.replace(/</g, "<");
+					escapedMsg = escapedMsg.replace(/>/g, ">");
+					escapedMsg = escapedMsg.replace(/\n/g, "");
+					escapedMsg = escapedMsg.replace(/\r/g, "");
+
+					/* Detect URIs and convert to links */
+					var uris = escapedMsg.match(/https?:\/\/[^ ]*/g);
+					for (thisuri in uris) {
+						escapedMsg = escapedMsg.replace(uris[thisuri], "<a target=\"_new\" href=\""+uris[thisuri]+"\">"+uris[thisuri]+"</a>");
+					}
+
+					/* Insert timestamp if necessary */
+					var timestamp="";
+					if (userProfile.special.match("t")) {
+						var currentTime = new Date();
+						var withts=" withts";
+						timestamp = "<span class=\"timestamp\">"+pad(currentTime.getHours(), 2)+":"+pad(currentTime.getMinutes(), 2)+" </span>";
+					}
+
+					/* Detect username */
+					if (escapedMsg.substr(0, msg[one].username.length)==msg[one].username) {
+						escapedMsg = escapedMsg.replace(msg[one].username, "<span class='msg_poster'>"+msg[one].username+"</span><span class='msg_content"+withts+"'><span>");
+						escapedMsg = escapedMsg+"</span></span>";
+					}
+				
+					/* Replace colour codes with appropriate span tags */				
+					var msgColours = escapedMsg.match(/\u001b../g);
+					if (msgColours != null) {
+						for (i=0;i<msgColours.length;i++) {
+							if (isNaN(msgColours[i].charAt(1))) {
+								var colourBold = "";
+								var fgColour = msgColours[i].charAt(1);
+								if (fgColour!=fgColour.toLowerCase()) { colourBold = " bold"; }
+								escapedMsg = escapedMsg.replace(msgColours[i], "</span><span class='colourfg"+msgColours[i].charAt(1)+colourBold+" colourbg"+msgColours[i].charAt(2)+"'>");
+							} else {
+								escapedMsg = escapedMsg.replace(msgColours[i], "</span><span class='colour"+msgColours[i].replace(/\u001b/g, "")+"'>");
+							}
+						}
+					}
+
+					/* Output the processed line */
+					$("#textlist").append( "<p class='msg"+type+" user_"+userIndex[msg[one].username.toLowerCase()]+"'>" + timestamp + escapedMsg + "</p");
+
+					break;
+
 				case 11: // Talker message
 				/* Escape HTML characters */
 					var escapedMsg = msg[one].text.replace(/&/g, "&");
@@ -92,6 +179,12 @@
 				case 23: // CheckOnOff
 					sendCmdHandle('who', drawWhoList);
 					break;
+				default: 
+					what = "<div class='msg"+type+"'>";
+					what += "Unknown message type '"+msg[one].state+"' body='"+msg[one].text+"'";
+					what += "</div>";
+					$("#textlist").append(what);
+					break;
 				}
 			}
 		}

Modified: trunk/webclient/send.php
===================================================================
--- trunk/webclient/send.php	2013-02-13 11:47:19 UTC (rev 1330)
+++ trunk/webclient/send.php	2013-02-13 11:52:15 UTC (rev 1331)
@@ -1,5 +1,7 @@
 <?
 
+require_once("config.php");
+
 if (isset($_COOKIE['mwsess'])) {
 	$data = unserialize($_COOKIE['mwsess']);
 	$sess = (int)$data['pid'];
@@ -9,13 +11,18 @@
 	$auth = trim(@$_REQUEST['auth']);
 }
 
-$path = "/var/run/mw/mwpoll.".$sess;
+$path = $poller_path.$sess;
 
 header("Content-type: application/json");
 
 $sock = socket_create(AF_UNIX, SOCK_SEQPACKET, 0);
 if (@socket_connect($sock, $path) === FALSE) {
-	echo "{\"status\":\"Socket open error\"}\n";
+	echo "{";
+	echo "\"status\":\"Socket open error\"";
+	$err = error_get_last();
+	echo ",\"detail\":\"".$err['message']."\"";
+	echo ",\"path\":\"".$path."\"";
+	echo "}\n";
 	exit;
 }
 

Modified: trunk/webclient/startup.php
===================================================================
--- trunk/webclient/startup.php	2013-02-13 11:47:19 UTC (rev 1330)
+++ trunk/webclient/startup.php	2013-02-13 11:52:15 UTC (rev 1331)
@@ -1,5 +1,7 @@
 <?
-$mwpoll = "/usr/lib64/mw/mwpoll";
+require_once("config.php");
+
+$mwpoll = $poller_bin;
 $username = trim($_REQUEST['username']);
 $password = trim($_REQUEST['password']);
 
@@ -86,10 +88,12 @@
 	} else {
 		$p = proc_open($mwpoll." -u ".$realuser." -s", $desc, $pipes);
 	}
+	$mode = "sucssite";
 }
 } else {
 # If not, try logging in with a password.
 	$p = proc_open($mwpoll." -u $username", $desc, $pipes);
+	$mode = "password";
 }
 
 if (empty($p)) {
@@ -105,7 +109,7 @@
 	exit;
 }
 
-if (@$_REQUEST['sucssite_loggedin']=="true" && empty($username)) {
+if ($mode == "sucssite" && @$_REQUEST['sucssite_loggedin']=="true" && empty($username)) {
 // If we have a sucssite session cookie, use that
 	fwrite($pipes[0], trim($_REQUEST['sucssite_session'])."\n");
 	if ($action="create") {
@@ -113,10 +117,17 @@
 	}
 } else {
 // Try logging on using username and password
-	fwrite($pipes[0], $password."\n");
+	if (fwrite($pipes[0], $password."\n") === FALSE) {
+		echo "Error writing to mwpoll\n";
+	}
 }
 
-$pid = trim(fgets($pipes[1]));
+$pid = fgets($pipes[1]);
+if ($pid === FALSE) {
+	echo "error reading pid.\n";
+}
+
+$pid = trim($pid);
 if (!is_numeric($pid)) {
 	if (substr($pid, -10) =="not found.") {
 	// User doesn't exist - ask for a Milliways password so we can create them!
@@ -125,7 +136,7 @@
 		$smarty->display("main.html");
 		exit;	
 	}
-	$smarty->assign("error", "Bad response: $pid");
+	$smarty->assign("error", "Bad response: pid=$pid");
 	$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
 	$smarty->display("main.html");
 	exit;
@@ -133,6 +144,10 @@
 
 $auth = fgets($pipes[1]);
 
+if ($auth === FALSE) {
+	echo "Error reading auth string\n";
+}
+
 $sess = array (
 	"pid" => $pid,
 	"auth" => $auth,




More information about the mw-devel mailing list