Sirius Emulator - From Scratch - C# 6.0

Status
Not open for further replies.

Jaden

not so active
Aug 24, 2014
886
263
Started working on client sided and server sided WebSockets, here is a sneek peak of a simple client side system
PHP:
window.ws = new wsImpl('ws://localhost:8181/');

var hasConnected = false;

function startWebSockets() {
    ws.onmessage = function (messageEvent) {
        onReceiveMessage(messageEvent.Data);
    };

    ws.onopen = function () {
        onConnectionOpened();
    };

    ws.onclose = function () {
        onConnectionClosed();
    }
}

function onReceiveMessage(messageData) {
    alert('You received a message from the WebSocket server: ' + messageData);
}

function onConnectionOpened() {
    console.log('Connected to the WebSocket server.');
    hasConnected = true;
}

function onConnectionClosed() {
    if (!hasConnected) {
        console.log('Failed to connect to the WebSocket server.');
    }
    else {
        console.log('Your connection to the WebSocket server was unexpectedly closed.');
    }
}

startWebSockets();
Why not use RCON?
 

KylePr0zZ

Member
Jul 22, 2016
51
14
Can your current web socket and RCON implementations be used for a rp websocket connection on a cms to do real time health bars, etc and interactive displays on the client like peakrp has done and holorp... Also keep up the amazing work, I see you've already completed the emulator which is fabulous. :)
 

Seriosk

Programmer;
Oct 29, 2016
256
105
Can your current web socket and RCON implementations be used for a rp websocket connection on a cms to do real time health bars, etc and interactive displays on the client like peakrp has done and holorp... Also keep up the amazing work, I see you've already completed the emulator which is fabulous. :)
I guess you can say anything is possible, simply just code an event for it in the emulator then handle it, here is an updated version of my WebSocket client-sided which handles multiple messages now.

Right now, all thats coded is Bootstrap custom notifications, but like I say, pretty much anything can be coded, and yeah, health, hygiene, energy, and hunger bars will come upon release.
Code:
var ws = new WebSocket('ws://localhost:8181/');

var hasConnected = false;

function startWebSockets() {
    ws.onmessage = function (messageEvent) {
        onReceiveMessage(messageEvent.data);
    };

    ws.onopen = function () {
        onConnectionOpened();
    };

    ws.onclose = function () {
        onConnectionClosed();
    }
}

function onReceiveMessage(messageData) {
    var messageParts = messageData.includes('\\') ? messageData.split('\\') : messageData;

    if (messageData.includes("\\")) {
        if (messageParts[0] == "compose:show_custom_notification") {
            showBootstrapNotification(messageParts[1], messageParts[2], messageParts[3], messageParts[4]);
        }
    }
    else {
        if (messageData == "compose:authentication_complete") {
            console.log('Authentication to WebSocket server has been completed.');
        }

        if (messageData == "compose:authentication_failed") {
            sendMessage("client_identity_token " + habboSso);
        }
    }
}

function onConnectionOpened() {
    console.log('Connected to the WebSocket server.');
    hasConnected = true;

    sendMessage("client_identity_token " + habboSso);
}

function onConnectionClosed() {
    if (!hasConnected) {
        console.log('Failed to connect to the WebSocket server.');
    }
    else {
        console.log('Your connection to the WebSocket server was unexpectedly closed.');
    }
}

function sendMessage(message) {
    if (hasConnected) {
        ws.send(message);
    }
}

startWebSockets();

function showBootstrapNotification(notificationTitle, notificationContent, notificationColor, notificationSize) {
    console.log('trying to execute notification');

    var notificationArea = $('#notification_area');
    var notificationHtml;

    notificationHtml += '<div class="col-md-' + notificationSize + ' col-centered">';
    notificationHtml += '<div class="draggable panel panel-pink">';
    notificationHtml += '<div class="panel-heading" style="background-color: ' + notificationColor + '">';
    notificationHtml += notificationTitle;
    notificationHtml += '</div>';
    notificationHtml += '<div class="panel-body">';
    notificationHtml += notificationContent;
    notificationHtml += '</div>';
    notificationHtml += '</div>';
    notificationHtml += '</div>';
 
    $("#notification_area").prepend(notificationHtml);
    $('.draggable').draggable();
}

Emulator news
I've changed how SSO works, their now stored in a table called srp_user_auth_tickets with an ID primary key and a varchar for the SSO, it'll be deleted upon login and created on page load CMS.
 
Status
Not open for further replies.

Users who are viewing this thread

Top