live_socket.h

main 122 lines · 3.4 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_SOCKET_H_
19#define _RME_LIVE_SOCKET_H_
20
21#include "position.h"
22#include "net_connection.h"
23#include "live_packets.h"
24#include "filehandle.h"
25#include "iomap.h"
26
27#include <memory>
28#include <unordered_map>
29
30class LiveLogTab;
31class Action;
32
33struct LiveCursor {
34 uint32_t id;
35 wxColor color;
36 Position pos;
37};
38
39class LiveSocket {
40public:
41 LiveSocket();
42 virtual ~LiveSocket();
43
44 //
45 wxString getName() const;
46 bool setName(const wxString& newName);
47
48 wxString getPassword() const;
49 bool setPassword(const wxString& newPassword);
50
51 wxString getLastError() const;
52 void setLastError(const wxString& error);
53
54 std::string getHostName() const;
55 std::vector<LiveCursor> getCursorList() const;
56
57 // Check socket type
58 virtual bool IsServer() const { return false; }
59 virtual bool IsClient() const { return false; }
60
61 //
62 void logMessage(const wxString& message);
63
64 //
65 virtual void receiveHeader() = 0;
66 virtual void receive(uint32_t packetSize) = 0;
67 virtual void send(NetworkMessage& message) = 0;
68 virtual void sendChat(const wxString& chatMessage) = 0;
69
70 //
71 virtual void updateCursor(const Position& position) = 0;
72
73 // Helper method to safely get app directory for logging
74 static wxString GetAppDir() {
75 wxString dir;
76 try {
77 dir = wxStandardPaths::Get().GetUserDataDir();
78 if (!wxDirExists(dir)) {
79 wxMkdir(dir);
80 }
81 }
82 catch (...) {
83 dir = "."; // Fallback to current directory
84 }
85 return dir;
86 }
87
88protected:
89 // receive / send methods
90 void receiveNode(NetworkMessage& message, Editor& editor, Action* action, int32_t ndx, int32_t ndy, bool underground);
91 void sendNode(uint32_t clientId, QTreeNode* node, int32_t ndx, int32_t ndy, uint32_t floorMask);
92
93 void receiveFloor(NetworkMessage& message, Editor& editor, Action* action, int32_t ndx, int32_t ndy, int32_t z, QTreeNode* node, Floor* floor);
94 void sendFloor(NetworkMessage& message, Floor* floor);
95
96 void receiveTile(BinaryNode* node, Editor& editor, Action* action, const Position* position);
97 void sendTile(MemoryNodeFileWriteHandle& writer, Tile* tile, const Position* position);
98
99 // read / write types
100 Tile* readTile(BinaryNode* node, Editor& editor, const Position* position);
101
102 LiveCursor readCursor(NetworkMessage& message);
103 void writeCursor(NetworkMessage& message, const LiveCursor& cursor);
104
105 //
106 std::unordered_map<uint32_t, LiveCursor> cursors;
107
108 MemoryNodeFileReadHandle mapReader;
109 MemoryNodeFileWriteHandle mapWriter;
110 VirtualIOMap mapVersion;
111
112 LiveLogTab* log;
113
114 wxString name;
115 wxString password;
116 wxString lastError;
117
118 friend class LiveLogTab;
119};
120
121#endif
122
Top