-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.coffee
56 lines (44 loc) · 1.5 KB
/
connection.coffee
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
User = require('./user').User
exports.start = (app, lobby) ->
io = require('socket.io').listen(app)
room = null
io.sockets.on 'connection', (socket) ->
user = new User(socket)
socket.emit('news', { hello: 'world' })
socket.on 'disconnect', () ->
console.log(user.name + ' disconnected')
socket.on 'my other event', (data) ->
# 送信: socket.emit('my other event', { my: 'data' });
console.log(data)
console.log(data.my)
socket.on 'enter', (data) ->
console.log(data)
room = lobby.rooms[data.roomId]
room.addUser(user)
socket.on 'login', (data) ->
return if not room
console.log(data)
isSuccess = room.loginUser(user, data.args[0])
res = if isSuccess then 'logged in successfully' else 'already logged in'
socket.emit('ls', { map: res })
socket.on 'getname', (data) ->
console.log('getname')
console.log(data)
socket.emit('ls', { map: user.getNmae() })
socket.on 'ls', (data) ->
return if not room
console.log(data)
socket.emit('ls', { map: room.getStatus().map })
socket.on 'users', (data) ->
return if not room
console.log(data)
names = (u.name for u in room.users).join "\n"
socket.emit('ls', { map: names })
socket.on 'mv', (data) ->
console.log(data)
socket.on 'buid', (data) ->
console.log(data)
socket.on 'debug', (data) ->
console.log('====================')
console.log(user.name)
console.log(user.id)