1 /* -*- mode: c++; c-file-style: raknet; tab-always-indent: nil; -*- */
2 /**
3 * @file
4 * @brief Unique Player Identifier Class implementation
5 *
6 * Copyright (c) 2003, Rakkarsoft LLC and Kevin Jenkins
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of the <organization> nor the
17 * names of its contributors may be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #include "NetworkTypes.h"
32 #include "BitStream.h"
33 #include <boost/lexical_cast.hpp>
34
operator ==(const PlayerID & left,const PlayerID & right)35 int operator==( const PlayerID& left, const PlayerID& right )
36 {
37 return left.binaryAddress == right.binaryAddress && left.port == right.port;
38 }
39
operator !=(const PlayerID & left,const PlayerID & right)40 int operator!=( const PlayerID& left, const PlayerID& right )
41 {
42 return left.binaryAddress != right.binaryAddress || left.port != right.port;
43 }
44
operator >(const PlayerID & left,const PlayerID & right)45 int operator>( const PlayerID& left, const PlayerID& right )
46 {
47 return ( ( left.binaryAddress > right.binaryAddress ) || ( ( left.binaryAddress == right.binaryAddress ) && ( left.port > right.port ) ) );
48 }
49
operator <(const PlayerID & left,const PlayerID & right)50 int operator<( const PlayerID& left, const PlayerID& right )
51 {
52 return ( ( left.binaryAddress < right.binaryAddress ) || ( ( left.binaryAddress == right.binaryAddress ) && ( left.port < right.port ) ) );
53 }
54
toString() const55 std::string PlayerID::toString() const
56 {
57 return boost::lexical_cast<std::string>(binaryAddress) + ":" + boost::lexical_cast<std::string>(port);
58 }
59
getStream() const60 RakNet::BitStream Packet::getStream() const
61 {
62 return RakNet::BitStream((char*)data, BITS_TO_BYTES(bitSize), false);
63 }
64