1 /** 2 Copyright: Copyright (c) 2015-2018 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 module voxelman.net.packets; 7 8 import datadriven : EntityId; 9 10 void registerPackets(Connection)(Connection c) 11 { 12 // Server -> Client 13 c.registerPacket!PacketMapPacket; 14 c.registerPacket!IdMapPacket; 15 c.registerPacket!SessionInfoPacket; 16 17 // Client -> Server 18 c.registerPacket!LoginPacket; 19 c.registerPacket!GameStartPacket; 20 21 // Common 22 c.registerPacket!MessagePacket; 23 24 // Server -> Client 25 c.registerPacket!ClientLoggedInPacket; 26 c.registerPacket!ClientLoggedOutPacket; 27 } 28 29 struct PacketMapPacket 30 { 31 string[] packetNames; 32 } 33 34 struct IdMapPacket 35 { 36 string mapName; 37 string[] names; 38 } 39 40 // client request 41 struct LoginPacket 42 { 43 string clientName; 44 } 45 46 struct GameStartPacket 47 { 48 } 49 50 // server response 51 struct SessionInfoPacket 52 { 53 EntityId yourId; 54 string[EntityId] clientNames; 55 } 56 57 struct ClientLoggedInPacket 58 { 59 EntityId clientId; 60 string clientName; 61 } 62 63 struct ClientLoggedOutPacket 64 { 65 EntityId clientId; 66 } 67 68 enum MessageEndpoint 69 { 70 chat, 71 launcherConsole, 72 integratedConsole, 73 } 74 75 // Where server should send command output depending on client input method 76 MessageEndpoint[4] commandSourceToMsgEndpoint = [ 77 MessageEndpoint.integratedConsole, // <= clientConsole, 78 MessageEndpoint.chat, // <= clientChat, 79 MessageEndpoint.launcherConsole, // <= clientLauncher, 80 MessageEndpoint.integratedConsole // <= localLauncher, shouldn't happen 81 ]; 82 83 // sent from client with peer == 0 and from server with userId of sender. 84 struct MessagePacket 85 { 86 string msg; 87 EntityId clientId; // from. Set to 0 when sending from client 88 MessageEndpoint endpoint; // Where message came from (if from client), or should be sent to (if to client) 89 }