Merge branch 'development' into multi_server
[KiwiIRC.git] / server / irc / user.js
1 var util = require('util'),
2 EventBinder = require('./eventbinder.js');
3
4 var IrcUser = function (irc_connection, nick) {
5 this.irc_connection = irc_connection;
6 this.nick = nick;
7
8 this.irc_events = {
9 nick: onNick,
10 away: onAway,
11 quit: onQuit,
12 whoisuser: onWhoisUser,
13 whoisoperator: onWhoisOperator,
14 whoischannels: onWhoisChannels,
15 whoismodes: onWhoisModes,
16 whoisidle: onWhoisIdle,
17 whoisregnick: onWhoisRegNick,
18 endofwhois: onWhoisEnd,
19 notice: onNotice,
20 ctcp_response: onCtcpResponse,
21 privmsg: onPrivmsg,
22 ctcp_request: onCtcpRequest,
23 mode: onMode
24 };
25 EventBinder.bindIrcEvents('user ' + this.nick, this.irc_events, this, irc_connection);
26 };
27
28
29 module.exports = IrcUser;
30
31
32 IrcUser.prototype.dispose = function () {
33 EventBinder.unbindIrcEvents('user ' + this.nick, this.irc_events, this.irc_connection);
34 this.irc_connection = undefined;
35 };
36
37
38 function onNick(event) {
39 this.irc_connection.clientEvent('nick', {
40 nick: event.nick,
41 ident: event.ident,
42 hostname: event.hostname,
43 newnick: event.newnick
44 });
45
46 // TODO: uncomment when using an IrcUser per nick
47 //EventBinder.unbindIrcEvents('user ' + this.nick, this.irc_events, irc_connection);
48 //this.nick = event.newnick;
49 //EventBinder.bindIrcEvents('user ' + this.nick, this.irc_events, this, irc_connection);
50 };
51
52 function onAway(event) {
53 this.irc_connection.clientEvent('away', {
54 nick: event.nick,
55 msg: event.msg
56 });
57 };
58
59 function onQuit(event) {
60 this.irc_connection.clientEvent('quit', {
61 nick: event.nick,
62 ident: event.ident,
63 hostname: event.hostname,
64 message: event.trailing
65 });
66 };
67
68 function onWhoisUser(event) {
69 this.irc_connection.clientEvent('whois', {
70 nick: event.nick,
71 ident: event.ident,
72 host: event.host,
73 msg: event.msg,
74 end: false
75 });
76 };
77
78 function onWhoisServer(event) {
79 this.irc_connection.clientEvent('whois', {
80 nick: event.nick,
81 irc_server: event.irc_server,
82 end: false
83 });
84 };
85
86 function onWhoisOperator(event) {
87 this.irc_connection.clientEvent('whois', {
88 nick: event.nick,
89 msg: event.msg,
90 end: false
91 });
92 };
93
94 function onWhoisChannels(event) {
95 this.irc_connection.clientEvent('whois', {
96 nick: event.nick,
97 chans: event.chans,
98 end: false
99 });
100 };
101
102 function onWhoisModes(event) {
103 this.irc_connection.clientEvent('whois', {
104 nick: event.nick,
105 msg: event.msg,
106 end: false
107 });
108 };
109
110 function onWhoisIdle(event) {
111 this.irc_connection.clientEvent('whois', {
112 nick: event.nick,
113 idle: event.idle,
114 logon: event.logon || undefined,
115 end: false
116 });
117 };
118
119 function onWhoisRegNick(event) {
120 this.irc_connection.clientEvent('whois', {
121 nick: event.nick,
122 msg: event.msg,
123 end: false
124 });
125 };
126
127 function onWhoisEnd(event) {
128 this.irc_connection.clientEvent('whois', {
129 nick: event.nick,
130 msg: event.msg,
131 end: true
132 });
133 };
134
135 function onNotice(event) {
136 this.irc_connection.clientEvent('notice', {
137 nick: event.nick,
138 ident: event.ident,
139 hostname: event.hostname,
140 target: event.target,
141 msg: event.msg
142 });
143 };
144
145 function onCtcpResponse(event) {
146 this.irc_connection.clientEvent('ctcp_response', {
147 nick: event.nick,
148 ident: event.ident,
149 hostname: event.hostname,
150 channel: event.channel,
151 msg: event.msg
152 });
153 };
154
155 function onPrivmsg(event) {
156 this.irc_connection.clientEvent('msg', {
157 nick: event.nick,
158 ident: event.ident,
159 hostname: event.hostname,
160 channel: event.channel,
161 msg: event.msg
162 });
163 };
164
165 function onCtcpRequest(event) {
166 this.irc_connection.clientEvent('ctcp_request', {
167 nick: event.nick,
168 ident: event.ident,
169 hostname: event.hostname,
170 target: event.target,
171 type: event.type,
172 msg: event.msg
173 });
174 };
175
176 function onMode(event) {
177 this.irc_connection.clientEvent('mode', {
178 target: event.target,
179 nick: event.nick,
180 modes: event.modes
181 });
182 };