hi since multiplayer is not stable (users mostly disconnected) its might be good for small games but no good for big games.
i have an idea which we can make a multiplayer with websocket and don't need to js programming !!!
this is what we need :
1 - nodejs server script
2 - server side game
3 - client side game
so we need to make a node js to pass the all client messages to the host and pass host messages to a specific client !
like this :
all clients >> node js server >> server game (we can run node js and server game in single host so the latency is 0)
game server >> node js server (get client username from the server message and send message to that user) >> a specific client
client message type is : (c$tag$username$data)
server message type is : (s$tag$username$data)
i will say why we have this type of messages !
so we need a node server to do that and i wanted to use ws module for nodejs but it doesn't respond sometimes !!
this is my code for ws server :
in my code server split messages and if "c" so this message from client and if "s" then its a server
"tag" is like tag in multiplayer plugin
"username" is client username (even in server messages)
so in server game and client game we can split messages with tokenat and then use them !
so anyone can help ?
var WebSocketServer = require('ws').Server, wss = new WebSocketServer({port: 1337});
var connections = {};
wss.on('connection', function(ws) {
ws.on('message', function(message,ws) {
console.log('received: %s', message);
var res = message.split("$");
if(res[0] == "s")
{
ws.send(message);
if(res[1] == "login")
{
connections["server"] = ws;
}
else
{
ws.send(message);
if(connections["client"])
{
connections[res[2]].send(res[1] + res[3]);
}
}
}
else
{
if(res[1] == "login")
{
connections[res[2]] = ws;
}
else
{
connections["server"].send(res[1] + res[2] + res[3]);
}
}
});
});
[/code:2ebh4j8g]