log() public method

public log ( $msg = "" )
Example #1
0
function main()
{
    require 'WebSocket.class.php';
    $webSocketServer = new WebSocket();
    //$webSocketServer = Api('WebSocket');
    $onMessage = function ($clientID, $message, $messageLength, $binary) use($webSocketServer) {
        $ip = long2ip($webSocketServer->wsClients[$clientID][6]);
        // check if message length is 0
        if ($messageLength == 0) {
            $webSocketServer->wsClose($clientID);
            return;
        }
        //The speaker is the only person in the room. Don't let them feel lonely.
        if (sizeof($webSocketServer->wsClients) == 1) {
            $webSocketServer->wsSend($clientID, "没有别的人在房间里,但我还是会听你的。——你可靠的服务器");
        } else {
            //Send the message to everyone but the person who said it
            foreach ($webSocketServer->wsClients as $id => $client) {
                if ($id != $clientID) {
                    $webSocketServer->wsSend($id, "游客 {$clientID} ({$ip}) 说 \"{$message}\"");
                }
            }
        }
    };
    $onOpen = function ($clientID) use($webSocketServer) {
        $ip = long2ip($webSocketServer->wsClients[$clientID][6]);
        $webSocketServer->log("{$ip} ({$clientID}) 已连接。");
        //Send a join notice to everyone but the person who joined
        foreach ($webSocketServer->wsClients as $id => $client) {
            if ($id != $clientID) {
                $webSocketServer->wsSend($id, "游客 {$clientID} ({$ip}) 加入房间。");
            }
        }
    };
    $onClose = function ($clientID, $status) use($webSocketServer) {
        $ip = long2ip($webSocketServer->wsClients[$clientID][6]);
        $webSocketServer->log("{$ip} ({$clientID}) 已断开。");
        //Send a user left notice to everyone in the room
        foreach ($webSocketServer->wsClients as $id => $client) {
            $webSocketServer->wsSend($id, "游客 {$clientID} ({$ip}) 离开了房间。");
        }
    };
    $webSocketServer->bind('message', $onMessage);
    $webSocketServer->bind('open', $onOpen);
    $webSocketServer->bind('close', $onClose);
    $serverStatus = $webSocketServer->wsStartServer('0.0.0.0', 9300);
    if ($serverStatus == false) {
        echo $webSocketServer->error;
    } else {
        echo 'webSocketServer Normal end';
    }
}
Example #2
0
include "{$IP}/extensions/VisualEditor/VisualEditor.php";
$wgDefaultUserOptions['visualeditor-enable'] = 1;
// enabled by default for all
$wgHiddenPrefs[] = 'visualeditor-enable';
// don't allow disabling
$wgDefaultUserOptions['visualeditor-enable-experimental'] = 1;
$wgVisualEditorParsoidURL = 'http://localhost:8142';
$wgVisualEditorParsoidPrefix = 'ligmincha';
$wgVisualEditorSupportedSkins[] = 'monobook';
// Organic Design extensions
wfLoadExtension('ExtraMagic');
wfLoadExtension('HighlightJS');
wfLoadExtension('AjaxComments');
$wgAjaxCommentsPollServer = -1;
include "{$IP}/extensions/WebSocket/WebSocket.php";
WebSocket::$log = __DIR__ . '/ws.log';
WebSocket::$rewrite = true;
WebSocket::$ssl_cert = '/etc/letsencrypt/live/ligmincha.com.br/fullchain.pem';
WebSocket::$ssl_key = '/etc/letsencrypt/live/ligmincha.com.br/privkey.pem';
// Make Category:Público public access
$wgHooks['UserGetRights'][] = 'wfPublicCat';
function wfPublicCat()
{
    global $wgWhitelistRead;
    $title = Title::newFromText($_REQUEST['title']);
    if (is_object($title)) {
        $id = $title->getArticleID();
        $dbr = wfGetDB(DB_SLAVE);
        if ($dbr->selectRow('categorylinks', '1', "cl_from = {$id} AND cl_to = 'Público'")) {
            $wgWhitelistRead[] = $title->getPrefixedText();
        }
Example #3
0
 /**
  * Send data to the local WebSocket daemon if active
  */
 private static function sendToWebSocket($queue, $session)
 {
     // Lazy-load the Fake MediaWiki environment and the OD Websocket class from the MediaWiki extension
     if (!defined('WEBSOCKET_VERSION')) {
         require_once __DIR__ . '/WebSocket/WebSocket.php';
         WebSocket::$log = '/var/www/extensions/MediaWiki/WebSocket/ws.log';
         // tmp to match my current daemon
         WebSocket::$rewrite = true;
         WebSocket::setup();
     }
     if (WebSocket::isActive()) {
         // Set the ID of this WebSocket message to the session ID of the sender so the WS server doesn't bounce it back to them
         WebSocket::$clientID = $session;
         // Send queue to all clients
         lgDebug('Sending to WebSocket');
         WebSocket::send('LigminchaGlobal', $queue);
         lgDebug('Sent to WebSocket');
     } else {
         lgDebug('Not sending to WebSocket: not active');
     }
 }
Example #4
0
 * WebSocket extension - Allows live connections between the server and other current clients
 *
 * See http://www.organicdesign.co.nz/Extension:WebSocket for details
 * 
 * @file
 * @ingroup Extensions
 * @author Aran Dunkley [http://www.organicdesign.co.nz/aran Aran Dunkley]
 * @copyright © 2015 Aran Dunkley
 * @licence GNU General Public Licence 2.0 or later
 */
if (!defined('MEDIAWIKI')) {
    die('Not an entry point.');
}
define('WEBSOCKET_VERSION', '1.2.1, 2015-04-28');
require __DIR__ . '/WebSocket.class.php';
require __DIR__ . '/WebSocketClient.class.php';
WebSocket::$port = 1729;
# Port the WebSocket daemon will run on
WebSocket::$rewrite = false;
# Configure URL rewriting so that the WebSocket port doesn't need to be public
WebSocket::$perl = '/usr/bin/perl';
# Location of the Perl interpreter
WebSocket::$log = false;
# Set a file location to log WebSocket daemon events and errors
WebSocket::$ssl_cert = false;
# If the wiki uses SSL, then the WebSocket will need to know the certificate file,
WebSocket::$ssl_key = false;
# and the SSL key file
$wgExtensionCredits['other'][] = array('path' => __FILE__, 'name' => 'WebSocket', 'author' => '[http://www.organicdesign.co.nz/aran Aran Dunkley]', 'url' => 'http://www.organicdesign.co.nz/Extension:WebSocket', 'descriptionmsg' => 'websocket-desc', 'version' => WEBSOCKET_VERSION);
$wgExtensionMessagesFiles['WebSocket'] = __DIR__ . '/WebSocket.i18n.php';
new WebSocket();