Compare commits
No commits in common. "d510caa123be6b7e82f202882dca69bfc2b5db5e" and "6a36df3593632d6d060ae03a94241ef7f3c4102e" have entirely different histories.
d510caa123
...
6a36df3593
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.28.3",
|
||||
"version": "1.28.2",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "schat2-clive",
|
||||
"version": "1.28.3",
|
||||
"version": "1.28.2",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^8.3.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.28.3",
|
||||
"version": "1.28.2",
|
||||
"description": "Game host for SChat 2-powered chat sites",
|
||||
"main": "src/app.js",
|
||||
"scripts": {
|
||||
|
|
20
src/schat.js
20
src/schat.js
|
@ -17,9 +17,10 @@ const instance = process.env.NODE_APP_INSTANCE || 'main';
|
|||
logger.setLevel(argv.level || 'info');
|
||||
|
||||
async function auth() {
|
||||
const httpSession = bhttp.session();
|
||||
const username = config.uniqueUsername ? `${config.user.username}-${new Date().getTime().toString().slice(-5)}` : config.user.username;
|
||||
|
||||
const res = await bhttp.post(`${config.api}/session`, {
|
||||
const res = await httpSession.post(`${config.api}/session`, {
|
||||
...config.user,
|
||||
username,
|
||||
}, {
|
||||
|
@ -34,17 +35,13 @@ async function auth() {
|
|||
|
||||
return {
|
||||
user: res.body,
|
||||
// auth may return an explicit auth cookie domain, but we connect through the VPN domain that would break the cookie, so don't use a bhttp session and strip the domain
|
||||
sessionCookie: res.headers['set-cookie'][0].replace(/Domain=.*;/, ''),
|
||||
httpSession,
|
||||
sessionCookie: res.headers['set-cookie'][0],
|
||||
};
|
||||
}
|
||||
|
||||
async function getWsId(sessionCookie) {
|
||||
const res = await bhttp.get(`${config.api}/socket`, {
|
||||
headers: {
|
||||
cookie: sessionCookie,
|
||||
},
|
||||
});
|
||||
async function getWsId(httpSession) {
|
||||
const res = await httpSession.get(`${config.api}/socket`);
|
||||
|
||||
if (res.statusCode !== 200) {
|
||||
throw new Error(`Failed to retrieve WebSocket ID: ${res.body.toString()}`);
|
||||
|
@ -138,10 +135,11 @@ async function connect(bot, games) {
|
|||
|
||||
socket.connect = async () => {
|
||||
try {
|
||||
const { user, sessionCookie } = await auth();
|
||||
const wsCreds = await getWsId(sessionCookie);
|
||||
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}`);
|
||||
|
||||
|
|
Loading…
Reference in New Issue