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,2013,2014,2015,2016 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 |
… | |
… | |
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) |
… | |
… | |
718 | { |
719 | { |
719 | val >>= 7; |
720 | val >>= 7; |
720 | *--p = (val & 0x7F) | 0x80; |
721 | *--p = (val & 0x7F) | 0x80; |
721 | } |
722 | } |
722 | |
723 | |
723 | return *this << data (p, buf + maxlen - p); |
724 | return *this << data_n (p, buf + maxlen - p); |
724 | } |
725 | } |
725 | |
726 | |
726 | packet &packet::operator <<(const data &v) |
727 | packet &packet::operator <<(const data_n &v) |
727 | { |
728 | { |
728 | if (room () < v.len) |
729 | if (room () < v.len) |
729 | reset (); |
730 | reset (); |
730 | else |
731 | else |
731 | { |
732 | { |
… | |
… | |
740 | } |
741 | } |
741 | |
742 | |
742 | packet &packet::operator <<(const data8 &v) |
743 | packet &packet::operator <<(const data8 &v) |
743 | { |
744 | { |
744 | unsigned int len = min (v.len, 0x00FF); |
745 | unsigned int len = min (v.len, 0x00FF); |
745 | return *this << uint8 (len) << data (v.ptr, len); |
746 | return *this << uint8 (len) << data_n (v.ptr, len); |
746 | } |
747 | } |
747 | |
748 | |
748 | packet &packet::operator <<(const data16 &v) |
749 | packet &packet::operator <<(const data16 &v) |
749 | { |
750 | { |
750 | unsigned int len = min (v.len, 0xFFFF); |
751 | unsigned int len = min (v.len, 0xFFFF); |
751 | return *this << uint16 (len) << data (v.ptr, len); |
752 | return *this << uint16 (len) << data_n (v.ptr, len); |
752 | } |
753 | } |
753 | |
754 | |
754 | packet &packet::operator <<(const char *v) |
755 | packet &packet::operator <<(const char *v) |
755 | { |
756 | { |
756 | return *this << data (v, strlen (v ? v : 0)); |
757 | return *this << data_n (v, v ? strlen (v) : 0); |
757 | } |
758 | } |
758 | |
759 | |
759 | void |
760 | void |
760 | packet::vprintf (const char *format, va_list ap) |
761 | packet::vprintf (const char *format, va_list ap) |
761 | { |
762 | { |