├── .gitignore ├── LICENSE.md ├── README.md ├── client ├── Binary.cpp ├── CMakeLists.txt ├── Channel.cpp ├── Event.cpp ├── Main.cpp ├── PacketReader.cpp ├── Platform.hpp ├── RedRelayClient.cpp └── RedRelayClient.hpp ├── deps ├── README.md ├── SFML │ ├── Clock.cpp │ ├── Config.hpp │ ├── Err.cpp │ ├── IpAddress.cpp │ ├── Lock.cpp │ ├── Mutex.cpp │ ├── Network.hpp │ ├── Network │ │ ├── Export.hpp │ │ ├── IpAddress.hpp │ │ ├── Socket.hpp │ │ ├── SocketHandle.hpp │ │ ├── SocketImpl.hpp │ │ ├── SocketSelector.hpp │ │ ├── TcpListener.hpp │ │ ├── TcpSocket.hpp │ │ ├── UdpSocket.hpp │ │ ├── UnixSocketImpl.hpp │ │ └── Win32SocketImpl.hpp │ ├── Sleep.cpp │ ├── Socket.cpp │ ├── SocketSelector.cpp │ ├── System.hpp │ ├── System │ │ ├── Clock.hpp │ │ ├── Err.hpp │ │ ├── Export.hpp │ │ ├── Lock.hpp │ │ ├── Mutex.hpp │ │ ├── NonCopyable.hpp │ │ ├── Sleep.hpp │ │ ├── Time.hpp │ │ ├── UnixClockImpl.hpp │ │ ├── UnixImpl.hpp │ │ ├── UnixMutexImpl.hpp │ │ ├── UnixSleepImpl.hpp │ │ ├── Win32ClockImpl.hpp │ │ ├── Win32MutexImpl.hpp │ │ └── Win32SleepImpl.hpp │ ├── TcpListener.cpp │ ├── TcpSocket.cpp │ ├── Time.cpp │ ├── UdpSocket.cpp │ ├── UnixClockImpl.cpp │ ├── UnixMutexImpl.cpp │ ├── UnixSleepImpl.cpp │ ├── UnixSocketImpl.cpp │ ├── Win32ClockImpl.cpp │ ├── Win32MutexImpl.cpp │ ├── Win32SleepImpl.cpp │ └── Win32SocketImpl.cpp ├── wepoll.c └── wepoll.h ├── doc └── client.html ├── include ├── RedRelayClient.hpp └── RedRelayServer.hpp └── server ├── CMakeLists.txt ├── Channel.cpp ├── ConsoleColors.hpp ├── EpollSelector.cpp ├── EpollSelector.hpp ├── IDPool.hpp ├── Main.cpp ├── ModSocket.hpp ├── Platform.hpp ├── RedRelayServer.cpp ├── RedRelayServer.hpp └── RelayPacket.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # RedRelay 2 | 3 | RedRelay - Copyright (C) 2019 LekKit - published under zlib/libpng license 4 | 5 | This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | 9 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 10 | 11 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 12 | 13 | 3. This notice may not be removed or altered from any source distribution. 14 | 15 | ## External libraries used by RedRelay 16 | 17 | * _SFML-Network_ is under zlib/libpng license 18 | * _wepoll_ (optional) is under BSD license 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RedRelay 2 | RedRelay is a C++ networking library reimplementing Lacewing Relay protocol - an IRC-like protocol where peers have their unique IDs and names, can join channels and transmit data packets through TCP or UDP - can be used for chat, games, VoIP, data sharing, etc. 3 | 4 | It is cross-platform and allows to use it not only in C++, but also as a Clickeam Fusion extension, or, for example, in Lua. 5 | 6 | RedRelay is completely open-source, licensed under zlib/libpng license, allowing you to use it in any commercial project, etc 7 | 8 | Documentation for the client library can be found at [doc/client.html](https://htmlpreview.github.io/?https://github.com/LekKit/RedRelay/blob/master/doc/client.html) 9 | -------------------------------------------------------------------------------- /client/Binary.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // RedRelay - a Lacewing Relay protocol reimplementation 4 | // Copyright (c) 2019 LekKit (LekKit#4400 in Discord) 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source distribution. 21 | // 22 | //////////////////////////////////////////////////////////// 23 | 24 | #include "RedRelayClient.hpp" 25 | 26 | namespace rc{ 27 | 28 | Binary::Binary(std::size_t Size){ 29 | size=0; 30 | capacity=Size+6; 31 | buffer = new char[Size+6]; 32 | } 33 | 34 | Binary::~Binary(){ 35 | delete[] buffer; 36 | } 37 | 38 | void Binary::Reallocate(std::size_t newcapacity){ 39 | if (newcapacity<=size+6 || newcapacity==capacity) return; 40 | char* tmp = new char[newcapacity]; 41 | for (std::size_t i=0; icapacity) Reallocate(capacity*2); 49 | size=Size; 50 | } 51 | 52 | const char* Binary::GetAddress() const { 53 | return &buffer[6]; 54 | } 55 | 56 | std::size_t Binary::GetSize() const { 57 | return size; 58 | } 59 | 60 | void Binary::Clear(){ 61 | size=0; 62 | } 63 | 64 | /* By almost any compiler this should be optimized into 65 | direct copy, with byte reversing on big-endian CPU */ 66 | 67 | void Binary::AddByte(uint8_t Byte){ 68 | while (size+6+1>capacity) Reallocate(capacity*2); 69 | buffer[6+size++]=Byte; 70 | } 71 | 72 | void Binary::AddShort(uint16_t Short){ 73 | while (size+6+2>capacity) Reallocate(capacity*2); 74 | buffer[6+size++]=Short&255; 75 | buffer[6+size++]=(Short>>8)&255; 76 | } 77 | 78 | void Binary::AddInt(uint32_t Int){ 79 | while (size+6+4>capacity) Reallocate(capacity*2); 80 | buffer[6+size++]=Int&255; 81 | buffer[6+size++]=(Int>>8)&255; 82 | buffer[6+size++]=(Int>>16)&255; 83 | buffer[6+size++]=(Int>>24)&255; 84 | } 85 | 86 | void Binary::AddLong(uint64_t Long){ 87 | while (size+6+8>capacity) Reallocate(capacity*2); 88 | buffer[6+size++]=Long&255; 89 | buffer[6+size++]=(Long>>8)&255; 90 | buffer[6+size++]=(Long>>16)&255; 91 | buffer[6+size++]=(Long>>24)&255; 92 | buffer[6+size++]=(Long>>32)&255; 93 | buffer[6+size++]=(Long>>40)&255; 94 | buffer[6+size++]=(Long>>48)&255; 95 | buffer[6+size++]=(Long>>56)&255; 96 | } 97 | 98 | void Binary::AddFloat(float Float){ 99 | uint32_t tmp; 100 | memcpy(&tmp, &Float, 4); 101 | AddInt(tmp); 102 | } 103 | 104 | void Binary::AddDouble(double Double){ 105 | uint64_t tmp; 106 | memcpy(&tmp, &Double, 8); 107 | AddLong(tmp); 108 | } 109 | 110 | void Binary::AddString(const std::string& String){ 111 | while (size+6+String.length()>capacity) Reallocate(capacity*2); 112 | memcpy(&buffer[6+size], String.c_str(), String.length()); 113 | size+=String.length(); 114 | } 115 | 116 | void Binary::AddNullString(const std::string& String){ 117 | AddString(String); 118 | AddByte(0); 119 | } 120 | 121 | void Binary::AddBinary(const void* Data, std::size_t Size){ 122 | while (size+6+Size>capacity) Reallocate(capacity*2); 123 | memcpy(&buffer[6+size], Data, Size); 124 | size+=Size; 125 | } 126 | 127 | ///////////////////////////////////////////////// 128 | // Relay packet inheritance for internal usage // 129 | ///////////////////////////////////////////////// 130 | 131 | void RelayPacket::SetType(const uint8_t Type){ 132 | type=Type<<4; 133 | } 134 | 135 | void RelayPacket::SetVariant(const uint8_t Variant){ 136 | type=(type&240)|(Variant&15); 137 | } 138 | 139 | const char* RelayPacket::GetPacket(){ 140 | if (size<254){ 141 | buffer[4]=type; 142 | buffer[5]=size&255; 143 | return &buffer[4]; 144 | } else if (size<65535){ 145 | buffer[2]=type; 146 | buffer[3]=(uint8_t)254; 147 | buffer[4]=size&255; 148 | buffer[5]=(size>>8)&255; 149 | return &buffer[2]; 150 | } else { 151 | buffer[0]=type; 152 | buffer[1]=(uint8_t)254; 153 | buffer[2]=size&255; 154 | buffer[3]=(size>>8)&255; 155 | buffer[4]=(size>>16)&255; 156 | buffer[5]=(size>>24)&255; 157 | return &buffer[0]; 158 | } 159 | } 160 | 161 | std::size_t RelayPacket::GetPacketSize() const { 162 | if (size<254) return 2+size; 163 | else if (size<65535) return 4+size; 164 | else return 6+size; 165 | } 166 | 167 | void RelayPacket::Clear(){ 168 | type=0; 169 | size=0; 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.2) 2 | 3 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 4 | message(STATUS "Setting build type to Release as none was specified.") 5 | set(CMAKE_BUILD_TYPE "Release" CACHE 6 | STRING "Choose the type of build." FORCE) 7 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 8 | "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 9 | endif() 10 | 11 | set(CMAKE_CXX_FLAGS "-std=c++11" CACHE STRING "Flags used by the CXX compiler during all build types." FORCE) 12 | 13 | macro(set_option var default type docstring) 14 | if(NOT DEFINED ${var}) 15 | set(${var} ${default}) 16 | endif() 17 | set(${var} ${${var}} CACHE ${type} ${docstring} FORCE) 18 | endmacro() 19 | 20 | set_option(REDRELAY_EXAMPLE TRUE BOOL "Build example RedRelay Client application") 21 | set_option(SFML_FORCE_STATIC FALSE BOOL "Force building SFML from deps instead of using a pre-installed lib") 22 | 23 | project(RedRelayClient VERSION 9) 24 | 25 | if (NOT SFML_FORCE_STATIC) 26 | find_package(SFML 2.5 COMPONENTS network) 27 | endif() 28 | if (NOT SFML_FOUND AND NOT SFML_FORCE_STATIC) 29 | message(STATUS "SFML not found. Proceeding to build a minimal version from ../deps") 30 | endif() 31 | if (SFML_FORCE_STATIC) 32 | message(STATUS "Forced to build a minimal version of SFML from ../deps") 33 | endif() 34 | if (NOT SFML_FOUND OR SFML_FORCE_STATIC) 35 | add_definitions(-DSFML_STATIC) 36 | include_directories(../deps) 37 | list (APPEND REDRELAY_SOURCES ../deps/SFML/Err.cpp ../deps/SFML/Time.cpp ../deps/SFML/Sleep.cpp ../deps/SFML/Clock.cpp ../deps/SFML/Lock.cpp ../deps/SFML/Mutex.cpp 38 | ../deps/SFML/IpAddress.cpp ../deps/SFML/Socket.cpp ../deps/SFML/SocketSelector.cpp ../deps/SFML/TcpListener.cpp ../deps/SFML/TcpSocket.cpp ../deps/SFML/UdpSocket.cpp) 39 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 40 | list (APPEND REDRELAY_SOURCES ../deps/SFML/Win32ClockImpl.cpp ../deps/SFML/Win32MutexImpl.cpp ../deps/SFML/Win32SleepImpl.cpp ../deps/SFML/Win32SocketImpl.cpp) 41 | else() 42 | list (APPEND REDRELAY_SOURCES ../deps/SFML/UnixClockImpl.cpp ../deps/SFML/UnixMutexImpl.cpp ../deps/SFML/UnixSleepImpl.cpp ../deps/SFML/UnixSocketImpl.cpp) 43 | endif() 44 | endif() 45 | 46 | add_library(redrelay-client STATIC ${REDRELAY_SOURCES} RedRelayClient.cpp Channel.cpp Event.cpp Binary.cpp PacketReader.cpp) 47 | 48 | if (REDRELAY_EXAMPLE) 49 | message(STATUS "Example RedRelay application will be built") 50 | add_executable(RedRelayExample Main.cpp) 51 | 52 | if (SFML_FOUND AND NOT SFML_FORCE_STATIC) 53 | list (APPEND REDRELAY_LIBS sfml-network sfml-system) 54 | endif() 55 | 56 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 57 | list (APPEND REDRELAY_LIBS winmm ws2_32) 58 | if(${CMAKE_BUILD_TYPE} STREQUAL "Release") 59 | set (LINKERFLAGS "${LINKERFLAGS} -static") 60 | endif() 61 | endif() 62 | 63 | if(${CMAKE_BUILD_TYPE} STREQUAL "Release") 64 | set (LINKERFLAGS "${LINKERFLAGS} -s") 65 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 66 | set (LINKERFLAGS "${LINKERFLAGS} -flto") 67 | endif() 68 | endif() 69 | 70 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${LINKERFLAGS} CACHE STRING "Flags used by the linker during RELEASE builds." FORCE) 71 | 72 | target_link_libraries(RedRelayExample PUBLIC redrelay-client ${REDRELAY_LIBS}) 73 | endif() 74 | -------------------------------------------------------------------------------- /client/Channel.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // RedRelay - a Lacewing Relay protocol reimplementation 4 | // Copyright (c) 2019 LekKit (LekKit#4400 in Discord) 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source distribution. 21 | // 22 | //////////////////////////////////////////////////////////// 23 | 24 | #include "RedRelayClient.hpp" 25 | 26 | namespace rc{ 27 | 28 | Peer::Peer(uint16_t PeerID, const std::string& PeerName){ 29 | ID=PeerID; 30 | Name=PeerName; 31 | } 32 | 33 | uint16_t Peer::GetID() const { 34 | return ID; 35 | } 36 | 37 | std::string Peer::GetName() const { 38 | return Name; 39 | } 40 | 41 | Channel::Channel(uint16_t ChannelID, const std::string& ChannelName, uint8_t ChannelFlags){ 42 | ID=ChannelID; 43 | Name=ChannelName; 44 | Flags=ChannelFlags; 45 | } 46 | 47 | uint16_t Channel::GetID() const { 48 | return ID; 49 | } 50 | 51 | std::string Channel::GetName() const { 52 | return Name; 53 | } 54 | 55 | std::size_t Channel::GetPeerCount() const { 56 | return Peers.size(); 57 | } 58 | 59 | const std::vector& Channel::GetPeerList() const { 60 | return Peers; 61 | } 62 | 63 | const Peer& Channel::GetPeer(uint16_t ID) const { 64 | for (const Peer&i : Peers) if (i.ID==ID) return i; 65 | return defpeer; 66 | } 67 | 68 | const Peer& Channel::GetPeer(const std::string& Name) const { 69 | for (const Peer&i : Peers) if (i.Name==Name) return i; 70 | return defpeer; 71 | } 72 | 73 | uint16_t Channel::GetMasterID() const { 74 | return Master; 75 | } 76 | 77 | uint8_t Channel::GetFlags() const { 78 | return Flags; 79 | } 80 | 81 | bool Channel::IsHidden() const { 82 | return (Flags&1)!=0; 83 | } 84 | 85 | bool Channel::IsAutoClosed() const { 86 | return (Flags&2)!=0; 87 | } 88 | 89 | const Peer Channel::defpeer(0, ""); 90 | 91 | } 92 | -------------------------------------------------------------------------------- /client/Event.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // RedRelay - a Lacewing Relay protocol reimplementation 4 | // Copyright (c) 2019 LekKit (LekKit#4400 in Discord) 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source distribution. 21 | // 22 | //////////////////////////////////////////////////////////// 23 | 24 | #include "RedRelayClient.hpp" 25 | 26 | namespace rc{ 27 | 28 | Event::Event(uint8_t EventType, const std::string& Message, uint16_t Short1, uint16_t Short2, uint16_t Short3){ 29 | Type = EventType; 30 | m_string = Message; 31 | m_short1 = Short1; 32 | m_short2 = Short2; 33 | m_short3 = Short3; 34 | } 35 | 36 | Event::Event(){ 37 | Type = Error; 38 | } 39 | 40 | std::string Event::ErrorMessage() const { 41 | if (Type==Error) return m_string; 42 | return ""; 43 | } 44 | 45 | std::string Event::DenyMessage() const { 46 | if (Type==ConnectDenied || Type==NameDenied || Type==ChannelDenied || Type==ChannelLeaveDenied) return m_string; 47 | return ""; 48 | } 49 | 50 | std::string Event::WelcomeMessage() const { 51 | if (Type==Connected) return m_string; 52 | return ""; 53 | } 54 | 55 | std::string Event::DisconnectAddress() const { 56 | if (Type==Disconnected) return m_string; 57 | return ""; 58 | } 59 | 60 | uint16_t Event::ChannelsCount() const { 61 | if (Type==ListReceived) return m_short1; 62 | return 0; 63 | } 64 | 65 | std::string Event::ChannelName() const { 66 | if (Type==ChannelJoin || Type==ChannelLeave || Type==ListEntry) return m_string; 67 | return ""; 68 | } 69 | 70 | uint16_t Event::ChannelID() const { 71 | return m_short2; 72 | } 73 | 74 | uint16_t Event::PeersCount() const { 75 | if (Type==ListEntry) return m_short3; 76 | return 0; 77 | } 78 | 79 | std::string Event::PeerName() const { 80 | if (Type==PeerJoined || Type==PeerLeft || Type==PeerChangedName) return m_string; 81 | return ""; 82 | } 83 | 84 | uint16_t Event::PeerID() const { 85 | return m_short1; 86 | } 87 | 88 | bool Event::PeerWasMaster() const { 89 | if (Type != PeerLeft) return false; 90 | return m_short3 == 1; 91 | } 92 | 93 | const char* Event::Address() const { 94 | return m_string.c_str(); 95 | } 96 | 97 | uint32_t Event::Size() const { 98 | return m_string.length(); 99 | } 100 | 101 | uint8_t Event::Subchannel() const { 102 | if (Type>=ChannelBlast) return m_short3&255; 103 | return 0; 104 | } 105 | 106 | uint8_t Event::Variant() const { 107 | if (Type>=ChannelBlast) return (m_short3>>8)&255; 108 | return 0; 109 | } 110 | 111 | uint8_t Event::UByte(uint32_t Index) const { 112 | if (m_string.length() 4 | #include 5 | #include "RedRelayClient.hpp" 6 | 7 | int main(int argc, char** argv){ 8 | rc::RedRelayClient Client; 9 | std::cout<1 ? argv[1] : "lekkit.hopto.org", argc>2 ? atoi(argv[2]) : 6121); 11 | while (true){ 12 | Client.Update(); 13 | for (const rc::Event&i : Client.Events) 14 | switch (i.Type){ 15 | case rc::Event::Error: 16 | std::cout<1 && (unsigned char)buffer[packetbegin+1]<254) return (unsigned char)buffer[packetbegin+1]; 82 | if (received>3 && (unsigned char)buffer[packetbegin+1]==254) return (unsigned char)buffer[packetbegin+2]|(unsigned char)buffer[packetbegin+3]<<8; 83 | if (received>5) return (unsigned char)buffer[packetbegin+2]|(unsigned char)buffer[packetbegin+3]<<8|(unsigned char)buffer[packetbegin+4]<<16|(unsigned char)buffer[packetbegin+5]<<24; 84 | return 65535; 85 | } 86 | 87 | uint8_t PacketReader::GetPacketType() const { 88 | return buffer[packetbegin]; 89 | } 90 | 91 | void PacketReader::NextPacket(){ 92 | received-=PacketSize()+SizeOffset()+1; 93 | packetbegin+=PacketSize()+SizeOffset()+1; 94 | if (packetbegin>0 && !PacketReady()){ 95 | memmove(buffer, &buffer[packetbegin], received); 96 | packetbegin=0; 97 | } 98 | } 99 | 100 | void PacketReader::Clear(){ 101 | received=0; 102 | packetbegin=0; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /client/Platform.hpp: -------------------------------------------------------------------------------- 1 | //Platform identification tool 2 | 3 | #ifndef PLATFORM_IDENTIFIER 4 | #define PLATFORM_IDENTIFIER 5 | 6 | #if defined(__amd64__) || defined(__x86_64__) || defined(__amd64) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) 7 | #define ARCHITECTURE "x86_64" 8 | #elif defined(__i386__) || defined(_M_X86) || defined(_M_IX86) 9 | #define ARCHITECTURE "x86" 10 | #elif defined(__ARM_ARCH_7__) 11 | #define ARCHITECTURE "ARMv7" 12 | #elif defined(__arm__) || defined(_M_ARM) 13 | #define ARCHITECTURE "ARMv6" 14 | #endif 15 | 16 | #if defined(__linux__) 17 | #define OPERATING_SYSTEM "Linux" 18 | #elif defined(_WIN32) 19 | #define OPERATING_SYSTEM "Windows" 20 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 21 | #define OPERATING_SYSTEM "BSD" 22 | #elif defined(__APPLE__) 23 | #define OPERATING_SYSTEM "Mac OS" 24 | #endif 25 | 26 | #ifndef ARCHITECTURE 27 | #define ARCHITECTURE "Unknown" 28 | #endif 29 | 30 | #ifndef OPERATING_SYSTEM 31 | #define OPERATING_SYSTEM "Unknown" 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /deps/README.md: -------------------------------------------------------------------------------- 1 | Warning: those are not the official SFML sources, they were modified only for compiling RedRelay if you don't have SFML 2 | Obtain SFML here: https://www.sfml-dev.org/ 3 | wepoll lib: https://github.com/piscisaureus/wepoll -------------------------------------------------------------------------------- /deps/SFML/Clock.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | 30 | #if defined(SFML_SYSTEM_WINDOWS) 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | 37 | namespace sf 38 | { 39 | //////////////////////////////////////////////////////////// 40 | Clock::Clock() : 41 | m_startTime(priv::ClockImpl::getCurrentTime()) 42 | { 43 | } 44 | 45 | 46 | //////////////////////////////////////////////////////////// 47 | Time Clock::getElapsedTime() const 48 | { 49 | return priv::ClockImpl::getCurrentTime() - m_startTime; 50 | } 51 | 52 | 53 | //////////////////////////////////////////////////////////// 54 | Time Clock::restart() 55 | { 56 | Time now = priv::ClockImpl::getCurrentTime(); 57 | Time elapsed = now - m_startTime; 58 | m_startTime = now; 59 | 60 | return elapsed; 61 | } 62 | 63 | } // namespace sf 64 | -------------------------------------------------------------------------------- /deps/SFML/Config.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_CONFIG_HPP 26 | #define SFML_CONFIG_HPP 27 | 28 | 29 | //////////////////////////////////////////////////////////// 30 | // Define the SFML version 31 | //////////////////////////////////////////////////////////// 32 | #define SFML_VERSION_MAJOR 2 33 | #define SFML_VERSION_MINOR 5 34 | #define SFML_VERSION_PATCH 0 35 | 36 | 37 | //////////////////////////////////////////////////////////// 38 | // Identify the operating system 39 | // see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system 40 | //////////////////////////////////////////////////////////// 41 | #if defined(_WIN32) 42 | 43 | // Windows 44 | #define SFML_SYSTEM_WINDOWS 45 | #ifndef NOMINMAX 46 | #define NOMINMAX 47 | #endif 48 | 49 | #elif defined(__APPLE__) && defined(__MACH__) 50 | 51 | // Apple platform, see which one it is 52 | #include "TargetConditionals.h" 53 | 54 | #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 55 | 56 | // iOS 57 | #define SFML_SYSTEM_IOS 58 | 59 | #elif TARGET_OS_MAC 60 | 61 | // MacOS 62 | #define SFML_SYSTEM_MACOS 63 | 64 | #else 65 | 66 | // Unsupported Apple system 67 | #error This Apple operating system is not supported by SFML library 68 | 69 | #endif 70 | 71 | #elif defined(__unix__) 72 | 73 | // UNIX system, see which one it is 74 | #if defined(__ANDROID__) 75 | 76 | // Android 77 | #define SFML_SYSTEM_ANDROID 78 | 79 | #elif defined(__linux__) 80 | 81 | // Linux 82 | #define SFML_SYSTEM_LINUX 83 | 84 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 85 | 86 | // FreeBSD 87 | #define SFML_SYSTEM_FREEBSD 88 | 89 | #elif defined(__OpenBSD__) 90 | 91 | // OpenBSD 92 | #define SFML_SYSTEM_OPENBSD 93 | 94 | #else 95 | 96 | // Unsupported UNIX system 97 | #error This UNIX operating system is not supported by SFML library 98 | 99 | #endif 100 | 101 | #else 102 | 103 | // Unsupported system 104 | #error This operating system is not supported by SFML library 105 | 106 | #endif 107 | 108 | 109 | //////////////////////////////////////////////////////////// 110 | // Define a portable debug macro 111 | //////////////////////////////////////////////////////////// 112 | #if !defined(NDEBUG) 113 | 114 | #define SFML_DEBUG 115 | 116 | #endif 117 | 118 | 119 | //////////////////////////////////////////////////////////// 120 | // Define helpers to create portable import / export macros for each module 121 | //////////////////////////////////////////////////////////// 122 | #if !defined(SFML_STATIC) 123 | 124 | #if defined(SFML_SYSTEM_WINDOWS) 125 | 126 | // Windows compilers need specific (and different) keywords for export and import 127 | #define SFML_API_EXPORT __declspec(dllexport) 128 | #define SFML_API_IMPORT __declspec(dllimport) 129 | 130 | // For Visual C++ compilers, we also need to turn off this annoying C4251 warning 131 | #ifdef _MSC_VER 132 | 133 | #pragma warning(disable: 4251) 134 | 135 | #endif 136 | 137 | #else // Linux, FreeBSD, Mac OS X 138 | 139 | #if __GNUC__ >= 4 140 | 141 | // GCC 4 has special keywords for showing/hidding symbols, 142 | // the same keyword is used for both importing and exporting 143 | #define SFML_API_EXPORT __attribute__ ((__visibility__ ("default"))) 144 | #define SFML_API_IMPORT __attribute__ ((__visibility__ ("default"))) 145 | 146 | #else 147 | 148 | // GCC < 4 has no mechanism to explicitely hide symbols, everything's exported 149 | #define SFML_API_EXPORT 150 | #define SFML_API_IMPORT 151 | 152 | #endif 153 | 154 | #endif 155 | 156 | #else 157 | 158 | // Static build doesn't need import/export macros 159 | #define SFML_API_EXPORT 160 | #define SFML_API_IMPORT 161 | 162 | #endif 163 | 164 | 165 | //////////////////////////////////////////////////////////// 166 | // Cross-platform warning for deprecated functions and classes 167 | // 168 | // Usage: 169 | // class SFML_DEPRECATED MyClass 170 | // { 171 | // SFML_DEPRECATED void memberFunc(); 172 | // }; 173 | // 174 | // SFML_DEPRECATED void globalFunc(); 175 | //////////////////////////////////////////////////////////// 176 | #if defined(SFML_NO_DEPRECATED_WARNINGS) 177 | 178 | // User explicitly requests to disable deprecation warnings 179 | #define SFML_DEPRECATED 180 | 181 | #elif defined(_MSC_VER) 182 | 183 | // Microsoft C++ compiler 184 | // Note: On newer MSVC versions, using deprecated functions causes a compiler error. In order to 185 | // trigger a warning instead of an error, the compiler flag /sdl- (instead of /sdl) must be specified. 186 | #define SFML_DEPRECATED __declspec(deprecated) 187 | 188 | #elif defined(__GNUC__) 189 | 190 | // g++ and Clang 191 | #define SFML_DEPRECATED __attribute__ ((deprecated)) 192 | 193 | #else 194 | 195 | // Other compilers are not supported, leave class or function as-is. 196 | // With a bit of luck, the #pragma directive works, otherwise users get a warning (no error!) for unrecognized #pragma. 197 | #pragma message("SFML_DEPRECATED is not supported for your compiler, please contact the SFML team") 198 | #define SFML_DEPRECATED 199 | 200 | #endif 201 | 202 | 203 | //////////////////////////////////////////////////////////// 204 | // Define portable fixed-size types 205 | //////////////////////////////////////////////////////////// 206 | namespace sf 207 | { 208 | // All "common" platforms use the same size for char, short and int 209 | // (basically there are 3 types for 3 sizes, so no other match is possible), 210 | // we can use them without doing any kind of check 211 | 212 | // 8 bits integer types 213 | typedef signed char Int8; 214 | typedef unsigned char Uint8; 215 | 216 | // 16 bits integer types 217 | typedef signed short Int16; 218 | typedef unsigned short Uint16; 219 | 220 | // 32 bits integer types 221 | typedef signed int Int32; 222 | typedef unsigned int Uint32; 223 | 224 | // 64 bits integer types 225 | #if defined(_MSC_VER) 226 | typedef signed __int64 Int64; 227 | typedef unsigned __int64 Uint64; 228 | #else 229 | typedef signed long long Int64; 230 | typedef unsigned long long Uint64; 231 | #endif 232 | 233 | } // namespace sf 234 | 235 | 236 | #endif // SFML_CONFIG_HPP 237 | -------------------------------------------------------------------------------- /deps/SFML/Err.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace 34 | { 35 | // This class will be used as the default streambuf of sf::Err, 36 | // it outputs to stderr by default (to keep the default behavior) 37 | class DefaultErrStreamBuf : public std::streambuf 38 | { 39 | public: 40 | 41 | DefaultErrStreamBuf() 42 | { 43 | // Allocate the write buffer 44 | static const int size = 64; 45 | char* buffer = new char[size]; 46 | setp(buffer, buffer + size); 47 | } 48 | 49 | ~DefaultErrStreamBuf() 50 | { 51 | // Synchronize 52 | sync(); 53 | 54 | // Delete the write buffer 55 | delete[] pbase(); 56 | } 57 | 58 | private: 59 | 60 | virtual int overflow(int character) 61 | { 62 | if ((character != EOF) && (pptr() != epptr())) 63 | { 64 | // Valid character 65 | return sputc(static_cast(character)); 66 | } 67 | else if (character != EOF) 68 | { 69 | // Not enough space in the buffer: synchronize output and try again 70 | sync(); 71 | return overflow(character); 72 | } 73 | else 74 | { 75 | // Invalid character: synchronize output 76 | return sync(); 77 | } 78 | } 79 | 80 | virtual int sync() 81 | { 82 | // Check if there is something into the write buffer 83 | if (pbase() != pptr()) 84 | { 85 | // Print the contents of the write buffer into the standard error output 86 | std::size_t size = static_cast(pptr() - pbase()); 87 | fwrite(pbase(), 1, size, stderr); 88 | 89 | // Reset the pointer position to the beginning of the write buffer 90 | setp(pbase(), epptr()); 91 | } 92 | 93 | return 0; 94 | } 95 | }; 96 | } 97 | 98 | namespace sf 99 | { 100 | //////////////////////////////////////////////////////////// 101 | std::ostream& err() 102 | { 103 | static DefaultErrStreamBuf buffer; 104 | static std::ostream stream(&buffer); 105 | 106 | return stream; 107 | } 108 | 109 | 110 | } // namespace sf 111 | -------------------------------------------------------------------------------- /deps/SFML/IpAddress.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | namespace sf 35 | { 36 | //////////////////////////////////////////////////////////// 37 | const IpAddress IpAddress::None; 38 | const IpAddress IpAddress::Any(0, 0, 0, 0); 39 | const IpAddress IpAddress::LocalHost(127, 0, 0, 1); 40 | const IpAddress IpAddress::Broadcast(255, 255, 255, 255); 41 | 42 | 43 | //////////////////////////////////////////////////////////// 44 | IpAddress::IpAddress() : 45 | m_address(0), 46 | m_valid (false) 47 | { 48 | } 49 | 50 | 51 | //////////////////////////////////////////////////////////// 52 | IpAddress::IpAddress(const std::string& address) : 53 | m_address(0), 54 | m_valid (false) 55 | { 56 | resolve(address); 57 | } 58 | 59 | 60 | //////////////////////////////////////////////////////////// 61 | IpAddress::IpAddress(const char* address) : 62 | m_address(0), 63 | m_valid (false) 64 | { 65 | resolve(address); 66 | } 67 | 68 | 69 | //////////////////////////////////////////////////////////// 70 | IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) : 71 | m_address(htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3)), 72 | m_valid (true) 73 | { 74 | } 75 | 76 | 77 | //////////////////////////////////////////////////////////// 78 | IpAddress::IpAddress(Uint32 address) : 79 | m_address(htonl(address)), 80 | m_valid (true) 81 | { 82 | } 83 | 84 | 85 | //////////////////////////////////////////////////////////// 86 | std::string IpAddress::toString() const 87 | { 88 | in_addr address; 89 | address.s_addr = m_address; 90 | 91 | return inet_ntoa(address); 92 | } 93 | 94 | 95 | //////////////////////////////////////////////////////////// 96 | Uint32 IpAddress::toInteger() const 97 | { 98 | return ntohl(m_address); 99 | } 100 | 101 | 102 | //////////////////////////////////////////////////////////// 103 | IpAddress IpAddress::getLocalAddress() 104 | { 105 | // The method here is to connect a UDP socket to anyone (here to localhost), 106 | // and get the local socket address with the getsockname function. 107 | // UDP connection will not send anything to the network, so this function won't cause any overhead. 108 | 109 | IpAddress localAddress; 110 | 111 | // Create the socket 112 | SocketHandle sock = socket(PF_INET, SOCK_DGRAM, 0); 113 | if (sock == priv::SocketImpl::invalidSocket()) 114 | return localAddress; 115 | 116 | // Connect the socket to localhost on any port 117 | sockaddr_in address = priv::SocketImpl::createAddress(ntohl(INADDR_LOOPBACK), 9); 118 | if (connect(sock, reinterpret_cast(&address), sizeof(address)) == -1) 119 | { 120 | priv::SocketImpl::close(sock); 121 | return localAddress; 122 | } 123 | 124 | // Get the local address of the socket connection 125 | priv::SocketImpl::AddrLength size = sizeof(address); 126 | if (getsockname(sock, reinterpret_cast(&address), &size) == -1) 127 | { 128 | priv::SocketImpl::close(sock); 129 | return localAddress; 130 | } 131 | 132 | // Close the socket 133 | priv::SocketImpl::close(sock); 134 | 135 | // Finally build the IP address 136 | localAddress = IpAddress(ntohl(address.sin_addr.s_addr)); 137 | 138 | return localAddress; 139 | } 140 | 141 | 142 | //////////////////////////////////////////////////////////// 143 | void IpAddress::resolve(const std::string& address) 144 | { 145 | m_address = 0; 146 | m_valid = false; 147 | 148 | if (address == "255.255.255.255") 149 | { 150 | // The broadcast address needs to be handled explicitly, 151 | // because it is also the value returned by inet_addr on error 152 | m_address = INADDR_BROADCAST; 153 | m_valid = true; 154 | } 155 | else if (address == "0.0.0.0") 156 | { 157 | m_address = INADDR_ANY; 158 | m_valid = true; 159 | } 160 | else 161 | { 162 | // Try to convert the address as a byte representation ("xxx.xxx.xxx.xxx") 163 | Uint32 ip = inet_addr(address.c_str()); 164 | if (ip != INADDR_NONE) 165 | { 166 | m_address = ip; 167 | m_valid = true; 168 | } 169 | else 170 | { 171 | // Not a valid address, try to convert it as a host name 172 | addrinfo hints; 173 | std::memset(&hints, 0, sizeof(hints)); 174 | hints.ai_family = AF_INET; 175 | addrinfo* result = NULL; 176 | if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) 177 | { 178 | if (result) 179 | { 180 | ip = reinterpret_cast(result->ai_addr)->sin_addr.s_addr; 181 | freeaddrinfo(result); 182 | m_address = ip; 183 | m_valid = true; 184 | } 185 | } 186 | } 187 | } 188 | } 189 | 190 | 191 | //////////////////////////////////////////////////////////// 192 | bool operator ==(const IpAddress& left, const IpAddress& right) 193 | { 194 | return !(left < right) && !(right < left); 195 | } 196 | 197 | 198 | //////////////////////////////////////////////////////////// 199 | bool operator !=(const IpAddress& left, const IpAddress& right) 200 | { 201 | return !(left == right); 202 | } 203 | 204 | 205 | //////////////////////////////////////////////////////////// 206 | bool operator <(const IpAddress& left, const IpAddress& right) 207 | { 208 | return std::make_pair(left.m_valid, left.m_address) < std::make_pair(right.m_valid, right.m_address); 209 | } 210 | 211 | 212 | //////////////////////////////////////////////////////////// 213 | bool operator >(const IpAddress& left, const IpAddress& right) 214 | { 215 | return right < left; 216 | } 217 | 218 | 219 | //////////////////////////////////////////////////////////// 220 | bool operator <=(const IpAddress& left, const IpAddress& right) 221 | { 222 | return !(right < left); 223 | } 224 | 225 | 226 | //////////////////////////////////////////////////////////// 227 | bool operator >=(const IpAddress& left, const IpAddress& right) 228 | { 229 | return !(left < right); 230 | } 231 | 232 | 233 | //////////////////////////////////////////////////////////// 234 | std::istream& operator >>(std::istream& stream, IpAddress& address) 235 | { 236 | std::string str; 237 | stream >> str; 238 | address = IpAddress(str); 239 | 240 | return stream; 241 | } 242 | 243 | 244 | //////////////////////////////////////////////////////////// 245 | std::ostream& operator <<(std::ostream& stream, const IpAddress& address) 246 | { 247 | return stream << address.toString(); 248 | } 249 | 250 | } // namespace sf 251 | -------------------------------------------------------------------------------- /deps/SFML/Lock.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | 31 | 32 | namespace sf 33 | { 34 | //////////////////////////////////////////////////////////// 35 | Lock::Lock(Mutex& mutex) : 36 | m_mutex(mutex) 37 | { 38 | m_mutex.lock(); 39 | } 40 | 41 | 42 | //////////////////////////////////////////////////////////// 43 | Lock::~Lock() 44 | { 45 | m_mutex.unlock(); 46 | } 47 | 48 | } // namespace sf 49 | -------------------------------------------------------------------------------- /deps/SFML/Mutex.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | 30 | #if defined(SFML_SYSTEM_WINDOWS) 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | 37 | namespace sf 38 | { 39 | //////////////////////////////////////////////////////////// 40 | Mutex::Mutex() 41 | { 42 | m_mutexImpl = new priv::MutexImpl; 43 | } 44 | 45 | 46 | //////////////////////////////////////////////////////////// 47 | Mutex::~Mutex() 48 | { 49 | delete m_mutexImpl; 50 | } 51 | 52 | 53 | //////////////////////////////////////////////////////////// 54 | void Mutex::lock() 55 | { 56 | m_mutexImpl->lock(); 57 | } 58 | 59 | 60 | //////////////////////////////////////////////////////////// 61 | void Mutex::unlock() 62 | { 63 | m_mutexImpl->unlock(); 64 | } 65 | 66 | } // namespace sf 67 | -------------------------------------------------------------------------------- /deps/SFML/Network.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_NETWORK_HPP 26 | #define SFML_NETWORK_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | #endif // SFML_NETWORK_HPP 43 | 44 | //////////////////////////////////////////////////////////// 45 | /// \defgroup network Network module 46 | /// 47 | /// Socket-based communication, utilities and higher-level 48 | /// network protocols (HTTP, FTP). 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | -------------------------------------------------------------------------------- /deps/SFML/Network/Export.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_NETWORK_EXPORT_HPP 26 | #define SFML_NETWORK_EXPORT_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | 33 | 34 | //////////////////////////////////////////////////////////// 35 | // Define portable import / export macros 36 | //////////////////////////////////////////////////////////// 37 | #if defined(SFML_NETWORK_EXPORTS) 38 | 39 | #define SFML_NETWORK_API SFML_API_EXPORT 40 | 41 | #else 42 | 43 | #define SFML_NETWORK_API SFML_API_IMPORT 44 | 45 | #endif 46 | 47 | 48 | #endif // SFML_NETWORK_EXPORT_HPP 49 | -------------------------------------------------------------------------------- /deps/SFML/Network/Socket.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SOCKET_HPP 26 | #define SFML_SOCKET_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | class EpollSelector; 37 | 38 | namespace sf 39 | { 40 | class SocketSelector; 41 | 42 | //////////////////////////////////////////////////////////// 43 | /// \brief Base class for all the socket types 44 | /// 45 | //////////////////////////////////////////////////////////// 46 | class SFML_NETWORK_API Socket : NonCopyable 47 | { 48 | public: 49 | 50 | //////////////////////////////////////////////////////////// 51 | /// \brief Status codes that may be returned by socket functions 52 | /// 53 | //////////////////////////////////////////////////////////// 54 | enum Status 55 | { 56 | Done, ///< The socket has sent / received the data 57 | NotReady, ///< The socket is not ready to send / receive data yet 58 | Partial, ///< The socket sent a part of the data 59 | Disconnected, ///< The TCP socket has been disconnected 60 | Error ///< An unexpected error happened 61 | }; 62 | 63 | //////////////////////////////////////////////////////////// 64 | /// \brief Some special values used by sockets 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | enum 68 | { 69 | AnyPort = 0 ///< Special value that tells the system to pick any available port 70 | }; 71 | 72 | public: 73 | 74 | //////////////////////////////////////////////////////////// 75 | /// \brief Destructor 76 | /// 77 | //////////////////////////////////////////////////////////// 78 | virtual ~Socket(); 79 | 80 | //////////////////////////////////////////////////////////// 81 | /// \brief Set the blocking state of the socket 82 | /// 83 | /// In blocking mode, calls will not return until they have 84 | /// completed their task. For example, a call to Receive in 85 | /// blocking mode won't return until some data was actually 86 | /// received. 87 | /// In non-blocking mode, calls will always return immediately, 88 | /// using the return code to signal whether there was data 89 | /// available or not. 90 | /// By default, all sockets are blocking. 91 | /// 92 | /// \param blocking True to set the socket as blocking, false for non-blocking 93 | /// 94 | /// \see isBlocking 95 | /// 96 | //////////////////////////////////////////////////////////// 97 | void setBlocking(bool blocking); 98 | 99 | //////////////////////////////////////////////////////////// 100 | /// \brief Tell whether the socket is in blocking or non-blocking mode 101 | /// 102 | /// \return True if the socket is blocking, false otherwise 103 | /// 104 | /// \see setBlocking 105 | /// 106 | //////////////////////////////////////////////////////////// 107 | bool isBlocking() const; 108 | 109 | protected: 110 | 111 | //////////////////////////////////////////////////////////// 112 | /// \brief Types of protocols that the socket can use 113 | /// 114 | //////////////////////////////////////////////////////////// 115 | enum Type 116 | { 117 | Tcp, ///< TCP protocol 118 | Udp ///< UDP protocol 119 | }; 120 | 121 | //////////////////////////////////////////////////////////// 122 | /// \brief Default constructor 123 | /// 124 | /// This constructor can only be accessed by derived classes. 125 | /// 126 | /// \param type Type of the socket (TCP or UDP) 127 | /// 128 | //////////////////////////////////////////////////////////// 129 | Socket(Type type); 130 | 131 | //////////////////////////////////////////////////////////// 132 | /// \brief Return the internal handle of the socket 133 | /// 134 | /// The returned handle may be invalid if the socket 135 | /// was not created yet (or already destroyed). 136 | /// This function can only be accessed by derived classes. 137 | /// 138 | /// \return The internal (OS-specific) handle of the socket 139 | /// 140 | //////////////////////////////////////////////////////////// 141 | SocketHandle getHandle() const; 142 | 143 | //////////////////////////////////////////////////////////// 144 | /// \brief Create the internal representation of the socket 145 | /// 146 | /// This function can only be accessed by derived classes. 147 | /// 148 | //////////////////////////////////////////////////////////// 149 | void create(); 150 | 151 | //////////////////////////////////////////////////////////// 152 | /// \brief Create the internal representation of the socket 153 | /// from a socket handle 154 | /// 155 | /// This function can only be accessed by derived classes. 156 | /// 157 | /// \param handle OS-specific handle of the socket to wrap 158 | /// 159 | //////////////////////////////////////////////////////////// 160 | void create(SocketHandle handle); 161 | 162 | //////////////////////////////////////////////////////////// 163 | /// \brief Close the socket gracefully 164 | /// 165 | /// This function can only be accessed by derived classes. 166 | /// 167 | //////////////////////////////////////////////////////////// 168 | void close(); 169 | 170 | private: 171 | 172 | friend class SocketSelector; 173 | 174 | friend class ::EpollSelector; 175 | 176 | //////////////////////////////////////////////////////////// 177 | // Member data 178 | //////////////////////////////////////////////////////////// 179 | Type m_type; ///< Type of the socket (TCP or UDP) 180 | SocketHandle m_socket; ///< Socket descriptor 181 | bool m_isBlocking; ///< Current blocking mode of the socket 182 | }; 183 | 184 | } // namespace sf 185 | 186 | 187 | #endif // SFML_SOCKET_HPP 188 | 189 | 190 | //////////////////////////////////////////////////////////// 191 | /// \class sf::Socket 192 | /// \ingroup network 193 | /// 194 | /// This class mainly defines internal stuff to be used by 195 | /// derived classes. 196 | /// 197 | /// The only public features that it defines, and which 198 | /// is therefore common to all the socket classes, is the 199 | /// blocking state. All sockets can be set as blocking or 200 | /// non-blocking. 201 | /// 202 | /// In blocking mode, socket functions will hang until 203 | /// the operation completes, which means that the entire 204 | /// program (well, in fact the current thread if you use 205 | /// multiple ones) will be stuck waiting for your socket 206 | /// operation to complete. 207 | /// 208 | /// In non-blocking mode, all the socket functions will 209 | /// return immediately. If the socket is not ready to complete 210 | /// the requested operation, the function simply returns 211 | /// the proper status code (Socket::NotReady). 212 | /// 213 | /// The default mode, which is blocking, is the one that is 214 | /// generally used, in combination with threads or selectors. 215 | /// The non-blocking mode is rather used in real-time 216 | /// applications that run an endless loop that can poll 217 | /// the socket often enough, and cannot afford blocking 218 | /// this loop. 219 | /// 220 | /// \see sf::TcpListener, sf::TcpSocket, sf::UdpSocket 221 | /// 222 | //////////////////////////////////////////////////////////// 223 | -------------------------------------------------------------------------------- /deps/SFML/Network/SocketHandle.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SOCKETHANDLE_HPP 26 | #define SFML_SOCKETHANDLE_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | 33 | #if defined(SFML_SYSTEM_WINDOWS) 34 | #include 35 | #endif 36 | 37 | 38 | namespace sf 39 | { 40 | //////////////////////////////////////////////////////////// 41 | // Define the low-level socket handle type, specific to 42 | // each platform 43 | //////////////////////////////////////////////////////////// 44 | #if defined(SFML_SYSTEM_WINDOWS) 45 | 46 | typedef UINT_PTR SocketHandle; 47 | 48 | #else 49 | 50 | typedef int SocketHandle; 51 | 52 | #endif 53 | 54 | } // namespace sf 55 | 56 | 57 | #endif // SFML_SOCKETHANDLE_HPP 58 | -------------------------------------------------------------------------------- /deps/SFML/Network/SocketImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | 30 | 31 | #if defined(SFML_SYSTEM_WINDOWS) 32 | 33 | #include 34 | 35 | #else 36 | 37 | #include 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /deps/SFML/Network/TcpListener.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_TCPLISTENER_HPP 26 | #define SFML_TCPLISTENER_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | namespace sf 37 | { 38 | class TcpSocket; 39 | 40 | //////////////////////////////////////////////////////////// 41 | /// \brief Socket that listens to new TCP connections 42 | /// 43 | //////////////////////////////////////////////////////////// 44 | class SFML_NETWORK_API TcpListener : public Socket 45 | { 46 | public: 47 | 48 | //////////////////////////////////////////////////////////// 49 | /// \brief Default constructor 50 | /// 51 | //////////////////////////////////////////////////////////// 52 | TcpListener(); 53 | 54 | //////////////////////////////////////////////////////////// 55 | /// \brief Get the port to which the socket is bound locally 56 | /// 57 | /// If the socket is not listening to a port, this function 58 | /// returns 0. 59 | /// 60 | /// \return Port to which the socket is bound 61 | /// 62 | /// \see listen 63 | /// 64 | //////////////////////////////////////////////////////////// 65 | unsigned short getLocalPort() const; 66 | 67 | //////////////////////////////////////////////////////////// 68 | /// \brief Start listening for incoming connection attempts 69 | /// 70 | /// This function makes the socket start listening on the 71 | /// specified port, waiting for incoming connection attempts. 72 | /// 73 | /// If the socket is already listening on a port when this 74 | /// function is called, it will stop listening on the old 75 | /// port before starting to listen on the new port. 76 | /// 77 | /// \param port Port to listen on for incoming connection attempts 78 | /// \param address Address of the interface to listen on 79 | /// 80 | /// \return Status code 81 | /// 82 | /// \see accept, close 83 | /// 84 | //////////////////////////////////////////////////////////// 85 | Status listen(unsigned short port, const IpAddress& address = IpAddress::Any); 86 | 87 | //////////////////////////////////////////////////////////// 88 | /// \brief Stop listening and close the socket 89 | /// 90 | /// This function gracefully stops the listener. If the 91 | /// socket is not listening, this function has no effect. 92 | /// 93 | /// \see listen 94 | /// 95 | //////////////////////////////////////////////////////////// 96 | void close(); 97 | 98 | //////////////////////////////////////////////////////////// 99 | /// \brief Accept a new connection 100 | /// 101 | /// If the socket is in blocking mode, this function will 102 | /// not return until a connection is actually received. 103 | /// 104 | /// \param socket Socket that will hold the new connection 105 | /// 106 | /// \return Status code 107 | /// 108 | /// \see listen 109 | /// 110 | //////////////////////////////////////////////////////////// 111 | Status accept(TcpSocket& socket); 112 | }; 113 | 114 | 115 | } // namespace sf 116 | 117 | 118 | #endif // SFML_TCPLISTENER_HPP 119 | 120 | 121 | //////////////////////////////////////////////////////////// 122 | /// \class sf::TcpListener 123 | /// \ingroup network 124 | /// 125 | /// A listener socket is a special type of socket that listens to 126 | /// a given port and waits for connections on that port. 127 | /// This is all it can do. 128 | /// 129 | /// When a new connection is received, you must call accept and 130 | /// the listener returns a new instance of sf::TcpSocket that 131 | /// is properly initialized and can be used to communicate with 132 | /// the new client. 133 | /// 134 | /// Listener sockets are specific to the TCP protocol, 135 | /// UDP sockets are connectionless and can therefore communicate 136 | /// directly. As a consequence, a listener socket will always 137 | /// return the new connections as sf::TcpSocket instances. 138 | /// 139 | /// A listener is automatically closed on destruction, like all 140 | /// other types of socket. However if you want to stop listening 141 | /// before the socket is destroyed, you can call its close() 142 | /// function. 143 | /// 144 | /// Usage example: 145 | /// \code 146 | /// // Create a listener socket and make it wait for new 147 | /// // connections on port 55001 148 | /// sf::TcpListener listener; 149 | /// listener.listen(55001); 150 | /// 151 | /// // Endless loop that waits for new connections 152 | /// while (running) 153 | /// { 154 | /// sf::TcpSocket client; 155 | /// if (listener.accept(client) == sf::Socket::Done) 156 | /// { 157 | /// // A new client just connected! 158 | /// std::cout << "New connection received from " << client.getRemoteAddress() << std::endl; 159 | /// doSomethingWith(client); 160 | /// } 161 | /// } 162 | /// \endcode 163 | /// 164 | /// \see sf::TcpSocket, sf::Socket 165 | /// 166 | //////////////////////////////////////////////////////////// 167 | -------------------------------------------------------------------------------- /deps/SFML/Network/UnixSocketImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SOCKETIMPL_HPP 26 | #define SFML_SOCKETIMPL_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | 41 | namespace sf 42 | { 43 | namespace priv 44 | { 45 | //////////////////////////////////////////////////////////// 46 | /// \brief Helper class implementing all the non-portable 47 | /// socket stuff; this is the Unix version 48 | /// 49 | //////////////////////////////////////////////////////////// 50 | class SocketImpl 51 | { 52 | public: 53 | 54 | //////////////////////////////////////////////////////////// 55 | // Types 56 | //////////////////////////////////////////////////////////// 57 | typedef socklen_t AddrLength; 58 | 59 | //////////////////////////////////////////////////////////// 60 | /// \brief Create an internal sockaddr_in address 61 | /// 62 | /// \param address Target address 63 | /// \param port Target port 64 | /// 65 | /// \return sockaddr_in ready to be used by socket functions 66 | /// 67 | //////////////////////////////////////////////////////////// 68 | static sockaddr_in createAddress(Uint32 address, unsigned short port); 69 | 70 | //////////////////////////////////////////////////////////// 71 | /// \brief Return the value of the invalid socket 72 | /// 73 | /// \return Special value of the invalid socket 74 | /// 75 | //////////////////////////////////////////////////////////// 76 | static SocketHandle invalidSocket(); 77 | 78 | //////////////////////////////////////////////////////////// 79 | /// \brief Close and destroy a socket 80 | /// 81 | /// \param sock Handle of the socket to close 82 | /// 83 | //////////////////////////////////////////////////////////// 84 | static void close(SocketHandle sock); 85 | 86 | //////////////////////////////////////////////////////////// 87 | /// \brief Set a socket as blocking or non-blocking 88 | /// 89 | /// \param sock Handle of the socket 90 | /// \param block New blocking state of the socket 91 | /// 92 | //////////////////////////////////////////////////////////// 93 | static void setBlocking(SocketHandle sock, bool block); 94 | 95 | //////////////////////////////////////////////////////////// 96 | /// Get the last socket error status 97 | /// 98 | /// \return Status corresponding to the last socket error 99 | /// 100 | //////////////////////////////////////////////////////////// 101 | static Socket::Status getErrorStatus(); 102 | }; 103 | 104 | } // namespace priv 105 | 106 | } // namespace sf 107 | 108 | 109 | #endif // SFML_SOCKETIMPL_HPP 110 | -------------------------------------------------------------------------------- /deps/SFML/Network/Win32SocketImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SOCKETIMPL_HPP 26 | #define SFML_SOCKETIMPL_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #ifdef _WIN32_WINDOWS 32 | #undef _WIN32_WINDOWS 33 | #endif 34 | #ifdef _WIN32_WINNT 35 | #undef _WIN32_WINNT 36 | #endif 37 | #define _WIN32_WINDOWS 0x0501 38 | #define _WIN32_WINNT 0x0501 39 | #include 40 | #define FD_SETSIZE 1024 41 | #include 42 | #include 43 | 44 | 45 | namespace sf 46 | { 47 | namespace priv 48 | { 49 | //////////////////////////////////////////////////////////// 50 | /// \brief Helper class implementing all the non-portable 51 | /// socket stuff; this is the Windows version 52 | /// 53 | //////////////////////////////////////////////////////////// 54 | class SocketImpl 55 | { 56 | public: 57 | 58 | //////////////////////////////////////////////////////////// 59 | // Types 60 | //////////////////////////////////////////////////////////// 61 | typedef int AddrLength; 62 | 63 | //////////////////////////////////////////////////////////// 64 | /// \brief Create an internal sockaddr_in address 65 | /// 66 | /// \param address Target address 67 | /// \param port Target port 68 | /// 69 | /// \return sockaddr_in ready to be used by socket functions 70 | /// 71 | //////////////////////////////////////////////////////////// 72 | static sockaddr_in createAddress(Uint32 address, unsigned short port); 73 | 74 | //////////////////////////////////////////////////////////// 75 | /// \brief Return the value of the invalid socket 76 | /// 77 | /// \return Special value of the invalid socket 78 | /// 79 | //////////////////////////////////////////////////////////// 80 | static SocketHandle invalidSocket(); 81 | 82 | //////////////////////////////////////////////////////////// 83 | /// \brief Close and destroy a socket 84 | /// 85 | /// \param sock Handle of the socket to close 86 | /// 87 | //////////////////////////////////////////////////////////// 88 | static void close(SocketHandle sock); 89 | 90 | //////////////////////////////////////////////////////////// 91 | /// \brief Set a socket as blocking or non-blocking 92 | /// 93 | /// \param sock Handle of the socket 94 | /// \param block New blocking state of the socket 95 | /// 96 | //////////////////////////////////////////////////////////// 97 | static void setBlocking(SocketHandle sock, bool block); 98 | 99 | //////////////////////////////////////////////////////////// 100 | /// Get the last socket error status 101 | /// 102 | /// \return Status corresponding to the last socket error 103 | /// 104 | //////////////////////////////////////////////////////////// 105 | static Socket::Status getErrorStatus(); 106 | }; 107 | 108 | } // namespace priv 109 | 110 | } // namespace sf 111 | 112 | 113 | #endif // SFML_SOCKETIMPL_HPP 114 | -------------------------------------------------------------------------------- /deps/SFML/Sleep.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | 30 | #if defined(SFML_SYSTEM_WINDOWS) 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | 37 | namespace sf 38 | { 39 | //////////////////////////////////////////////////////////// 40 | void sleep(Time duration) 41 | { 42 | if (duration >= Time::Zero) 43 | priv::sleepImpl(duration); 44 | } 45 | 46 | } // namespace sf 47 | -------------------------------------------------------------------------------- /deps/SFML/Socket.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace sf 34 | { 35 | //////////////////////////////////////////////////////////// 36 | Socket::Socket(Type type) : 37 | m_type (type), 38 | m_socket (priv::SocketImpl::invalidSocket()), 39 | m_isBlocking(true) 40 | { 41 | 42 | } 43 | 44 | 45 | //////////////////////////////////////////////////////////// 46 | Socket::~Socket() 47 | { 48 | // Close the socket before it gets destructed 49 | close(); 50 | } 51 | 52 | 53 | //////////////////////////////////////////////////////////// 54 | void Socket::setBlocking(bool blocking) 55 | { 56 | // Apply if the socket is already created 57 | if (m_socket != priv::SocketImpl::invalidSocket()) 58 | priv::SocketImpl::setBlocking(m_socket, blocking); 59 | 60 | m_isBlocking = blocking; 61 | } 62 | 63 | 64 | //////////////////////////////////////////////////////////// 65 | bool Socket::isBlocking() const 66 | { 67 | return m_isBlocking; 68 | } 69 | 70 | 71 | //////////////////////////////////////////////////////////// 72 | SocketHandle Socket::getHandle() const 73 | { 74 | return m_socket; 75 | } 76 | 77 | 78 | //////////////////////////////////////////////////////////// 79 | void Socket::create() 80 | { 81 | // Don't create the socket if it already exists 82 | if (m_socket == priv::SocketImpl::invalidSocket()) 83 | { 84 | SocketHandle handle = socket(PF_INET, m_type == Tcp ? SOCK_STREAM : SOCK_DGRAM, 0); 85 | 86 | if (handle == priv::SocketImpl::invalidSocket()) 87 | { 88 | err() << "Failed to create socket" << std::endl; 89 | return; 90 | } 91 | 92 | create(handle); 93 | } 94 | } 95 | 96 | 97 | //////////////////////////////////////////////////////////// 98 | void Socket::create(SocketHandle handle) 99 | { 100 | // Don't create the socket if it already exists 101 | if (m_socket == priv::SocketImpl::invalidSocket()) 102 | { 103 | // Assign the new handle 104 | m_socket = handle; 105 | 106 | // Set the current blocking state 107 | setBlocking(m_isBlocking); 108 | 109 | if (m_type == Tcp) 110 | { 111 | // Disable the Nagle algorithm (i.e. removes buffering of TCP packets) 112 | int yes = 1; 113 | if (setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&yes), sizeof(yes)) == -1) 114 | { 115 | err() << "Failed to set socket option \"TCP_NODELAY\" ; " 116 | << "all your TCP packets will be buffered" << std::endl; 117 | } 118 | 119 | // On Mac OS X, disable the SIGPIPE signal on disconnection 120 | #ifdef SFML_SYSTEM_MACOS 121 | if (setsockopt(m_socket, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast(&yes), sizeof(yes)) == -1) 122 | { 123 | err() << "Failed to set socket option \"SO_NOSIGPIPE\"" << std::endl; 124 | } 125 | #endif 126 | } 127 | else 128 | { 129 | // Enable broadcast by default for UDP sockets 130 | int yes = 1; 131 | if (setsockopt(m_socket, SOL_SOCKET, SO_BROADCAST, reinterpret_cast(&yes), sizeof(yes)) == -1) 132 | { 133 | err() << "Failed to enable broadcast on UDP socket" << std::endl; 134 | } 135 | } 136 | } 137 | } 138 | 139 | 140 | //////////////////////////////////////////////////////////// 141 | void Socket::close() 142 | { 143 | // Close the socket 144 | if (m_socket != priv::SocketImpl::invalidSocket()) 145 | { 146 | priv::SocketImpl::close(m_socket); 147 | m_socket = priv::SocketImpl::invalidSocket(); 148 | } 149 | } 150 | 151 | } // namespace sf 152 | -------------------------------------------------------------------------------- /deps/SFML/SocketSelector.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef _MSC_VER 36 | #pragma warning(disable: 4127) // "conditional expression is constant" generated by the FD_SET macro 37 | #endif 38 | 39 | 40 | namespace sf 41 | { 42 | //////////////////////////////////////////////////////////// 43 | struct SocketSelector::SocketSelectorImpl 44 | { 45 | fd_set allSockets; ///< Set containing all the sockets handles 46 | fd_set socketsReady; ///< Set containing handles of the sockets that are ready 47 | int maxSocket; ///< Maximum socket handle 48 | int socketCount; ///< Number of socket handles 49 | }; 50 | 51 | 52 | //////////////////////////////////////////////////////////// 53 | SocketSelector::SocketSelector() : 54 | m_impl(new SocketSelectorImpl) 55 | { 56 | clear(); 57 | } 58 | 59 | 60 | //////////////////////////////////////////////////////////// 61 | SocketSelector::SocketSelector(const SocketSelector& copy) : 62 | m_impl(new SocketSelectorImpl(*copy.m_impl)) 63 | { 64 | 65 | } 66 | 67 | 68 | //////////////////////////////////////////////////////////// 69 | SocketSelector::~SocketSelector() 70 | { 71 | delete m_impl; 72 | } 73 | 74 | 75 | //////////////////////////////////////////////////////////// 76 | void SocketSelector::add(Socket& socket) 77 | { 78 | SocketHandle handle = socket.getHandle(); 79 | if (handle != priv::SocketImpl::invalidSocket()) 80 | { 81 | 82 | #if defined(SFML_SYSTEM_WINDOWS) 83 | 84 | if (m_impl->socketCount >= FD_SETSIZE) 85 | { 86 | err() << "The socket can't be added to the selector because the " 87 | << "selector is full. This is a limitation of your operating " 88 | << "system's FD_SETSIZE setting."; 89 | return; 90 | } 91 | 92 | if (FD_ISSET(handle, &m_impl->allSockets)) 93 | return; 94 | 95 | m_impl->socketCount++; 96 | 97 | #else 98 | 99 | if (handle >= FD_SETSIZE) 100 | { 101 | err() << "The socket can't be added to the selector because its " 102 | << "ID is too high. This is a limitation of your operating " 103 | << "system's FD_SETSIZE setting."; 104 | return; 105 | } 106 | 107 | // SocketHandle is an int in POSIX 108 | m_impl->maxSocket = std::max(m_impl->maxSocket, handle); 109 | 110 | #endif 111 | 112 | FD_SET(handle, &m_impl->allSockets); 113 | } 114 | } 115 | 116 | 117 | //////////////////////////////////////////////////////////// 118 | void SocketSelector::remove(Socket& socket) 119 | { 120 | SocketHandle handle = socket.getHandle(); 121 | if (handle != priv::SocketImpl::invalidSocket()) 122 | { 123 | 124 | #if defined(SFML_SYSTEM_WINDOWS) 125 | 126 | if (!FD_ISSET(handle, &m_impl->allSockets)) 127 | return; 128 | 129 | m_impl->socketCount--; 130 | 131 | #else 132 | 133 | if (handle >= FD_SETSIZE) 134 | return; 135 | 136 | #endif 137 | 138 | FD_CLR(handle, &m_impl->allSockets); 139 | FD_CLR(handle, &m_impl->socketsReady); 140 | } 141 | } 142 | 143 | 144 | //////////////////////////////////////////////////////////// 145 | void SocketSelector::clear() 146 | { 147 | FD_ZERO(&m_impl->allSockets); 148 | FD_ZERO(&m_impl->socketsReady); 149 | 150 | m_impl->maxSocket = 0; 151 | m_impl->socketCount = 0; 152 | } 153 | 154 | 155 | //////////////////////////////////////////////////////////// 156 | bool SocketSelector::wait(Time timeout) 157 | { 158 | // Setup the timeout 159 | timeval time; 160 | time.tv_sec = static_cast(timeout.asMicroseconds() / 1000000); 161 | time.tv_usec = static_cast(timeout.asMicroseconds() % 1000000); 162 | 163 | // Initialize the set that will contain the sockets that are ready 164 | m_impl->socketsReady = m_impl->allSockets; 165 | 166 | // Wait until one of the sockets is ready for reading, or timeout is reached 167 | // The first parameter is ignored on Windows 168 | int count = select(m_impl->maxSocket + 1, &m_impl->socketsReady, NULL, NULL, timeout != Time::Zero ? &time : NULL); 169 | 170 | return count > 0; 171 | } 172 | 173 | 174 | //////////////////////////////////////////////////////////// 175 | bool SocketSelector::isReady(Socket& socket) const 176 | { 177 | SocketHandle handle = socket.getHandle(); 178 | if (handle != priv::SocketImpl::invalidSocket()) 179 | { 180 | 181 | #if !defined(SFML_SYSTEM_WINDOWS) 182 | 183 | if (handle >= FD_SETSIZE) 184 | return false; 185 | 186 | #endif 187 | 188 | return FD_ISSET(handle, &m_impl->socketsReady) != 0; 189 | } 190 | 191 | return false; 192 | } 193 | 194 | 195 | //////////////////////////////////////////////////////////// 196 | SocketSelector& SocketSelector::operator =(const SocketSelector& right) 197 | { 198 | SocketSelector temp(right); 199 | 200 | std::swap(m_impl, temp.m_impl); 201 | 202 | return *this; 203 | } 204 | 205 | } // namespace sf 206 | -------------------------------------------------------------------------------- /deps/SFML/System.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SYSTEM_HPP 26 | #define SFML_SYSTEM_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #endif // SFML_SYSTEM_HPP 41 | 42 | //////////////////////////////////////////////////////////// 43 | /// \defgroup system System module 44 | /// 45 | /// Base module of SFML, defining various utilities. It provides 46 | /// vector classes, Unicode strings and conversion functions, 47 | /// threads and mutexes, timing classes. 48 | /// 49 | //////////////////////////////////////////////////////////// 50 | -------------------------------------------------------------------------------- /deps/SFML/System/Clock.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_CLOCK_HPP 26 | #define SFML_CLOCK_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | //////////////////////////////////////////////////////////// 38 | /// \brief Utility class that measures the elapsed time 39 | /// 40 | //////////////////////////////////////////////////////////// 41 | class SFML_SYSTEM_API Clock 42 | { 43 | public: 44 | 45 | //////////////////////////////////////////////////////////// 46 | /// \brief Default constructor 47 | /// 48 | /// The clock starts automatically after being constructed. 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | Clock(); 52 | 53 | //////////////////////////////////////////////////////////// 54 | /// \brief Get the elapsed time 55 | /// 56 | /// This function returns the time elapsed since the last call 57 | /// to restart() (or the construction of the instance if restart() 58 | /// has not been called). 59 | /// 60 | /// \return Time elapsed 61 | /// 62 | //////////////////////////////////////////////////////////// 63 | Time getElapsedTime() const; 64 | 65 | //////////////////////////////////////////////////////////// 66 | /// \brief Restart the clock 67 | /// 68 | /// This function puts the time counter back to zero. 69 | /// It also returns the time elapsed since the clock was started. 70 | /// 71 | /// \return Time elapsed 72 | /// 73 | //////////////////////////////////////////////////////////// 74 | Time restart(); 75 | 76 | private: 77 | 78 | //////////////////////////////////////////////////////////// 79 | // Member data 80 | //////////////////////////////////////////////////////////// 81 | Time m_startTime; ///< Time of last reset, in microseconds 82 | }; 83 | 84 | } // namespace sf 85 | 86 | 87 | #endif // SFML_CLOCK_HPP 88 | 89 | 90 | //////////////////////////////////////////////////////////// 91 | /// \class sf::Clock 92 | /// \ingroup system 93 | /// 94 | /// sf::Clock is a lightweight class for measuring time. 95 | /// 96 | /// Its provides the most precise time that the underlying 97 | /// OS can achieve (generally microseconds or nanoseconds). 98 | /// It also ensures monotonicity, which means that the returned 99 | /// time can never go backward, even if the system time is 100 | /// changed. 101 | /// 102 | /// Usage example: 103 | /// \code 104 | /// sf::Clock clock; 105 | /// ... 106 | /// Time time1 = clock.getElapsedTime(); 107 | /// ... 108 | /// Time time2 = clock.restart(); 109 | /// \endcode 110 | /// 111 | /// The sf::Time value returned by the clock can then be 112 | /// converted to a number of seconds, milliseconds or even 113 | /// microseconds. 114 | /// 115 | /// \see sf::Time 116 | /// 117 | //////////////////////////////////////////////////////////// 118 | -------------------------------------------------------------------------------- /deps/SFML/System/Err.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_ERR_HPP 26 | #define SFML_ERR_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | //////////////////////////////////////////////////////////// 38 | /// \brief Standard stream used by SFML to output warnings and errors 39 | /// 40 | //////////////////////////////////////////////////////////// 41 | SFML_SYSTEM_API std::ostream& err(); 42 | 43 | } // namespace sf 44 | 45 | 46 | #endif // SFML_ERR_HPP 47 | 48 | 49 | //////////////////////////////////////////////////////////// 50 | /// \fn sf::err 51 | /// \ingroup system 52 | /// 53 | /// By default, sf::err() outputs to the same location as std::cerr, 54 | /// (-> the stderr descriptor) which is the console if there's 55 | /// one available. 56 | /// 57 | /// It is a standard std::ostream instance, so it supports all the 58 | /// insertion operations defined by the STL 59 | /// (operator <<, manipulators, etc.). 60 | /// 61 | /// sf::err() can be redirected to write to another output, independently 62 | /// of std::cerr, by using the rdbuf() function provided by the 63 | /// std::ostream class. 64 | /// 65 | /// Example: 66 | /// \code 67 | /// // Redirect to a file 68 | /// std::ofstream file("sfml-log.txt"); 69 | /// std::streambuf* previous = sf::err().rdbuf(file.rdbuf()); 70 | /// 71 | /// // Redirect to nothing 72 | /// sf::err().rdbuf(NULL); 73 | /// 74 | /// // Restore the original output 75 | /// sf::err().rdbuf(previous); 76 | /// \endcode 77 | /// 78 | /// \return Reference to std::ostream representing the SFML error stream 79 | /// 80 | //////////////////////////////////////////////////////////// 81 | -------------------------------------------------------------------------------- /deps/SFML/System/Export.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SYSTEM_EXPORT_HPP 26 | #define SFML_SYSTEM_EXPORT_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | 33 | 34 | //////////////////////////////////////////////////////////// 35 | // Define portable import / export macros 36 | //////////////////////////////////////////////////////////// 37 | #if defined(SFML_SYSTEM_EXPORTS) 38 | 39 | #define SFML_SYSTEM_API SFML_API_EXPORT 40 | 41 | #else 42 | 43 | #define SFML_SYSTEM_API SFML_API_IMPORT 44 | 45 | #endif 46 | 47 | 48 | #endif // SFML_SYSTEM_EXPORT_HPP 49 | -------------------------------------------------------------------------------- /deps/SFML/System/Lock.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_LOCK_HPP 26 | #define SFML_LOCK_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | class Mutex; 38 | 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Automatic wrapper for locking and unlocking mutexes 41 | /// 42 | //////////////////////////////////////////////////////////// 43 | class SFML_SYSTEM_API Lock : NonCopyable 44 | { 45 | public: 46 | 47 | //////////////////////////////////////////////////////////// 48 | /// \brief Construct the lock with a target mutex 49 | /// 50 | /// The mutex passed to sf::Lock is automatically locked. 51 | /// 52 | /// \param mutex Mutex to lock 53 | /// 54 | //////////////////////////////////////////////////////////// 55 | explicit Lock(Mutex& mutex); 56 | 57 | //////////////////////////////////////////////////////////// 58 | /// \brief Destructor 59 | /// 60 | /// The destructor of sf::Lock automatically unlocks its mutex. 61 | /// 62 | //////////////////////////////////////////////////////////// 63 | ~Lock(); 64 | 65 | private: 66 | 67 | //////////////////////////////////////////////////////////// 68 | // Member data 69 | //////////////////////////////////////////////////////////// 70 | Mutex& m_mutex; ///< Mutex to lock / unlock 71 | }; 72 | 73 | } // namespace sf 74 | 75 | 76 | #endif // SFML_LOCK_HPP 77 | 78 | 79 | //////////////////////////////////////////////////////////// 80 | /// \class sf::Lock 81 | /// \ingroup system 82 | /// 83 | /// sf::Lock is a RAII wrapper for sf::Mutex. By unlocking 84 | /// it in its destructor, it ensures that the mutex will 85 | /// always be released when the current scope (most likely 86 | /// a function) ends. 87 | /// This is even more important when an exception or an early 88 | /// return statement can interrupt the execution flow of the 89 | /// function. 90 | /// 91 | /// For maximum robustness, sf::Lock should always be used 92 | /// to lock/unlock a mutex. 93 | /// 94 | /// Usage example: 95 | /// \code 96 | /// sf::Mutex mutex; 97 | /// 98 | /// void function() 99 | /// { 100 | /// sf::Lock lock(mutex); // mutex is now locked 101 | /// 102 | /// functionThatMayThrowAnException(); // mutex is unlocked if this function throws 103 | /// 104 | /// if (someCondition) 105 | /// return; // mutex is unlocked 106 | /// 107 | /// } // mutex is unlocked 108 | /// \endcode 109 | /// 110 | /// Because the mutex is not explicitly unlocked in the code, 111 | /// it may remain locked longer than needed. If the region 112 | /// of the code that needs to be protected by the mutex is 113 | /// not the entire function, a good practice is to create a 114 | /// smaller, inner scope so that the lock is limited to this 115 | /// part of the code. 116 | /// 117 | /// \code 118 | /// sf::Mutex mutex; 119 | /// 120 | /// void function() 121 | /// { 122 | /// { 123 | /// sf::Lock lock(mutex); 124 | /// codeThatRequiresProtection(); 125 | /// 126 | /// } // mutex is unlocked here 127 | /// 128 | /// codeThatDoesntCareAboutTheMutex(); 129 | /// } 130 | /// \endcode 131 | /// 132 | /// Having a mutex locked longer than required is a bad practice 133 | /// which can lead to bad performances. Don't forget that when 134 | /// a mutex is locked, other threads may be waiting doing nothing 135 | /// until it is released. 136 | /// 137 | /// \see sf::Mutex 138 | /// 139 | //////////////////////////////////////////////////////////// 140 | -------------------------------------------------------------------------------- /deps/SFML/System/Mutex.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_MUTEX_HPP 26 | #define SFML_MUTEX_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | class MutexImpl; 40 | } 41 | 42 | //////////////////////////////////////////////////////////// 43 | /// \brief Blocks concurrent access to shared resources 44 | /// from multiple threads 45 | /// 46 | //////////////////////////////////////////////////////////// 47 | class SFML_SYSTEM_API Mutex : NonCopyable 48 | { 49 | public: 50 | 51 | //////////////////////////////////////////////////////////// 52 | /// \brief Default constructor 53 | /// 54 | //////////////////////////////////////////////////////////// 55 | Mutex(); 56 | 57 | //////////////////////////////////////////////////////////// 58 | /// \brief Destructor 59 | /// 60 | //////////////////////////////////////////////////////////// 61 | ~Mutex(); 62 | 63 | //////////////////////////////////////////////////////////// 64 | /// \brief Lock the mutex 65 | /// 66 | /// If the mutex is already locked in another thread, 67 | /// this call will block the execution until the mutex 68 | /// is released. 69 | /// 70 | /// \see unlock 71 | /// 72 | //////////////////////////////////////////////////////////// 73 | void lock(); 74 | 75 | //////////////////////////////////////////////////////////// 76 | /// \brief Unlock the mutex 77 | /// 78 | /// \see lock 79 | /// 80 | //////////////////////////////////////////////////////////// 81 | void unlock(); 82 | 83 | private: 84 | 85 | //////////////////////////////////////////////////////////// 86 | // Member data 87 | //////////////////////////////////////////////////////////// 88 | priv::MutexImpl* m_mutexImpl; ///< OS-specific implementation 89 | }; 90 | 91 | } // namespace sf 92 | 93 | 94 | #endif // SFML_MUTEX_HPP 95 | 96 | 97 | //////////////////////////////////////////////////////////// 98 | /// \class sf::Mutex 99 | /// \ingroup system 100 | /// 101 | /// Mutex stands for "MUTual EXclusion". A mutex is a 102 | /// synchronization object, used when multiple threads are involved. 103 | /// 104 | /// When you want to protect a part of the code from being accessed 105 | /// simultaneously by multiple threads, you typically use a 106 | /// mutex. When a thread is locked by a mutex, any other thread 107 | /// trying to lock it will be blocked until the mutex is released 108 | /// by the thread that locked it. This way, you can allow only 109 | /// one thread at a time to access a critical region of your code. 110 | /// 111 | /// Usage example: 112 | /// \code 113 | /// Database database; // this is a critical resource that needs some protection 114 | /// sf::Mutex mutex; 115 | /// 116 | /// void thread1() 117 | /// { 118 | /// mutex.lock(); // this call will block the thread if the mutex is already locked by thread2 119 | /// database.write(...); 120 | /// mutex.unlock(); // if thread2 was waiting, it will now be unblocked 121 | /// } 122 | /// 123 | /// void thread2() 124 | /// { 125 | /// mutex.lock(); // this call will block the thread if the mutex is already locked by thread1 126 | /// database.write(...); 127 | /// mutex.unlock(); // if thread1 was waiting, it will now be unblocked 128 | /// } 129 | /// \endcode 130 | /// 131 | /// Be very careful with mutexes. A bad usage can lead to bad problems, 132 | /// like deadlocks (two threads are waiting for each other and the 133 | /// application is globally stuck). 134 | /// 135 | /// To make the usage of mutexes more robust, particularly in 136 | /// environments where exceptions can be thrown, you should 137 | /// use the helper class sf::Lock to lock/unlock mutexes. 138 | /// 139 | /// SFML mutexes are recursive, which means that you can lock 140 | /// a mutex multiple times in the same thread without creating 141 | /// a deadlock. In this case, the first call to lock() behaves 142 | /// as usual, and the following ones have no effect. 143 | /// However, you must call unlock() exactly as many times as you 144 | /// called lock(). If you don't, the mutex won't be released. 145 | /// 146 | /// \see sf::Lock 147 | /// 148 | //////////////////////////////////////////////////////////// 149 | -------------------------------------------------------------------------------- /deps/SFML/System/NonCopyable.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_NONCOPYABLE_HPP 26 | #define SFML_NONCOPYABLE_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | 33 | 34 | namespace sf 35 | { 36 | //////////////////////////////////////////////////////////// 37 | /// \brief Utility class that makes any derived 38 | /// class non-copyable 39 | /// 40 | //////////////////////////////////////////////////////////// 41 | class SFML_SYSTEM_API NonCopyable 42 | { 43 | protected: 44 | 45 | //////////////////////////////////////////////////////////// 46 | /// \brief Default constructor 47 | /// 48 | /// Because this class has a copy constructor, the compiler 49 | /// will not automatically generate the default constructor. 50 | /// That's why we must define it explicitly. 51 | /// 52 | //////////////////////////////////////////////////////////// 53 | NonCopyable() {} 54 | 55 | //////////////////////////////////////////////////////////// 56 | /// \brief Default destructor 57 | /// 58 | /// By declaring a protected destructor it's impossible to 59 | /// call delete on a pointer of sf::NonCopyable, thus 60 | /// preventing possible resource leaks. 61 | /// 62 | //////////////////////////////////////////////////////////// 63 | ~NonCopyable() {} 64 | 65 | private: 66 | 67 | //////////////////////////////////////////////////////////// 68 | /// \brief Disabled copy constructor 69 | /// 70 | /// By making the copy constructor private, the compiler will 71 | /// trigger an error if anyone outside tries to use it. 72 | /// To prevent NonCopyable or friend classes from using it, 73 | /// we also give no definition, so that the linker will 74 | /// produce an error if the first protection was inefficient. 75 | /// 76 | //////////////////////////////////////////////////////////// 77 | NonCopyable(const NonCopyable&); 78 | 79 | //////////////////////////////////////////////////////////// 80 | /// \brief Disabled assignment operator 81 | /// 82 | /// By making the assignment operator private, the compiler will 83 | /// trigger an error if anyone outside tries to use it. 84 | /// To prevent NonCopyable or friend classes from using it, 85 | /// we also give no definition, so that the linker will 86 | /// produce an error if the first protection was inefficient. 87 | /// 88 | //////////////////////////////////////////////////////////// 89 | NonCopyable& operator =(const NonCopyable&); 90 | }; 91 | 92 | } // namespace sf 93 | 94 | 95 | #endif // SFML_NONCOPYABLE_HPP 96 | 97 | 98 | //////////////////////////////////////////////////////////// 99 | /// \class sf::NonCopyable 100 | /// \ingroup system 101 | /// 102 | /// This class makes its instances non-copyable, by explicitly 103 | /// disabling its copy constructor and its assignment operator. 104 | /// 105 | /// To create a non-copyable class, simply inherit from 106 | /// sf::NonCopyable. 107 | /// 108 | /// The type of inheritance (public or private) doesn't matter, 109 | /// the copy constructor and assignment operator are declared private 110 | /// in sf::NonCopyable so they will end up being inaccessible in both 111 | /// cases. Thus you can use a shorter syntax for inheriting from it 112 | /// (see below). 113 | /// 114 | /// Usage example: 115 | /// \code 116 | /// class MyNonCopyableClass : sf::NonCopyable 117 | /// { 118 | /// ... 119 | /// }; 120 | /// \endcode 121 | /// 122 | /// Deciding whether the instances of a class can be copied 123 | /// or not is a very important design choice. You are strongly 124 | /// encouraged to think about it before writing a class, 125 | /// and to use sf::NonCopyable when necessary to prevent 126 | /// many potential future errors when using it. This is also 127 | /// a very important indication to users of your class. 128 | /// 129 | //////////////////////////////////////////////////////////// 130 | -------------------------------------------------------------------------------- /deps/SFML/System/Sleep.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SLEEP_HPP 26 | #define SFML_SLEEP_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | //////////////////////////////////////////////////////////// 38 | /// \ingroup system 39 | /// \brief Make the current thread sleep for a given duration 40 | /// 41 | /// sf::sleep is the best way to block a program or one of its 42 | /// threads, as it doesn't consume any CPU power. 43 | /// 44 | /// \param duration Time to sleep 45 | /// 46 | //////////////////////////////////////////////////////////// 47 | void SFML_SYSTEM_API sleep(Time duration); 48 | 49 | } // namespace sf 50 | 51 | 52 | #endif // SFML_SLEEP_HPP 53 | -------------------------------------------------------------------------------- /deps/SFML/System/UnixClockImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_CLOCKIMPLUNIX_HPP 26 | #define SFML_CLOCKIMPLUNIX_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Unix implementation of sf::Clock 41 | /// 42 | //////////////////////////////////////////////////////////// 43 | class ClockImpl 44 | { 45 | public: 46 | 47 | //////////////////////////////////////////////////////////// 48 | /// \brief Get the current time 49 | /// 50 | /// \return Current time 51 | /// 52 | //////////////////////////////////////////////////////////// 53 | static Time getCurrentTime(); 54 | }; 55 | 56 | } // namespace priv 57 | 58 | } // namespace sf 59 | 60 | 61 | #endif // SFML_CLOCKIMPLUNIX_HPP 62 | -------------------------------------------------------------------------------- /deps/SFML/System/UnixImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_MUTEXIMPL_HPP 26 | #define SFML_MUTEXIMPL_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Unix implementation of mutexes 41 | //////////////////////////////////////////////////////////// 42 | class MutexImpl : NonCopyable 43 | { 44 | public: 45 | 46 | //////////////////////////////////////////////////////////// 47 | /// \brief Default constructor 48 | /// 49 | //////////////////////////////////////////////////////////// 50 | MutexImpl(); 51 | 52 | //////////////////////////////////////////////////////////// 53 | /// \brief Destructor 54 | /// 55 | //////////////////////////////////////////////////////////// 56 | ~MutexImpl(); 57 | 58 | //////////////////////////////////////////////////////////// 59 | /// \brief Lock the mutex 60 | /// 61 | //////////////////////////////////////////////////////////// 62 | void lock(); 63 | 64 | //////////////////////////////////////////////////////////// 65 | /// \brief Unlock the mutex 66 | /// 67 | //////////////////////////////////////////////////////////// 68 | void unlock(); 69 | 70 | private: 71 | 72 | //////////////////////////////////////////////////////////// 73 | // Member data 74 | //////////////////////////////////////////////////////////// 75 | pthread_mutex_t m_mutex; ///< pthread handle of the mutex 76 | }; 77 | 78 | } // namespace priv 79 | 80 | } // namespace sf 81 | 82 | 83 | #endif // SFML_MUTEXIMPL_HPP 84 | -------------------------------------------------------------------------------- /deps/SFML/System/UnixMutexImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_MUTEXIMPL_HPP 26 | #define SFML_MUTEXIMPL_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Unix implementation of mutexes 41 | //////////////////////////////////////////////////////////// 42 | class MutexImpl : NonCopyable 43 | { 44 | public: 45 | 46 | //////////////////////////////////////////////////////////// 47 | /// \brief Default constructor 48 | /// 49 | //////////////////////////////////////////////////////////// 50 | MutexImpl(); 51 | 52 | //////////////////////////////////////////////////////////// 53 | /// \brief Destructor 54 | /// 55 | //////////////////////////////////////////////////////////// 56 | ~MutexImpl(); 57 | 58 | //////////////////////////////////////////////////////////// 59 | /// \brief Lock the mutex 60 | /// 61 | //////////////////////////////////////////////////////////// 62 | void lock(); 63 | 64 | //////////////////////////////////////////////////////////// 65 | /// \brief Unlock the mutex 66 | /// 67 | //////////////////////////////////////////////////////////// 68 | void unlock(); 69 | 70 | private: 71 | 72 | //////////////////////////////////////////////////////////// 73 | // Member data 74 | //////////////////////////////////////////////////////////// 75 | pthread_mutex_t m_mutex; ///< pthread handle of the mutex 76 | }; 77 | 78 | } // namespace priv 79 | 80 | } // namespace sf 81 | 82 | 83 | #endif // SFML_MUTEXIMPL_HPP 84 | -------------------------------------------------------------------------------- /deps/SFML/System/UnixSleepImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SLEEPIMPLUNIX_HPP 26 | #define SFML_SLEEPIMPLUNIX_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Unix implementation of sf::Sleep 41 | /// 42 | /// \param time Time to sleep 43 | /// 44 | //////////////////////////////////////////////////////////// 45 | void sleepImpl(Time time); 46 | 47 | } // namespace priv 48 | 49 | } // namespace sf 50 | 51 | 52 | #endif // SFML_SLEEPIMPLUNIX_HPP 53 | -------------------------------------------------------------------------------- /deps/SFML/System/Win32ClockImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_CLOCKIMPLWIN32_HPP 26 | #define SFML_CLOCKIMPLWIN32_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Windows implementation of sf::Clock 41 | /// 42 | //////////////////////////////////////////////////////////// 43 | class ClockImpl 44 | { 45 | public: 46 | 47 | //////////////////////////////////////////////////////////// 48 | /// \brief Get the current time 49 | /// 50 | /// \return Current time 51 | /// 52 | //////////////////////////////////////////////////////////// 53 | static Time getCurrentTime(); 54 | }; 55 | 56 | } // namespace priv 57 | 58 | } // namespace sf 59 | 60 | 61 | #endif // SFML_CLOCKIMPLWIN32_HPP 62 | -------------------------------------------------------------------------------- /deps/SFML/System/Win32MutexImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_MUTEXIMPL_HPP 26 | #define SFML_MUTEXIMPL_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Windows implementation of mutexes 41 | //////////////////////////////////////////////////////////// 42 | class MutexImpl : NonCopyable 43 | { 44 | public: 45 | 46 | //////////////////////////////////////////////////////////// 47 | /// \brief Default constructor 48 | /// 49 | //////////////////////////////////////////////////////////// 50 | MutexImpl(); 51 | 52 | //////////////////////////////////////////////////////////// 53 | /// \brief Destructor 54 | /// 55 | //////////////////////////////////////////////////////////// 56 | ~MutexImpl(); 57 | 58 | //////////////////////////////////////////////////////////// 59 | /// \brief Lock the mutex 60 | /// 61 | //////////////////////////////////////////////////////////// 62 | void lock(); 63 | 64 | //////////////////////////////////////////////////////////// 65 | /// \brief Unlock the mutex 66 | /// 67 | //////////////////////////////////////////////////////////// 68 | void unlock(); 69 | 70 | private: 71 | 72 | //////////////////////////////////////////////////////////// 73 | // Member data 74 | //////////////////////////////////////////////////////////// 75 | CRITICAL_SECTION m_mutex; ///< Win32 handle of the mutex 76 | }; 77 | 78 | } // namespace priv 79 | 80 | } // namespace sf 81 | 82 | 83 | #endif // SFML_MUTEXIMPL_HPP 84 | -------------------------------------------------------------------------------- /deps/SFML/System/Win32SleepImpl.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_SLEEPIMPLWIN32_HPP 26 | #define SFML_SLEEPIMPLWIN32_HPP 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Headers 30 | //////////////////////////////////////////////////////////// 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | /// \brief Windows implementation of sf::Sleep 41 | /// 42 | /// \param time Time to sleep 43 | /// 44 | //////////////////////////////////////////////////////////// 45 | void sleepImpl(Time time); 46 | 47 | } // namespace priv 48 | 49 | } // namespace sf 50 | 51 | 52 | #endif // SFML_SLEEPIMPLWIN32_HPP 53 | -------------------------------------------------------------------------------- /deps/SFML/TcpListener.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | namespace sf 35 | { 36 | //////////////////////////////////////////////////////////// 37 | TcpListener::TcpListener() : 38 | Socket(Tcp) 39 | { 40 | 41 | } 42 | 43 | 44 | //////////////////////////////////////////////////////////// 45 | unsigned short TcpListener::getLocalPort() const 46 | { 47 | if (getHandle() != priv::SocketImpl::invalidSocket()) 48 | { 49 | // Retrieve informations about the local end of the socket 50 | sockaddr_in address; 51 | priv::SocketImpl::AddrLength size = sizeof(address); 52 | if (getsockname(getHandle(), reinterpret_cast(&address), &size) != -1) 53 | { 54 | return ntohs(address.sin_port); 55 | } 56 | } 57 | 58 | // We failed to retrieve the port 59 | return 0; 60 | } 61 | 62 | 63 | //////////////////////////////////////////////////////////// 64 | Socket::Status TcpListener::listen(unsigned short port, const IpAddress& address) 65 | { 66 | // Close the socket if it is already bound 67 | close(); 68 | 69 | // Create the internal socket if it doesn't exist 70 | create(); 71 | 72 | // Check if the address is valid 73 | if ((address == IpAddress::None) || (address == IpAddress::Broadcast)) 74 | return Error; 75 | 76 | // Bind the socket to the specified port 77 | sockaddr_in addr = priv::SocketImpl::createAddress(address.toInteger(), port); 78 | if (bind(getHandle(), reinterpret_cast(&addr), sizeof(addr)) == -1) 79 | { 80 | // Not likely to happen, but... 81 | err() << "Failed to bind listener socket to port " << port << std::endl; 82 | return Error; 83 | } 84 | 85 | // Listen to the bound port 86 | if (::listen(getHandle(), SOMAXCONN) == -1) 87 | { 88 | // Oops, socket is deaf 89 | err() << "Failed to listen to port " << port << std::endl; 90 | return Error; 91 | } 92 | 93 | return Done; 94 | } 95 | 96 | 97 | //////////////////////////////////////////////////////////// 98 | void TcpListener::close() 99 | { 100 | // Simply close the socket 101 | Socket::close(); 102 | } 103 | 104 | 105 | //////////////////////////////////////////////////////////// 106 | Socket::Status TcpListener::accept(TcpSocket& socket) 107 | { 108 | // Make sure that we're listening 109 | if (getHandle() == priv::SocketImpl::invalidSocket()) 110 | { 111 | err() << "Failed to accept a new connection, the socket is not listening" << std::endl; 112 | return Error; 113 | } 114 | 115 | // Accept a new connection 116 | sockaddr_in address; 117 | priv::SocketImpl::AddrLength length = sizeof(address); 118 | SocketHandle remote = ::accept(getHandle(), reinterpret_cast(&address), &length); 119 | 120 | // Check for errors 121 | if (remote == priv::SocketImpl::invalidSocket()) 122 | return priv::SocketImpl::getErrorStatus(); 123 | 124 | // Initialize the new connected socket 125 | socket.close(); 126 | socket.create(remote); 127 | 128 | return Done; 129 | } 130 | 131 | } // namespace sf 132 | -------------------------------------------------------------------------------- /deps/SFML/Time.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | 30 | 31 | namespace sf 32 | { 33 | //////////////////////////////////////////////////////////// 34 | const Time Time::Zero; 35 | 36 | 37 | //////////////////////////////////////////////////////////// 38 | Time::Time() : 39 | m_microseconds(0) 40 | { 41 | } 42 | 43 | 44 | //////////////////////////////////////////////////////////// 45 | float Time::asSeconds() const 46 | { 47 | return m_microseconds / 1000000.f; 48 | } 49 | 50 | 51 | //////////////////////////////////////////////////////////// 52 | Int32 Time::asMilliseconds() const 53 | { 54 | return static_cast(m_microseconds / 1000); 55 | } 56 | 57 | 58 | //////////////////////////////////////////////////////////// 59 | Int64 Time::asMicroseconds() const 60 | { 61 | return m_microseconds; 62 | } 63 | 64 | 65 | //////////////////////////////////////////////////////////// 66 | Time::Time(Int64 microseconds) : 67 | m_microseconds(microseconds) 68 | { 69 | } 70 | 71 | 72 | //////////////////////////////////////////////////////////// 73 | Time seconds(float amount) 74 | { 75 | return Time(static_cast(amount * 1000000)); 76 | } 77 | 78 | 79 | //////////////////////////////////////////////////////////// 80 | Time milliseconds(Int32 amount) 81 | { 82 | return Time(static_cast(amount) * 1000); 83 | } 84 | 85 | 86 | //////////////////////////////////////////////////////////// 87 | Time microseconds(Int64 amount) 88 | { 89 | return Time(amount); 90 | } 91 | 92 | 93 | //////////////////////////////////////////////////////////// 94 | bool operator ==(Time left, Time right) 95 | { 96 | return left.asMicroseconds() == right.asMicroseconds(); 97 | } 98 | 99 | 100 | //////////////////////////////////////////////////////////// 101 | bool operator !=(Time left, Time right) 102 | { 103 | return left.asMicroseconds() != right.asMicroseconds(); 104 | } 105 | 106 | 107 | //////////////////////////////////////////////////////////// 108 | bool operator <(Time left, Time right) 109 | { 110 | return left.asMicroseconds() < right.asMicroseconds(); 111 | } 112 | 113 | 114 | //////////////////////////////////////////////////////////// 115 | bool operator >(Time left, Time right) 116 | { 117 | return left.asMicroseconds() > right.asMicroseconds(); 118 | } 119 | 120 | 121 | //////////////////////////////////////////////////////////// 122 | bool operator <=(Time left, Time right) 123 | { 124 | return left.asMicroseconds() <= right.asMicroseconds(); 125 | } 126 | 127 | 128 | //////////////////////////////////////////////////////////// 129 | bool operator >=(Time left, Time right) 130 | { 131 | return left.asMicroseconds() >= right.asMicroseconds(); 132 | } 133 | 134 | 135 | //////////////////////////////////////////////////////////// 136 | Time operator -(Time right) 137 | { 138 | return microseconds(-right.asMicroseconds()); 139 | } 140 | 141 | 142 | //////////////////////////////////////////////////////////// 143 | Time operator +(Time left, Time right) 144 | { 145 | return microseconds(left.asMicroseconds() + right.asMicroseconds()); 146 | } 147 | 148 | 149 | //////////////////////////////////////////////////////////// 150 | Time& operator +=(Time& left, Time right) 151 | { 152 | return left = left + right; 153 | } 154 | 155 | 156 | //////////////////////////////////////////////////////////// 157 | Time operator -(Time left, Time right) 158 | { 159 | return microseconds(left.asMicroseconds() - right.asMicroseconds()); 160 | } 161 | 162 | 163 | //////////////////////////////////////////////////////////// 164 | Time& operator -=(Time& left, Time right) 165 | { 166 | return left = left - right; 167 | } 168 | 169 | 170 | //////////////////////////////////////////////////////////// 171 | Time operator *(Time left, float right) 172 | { 173 | return seconds(left.asSeconds() * right); 174 | } 175 | 176 | 177 | //////////////////////////////////////////////////////////// 178 | Time operator *(Time left, Int64 right) 179 | { 180 | return microseconds(left.asMicroseconds() * right); 181 | } 182 | 183 | 184 | //////////////////////////////////////////////////////////// 185 | Time operator *(float left, Time right) 186 | { 187 | return right * left; 188 | } 189 | 190 | 191 | //////////////////////////////////////////////////////////// 192 | Time operator *(Int64 left, Time right) 193 | { 194 | return right * left; 195 | } 196 | 197 | 198 | //////////////////////////////////////////////////////////// 199 | Time& operator *=(Time& left, float right) 200 | { 201 | return left = left * right; 202 | } 203 | 204 | 205 | //////////////////////////////////////////////////////////// 206 | Time& operator *=(Time& left, Int64 right) 207 | { 208 | return left = left * right; 209 | } 210 | 211 | 212 | //////////////////////////////////////////////////////////// 213 | Time operator /(Time left, float right) 214 | { 215 | return seconds(left.asSeconds() / right); 216 | } 217 | 218 | 219 | //////////////////////////////////////////////////////////// 220 | Time operator /(Time left, Int64 right) 221 | { 222 | return microseconds(left.asMicroseconds() / right); 223 | } 224 | 225 | 226 | //////////////////////////////////////////////////////////// 227 | Time& operator /=(Time& left, float right) 228 | { 229 | return left = left / right; 230 | } 231 | 232 | 233 | //////////////////////////////////////////////////////////// 234 | Time& operator /=(Time& left, Int64 right) 235 | { 236 | return left = left / right; 237 | } 238 | 239 | 240 | //////////////////////////////////////////////////////////// 241 | float operator /(Time left, Time right) 242 | { 243 | return left.asSeconds() / right.asSeconds(); 244 | } 245 | 246 | 247 | //////////////////////////////////////////////////////////// 248 | Time operator %(Time left, Time right) 249 | { 250 | return microseconds(left.asMicroseconds() % right.asMicroseconds()); 251 | } 252 | 253 | 254 | //////////////////////////////////////////////////////////// 255 | Time& operator %=(Time& left, Time right) 256 | { 257 | return left = left % right; 258 | } 259 | 260 | } // namespace sf 261 | -------------------------------------------------------------------------------- /deps/SFML/UdpSocket.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | //////////////////////////////////////////////////////////// 38 | UdpSocket::UdpSocket() : 39 | Socket (Udp), 40 | m_buffer(MaxDatagramSize) 41 | { 42 | 43 | } 44 | 45 | 46 | //////////////////////////////////////////////////////////// 47 | unsigned short UdpSocket::getLocalPort() const 48 | { 49 | if (getHandle() != priv::SocketImpl::invalidSocket()) 50 | { 51 | // Retrieve informations about the local end of the socket 52 | sockaddr_in address; 53 | priv::SocketImpl::AddrLength size = sizeof(address); 54 | if (getsockname(getHandle(), reinterpret_cast(&address), &size) != -1) 55 | { 56 | return ntohs(address.sin_port); 57 | } 58 | } 59 | 60 | // We failed to retrieve the port 61 | return 0; 62 | } 63 | 64 | 65 | //////////////////////////////////////////////////////////// 66 | Socket::Status UdpSocket::bind(unsigned short port, const IpAddress& address) 67 | { 68 | // Close the socket if it is already bound 69 | close(); 70 | 71 | // Create the internal socket if it doesn't exist 72 | create(); 73 | 74 | // Check if the address is valid 75 | if ((address == IpAddress::None) || (address == IpAddress::Broadcast)) 76 | return Error; 77 | 78 | // Bind the socket 79 | sockaddr_in addr = priv::SocketImpl::createAddress(address.toInteger(), port); 80 | if (::bind(getHandle(), reinterpret_cast(&addr), sizeof(addr)) == -1) 81 | { 82 | err() << "Failed to bind socket to port " << port << std::endl; 83 | return Error; 84 | } 85 | 86 | return Done; 87 | } 88 | 89 | 90 | //////////////////////////////////////////////////////////// 91 | void UdpSocket::unbind() 92 | { 93 | // Simply close the socket 94 | close(); 95 | } 96 | 97 | 98 | //////////////////////////////////////////////////////////// 99 | Socket::Status UdpSocket::send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort) 100 | { 101 | // Create the internal socket if it doesn't exist 102 | create(); 103 | 104 | // Make sure that all the data will fit in one datagram 105 | if (size > MaxDatagramSize) 106 | { 107 | err() << "Cannot send data over the network " 108 | << "(the number of bytes to send is greater than sf::UdpSocket::MaxDatagramSize)" << std::endl; 109 | return Error; 110 | } 111 | 112 | // Build the target address 113 | sockaddr_in address = priv::SocketImpl::createAddress(remoteAddress.toInteger(), remotePort); 114 | 115 | // Send the data (unlike TCP, all the data is always sent in one call) 116 | int sent = sendto(getHandle(), static_cast(data), static_cast(size), 0, reinterpret_cast(&address), sizeof(address)); 117 | 118 | // Check for errors 119 | if (sent < 0) 120 | return priv::SocketImpl::getErrorStatus(); 121 | 122 | return Done; 123 | } 124 | 125 | 126 | //////////////////////////////////////////////////////////// 127 | Socket::Status UdpSocket::receive(void* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort) 128 | { 129 | // First clear the variables to fill 130 | received = 0; 131 | remoteAddress = IpAddress(); 132 | remotePort = 0; 133 | 134 | // Check the destination buffer 135 | if (!data) 136 | { 137 | err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl; 138 | return Error; 139 | } 140 | 141 | // Data that will be filled with the other computer's address 142 | sockaddr_in address = priv::SocketImpl::createAddress(INADDR_ANY, 0); 143 | 144 | // Receive a chunk of bytes 145 | priv::SocketImpl::AddrLength addressSize = sizeof(address); 146 | int sizeReceived = recvfrom(getHandle(), static_cast(data), static_cast(size), 0, reinterpret_cast(&address), &addressSize); 147 | 148 | // Check for errors 149 | if (sizeReceived < 0) 150 | return priv::SocketImpl::getErrorStatus(); 151 | 152 | // Fill the sender informations 153 | received = static_cast(sizeReceived); 154 | remoteAddress = IpAddress(ntohl(address.sin_addr.s_addr)); 155 | remotePort = ntohs(address.sin_port); 156 | 157 | return Done; 158 | } 159 | 160 | 161 | } // namespace sf 162 | -------------------------------------------------------------------------------- /deps/SFML/UnixClockImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) 30 | #include 31 | #else 32 | #include 33 | #endif 34 | 35 | 36 | namespace sf 37 | { 38 | namespace priv 39 | { 40 | //////////////////////////////////////////////////////////// 41 | Time ClockImpl::getCurrentTime() 42 | { 43 | #if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) 44 | 45 | // Mac OS X specific implementation (it doesn't support clock_gettime) 46 | static mach_timebase_info_data_t frequency = {0, 0}; 47 | if (frequency.denom == 0) 48 | mach_timebase_info(&frequency); 49 | Uint64 nanoseconds = mach_absolute_time() * frequency.numer / frequency.denom; 50 | return sf::microseconds(nanoseconds / 1000); 51 | 52 | #else 53 | 54 | // POSIX implementation 55 | timespec time; 56 | clock_gettime(CLOCK_MONOTONIC, &time); 57 | return sf::microseconds(static_cast(time.tv_sec) * 1000000 + time.tv_nsec / 1000); 58 | 59 | #endif 60 | } 61 | 62 | } // namespace priv 63 | 64 | } // namespace sf 65 | -------------------------------------------------------------------------------- /deps/SFML/UnixMutexImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | 30 | 31 | namespace sf 32 | { 33 | namespace priv 34 | { 35 | //////////////////////////////////////////////////////////// 36 | MutexImpl::MutexImpl() 37 | { 38 | // Make it recursive to follow the expected behavior 39 | pthread_mutexattr_t attributes; 40 | pthread_mutexattr_init(&attributes); 41 | pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE); 42 | 43 | pthread_mutex_init(&m_mutex, &attributes); 44 | } 45 | 46 | 47 | //////////////////////////////////////////////////////////// 48 | MutexImpl::~MutexImpl() 49 | { 50 | pthread_mutex_destroy(&m_mutex); 51 | } 52 | 53 | 54 | //////////////////////////////////////////////////////////// 55 | void MutexImpl::lock() 56 | { 57 | pthread_mutex_lock(&m_mutex); 58 | } 59 | 60 | 61 | //////////////////////////////////////////////////////////// 62 | void MutexImpl::unlock() 63 | { 64 | pthread_mutex_unlock(&m_mutex); 65 | } 66 | 67 | } // namespace priv 68 | 69 | } // namespace sf 70 | -------------------------------------------------------------------------------- /deps/SFML/UnixSleepImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace sf 34 | { 35 | namespace priv 36 | { 37 | //////////////////////////////////////////////////////////// 38 | void sleepImpl(Time time) 39 | { 40 | Uint64 usecs = time.asMicroseconds(); 41 | 42 | // Construct the time to wait 43 | timespec ti; 44 | ti.tv_nsec = (usecs % 1000000) * 1000; 45 | ti.tv_sec = usecs / 1000000; 46 | 47 | // Wait... 48 | // If nanosleep returns -1, we check errno. If it is EINTR 49 | // nanosleep was interrupted and has set ti to the remaining 50 | // duration. We continue sleeping until the complete duration 51 | // has passed. We stop sleeping if it was due to an error. 52 | while ((nanosleep(&ti, &ti) == -1) && (errno == EINTR)) 53 | { 54 | } 55 | } 56 | 57 | } // namespace priv 58 | 59 | } // namespace sf 60 | -------------------------------------------------------------------------------- /deps/SFML/UnixSocketImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | namespace sf 36 | { 37 | namespace priv 38 | { 39 | //////////////////////////////////////////////////////////// 40 | sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port) 41 | { 42 | sockaddr_in addr; 43 | std::memset(&addr, 0, sizeof(addr)); 44 | addr.sin_addr.s_addr = htonl(address); 45 | addr.sin_family = AF_INET; 46 | addr.sin_port = htons(port); 47 | 48 | #if defined(SFML_SYSTEM_MACOS) 49 | addr.sin_len = sizeof(addr); 50 | #endif 51 | 52 | return addr; 53 | } 54 | 55 | 56 | //////////////////////////////////////////////////////////// 57 | SocketHandle SocketImpl::invalidSocket() 58 | { 59 | return -1; 60 | } 61 | 62 | 63 | //////////////////////////////////////////////////////////// 64 | void SocketImpl::close(SocketHandle sock) 65 | { 66 | ::close(sock); 67 | } 68 | 69 | 70 | //////////////////////////////////////////////////////////// 71 | void SocketImpl::setBlocking(SocketHandle sock, bool block) 72 | { 73 | int status = fcntl(sock, F_GETFL); 74 | if (block) 75 | { 76 | if (fcntl(sock, F_SETFL, status & ~O_NONBLOCK) == -1) 77 | err() << "Failed to set file status flags: " << errno << std::endl; 78 | } 79 | else 80 | { 81 | if (fcntl(sock, F_SETFL, status | O_NONBLOCK) == -1) 82 | err() << "Failed to set file status flags: " << errno << std::endl; 83 | 84 | } 85 | } 86 | 87 | 88 | //////////////////////////////////////////////////////////// 89 | Socket::Status SocketImpl::getErrorStatus() 90 | { 91 | // The followings are sometimes equal to EWOULDBLOCK, 92 | // so we have to make a special case for them in order 93 | // to avoid having double values in the switch case 94 | if ((errno == EAGAIN) || (errno == EINPROGRESS)) 95 | return Socket::NotReady; 96 | 97 | switch (errno) 98 | { 99 | case EWOULDBLOCK: return Socket::NotReady; 100 | case ECONNABORTED: return Socket::Disconnected; 101 | case ECONNRESET: return Socket::Disconnected; 102 | case ETIMEDOUT: return Socket::Disconnected; 103 | case ENETRESET: return Socket::Disconnected; 104 | case ENOTCONN: return Socket::Disconnected; 105 | case EPIPE: return Socket::Disconnected; 106 | default: return Socket::Error; 107 | } 108 | } 109 | 110 | } // namespace priv 111 | 112 | } // namespace sf 113 | -------------------------------------------------------------------------------- /deps/SFML/Win32ClockImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | namespace 35 | { 36 | LARGE_INTEGER getFrequency() 37 | { 38 | LARGE_INTEGER frequency; 39 | QueryPerformanceFrequency(&frequency); 40 | return frequency; 41 | } 42 | 43 | bool isWindowsXpOrOlder() 44 | { 45 | // Windows XP was the last 5.x version of Windows 46 | return static_cast(LOBYTE(LOWORD(GetVersion()))) < 6; 47 | } 48 | } 49 | 50 | namespace sf 51 | { 52 | namespace priv 53 | { 54 | //////////////////////////////////////////////////////////// 55 | Time ClockImpl::getCurrentTime() 56 | { 57 | // Get the frequency of the performance counter 58 | // (it is constant across the program lifetime) 59 | static LARGE_INTEGER frequency = getFrequency(); 60 | 61 | // Detect if we are on Windows XP or older 62 | static bool oldWindows = isWindowsXpOrOlder(); 63 | 64 | LARGE_INTEGER time; 65 | 66 | if (oldWindows) 67 | { 68 | static sf::Mutex oldWindowsMutex; 69 | 70 | // Acquire a lock (CRITICAL_SECTION) to prevent travelling back in time 71 | Lock lock(oldWindowsMutex); 72 | 73 | // Get the current time 74 | QueryPerformanceCounter(&time); 75 | } 76 | else 77 | { 78 | // Get the current time 79 | QueryPerformanceCounter(&time); 80 | } 81 | 82 | // Return the current time as microseconds 83 | return sf::microseconds(1000000 * time.QuadPart / frequency.QuadPart); 84 | } 85 | 86 | } // namespace priv 87 | 88 | } // namespace sf 89 | -------------------------------------------------------------------------------- /deps/SFML/Win32MutexImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | 30 | 31 | namespace sf 32 | { 33 | namespace priv 34 | { 35 | //////////////////////////////////////////////////////////// 36 | MutexImpl::MutexImpl() 37 | { 38 | InitializeCriticalSection(&m_mutex); 39 | } 40 | 41 | 42 | //////////////////////////////////////////////////////////// 43 | MutexImpl::~MutexImpl() 44 | { 45 | DeleteCriticalSection(&m_mutex); 46 | } 47 | 48 | 49 | //////////////////////////////////////////////////////////// 50 | void MutexImpl::lock() 51 | { 52 | EnterCriticalSection(&m_mutex); 53 | } 54 | 55 | 56 | //////////////////////////////////////////////////////////// 57 | void MutexImpl::unlock() 58 | { 59 | LeaveCriticalSection(&m_mutex); 60 | } 61 | 62 | } // namespace priv 63 | 64 | } // namespace sf 65 | -------------------------------------------------------------------------------- /deps/SFML/Win32SleepImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | 31 | 32 | namespace sf 33 | { 34 | namespace priv 35 | { 36 | //////////////////////////////////////////////////////////// 37 | void sleepImpl(Time time) 38 | { 39 | // Get the supported timer resolutions on this system 40 | TIMECAPS tc; 41 | timeGetDevCaps(&tc, sizeof(TIMECAPS)); 42 | 43 | // Set the timer resolution to the minimum for the Sleep call 44 | timeBeginPeriod(tc.wPeriodMin); 45 | 46 | // Wait... 47 | ::Sleep(time.asMilliseconds()); 48 | 49 | // Reset the timer resolution back to the system default 50 | timeEndPeriod(tc.wPeriodMin); 51 | } 52 | 53 | } // namespace priv 54 | 55 | } // namespace sf 56 | -------------------------------------------------------------------------------- /deps/SFML/Win32SocketImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Headers 27 | //////////////////////////////////////////////////////////// 28 | #include 29 | #include 30 | 31 | 32 | namespace sf 33 | { 34 | namespace priv 35 | { 36 | //////////////////////////////////////////////////////////// 37 | sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port) 38 | { 39 | sockaddr_in addr; 40 | std::memset(&addr, 0, sizeof(addr)); 41 | addr.sin_addr.s_addr = htonl(address); 42 | addr.sin_family = AF_INET; 43 | addr.sin_port = htons(port); 44 | 45 | return addr; 46 | } 47 | 48 | 49 | //////////////////////////////////////////////////////////// 50 | SocketHandle SocketImpl::invalidSocket() 51 | { 52 | return INVALID_SOCKET; 53 | } 54 | 55 | 56 | //////////////////////////////////////////////////////////// 57 | void SocketImpl::close(SocketHandle sock) 58 | { 59 | closesocket(sock); 60 | } 61 | 62 | 63 | //////////////////////////////////////////////////////////// 64 | void SocketImpl::setBlocking(SocketHandle sock, bool block) 65 | { 66 | u_long blocking = block ? 0 : 1; 67 | ioctlsocket(sock, FIONBIO, &blocking); 68 | } 69 | 70 | 71 | //////////////////////////////////////////////////////////// 72 | Socket::Status SocketImpl::getErrorStatus() 73 | { 74 | switch (WSAGetLastError()) 75 | { 76 | case WSAEWOULDBLOCK: return Socket::NotReady; 77 | case WSAEALREADY: return Socket::NotReady; 78 | case WSAECONNABORTED: return Socket::Disconnected; 79 | case WSAECONNRESET: return Socket::Disconnected; 80 | case WSAETIMEDOUT: return Socket::Disconnected; 81 | case WSAENETRESET: return Socket::Disconnected; 82 | case WSAENOTCONN: return Socket::Disconnected; 83 | case WSAEISCONN: return Socket::Done; // when connecting a non-blocking socket 84 | default: return Socket::Error; 85 | } 86 | } 87 | 88 | 89 | //////////////////////////////////////////////////////////// 90 | // Windows needs some initialization and cleanup to get 91 | // sockets working properly... so let's create a class that will 92 | // do it automatically 93 | //////////////////////////////////////////////////////////// 94 | struct SocketInitializer 95 | { 96 | SocketInitializer() 97 | { 98 | WSADATA init; 99 | WSAStartup(MAKEWORD(2, 2), &init); 100 | } 101 | 102 | ~SocketInitializer() 103 | { 104 | WSACleanup(); 105 | } 106 | }; 107 | 108 | SocketInitializer globalInitializer; 109 | 110 | } // namespace priv 111 | 112 | } // namespace sf 113 | -------------------------------------------------------------------------------- /deps/wepoll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wepoll - epoll for Windows 3 | * https://github.com/piscisaureus/wepoll 4 | * 5 | * Copyright 2012-2018, Bert Belder 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are 10 | * met: 11 | * 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef WEPOLL_H_ 33 | #define WEPOLL_H_ 34 | 35 | #ifndef WEPOLL_EXPORT 36 | #define WEPOLL_EXPORT 37 | #endif 38 | 39 | #include 40 | 41 | enum EPOLL_EVENTS { 42 | EPOLLIN = (int) (1U << 0), 43 | EPOLLPRI = (int) (1U << 1), 44 | EPOLLOUT = (int) (1U << 2), 45 | EPOLLERR = (int) (1U << 3), 46 | EPOLLHUP = (int) (1U << 4), 47 | EPOLLRDNORM = (int) (1U << 6), 48 | EPOLLRDBAND = (int) (1U << 7), 49 | EPOLLWRNORM = (int) (1U << 8), 50 | EPOLLWRBAND = (int) (1U << 9), 51 | EPOLLMSG = (int) (1U << 10), /* Never reported. */ 52 | EPOLLRDHUP = (int) (1U << 13), 53 | EPOLLONESHOT = (int) (1U << 31) 54 | }; 55 | 56 | #define EPOLLIN (1U << 0) 57 | #define EPOLLPRI (1U << 1) 58 | #define EPOLLOUT (1U << 2) 59 | #define EPOLLERR (1U << 3) 60 | #define EPOLLHUP (1U << 4) 61 | #define EPOLLRDNORM (1U << 6) 62 | #define EPOLLRDBAND (1U << 7) 63 | #define EPOLLWRNORM (1U << 8) 64 | #define EPOLLWRBAND (1U << 9) 65 | #define EPOLLMSG (1U << 10) 66 | #define EPOLLRDHUP (1U << 13) 67 | #define EPOLLONESHOT (1U << 31) 68 | 69 | #define EPOLL_CTL_ADD 1 70 | #define EPOLL_CTL_MOD 2 71 | #define EPOLL_CTL_DEL 3 72 | 73 | typedef void* HANDLE; 74 | typedef uintptr_t SOCKET; 75 | 76 | typedef union epoll_data { 77 | void* ptr; 78 | int fd; 79 | uint32_t u32; 80 | uint64_t u64; 81 | SOCKET sock; /* Windows specific */ 82 | HANDLE hnd; /* Windows specific */ 83 | } epoll_data_t; 84 | 85 | struct epoll_event { 86 | uint32_t events; /* Epoll events and flags */ 87 | epoll_data_t data; /* User data variable */ 88 | }; 89 | 90 | #ifdef __cplusplus 91 | extern "C" { 92 | #endif 93 | 94 | WEPOLL_EXPORT HANDLE epoll_create(int size); 95 | WEPOLL_EXPORT HANDLE epoll_create1(int flags); 96 | 97 | WEPOLL_EXPORT int epoll_close(HANDLE ephnd); 98 | 99 | WEPOLL_EXPORT int epoll_ctl(HANDLE ephnd, 100 | int op, 101 | SOCKET sock, 102 | struct epoll_event* event); 103 | 104 | WEPOLL_EXPORT int epoll_wait(HANDLE ephnd, 105 | struct epoll_event* events, 106 | int maxevents, 107 | int timeout); 108 | 109 | #ifdef __cplusplus 110 | } /* extern "C" */ 111 | #endif 112 | 113 | #endif /* WEPOLL_H_ */ 114 | -------------------------------------------------------------------------------- /include/RedRelayServer.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // RedRelay - a Lacewing Relay protocol reimplementation 4 | // Copyright (c) 2019 LekKit (LekKit#4400 in Discord) 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source distribution. 21 | // 22 | //////////////////////////////////////////////////////////// 23 | 24 | #ifndef REDRELAY_SERVER 25 | #define REDRELAY_SERVER 26 | 27 | #define REDRELAY_SERVER_BUILD 10 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "IDPool.hpp" 34 | #include 35 | 36 | #ifdef REDRELAY_EPOLL 37 | #include "EpollSelector.hpp" 38 | #endif 39 | 40 | #ifdef REDRELAY_MULTITHREAD 41 | #include 42 | #endif 43 | 44 | namespace rs{ 45 | 46 | class RelayPacket{ 47 | private: 48 | std::size_t capacity; 49 | std::size_t size; 50 | uint8_t type; 51 | char* buffer; 52 | public: 53 | RelayPacket(std::size_t Size=65536); 54 | ~RelayPacket(); 55 | void Reallocate(std::size_t newcapacity); 56 | void SetType(const uint8_t Type); 57 | void AddByte(const uint8_t Byte); 58 | void AddShort(const uint16_t Short); 59 | void AddInt(const uint32_t Int); 60 | void AddString(const std::string& String); 61 | const char* GetPacket(); 62 | std::size_t GetPacketSize() const; 63 | std::size_t GetSize() const; 64 | void Clear(); 65 | }; 66 | 67 | class Peer{ 68 | friend class RedRelayServer; 69 | private: 70 | static sf::TcpSocket defsocket; 71 | 72 | char buffer[65536]; 73 | uint32_t packetsize=0; 74 | uint32_t buffbegin=0; 75 | sf::TcpSocket* Socket=&defsocket; 76 | uint32_t IpAddr=0; 77 | uint16_t UdpPort=0; 78 | uint8_t PingTries=0; 79 | std::string Name; 80 | std::vector Channels; //Channels used by peer, represented as ID 81 | 82 | uint32_t MessageSize() const; 83 | uint8_t SizeOffset() const; 84 | bool MessageReady() const; 85 | void EraseChannel(uint16_t ChannelID); 86 | void AddChannel(uint16_t ChannelID); 87 | 88 | public: 89 | std::string GetName() const; 90 | const std::vector& GetJoinedChannels() const; 91 | sf::IpAddress GetIP() const; 92 | bool IsInChannel(uint16_t ChannelID) const; 93 | }; 94 | 95 | class Channel{ 96 | friend class RedRelayServer; 97 | private: 98 | std::string Name; 99 | std::vector Peers; //Peers in channel, represented as ID 100 | bool HideFromList=false, CloseOnLeave=false; //Channel flags 101 | uint16_t Master; //Channel master ID 102 | 103 | void ErasePeer(uint16_t PeerID); 104 | void AddPeer(uint16_t PeerID); 105 | public: 106 | std::string GetName() const; 107 | bool IsHidden() const; 108 | bool IsAutoClosed() const; 109 | const std::vector& GetPeerList() const; 110 | uint16_t GetPeersCount() const; 111 | uint16_t GetMasterID() const; 112 | bool HasPeer(uint16_t PeerID) const; 113 | }; 114 | 115 | class Connection{ //Used for clients before handshake 116 | friend class RedRelayServer; 117 | private: 118 | sf::TcpSocket* Socket=NULL; 119 | std::size_t received=0; 120 | char buffer[14]; 121 | }; 122 | 123 | class RedRelayServer{ 124 | private: 125 | struct callstruct{ 126 | void (*Error)(const std::string& ErrorMessage); 127 | void (*ServerStart)(uint16_t Port); 128 | bool (*PeerConnect)(uint16_t PeerID, const sf::IpAddress& Address, std::string& DenyReason); 129 | void (*PeerDisconnect)(uint16_t PeerID); 130 | bool (*NameSet)(uint16_t PeerID, std::string& Name, std::string& DenyReason); 131 | bool (*ChannelJoin)(uint16_t PeerID, uint16_t ChannelID, std::string& DenyReason); 132 | bool (*ChannelLeave)(uint16_t PeerID, uint16_t ChannelID, std::string& DenyReason); 133 | void (*ChannelClosed)(uint16_t ChannelID); 134 | bool (*ChannelsListRequest)(uint16_t PeerID, std::string& DenyReason); 135 | void (*ServerMessageSent)(uint16_t PeerID, uint8_t Subchannel, const char* Packet, std::size_t Size); 136 | void (*ServerMessageBlast)(uint16_t PeerID, uint8_t Subchannel, const char* Packet, std::size_t Size); 137 | }; 138 | callstruct Callbacks; 139 | 140 | //Server configuration 141 | uint16_t ConnectionsLimit, PeersLimit, ChannelsLimit, PeerChannelsLimit; 142 | bool GiveNewMaster, LoggingEnabled; 143 | uint8_t PingInterval; 144 | std::string WelcomeMessage; 145 | #ifdef REDRELAY_MULTITHREAD 146 | volatile bool Running, Destructible; 147 | #else 148 | bool Running, Destructible; 149 | #endif 150 | 151 | //Packet buffer 152 | RelayPacket packet; 153 | char UdpBuffer[65536]; 154 | 155 | //Data containers for peers, channels 156 | std::unordered_map ChannelNames; 157 | IndexedPool ConnectionsPool; 158 | IndexedPool PeersPool; 159 | IndexedPool ChannelsPool; 160 | 161 | //Network interfaces 162 | sf::TcpListener TcpListener; 163 | sf::UdpSocket UdpSocket; 164 | #ifdef REDRELAY_EPOLL 165 | EpollSelector Selector; 166 | #else 167 | sf::SocketSelector Selector; 168 | #endif 169 | 170 | #ifdef REDRELAY_MULTITHREAD 171 | void UdpHandler(); 172 | #endif 173 | 174 | //Timers 175 | sf::Clock DeltaClock; 176 | float DeltaTime(); 177 | float Timer(); 178 | 179 | //Peers and connections related stuff 180 | void DropConnection(uint16_t ID); 181 | void DenyConnection(uint16_t ID, const std::string& Reason); 182 | void DenyNameChange(uint16_t ID, const std::string& Name, const std::string& Reason); 183 | void DenyChannelJoin(uint16_t ID, const std::string& Name, const std::string& Reason); 184 | void PeerLeftChannel(uint16_t Channel, uint16_t Peer); 185 | void PeerDroppedFromChannel(uint16_t Channel, uint16_t Peer); 186 | 187 | //Handling messages 188 | void HandleTCP(uint16_t ID, char* Msg, std::size_t Size, uint8_t Type); 189 | void NewConnection(); 190 | void ReceiveUdp(); 191 | void ReceiveTcp(uint16_t PeerID); 192 | void HandleConnection(uint16_t ConnectionID); 193 | public: 194 | RedRelayServer(); 195 | ~RedRelayServer(); 196 | std::string GetVersion() const; 197 | void Log(std::string message, uint8_t colour=15); 198 | void SetPingInterval(uint8_t Interval); 199 | void SetConnectionsLimit(uint16_t Limit); 200 | void SetPeersLimit(uint16_t Limit); 201 | void SetChannelsLimit(uint16_t Limit); 202 | void SetChannelsPerPeerLimit(uint16_t Limit); 203 | void SetWelcomeMessage(const std::string& String); 204 | void SetLogEnabled(bool Flag); 205 | const Peer& GetPeer(uint16_t PeerID); 206 | const Channel& GetChannel(uint16_t ChannelID); 207 | void SetErrorCallback(void(*Error)(const std::string& ErrorMessage)); 208 | void SetStartCallback(void(*ServerStarted)(uint16_t)); 209 | void SetConnectCallback(bool(*PeerConnect)(uint16_t, const sf::IpAddress&, std::string&)); 210 | void SetDisconnectCallback(void(*DisconnectCallback)(uint16_t)); 211 | void SetNameCallback(bool(*NameSet)(uint16_t, std::string&, std::string&)); 212 | void SetChannelJoinCallback(bool(*ChannelJoin)(uint16_t, uint16_t, std::string&)); 213 | void SetChannelLeaveCallback(bool(*ChannelLeave)(uint16_t, uint16_t, std::string&)); 214 | void SetChannelClosedCallback(void(*ChannelClosed)(uint16_t)); 215 | void SetChannelsListRequestCallback(bool(*ChannelsListRequest)(uint16_t, std::string&)); 216 | void SetServerSentCallback(void(*ServerMessageSent)(uint16_t, uint8_t, const char*, std::size_t)); 217 | void SetServerBlastCallback(void(*ServerMessageBlast)(uint16_t, uint8_t, const char*, std::size_t)); 218 | void DropPeer(uint16_t ID); 219 | void Start(uint16_t Port=6121); 220 | void Stop(bool Block=false); 221 | bool IsRunning(); 222 | }; 223 | 224 | } 225 | #endif 226 | -------------------------------------------------------------------------------- /server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.2) 2 | 3 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 4 | message(STATUS "Setting build type to Release as none was specified.") 5 | set(CMAKE_BUILD_TYPE "Release" CACHE 6 | STRING "Choose the type of build." FORCE) 7 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 8 | "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 9 | endif() 10 | 11 | set(CMAKE_CXX_FLAGS "-std=c++11" CACHE STRING "Flags used by the CXX compiler during all build types." FORCE) 12 | 13 | macro(set_option var default type docstring) 14 | if(NOT DEFINED ${var}) 15 | set(${var} ${default}) 16 | endif() 17 | set(${var} ${${var}} CACHE ${type} ${docstring} FORCE) 18 | endmacro() 19 | 20 | set_option(REDRELAY_EXECUTABLE TRUE BOOL "Build RedRelay Server as executable, otherwise only library will be built") 21 | set_option(REDRELAY_EPOLL TRUE BOOL "Build RedRelay Server with epoll/kqueue/IOCP support") 22 | set_option(REDRELAY_MULTITHREAD FALSE BOOL "Build RedRelay Server with UDP multi-threading") 23 | set_option(SFML_FORCE_STATIC FALSE BOOL "Force building SFML from deps instead of using a pre-installed lib") 24 | 25 | project(RedRelayServer VERSION 9) 26 | 27 | if (NOT SFML_FORCE_STATIC) 28 | find_package(SFML 2.5 COMPONENTS network) 29 | endif() 30 | if (NOT SFML_FOUND AND NOT SFML_FORCE_STATIC) 31 | message(STATUS "SFML not found. Proceeding to build a minimal version from ../deps") 32 | endif() 33 | if (SFML_FORCE_STATIC) 34 | message(STATUS "Forced to build a minimal version of SFML from ../deps") 35 | endif() 36 | if (NOT SFML_FOUND OR SFML_FORCE_STATIC) 37 | add_definitions(-DSFML_STATIC) 38 | include_directories(../deps) 39 | list (APPEND REDRELAY_SOURCES ../deps/SFML/Err.cpp ../deps/SFML/Time.cpp ../deps/SFML/Sleep.cpp ../deps/SFML/Clock.cpp ../deps/SFML/Lock.cpp ../deps/SFML/Mutex.cpp 40 | ../deps/SFML/IpAddress.cpp ../deps/SFML/Socket.cpp ../deps/SFML/SocketSelector.cpp ../deps/SFML/TcpListener.cpp ../deps/SFML/TcpSocket.cpp ../deps/SFML/UdpSocket.cpp) 41 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 42 | list (APPEND REDRELAY_SOURCES ../deps/SFML/Win32ClockImpl.cpp ../deps/SFML/Win32MutexImpl.cpp ../deps/SFML/Win32SleepImpl.cpp ../deps/SFML/Win32SocketImpl.cpp) 43 | else() 44 | list (APPEND REDRELAY_SOURCES ../deps/SFML/UnixClockImpl.cpp ../deps/SFML/UnixMutexImpl.cpp ../deps/SFML/UnixSleepImpl.cpp ../deps/SFML/UnixSocketImpl.cpp) 45 | endif() 46 | endif() 47 | 48 | if (REDRELAY_EPOLL) 49 | add_definitions(-DREDRELAY_EPOLL) 50 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 51 | message(STATUS "Extended polling on Windows requires libwepoll, added to build list") 52 | include_directories(../deps) 53 | list (APPEND REDRELAY_SOURCES ../deps/wepoll.c) 54 | endif() 55 | list (APPEND REDRELAY_SOURCES EpollSelector.cpp) 56 | endif() 57 | 58 | if (REDRELAY_MULTITHREAD) 59 | message(STATUS "Warning: multi-threading in RedRelay wasn't extensively tested, use at your own risk") 60 | add_definitions(-DREDRELAY_MULTITHREAD) 61 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 62 | list (APPEND REDRELAY_LIBS pthread) 63 | endif() 64 | endif() 65 | 66 | add_library(redrelay-server STATIC ${REDRELAY_SOURCES} RedRelayServer.cpp Channel.cpp RelayPacket.cpp) 67 | 68 | if (REDRELAY_EXECUTABLE) 69 | add_executable(RedRelayServer Main.cpp) 70 | 71 | if (SFML_FOUND AND NOT SFML_FORCE_STATIC) 72 | list (APPEND REDRELAY_LIBS sfml-network sfml-system) 73 | endif() 74 | 75 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 76 | list (APPEND REDRELAY_LIBS winmm ws2_32) 77 | if(${CMAKE_BUILD_TYPE} STREQUAL "Release") 78 | set (LINKERFLAGS "${LINKERFLAGS} -static") 79 | endif() 80 | endif() 81 | 82 | if(${CMAKE_BUILD_TYPE} STREQUAL "Release") 83 | set (LINKERFLAGS "${LINKERFLAGS} -s") 84 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 85 | set (LINKERFLAGS "${LINKERFLAGS} -flto") 86 | endif() 87 | endif() 88 | 89 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${LINKERFLAGS} CACHE STRING "Flags used by the linker during RELEASE builds." FORCE) 90 | 91 | target_link_libraries(RedRelayServer PUBLIC redrelay-server ${REDRELAY_LIBS}) 92 | endif() 93 | -------------------------------------------------------------------------------- /server/Channel.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // RedRelay - a Lacewing Relay protocol reimplementation 4 | // Copyright (c) 2019 LekKit (LekKit#4400 in Discord) 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source distribution. 21 | // 22 | //////////////////////////////////////////////////////////// 23 | 24 | #include "RedRelayServer.hpp" 25 | 26 | namespace rs{ 27 | 28 | ///////////// 29 | // Channel // 30 | ///////////// 31 | 32 | std::string Channel::GetName() const { 33 | return Name; 34 | } 35 | 36 | bool Channel::IsHidden() const { 37 | return HideFromList; 38 | } 39 | 40 | bool Channel::IsAutoClosed() const { 41 | return CloseOnLeave; 42 | } 43 | 44 | const std::vector& Channel::GetPeerList() const { 45 | return Peers; 46 | } 47 | 48 | uint16_t Channel::GetPeersCount() const { 49 | return Peers.size(); 50 | } 51 | 52 | uint16_t Channel::GetMasterID() const { 53 | return Master; 54 | } 55 | 56 | bool Channel::HasPeer(uint16_t PeerID) const { 57 | for (uint16_t peer : Peers) if (peer == PeerID) return true; 58 | return false; 59 | } 60 | 61 | void Channel::ErasePeer(uint16_t PeerID){ 62 | for (uint32_t i=0; i1 && (uint8_t)buffer[buffbegin+1]<254) return (uint8_t)buffer[buffbegin+1]; 75 | if (packetsize>3 && (uint8_t)buffer[buffbegin+1]==254) return (uint8_t)buffer[buffbegin+2] | (uint8_t)buffer[buffbegin+3]<<8; 76 | if (packetsize>5) return (uint8_t)buffer[buffbegin+2] | (uint8_t)buffer[buffbegin+3]<<8 | (uint8_t)buffer[buffbegin+4]<<16 | (uint8_t)buffer[buffbegin+5]<<24; 77 | return 65535; 78 | } 79 | uint8_t Peer::SizeOffset() const { 80 | if (packetsize<2) return 0; 81 | if ((uint8_t)buffer[buffbegin+1]<254) return 1; 82 | if ((uint8_t)buffer[buffbegin+1]==254) return 3; 83 | return 5; 84 | } 85 | bool Peer::MessageReady() const { 86 | return MessageSize()+SizeOffset()& Peer::GetJoinedChannels() const { 94 | return Channels; 95 | } 96 | 97 | sf::IpAddress Peer::GetIP() const { 98 | return Socket->getRemoteAddress(); 99 | } 100 | 101 | bool Peer::IsInChannel(uint16_t ChannelID) const { 102 | for (uint16_t channel : Channels) if (channel == ChannelID) return true; 103 | return false; 104 | } 105 | 106 | void Peer::EraseChannel(uint16_t ChannelID){ 107 | for (uint32_t i=0; i 6 | HANDLE ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 7 | 8 | #else 9 | 10 | std::string ConsoleColors[]={"\033[0;30m", 11 | "\033[0;34m", 12 | "\033[0;32m", 13 | "\033[0;36m", 14 | "\033[0;31m", 15 | "\035[0;31m", 16 | "\033[0;33m", 17 | "\033[0;37m", 18 | "\033[1;30m", 19 | "\033[1;34m", 20 | "\033[1;32m", 21 | "\033[1;36m", 22 | "\033[1;31m", 23 | "\035[1;31m", 24 | "\033[1;33m", 25 | "\033[1;37m"}; 26 | 27 | #endif 28 | 29 | inline void ChangeConsoleColor(uint8_t color){ 30 | #ifdef _WIN32 31 | SetConsoleTextAttribute(ConsoleHandle, color); 32 | #else 33 | std::cout< 25 | #include "ModSocket.hpp" 26 | #include "EpollSelector.hpp" 27 | 28 | EpollSelector::EpollSelector(std::size_t Size){ 29 | maxevents = Size; 30 | events = new epoll_event[Size]; 31 | #ifdef KQUEUE 32 | epoll_fd = kqueue(); 33 | #else 34 | epoll_fd = epoll_create(64); 35 | #endif 36 | if (epoll_fd==INVAL_FD) std::cout<<"Failed to create epoll descriptor"< 33 | #include 34 | #define epoll_close(fd) close(fd) 35 | typedef int epolld; 36 | #define INVAL_FD -1 37 | #elif defined(_WIN32) 38 | #include "wepoll.h" 39 | typedef HANDLE epolld; 40 | #define INVAL_FD NULL 41 | #elif defined(KQUEUE) 42 | #include 43 | #include 44 | #include 45 | #define epoll_close(fd) close(fd) 46 | typedef struct kevent epoll_event; 47 | typedef int epolld; 48 | #define INVAL_FD -1 49 | #else 50 | #error Extended polling not supported on target platform 51 | #endif 52 | 53 | class EpollSelector{ 54 | private: 55 | std::size_t maxevents; 56 | epolld epoll_fd; 57 | epoll_event* events; 58 | public: 59 | EpollSelector(std::size_t Size=1024); 60 | ~EpollSelector(); 61 | void add(const sf::Socket& sock, uint32_t id); 62 | void remove(const sf::Socket& sock); 63 | void mod(const sf::Socket& sock, uint32_t id); 64 | int wait(int timeout=-1); 65 | uint32_t at(uint32_t index) const; 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /server/IDPool.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // RedRelay - a Lacewing Relay protocol reimplementation 4 | // Copyright (c) 2019 LekKit (LekKit#4400 in Discord) 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source distribution. 21 | // 22 | //////////////////////////////////////////////////////////// 23 | 24 | #ifndef REDRELAY_ID_POOL 25 | #define REDRELAY_ID_POOL 26 | 27 | #include 28 | #include 29 | 30 | namespace rs{ 31 | 32 | //Pool iterator 33 | template 34 | class IndexedElement{ 35 | public: 36 | unsigned int index=0; 37 | T* element=NULL; 38 | }; 39 | 40 | 41 | 42 | template 43 | class IndexedPool{ 44 | public: 45 | ~IndexedPool(){ 46 | Clear(); 47 | } 48 | 49 | bool AutoScale=true; //If our vector is too small, creates empty cells to prevent "out of range" 50 | 51 | T& operator[](unsigned int index){ 52 | if (index>=m_pool.size() || m_pool.at(index)==NULL){ //If requested element doesn't exist, returns empty type to prevent segmentation fault 53 | std::cout<<"SEGFAULT prevented in pool "<=m_pool.size()) m_pool.push_back(NULL); 63 | return m_pool.at(index); 64 | } 65 | 66 | std::size_t Size() const { 67 | return m_allocated.size(); 68 | } 69 | 70 | std::vector>& GetAllocated(){ //Get all our allocated elements 71 | return m_allocated; 72 | } 73 | 74 | bool Allocated(unsigned int index) const { //Check if specified ID is busy 75 | return !(index>=m_pool.size() || m_pool.at(index)==NULL); 76 | } 77 | 78 | void Allocate(unsigned int index){ //Allocate element with given ID 79 | if (AutoScale) while (index>=m_pool.size()) m_pool.push_back(NULL); 80 | if (m_pool.at(index)==NULL){ //Only if our ID isn't busy already 81 | m_pool.at(index)=new T; 82 | IndexedElement IndexedElement; 83 | IndexedElement.index = index; 84 | IndexedElement.element = m_pool.at(index); 85 | m_allocated.push_back(IndexedElement); 86 | } 87 | } 88 | 89 | void Deallocate(unsigned int index){ //Destroy element at given ID 90 | if (index m_pool; 106 | std::vector> m_allocated; 107 | T emptytype; 108 | }; 109 | 110 | } 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /server/Main.cpp: -------------------------------------------------------------------------------- 1 | //Example RedRelay server 2 | #include "RedRelayServer.hpp" 3 | #include 4 | #include 5 | 6 | rs::RedRelayServer& Server = *new rs::RedRelayServer; 7 | std::fstream config; 8 | uint16_t Port = 6121; 9 | bool PortSet = false, 10 | PingIntervalSet = false, 11 | LogEnabledSet = false, 12 | ConnectionsLimitSet = false, 13 | PeersLimitSet = false, 14 | ChannelsLimitSet = false, 15 | ChannelsPerPeerLimitSet = false; 16 | 17 | bool LoadConfig(){ 18 | config.open("redrelay.cfg", std::fstream::out | std::fstream::in); 19 | if (!config.is_open()){ 20 | std::ofstream tmp("redrelay.cfg"); 21 | if (!tmp.is_open()){ 22 | Server.Log("Could not create config file", 4); 23 | return false; 24 | } 25 | tmp<<"#RedRelay Server configuration file\n\ 26 | \n\ 27 | #Server port\n\ 28 | Port = 6121\n\ 29 | \n\ 30 | #Keepalive ping interval (in seconds)\n\ 31 | #Set to 0 to disable\n\ 32 | PingInterval = 3\n\ 33 | \n\ 34 | #Logging\n\ 35 | LogEnabled = true\n\ 36 | \n\ 37 | #Limits unauthorised connections\n\ 38 | ConnectionsLimit = 16\n\ 39 | \n\ 40 | #Limits the peers count on the server\n\ 41 | PeersLimit = 128\n\ 42 | \n\ 43 | #Limits channels count (including hidden channels)\n\ 44 | ChannelsLimit = 32\n\ 45 | \n\ 46 | #Limits channels in which peer can be at once\n\ 47 | ChannelsPerPeerLimit = 4\n\ 48 | \n\ 49 | #WelcomeMessage = \"\""; 50 | tmp.close(); 51 | config.open("redrelay.cfg", std::fstream::out | std::fstream::in); 52 | } 53 | return true; 54 | } 55 | 56 | void SetProp(const std::string& PropName, const std::string& PropVal){ 57 | //std::cout<<"SetProp: "<>tmp; 118 | PropVal+=tmp; 119 | } 120 | if (PropVal.length()>1) SetProp(PropName, PropVal.substr(1, PropVal.length()-2)); 121 | } else SetProp(PropName, PropVal); 122 | } 123 | } 124 | } 125 | config.clear(); 126 | if (!PortSet) config<<"\nPort = 6121"; 127 | if (!PingIntervalSet) config<<"\nPingInterval = 3"; 128 | if (!LogEnabledSet) config<<"\nLogEnabled = true"; 129 | if (!ConnectionsLimitSet) config<<"\nConnectionsLimit = 16"; 130 | if (!PeersLimitSet) config<<"\nPeersLimit = 128"; 131 | if (!ChannelsLimitSet) config<<"\nChannelsLimit = 32"; 132 | if (!ChannelsPerPeerLimitSet) config<<"\nChannelsPerPeerLimit = 4"; 133 | config.close(); 134 | } 135 | 136 | signal(SIGINT, sig_handler); 137 | while (running){ //In case of failure, retry every 5s 138 | Server.Start(Port); 139 | if (running) sf::sleep(sf::seconds(5)); 140 | } 141 | 142 | return 0; 143 | } 144 | -------------------------------------------------------------------------------- /server/Platform.hpp: -------------------------------------------------------------------------------- 1 | //Platform identification tool 2 | 3 | #ifndef PLATFORM_IDENTIFIER 4 | #define PLATFORM_IDENTIFIER 5 | 6 | #if defined(__amd64__) || defined(__x86_64__) || defined(__amd64) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) 7 | #define ARCHITECTURE "x86_64" 8 | #elif defined(__i386__) || defined(_M_X86) || defined(_M_IX86) 9 | #define ARCHITECTURE "x86" 10 | #elif defined(__ARM_ARCH_7__) 11 | #define ARCHITECTURE "ARMv7" 12 | #elif defined(__arm__) || defined(_M_ARM) 13 | #define ARCHITECTURE "ARMv6" 14 | #endif 15 | 16 | #if defined(__linux__) 17 | #define OPERATING_SYSTEM "Linux" 18 | #elif defined(_WIN32) 19 | #define OPERATING_SYSTEM "Windows" 20 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 21 | #define OPERATING_SYSTEM "BSD" 22 | #elif defined(__APPLE__) 23 | #define OPERATING_SYSTEM "Mac OS" 24 | #endif 25 | 26 | #ifndef ARCHITECTURE 27 | #define ARCHITECTURE "Unknown" 28 | #endif 29 | 30 | #ifndef OPERATING_SYSTEM 31 | #define OPERATING_SYSTEM "Unknown" 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /server/RelayPacket.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // RedRelay - a Lacewing Relay protocol reimplementation 4 | // Copyright (c) 2019 LekKit (LekKit#4400 in Discord) 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source distribution. 21 | // 22 | //////////////////////////////////////////////////////////// 23 | 24 | #include "RedRelayServer.hpp" 25 | #include 26 | 27 | namespace rs{ 28 | 29 | RelayPacket::RelayPacket(std::size_t Size){ 30 | size=0; 31 | type=0; 32 | capacity=Size; 33 | buffer = new char[Size]; 34 | } 35 | 36 | RelayPacket::~RelayPacket(){ 37 | delete[] buffer; 38 | } 39 | 40 | void RelayPacket::Reallocate(std::size_t newcapacity){ 41 | if (newcapacity<=size+6 || newcapacity==capacity) return; 42 | char* tmp = new char[newcapacity]; 43 | memcpy(&tmp[6], &buffer[6], size); 44 | delete[] buffer; 45 | capacity = newcapacity; 46 | buffer = tmp; 47 | } 48 | 49 | void RelayPacket::SetType(const uint8_t Type){ 50 | type=Type<<4; 51 | } 52 | 53 | void RelayPacket::AddByte(const uint8_t Byte){ 54 | while (size+6+1>capacity) Reallocate(capacity*2); 55 | buffer[6+size++]=Byte; 56 | } 57 | 58 | void RelayPacket::AddShort(const uint16_t Short){ 59 | while (size+6+2>capacity) Reallocate(capacity*2); 60 | buffer[6+size++]=Short&255; 61 | buffer[6+size++]=(Short>>8)&255; 62 | } 63 | 64 | void RelayPacket::AddInt(const uint32_t Int){ 65 | while (size+6+4>capacity) Reallocate(capacity*2); 66 | buffer[6+size++]=Int&255; 67 | buffer[6+size++]=(Int>>8)&255; 68 | buffer[6+size++]=(Int>>16)&255; 69 | buffer[6+size++]=(Int>>24)&255; 70 | } 71 | 72 | void RelayPacket::AddString(const std::string& String){ 73 | while (size+6+String.length()>capacity) Reallocate(capacity*2); 74 | memcpy(&buffer[6+size], String.c_str(), String.length()); 75 | size+=String.length(); 76 | } 77 | 78 | const char* RelayPacket::GetPacket(){ 79 | if (size<254){ 80 | buffer[4]=type; 81 | buffer[5]=size&255; 82 | return &buffer[4]; 83 | } else if (size<65535){ 84 | buffer[2]=type; 85 | buffer[3]=(uint8_t)254; 86 | buffer[4]=size&255; 87 | buffer[5]=(size>>8)&255; 88 | return &buffer[2]; 89 | } else { 90 | buffer[0]=type; 91 | buffer[1]=(uint8_t)254; 92 | buffer[2]=size&255; 93 | buffer[3]=(size>>8)&255; 94 | buffer[4]=(size>>16)&255; 95 | buffer[5]=(size>>24)&255; 96 | return &buffer[0]; 97 | } 98 | } 99 | 100 | std::size_t RelayPacket::GetPacketSize() const { 101 | if (size<254){ 102 | return 2+size; 103 | } else if (size<65535){ 104 | return 4+size; 105 | } else { 106 | return 6+size; 107 | } 108 | } 109 | 110 | std::size_t RelayPacket::GetSize() const { 111 | return size; 112 | } 113 | 114 | void RelayPacket::Clear(){ 115 | type=0; 116 | size=0; 117 | } 118 | 119 | } --------------------------------------------------------------------------------