live_client.h

main 104 lines · 3.1 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_CLIENT_H_
19#define _RME_LIVE_CLIENT_H_
20
21#include "live_socket.h"
22#include "net_connection.h"
23
24#include <set>
25
26class DirtyList;
27class MapTab;
28
29class LiveClient : public LiveSocket {
30public:
31 LiveClient();
32 ~LiveClient();
33
34 //
35 bool connect(const std::string& address, uint16_t port);
36 void tryConnect(boost::asio::ip::tcp::resolver::results_type::iterator endpoint);
37
38 void close();
39 bool handleError(const boost::system::error_code& error);
40
41 //
42 std::string getHostName() const;
43
44 //
45 void receiveHeader() override;
46 void receive(uint32_t packetSize) override;
47 void send(NetworkMessage& message) override;
48 void sendWithoutLogging(NetworkMessage& message); // For cursor updates and other high-frequency events
49
50 //
51 void updateCursor(const Position& position) override;
52
53 LiveLogTab* createLogWindow(wxWindow* parent);
54
55
56 MapTab* createEditorWindow();
57
58 // Override socket type check
59 bool IsClient() const override { return true; }
60
61
62 // send packets
63 void sendHello();
64 void sendNodeRequests();
65 void sendChanges(DirtyList& dirtyList);
66 void sendChat(const wxString& chatMessage) override;
67 void sendReady();
68 void sendColorUpdate(uint32_t targetClientId, const wxColor& color);
69
70 // Flags a node as queried and stores it, need to call SendNodeRequest to send it to server
71 void queryNode(int32_t ndx, int32_t ndy, bool underground);
72
73protected:
74 void parsePacket(NetworkMessage message);
75
76 // parse packets
77 void parseHello(NetworkMessage& message);
78 void parseKick(NetworkMessage& message);
79 void parseClientAccepted(NetworkMessage& message);
80 void parseChangeClientVersion(NetworkMessage& message);
81 void parseServerTalk(NetworkMessage& message);
82 void parseNode(NetworkMessage& message);
83 void parseCursorUpdate(NetworkMessage& message);
84 void parseStartOperation(NetworkMessage& message);
85 void parseUpdateOperation(NetworkMessage& message);
86 void parseColorUpdate(NetworkMessage& message);
87
88 //
89 NetworkMessage readMessage;
90
91 std::set<uint32_t> queryNodeList;
92 wxString currentOperation;
93
94 std::shared_ptr<boost::asio::ip::tcp::resolver> resolver;
95 std::shared_ptr<boost::asio::ip::tcp::socket> socket;
96
97 Editor* editor;
98
99 bool stopped;
100 bool isDrawingReady; // Flag indicating client is ready to handle drawing operations
101};
102
103#endif
104
Top