C# Class NetworkingPeer, Droid-Soccer

Inheritance: LoadbalancingPeer, IPhotonPeerListener
Show file Open project: repelex/Droid-Soccer Class Usage Examples

Public Properties

Property Type Description
IsInitialConnect bool
PrefabCache GameObject>.Dictionary
UsePrefabCache bool
hasSwitchedMC bool
insideLobby bool
mActors PhotonPlayer>.Dictionary
mGameList RoomInfo>.Dictionary
mGameListCopy RoomInfo[],
mOtherPlayerListCopy PhotonPlayer[],
mPlayerListCopy PhotonPlayer[],

Protected Properties

Property Type Description
LobbyStatistics List
currentLevelPrefix short
loadingLevelAndPausedNetwork bool
mAppId string
photonViewList PhotonView>.Dictionary

Private Properties

Property Type Description
AddNewPlayer void
AlmostEquals bool
CheckMasterClient void
CheckTypeMatch bool
DeltaCompressionRead bool
DeltaCompressionWrite bool
DisconnectToReconnect void
DoInstantiate GameObject
GameEnteredOnGameServer void
GetActorPropertiesForActorNr ExitGames.Client.Photon.Hashtable
GetLocalActorProperties ExitGames.Client.Photon.Hashtable
GetNameServerAddress string
HandleEventLeave void
LeftLobbyCleanup void
LeftRoomCleanup void
ObjectIsSameWithInprecision bool
OnSerializeRead void
OnSerializeWrite ExitGames.Client.Photon.Hashtable
OpRemoveFromServerInstantiationsOfPlayer void
RPC void
RPC void
ReadoutProperties void
RebuildPlayerListCopies void
RemoveCacheOfLeftPlayers void
RemoveInstantiationData void
RemovePlayer void
ResetPhotonViewsOnSerialize void
ReturnLowestPlayerId int
SendDestroyOfAll void
SendDestroyOfPlayer void
SendInstantiate ExitGames.Client.Photon.Hashtable
SendPlayerName void
SendVacantViewIds void
ServerCleanInstantiateAndDestroy void
StoreInstantiationData void

Public Methods

Method Description
ChangeLocalID ( int newID ) : void
CleanRpcBufferIfMine ( PhotonView, view ) : void
Connect ( string serverAddress, ServerConnection, type ) : bool
Connect ( string serverAddress, string applicationName ) : bool
ConnectToNameServer ( ) : bool

Connects to the NameServer for Photon Cloud, where a region and server list can be obtained.

ConnectToRegionMaster ( CloudRegionCode region ) : bool

Connects you to a specific region's Master Server, using the Name Server to find the IP.

DebugReturn ( DebugLevel, level, string message ) : void
DestroyAll ( bool localOnly ) : void
DestroyPlayerObjects ( int playerId, bool localOnly ) : void

Destroys all Instantiates and RPCs locally and (if not localOnly) sends EvDestroy(player) and clears related events in the server buffer.

Disconnect ( ) : void

Complete disconnect from photon (and the open master OR game server)

FetchInstantiationData ( int instantiationId ) : object[]
GetInstantiatedObjectsId ( GameObject go ) : int

This returns -1 if the GO could not be found in list of instantiatedObjects.

GetPhotonView ( int viewID ) : PhotonView,
GetRegions ( ) : bool

While on the NameServer, this gets you the list of regional servers (short names and their IPs to ping them).

LocalCleanPhotonView ( PhotonView, view ) : bool
NetworkingPeer ( string playername, ConnectionProtocol connectionProtocol ) : System.Linq
NewSceneLoaded ( ) : void
OnEvent ( EventData, photonEvent ) : void
OnOperationResponse ( OperationResponse operationResponse ) : void
OnStatusChanged ( StatusCode statusCode ) : void
OpCleanRpcBuffer ( PhotonView, view ) : void

Cleans server RPCs for PhotonView (without any further checks).

OpCleanRpcBuffer ( int actorNumber ) : void

Removes the RPCs of someone else (to be used as master). This won't clean any local caches. It just tells the server to forget a player's RPCs and instantiates.

OpCreateGame ( EnterRoomParams, enterRoomParams ) : bool

NetworkingPeer.OpCreateGame

OpFindFriends ( string friendsToFind ) : bool

Request the rooms and online status for a list of friends. All client must set a unique username via PlayerName property. The result is available in this.Friends.

Used on Master Server to find the rooms played by a selected list of users. The result will be mapped to LoadBalancingClient.Friends when available. The list is initialized by OpFindFriends on first use (before that, it is null). Users identify themselves by setting a PlayerName in the LoadBalancingClient instance. This in turn will send the name in OpAuthenticate after each connect (to master and game servers). Note: Changing a player's name doesn't make sense when using a friend list. The list of usernames must be fetched from some other source (not provided by Photon). Internal: The server response includes 2 arrays of info (each index matching a friend from the request): ParameterCode.FindFriendsResponseOnlineList = bool[] of online states ParameterCode.FindFriendsResponseRoomIdList = string[] of room names (empty string if not in a room)

OpJoinRandomRoom ( OpJoinRandomRoomParams, opJoinRandomRoomParams ) : bool

NetworkingPeer.OpJoinRandomRoom

this override just makes sure we have a mRoomToGetInto, even if it's blank (the properties provided in this method are filters. they are not set when we join the game)

OpJoinRoom ( EnterRoomParams, opParams ) : bool

NetworkingPeer.OpJoinRoom

OpLeave ( ) : bool

Operation Leave will exit any current room.

This also happens when you disconnect from the server. Disconnect might be a step less if you don't want to create a new room on the same server.

OpRaiseEvent ( byte eventCode, object customEventContent, bool sendReliable, RaiseEventOptions, raiseEventOptions ) : bool
OpRemoveCompleteCache ( ) : void
OpRemoveCompleteCacheOfPlayer ( int actorNumber ) : void

Instead removing RPCs or Instantiates, this removed everything cached by the actor.

RegisterPhotonView ( PhotonView, netView ) : void
RemoveRPCsInGroup ( int group ) : void
RunViewUpdate ( ) : void
SendMonoMessage ( PhotonNetworkingMessage methodString ) : void
SetApp ( string appId, string gameVersion ) : void
SetLevelPrefix ( short prefix ) : void
SetMasterClient ( int nextMasterId ) : bool

Uses a well-known property to set someone new as Master Client in room (requires "Server Side Master Client" feature).

SetReceivingEnabled ( int group, bool enabled ) : void
SetReceivingEnabled ( int enableGroups, int disableGroups ) : void
SetSendingEnabled ( int group, bool enabled ) : void
SetSendingEnabled ( int enableGroups, int disableGroups ) : void
WebRpc ( string uriPath, object parameters ) : bool

Protected Methods

Method Description
ExecuteRpc ( ExitGames.Client.Photon.Hashtable rpcData, PhotonPlayer, sender ) : void

Executes a received RPC event

GetMethod ( MonoBehaviour monob, string methodType, MethodInfo &mi ) : bool
GetPlayerWithId ( int number ) : PhotonPlayer,
LoadLevelIfSynced ( ) : void

Internally used to detect the current scene and load it if PhotonNetwork.automaticallySyncScene is enabled.

LocalCleanupAnythingInstantiated ( bool destroyInstantiatedGameObjects ) : void

Cleans up anything that was instantiated in-game (not loaded with the scene).

RemoveInstantiatedGO ( GameObject go, bool localOnly ) : void

Removes GameObject and the PhotonViews on it from local lists and optionally updates remotes. GameObject gets destroyed at end.

This method might fail and quit early due to several tests.

RequestOwnership ( int viewID, int fromOwner ) : void
SetLevelInPropsIfSynced ( object levelId ) : void
SetMasterClient ( int playerId, bool sync ) : bool

Fake-sets a new Master Client for this room via RaiseEvent.

Does not affect RaiseEvent with target MasterClient but RPC().

TransferOwnership ( int viewID, int playerID ) : void
UpdateMasterClient ( ) : void

Call when the server provides a MasterClientId (due to joining or the current MC leaving, etc).

UpdatedActorList ( int actorsInRoom ) : void

Private Methods

Method Description
AddNewPlayer ( int ID, PhotonPlayer, player ) : void
AlmostEquals ( object lastData, object currentContent ) : bool
CheckMasterClient ( int leavingPlayerId ) : void

Picks the new master client from player list, if the current Master is leaving (leavingPlayerId) or if no master was assigned so far.

CheckTypeMatch ( ParameterInfo methodParameters, Type callParameterTypes ) : bool

Check if all types match with parameters. We can have more paramters then types (allow last RPC type to be different).

DeltaCompressionRead ( PhotonView, view, ExitGames.Client.Photon.Hashtable data ) : bool

reads incoming messages created by "OnSerialize"

DeltaCompressionWrite ( PhotonView, view, ExitGames.Client.Photon.Hashtable data ) : bool

Compares the new data with previously sent data and skips values that didn't change.

DisconnectToReconnect ( ) : void

Internally used only. Triggers OnStateChange with "Disconnect" in next dispatch which is the signal to re-connect (if at all).

DoInstantiate ( ExitGames.Client.Photon.Hashtable evData, PhotonPlayer, photonPlayer, GameObject resourceGameObject ) : GameObject
GameEnteredOnGameServer ( OperationResponse operationResponse ) : void
GetActorPropertiesForActorNr ( ExitGames.Client.Photon.Hashtable actorProperties, int actorNr ) : ExitGames.Client.Photon.Hashtable
GetLocalActorProperties ( ) : ExitGames.Client.Photon.Hashtable
GetNameServerAddress ( ) : string

Gets the NameServer Address (with prefix and port), based on the set protocol (this.UsedProtocol).

HandleEventLeave ( int actorID, EventData, evLeave ) : void

Called when the event Leave (of some other player) arrived. Cleans game objects, views locally. The master will also clean the

LeftLobbyCleanup ( ) : void

Called at disconnect/leavelobby etc. This CAN also be called when we are not in a lobby (e.g. disconnect from room)

Calls callback method OnLeftLobby if this client was in a lobby initially. Clears the lobby's game lists.

LeftRoomCleanup ( ) : void

Called when "this client" left a room to clean up.

ObjectIsSameWithInprecision ( object one, object two ) : bool

Returns true if both objects are almost identical. Used to check whether two objects are similar enough to skip an update.

OnSerializeRead ( ExitGames.Client.Photon.Hashtable data, PhotonPlayer, sender, int networkTime, short correctPrefix ) : void

Reads updates created by OnSerializeWrite

OnSerializeWrite ( PhotonView, view ) : ExitGames.Client.Photon.Hashtable
OpRemoveFromServerInstantiationsOfPlayer ( int actorNr ) : void
RPC ( PhotonView, view, string methodName, PhotonPlayer, player, bool encrypt ) : void
RPC ( PhotonView, view, string methodName, PhotonTargets target, bool encrypt ) : void
ReadoutProperties ( ExitGames.Client.Photon.Hashtable gameProperties, ExitGames.Client.Photon.Hashtable pActorProperties, int targetActorNr ) : void
RebuildPlayerListCopies ( ) : void
RemoveCacheOfLeftPlayers ( ) : void
RemoveInstantiationData ( int instantiationId ) : void
RemovePlayer ( int ID, PhotonPlayer, player ) : void
ResetPhotonViewsOnSerialize ( ) : void

Resets the PhotonView "lastOnSerializeDataSent" so that "OnReliable" synched PhotonViews send a complete state to new clients (if the state doesnt change, no messages would be send otherwise!). Note that due to this reset, ALL other players will receive the full OnSerialize.

ReturnLowestPlayerId ( PhotonPlayer, players, int playerIdToIgnore ) : int
SendDestroyOfAll ( ) : void
SendDestroyOfPlayer ( int actorNr ) : void
SendInstantiate ( string prefabName, Vector3 position, Quaternion rotation, int group, int viewIDs, object data, bool isGlobalObject ) : ExitGames.Client.Photon.Hashtable
SendPlayerName ( ) : void
SendVacantViewIds ( ) : void
ServerCleanInstantiateAndDestroy ( int instantiateId, int creatorId, bool isRuntimeInstantiated ) : void

Removes an instantiation event from the server's cache. Needs id and actorNr of player who instantiated.

StoreInstantiationData ( int instantiationId, object instantiationData ) : void

Method Details

ChangeLocalID() public method

public ChangeLocalID ( int newID ) : void
newID int
return void

CleanRpcBufferIfMine() public method

public CleanRpcBufferIfMine ( PhotonView, view ) : void
view PhotonView,
return void

Connect() public method

public Connect ( string serverAddress, ServerConnection, type ) : bool
serverAddress string
type ServerConnection,
return bool

Connect() public method

public Connect ( string serverAddress, string applicationName ) : bool
serverAddress string
applicationName string
return bool

ConnectToNameServer() public method

Connects to the NameServer for Photon Cloud, where a region and server list can be obtained.
public ConnectToNameServer ( ) : bool
return bool

ConnectToRegionMaster() public method

Connects you to a specific region's Master Server, using the Name Server to find the IP.
public ConnectToRegionMaster ( CloudRegionCode region ) : bool
region CloudRegionCode
return bool

DebugReturn() public method

public DebugReturn ( DebugLevel, level, string message ) : void
level DebugLevel,
message string
return void

DestroyAll() public method

public DestroyAll ( bool localOnly ) : void
localOnly bool
return void

DestroyPlayerObjects() public method

Destroys all Instantiates and RPCs locally and (if not localOnly) sends EvDestroy(player) and clears related events in the server buffer.
public DestroyPlayerObjects ( int playerId, bool localOnly ) : void
playerId int
localOnly bool
return void

Disconnect() public method

Complete disconnect from photon (and the open master OR game server)
public Disconnect ( ) : void
return void

ExecuteRpc() protected method

Executes a received RPC event
protected ExecuteRpc ( ExitGames.Client.Photon.Hashtable rpcData, PhotonPlayer, sender ) : void
rpcData ExitGames.Client.Photon.Hashtable
sender PhotonPlayer,
return void

FetchInstantiationData() public method

public FetchInstantiationData ( int instantiationId ) : object[]
instantiationId int
return object[]

GetInstantiatedObjectsId() public method

This returns -1 if the GO could not be found in list of instantiatedObjects.
public GetInstantiatedObjectsId ( GameObject go ) : int
go GameObject
return int

GetMethod() protected static method

protected static GetMethod ( MonoBehaviour monob, string methodType, MethodInfo &mi ) : bool
monob MonoBehaviour
methodType string
mi MethodInfo
return bool

GetPhotonView() public method

public GetPhotonView ( int viewID ) : PhotonView,
viewID int
return PhotonView,

GetPlayerWithId() protected method

protected GetPlayerWithId ( int number ) : PhotonPlayer,
number int
return PhotonPlayer,

GetRegions() public method

While on the NameServer, this gets you the list of regional servers (short names and their IPs to ping them).
public GetRegions ( ) : bool
return bool

LoadLevelIfSynced() protected method

Internally used to detect the current scene and load it if PhotonNetwork.automaticallySyncScene is enabled.
protected LoadLevelIfSynced ( ) : void
return void

LocalCleanPhotonView() public method

public LocalCleanPhotonView ( PhotonView, view ) : bool
view PhotonView,
return bool

LocalCleanupAnythingInstantiated() protected method

Cleans up anything that was instantiated in-game (not loaded with the scene).
protected LocalCleanupAnythingInstantiated ( bool destroyInstantiatedGameObjects ) : void
destroyInstantiatedGameObjects bool
return void

NetworkingPeer() public method

public NetworkingPeer ( string playername, ConnectionProtocol connectionProtocol ) : System.Linq
playername string
connectionProtocol ConnectionProtocol
return System.Linq

NewSceneLoaded() public method

public NewSceneLoaded ( ) : void
return void

OnEvent() public method

public OnEvent ( EventData, photonEvent ) : void
photonEvent EventData,
return void

OnOperationResponse() public method

public OnOperationResponse ( OperationResponse operationResponse ) : void
operationResponse OperationResponse
return void

OnStatusChanged() public method

public OnStatusChanged ( StatusCode statusCode ) : void
statusCode StatusCode
return void

OpCleanRpcBuffer() public method

Cleans server RPCs for PhotonView (without any further checks).
public OpCleanRpcBuffer ( PhotonView, view ) : void
view PhotonView,
return void

OpCleanRpcBuffer() public method

Removes the RPCs of someone else (to be used as master). This won't clean any local caches. It just tells the server to forget a player's RPCs and instantiates.
public OpCleanRpcBuffer ( int actorNumber ) : void
actorNumber int
return void

OpCreateGame() public method

NetworkingPeer.OpCreateGame
public OpCreateGame ( EnterRoomParams, enterRoomParams ) : bool
enterRoomParams EnterRoomParams,
return bool

OpFindFriends() public method

Request the rooms and online status for a list of friends. All client must set a unique username via PlayerName property. The result is available in this.Friends.
Used on Master Server to find the rooms played by a selected list of users. The result will be mapped to LoadBalancingClient.Friends when available. The list is initialized by OpFindFriends on first use (before that, it is null). Users identify themselves by setting a PlayerName in the LoadBalancingClient instance. This in turn will send the name in OpAuthenticate after each connect (to master and game servers). Note: Changing a player's name doesn't make sense when using a friend list. The list of usernames must be fetched from some other source (not provided by Photon). Internal: The server response includes 2 arrays of info (each index matching a friend from the request): ParameterCode.FindFriendsResponseOnlineList = bool[] of online states ParameterCode.FindFriendsResponseRoomIdList = string[] of room names (empty string if not in a room)
public OpFindFriends ( string friendsToFind ) : bool
friendsToFind string Array of friend's names (make sure they are unique).
return bool

OpJoinRandomRoom() public method

NetworkingPeer.OpJoinRandomRoom
this override just makes sure we have a mRoomToGetInto, even if it's blank (the properties provided in this method are filters. they are not set when we join the game)
public OpJoinRandomRoom ( OpJoinRandomRoomParams, opJoinRandomRoomParams ) : bool
opJoinRandomRoomParams OpJoinRandomRoomParams,
return bool

OpJoinRoom() public method

NetworkingPeer.OpJoinRoom
public OpJoinRoom ( EnterRoomParams, opParams ) : bool
opParams EnterRoomParams,
return bool

OpLeave() public method

Operation Leave will exit any current room.
This also happens when you disconnect from the server. Disconnect might be a step less if you don't want to create a new room on the same server.
public OpLeave ( ) : bool
return bool

OpRaiseEvent() public method

public OpRaiseEvent ( byte eventCode, object customEventContent, bool sendReliable, RaiseEventOptions, raiseEventOptions ) : bool
eventCode byte
customEventContent object
sendReliable bool
raiseEventOptions RaiseEventOptions,
return bool

OpRemoveCompleteCache() public method

public OpRemoveCompleteCache ( ) : void
return void

OpRemoveCompleteCacheOfPlayer() public method

Instead removing RPCs or Instantiates, this removed everything cached by the actor.
public OpRemoveCompleteCacheOfPlayer ( int actorNumber ) : void
actorNumber int
return void

RegisterPhotonView() public method

public RegisterPhotonView ( PhotonView, netView ) : void
netView PhotonView,
return void

RemoveInstantiatedGO() protected method

Removes GameObject and the PhotonViews on it from local lists and optionally updates remotes. GameObject gets destroyed at end.
This method might fail and quit early due to several tests.
protected RemoveInstantiatedGO ( GameObject go, bool localOnly ) : void
go GameObject GameObject to cleanup.
localOnly bool For localOnly, tests of control are skipped and the server is not updated.
return void

RemoveRPCsInGroup() public method

public RemoveRPCsInGroup ( int group ) : void
group int
return void

RequestOwnership() protected method

protected RequestOwnership ( int viewID, int fromOwner ) : void
viewID int
fromOwner int
return void

RunViewUpdate() public method

public RunViewUpdate ( ) : void
return void

SendMonoMessage() public static method

public static SendMonoMessage ( PhotonNetworkingMessage methodString ) : void
methodString PhotonNetworkingMessage
return void

SetApp() public method

public SetApp ( string appId, string gameVersion ) : void
appId string
gameVersion string
return void

SetLevelInPropsIfSynced() protected method

protected SetLevelInPropsIfSynced ( object levelId ) : void
levelId object
return void

SetLevelPrefix() public method

public SetLevelPrefix ( short prefix ) : void
prefix short
return void

SetMasterClient() public method

Uses a well-known property to set someone new as Master Client in room (requires "Server Side Master Client" feature).
public SetMasterClient ( int nextMasterId ) : bool
nextMasterId int
return bool

SetMasterClient() protected method

Fake-sets a new Master Client for this room via RaiseEvent.
Does not affect RaiseEvent with target MasterClient but RPC().
protected SetMasterClient ( int playerId, bool sync ) : bool
playerId int
sync bool
return bool

SetReceivingEnabled() public method

public SetReceivingEnabled ( int group, bool enabled ) : void
group int
enabled bool
return void

SetReceivingEnabled() public method

public SetReceivingEnabled ( int enableGroups, int disableGroups ) : void
enableGroups int
disableGroups int
return void

SetSendingEnabled() public method

public SetSendingEnabled ( int group, bool enabled ) : void
group int
enabled bool
return void

SetSendingEnabled() public method

public SetSendingEnabled ( int enableGroups, int disableGroups ) : void
enableGroups int
disableGroups int
return void

TransferOwnership() protected method

protected TransferOwnership ( int viewID, int playerID ) : void
viewID int
playerID int
return void

UpdateMasterClient() protected method

Call when the server provides a MasterClientId (due to joining or the current MC leaving, etc).
protected UpdateMasterClient ( ) : void
return void

UpdatedActorList() protected method

protected UpdatedActorList ( int actorsInRoom ) : void
actorsInRoom int
return void

WebRpc() public method

public WebRpc ( string uriPath, object parameters ) : bool
uriPath string
parameters object
return bool

Property Details

IsInitialConnect public property

public bool IsInitialConnect
return bool

LobbyStatistics protected property

protected List LobbyStatistics
return List

PrefabCache public static property

public static Dictionary PrefabCache
return GameObject>.Dictionary

UsePrefabCache public static property

public static bool UsePrefabCache
return bool

currentLevelPrefix protected property

protected short currentLevelPrefix
return short

hasSwitchedMC public property

public bool hasSwitchedMC
return bool

insideLobby public property

public bool insideLobby
return bool

loadingLevelAndPausedNetwork protected property

Internally used to flag if the message queue was disabled by a "scene sync" situation (to re-enable it).
protected bool loadingLevelAndPausedNetwork
return bool

mActors public property

public Dictionary mActors
return PhotonPlayer>.Dictionary

mAppId protected property

Contains the AppId for the Photon Cloud (ignored by Photon Servers).
protected string mAppId
return string

mGameList public property

public Dictionary mGameList
return RoomInfo>.Dictionary

mGameListCopy public property

public RoomInfo[], mGameListCopy
return RoomInfo[],

mOtherPlayerListCopy public property

public PhotonPlayer[], mOtherPlayerListCopy
return PhotonPlayer[],

mPlayerListCopy public property

public PhotonPlayer[], mPlayerListCopy
return PhotonPlayer[],

photonViewList protected property

protected Dictionary photonViewList
return PhotonView>.Dictionary