<?php require_once 'lib/Utils.php'; require_once 'lib/ServerConnection.php'; $connection = new ServerConnection('127.0.0.1', 15700); check($connection->isConnected()); $data = json_encode(array('action' => 'help')); print_r(unpack("c*", $data)); $connection->send(pack("i", strlen($data)) . $data . pack("i", strlen($data)) . $data); $resp = $connection->recvPacket(); print_r($resp); die; $connection->sendPacket(array('action' => 'execute', 'data' => array('environmentId' => 0, 'code' => 'print("lalala"); return { 1, 3 };'))); $resp = $connection->recvPacket(); check($resp['rs'] == 0); check($resp['error'] == 'ERROR_BAD_SEQUENCE');
$connection->sendPacket(array('action' => 'ExecuteCode', 'data' => array('environmentId' => 0, 'code' => sprintf('ChatManager.addUserToChannel(%d, "%s");', 2, USER_1_2_CHANNEL)))); $resp = $connection->recvPacket(); check($resp['rs'] == 1, $resp); // ---------------------------------------------------------// // ADD USER // ---------------------------------------------------------// $user_1 = new ServerConnection('127.0.0.1', 15600); check($user_1->isConnected()); $user_1->sendPacket(array('action' => 'auth', 'data' => array('uid' => 1, 'key' => USER_1_KEY))); $resp = $user_1->recvPacket(); check($resp['rs'] == 1, $resp); // ---------------------------------------------------------// // ADD ANOTHER USER // ---------------------------------------------------------// $user_2 = new ServerConnection('127.0.0.1', 15600); check($user_2->isConnected()); // BAD KEY $user_2->sendPacket(array('action' => 'auth', 'data' => array('uid' => 2, 'key' => USER_1_KEY))); $resp = $user_2->recvPacket(); check($resp['rs'] == 0, $resp); // OK $user_2->sendPacket(array('action' => 'auth', 'data' => array('uid' => 2, 'key' => USER_2_KEY))); $resp = $user_2->recvPacket(); check($resp['rs'] == 1, $resp); // ---------------------------------------------------------// // SEND MESSAGE // ---------------------------------------------------------// $user_1->sendPacket(array('action' => 'sendMessage', 'data' => array('channel' => USER_1_2_CHANNEL, 'message' => 'Hello world!'))); $resp = $user_1->recvPacket(); check($resp['event'] == 'newMessage', $resp); $resp = $user_1->recvPacket();