1 /** 2 Copyright: Copyright (c) 2015-2016 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 netlib.connection; 9 10 void registerPackets(Connection c) 11 { 12 // Server -> Client 13 c.registerPacket!PacketMapPacket; 14 c.registerPacket!LoginPacket; 15 c.registerPacket!SessionInfoPacket; 16 17 // Common 18 c.registerPacket!MessagePacket; 19 20 // Server -> Client 21 c.registerPacket!ClientLoggedInPacket; 22 c.registerPacket!ClientLoggedOutPacket; 23 } 24 25 struct PacketMapPacket 26 { 27 string[] packetNames; 28 } 29 30 // client request 31 struct LoginPacket 32 { 33 string clientName; 34 } 35 36 // server response 37 struct SessionInfoPacket 38 { 39 ClientId yourId; 40 string[ClientId] clientNames; 41 } 42 43 struct ClientLoggedInPacket 44 { 45 ClientId clientId; 46 string clientName; 47 } 48 49 struct ClientLoggedOutPacket 50 { 51 ClientId clientId; 52 } 53 54 // sent from client with peer == 0 and from server with userId of sender. 55 struct MessagePacket 56 { 57 ClientId clientId; // from. Set to 0 when sending from client 58 string msg; 59 }