changed message format master
changed message format

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -33,13 +33,13 @@
               socket.onmessage = function(msg){
                  message('<p class="message">Received: '+msg.data);
                  var msgdata = msg.data;
-                 var _message = msgdata.split ('$');
-                 var cmd = _message[0];
-                 var msg = _message[1];
-                 console.log ('CMD: '+cmd);
-                 console.log ('MSG: '+msg);
-                 if ( cmd == "changebackground" ) {
-                    $("body").css("background-color", msg );
+                 var _message = msgdata.split (':');
+                 var action = _message[0];
+                 var params = _message[1];
+                 console.log ('ACTION: '+action);
+                 console.log ('PARAMS: '+params);
+                 if ( action == "changebackground" ) {
+                    $("body").css("background-color", params );
                  }
               }
 
@@ -141,7 +141,7 @@
         <div id="chatLog">
         </div>
         <p id="examples">e.g. try 'ping'</p>
-        <input id="text" type="text" value="chat|changebackground$red" />
+        <input id="text" type="text" value="do|changebackground:red" />
         <!--button id="disconnect">Disconnect</button-->
 </div>
 <?php $url = urlencode ("http://".$_SERVER['HTTP_HOST']."/?code=".session_id ()); ?>

file:a/server.php -> file:b/server.php
--- a/server.php
+++ b/server.php
@@ -78,29 +78,18 @@
 				$cmd = strtolower ($piece[0]);
 
 				if ( !empty($piece[1]) ) {
-					$txt = $piece[1];
+					$message = $piece[1];
 				}
 
 				switch ($cmd) {
-					case "chat": // chat|session:message
+					case "do": // do|action:params
 						if ( $session ) {
-							$txt = explode (":", $txt);
-							//$session = $txt[0];
-							$message = $txt[0];
-							//if ( $_sockets[intval($socket)]['session'] == $session ) {
-								//sendMesage ($socket, $message);
-								sendMessageToAll ($allclients, $socket, $session, $message);
-							//}
-						} else {
-							sendMesage ($socket, "wrong session");
+							sendMessageToAll ($allclients, $socket, $session, $message);
 						}
 					break;
 
 					case "login"; // login|session
-						$txt = explode (":", $txt);
-						$session = $txt[0];
-
-						$_sockets[intval($socket)]['session'] = $session;
+						$_sockets[intval($socket)]['session'] = $message;
 						sendMesage ($socket, "true");
 					break;
 

comments