mirror of
https://github.com/ApfelTeeSaft/LawinServerV2.git
synced 2026-08-26 19:23:39 +00:00
Add matchmaker.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
const crypto = require("crypto");
|
||||
|
||||
module.exports = (ws) => {
|
||||
// create hashes
|
||||
const ticketId = crypto.createHash('md5').update(`1${Date.now()}`).digest('hex');
|
||||
const matchId = crypto.createHash('md5').update(`2${Date.now()}`).digest('hex');
|
||||
const sessionId = crypto.createHash('md5').update(`3${Date.now()}`).digest('hex');
|
||||
|
||||
// you can use setTimeout to send the websocket messages at certain times
|
||||
setTimeout(Connecting, 200/* Milliseconds */);
|
||||
setTimeout(Waiting, 1000); // 0.8 Seconds after Connecting
|
||||
setTimeout(Queued, 2000); // 1 Second after Waiting
|
||||
setTimeout(SessionAssignment, 6000); // 4 Seconds after Queued
|
||||
setTimeout(Join, 8000); // 2 Seconds after SessionAssignment
|
||||
|
||||
function Connecting() {
|
||||
ws.send(JSON.stringify({
|
||||
"payload": {
|
||||
"state": "Connecting"
|
||||
},
|
||||
"name": "StatusUpdate"
|
||||
}));
|
||||
}
|
||||
|
||||
function Waiting() {
|
||||
ws.send(JSON.stringify({
|
||||
"payload": {
|
||||
"totalPlayers": 1,
|
||||
"connectedPlayers": 1,
|
||||
"state": "Waiting"
|
||||
},
|
||||
"name": "StatusUpdate"
|
||||
}));
|
||||
}
|
||||
|
||||
function Queued() {
|
||||
ws.send(JSON.stringify({
|
||||
"payload": {
|
||||
"ticketId": ticketId,
|
||||
"queuedPlayers": 0,
|
||||
"estimatedWaitSec": 0,
|
||||
"status": {},
|
||||
"state": "Queued"
|
||||
},
|
||||
"name": "StatusUpdate"
|
||||
}));
|
||||
}
|
||||
|
||||
function SessionAssignment() {
|
||||
ws.send(JSON.stringify({
|
||||
"payload": {
|
||||
"matchId": matchId,
|
||||
"state": "SessionAssignment"
|
||||
},
|
||||
"name": "StatusUpdate"
|
||||
}));
|
||||
}
|
||||
|
||||
function Join() {
|
||||
ws.send(JSON.stringify({
|
||||
"payload": {
|
||||
"matchId": matchId,
|
||||
"sessionId": sessionId,
|
||||
"joinDelaySec": 1
|
||||
},
|
||||
"name": "Play"
|
||||
}));
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -12,7 +12,8 @@ const User = require("../model/user.js");
|
||||
const Friends = require("../model/friends.js");
|
||||
|
||||
const port = 80;
|
||||
const wss = new WebSocket({ server: app.listen(port, () => log.xmpp(`XMPP started listening on port ${port}`)) });
|
||||
const wss = new WebSocket({ server: app.listen(port, () => log.xmpp(`XMPP and Matchmaker started listening on port ${port}`)) });
|
||||
const matchmaker = require("../matchmaker/matchmaker.js");
|
||||
|
||||
global.Clients = [];
|
||||
|
||||
@@ -44,6 +45,9 @@ app.get("/clients", (req, res) => {
|
||||
})
|
||||
|
||||
wss.on('connection', async (ws) => {
|
||||
// Start matchmaker if it's not connecting for xmpp.
|
||||
if (ws.protocol.toLowerCase() != "xmpp") return matchmaker(ws);
|
||||
|
||||
var accountId = "";
|
||||
var displayName = "";
|
||||
var token = "";
|
||||
|
||||
Reference in New Issue
Block a user