-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.js
38 lines (29 loc) · 821 Bytes
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import dotenv from 'dotenv'
import mc from 'minecraft-protocol'
dotenv.config()
import { Connection } from './src/worldManager.js'
let host = process.env.HOST
let port = process.env.PORT
let version = process.env.VERSION
// Server user connects to
const playerServer = mc.createServer({
'online-mode': false,
port: 25565,
version,
maxPlayers: 1
})
console.log("Proxy running at 127.0.0.1:25565")
let connection;
playerServer.on('login', async (playerClient) => {
console.log(`${playerClient.username} connected to the proxy`)
if (!connection) {
connection = new Connection(host, port)
await connection.created
console.log("Created connection")
}
connection.connectClient(playerClient)
playerClient.once('end', () => {
connection.closeConnection()
connection = null
});
})