Class P2PMessage
- Namespace
- SteamNetworkLib.Models
- Assembly
- SteamNetworkLib.dll
Base class for all P2P messages in SteamNetworkLib. Provides common functionality for serialization, deserialization, and message metadata.
public abstract class P2PMessage
- Inheritance
-
P2PMessage
- Derived
- Inherited Members
Constructors
P2PMessage()
Initializes a new instance of the P2PMessage class. Sets the timestamp to the current UTC time.
protected P2PMessage()
Properties
MessageType
Gets the unique identifier for this message type. Must be implemented by derived classes to specify the message type.
public abstract string MessageType { get; }
Property Value
SenderId
Gets or sets the Steam ID of the player who sent this message. This is automatically set when sending messages through the P2P manager.
public CSteamID SenderId { get; set; }
Property Value
- CSteamID
Timestamp
Gets or sets the timestamp when this message was created. Defaults to UTC time when the message instance is created.
public DateTime Timestamp { get; set; }
Property Value
Methods
CreateJsonBase(string)
Helper method to create a JSON representation of basic message properties. Can be extended by derived classes to include their specific properties.
protected string CreateJsonBase(string additionalData = "")
Parameters
additionalData
stringAdditional JSON data to include in the base JSON string.
Returns
- string
A JSON string containing the base message properties and any additional data.
Deserialize(byte[])
Deserializes the message from a byte array received over the network. Must be implemented by derived classes to reconstruct their specific data.
public abstract void Deserialize(byte[] data)
Parameters
data
byte[]The byte array containing the serialized message data.
ExtractJsonValue(string, string)
Simple JSON value extractor that avoids dependencies on external JSON libraries. Handles both quoted strings and unquoted values (numbers, booleans).
protected string ExtractJsonValue(string json, string key)
Parameters
Returns
- string
The extracted value as a string, or an empty string if not found.
ParseJsonBase(string)
Helper method to parse basic message properties from JSON. Should be called by derived classes to populate the base properties.
protected void ParseJsonBase(string json)
Parameters
json
stringThe JSON string to parse.
Serialize()
Serializes the message to a byte array for network transmission. Must be implemented by derived classes to handle their specific data.
public abstract byte[] Serialize()
Returns
- byte[]
A byte array containing the serialized message data.