live_server.h

main 105 lines · 2.9 KB Raw
Alex Alex Commit Map Editor 18/10/2026 23:40
1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#ifndef _RME_LIVE_SERVER_H_
19#define _RME_LIVE_SERVER_H_
20
21#include "live_socket.h"
22#include "net_connection.h"
23#include "action.h"
24
25class LivePeer;
26class LiveLogTab;
27class QTreeNode;
28
29class LiveServer : public LiveSocket {
30public:
31 LiveServer(Editor& editor);
32 ~LiveServer();
33
34 //
35 bool bind();
36 void close();
37
38 void acceptClient();
39 void removeClient(uint32_t id);
40
41 //
42 void receiveHeader() override { }
43 void receive(uint32_t packetSize) override { }
44 void send(NetworkMessage& message) override { }
45 void sendChat(const wxString& chatMessage) override;
46
47 //
48 void updateCursor(const Position& position) override;
49 void updateClientList() const;
50
51 //
52 LiveLogTab* createLogWindow(wxWindow* parent);
53
54 //
55 uint16_t getPort() const;
56 bool setPort(int32_t newPort);
57
58 Editor* getEditor() const {
59 return editor;
60 }
61
62 uint32_t getFreeClientId();
63 std::string getHostName() const;
64
65 //
66 void broadcastNodes(DirtyList& dirtyList);
67 void broadcastChat(const wxString& speaker, const wxString& chatMessage);
68 void broadcastCursor(const LiveCursor& cursor);
69 void broadcastColorChange(uint32_t clientId, const wxColor& color);
70
71 void startOperation(const wxString& operationMessage);
72 void updateOperation(int32_t percent);
73
74 // Override socket type check
75 bool IsServer() const override { return true; }
76
77 void setUsedColor(const wxColor& color);
78 wxColor getUsedColor() const { return usedColor; }
79
80 const std::unordered_map<uint32_t, LivePeer*>& getClients() const { return clients; }
81
82 // Helper method for writing cursor data to messages
83 void writeCursorToMessage(NetworkMessage& message, const LiveCursor& cursor) {
84 writeCursor(message, cursor);
85 }
86
87protected:
88 std::unordered_map<uint32_t, LivePeer*> clients;
89
90 std::shared_ptr<boost::asio::ip::tcp::acceptor> acceptor;
91 std::shared_ptr<boost::asio::ip::tcp::socket> socket;
92
93 Editor* editor;
94
95 uint32_t clientIds;
96 uint16_t port;
97
98 bool stopped;
99 bool drawingReady; // Flag indicating server is ready for drawing operations
100
101 wxColor usedColor;
102};
103
104#endif
105
Top