4#include "WebSocketsModule.h"
8#define Log(pmt, ...) UE_LOG(LogMultiplayerWebSocket, Log, TEXT(pmt), ##__VA_ARGS__)
9#define Warn(pmt, ...) UE_LOG(LogMultiplayerWebSocket, Warning, TEXT(pmt), ##__VA_ARGS__)
10#define Error(pmt, ...) UE_LOG(LogMultiplayerWebSocket, Error, TEXT(pmt), ##__VA_ARGS__)
11#define Fatal(pmt, ...) UE_LOG(LogMultiplayerWebSocket, Fatal, TEXT(pmt), ##__VA_ARGS__)
14 bShouldRestartOnBadClose(true),
15 bShouldReplayLastRequestOnBadClose(true)
22 Log(
"MultiplayerWebSocket destructor.");
28 Log(
"MultiplayerWebSocket Disconnect.");
31 Log(
"Disconnecting...");
44 Log(
"Connecting to websocket at %s", *Uri);
55 Log(
"Setting up the socket.");
61 Log(
"WebSocket connect called.");
82 FString JsonString = FString::Format(TEXT(
"{ \"OrgId\": {0}, \"ModuleId\": {1}}"), { FStringFormatArg(OrgId), FStringFormatArg(ModuleId) });
93 if (!&FWebSocketsModule::Get())
98 Socket = FWebSocketsModule::Get().CreateWebSocket(Uri, Protocol);
100 Socket->OnConnected().AddLambda([&]() ->
void {
101 Log(
"WebSocket connected.");
106 Socket->OnConnectionError().AddLambda([&](
const FString&
Error) ->
void {
107 Error(
"Failed to connect with error: %s", *
Error);
112 Socket->OnClosed().AddLambda([&](int32 StatusCode,
const FString& Reason,
bool bWasClean) ->
void {
113 Log(
"Socket closed with status %d, for reason %s", StatusCode, *Reason);
127 Socket->OnMessage().AddLambda([&](
const FString& Message) ->
void {
128 Log(
"Socket received message %s", *Message);
133 Socket->OnRawMessage().AddLambda([&](
const void* Data, SIZE_T Size, SIZE_T BytesRemaining) ->
void {
135 Log(
"A raw message was received of size %d.", Size);
138 Socket->OnMessageSent().AddLambda([&](
const FString& MessageString) ->
void {
139 Log(
"Apex message sent.");
150 switch (NextRequest.RequestType)
158 Error(
"Invalid request type submitted of type %d", NextRequest.RequestType);
DEFINE_LOG_CATEGORY_STATIC(LogMultiplayerWebSocket, Log, All)
MultiplayerRequestData LastWebSocketRequest
void SendData(FString Data)
bool bShouldRestartOnBadClose
FSocketDisconnected SocketDisconnectedEvent
bool bShouldReplayLastRequestOnBadClose
TSharedPtr< IWebSocket > WebSocket
FSocketConnected SocketConnectedEvent
FSocketConnectFailed SocketConnectFailedEvent
void SetupSocket(TSharedPtr< IWebSocket > &Socket, FString Uri, FString Protocol)
TArray< MultiplayerRequestData > PendingWebsocketRequests
FSocketMessageReceived SocketMessageReceivedEvent
void ProcessNextRequest()
void RequestMatchMake(int OrgId, int ModuleId)
bool IsWebsocketConnected()
bool AttemptConnect(FString Uri, FString Protocol="wss")