Photon Server API Documentation v5.0RC1

Classes | Public Member Functions | Public Attributes | Protected Member Functions | Properties | List of all members
Photon.Hive.HivePeer Class Reference

Inheritance class of PeerBase.
The LitePeer dispatches incoming OperationRequests at OnOperationRequest. When joining a Room a Caching.RoomReference is stored in the RoomReference property. An IFiber guarantees that all outgoing messages (events/operations) are sent one after the other. More...

Inheritance diagram for Photon.Hive.HivePeer:
Photon.SocketServer.ClientPeer Photon.SocketServer.PeerBase Photon.LoadBalancing.GameServer.GameClientPeer

Classes

class  JoinStages
 

Public Member Functions

 HivePeer (InitRequest request)
 Initializes a new instance of the HivePeer class. More...
 
bool ValidateOperation (Operation operation, SendParameters sendParameters)
 Checks if a operation is valid. If the operation is not valid an operation response containing a descriptive error message will be sent to the peer. More...
 
void RemovePeerFromCurrentRoom (int reason, string detail)
 Checks if the the state of peer is set to a reference of a room. If a room reference is present the peer will be removed from the related room and the reference will be disposed. Disposing the reference allows the associated room factory to remove the room instance if no more references to the room exists. More...
 
void ReleaseRoomReference ()
 
void OnJoinFailed (ErrorCode result, string details)
 
virtual bool IsThisSameSession (HivePeer peer)
 
virtual void UpdateSecure (string key, object value)
 
- Public Member Functions inherited from Photon.SocketServer.ClientPeer
void Trace (bool enabled, string tag)
 
new void GetTraceStatus (out int traceOptions, out int enableOptions, out string tag)
 
void TraceIfEnabledInConnect (string tag)
 Starts tracing if client connected with PeerId 0xFFFE to signal it wants to be traced (e.g. reconnect after an unexpected disconnect) More...
 
- Public Member Functions inherited from Photon.SocketServer.PeerBase
void Initialize (InitRequest initRequest)
 
override string ToString ()
 
void Disconnect (int disconnectError=ErrorCodes.Ok)
 Closes the connection. More...
 
void AbortConnection ()
 Forces the connection to close immediately. Should only be used if "Disconnect" does not lead to a clean connection shutdown, e.g. in case of an overloaded connection. More...
 
void Flush ()
 Flushes all pending data to the socket. More...
 
byte[] InitializeEncryption (byte[] otherPartyPublicKey)
 Initializes the peer to receive and send encrypted operations with EncryptionMethod.Sha256Pkcs7. More...
 
byte[] InitializeEncryption (byte[] otherPartyPublicKey, EncryptionMethod mode)
 Initializes the peer to receive and send encrypted operations. More...
 
bool SetupEncryption (EncryptionData encryptionData, byte channelCount, out short errorCode, out string errorMsg)
 
SendResult SendEvent (IEventData eventData, SendParameters sendParameters)
 Sends an IEventData object to the client. More...
 
SendResult SendMessage (object message, SendParameters sendParameters)
 
SendResult SendOperationResponse (OperationResponse operationResponse, SendParameters sendParameters)
 Sends the operation response to the client. More...
 
SendResult SendDisconnectMessage (DisconnectMessage message, SendParameters sendParameters, int disconnectDelay=DefaultDisconnectInterval)
 
void GetStats (out int roundTripTime, out int roundTripTimeVariance, out int numFailures)
 
void SetDebugString (string message)
 
string GetDebugString ()
 
virtual string GetHistograms ()
 
SendResult SendEventAndDisconnect (IEventData eventData, SendParameters sendParameters, int disconnectDelay=DefaultDisconnectInterval, int disconnectCode=ErrorCodes.Ok)
 
SendResult SendMessageAndDisconnect (object message, SendParameters sendParameters, int disconnectDelay=DefaultDisconnectInterval, int disconnectCode=ErrorCodes.Ok)
 
SendResult SendOperationResponseAndDisconnect (OperationResponse operationResponse, SendParameters sendParameters, int disconnectDelay=DefaultDisconnectInterval)
 Sends the operation response to the client. More...
 
void ScheduleDisconnect (int disconnectError, int delay)
 Schedules disconnect for peer. After this call data will be neither accepted from nor sent to client one of use cases is next: send error info and schedule for disconnect. this will give a chance to error information to reach a client More...
 
int GetLastTouch ()
 
void SetPrivateCustomTypeCache (CustomTypeCache cache)
 Sets private custom type cache. It is supposed to be used together with plugins. In other case Protocol.TryRegisterCustomType should be used More...
 
void SetInboundController (InboundController controller)
 
void Dispose ()
 Disposes the peer. More...
 
void Trace (bool enabled, object tag)
 

Public Attributes

int JoinStage => this.joinStage
 
- Public Attributes inherited from Photon.SocketServer.PeerBase
bool Connected => this.ConnectionState == ConnectionState.Connected || this.connectionState == ConnectionState.ScheduledForDisconnect
 Gets a value indicating whether this PeerBase instance is connected. More...
 
int ConnectionId => this.UnmanagedPeer.GetConnectionID()
 Gets the connection id. More...
 
bool IsConnectionSecure => this.datagramEncryptionUsed || this.NetworkProtocol == NetworkProtocolType.SecureWebSocket
 
bool Disposed => this.ConnectionState == ConnectionState.Disposed
 Gets a value indicating whether the peer was disposed. More...
 
bool ScheduledForDisconnect => this.connectionState == ConnectionState.ScheduledForDisconnect
 
IPAddress LocalIPAddress => string.IsNullOrEmpty(this.LocalIP) ? IPAddress.None : IPAddress.Parse(this.LocalIP)
 Gets the IP Address the client connects to. More...
 
IPAddress RemoteIPAddress => string.IsNullOrEmpty(this.RemoteIP) ? IPAddress.None : IPAddress.Parse(this.RemoteIP)
 Gets the client's remote IP address. More...
 
IFiber RequestFiber => this.requestFiber
 Gets fiber for incoming messages. More...
 
bool LocalIPAddressIsIPv6 => this.LocalIPAddress.AddressFamily == AddressFamily.InterNetworkV6
 If true connection is using a server IPv6 endpoint. More...
 
bool IsIPv6ToIPv4Bridged => this.SourceUsingIPv6 && this.LocalIPAddress.AddressFamily != AddressFamily.InterNetworkV6
 If true the client is being bridged (DNS64+NAT64), also SourceUsingIPv6. More...
 
ProtocolType ProtocolType => this.protocol.ProtocolType
 

Protected Member Functions

virtual void HandleCreateGameOperation (OperationRequest operationRequest, SendParameters sendParameters)
 
virtual void HandleRaiseEventOperation (OperationRequest operationRequest, SendParameters sendParameters)
 Enqueues RaiseEvent operation requests in the peers current game. More...
 
virtual void HandleSetPropertiesOperation (OperationRequest operationRequest, SendParameters sendParameters)
 Enqueues SetProperties operation requests in the peers current game. More...
 
virtual void HandleJoinGameOperation (OperationRequest operationRequest, SendParameters sendParameters)
 Handles the JoinGameRequest to enter a HiveGame. This method removes the peer from any previously joined room, finds the room intended for join and enqueues the operation for it to handle. More...
 
virtual bool MayJoinOrCreateGame (JoinGameRequest joinRequest, out short errorCode, out string errorMsg)
 
virtual PluginTraits GetPluginTraits ()
 
virtual void HandleLeaveOperation (OperationRequest operationRequest, SendParameters sendParameters)
 Handles the LeaveRequest to leave a HiveGame. More...
 
virtual void HandlePingOperation (OperationRequest operationRequest, SendParameters sendParameters)
 Handles a ping operation. More...
 
virtual void HandleRpcOperation (OperationRequest request, SendParameters sendParameters)
 Handles WebRpc operation More...
 
override void OnDisconnect (int reasonCode, string reasonDetail)
 Called when client disconnects. Ensures that disconnected players leave the game Room. The player is not removed immediately but a message is sent to the room. This avoids threading issues by making sure the player remove is not done concurrently with operations. More...
 
override void OnOperationRequest (OperationRequest operationRequest, SendParameters sendParameters)
 Called when the client sends an OperationRequest. More...
 
void HandleUnknownOperationCode (OperationRequest operationRequest, SendParameters sendParameters)
 
virtual void HandleDebugGameOperation (OperationRequest operationRequest, SendParameters sendParameters)
 
virtual RoomReference GetOrCreateRoom (string gameId, params object[] args)
 
virtual bool TryCreateRoom (string gameId, out RoomReference roomReference, params object[] args)
 
virtual bool TryGetRoomReference (string gameId, out RoomReference roomReference)
 
virtual bool TryGetRoomWithoutReference (string gameId, out Room room)
 
virtual void OnRoomNotFound (string gameId)
 
override void OnDeserializationError (byte[] data, RtsMessageType msgType, string debugMessage, short errorCode=ErrorCodes.UnexpectedData, byte code=0, Exception exception=null)
 This method is called if incoming data has an unexpected format. Per default this method disconnects the client. Override to change this behavior. More...
 
override void OnSendBufferFull ()
 A send operation failed because of insufficient buffer space. If this happens there is too much reliable data being sent for the available band width. The client is disconnected per default. Override to change the behavior. More...
 
override void OnSendBufferEmpty ()
 The default behavior of OnSendBufferFull is to disconnect the client. If this behavior is changed (override) the inheritor can pause sending until OnSendBufferEmpty is called. More...
 
- Protected Member Functions inherited from Photon.SocketServer.ClientPeer
 ClientPeer (InitRequest initRequest)
 
- Protected Member Functions inherited from Photon.SocketServer.PeerBase
virtual SendResult SendData (byte[] data, SendParameters sendParameters)
 Sends bytes to the client. More...
 
virtual void OnReceive (byte[] data, SendParameters sendParameters)
 Invoked if incoming data was received for the peer. More...
 
void OnMessageInternal (object message, SendParameters sendParameters)
 
void OnOperationRequestInternal (OperationRequest operationRequest, SendParameters sendParameters)
 
virtual void Dispose (bool disposing)
 Disposes the internal fibers. More...
 
OperationRequest ParseOperationRequest (byte[] data, SendParameters sendParameters)
 
OperationRequest ParseInternalOperationRequest (byte[] data, SendParameters sendParameters)
 
object ParseMessage (byte[] data, SendParameters sendParameters)
 
byte[] ParseRawMessage (byte[] data, SendParameters sendParameters)
 
void HandleParseError (byte[] data, SendParameters sendParameters, Exception exception, string errorMsg, short errorCode, RtsMessageType msgType, byte operationCode=0)
 
void GetTraceStatus (out int traceOptions, out int enableOptions, out string tag)
 
void DisconnectAfterSend (int disconnectCode, int disconnectDelay, SendResult result)
 
virtual void OnEncryptionQueueOverload (EncryptionQueueFailureParams failureParams)
 

Properties

RoomReference RoomReference [get]
 Gets or sets a Caching.RoomReference when joining a Room. More...
 
Actor Actor [get, set]
 
string UserId [get, protected set]
 
WebRpcHandler WebRpcHandler [get, set]
 
Dictionary< string, object > AuthCookie [get, protected set]
 
AuthenticationToken AuthToken [get, protected set]
 
int HttpRpcCallsLimit [get, set]
 
int CheckCount [get, set]
 The count of checks which were performed on this peer while it is in invalid state. More...
 
int LimitMaxUniqPropertyKeysPerPeer = int.MaxValue [get, set]
 
int LimitMaxPropertiesSizePerGame = int.MaxValue [get, set]
 
- Properties inherited from Photon.SocketServer.PeerBase
ConnectionState ConnectionState [get, set]
 Gets the ConnectionState for this instance. More...
 
string LocalIP [get]
 Gets the IP the client connects to. More...
 
int LocalPort [get]
 Gets the port the client connects to. More...
 
NetworkProtocolType NetworkProtocol [get]
 Gets the network protocol type used by the peer. More...
 
IRpcProtocol Protocol [get, set]
 Gets the used IRpcProtocol protocol. More...
 
string RemoteIP [get]
 Gets the client's remote IP address. More...
 
int RemotePort [get]
 Gets the port the client connects from. More...
 
int RoundTripTime [get, protected set]
 Gets the last round trip time for this peer. More...
 
int RoundTripTimeVariance [get, protected set]
 Gets the last round trip time variance for this peer. More...
 
int NumFailures [get, protected set]
 
bool SourceUsingIPv6 [get]
 If true the peer is using IPv6 to connect to the server, if the server endpoint used is not IPv6 (LocalIPAddressIsIPv6) it means the client is being bridged (DNS64+NAT64), also IsIPv6ToIPv4Bridged. More...
 
bool ClientUsingDebugLib [get]
 
byte SdkId [get]
 
byte PlatformId [get]
 
Version ClientVersion [get, protected set]
 
DateTime CreationTime = DateTime.Now [get]
 
PeerType PeerType [get]
 Under laying native peer type More...
 
InboundController PrivateInboundController [get]
 
int LastErrorCode [get]
 last error code that we was sent/set though this peer More...
 

Additional Inherited Members

- Static Public Attributes inherited from Photon.SocketServer.PeerBase
const int DefaultDisconnectInterval = 5_000
 
- Static Protected Member Functions inherited from Photon.SocketServer.PeerBase
static bool NeedSendErrorLog (SendResult sendResult)
 
- Protected Attributes inherited from Photon.SocketServer.PeerBase
readonly object SyncRoot = new object()
 object for synchronization More...
 
CustomTypeCache privateCustomTypeCache
 
PeerMetaDataContext metaDataContext
 
- Static Protected Attributes inherited from Photon.SocketServer.PeerBase
static readonly ILogger sendErrorLog = LogManager.GetLogger("Photon.ErrorLog.PeerSendError")
 

Detailed Description

Inheritance class of PeerBase.
The LitePeer dispatches incoming OperationRequests at OnOperationRequest. When joining a Room a Caching.RoomReference is stored in the RoomReference property. An IFiber guarantees that all outgoing messages (events/operations) are sent one after the other.

Constructor & Destructor Documentation

◆ HivePeer()

Photon.Hive.HivePeer.HivePeer ( InitRequest  request)
inline

Initializes a new instance of the HivePeer class.

Member Function Documentation

◆ GetOrCreateRoom()

virtual RoomReference Photon.Hive.HivePeer.GetOrCreateRoom ( string  gameId,
params object[]  args 
)
inlineprotectedvirtual

◆ GetPluginTraits()

virtual PluginTraits Photon.Hive.HivePeer.GetPluginTraits ( )
inlineprotectedvirtual

◆ HandleCreateGameOperation()

virtual void Photon.Hive.HivePeer.HandleCreateGameOperation ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

◆ HandleDebugGameOperation()

virtual void Photon.Hive.HivePeer.HandleDebugGameOperation ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

◆ HandleJoinGameOperation()

virtual void Photon.Hive.HivePeer.HandleJoinGameOperation ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Handles the JoinGameRequest to enter a HiveGame. This method removes the peer from any previously joined room, finds the room intended for join and enqueues the operation for it to handle.

Parameters
operationRequestThe operation request to handle.
sendParametersThe send Parameters.

◆ HandleLeaveOperation()

virtual void Photon.Hive.HivePeer.HandleLeaveOperation ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Handles the LeaveRequest to leave a HiveGame.

Parameters
operationRequestThe operation request to handle.
sendParametersThe send Parameters.

◆ HandlePingOperation()

virtual void Photon.Hive.HivePeer.HandlePingOperation ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Handles a ping operation.

Parameters
operationRequestThe operation request to handle.
sendParametersThe send Parameters.

◆ HandleRaiseEventOperation()

virtual void Photon.Hive.HivePeer.HandleRaiseEventOperation ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Enqueues RaiseEvent operation requests in the peers current game.

Parameters
operationRequestThe operation request.
sendParametersThe send Parameters.

The current for a peer is stored in the peers state property. Using the Room.EnqueueOperation method ensures that all operation request dispatch logic has thread safe access to all room instance members since they are processed in a serial order.

Inheritors can use this method to enqueue there custom game operation to the peers current game.

Reimplemented in Photon.LoadBalancing.GameServer.GameClientPeer.

◆ HandleRpcOperation()

virtual void Photon.Hive.HivePeer.HandleRpcOperation ( OperationRequest  request,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Handles WebRpc operation

Parameters
requestThe operation request to handle.
sendParametersThe send Parameters.

◆ HandleSetPropertiesOperation()

virtual void Photon.Hive.HivePeer.HandleSetPropertiesOperation ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Enqueues SetProperties operation requests in the peers current game.

Parameters
operationRequestThe operation request.
sendParametersThe send Parameters.

The current for a peer is stored in the peers state property. Using the Room.EnqueueOperation method ensures that all operation request dispatch logic has thread safe access to all room instance members since they are processed in a serial order.

Inheritors can use this method to enqueue there custom game operation to the peers current game.

◆ HandleUnknownOperationCode()

void Photon.Hive.HivePeer.HandleUnknownOperationCode ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotected

◆ IsThisSameSession()

virtual bool Photon.Hive.HivePeer.IsThisSameSession ( HivePeer  peer)
inlinevirtual

◆ MayJoinOrCreateGame()

virtual bool Photon.Hive.HivePeer.MayJoinOrCreateGame ( JoinGameRequest  joinRequest,
out short  errorCode,
out string  errorMsg 
)
inlineprotectedvirtual

◆ OnDeserializationError()

override void Photon.Hive.HivePeer.OnDeserializationError ( byte[]  data,
RtsMessageType  msgType,
string  debugMessage,
short  errorCode = ErrorCodes.UnexpectedData,
byte  opCode = 0,
Exception  exception = null 
)
inlineprotectedvirtual

This method is called if incoming data has an unexpected format. Per default this method disconnects the client. Override to change this behavior.

Parameters
dataThe received data.
debugMessageA debug message that specifies why the data was unexpected.
errorCode
opCode
exceptionparsing exception

Reimplemented from Photon.SocketServer.PeerBase.

◆ OnDisconnect()

override void Photon.Hive.HivePeer.OnDisconnect ( int  reasonCode,
string  reasonDetail 
)
inlineprotectedvirtual

Called when client disconnects. Ensures that disconnected players leave the game Room. The player is not removed immediately but a message is sent to the room. This avoids threading issues by making sure the player remove is not done concurrently with operations.

Implements Photon.SocketServer.PeerBase.

◆ OnJoinFailed()

void Photon.Hive.HivePeer.OnJoinFailed ( ErrorCode  result,
string  details 
)
inline

◆ OnOperationRequest()

override void Photon.Hive.HivePeer.OnOperationRequest ( OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Called when the client sends an OperationRequest.

Parameters
operationRequestThe operation request.
sendParametersThe send Parameters.

Implements Photon.SocketServer.PeerBase.

◆ OnRoomNotFound()

virtual void Photon.Hive.HivePeer.OnRoomNotFound ( string  gameId)
inlineprotectedvirtual

◆ OnSendBufferEmpty()

override void Photon.Hive.HivePeer.OnSendBufferEmpty ( )
inlineprotectedvirtual

The default behavior of OnSendBufferFull is to disconnect the client. If this behavior is changed (override) the inheritor can pause sending until OnSendBufferEmpty is called.

Reimplemented from Photon.SocketServer.PeerBase.

◆ OnSendBufferFull()

override void Photon.Hive.HivePeer.OnSendBufferFull ( )
inlineprotectedvirtual

A send operation failed because of insufficient buffer space. If this happens there is too much reliable data being sent for the available band width. The client is disconnected per default. Override to change the behavior.

Reimplemented from Photon.SocketServer.PeerBase.

◆ ReleaseRoomReference()

void Photon.Hive.HivePeer.ReleaseRoomReference ( )
inline

◆ RemovePeerFromCurrentRoom()

void Photon.Hive.HivePeer.RemovePeerFromCurrentRoom ( int  reason,
string  detail 
)
inline

Checks if the the state of peer is set to a reference of a room. If a room reference is present the peer will be removed from the related room and the reference will be disposed. Disposing the reference allows the associated room factory to remove the room instance if no more references to the room exists.

◆ TryCreateRoom()

virtual bool Photon.Hive.HivePeer.TryCreateRoom ( string  gameId,
out RoomReference  roomReference,
params object[]  args 
)
inlineprotectedvirtual

◆ TryGetRoomReference()

virtual bool Photon.Hive.HivePeer.TryGetRoomReference ( string  gameId,
out RoomReference  roomReference 
)
inlineprotectedvirtual

◆ TryGetRoomWithoutReference()

virtual bool Photon.Hive.HivePeer.TryGetRoomWithoutReference ( string  gameId,
out Room  room 
)
inlineprotectedvirtual

◆ UpdateSecure()

virtual void Photon.Hive.HivePeer.UpdateSecure ( string  key,
object  value 
)
inlinevirtual

◆ ValidateOperation()

bool Photon.Hive.HivePeer.ValidateOperation ( Operation  operation,
SendParameters  sendParameters 
)
inline

Checks if a operation is valid. If the operation is not valid an operation response containing a descriptive error message will be sent to the peer.

Parameters
operationThe operation.
sendParametersThe send Parameters.
Returns
true if the operation is valid; otherwise false.

Member Data Documentation

◆ JoinStage

int Photon.Hive.HivePeer.JoinStage => this.joinStage

Property Documentation

◆ Actor

Actor Photon.Hive.HivePeer.Actor
getset

◆ AuthCookie

Dictionary<string, object> Photon.Hive.HivePeer.AuthCookie
getprotected set

◆ AuthToken

AuthenticationToken Photon.Hive.HivePeer.AuthToken
getprotected set

◆ CheckCount

int Photon.Hive.HivePeer.CheckCount
getset

The count of checks which were performed on this peer while it is in invalid state.

◆ HttpRpcCallsLimit

int Photon.Hive.HivePeer.HttpRpcCallsLimit
getsetprotected

◆ LimitMaxPropertiesSizePerGame

int Photon.Hive.HivePeer.LimitMaxPropertiesSizePerGame = int.MaxValue
getset

◆ LimitMaxUniqPropertyKeysPerPeer

int Photon.Hive.HivePeer.LimitMaxUniqPropertyKeysPerPeer = int.MaxValue
getsetprotected

◆ RoomReference

RoomReference Photon.Hive.HivePeer.RoomReference
getprotected

Gets or sets a Caching.RoomReference when joining a Room.

◆ UserId

string Photon.Hive.HivePeer.UserId
getprotected set

◆ WebRpcHandler

WebRpcHandler Photon.Hive.HivePeer.WebRpcHandler
getset