-- Message reader & writers for SMG Communication Protocol -- This part effectively serializes/deserializes game data structures -- for transmission between client and server. -- Note that messages themeselves are simply arrays of octets. -- (see also raw_types.ads/adb and packing.ads/adb for related parts) -- NB: message ids and padding as per protocol spec are handled HERE ONLY. -- Relies on: -- RNG (for random padding) -- CRC32 (for CRC calculations) -- Raw_Types -- Data_Structs -- S.MG, 2018 with Raw_Types; with RNG; with CRC32; with Data_Structs; use Data_Structs; with Interfaces; package Messages is -- exception raised when given message to read fails sanity checks Invalid_Msg: exception; ------------------------------------------------ -- Writes a Serpent Keyset to the given Serpent Message -- -- Keyset - the set of keys to write to message -- Counter - the message count procedure Write_SKeys_SMsg( Keyset : in Serpent_Keyset; Counter : in Interfaces.Unsigned_16; Msg : out Raw_Types.Serpent_Msg); -- Reads a Serpent Keyset from the given Serpent Message -- The opposite of Write_SKeys_SMsg above -- Raises Invalid_Message exception if given message fails sanity checks procedure Read_SKeys_SMsg( Msg : in Raw_Types.Serpent_Msg; Counter : out Interfaces.Unsigned_16; Keyset : out Serpent_Keyset); private -- if native is little endian, does nothing; -- if native is big endian, it flips the input's octets. -- (strictly for arrays of octets) procedure Cast_LE( LE: in out Raw_Types.Octets ); -- protocol message types IDs, fixed as per protocol specification -- Serpent messages end in "S_Type" -- RSA messages end in "R_Type" -- Character action types end in "A_Type" -- Serpent message types SKeys_S_Type : constant Interfaces.Unsigned_8 := 1; Key_Mgm_S_Type : constant Interfaces.Unsigned_8 := 2; File_Transfer_S_Type : constant Interfaces.Unsigned_8 := 3; File_Req_S_Type : constant Interfaces.Unsigned_8 := 4; Client_Action_S_Type : constant Interfaces.Unsigned_8 := 5; World_Bulletin_S_Type: constant Interfaces.Unsigned_8 := 6; Obj_Request_S_Type : constant Interfaces.Unsigned_8 := 7; Obj_Info_S_Type : constant Interfaces.Unsigned_8 := 8; -- RSA message types RKeys_R_Type : constant Interfaces.Unsigned_8 := 251; SKeys_R_Type : constant Interfaces.Unsigned_8 := 157; Key_Mgm_R_Type : constant Interfaces.Unsigned_8 := 233; -- Character action types Lock_A_Type : constant Interfaces.Unsigned_8 := 0; Make_A_Type : constant Interfaces.Unsigned_8 := 1; Explore_A_Type : constant Interfaces.Unsigned_8 := 2; Exchange_A_Type : constant Interfaces.Unsigned_8 := 3; Attack_A_Type : constant Interfaces.Unsigned_8 := 4; Repair_A_Type : constant Interfaces.Unsigned_8 := 5; Move_A_Type : constant Interfaces.Unsigned_8 := 6; Train_A_Type : constant Interfaces.Unsigned_8 := 7; end Messages;