Compare commits

...

2 Commits

3 changed files with 12 additions and 11 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "schat2-clive",
"version": "1.5.19",
"version": "1.6.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "schat2-clive",
"version": "1.5.19",
"version": "1.6.0",
"license": "ISC",
"dependencies": {
"bhttp": "^1.2.8",

View File

@ -1,6 +1,6 @@
{
"name": "schat2-clive",
"version": "1.5.19",
"version": "1.6.0",
"description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js",
"scripts": {

View File

@ -260,10 +260,16 @@ function handleError(error, socket, domain, data) {
}
}
async function connect(wsCreds, sessionCookie, bot, games) {
async function connect(bot, games) {
const socket = { ws: { readyState: 0 } };
socket.connect = () => {
socket.connect = async () => {
const { user, httpSession, sessionCookie } = await auth();
const wsCreds = await getWsId(httpSession);
bot.user = user;
bot.httpSession = httpSession;
logger.info(`Attempting to connect to ${config.socket}`);
socket.ws = new WebSocket(`${config.socket}?${new URLSearchParams({ v: wsCreds.wsId, t: wsCreds.timestamp }).toString()}`, [], {
@ -310,19 +316,14 @@ async function connect(wsCreds, sessionCookie, bot, games) {
}
async function init() {
const { user, httpSession, sessionCookie } = await auth();
const wsCreds = await getWsId(httpSession);
const bot = {
user,
httpSession,
rooms: [],
users: [],
};
const games = getGames(bot);
bot.socket = await connect(wsCreds, sessionCookie, bot, games);
bot.socket = await connect(bot, games);
await initPoints();
}