TNet 3  3.0.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
TNet.TNManager Class Reference

Tasharen Network Manager tailored for Unity. More...

Inheritance diagram for TNet.TNManager:

Public Member Functions

delegate bool IsJoiningChannelFunc (int channelID)
 
delegate void ProcessPacketsFunc ()
 
delegate void LoadSceneFunc (string levelName)
 
delegate AsyncOperation LoadSceneAsyncFunc (string levelName)
 

Static Public Member Functions

static void SetAdmin (string passKey)
 Set administrator privileges. Note that failing the password test will cause a disconnect. More...
 
static void AddAdmin (string passKey)
 Add a new pass key to the admin file. More...
 
static void RemoveAdmin (string passKey)
 Remove the specified pass key from the admin file. More...
 
static void SetAlias (string alias)
 Set a player alias. Player aliases can be used to store useful player-associated data such as Steam usernames, database IDs, or other unique identifiers. Aliases will show up in TNet's log and can also be banned by on the server side. When a player is banned, all their aliases are banned as well, so be careful to make sure that they are indeed unique. All aliases are visible via TNet.Player.aliases list of each player. More...
 
static void ResetPacketCount ()
 Immediately reset the packet count. Calling this isn't necessary as they get updated once per second anyway. More...
 
static bool IsHosting (int channelID)
 Whether the player is hosting this channel. More...
 
static bool IsChannelLocked (int channelID)
 Whether the specified channel is currently locked. More...
 
static bool IsInChannel (int channelID)
 Check to see if we are currently in the specified channel. More...
 
static Player GetHost (int channelID)
 Get the player hosting the specified channel. Only works for the channels the player is in. More...
 
static List< PlayerGetPlayers (int channelID)
 Get a list of players under the specified channel. This will only work for channels the player has joined. The returned list will not include TNManager.player. More...
 
static DataNode GetServerData (string key)
 Retrieve the specified server option. More...
 
static T GetServerData< T > (string key)
 Retrieve the specified server option. More...
 
static T GetServerData< T > (string key, T def)
 Retrieve the specified server option. More...
 
static void SetServerData (string text)
 Set the specified server option using key = value notation. More...
 
static void SetServerData (DataNode node)
 Set the specified server option. More...
 
static void SetServerData (string key, object val)
 Set the specified server option. More...
 
static Channel GetChannel (int channelID)
 Return a channel with the specified ID. This will only work as long as the player is in this channel. More...
 
static DataNode GetChannelData (string key)
 Convenience method: Retrieve the specified channel option. More...
 
static T GetChannelData< T > (string key)
 Convenience method: Retrieve the specified channel option. More...
 
static T GetChannelData< T > (string key, T def)
 Convenience method: Retrieve the specified channel option. More...
 
static DataNode GetChannelData (int channelID, string key)
 Convenience method: Retrieve the specified channel option. More...
 
static T GetChannelData< T > (int channelID, string key)
 Convenience method: Retrieve the specified channel option. More...
 
static T GetChannelData< T > (int channelID, string key, T def)
 Convenience method: Retrieve the specified channel option. More...
 
static void SetChannelData (string key, object val)
 Set the specified channel option. More...
 
static void SetChannelData (int channelID, string key, object val)
 Set the specified channel option. More...
 
static Player GetPlayer (int id)
 Get the player associated with the specified ID. More...
 
static Player GetPlayer (string name)
 Get the player associated with the specified name. More...
 
static Player FindPlayer (string name)
 Find the player associated with the specified partial name. This function is not case sensitive, so calling it with "Ren" will return "Aren Mook" as a possible choice. More...
 
static DataNode GetPlayerData (string path)
 Get our player's data. More...
 
static T GetPlayerData< T > (string path)
 Convenience method: Get the specified value from our player. More...
 
static T GetPlayerData< T > (string path, T defaultVal)
 Convenience method: Get the specified value from our player. More...
 
static void SetPlayerData (string path, object val)
 Set the specified value on our player. More...
 
static void SetPlayerData (string text)
 Set the specified value on our player using key = value notation. More...
 
static void GetChannelList (GameClient.OnGetChannels callback)
 Get a list of channels from the server. More...
 
static void SetPacketHandler (byte packetID, GameClient.OnPacket callback)
 Set the following function to handle this type of packets. More...
 
static void SetPacketHandler (Packet packet, GameClient.OnPacket callback)
 Set the following function to handle this type of packets. More...
 
static bool StartUDP (int udpPort)
 Start listening for incoming UDP packets on the specified port. More...
 
static void StopUDP ()
 Stop listening to incoming UDP packets. More...
 
static void Ping (IPEndPoint udpEndPoint, TNEvents.OnPing callback)
 Send a remote ping request to the specified TNet server. More...
 
static void Connect ()
 Connect to a local server. More...
 
static void Connect (string address)
 Connect to the specified destination with the address and port specified as "255.255.255.255:255". More...
 
static void Connect (string address, int port)
 Connect to the specified destination. More...
 
static void Connect (IPEndPoint externalIP, IPEndPoint internalIP)
 Connect to the specified remote destination. More...
 
static void Disconnect ()
 Disconnect from the specified destination. More...
 
static void JoinChannel (int channelID, bool persistent=false, bool leaveCurrentChannel=false)
 Join the specified channel. More...
 
static void JoinChannel (int channelID, string levelName, bool leaveCurrentChannel=true)
 Join the specified channel. This channel will be marked as persistent, meaning it will stay open even when the last player leaves, unless explicitly closed first. More...
 
static void JoinChannel (int channelID, string levelName, bool persistent, int playerLimit, string password, bool leaveCurrentChannel=true)
 Join the specified channel. More...
 
static void JoinRandomChannel (string levelName, bool persistent, int playerLimit, string password, bool leaveCurrentChannel=true)
 Join a random open game channel or create a new one. Guaranteed to load the specified level. More...
 
static void CreateChannel (string levelName, bool persistent, int playerLimit, string password, bool leaveCurrentChannel=true)
 Create a new channel. More...
 
static void CloseChannel ()
 Close the channel the player is in. New players will be prevented from joining. Once a channel has been closed, it cannot be re-opened. More...
 
static void CloseChannel (int channelID)
 Close the channel the player is in. New players will be prevented from joining. Once a channel has been closed, it cannot be re-opened. More...
 
static void LeaveAllChannels ()
 Leave all of the channels we're currently in. More...
 
static void LeaveChannel ()
 Leave the channel we're in. More...
 
static void LeaveChannel (int channelID)
 Leave the channel we're in. More...
 
static void DeleteChannel (int id, bool disconnect)
 Delete the specified channel. More...
 
static void SetPlayerLimit (int max)
 Change the maximum number of players that can join the channel the player is currently in. More...
 
static void SetPlayerLimit (int channelID, int max)
 Change the maximum number of players that can join the channel the player is currently in. More...
 
static void LoadLevel (string levelName)
 Load the specified level. More...
 
static void LoadLevel (int channelID, string levelName)
 Load the specified level. More...
 
static void SaveFile (string filename, byte[] data)
 Save the specified file on the server. More...
 
static void LoadFile (string filename, GameClient.OnLoadFile callback)
 Load the specified file residing on the server. More...
 
static void SetPlayerSave (string filename, DataNode.SaveType type=DataNode.SaveType.Binary)
 Specify where the player's data should be saved. You only need to call this function once and TNet will automatically save the player file for you every time you use TNManager.SetPlayerData afterwards. More...
 
static void DeleteFile (string filename)
 Delete the specified file on the server. More...
 
static void SetHost (Player player)
 Change the hosting player. More...
 
static void SetHost (int channelID, Player player)
 Change the hosting player. More...
 
static void SetTimeout (int seconds)
 Set the timeout for the player. By default it's 10 seconds. If you know you are about to load a large level, and it's going to take, say 60 seconds, set this timeout to 120 seconds just to be safe. When the level finishes loading, change this back to 10 seconds so that dropped connections gets detected correctly. More...
 
static void LockChannel (bool locked)
 Lock the channel the player is currently in. More...
 
static void LockChannel (int channelID, bool locked)
 Lock the specified channel, preventing all future persistent RFCs from being saved. More...
 
static void Instantiate (int rccID, string path, bool persistent, params object[] objs)
 Create a packet that will send a custom object creation call. Instantiate a new game object in the current channel on all connected players. More...
 
static void Instantiate (string funcName, string path, bool persistent, params object[] objs)
 Create a packet that will send a custom object creation call. Instantiate a new game object in the current channel on all connected players. More...
 
static void Instantiate (int channelID, int rccID, string path, bool persistent, params object[] objs)
 Create a packet that will send a custom object creation call. Instantiate a new game object in the specified channel on all connected players. More...
 
static void Instantiate (int channelID, string funcName, string path, bool persistent, params object[] objs)
 Create a packet that will send a custom object creation call. Instantiate a new game object in the specified channel on all connected players. More...
 
static void AddRCCs< T > ()
 Add a new Remote Creation Call. More...
 
static void AddRCCs (System.Type type)
 Add a new Remote Creation Call. More...
 
static void Log (string text)
 Write a server log entry. More...
 
static BinaryWriter BeginSend (Packet type)
 Begin sending a new packet to the server. More...
 
static BinaryWriter BeginSend (byte packetID)
 Begin sending a new packet to the server. More...
 
static void EndSend ()
 Send the outgoing buffer. This should only be used for generic packets going straight to the server. Packets that are going to a channel should use EndSend(channelID, reliable) function instead. More...
 
static void EndSend (int channelID, bool reliable=true)
 Send the outgoing buffer. More...
 
static void EndSendToLAN (int port)
 Broadcast the packet to everyone on the LAN. More...
 
static void EndSend (IPEndPoint target)
 Broadcast the packet to the specified endpoint via UDP. More...
 
static bool WriteCache (string path, byte[] data, bool inMyDocuments=false)
 Write the specified data into a local cache file belonging to connected server. More...
 
static byte[] ReadCache (string path)
 Read the specified file from the cache belonging to the connected server. More...
 
static int IndexOf (GameObject go)
 Find the index of the specified game object. More...
 
static void AddToReceiveQueue (TNet.Buffer buff)
 Add the specified packet to the receive queue. Useful for inserting messages to be processed by the network manager. More...
 
static void SetServerOption (string text)
 
static void SetServerOption (string key, object val)
 
static void SetServerOption (DataNode node)
 
static void SetChannelOption (DataNode node)
 
static void EndSend (bool reliable)
 
static DataNode GetServerOption (string key)
 
static T GetServerOption< T > (string key)
 
static T GetServerOption< T > (string key, T def)
 
static void Destroy (GameObject go)
 

Public Attributes

GameObject[] objects
 List of objects that can be instantiated by the network. More...
 

Static Public Attributes

static bool isPaused = false
 Whether the application is currently paused. More...
 
static bool rebuildMethodList = true
 If set to 'true', the list of custom creation functions will be rebuilt the next time it's accessed. More...
 
static IsJoiningChannelFunc IsJoiningChannel
 Whether we are currently trying to join the specified channel. More...
 
static int lastChannelID = 0
 ID of the channel the player is in. Note that if used while the player is in more than one channel, a warning will be shown. More...
 
static ProcessPacketsFunc ProcessPackets
 If you want to do custom logic for when packets can be processed and when they can't be, overwrite this delegate. More...
 
static LoadSceneFunc LoadScene
 Load the chosen scene. More...
 
static LoadSceneAsyncFunc LoadSceneAsync
 Load the chosen scene asynchronously. More...
 
static AsyncOperation loadLevelOperation = null
 When a level is being loaded, this value will contain the async coroutine for the LoadLevel operation. You can yield on it if you need. More...
 

Properties

static TNEvents.OnPing onPing [get, set]
 Ping notification. More...
 
static TNEvents.OnError onError [get, set]
 Error notification. More...
 
static TNEvents.OnConnect onConnect [get, set]
 Connection attempt result indicating success or failure. More...
 
static TNEvents.OnDisconnect onDisconnect [get, set]
 Notification sent after the connection terminates for any reason. More...
 
static TNEvents.OnJoinChannel onJoinChannel [get, set]
 Notification sent when attempting to join a channel, indicating a success or failure. More...
 
static TNEvents.OnLeaveChannel onLeaveChannel [get, set]
 Notification sent when leaving a channel for any reason, including being disconnected. More...
 
static TNEvents.OnLoadLevel onLoadLevel [get, set]
 Notification sent when changing levels. More...
 
static TNEvents.OnPlayerJoin onPlayerJoin [get, set]
 Notification sent when a new player joins the channel. More...
 
static TNEvents.OnPlayerLeave onPlayerLeave [get, set]
 Notification sent when a player leaves the channel. More...
 
static TNEvents.OnRenamePlayer onRenamePlayer [get, set]
 Notification of some player changing their name. More...
 
static TNEvents.OnHostChanged onHostChanged [get, set]
 Notification sent when the channel's host changes. More...
 
static TNEvents.OnSetServerData onSetServerData [get, set]
 Notification sent when the server's data gets changed. More...
 
static TNEvents.OnSetChannelData onSetChannelData [get, set]
 Notification sent when the channel's data gets changed. More...
 
static TNEvents.OnSetPlayerData onSetPlayerData [get, set]
 Notification sent when player data gets changed. More...
 
static TNEvents.OnLockChannel onLockChannel [get, set]
 Callback triggered when the channel becomes locked or unlocked. More...
 
static TNEvents.OnSetAdmin onSetAdmin [get, set]
 Callback triggered when the player gets verified as an administrator. More...
 
static bool isAdmin [get]
 Whether the player has verified himself as an administrator. More...
 
static GameClient client [get]
 TNet Client used for communication. More...
 
static bool isConnected [get]
 Whether we're currently connected. More...
 
static int sentPackets [get]
 How many packets were sent in the last second. More...
 
static int receivedPackets [get]
 How many packets have been received in the last second. More...
 
static bool isJoiningChannel [get]
 Whether we are currently in the process of joining a channel. To find out whether we are joining a specific channel, use the "IsJoiningChannel(id)" function. More...
 
static bool isTryingToConnect [get]
 Whether we are currently trying to establish a new connection. More...
 
static bool isHosting [get]
 Whether we're currently hosting. Note that this should only be used if the player is in only one channel. More...
 
static bool isInChannel [get]
 Whether we're currently in any channel. To find out if we are in a specific channel, use TNManager.IsInChannel(id). More...
 
static bool isActive [get, set]
 You can pause TNManager's message processing if you like. This happens automatically when a scene is being loaded. More...
 
static bool noDelay [get, set]
 Enable or disable the Nagle's buffering algorithm (aka NO_DELAY flag). Enabling this flag will improve latency at the cost of increased bandwidth. http://en.wikipedia.org/wiki/Nagle's_algorithm More...
 
static int ping [get]
 Current ping to the server. More...
 
static bool canUseUDP [get]
 Whether we can use unreliable packets (UDP) to communicate with the server. More...
 
static int listeningPort [get]
 Listening port for incoming UDP packets. Set via TNManager.StartUDP(). More...
 
static long serverTime [get]
 Current time on the server in milliseconds. More...
 
static long serverUptime [get]
 Server's uptime in milliseconds. More...
 
static double time [get]
 Time elapsed either since the server has been started up in seconds, or (if not connected) – time since TNManager was first used. It's a more precise version of Unity's Time.time, since it takes a mere 3 hours for float precision to start dropping milliseconds. More...
 
static long playedTime [get]
 Player's /played time in seconds. This value is automatically tracked by the server and is saved as a part of the player file. More...
 
static int packetSourceID [get]
 Forward and Create type packets write down their source. If the packet was sent by the server instead of another player, the ID will be 0. More...
 
static IPEndPoint packetSourceIP [get]
 Address from which the packet was received. Only available during packet processing callbacks. If null, then the packet arrived via the active connection (TCP). If the return value is not null, then the last packet arrived via UDP. More...
 
static IPEndPoint tcpEndPoint [get]
 TCP end point, available only if we're actually connected to the server. More...
 
static List< Channelchannels [get]
 List of channels the player is currently in. More...
 
static int playerID [get]
 The player's unique identifier. More...
 
static string playerName [get, set]
 Get or set the player's name as everyone sees him on the network. More...
 
static DataNode playerData [get, set]
 Get or set the player's data, synchronizing it with the server. To change the data, use TNManager.SetPlayerData instead of changing the content directly. More...
 
static List< Playerplayers [get]
 List of other players in the same channel as the client. This list does not include TNManager.player. More...
 
static Player player [get]
 Get the local player. More...
 
static DataNode serverData [get, set]
 Server configuration is set by administrators. In most cases you should use GetServerData and SetServerData functions instead. More...
 
static DataNode playerDataNode [get]
 
static DataNode serverOptions [get]
 
static IPEndPoint packetSource [get]
 
static bool isChannelLocked [get]
 
static string channelData [get, set]
 
static int channelID [get]
 
static int hostID [get]
 

Detailed Description

Tasharen Network Manager tailored for Unity.

Member Function Documentation

static void TNet.TNManager.AddAdmin ( string  passKey)
static

Add a new pass key to the admin file.

static void TNet.TNManager.AddRCCs ( System.Type  type)
static

Add a new Remote Creation Call.

static void TNet.TNManager.AddRCCs< T > ( )
static

Add a new Remote Creation Call.

static void TNet.TNManager.AddToReceiveQueue ( TNet.Buffer  buff)
static

Add the specified packet to the receive queue. Useful for inserting messages to be processed by the network manager.

static BinaryWriter TNet.TNManager.BeginSend ( Packet  type)
static

Begin sending a new packet to the server.

static BinaryWriter TNet.TNManager.BeginSend ( byte  packetID)
static

Begin sending a new packet to the server.

static void TNet.TNManager.CloseChannel ( )
static

Close the channel the player is in. New players will be prevented from joining. Once a channel has been closed, it cannot be re-opened.

static void TNet.TNManager.CloseChannel ( int  channelID)
static

Close the channel the player is in. New players will be prevented from joining. Once a channel has been closed, it cannot be re-opened.

static void TNet.TNManager.Connect ( )
static

Connect to a local server.

static void TNet.TNManager.Connect ( string  address)
static

Connect to the specified destination with the address and port specified as "255.255.255.255:255".

static void TNet.TNManager.Connect ( string  address,
int  port 
)
static

Connect to the specified destination.

static void TNet.TNManager.Connect ( IPEndPoint  externalIP,
IPEndPoint  internalIP 
)
static

Connect to the specified remote destination.

static void TNet.TNManager.CreateChannel ( string  levelName,
bool  persistent,
int  playerLimit,
string  password,
bool  leaveCurrentChannel = true 
)
static

Create a new channel.

Parameters
levelNameLevel that will be loaded first.
persistentWhether the channel will remain active even when the last player leaves.
playerLimitMaximum number of players that can be in this channel at once.
passwordPassword for the channel. First player sets the password.
static void TNet.TNManager.DeleteChannel ( int  id,
bool  disconnect 
)
static

Delete the specified channel.

static void TNet.TNManager.DeleteFile ( string  filename)
static

Delete the specified file on the server.

static void TNet.TNManager.Destroy ( GameObject  go)
static
static void TNet.TNManager.Disconnect ( )
static

Disconnect from the specified destination.

static void TNet.TNManager.EndSend ( )
static

Send the outgoing buffer. This should only be used for generic packets going straight to the server. Packets that are going to a channel should use EndSend(channelID, reliable) function instead.

static void TNet.TNManager.EndSend ( int  channelID,
bool  reliable = true 
)
static

Send the outgoing buffer.

static void TNet.TNManager.EndSend ( IPEndPoint  target)
static

Broadcast the packet to the specified endpoint via UDP.

static void TNet.TNManager.EndSend ( bool  reliable)
static
static void TNet.TNManager.EndSendToLAN ( int  port)
static

Broadcast the packet to everyone on the LAN.

static Player TNet.TNManager.FindPlayer ( string  name)
static

Find the player associated with the specified partial name. This function is not case sensitive, so calling it with "Ren" will return "Aren Mook" as a possible choice.

static Channel TNet.TNManager.GetChannel ( int  channelID)
static

Return a channel with the specified ID. This will only work as long as the player is in this channel.

static DataNode TNet.TNManager.GetChannelData ( string  key)
static

Convenience method: Retrieve the specified channel option.

static DataNode TNet.TNManager.GetChannelData ( int  channelID,
string  key 
)
static

Convenience method: Retrieve the specified channel option.

static T TNet.TNManager.GetChannelData< T > ( string  key)
static

Convenience method: Retrieve the specified channel option.

static T TNet.TNManager.GetChannelData< T > ( string  key,
def 
)
static

Convenience method: Retrieve the specified channel option.

static T TNet.TNManager.GetChannelData< T > ( int  channelID,
string  key 
)
static

Convenience method: Retrieve the specified channel option.

static T TNet.TNManager.GetChannelData< T > ( int  channelID,
string  key,
def 
)
static

Convenience method: Retrieve the specified channel option.

static void TNet.TNManager.GetChannelList ( GameClient.OnGetChannels  callback)
static

Get a list of channels from the server.

static Player TNet.TNManager.GetHost ( int  channelID)
static

Get the player hosting the specified channel. Only works for the channels the player is in.

static Player TNet.TNManager.GetPlayer ( int  id)
static

Get the player associated with the specified ID.

static Player TNet.TNManager.GetPlayer ( string  name)
static

Get the player associated with the specified name.

static DataNode TNet.TNManager.GetPlayerData ( string  path)
static

Get our player's data.

static T TNet.TNManager.GetPlayerData< T > ( string  path)
static

Convenience method: Get the specified value from our player.

static T TNet.TNManager.GetPlayerData< T > ( string  path,
defaultVal 
)
static

Convenience method: Get the specified value from our player.

static List<Player> TNet.TNManager.GetPlayers ( int  channelID)
static

Get a list of players under the specified channel. This will only work for channels the player has joined. The returned list will not include TNManager.player.

static DataNode TNet.TNManager.GetServerData ( string  key)
static

Retrieve the specified server option.

static T TNet.TNManager.GetServerData< T > ( string  key)
static

Retrieve the specified server option.

static T TNet.TNManager.GetServerData< T > ( string  key,
def 
)
static

Retrieve the specified server option.

static DataNode TNet.TNManager.GetServerOption ( string  key)
static
static T TNet.TNManager.GetServerOption< T > ( string  key)
static
static T TNet.TNManager.GetServerOption< T > ( string  key,
def 
)
static
static int TNet.TNManager.IndexOf ( GameObject  go)
static

Find the index of the specified game object.

static void TNet.TNManager.Instantiate ( int  rccID,
string  path,
bool  persistent,
params object[]  objs 
)
static

Create a packet that will send a custom object creation call. Instantiate a new game object in the current channel on all connected players.

static void TNet.TNManager.Instantiate ( string  funcName,
string  path,
bool  persistent,
params object[]  objs 
)
static

Create a packet that will send a custom object creation call. Instantiate a new game object in the current channel on all connected players.

static void TNet.TNManager.Instantiate ( int  channelID,
int  rccID,
string  path,
bool  persistent,
params object[]  objs 
)
static

Create a packet that will send a custom object creation call. Instantiate a new game object in the specified channel on all connected players.

static void TNet.TNManager.Instantiate ( int  channelID,
string  funcName,
string  path,
bool  persistent,
params object[]  objs 
)
static

Create a packet that will send a custom object creation call. Instantiate a new game object in the specified channel on all connected players.

static bool TNet.TNManager.IsChannelLocked ( int  channelID)
static

Whether the specified channel is currently locked.

static bool TNet.TNManager.IsHosting ( int  channelID)
static

Whether the player is hosting this channel.

static bool TNet.TNManager.IsInChannel ( int  channelID)
static

Check to see if we are currently in the specified channel.

delegate bool TNet.TNManager.IsJoiningChannelFunc ( int  channelID)
static void TNet.TNManager.JoinChannel ( int  channelID,
bool  persistent = false,
bool  leaveCurrentChannel = false 
)
static

Join the specified channel.

Parameters
channelIDID of the channel. Every player joining this channel will see one another.
persistentWhether the channel will remain active even when the last player leaves.
static void TNet.TNManager.JoinChannel ( int  channelID,
string  levelName,
bool  leaveCurrentChannel = true 
)
static

Join the specified channel. This channel will be marked as persistent, meaning it will stay open even when the last player leaves, unless explicitly closed first.

Parameters
channelIDID of the channel. Every player joining this channel will see one another.
levelNameLevel that will be loaded first.
static void TNet.TNManager.JoinChannel ( int  channelID,
string  levelName,
bool  persistent,
int  playerLimit,
string  password,
bool  leaveCurrentChannel = true 
)
static

Join the specified channel.

Parameters
channelIDID of the channel. Every player joining this channel will see one another.
levelNameLevel that will be loaded first.
persistentWhether the channel will remain active even when the last player leaves.
playerLimitMaximum number of players that can be in this channel at once.
passwordPassword for the channel. First player sets the password.
static void TNet.TNManager.JoinRandomChannel ( string  levelName,
bool  persistent,
int  playerLimit,
string  password,
bool  leaveCurrentChannel = true 
)
static

Join a random open game channel or create a new one. Guaranteed to load the specified level.

Parameters
levelNameLevel that will be loaded first.
persistentWhether the channel will remain active even when the last player leaves.
playerLimitMaximum number of players that can be in this channel at once.
passwordPassword for the channel. First player sets the password.
static void TNet.TNManager.LeaveAllChannels ( )
static

Leave all of the channels we're currently in.

static void TNet.TNManager.LeaveChannel ( )
static

Leave the channel we're in.

static void TNet.TNManager.LeaveChannel ( int  channelID)
static

Leave the channel we're in.

static void TNet.TNManager.LoadFile ( string  filename,
GameClient.OnLoadFile  callback 
)
static

Load the specified file residing on the server.

static void TNet.TNManager.LoadLevel ( string  levelName)
static

Load the specified level.

static void TNet.TNManager.LoadLevel ( int  channelID,
string  levelName 
)
static

Load the specified level.

delegate AsyncOperation TNet.TNManager.LoadSceneAsyncFunc ( string  levelName)
delegate void TNet.TNManager.LoadSceneFunc ( string  levelName)
static void TNet.TNManager.LockChannel ( bool  locked)
static

Lock the channel the player is currently in.

static void TNet.TNManager.LockChannel ( int  channelID,
bool  locked 
)
static

Lock the specified channel, preventing all future persistent RFCs from being saved.

static void TNet.TNManager.Log ( string  text)
static

Write a server log entry.

static void TNet.TNManager.Ping ( IPEndPoint  udpEndPoint,
TNEvents.OnPing  callback 
)
static

Send a remote ping request to the specified TNet server.

delegate void TNet.TNManager.ProcessPacketsFunc ( )
static byte [] TNet.TNManager.ReadCache ( string  path)
static

Read the specified file from the cache belonging to the connected server.

static void TNet.TNManager.RemoveAdmin ( string  passKey)
static

Remove the specified pass key from the admin file.

static void TNet.TNManager.ResetPacketCount ( )
static

Immediately reset the packet count. Calling this isn't necessary as they get updated once per second anyway.

static void TNet.TNManager.SaveFile ( string  filename,
byte[]  data 
)
static

Save the specified file on the server.

static void TNet.TNManager.SetAdmin ( string  passKey)
static

Set administrator privileges. Note that failing the password test will cause a disconnect.

static void TNet.TNManager.SetAlias ( string  alias)
static

Set a player alias. Player aliases can be used to store useful player-associated data such as Steam usernames, database IDs, or other unique identifiers. Aliases will show up in TNet's log and can also be banned by on the server side. When a player is banned, all their aliases are banned as well, so be careful to make sure that they are indeed unique. All aliases are visible via TNet.Player.aliases list of each player.

static void TNet.TNManager.SetChannelData ( string  key,
object  val 
)
static

Set the specified channel option.

static void TNet.TNManager.SetChannelData ( int  channelID,
string  key,
object  val 
)
static

Set the specified channel option.

static void TNet.TNManager.SetChannelOption ( DataNode  node)
static
static void TNet.TNManager.SetHost ( Player  player)
static

Change the hosting player.

static void TNet.TNManager.SetHost ( int  channelID,
Player  player 
)
static

Change the hosting player.

static void TNet.TNManager.SetPacketHandler ( byte  packetID,
GameClient.OnPacket  callback 
)
static

Set the following function to handle this type of packets.

static void TNet.TNManager.SetPacketHandler ( Packet  packet,
GameClient.OnPacket  callback 
)
static

Set the following function to handle this type of packets.

static void TNet.TNManager.SetPlayerData ( string  path,
object  val 
)
static

Set the specified value on our player.

static void TNet.TNManager.SetPlayerData ( string  text)
static

Set the specified value on our player using key = value notation.

static void TNet.TNManager.SetPlayerLimit ( int  max)
static

Change the maximum number of players that can join the channel the player is currently in.

static void TNet.TNManager.SetPlayerLimit ( int  channelID,
int  max 
)
static

Change the maximum number of players that can join the channel the player is currently in.

static void TNet.TNManager.SetPlayerSave ( string  filename,
DataNode.SaveType  type = DataNode.SaveType.Binary 
)
static

Specify where the player's data should be saved. You only need to call this function once and TNet will automatically save the player file for you every time you use TNManager.SetPlayerData afterwards.

static void TNet.TNManager.SetServerData ( string  text)
static

Set the specified server option using key = value notation.

static void TNet.TNManager.SetServerData ( DataNode  node)
static

Set the specified server option.

static void TNet.TNManager.SetServerData ( string  key,
object  val 
)
static

Set the specified server option.

static void TNet.TNManager.SetServerOption ( string  text)
static
static void TNet.TNManager.SetServerOption ( string  key,
object  val 
)
static
static void TNet.TNManager.SetServerOption ( DataNode  node)
static
static void TNet.TNManager.SetTimeout ( int  seconds)
static

Set the timeout for the player. By default it's 10 seconds. If you know you are about to load a large level, and it's going to take, say 60 seconds, set this timeout to 120 seconds just to be safe. When the level finishes loading, change this back to 10 seconds so that dropped connections gets detected correctly.

static bool TNet.TNManager.StartUDP ( int  udpPort)
static

Start listening for incoming UDP packets on the specified port.

static void TNet.TNManager.StopUDP ( )
static

Stop listening to incoming UDP packets.

static bool TNet.TNManager.WriteCache ( string  path,
byte[]  data,
bool  inMyDocuments = false 
)
static

Write the specified data into a local cache file belonging to connected server.

Member Data Documentation

IsJoiningChannelFunc TNet.TNManager.IsJoiningChannel
static
Initial value:
= delegate(int channelID)
{
if (mInstance == null) return false;
if (channelID < 0)
{
return (mInstance.mLoadingLevel.size != 0 || mInstance.mClient.isJoiningChannel);
}
return mInstance.mLoadingLevel.Contains(channelID) || mInstance.mClient.IsJoiningChannel(channelID);
}

Whether we are currently trying to join the specified channel.

bool TNet.TNManager.isPaused = false
static

Whether the application is currently paused.

int TNet.TNManager.lastChannelID = 0
static

ID of the channel the player is in. Note that if used while the player is in more than one channel, a warning will be shown.

AsyncOperation TNet.TNManager.loadLevelOperation = null
static

When a level is being loaded, this value will contain the async coroutine for the LoadLevel operation. You can yield on it if you need.

LoadSceneFunc TNet.TNManager.LoadScene
static
Initial value:
= delegate(string levelName)
{
if (!string.IsNullOrEmpty(levelName))
{
UnityEngine.SceneManagement.SceneManager.LoadScene(levelName);
}
}

Load the chosen scene.

LoadSceneAsyncFunc TNet.TNManager.LoadSceneAsync
static
Initial value:
= delegate(string levelName)
{
if (!string.IsNullOrEmpty(levelName))
{
return UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(levelName);
}
return null;
}

Load the chosen scene asynchronously.

GameObject [] TNet.TNManager.objects

List of objects that can be instantiated by the network.

ProcessPacketsFunc TNet.TNManager.ProcessPackets
static
Initial value:
= delegate()
{
if (mInstance != null && mInstance.mLoadingLevel.size == 0)
{
mInstance.mClient.ProcessPackets();
}
}

If you want to do custom logic for when packets can be processed and when they can't be, overwrite this delegate.

bool TNet.TNManager.rebuildMethodList = true
static

If set to 'true', the list of custom creation functions will be rebuilt the next time it's accessed.

Property Documentation

bool TNet.TNManager.canUseUDP
staticget

Whether we can use unreliable packets (UDP) to communicate with the server.

string TNet.TNManager.channelData
staticgetset
int TNet.TNManager.channelID
staticget
List<Channel> TNet.TNManager.channels
staticget

List of channels the player is currently in.

GameClient TNet.TNManager.client
staticget

TNet Client used for communication.

int TNet.TNManager.hostID
staticget
bool TNet.TNManager.isActive
staticgetset

You can pause TNManager's message processing if you like. This happens automatically when a scene is being loaded.

bool TNet.TNManager.isAdmin
staticget

Whether the player has verified himself as an administrator.

bool TNet.TNManager.isChannelLocked
staticget
bool TNet.TNManager.isConnected
staticget

Whether we're currently connected.

bool TNet.TNManager.isHosting
staticget

Whether we're currently hosting. Note that this should only be used if the player is in only one channel.

bool TNet.TNManager.isInChannel
staticget

Whether we're currently in any channel. To find out if we are in a specific channel, use TNManager.IsInChannel(id).

bool TNet.TNManager.isJoiningChannel
staticget

Whether we are currently in the process of joining a channel. To find out whether we are joining a specific channel, use the "IsJoiningChannel(id)" function.

bool TNet.TNManager.isTryingToConnect
staticget

Whether we are currently trying to establish a new connection.

int TNet.TNManager.listeningPort
staticget

Listening port for incoming UDP packets. Set via TNManager.StartUDP().

bool TNet.TNManager.noDelay
staticgetset

Enable or disable the Nagle's buffering algorithm (aka NO_DELAY flag). Enabling this flag will improve latency at the cost of increased bandwidth. http://en.wikipedia.org/wiki/Nagle's_algorithm

TNEvents.OnConnect TNet.TNManager.onConnect
staticgetset

Connection attempt result indicating success or failure.

TNEvents.OnDisconnect TNet.TNManager.onDisconnect
staticgetset

Notification sent after the connection terminates for any reason.

TNEvents.OnError TNet.TNManager.onError
staticgetset

Error notification.

TNEvents.OnHostChanged TNet.TNManager.onHostChanged
staticgetset

Notification sent when the channel's host changes.

TNEvents.OnJoinChannel TNet.TNManager.onJoinChannel
staticgetset

Notification sent when attempting to join a channel, indicating a success or failure.

TNEvents.OnLeaveChannel TNet.TNManager.onLeaveChannel
staticgetset

Notification sent when leaving a channel for any reason, including being disconnected.

TNEvents.OnLoadLevel TNet.TNManager.onLoadLevel
staticgetset

Notification sent when changing levels.

TNEvents.OnLockChannel TNet.TNManager.onLockChannel
staticgetset

Callback triggered when the channel becomes locked or unlocked.

TNEvents.OnPing TNet.TNManager.onPing
staticgetset

Ping notification.

TNEvents.OnPlayerJoin TNet.TNManager.onPlayerJoin
staticgetset

Notification sent when a new player joins the channel.

TNEvents.OnPlayerLeave TNet.TNManager.onPlayerLeave
staticgetset

Notification sent when a player leaves the channel.

TNEvents.OnRenamePlayer TNet.TNManager.onRenamePlayer
staticgetset

Notification of some player changing their name.

TNEvents.OnSetAdmin TNet.TNManager.onSetAdmin
staticgetset

Callback triggered when the player gets verified as an administrator.

TNEvents.OnSetChannelData TNet.TNManager.onSetChannelData
staticgetset

Notification sent when the channel's data gets changed.

TNEvents.OnSetPlayerData TNet.TNManager.onSetPlayerData
staticgetset

Notification sent when player data gets changed.

TNEvents.OnSetServerData TNet.TNManager.onSetServerData
staticgetset

Notification sent when the server's data gets changed.

IPEndPoint TNet.TNManager.packetSource
staticget
int TNet.TNManager.packetSourceID
staticget

Forward and Create type packets write down their source. If the packet was sent by the server instead of another player, the ID will be 0.

IPEndPoint TNet.TNManager.packetSourceIP
staticget

Address from which the packet was received. Only available during packet processing callbacks. If null, then the packet arrived via the active connection (TCP). If the return value is not null, then the last packet arrived via UDP.

int TNet.TNManager.ping
staticget

Current ping to the server.

long TNet.TNManager.playedTime
staticget

Player's /played time in seconds. This value is automatically tracked by the server and is saved as a part of the player file.

Player TNet.TNManager.player
staticget

Get the local player.

DataNode TNet.TNManager.playerData
staticgetset

Get or set the player's data, synchronizing it with the server. To change the data, use TNManager.SetPlayerData instead of changing the content directly.

DataNode TNet.TNManager.playerDataNode
staticget
int TNet.TNManager.playerID
staticget

The player's unique identifier.

string TNet.TNManager.playerName
staticgetset

Get or set the player's name as everyone sees him on the network.

List<Player> TNet.TNManager.players
staticget

List of other players in the same channel as the client. This list does not include TNManager.player.

int TNet.TNManager.receivedPackets
staticget

How many packets have been received in the last second.

int TNet.TNManager.sentPackets
staticget

How many packets were sent in the last second.

DataNode TNet.TNManager.serverData
staticgetset

Server configuration is set by administrators. In most cases you should use GetServerData and SetServerData functions instead.

DataNode TNet.TNManager.serverOptions
staticget
long TNet.TNManager.serverTime
staticget

Current time on the server in milliseconds.

long TNet.TNManager.serverUptime
staticget

Server's uptime in milliseconds.

IPEndPoint TNet.TNManager.tcpEndPoint
staticget

TCP end point, available only if we're actually connected to the server.

double TNet.TNManager.time
staticget

Time elapsed either since the server has been started up in seconds, or (if not connected) – time since TNManager was first used. It's a more precise version of Unity's Time.time, since it takes a mere 3 hours for float precision to start dropping milliseconds.


The documentation for this class was generated from the following file: