Photon Unity Networking
v1.81
|
Central class of the Photon Chat API to connect, handle channels and messages. More...
Inherits IPhotonPeerListener.
Public Member Functions | |
bool | CanChatInChannel (string channelName) |
ChatClient (IChatClientListener listener, ConnectionProtocol protocol=ConnectionProtocol.Udp) | |
bool | Connect (string appId, string appVersion, AuthenticationValues authValues) |
Connects this client to the Photon Chat Cloud service, which will also authenticate the user (and set a UserId). More... | |
void | Service () |
Must be called regularly to keep connection between client and server alive and to process incoming messages. More... | |
void | Disconnect () |
void | StopThread () |
bool | Subscribe (string[] channels) |
Sends operation to subscribe to a list of channels by name. More... | |
bool | Subscribe (string[] channels, int messagesFromHistory) |
Sends operation to subscribe client to channels, optionally fetching a number of messages from the cache. More... | |
bool | Unsubscribe (string[] channels) |
Unsubscribes from a list of channels, which stops getting messages from those. More... | |
bool | PublishMessage (string channelName, object message) |
Sends a message to a public channel which this client subscribed to. More... | |
bool | SendPrivateMessage (string target, object message) |
Sends a private message to a single target user. Calls OnPrivateMessage on the receiving client. More... | |
bool | SendPrivateMessage (string target, object message, bool encrypt) |
Sends a private message to a single target user. Calls OnPrivateMessage on the receiving client. More... | |
bool | SetOnlineStatus (int status) |
Sets the user's status without changing your status-message. More... | |
bool | SetOnlineStatus (int status, object message) |
Sets the user's status without changing your status-message. More... | |
bool | AddFriends (string[] friends) |
Adds friends to a list on the Chat Server which will send you status updates for those. More... | |
bool | RemoveFriends (string[] friends) |
Removes the provided entries from the list on the Chat Server and stops their status updates. More... | |
string | GetPrivateChannelNameByUser (string userName) |
Get you the (locally used) channel name for the chat between this client and another user. More... | |
bool | TryGetChannel (string channelName, bool isPrivate, out ChatChannel channel) |
Simplified access to either private or public channels by name. More... | |
bool | TryGetChannel (string channelName, out ChatChannel channel) |
Simplified access to all channels by name. Checks public channels first, then private ones. More... | |
void | SendAcksOnly () |
Public Attributes | |
int | MessageLimit |
If greater than 0, new channels will limit the number of messages they cache locally. More... | |
readonly Dictionary< string, ChatChannel > | PublicChannels |
readonly Dictionary< string, ChatChannel > | PrivateChannels |
ChatPeer | chatPeer = null |
Properties | |
string | NameServerAddress [get, set] |
The address of last connected Name Server. More... | |
string | FrontendAddress [get, set] |
The address of the actual chat server assigned from NameServer. Public for read only. More... | |
string | ChatRegion [get, set] |
Settable only before you connect! Defaults to "EU". More... | |
ChatState | State [get, set] |
Current state of the ChatClient. Also use CanChat. More... | |
ChatDisconnectCause | DisconnectedCause [get, set] |
bool | CanChat [get] |
string | AppVersion [get, set] |
The version of your client. A new version also creates a new "virtual app" to separate players from older client versions. More... | |
string | AppId [get, set] |
The AppID as assigned from the Photon Cloud. If you host yourself, this is the "regular" Photon Server Application Name (most likely: "LoadBalancing"). More... | |
AuthenticationValues | AuthValues [get, set] |
Settable only before you connect! More... | |
string | UserId [get, set] |
The unique ID of a user/person, stored in AuthValues.UserId. Set it before you connect. More... | |
DebugLevel | DebugOut [get, set] |
Sets the level (and amount) of debug output provided by the library. More... | |
Detailed Description
Central class of the Photon Chat API to connect, handle channels and messages.
This class must be instantiated with a IChatClientListener instance to get the callbacks. Integrate it into your game loop by calling Service regularly. Call Connect with an AppId that is setup as Photon Chat application. Note: Connect covers multiple messages between this client and the servers. A short workflow will connect you to a chat server.
Each ChatClient resembles a user in chat (set in Connect). Each user automatically subscribes a channel for incoming private messages and can message any other user privately. Before you publish messages in any non-private channel, that channel must be subscribed.
PublicChannels is a list of subscribed channels, containing messages and senders. PrivateChannels contains all incoming and sent private messages.
Constructor & Destructor Documentation
ExitGames.Client.Photon.Chat.ChatClient.ChatClient | ( | IChatClientListener | listener, |
ConnectionProtocol | protocol = ConnectionProtocol.Udp |
||
) |
Member Function Documentation
bool ExitGames.Client.Photon.Chat.ChatClient.AddFriends | ( | string[] | friends | ) |
Adds friends to a list on the Chat Server which will send you status updates for those.
AddFriends and RemoveFriends enable clients to handle their friend list in the Photon Chat server. Having users on your friends list gives you access to their current online status (and whatever info your client sets in it).
Each user can set an online status consisting of an integer and an arbitratry (serializable) object. The object can be null, Hashtable, object[] or anything else Photon can serialize.
The status is published automatically to friends (anyone who set your user ID with AddFriends).
Photon flushes friends-list when a chat client disconnects, so it has to be set each time. If your community API gives you access to online status already, you could filter and set online friends in AddFriends.
Actual friend relations are not persistent and have to be stored outside of Photon.
- Parameters
-
friends Array of friend userIds.
- Returns
- If the operation could be sent.
bool ExitGames.Client.Photon.Chat.ChatClient.CanChatInChannel | ( | string | channelName | ) |
bool ExitGames.Client.Photon.Chat.ChatClient.Connect | ( | string | appId, |
string | appVersion, | ||
AuthenticationValues | authValues | ||
) |
Connects this client to the Photon Chat Cloud service, which will also authenticate the user (and set a UserId).
- Parameters
-
appId Get your Photon Chat AppId from the Dashboard. appVersion Any version string you make up. Used to separate users and variants of your clients, which might be incompatible. authValues Values for authentication. You can leave this null, if you set a UserId before. If you set authValues, they will override any UserId set before.
- Returns
void ExitGames.Client.Photon.Chat.ChatClient.Disconnect | ( | ) |
string ExitGames.Client.Photon.Chat.ChatClient.GetPrivateChannelNameByUser | ( | string | userName | ) |
Get you the (locally used) channel name for the chat between this client and another user.
- Parameters
-
userName Remote user's name or UserId.
- Returns
- The (locally used) channel name for a private channel.
bool ExitGames.Client.Photon.Chat.ChatClient.PublishMessage | ( | string | channelName, |
object | message | ||
) |
Sends a message to a public channel which this client subscribed to.
Before you publish to a channel, you have to subscribe it. Everyone in that channel will get the message.
- Parameters
-
channelName Name of the channel to publish to. message Your message (string or any serializable data).
- Returns
- False if the client is not yet ready to send messages.
bool ExitGames.Client.Photon.Chat.ChatClient.RemoveFriends | ( | string[] | friends | ) |
Removes the provided entries from the list on the Chat Server and stops their status updates.
Photon flushes friends-list when a chat client disconnects. Unless you want to remove individual entries, you don't have to RemoveFriends.
AddFriends and RemoveFriends enable clients to handle their friend list in the Photon Chat server. Having users on your friends list gives you access to their current online status (and whatever info your client sets in it).
Each user can set an online status consisting of an integer and an arbitratry (serializable) object. The object can be null, Hashtable, object[] or anything else Photon can serialize.
The status is published automatically to friends (anyone who set your user ID with AddFriends).
Photon flushes friends-list when a chat client disconnects, so it has to be set each time. If your community API gives you access to online status already, you could filter and set online friends in AddFriends.
Actual friend relations are not persistent and have to be stored outside of Photon.
AddFriends and RemoveFriends enable clients to handle their friend list in the Photon Chat server. Having users on your friends list gives you access to their current online status (and whatever info your client sets in it).
Each user can set an online status consisting of an integer and an arbitratry (serializable) object. The object can be null, Hashtable, object[] or anything else Photon can serialize.
The status is published automatically to friends (anyone who set your user ID with AddFriends).
Actual friend relations are not persistent and have to be stored outside of Photon.
- Parameters
-
friends Array of friend userIds.
- Returns
- If the operation could be sent.
void ExitGames.Client.Photon.Chat.ChatClient.SendAcksOnly | ( | ) |
bool ExitGames.Client.Photon.Chat.ChatClient.SendPrivateMessage | ( | string | target, |
object | message | ||
) |
Sends a private message to a single target user. Calls OnPrivateMessage on the receiving client.
- Parameters
-
target Username to send this message to. message The message you want to send. Can be a simple string or anything serializable.
- Returns
- True if this clients can send the message to the server.
bool ExitGames.Client.Photon.Chat.ChatClient.SendPrivateMessage | ( | string | target, |
object | message, | ||
bool | encrypt | ||
) |
Sends a private message to a single target user. Calls OnPrivateMessage on the receiving client.
- Parameters
-
target Username to send this message to. message The message you want to send. Can be a simple string or anything serializable. encrypt Optionally, private messages can be encrypted. Encryption is not end-to-end as the server decrypts the message.
- Returns
- True if this clients can send the message to the server.
void ExitGames.Client.Photon.Chat.ChatClient.Service | ( | ) |
Must be called regularly to keep connection between client and server alive and to process incoming messages.
This method limits the effort it does automatically using the private variable msDeltaForServiceCalls. That value is lower for connect and multiplied by 4 when chat-server connection is ready.
bool ExitGames.Client.Photon.Chat.ChatClient.SetOnlineStatus | ( | int | status | ) |
Sets the user's status without changing your status-message.
The predefined status values can be found in class ChatUserStatus. State ChatUserStatus.Invisible will make you offline for everyone and send no message.
You can set custom values in the status integer. Aside from the pre-configured ones, all states will be considered visible and online. Else, no one would see the custom state.
This overload does not change the set message.
- Parameters
-
status Predefined states are in class ChatUserStatus. Other values can be used at will.
- Returns
- True if the operation gets called on the server.
bool ExitGames.Client.Photon.Chat.ChatClient.SetOnlineStatus | ( | int | status, |
object | message | ||
) |
Sets the user's status without changing your status-message.
The predefined status values can be found in class ChatUserStatus. State ChatUserStatus.Invisible will make you offline for everyone and send no message.
You can set custom values in the status integer. Aside from the pre-configured ones, all states will be considered visible and online. Else, no one would see the custom state.
The message object can be anything that Photon can serialize, including (but not limited to) Hashtable, object[] and string. This value is defined by your own conventions.
- Parameters
-
status Predefined states are in class ChatUserStatus. Other values can be used at will. message Also sets a status-message which your friends can get.
- Returns
- True if the operation gets called on the server.
void ExitGames.Client.Photon.Chat.ChatClient.StopThread | ( | ) |
bool ExitGames.Client.Photon.Chat.ChatClient.Subscribe | ( | string[] | channels | ) |
Sends operation to subscribe to a list of channels by name.
- Parameters
-
channels List of channels to subscribe to. Avoid null or empty values.
- Returns
- If the operation could be sent at all (Example: Fails if not connected to Chat Server).
bool ExitGames.Client.Photon.Chat.ChatClient.Subscribe | ( | string[] | channels, |
int | messagesFromHistory | ||
) |
Sends operation to subscribe client to channels, optionally fetching a number of messages from the cache.
Subscribes channels will forward new messages to this user. Use PublishMessage to do so. The messages cache is limited but can be useful to get into ongoing conversations, if that's needed.
- Parameters
-
channels List of channels to subscribe to. Avoid null or empty values. messagesFromHistory 0: no history. 1 and higher: number of messages in history. -1: all available history.
- Returns
- If the operation could be sent at all (Example: Fails if not connected to Chat Server).
bool ExitGames.Client.Photon.Chat.ChatClient.TryGetChannel | ( | string | channelName, |
bool | isPrivate, | ||
out ChatChannel | channel | ||
) |
Simplified access to either private or public channels by name.
- Parameters
-
channelName Name of the channel to get. For private channels, the channel-name is composed of both user's names. isPrivate Define if you expect a private or public channel. channel Out parameter gives you the found channel, if any.
- Returns
- True if the channel was found.
bool ExitGames.Client.Photon.Chat.ChatClient.TryGetChannel | ( | string | channelName, |
out ChatChannel | channel | ||
) |
Simplified access to all channels by name. Checks public channels first, then private ones.
- Parameters
-
channelName Name of the channel to get. channel Out parameter gives you the found channel, if any.
- Returns
- True if the channel was found.
bool ExitGames.Client.Photon.Chat.ChatClient.Unsubscribe | ( | string[] | channels | ) |
Unsubscribes from a list of channels, which stops getting messages from those.
The client will remove these channels from the PublicChannels dictionary once the server sent a response to this request.
The request will be sent to the server and IChatClientListener.OnUnsubscribed gets called when the server actually removed the channel subscriptions.
Unsubscribe will fail if you include null or empty channel names.
- Parameters
-
channels Names of channels to unsubscribe.
- Returns
- False, if not connected to a chat server.
Member Data Documentation
ChatPeer ExitGames.Client.Photon.Chat.ChatClient.chatPeer = null |
int ExitGames.Client.Photon.Chat.ChatClient.MessageLimit |
If greater than 0, new channels will limit the number of messages they cache locally.
This can be useful to limit the amount of memory used by chats. You can set a MessageLimit per channel but this value gets applied to new ones.
Note: Changing this value, does not affect ChatChannels that are already in use!
readonly Dictionary<string, ChatChannel> ExitGames.Client.Photon.Chat.ChatClient.PrivateChannels |
readonly Dictionary<string, ChatChannel> ExitGames.Client.Photon.Chat.ChatClient.PublicChannels |
Property Documentation
|
getset |
|
getset |
The version of your client. A new version also creates a new "virtual app" to separate players from older client versions.
|
getset |
Settable only before you connect!
|
get |
|
getset |
Settable only before you connect! Defaults to "EU".
|
getset |
Sets the level (and amount) of debug output provided by the library.
This affects the callbacks to IChatClientListener.DebugReturn. Default Level: Error.
|
getset |
|
getset |
The address of the actual chat server assigned from NameServer. Public for read only.
|
getset |
The address of last connected Name Server.
|
getset |
Current state of the ChatClient. Also use CanChat.
|
getset |
The unique ID of a user/person, stored in AuthValues.UserId. Set it before you connect.
This value wraps AuthValues.UserId. It's not a nickname and we assume users with the same userID are the same person.