ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/lowlevel.C
(Generate patch)

Comparing deliantra/server/socket/lowlevel.C (file contents):
Revision 1.91 by root, Thu Nov 8 02:50:14 2012 UTC vs.
Revision 1.100 by root, Wed Nov 14 23:24:27 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 6 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 7 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 8 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 9 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 10 * option) any later version.
132 if (inbuf_len >= 2 + pkt_len) 133 if (inbuf_len >= 2 + pkt_len)
133 return 2 + pkt_len; 134 return 2 + pkt_len;
134 135
135 if (inbuf_len == sizeof (inbuf)) 136 if (inbuf_len == sizeof (inbuf))
136 { 137 {
137 send_packet_printf ("drawinfo %d input buffer overflow - closing connection.", NDI_RED | NDI_REPLY); 138 send_packet_printf ("msg %d log input buffer overflow - closing connection.", NDI_RED | NDI_REPLY);
138 destroy (); 139 destroy ();
139 return -1; 140 return -1;
140 } 141 }
141 } 142 }
142 143
150 memmove (inbuf, inbuf + len, inbuf_len); 151 memmove (inbuf, inbuf + len, inbuf_len);
151} 152}
152 153
153/***************************************************************************** 154/*****************************************************************************
154 * Start of command dispatch area. 155 * Start of command dispatch area.
155 * The commands here are protocol commands. 156 * The commands here are protocol commands.
156 ****************************************************************************/ 157 ****************************************************************************/
157 158
158// SocketCommand, PlayingCommand, should not exist with those ugly casts 159// SocketCommand, PlayingCommand, should not exist with those ugly casts
159#define SC(cb) (void *)static_cast<void (*)(char *, int, client *)>(cb), 160#define SC(cb) (void *)static_cast<void (*)(char *, int, client *)>(cb),
160#define PC(cb) (void *)static_cast<void (*)(char *, int, player *)>(cb), PF_PLAYER | 161#define PC(cb) (void *)static_cast<void (*)(char *, int, player *)>(cb), PF_PLAYER |
167 168
168/** 169/**
169 * Dispatch table for the server. 170 * Dispatch table for the server.
170 */ 171 */
171static struct packet_type packets[] = { 172static struct packet_type packets[] = {
172 {"ncom", PC(NewPlayerCmd) PF_PLAYING | PF_COMMAND6 },
173 {"command", PC(PlayerCmd) PF_PLAYING | PF_COMMAND0 }, 173 {"command", PC(PlayerCmd) PF_PLAYING | PF_COMMAND },
174 174
175 {"examine", PC(ExamineCmd) PF_PLAYING }, 175 {"examine", PC(ExamineCmd) PF_PLAYING },
176 {"ex", PC(ExCmd) PF_PLAYING }, 176 {"ex", PC(ExCmd) PF_PLAYING },
177 {"apply", PC(ApplyCmd) PF_PLAYING }, 177 {"apply", PC(ApplyCmd) PF_PLAYING },
178 {"lookat", PC(LookAt) PF_PLAYING }, 178 {"lookat", PC(LookAt) PF_PLAYING },
208// but kept seperate to emphasise the hack aspect, i.e. 208// but kept seperate to emphasise the hack aspect, i.e.
209// do it better, then remove. 209// do it better, then remove.
210static bool 210static bool
211always_immediate (const client *ns, const packet_type *pkt, const char *data, int len) 211always_immediate (const client *ns, const packet_type *pkt, const char *data, int len)
212{ 212{
213 if (!(pkt->flags & (PF_COMMAND0 | PF_COMMAND6))) 213 if (!(pkt->flags & PF_COMMAND))
214 return false; 214 return false;
215 215
216 if (!ns->pl || !ns->pl->ob || !ns->pl->ob->map) 216 if (!ns->pl || !ns->pl->ob || !ns->pl->ob->map)
217 return false; 217 return false;
218
219 if (pkt->flags & PF_COMMAND6)
220 {
221 data += 6;
222 len -= 6;
223 }
224 218
225 if (len > 4 && data [ 3] == ' ' && !strncmp (data, "say " , 4)) return true; 219 if (len > 4 && data [ 3] == ' ' && !strncmp (data, "say " , 4)) return true;
226 if (len > 5 && data [ 4] == ' ' && !strncmp (data, "chat " , 5)) return true; 220 if (len > 5 && data [ 4] == ' ' && !strncmp (data, "chat " , 5)) return true;
227 if (len > 6 && data [ 5] == ' ' && !strncmp (data, "shout " , 6)) return true; 221 if (len > 6 && data [ 5] == ' ' && !strncmp (data, "shout " , 6)) return true;
228 if (len > 8 && data [ 7] == ' ' && !strncmp (data, "suicide " , 8)) return true; 222 if (len > 8 && data [ 7] == ' ' && !strncmp (data, "suicide " , 8)) return true;
246 } 240 }
247 else 241 else
248 ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this); 242 ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this);
249 } 243 }
250 else 244 else
251 send_packet_printf ("drawinfo %d ERROR: you cannot execute '%s' now.", NDI_RED | NDI_REPLY, pkt->name); 245 send_packet_printf ("msg %d log ERROR: you cannot execute '%s' now.", NDI_RED | NDI_REPLY, pkt->name);
252} 246}
253 247
254bool 248bool
255client::handle_packet () 249client::handle_packet ()
256{ 250{
298 292
299 goto next_packet; 293 goto next_packet;
300 } 294 }
301 295
302 // If we get here, we didn't find a valid command. 296 // 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); 297 send_packet_printf ("msg %d log ERROR: command '%s' not supported.", NDI_RED | NDI_REPLY, (char *)inbuf + 2);
304 298
305next_packet: 299next_packet:
306 inbuf [pkt_len] = save_byte; // rather ugly 300 inbuf [pkt_len] = save_byte; // rather ugly
307 skip_packet (pkt_len); 301 skip_packet (pkt_len);
308 302
653void 647void
654client::send_packet (const char *buf, int len) 648client::send_packet (const char *buf, int len)
655{ 649{
656 packet sl; 650 packet sl;
657 651
658 sl << data (buf, len); 652 sl << data_n (buf, len);
659 send_packet (sl); 653 send_packet (sl);
660} 654}
661 655
662void 656void
663client::send_packet (const char *buf) 657client::send_packet (const char *buf)
695 cfperl_send_msg (this, color, type, msg); 689 cfperl_send_msg (this, color, type, msg);
696 else 690 else
697 send_packet_printf ("msg %d %s %s", color & NDI_CLIENT_MASK, type, msg); 691 send_packet_printf ("msg %d %s %s", color & NDI_CLIENT_MASK, type, msg);
698} 692}
699 693
700void
701client::send_drawinfo (const char *msg, int flags)
702{
703 send_msg (flags, "log", msg);
704}
705
706/*********************************************************************** 694/***********************************************************************
707 * 695 *
708 * packet functions/utilities 696 * packet functions/utilities
709 * 697 *
710 **********************************************************************/ 698 **********************************************************************/
731 { 719 {
732 val >>= 7; 720 val >>= 7;
733 *--p = (val & 0x7F) | 0x80; 721 *--p = (val & 0x7F) | 0x80;
734 } 722 }
735 723
736 return *this << data (p, buf + maxlen - p); 724 return *this << data_n (p, buf + maxlen - p);
737} 725}
738 726
739packet &packet::operator <<(const data &v) 727packet &packet::operator <<(const data_n &v)
740{ 728{
741 if (room () < v.len) 729 if (room () < v.len)
742 reset (); 730 reset ();
743 else 731 else
744 { 732 {
753} 741}
754 742
755packet &packet::operator <<(const data8 &v) 743packet &packet::operator <<(const data8 &v)
756{ 744{
757 unsigned int len = min (v.len, 0x00FF); 745 unsigned int len = min (v.len, 0x00FF);
758 return *this << uint8 (len) << data (v.ptr, len); 746 return *this << uint8 (len) << data_n (v.ptr, len);
759} 747}
760 748
761packet &packet::operator <<(const data16 &v) 749packet &packet::operator <<(const data16 &v)
762{ 750{
763 unsigned int len = min (v.len, 0xFFFF); 751 unsigned int len = min (v.len, 0xFFFF);
764 return *this << uint16 (len) << data (v.ptr, len); 752 return *this << uint16 (len) << data_n (v.ptr, len);
765} 753}
766 754
767packet &packet::operator <<(const char *v) 755packet &packet::operator <<(const char *v)
768{ 756{
769 return *this << data (v, strlen (v ? v : 0)); 757 return *this << data_n (v, v ? strlen (v) : 0);
770} 758}
771 759
772void 760void
773packet::vprintf (const char *format, va_list ap) 761packet::vprintf (const char *format, va_list ap)
774{ 762{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines