forked from Luca-spopo/ittlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DotBots-server.js.bk
61 lines (55 loc) · 1.66 KB
/
DotBots-server.js.bk
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
let play = {};//require("server-play")
/*
Modes/Lifecycle of a player:
Registering (Give your name, synch timestamps)
=> Preparing (Spawn location decided, etc, preparations made by server)
=> Playing (Player is playing right now)
=> Dead (Player has died, and camera is lingering)
=> Preparing
*/
{
const nameCheck = /^[a-z_0-9]{1, 10}$/i
// const messageHandlerTable = {}
// messageHandlerTable.TIME_SYNCH = function(message, ws)
// {
// let ret = false
// let temp = Date.now - this.ping_start
// if (temp < this.minPing)
// this.minPing = temp;
// else if (this.pingAttempts == 10)
// ret = messageHandlerTable.PREPARING
// this.pingAttempts++;
// return ret
// }
// messageHandlerTable.NAMING = function(message, ws) {
// if (nameCheck.test(message))
// this.name = message;
// return messageHandlerTable.TIME_SYNCH;
// }
const PlayerTable = new Map(); //WebSocket => Player Details
//PlayerTable is sent to other modules as context, and is thus const.
let messageHandler = function(message)
{
let details = PlayerTable.get(this)
//let temp = details.onMessage(message.data, this)
//if(temp)
// this.onMessage = temp;
details.onMessage.next(message)
}
let connectPlayer = function(ws)
{
let FSM = PlayerFSM();
let details = { name : "1337H4X", onMessage : FSM}; //messageHandlerTable.NAMING}
PlayerTable.set(ws, details)
FSM.next();
FSM.next(details, ws)
ws.on("message", messageHandler)
}
let main = function()
{
play.main({PlayerTable : PlayerTable});
exports.connectPlayer = connectPlayer; //Start accepting connections
}
exports.main = main;
}