Skip to content

Commit

Permalink
fix ai judge on hosted games
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 29, 2024
1 parent 57f231c commit 8ce65f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ export class Room {
// Not in judging step
return false;
}
if (this.settings.host && socket?.id !== this.settings.host) {
if (this.settings.host && socket && socket?.id !== this.settings.host) {
// Not the host
return;
}
Expand Down
6 changes: 3 additions & 3 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { makeRoomName, makeUserName } from './moniker';
import config from './config';

const app = express();
let server: any = null;
let server = null as https.Server | http.Server | null;
if (config.SSL_KEY_FILE && config.SSL_CRT_FILE) {
const key = fs.readFileSync(config.SSL_KEY_FILE as string);
const cert = fs.readFileSync(config.SSL_CRT_FILE as string);
server = https.createServer({ key: key, cert: cert }, app);
} else {
server = new http.Server(app);
}
const io = new Server(server, { cors: { origin: '*' } });
const io = new Server(server, { cors: { origin: '*' }, transports: ['websocket'] });
const rooms = new Map<string, Room>();
init();

Expand All @@ -44,7 +44,7 @@ async function init() {
rooms.set(roomId, new Room(io, roomId));
}
});
server.listen(config.PORT);
server?.listen(Number(config.PORT));
}

app.use(cors());
Expand Down
8 changes: 8 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ export default {
build: {
outDir: 'build',
},
server: {
https: process.env.SSL_CRT_FILE
? {
key: fs.readFileSync(process.env.SSL_KEY_FILE),
cert: fs.readFileSync(process.env.SSL_CRT_FILE),
}
: null,
},
};

0 comments on commit 8ce65f6

Please sign in to comment.