… | |
… | |
132 | if (inbuf_len >= 2 + pkt_len) |
132 | if (inbuf_len >= 2 + pkt_len) |
133 | return 2 + pkt_len; |
133 | return 2 + pkt_len; |
134 | |
134 | |
135 | if (inbuf_len == sizeof (inbuf)) |
135 | if (inbuf_len == sizeof (inbuf)) |
136 | { |
136 | { |
137 | send_packet_printf ("drawinfo %d input buffer overflow - closing connection.", NDI_RED | NDI_REPLY); |
137 | send_packet_printf ("msg %d log input buffer overflow - closing connection.", NDI_RED | NDI_REPLY); |
138 | destroy (); |
138 | destroy (); |
139 | return -1; |
139 | return -1; |
140 | } |
140 | } |
141 | } |
141 | } |
142 | |
142 | |
… | |
… | |
167 | |
167 | |
168 | /** |
168 | /** |
169 | * Dispatch table for the server. |
169 | * Dispatch table for the server. |
170 | */ |
170 | */ |
171 | static struct packet_type packets[] = { |
171 | static struct packet_type packets[] = { |
172 | {"ncom", PC(NewPlayerCmd) PF_PLAYING | PF_COMMAND6 }, |
|
|
173 | {"command", PC(PlayerCmd) PF_PLAYING | PF_COMMAND0 }, |
172 | {"command", PC(PlayerCmd) PF_PLAYING | PF_COMMAND }, |
174 | |
173 | |
175 | {"examine", PC(ExamineCmd) PF_PLAYING }, |
174 | {"examine", PC(ExamineCmd) PF_PLAYING }, |
176 | {"ex", PC(ExCmd) PF_PLAYING }, |
175 | {"ex", PC(ExCmd) PF_PLAYING }, |
177 | {"apply", PC(ApplyCmd) PF_PLAYING }, |
176 | {"apply", PC(ApplyCmd) PF_PLAYING }, |
178 | {"lookat", PC(LookAt) PF_PLAYING }, |
177 | {"lookat", PC(LookAt) PF_PLAYING }, |
… | |
… | |
208 | // but kept seperate to emphasise the hack aspect, i.e. |
207 | // but kept seperate to emphasise the hack aspect, i.e. |
209 | // do it better, then remove. |
208 | // do it better, then remove. |
210 | static bool |
209 | static bool |
211 | always_immediate (const client *ns, const packet_type *pkt, const char *data, int len) |
210 | always_immediate (const client *ns, const packet_type *pkt, const char *data, int len) |
212 | { |
211 | { |
213 | if (!(pkt->flags & (PF_COMMAND0 | PF_COMMAND6))) |
212 | if (!(pkt->flags & PF_COMMAND)) |
214 | return false; |
213 | return false; |
215 | |
214 | |
216 | if (!ns->pl || !ns->pl->ob || !ns->pl->ob->map) |
215 | if (!ns->pl || !ns->pl->ob || !ns->pl->ob->map) |
217 | return false; |
216 | return false; |
218 | |
|
|
219 | if (pkt->flags & PF_COMMAND6) |
|
|
220 | { |
|
|
221 | data += 6; |
|
|
222 | len -= 6; |
|
|
223 | } |
|
|
224 | |
217 | |
225 | if (len > 4 && data [ 3] == ' ' && !strncmp (data, "say " , 4)) return true; |
218 | if (len > 4 && data [ 3] == ' ' && !strncmp (data, "say " , 4)) return true; |
226 | if (len > 5 && data [ 4] == ' ' && !strncmp (data, "chat " , 5)) return true; |
219 | if (len > 5 && data [ 4] == ' ' && !strncmp (data, "chat " , 5)) return true; |
227 | if (len > 6 && data [ 5] == ' ' && !strncmp (data, "shout " , 6)) return true; |
220 | if (len > 6 && data [ 5] == ' ' && !strncmp (data, "shout " , 6)) return true; |
228 | if (len > 8 && data [ 7] == ' ' && !strncmp (data, "suicide " , 8)) return true; |
221 | if (len > 8 && data [ 7] == ' ' && !strncmp (data, "suicide " , 8)) return true; |
… | |
… | |
246 | } |
239 | } |
247 | else |
240 | else |
248 | ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this); |
241 | ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this); |
249 | } |
242 | } |
250 | else |
243 | else |
251 | send_packet_printf ("drawinfo %d ERROR: you cannot execute '%s' now.", NDI_RED | NDI_REPLY, pkt->name); |
244 | send_packet_printf ("drawinfo %d log ERROR: you cannot execute '%s' now.", NDI_RED | NDI_REPLY, pkt->name); |
252 | } |
245 | } |
253 | |
246 | |
254 | bool |
247 | bool |
255 | client::handle_packet () |
248 | client::handle_packet () |
256 | { |
249 | { |
… | |
… | |
298 | |
291 | |
299 | goto next_packet; |
292 | goto next_packet; |
300 | } |
293 | } |
301 | |
294 | |
302 | // If we get here, we didn't find a valid command. |
295 | // If we get here, we didn't find a valid command. |
303 | send_packet_printf ("drawinfo %d ERROR: command '%s' not supported.", NDI_RED | NDI_REPLY, (char *)inbuf + 2); |
296 | send_packet_printf ("msg %d log ERROR: command '%s' not supported.", NDI_RED | NDI_REPLY, (char *)inbuf + 2); |
304 | |
297 | |
305 | next_packet: |
298 | next_packet: |
306 | inbuf [pkt_len] = save_byte; // rather ugly |
299 | inbuf [pkt_len] = save_byte; // rather ugly |
307 | skip_packet (pkt_len); |
300 | skip_packet (pkt_len); |
308 | |
301 | |
… | |
… | |
695 | cfperl_send_msg (this, color, type, msg); |
688 | cfperl_send_msg (this, color, type, msg); |
696 | else |
689 | else |
697 | send_packet_printf ("msg %d %s %s", color & NDI_CLIENT_MASK, type, msg); |
690 | send_packet_printf ("msg %d %s %s", color & NDI_CLIENT_MASK, type, msg); |
698 | } |
691 | } |
699 | |
692 | |
700 | void |
|
|
701 | client::send_drawinfo (const char *msg, int flags) |
|
|
702 | { |
|
|
703 | send_msg (flags, "log", msg); |
|
|
704 | } |
|
|
705 | |
|
|
706 | /*********************************************************************** |
693 | /*********************************************************************** |
707 | * |
694 | * |
708 | * packet functions/utilities |
695 | * packet functions/utilities |
709 | * |
696 | * |
710 | **********************************************************************/ |
697 | **********************************************************************/ |