|
|
|
@ -3,30 +3,26 @@ import {log} from "./logger.js"; |
|
|
|
|
|
|
|
|
|
import {Server} from 'socket.io'; |
|
|
|
|
import {Room} from "./room.js"; |
|
|
|
|
import * as https from "https"; |
|
|
|
|
import * as fs from "fs"; |
|
|
|
|
import * as http from "http"; |
|
|
|
|
|
|
|
|
|
export function StartServer(settings: any){ |
|
|
|
|
|
|
|
|
|
require("dotenv").config(); |
|
|
|
|
const httpsPort = parseInt(process.env.HTTPS_PORT); |
|
|
|
|
|
|
|
|
|
let cert = fs.readFileSync(`${process.env.SSL_PATH}/cert.pem`); |
|
|
|
|
let key = fs.readFileSync(`${process.env.SSL_PATH}/key.pem`); |
|
|
|
|
let httpServer = http.createServer(); |
|
|
|
|
|
|
|
|
|
let httpsServer = https.createServer({key: key, cert: cert}); |
|
|
|
|
|
|
|
|
|
let sIO = new Server(httpsServer, { |
|
|
|
|
let sIO = new Server(httpServer, { |
|
|
|
|
cors: { |
|
|
|
|
origin: ["https://play.benjamin-kraft.local", "https://play.benjamin-kraft.eu"] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
path: settings.subPath |
|
|
|
|
}); |
|
|
|
|
if (settings.useP2P){ |
|
|
|
|
const p2p = require('socket.io-p2p-server').Server; |
|
|
|
|
sIO.use(p2p); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
httpsServer.listen(httpsPort); |
|
|
|
|
httpServer.listen(settings.port); |
|
|
|
|
|
|
|
|
|
Room.GameClass = settings.gameClass; |
|
|
|
|
|
|
|
|
@ -35,5 +31,5 @@ export function StartServer(settings: any){ |
|
|
|
|
// On new connection
|
|
|
|
|
sIO.on('connection', socket => connectionManager.newSocket(socket)); |
|
|
|
|
|
|
|
|
|
log('startup', null, null, 'Server is listening on port ' + httpsPort); |
|
|
|
|
log('startup', null, null, 'Server is listening on port ' + settings.port); |
|
|
|
|
} |