-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchat.coffee
148 lines (121 loc) · 5.94 KB
/
chat.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
database = require '../services/database'
parser = require '../utils/parser'
math = require '../utils/math'
builder = require '../utils/builder'
logger = new (require '../utils/logger')(name: 'Chat')
module.exports =
joinRoom: ->
return if @user.chat < 1
database.exec('SELECT * FROM chats WHERE id = ? LIMIT 1', [@user.chat]).then((data) =>
if @user.chat is 8
@send '<i b=";=;=;=- Cant ;=" f="932" v="1" cb="0" />'
@send '<w v="0 0 1" />'
@send '<done />'
return
@chat = data[0] if @chat is null
return false if !@chat
## Push the user to the rooms object
if typeof global.Server.rooms[@user.chat] is 'object'
global.Server.rooms[@user.chat][@user.id] = @
else
global.Server.rooms[@user.chat] = { }
global.Server.rooms[@user.chat][@user.id] = @
@chat.attached = try JSON.parse(@chat.attached) catch error then {}
@chat.onPool = @chat.onPool || 0
## Chat settings and info
## r: 1 - (All main owner) / 2 - (All moderator) / 3 - (All member) / 4 (All owner)
## v: 1 - (Normal) / 3 - (w_VIP) / 4 - (w_ALLP) / other - (All unregistered)
packet = builder.create('i')
packet.append('b', "#{@chat.bg};=#{@chat.attached.name||''};=#{@chat.attached.id||''};=#{@chat.language};=#{@chat.radio};=#{@chat.button}")
packet.append('f', '21233728')
packet.append('v', '3')
packet.append('cb', '2387')
@send packet.compose()
## Chat group powers
packet = builder.create('gp')
packet.append('p', '0|0|1163220288|1079330064|20975876|269549572|16645|4210689|1|4194304|0|0|0|')
packet.append('g180', "{'m':'','d':'','t':'','v':1}")
packet.append('g256', "{'rnk':'8','dt':120,'rc':'1','v':1}")
packet.append('g100', 'assistance,1lH2M4N,xatalert,1e7wfSx')
packet.append('g114', "{'m':'Lobby','t':'Staff','rnk':'8','b':'Jail','brk':'8','v':1}")
packet.append('g112', 'Welcome to the lobby! Visit assistance and help pages.')
packet.append('g246', "{'rnk':'8','dt':30,'rt':'10','rc':'1','tg':1000,'v':1}")
packet.append('g90', 'shit,faggot,slut,cum,nigga,niqqa,prostitute,ixat,azzhole,tits,dick,sex,fuk,fuc,thot')
packet.append('g80', "{'mb':'11','ubn':'8','mbt':24,'ss':'8','rgd':'8','prm':'14','bge':'8','mxt':60,'sme':'11','dnc':'11','bdg':'11','yl':'10','rc':'10','p':'7','ka':'7'}")
packet.append('g74', 'd,waiting,astonished,swt,crs,un,redface,evil,rolleyes,what,aghast,omg,smirk')
packet.append('g106', 'c#sloth')
@send packet.compose()
## Chat pools
@send builder.create('w').append('v', "#{@chat.onPool} #{@chat.pool}").compose()
## Broadcast the current user
packet = builder.create('u')
packet.append('cb', '1443256921')
.append('s', '1')
.append('f', @user.f)
.append('u', @user.id)
.append('n', @user.nickname)
.append('q', '3')
.append('a', @user.avatar)
.append('h', @user.url)
.append('cb', '1443256921')
.append('v', '0')
if @user.registered
packet.append('N', @user.username)
packet.append('d0', @user.d0)
packet.append('d2', @user.d2) if @user.d2
packet.appendRaw(@user.pStr)
@broadcast packet.compose()
## Room messages
database.exec('SELECT * FROM (SELECT * FROM messages WHERE id = ? AND pool = ? ORDER BY time DESC LIMIT 15) sub ORDER BY time ASC LIMIT 0,15', [ @user.chat, @chat.onPool ]).then((data) =>
offline = new Array()
for message in data
continue if global.Server.rooms[@user.chat][message.uid]?.chat.onPool is @chat.onPool
packet = builder.create('o')
packet.append('u', message.uid)
.append('u', message.uid)
.append('n', message.name)
.append('a', message.avatar)
packet.append('N', message.registered) if message.registered isnt 'unregistered'
if offline.indexOf(message.uid) is -1
@send packet.compose()
offline.push(message.uid)
for _, client of global.Server.rooms[@user.chat]
continue if client.id is @user.id or client.chat.onPool isnt @chat.onPool
user = client.user
packet = builder.create('u')
packet.append('cb', '1414865425')
packet.append('s', '1')
packet.append('f', user.f)
packet.append('u', user.id)
packet.append('q', '3')
packet.append('n', user.nickname)
packet.append('a', user.avatar)
packet.append('h', user.url)
packet.append('v', '0')
if user.registered
packet.append('N', user.username)
packet.append('d0', user.d0)
packet.append('d2', user.d2) if user.d2
packet.appendRaw(user.pStr)
@send packet.compose()
data.forEach((message) =>
packet = builder.create('m')
packet.append('E', message.time)
.append('u', message.uid)
.append('t', message.message)
.append('s', '1')
@send packet.compose()
)
## Scroll message
# database.exec('SELECT * FROM messages WHERE id = ? AND SUBSTRING(message FROM 0 FOR 2) ORDER BY time DESC LIMIT 1', [ @user.chat ]).then((data) ->
@send builder.create('m').append('t', "/s#{@chat.sc}").append('d', '123').compose()
## Done packet
@send '<done />'
# )
)
)
sendMessage: (user, message) ->
@broadcast builder.create('m').append('t', message).append('u', user).compose()
database.exec('INSERT INTO messages (id, uid, message, name, registered, avatar, time, pool) values (?, ?, ?, ?, ?, ?, ?, ?)', [ @user.chat, @user.id, message, @user.nickname, @user.username||'unregistered', @user.avatar, math.time(), @chat.onPool ]).then((data) ->
logger.log logger.level.DEBUG, 'New message sent'
).catch((err) -> logger.log logger.level.ERROR, 'Failed to send a message to the database', err)