Plasma Engine  2.0
Loading...
Searching...
No Matches
Fileserver.h
1#pragma once
2
3#include <FileservePlugin/Fileserver/ClientContext.h>
4#include <Foundation/Communication/RemoteInterface.h>
5#include <Foundation/Configuration/Singleton.h>
6#include <Foundation/Containers/HashTable.h>
7#include <Foundation/Types/UniquePtr.h>
8#include <Foundation/Types/Uuid.h>
9
10class plRemoteMessage;
11
13{
14 enum class Type
15 {
16 None,
17 ServerStarted,
18 ServerStopped,
19 ClientConnected,
20 ClientReconnected, // connected again after a disconnect
21 ClientDisconnected,
22 MountDataDir,
23 MountDataDirFailed,
24 UnmountDataDir,
25 FileDownloadRequest,
26 FileDownloading,
27 FileDownloadFinished,
28 FileDeleteRequest,
29 FileUploadRequest,
30 FileUploading,
31 FileUploadFinished,
32 AreYouThereRequest,
33 LogCustomActivity,
34 };
35
36 Type m_Type = Type::None;
37 plUInt32 m_uiClientID = 0;
38 const char* m_szName = nullptr;
39 const char* m_szPath = nullptr;
40 const char* m_szRedirectedPath = nullptr;
41 plUInt32 m_uiSizeTotal = 0;
42 plUInt32 m_uiSentTotal = 0;
43 plFileserveFileState m_FileState = plFileserveFileState::None;
44};
45
58class PL_FILESERVEPLUGIN_DLL plFileserver
59{
60 PL_DECLARE_SINGLETON(plFileserver);
61
62public:
64
66 void StartServer();
67
69 void StopServer();
70
72 bool UpdateServer();
73
75 bool IsServerRunning() const;
76
78 void SetPort(plUInt16 uiPort);
79
82 plUInt16 GetPort() const { return m_uiPort; }
83
86
88 void BroadcastReloadResourcesCommand();
89
90 static plResult SendConnectionInfo(
91 const char* szClientAddress, plUInt16 uiMyPort, const plArrayPtr<plStringBuilder>& myIPs, plTime timeout = plTime::MakeFromSeconds(10));
92
94
95 void SetCustomMessageHandler(plUInt32 uiSystemID, ClientMessageHandler handler);
96
97private:
98 void NetworkEventHandler(const plRemoteEvent& e);
99 plFileserveClientContext& DetermineClient(plRemoteMessage& msg);
100 void NetworkMsgHandler(plRemoteMessage& msg);
101 void UnknownNetworkMsgHandler(plRemoteMessage& msg);
102 void HandleMountRequest(plFileserveClientContext& client, plRemoteMessage& msg);
103 void HandleUnmountRequest(plFileserveClientContext& client, plRemoteMessage& msg);
104 void HandleFileRequest(plFileserveClientContext& client, plRemoteMessage& msg);
105 void HandleDeleteFileRequest(plFileserveClientContext& client, plRemoteMessage& msg);
106 void HandleUploadFileHeader(plFileserveClientContext& client, plRemoteMessage& msg);
107 void HandleUploadFileTransfer(plFileserveClientContext& client, plRemoteMessage& msg);
108 void HandleUploadFileFinished(plFileserveClientContext& client, plRemoteMessage& msg);
109 void LogCustomActivity(const char* szText);
110
113 plDynamicArray<plUInt8> m_SendToClient; // ie. 'downloads' from server to client
114 plDynamicArray<plUInt8> m_SentFromClient; // ie. 'uploads' from client to server
115 plStringBuilder m_sCurFileUpload;
116 plUuid m_FileUploadGuid;
117 plUInt32 m_uiFileUploadSize;
118 plUInt16 m_uiPort = 1042;
119 plMap<plUInt32, ClientMessageHandler> m_CustomMessageHandlers;
120};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition DynamicArray.h:81
Definition Event.h:177
Definition ClientContext.h:18
A file server allows to serve files from a host PC to another process that is potentially on another ...
Definition Fileserver.h:59
plUInt16 GetPort() const
Returns the currently set port. If the command line option "-fs_port X" was used, this will return th...
Definition Fileserver.h:82
plEvent< const plFileserverEvent & > m_Events
The server broadcasts events about its activity.
Definition Fileserver.h:85
Definition HashTable.h:333
Definition Map.h:408
Definition RemoteInterface.h:60
Encapsulates all the data that is transmitted when sending or receiving a message with plRemoteInterf...
Definition RemoteMessage.h:11
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
Definition Fileserver.h:13
Event type for connections.
Definition RemoteInterface.h:33
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE static constexpr plTime MakeFromSeconds(double fSeconds)
Creates an instance of plTime that was initialized from seconds.
Definition Time.h:30