C# Class UnityEngine.Networking.NetworkServer

High level UNET server.

显示文件 Open project: CarlosHBC/UnityDecompiled Class Usage Examples

Public Methods

Method Description
AddExternalConnection ( NetworkConnection conn ) : bool

This accepts a network connection from another external source and adds it to the server.

AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId ) : bool

When an AddPlayer message handler has received a request from a player, the server calls this to associate the player object with the connection.

AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId ) : bool
BecomeHost ( NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage peers ) : NetworkClient
ClearHandlers ( ) : void

Clear all registered callback handlers.

ClearLocalObjects ( ) : void

This clears all of the networked objects that the server is aware of. This can be required if a scene change deleted all of the objects without destroying them in the normal manner.

ClearSpawners ( ) : void

Clears all registered spawn prefab and spawn handler functions for this server.

Configure ( ConnectionConfig config, int maxConnections ) : bool

This configures the transport layer settings for the server.

Configure ( HostTopology topology ) : bool

This configures the transport layer settings for the server.

Destroy ( GameObject obj ) : void

Destroys this object and corresponding objects on all clients.

DestroyPlayersForConnection ( NetworkConnection conn ) : void

This destroys all the player objects associated with a NetworkConnections on a server.

DisconnectAll ( ) : void

Disconnect all currently connected clients.

FindLocalObject ( NetworkInstanceId netId ) : GameObject

This finds the local NetworkIdentity object with the specified network Id.

GetConnectionStats ( ) : NetworkConnection.PacketStat>.Dictionary

Gets aggregate packet stats for all connections.

GetStatsIn ( int &numMsgs, int &numBytes ) : void
GetStatsOut ( int &numMsgs, int &numBufferedMsgs, int &numBytes, int &lastBufferedPerSecond ) : void
Listen ( MatchInfo matchInfo, int listenPort ) : bool
Listen ( int serverPort ) : bool

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

Listen ( string ipAddress, int serverPort ) : bool

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

ListenRelay ( string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId ) : void

Starts a server using a Relay server. This is the manual way of using the Relay server, as the regular NetworkServer.Connect() will automatically use the Relay server if a match exists.

RegisterHandler ( short msgType, NetworkMessageDelegate handler ) : void

Register a handler for a particular message type.

Private Methods

Method Description
ActivateLocalClientScene ( ) : void
AddExternalConnectionInternal ( NetworkConnection conn ) : bool
AddLocalClient ( LocalClient localClient ) : int
BecomeHostInternal ( NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage peers ) : NetworkClient
CheckForNullObjects ( ) : void
CheckPlayerControllerIdForConnection ( NetworkConnection conn, short playerControllerId ) : bool
DestroyObject ( GameObject obj ) : void
DestroyObject ( NetworkIdentity uv, bool destroyServerObject ) : void
FinishPlayerForConnection ( NetworkConnection conn, NetworkIdentity uv, GameObject playerGameObject ) : void
GenerateConnectError ( int error ) : void
GenerateDataError ( NetworkConnection conn, int error ) : void
GenerateDisconnectError ( NetworkConnection conn, int error ) : void
GenerateError ( NetworkConnection conn, int error ) : void
GetNetworkIdentity ( GameObject go, NetworkIdentity &view ) : bool
HideForConnection ( NetworkIdentity uv, NetworkConnection conn ) : void
InternalAddPlayerForConnection ( NetworkConnection conn, GameObject playerGameObject, short playerControllerId ) : bool
InternalDisconnectAll ( ) : void
InternalListen ( string ipAddress, int serverPort ) : bool
InternalListenRelay ( string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId ) : void
InternalReplacePlayerForConnection ( NetworkConnection conn, GameObject playerGameObject, short playerControllerId ) : bool
InternalSetClientNotReady ( NetworkConnection conn ) : void
InternalSetMaxDelay ( float seconds ) : void
InternalUpdate ( ) : void
InvokeBytes ( ULocalConnectionToServer conn, byte buffer, int numBytes, int channelId ) : bool
InvokeHandlerOnServer ( ULocalConnectionToServer conn, short msgType, MessageBase msg, int channelId ) : bool
NetworkServer ( ) : System
OnClientReadyMessage ( NetworkMessage netMsg ) : void
OnCommandMessage ( NetworkMessage netMsg ) : void
OnConnected ( NetworkConnection conn ) : void
OnData ( NetworkConnection conn, int receivedSize, int channelId ) : void
OnDisconnected ( NetworkConnection conn ) : void
OnRemovePlayerMessage ( NetworkMessage netMsg ) : void
RegisterMessageHandlers ( ) : void

Method Details

AddExternalConnection() public static method

This accepts a network connection from another external source and adds it to the server.

public static AddExternalConnection ( NetworkConnection conn ) : bool
conn NetworkConnection Network connection to add.
return bool

AddPlayerForConnection() public static method

When an AddPlayer message handler has received a request from a player, the server calls this to associate the player object with the connection.

public static AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId ) : bool
conn NetworkConnection Connection which is adding the player.
player UnityEngine.GameObject Player object spawned for the player.
playerControllerId short The player controller ID number as specified by client.
return bool

AddPlayerForConnection() public static method

public static AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId ) : bool
conn NetworkConnection
player UnityEngine.GameObject
playerControllerId short
assetId NetworkHash128
return bool

BecomeHost() public static method

public static BecomeHost ( NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage peers ) : NetworkClient
oldClient NetworkClient
port int
matchInfo UnityEngine.Networking.Match.MatchInfo
oldConnectionId int
peers UnityEngine.Networking.NetworkSystem.PeerInfoMessage
return NetworkClient

ClearHandlers() public static method

Clear all registered callback handlers.

public static ClearHandlers ( ) : void
return void

ClearLocalObjects() public static method

This clears all of the networked objects that the server is aware of. This can be required if a scene change deleted all of the objects without destroying them in the normal manner.

public static ClearLocalObjects ( ) : void
return void

ClearSpawners() public static method

Clears all registered spawn prefab and spawn handler functions for this server.

public static ClearSpawners ( ) : void
return void

Configure() public static method

This configures the transport layer settings for the server.

public static Configure ( ConnectionConfig config, int maxConnections ) : bool
config ConnectionConfig Transport layer confuration object.
maxConnections int The maximum number of client connections to allow.
return bool

Configure() public static method

This configures the transport layer settings for the server.

public static Configure ( HostTopology topology ) : bool
topology HostTopology Transport layer topology object to use.
return bool

Destroy() public static method

Destroys this object and corresponding objects on all clients.

public static Destroy ( GameObject obj ) : void
obj UnityEngine.GameObject Game object to destroy.
return void

DestroyPlayersForConnection() public static method

This destroys all the player objects associated with a NetworkConnections on a server.

public static DestroyPlayersForConnection ( NetworkConnection conn ) : void
conn NetworkConnection The connections object to clean up for.
return void

DisconnectAll() public static method

Disconnect all currently connected clients.

public static DisconnectAll ( ) : void
return void

FindLocalObject() public static method

This finds the local NetworkIdentity object with the specified network Id.

public static FindLocalObject ( NetworkInstanceId netId ) : GameObject
netId NetworkInstanceId The netId of the NetworkIdentity object to find.
return UnityEngine.GameObject

GetConnectionStats() public static method

Gets aggregate packet stats for all connections.

public static GetConnectionStats ( ) : NetworkConnection.PacketStat>.Dictionary
return NetworkConnection.PacketStat>.Dictionary

GetStatsIn() public static method

public static GetStatsIn ( int &numMsgs, int &numBytes ) : void
numMsgs int
numBytes int
return void

GetStatsOut() public static method

public static GetStatsOut ( int &numMsgs, int &numBufferedMsgs, int &numBytes, int &lastBufferedPerSecond ) : void
numMsgs int
numBufferedMsgs int
numBytes int
lastBufferedPerSecond int
return void

Listen() public static method

public static Listen ( MatchInfo matchInfo, int listenPort ) : bool
matchInfo UnityEngine.Networking.Match.MatchInfo
listenPort int
return bool

Listen() public static method

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

public static Listen ( int serverPort ) : bool
serverPort int Listen port number.
return bool

Listen() public static method

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

public static Listen ( string ipAddress, int serverPort ) : bool
ipAddress string The IP address to bind to (optional).
serverPort int Listen port number.
return bool

ListenRelay() public static method

Starts a server using a Relay server. This is the manual way of using the Relay server, as the regular NetworkServer.Connect() will automatically use the Relay server if a match exists.

public static ListenRelay ( string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId ) : void
relayIp string Relay server IP Address.
relayPort int Relay server port.
netGuid NetworkID GUID of the network to create.
sourceId SourceID This server's sourceId.
nodeId NodeID The node to join the network with.
return void

RegisterHandler() public static method

Register a handler for a particular message type.

public static RegisterHandler ( short msgType, NetworkMessageDelegate handler ) : void
msgType short Message type number.
handler NetworkMessageDelegate Function handler which will be invoked for when this message type is received.
return void