1 /* bzflag 2 * Copyright (c) 1993-2021 Tim Riker 3 * 4 * This package is free software; you can redistribute it and/or 5 * modify it under the terms of the license found in the file 6 * named COPYING that should have accompanied this file. 7 * 8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 13 /* Address: 14 * Encapsulates an Internet address 15 * 16 * PlayerId: 17 * Unique network id for a player. Can be sent 18 * across the net. 19 */ 20 21 #ifndef BZF_INET_ADDR_H 22 #define BZF_INET_ADDR_H 23 24 // system headers 25 #include <sys/types.h> 26 #include <vector> 27 #include <string> 28 29 // local headers 30 #include "common.h" 31 #include "global.h" 32 #include "network.h" 33 #include "Pack.h" 34 35 typedef struct in_addr InAddr; // shorthand 36 37 class Address 38 { 39 public: 40 Address(); 41 Address(const std::string&); 42 Address(const Address&); 43 Address(const InAddr&); // input in nbo 44 Address(const struct sockaddr_in&); // input in nbo 45 ~Address(); 46 Address& operator=(const Address&); 47 48 operator InAddr() const; 49 bool operator==(const Address&) const; 50 bool operator!=(const Address&) const; 51 bool operator<(Address const&) const; 52 bool isAny() const; 53 bool isPrivate() const; 54 std::string getDotNotation() const; 55 uint8_t getIPVersion() const; 56 57 void* pack(void*) const; 58 const void* unpack(const void*); 59 60 static Address getHostAddress(const std::string &hostname = std::string("")); 61 static std::string getHostByAddress(InAddr); 62 static const std::string getHostName(const std::string &hostname = std::string("")); 63 64 private: 65 std::vector <InAddr> addr; 66 }; 67 68 typedef uint8_t PlayerId; 69 const int PlayerIdPLen = sizeof(PlayerId); 70 const int ServerIdPLen = 8; 71 72 // FIXME - enum maybe? put into namespace or class cage? 73 const PlayerId NoPlayer = 255; 74 const PlayerId AllPlayers = 254; 75 const PlayerId ServerPlayer = 253; 76 const PlayerId AdminPlayers = 252; 77 const PlayerId FirstTeam = 251; 78 const PlayerId LastRealPlayer = FirstTeam - NumTeams; 79 80 class ServerId 81 { 82 public: 83 void* pack(void*) const; 84 const void* unpack(const void*); 85 86 bool operator==(const ServerId&) const; 87 bool operator!=(const ServerId&) const; 88 89 public: 90 // host and port in network byte order 91 InAddr serverHost; // server host 92 int16_t port; // server port 93 int16_t number; // local player number 94 }; 95 96 #endif // BZF_INET_ADDR_H 97 98 // Local Variables: *** 99 // mode: C++ *** 100 // tab-width: 4 *** 101 // c-basic-offset: 4 *** 102 // indent-tabs-mode: nil *** 103 // End: *** 104 // ex: shiftwidth=4 tabstop=4 105