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.94 by root, Sun Nov 18 09:29:25 2012 UTC vs.
Revision 1.101 by root, Sat Dec 1 20:22:13 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.
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 |
239 } 240 }
240 else 241 else
241 ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this); 242 ((void (*)(char *, int, client *))pkt->cb)((char *)data, datalen, this);
242 } 243 }
243 else 244 else
244 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);
245} 246}
246 247
247bool 248bool
248client::handle_packet () 249client::handle_packet ()
249{ 250{
279 { 280 {
280 data = (char *)inbuf + 2; // better read garbage than segfault 281 data = (char *)inbuf + 2; // better read garbage than segfault
281 datalen = 0; 282 datalen = 0;
282 } 283 }
283 284
284 for (packet_type *pkt = packets; pkt < packets + array_length (packets); ++pkt) 285 for (packet_type *pkt = packets; pkt < packets + ecb_array_length (packets); ++pkt)
285 if (!strcmp ((char *)inbuf + 2, pkt->name)) 286 if (!strcmp ((char *)inbuf + 2, pkt->name))
286 { 287 {
287 if (pkt->flags & PF_PLAYER && !always_immediate (this, pkt, data, datalen)) 288 if (pkt->flags & PF_PLAYER && !always_immediate (this, pkt, data, datalen))
288 queue_command (pkt, data, datalen); 289 queue_command (pkt, data, datalen);
289 else 290 else
646void 647void
647client::send_packet (const char *buf, int len) 648client::send_packet (const char *buf, int len)
648{ 649{
649 packet sl; 650 packet sl;
650 651
651 sl << data (buf, len); 652 sl << data_n (buf, len);
652 send_packet (sl); 653 send_packet (sl);
653} 654}
654 655
655void 656void
656client::send_packet (const char *buf) 657client::send_packet (const char *buf)
688 cfperl_send_msg (this, color, type, msg); 689 cfperl_send_msg (this, color, type, msg);
689 else 690 else
690 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);
691} 692}
692 693
693void
694client::send_drawinfo (const char *msg, int flags)
695{
696 send_msg (flags, "log", msg);
697}
698
699/*********************************************************************** 694/***********************************************************************
700 * 695 *
701 * packet functions/utilities 696 * packet functions/utilities
702 * 697 *
703 **********************************************************************/ 698 **********************************************************************/
724 { 719 {
725 val >>= 7; 720 val >>= 7;
726 *--p = (val & 0x7F) | 0x80; 721 *--p = (val & 0x7F) | 0x80;
727 } 722 }
728 723
729 return *this << data (p, buf + maxlen - p); 724 return *this << data_n (p, buf + maxlen - p);
730} 725}
731 726
732packet &packet::operator <<(const data &v) 727packet &packet::operator <<(const data_n &v)
733{ 728{
734 if (room () < v.len) 729 if (room () < v.len)
735 reset (); 730 reset ();
736 else 731 else
737 { 732 {
746} 741}
747 742
748packet &packet::operator <<(const data8 &v) 743packet &packet::operator <<(const data8 &v)
749{ 744{
750 unsigned int len = min (v.len, 0x00FF); 745 unsigned int len = min (v.len, 0x00FF);
751 return *this << uint8 (len) << data (v.ptr, len); 746 return *this << uint8 (len) << data_n (v.ptr, len);
752} 747}
753 748
754packet &packet::operator <<(const data16 &v) 749packet &packet::operator <<(const data16 &v)
755{ 750{
756 unsigned int len = min (v.len, 0xFFFF); 751 unsigned int len = min (v.len, 0xFFFF);
757 return *this << uint16 (len) << data (v.ptr, len); 752 return *this << uint16 (len) << data_n (v.ptr, len);
758} 753}
759 754
760packet &packet::operator <<(const char *v) 755packet &packet::operator <<(const char *v)
761{ 756{
762 return *this << data (v, strlen (v ? v : 0)); 757 return *this << data_n (v, v ? strlen (v) : 0);
763} 758}
764 759
765void 760void
766packet::vprintf (const char *format, va_list ap) 761packet::vprintf (const char *format, va_list ap)
767{ 762{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines