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