5.5 strict warnings, change background color
[php-js-websockets.git] / server.php
blob:a/server.php -> blob:b/server.php
--- a/server.php
+++ b/server.php
@@ -37,7 +37,7 @@
 
 while (true) {
 	$changed_sockets = $read_sockets;
-	$num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL);
+	$num_changed_sockets = socket_select($changed_sockets, $write, $except, NULL);
 
 	foreach($changed_sockets as $socket) {
 	    if ($socket == $master) {
@@ -64,6 +64,7 @@
 				@socket_shutdown ($socket, 2);
 				@socket_close ($socket);
 			} else {
+				$session = $_sockets[intval($socket)]['session'];
 				$allclients = $read_sockets;
 				array_shift ($allclients);
 
@@ -85,13 +86,17 @@
 
 				switch ($cmd) {
 					case "chat": // chat|session:message
-						$txt = explode (":", $txt);
-						$session = $txt[0];
-						$message = $txt[1];
-						//if ( $_sockets[intval($socket)]['session'] == $session ) {
-							//sendMesageToYou ($socket, $message);
-							sendMessageToAll ($allclients, $session, $message);
-						//}
+						if ( $session ) {
+							$txt = explode (":", $txt);
+							//$session = $txt[0];
+							$message = $txt[0];
+							//if ( $_sockets[intval($socket)]['session'] == $session ) {
+								//sendMesageToYou ($socket, $message);
+								sendMessageToAll ($allclients, $socket, $session, $message);
+							//}
+						} else {
+							sendMesageToYou ($socket, "wrong session");
+						}
 					break;
 
 					case "login"; // login|session
@@ -99,7 +104,7 @@
 						$session = $txt[0];
 
 						$_sockets[intval($socket)]['session'] = $session;
-						sendMesageToYou ($socket, "true aaa bbb");
+						sendMesageToYou ($socket, "true");
 					break;
 
 					case "ping":

comments