12
12
#include "opennap.h"
13
13
#include "debug.h"
14
14
15
+ /* static buffer for use by public/emote. these get called a lot so speed
16
+ things up by keeping it around. there is no chance of either of these
17
+ being called from eachother or used elsewhere so this is safe */
18
+ static char PublicBuf [2048 ];
19
+
15
20
/* [ :<sender> ] <channel> <text> */
16
21
/* public message to a channel */
17
22
HANDLER (public )
@@ -23,7 +28,6 @@ HANDLER (public)
23
28
CHANUSER * chanUser ;
24
29
25
30
(void ) tag ;
26
- (void ) len ;
27
31
ASSERT (validate_connection (con ));
28
32
/* save the starting position of the pkt */
29
33
ptr = pkt ;
@@ -54,11 +58,6 @@ HANDLER (public)
54
58
unparsable (con );
55
59
return ;
56
60
}
57
- if (invalid_channel (pkt ))
58
- {
59
- invalid_channel_msg (con );
60
- return ;
61
- }
62
61
63
62
/* find the channel this message is going to. look the user's joined
64
63
channels since this should be faster than lookup in the hash table */
@@ -73,18 +72,25 @@ HANDLER (public)
73
72
/* relay this message to peer servers */
74
73
pass_message_args (con , tag , ":%s %s %s" , sender -> nick , chan -> name , pkt );
75
74
75
+ /* the majority of the users in the channel will see this message, so
76
+ form it one time */
77
+ len = form_message (PublicBuf , sizeof (PublicBuf ), MSG_SERVER_PUBLIC ,
78
+ "%s %s %s" , chan -> name ,
79
+ sender -> cloaked ? "Operator" : sender -> nick ,
80
+ pkt );
81
+
76
82
/* send this message to everyone in the channel */
77
83
for (list = chan -> users ; list ; list = list -> next )
78
84
{
79
85
chanUser = list -> data ;
80
86
ASSERT (chanUser -> magic == MAGIC_CHANUSER );
81
87
if (ISUSER (chanUser -> user -> con ))
82
88
{
83
- send_cmd ( chanUser -> user -> con , MSG_SERVER_PUBLIC , "%s %s %s" ,
84
- chan -> name , (! sender -> cloaked
85
- || chanUser -> user -> level >
86
- LEVEL_USER ) ? sender -> nick : "Operator" ,
87
- pkt );
89
+ if ( sender -> cloaked && chanUser -> user -> level > LEVEL_USER )
90
+ send_cmd ( chanUser -> user -> con , MSG_SERVER_PUBLIC , "%s %s %s" ,
91
+ chan -> name , sender -> nick , pkt );
92
+ else
93
+ queue_data ( chanUser -> user -> con , PublicBuf , len );
88
94
}
89
95
}
90
96
}
@@ -99,7 +105,6 @@ HANDLER (emote)
99
105
LIST * list ;
100
106
101
107
(void ) tag ;
102
- (void ) len ;
103
108
ASSERT (validate_connection (con ));
104
109
ptr = pkt ; /* save initial location */
105
110
if (pop_user (con , & pkt , & user ) != 0 )
@@ -126,11 +131,6 @@ HANDLER (emote)
126
131
unparsable (con );
127
132
return ;
128
133
}
129
- if (invalid_channel (av [0 ]))
130
- {
131
- invalid_channel_msg (con );
132
- return ;
133
- }
134
134
135
135
/* find the channel this message is going to. look the user's joined
136
136
channels since this should be faster than lookup in the hash table */
@@ -146,17 +146,24 @@ HANDLER (emote)
146
146
pass_message_args (con , tag , ":%s %s \"%s\"" , user -> nick , chan -> name ,
147
147
av [1 ]);
148
148
149
+ /* majority of the users see the same message, so form it once */
150
+ len = form_message (PublicBuf ,sizeof (PublicBuf ),tag ,"%s %s \"%s\"" ,
151
+ chan -> name ,
152
+ user -> cloaked ? "Operator" : user -> nick ,
153
+ av [1 ]);
154
+
149
155
/* send this message to all channel members */
150
156
for (list = chan -> users ; list ; list = list -> next )
151
157
{
152
158
chanUser = list -> data ;
153
159
ASSERT (chanUser -> magic == MAGIC_CHANUSER );
154
160
if (ISUSER (chanUser -> user -> con ))
155
161
{
156
- send_cmd (chanUser -> user -> con , tag , "%s %s \"%s\"" , chan -> name ,
157
- (!user -> cloaked
158
- || chanUser -> user -> level >
159
- LEVEL_MODERATOR ) ? user -> nick : "Operator" , av [1 ]);
162
+ if (user -> cloaked && chanUser -> user -> level > LEVEL_USER )
163
+ send_cmd (chanUser -> user -> con , tag , "%s %s \"%s\"" ,
164
+ chan -> name , user -> nick , av [1 ]);
165
+ else
166
+ queue_data (chanUser -> user -> con ,PublicBuf ,len );
160
167
}
161
168
}
162
169
}
0 commit comments