diff --git a/source/ps/Network/AllNetMessages.h b/source/ps/Network/AllNetMessages.h index 548fa2b931..0d8d94ec58 100755 --- a/source/ps/Network/AllNetMessages.h +++ b/source/ps/Network/AllNetMessages.h @@ -111,6 +111,11 @@ START_NMT_CLASS_(ServerHandshakeResponse) NMT_FIELD(CStr, m_Message) END_NMT_CLASS() +START_NMT_CLASS_(Result) + NMT_FIELD_INT(m_Code, u32, 4) + NMT_FIELD(CStr, m_Message) +END_NMT_CLASS() + START_NMT_CLASS_(Authenticate) NMT_FIELD(CStr, m_Nick) //NMT_FIELD(CPasswordHash, m_Password) @@ -129,7 +134,7 @@ START_NMT_CLASS_(PlayerConnect) NMT_END_ARRAY() END_NMT_CLASS() -#include "../EventTypes.h" +// #include "../EventTypes.h" END_NMTS() diff --git a/source/ps/Network/NMTCreator.h b/source/ps/Network/NMTCreator.h index dbaf064f02..4d2074a623 100755 --- a/source/ps/Network/NMTCreator.h +++ b/source/ps/Network/NMTCreator.h @@ -103,7 +103,7 @@ uint _nm::GetSerializedLength() const \ const _nm *thiz=this; #define NMT_START_ARRAY(_nm) \ - vector ::const_iterator it=_nm.begin(); \ + std::vector ::const_iterator it=_nm.begin(); \ while (it != _nm.end()) \ { \ const ARRAY_STRUCT_PREFIX##_nm *thiz=&*it; @@ -141,7 +141,7 @@ u8 *_nm::Serialize(u8 *buffer) const \ const _nm *thiz=this; #define NMT_START_ARRAY(_nm) \ - vector ::const_iterator it=_nm.begin(); \ + std::vector ::const_iterator it=_nm.begin(); \ while (it != _nm.end()) \ { \ const ARRAY_STRUCT_PREFIX##_nm *thiz=&*it; diff --git a/source/ps/Network/NetMessage.cpp b/source/ps/Network/NetMessage.cpp index 5ad46f1366..c3ffd0bc5c 100755 --- a/source/ps/Network/NetMessage.cpp +++ b/source/ps/Network/NetMessage.cpp @@ -1,6 +1,7 @@ +#include "precompiled.h" + #include "posix.h" #include "lib.h" -#include "misc.h" #include #define ALLNETMSGS_IMPLEMENT diff --git a/source/ps/Network/Network.cpp b/source/ps/Network/Network.cpp index 4cdf488231..4373a342f0 100755 --- a/source/ps/Network/Network.cpp +++ b/source/ps/Network/Network.cpp @@ -1,3 +1,5 @@ +#include "precompiled.h" + #include "Network.h" #include "Serialization.h" #include diff --git a/source/ps/Network/NetworkInternal.h b/source/ps/Network/NetworkInternal.h index 676bd02c91..da23d5c60e 100755 --- a/source/ps/Network/NetworkInternal.h +++ b/source/ps/Network/NetworkInternal.h @@ -12,8 +12,6 @@ #define closesocket(_fd) close(_fd) #else -#include "sysdep/win/win_internal.h" - #define Network_GetErrorString(_error, _buf, _buflen) \ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, _error+WSABASEERR, 0, _buf, _buflen, NULL) #define Network_LastError (WSAGetLastError() - WSABASEERR) @@ -74,7 +72,7 @@ struct CSocketSetInternal pthread_mutex_t m_Mutex; pthread_t m_Thread; - std::map m_HandleMap; + std::map m_HandleMap; #ifdef _WIN32 HWND m_hWnd; #else diff --git a/source/ps/Network/ServerSocket.cpp b/source/ps/Network/ServerSocket.cpp index ba6668e726..d01f978987 100755 --- a/source/ps/Network/ServerSocket.cpp +++ b/source/ps/Network/ServerSocket.cpp @@ -1,3 +1,5 @@ +#include "precompiled.h" + #include "Network.h" CServerSocket::~CServerSocket() diff --git a/source/ps/Network/SocketBase.cpp b/source/ps/Network/SocketBase.cpp index 9cb0ce57ea..126541fb82 100755 --- a/source/ps/Network/SocketBase.cpp +++ b/source/ps/Network/SocketBase.cpp @@ -1,3 +1,6 @@ +#include "precompiled.h" +#include "sysdep/win/win_internal.h" + #include "Network.h" #include "NetworkInternal.h" @@ -57,6 +60,25 @@ CSocketAddress::CSocketAddress(int port, ESocketProtocol proto) } } +CSocketAddress CSocketAddress::Loopback(int port, ESocketProtocol proto) +{ + CSocketAddress ret; + switch (proto) + { + case IPv4: + ret.m_Union.m_IPv4.sin_family=PF_INET; + ret.m_Union.m_IPv4.sin_addr.s_addr=htonl(INADDR_LOOPBACK); + ret.m_Union.m_IPv4.sin_port=htons(port); + break; + case IPv6: + ret.m_Union.m_IPv6.sin6_family=PF_INET6; + memcpy(&ret.m_Union.m_IPv6.sin6_addr, &in6addr_loopback, sizeof(in6addr_loopback)); + ret.m_Union.m_IPv6.sin6_port=htons(port); + break; + } + return ret; +} + PS_RESULT CSocketAddress::Resolve(const char *name, int port, CSocketAddress &addr) { if ((getaddrinfo) != NULL) @@ -681,10 +703,10 @@ void WaitLoop_SocketUpdateProc(int fd, int error, uint event) if (error) { PS_RESULT res=GetPS_RESULT(error); - if (res == PS_FAIL) - pSock->OnClose(CONNECTION_BROKEN); pSock->m_Error=res; pSock->m_State=SS_UNCONNECTED; + if (res == PS_FAIL) + pSock->OnClose(CONNECTION_BROKEN); return; } diff --git a/source/ps/Network/SocketBase.h b/source/ps/Network/SocketBase.h index a586354f42..c5411f9d1c 100755 --- a/source/ps/Network/SocketBase.h +++ b/source/ps/Network/SocketBase.h @@ -126,6 +126,12 @@ struct CSocketAddress * Returns the port number part of the address */ int GetPort() const; + + /* + Create an address pointing to the loopback, with the specified port and + protocol. Use this with Bind to only listen on the loopback interface. + */ + static CSocketAddress Loopback(int port, ESocketProtocol proto=IPv4); }; /** diff --git a/source/ps/Network/StreamSocket.cpp b/source/ps/Network/StreamSocket.cpp index fd650975db..1e2c93eb9c 100755 --- a/source/ps/Network/StreamSocket.cpp +++ b/source/ps/Network/StreamSocket.cpp @@ -1,3 +1,5 @@ +#include "precompiled.h" + #include "Network.h" #include "StreamSocket.h"