From 2e7a8b8bda4cef4a661d70b3305ad5267735543e Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:27:04 +0800 Subject: [PATCH] [raknet] Implement `EmailSender::GetResponse()` --- raknet/EmailSender.cpp | 38 ++++++++++++++++++++++++++++++++++++++ raknet/EmailSender.h | 16 ++++++++++++++++ raknet/NetworkTypes.cpp | 9 ++++++++- raknet/NetworkTypes.h | 10 ++++++++-- 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 raknet/EmailSender.cpp create mode 100644 raknet/EmailSender.h diff --git a/raknet/EmailSender.cpp b/raknet/EmailSender.cpp new file mode 100644 index 0000000..9c67707 --- /dev/null +++ b/raknet/EmailSender.cpp @@ -0,0 +1,38 @@ +// TODO: Implement EmailSender.cpp + +#include "EmailSender.h" +#include "TCPInterface.h" +#include "GetTime.h" +#include +#include // strstr + +#include "RakSleep.h" + +char *EmailSender::GetResponse(TCPInterface *tcpInterface, const PlayerID &emailServer, bool doPrintf) +{ + Packet *packet; + RakNetTime timeout; + timeout=RakNet::GetTime()+5000; + while (1) + { + if (tcpInterface->HasLostConnection()==emailServer) + return "Connection to server lost."; + packet = tcpInterface->Receive(); + if (packet) + { + if (doPrintf) + printf("%s", packet->data); + if (strstr((const char*)packet->data, "250")) + return 0; // OK + if (strstr((const char*)packet->data, "354")) + return 0; // OK + if (strstr((const char*)packet->data, "550")) + return "Failed on error code 550"; + if (strstr((const char*)packet->data, "553")) + return "Failed on error code 553"; + } + if (RakNet::GetTime() > timeout) + return "Timed out"; + RakSleep(100); + } +} diff --git a/raknet/EmailSender.h b/raknet/EmailSender.h new file mode 100644 index 0000000..880f57f --- /dev/null +++ b/raknet/EmailSender.h @@ -0,0 +1,16 @@ +// TODO: Implement EmailSender.h + +#ifndef __EMAIL_SENDER_H +#define __EMAIL_SENDER_H + +class TCPInterface; +#include "NetworkTypes.h" + +class EmailSender +{ +public: +protected: + char *GetResponse(TCPInterface *tcpInterface, const PlayerID &emailServer, bool doPrintf); +}; + +#endif diff --git a/raknet/NetworkTypes.cpp b/raknet/NetworkTypes.cpp index 73361a6..83e700e 100644 --- a/raknet/NetworkTypes.cpp +++ b/raknet/NetworkTypes.cpp @@ -1 +1,8 @@ -// TODO: Implement NetworkTypes.cpp \ No newline at end of file +// TODO: Implement NetworkTypes.cpp + +#include "NetworkTypes.h" + +bool PlayerID::operator==( const PlayerID& right ) const +{ + return binaryAddress == right.binaryAddress && port == right.port; +} diff --git a/raknet/NetworkTypes.h b/raknet/NetworkTypes.h index 8e38b74..b69cb0e 100644 --- a/raknet/NetworkTypes.h +++ b/raknet/NetworkTypes.h @@ -17,13 +17,19 @@ typedef long long RakNetTimeNS; /// Corresponds to a network address struct RAK_DLL_EXPORT PlayerID { - char _gap0[6]; + ///The peer address from inet_addr. + unsigned int binaryAddress; + ///The port number + unsigned short port; + + bool operator==( const PlayerID& right ) const; }; /// This represents a user message from another system. struct Packet { - char _gap0; + /// The data from the sender + unsigned char* data; }; struct RPCParameters