1 /** 2 Copyright: Copyright (c) 2015-2017 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 // sent from client with peer == 0 and from server with userId of sender. 69 struct MessagePacket 70 { 71 string msg; 72 EntityId clientId; // from. Set to 0 when sending from client 73 }