Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Assets/Photon/PhotonChat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Photon/PhotonChat/Code.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChannelCreationOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ----------------------------------------------------------------------------------------------------------------------
// <summary>The Photon Chat Api enables clients to connect to a chat server and communicate with other clients.</summary>
// <remarks>ChannelCreationOptions is a parameter used when subscribing to a public channel for the first time.</remarks>
// <copyright company="Exit Games GmbH">Photon Chat Api - Copyright (C) 2018 Exit Games GmbH</copyright>
// ----------------------------------------------------------------------------------------------------------------------

namespace Photon.Chat
{
public class ChannelCreationOptions
{
/// <summary>Default values of channel creation options.</summary>
public static ChannelCreationOptions Default = new ChannelCreationOptions();
/// <summary>Whether or not the channel to be created will allow client to keep a list of users.</summary>
public bool PublishSubscribers { get; set; }
/// <summary>Limit of the number of users subscribed to the channel to be created.</summary>
public int MaxSubscribers { get; set; }

#if CHAT_EXTENDED
public System.Collections.Generic.Dictionary<string, object> CustomProperties { get; set; }
#endif
}
}
12 changes: 12 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChannelCreationOptions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChannelWellKnownProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ----------------------------------------------------------------------------------------------------------------------
// <summary>The Photon Chat Api enables clients to connect to a chat server and communicate with other clients.</summary>
// <remarks>ChannelWellKnownProperties contains the list of well-known channel properties.</remarks>
// <copyright company="Exit Games GmbH">Photon Chat Api - Copyright (C) 2018 Exit Games GmbH</copyright>
// ----------------------------------------------------------------------------------------------------------------------

namespace Photon.Chat
{
public class ChannelWellKnownProperties
{
public const byte MaxSubscribers = 255;
public const byte PublishSubscribers = 254;
}
}
12 changes: 12 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChannelWellKnownProperties.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChatAppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// -----------------------------------------------------------------------
// <copyright file="ChatAppSettings.cs" company="Exit Games GmbH">
// Chat API for Photon - Copyright (C) 2018 Exit Games GmbH
// </copyright>
// <summary>Settings for Photon Chat application and the server to connect to.</summary>
// <author>[email protected]</author>
// ----------------------------------------------------------------------------

#if UNITY_4_7 || UNITY_5 || UNITY_5_3_OR_NEWER
#define SUPPORTED_UNITY
#endif


namespace Photon.Chat
{
using System;
using ExitGames.Client.Photon;
#if SUPPORTED_UNITY
using UnityEngine.Serialization;
#endif

/// <summary>
/// Settings for Photon application(s) and the server to connect to.
/// </summary>
/// <remarks>
/// This is Serializable for Unity, so it can be included in ScriptableObject instances.
/// </remarks>
#if !NETFX_CORE || SUPPORTED_UNITY
[Serializable]
#endif
public class ChatAppSettings
{
/// <summary>AppId for the Chat Api.</summary>
#if SUPPORTED_UNITY
[FormerlySerializedAs("AppId")]
#endif
public string AppIdChat;

/// <summary>The AppVersion can be used to identify builds and will split the AppId distinct "Virtual AppIds" (important for the users to find each other).</summary>
public string AppVersion;

/// <summary>Can be set to any of the Photon Cloud's region names to directly connect to that region.</summary>
public string FixedRegion;

/// <summary>The address (hostname or IP) of the server to connect to.</summary>
public string Server;

/// <summary>If not null, this sets the port of the first Photon server to connect to (that will "forward" the client as needed).</summary>
public ushort Port;

/// <summary>The network level protocol to use.</summary>
public ConnectionProtocol Protocol = ConnectionProtocol.Udp;

/// <summary>Enables a fallback to another protocol in case a connect to the Name Server fails.</summary>
/// <remarks>See: LoadBalancingClient.EnableProtocolFallback.</remarks>
public bool EnableProtocolFallback = true;

/// <summary>Log level for the network lib.</summary>
public DebugLevel NetworkLogging = DebugLevel.ERROR;

/// <summary>If true, the default nameserver address for the Photon Cloud should be used.</summary>
public bool IsDefaultNameServer { get { return string.IsNullOrEmpty(this.Server); } }


/// <summary>Available to not immediately break compatibility.</summary>
[Obsolete("Use AppIdChat instead.")]
public string AppId
{
get { return this.AppIdChat; }
set { this.AppIdChat = value; }
}
}
}
11 changes: 11 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChatAppSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

193 changes: 193 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChatChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// ----------------------------------------------------------------------------------------------------------------------
// <summary>The Photon Chat Api enables clients to connect to a chat server and communicate with other clients.</summary>
// <remarks>ChatClient is the main class of this api.</remarks>
// <copyright company="Exit Games GmbH">Photon Chat Api - Copyright (C) 2014 Exit Games GmbH</copyright>
// ----------------------------------------------------------------------------------------------------------------------

#if UNITY_4_7 || UNITY_5 || UNITY_5_3_OR_NEWER
#define SUPPORTED_UNITY
#endif

namespace Photon.Chat
{
using System.Collections.Generic;
using System.Text;

#if SUPPORTED_UNITY || NETFX_CORE
using Hashtable = ExitGames.Client.Photon.Hashtable;
using SupportClass = ExitGames.Client.Photon.SupportClass;
#endif


/// <summary>
/// A channel of communication in Photon Chat, updated by ChatClient and provided as READ ONLY.
/// </summary>
/// <remarks>
/// Contains messages and senders to use (read!) and display by your GUI.
/// Access these by:
/// ChatClient.PublicChannels
/// ChatClient.PrivateChannels
/// </remarks>
public class ChatChannel
{
/// <summary>Name of the channel (used to subscribe and unsubscribe).</summary>
public readonly string Name;

/// <summary>Senders of messages in chronological order. Senders and Messages refer to each other by index. Senders[x] is the sender of Messages[x].</summary>
public readonly List<string> Senders = new List<string>();

/// <summary>Messages in chronological order. Senders and Messages refer to each other by index. Senders[x] is the sender of Messages[x].</summary>
public readonly List<object> Messages = new List<object>();

/// <summary>If greater than 0, this channel will limit the number of messages, that it caches locally.</summary>
public int MessageLimit;

/// <summary>Unique channel ID.</summary>
public int ChannelID;

/// <summary>Is this a private 1:1 channel?</summary>
public bool IsPrivate { get; protected internal set; }

/// <summary>Count of messages this client still buffers/knows for this channel.</summary>
public int MessageCount { get { return this.Messages.Count; } }

/// <summary>
/// ID of the last message received.
/// </summary>
public int LastMsgId { get; protected set; }

private Dictionary<object, object> properties;

/// <summary>Whether or not this channel keeps track of the list of its subscribers.</summary>
public bool PublishSubscribers { get; protected set; }

/// <summary>Maximum number of channel subscribers. 0 means infinite.</summary>
public int MaxSubscribers { get; protected set; }

/// <summary>Subscribed users.</summary>
public readonly HashSet<string> Subscribers = new HashSet<string>();

/// <summary>Used internally to create new channels. This does NOT create a channel on the server! Use ChatClient.Subscribe.</summary>
public ChatChannel(string name)
{
this.Name = name;
}

/// <summary>Used internally to add messages to this channel.</summary>
public void Add(string sender, object message, int msgId)
{
this.Senders.Add(sender);
this.Messages.Add(message);
this.LastMsgId = msgId;
this.TruncateMessages();
}

/// <summary>Used internally to add messages to this channel.</summary>
public void Add(string[] senders, object[] messages, int lastMsgId)
{
this.Senders.AddRange(senders);
this.Messages.AddRange(messages);
this.LastMsgId = lastMsgId;
this.TruncateMessages();
}

/// <summary>Reduces the number of locally cached messages in this channel to the MessageLimit (if set).</summary>
public void TruncateMessages()
{
if (this.MessageLimit <= 0 || this.Messages.Count <= this.MessageLimit)
{
return;
}

int excessCount = this.Messages.Count - this.MessageLimit;
this.Senders.RemoveRange(0, excessCount);
this.Messages.RemoveRange(0, excessCount);
}

/// <summary>Clear the local cache of messages currently stored. This frees memory but doesn't affect the server.</summary>
public void ClearMessages()
{
this.Senders.Clear();
this.Messages.Clear();
}

/// <summary>Provides a string-representation of all messages in this channel.</summary>
/// <returns>All known messages in format "Sender: Message", line by line.</returns>
public string ToStringMessages()
{
StringBuilder txt = new StringBuilder();
for (int i = 0; i < this.Messages.Count; i++)
{
txt.AppendLine(string.Format("{0}: {1}", this.Senders[i], this.Messages[i]));
}
return txt.ToString();
}

internal void ReadChannelProperties(Dictionary<object, object> newProperties)
{
if (newProperties != null && newProperties.Count > 0)
{
if (this.properties == null)
{
this.properties = new Dictionary<object, object>(newProperties.Count);
}
foreach (var pair in newProperties)
{
if (pair.Value == null)
{
this.properties.Remove(pair.Key);
}
else
{
this.properties[pair.Key] = pair.Value;
}
}
object temp;
if (this.properties.TryGetValue(ChannelWellKnownProperties.PublishSubscribers, out temp))
{
this.PublishSubscribers = (bool)temp;
}
if (this.properties.TryGetValue(ChannelWellKnownProperties.MaxSubscribers, out temp))
{
this.MaxSubscribers = (int)temp;
}
}
}

internal void AddSubscribers(string[] users)
{
if (users == null)
{
return;
}
for (int i = 0; i < users.Length; i++)
{
this.Subscribers.Add(users[i]);
}
}

#if CHAT_EXTENDED
internal void ReadUserProperties(string userId, Dictionary<object, object> changedProperties)
{
throw new System.NotImplementedException();
}

internal bool TryGetChannelProperty<T>(object propertyKey, out T propertyValue)
{
propertyValue = default(T);
object temp;
if (properties != null && properties.TryGetValue(propertyKey, out temp) && temp is T)
{
propertyValue = (T)temp;
return true;
}
return false;
}

public bool TryGetCustomChannelProperty<T>(string propertyKey, out T propertyValue)
{
return this.TryGetChannelProperty(propertyKey, out propertyValue);
}
#endif
}
}
8 changes: 8 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChatChannel.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading