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 | |
247 | bool |
248 | bool |
248 | client::handle_packet () |
249 | client::handle_packet () |
249 | { |
250 | { |
… | |
… | |
646 | void |
647 | void |
647 | client::send_packet (const char *buf, int len) |
648 | client::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 | |
655 | void |
656 | void |
656 | client::send_packet (const char *buf) |
657 | client::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 | |
693 | void |
|
|
694 | client::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 | |
732 | packet &packet::operator <<(const data &v) |
727 | packet &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 | |
748 | packet &packet::operator <<(const data8 &v) |
743 | packet &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 | |
754 | packet &packet::operator <<(const data16 &v) |
749 | packet &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 | |
760 | packet &packet::operator <<(const char *v) |
755 | packet &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 | |
765 | void |
760 | void |
766 | packet::vprintf (const char *format, va_list ap) |
761 | packet::vprintf (const char *format, va_list ap) |
767 | { |
762 | { |