Skip to content

Commit

Permalink
Fixed room manager error
Browse files Browse the repository at this point in the history
Scene loading made synchronous
  • Loading branch information
ahnafnafee committed Nov 30, 2020
1 parent b7a444b commit 2955967
Show file tree
Hide file tree
Showing 117 changed files with 7,563 additions and 25,595 deletions.
1 change: 1 addition & 0 deletions .idea/.idea.Checkers/.idea/indexLayout.xml

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

68 changes: 47 additions & 21 deletions Assets/GUI/Fonts/MedinaFree SDF.asset

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions Assets/Photon/PhotonChat/Code/ChatAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace Photon.Chat
{
using System;
using ExitGames.Client.Photon;

using UnityEngine.Serialization;


/// <summary>
/// Settings for Photon application(s) and the server to connect to.
/// </summary>
Expand All @@ -28,7 +30,10 @@ namespace Photon.Chat
public class ChatAppSettings
{
/// <summary>AppId for the Chat Api.</summary>
public string AppId;
#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;
Expand All @@ -39,13 +44,29 @@ public class ChatAppSettings
/// <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;
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; }
}
}
}
73 changes: 68 additions & 5 deletions Assets/Photon/PhotonChat/Code/ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public class ChatClient : IPhotonPeerListener

private const byte HttpForwardWebFlag = 0x01;

/// <summary>Enables a fallback to another protocol in case a connect to the Name Server fails.</summary>
/// <remarks>
/// When connecting to the Name Server fails for a first time, the client will select an alternative
/// network protocol and re-try to connect.
///
/// The fallback will use the default Name Server port as defined by ProtocolToNameServerPort.
///
/// The fallback for TCP is UDP. All other protocols fallback to TCP.
/// </remarks>
public bool EnableProtocolFallback { get; set; }

/// <summary>The address of last connected Name Server.</summary>
public string NameServerAddress { get; private set; }

Expand Down Expand Up @@ -129,6 +140,16 @@ private set
/// Changing this value, does not affect ChatChannels that are already in use!
/// </remarks>
public int MessageLimit;

/// <summary>Limits the number of messages from private channel histories.</summary>
/// <remarks>
/// This is applied to all private channels on reconnect, as there is no explicit re-joining private channels.<br/>
/// Default is -1, which gets available messages up to a maximum set by the server.<br/>
/// A value of 0 gets you zero messages.<br/>
/// The server's limit of messages may be lower. If so, the server's value will overrule this.<br/>
/// </remarks>
public int PrivateChatHistoryLength = -1;

/// <summary> Public channels this client is subscribed to. </summary>
public readonly Dictionary<string, ChatChannel> PublicChannels;
/// <summary> Private channels in which this client has exchanged messages. </summary>
Expand Down Expand Up @@ -210,6 +231,7 @@ public ChatClient(IChatClientListener listener, ConnectionProtocol protocol = Co
this.PublicChannelsUnsubscribing = new HashSet<string>();
}


public bool ConnectUsingSettings(ChatAppSettings appSettings)
{
if (appSettings == null)
Expand All @@ -226,13 +248,15 @@ public bool ConnectUsingSettings(ChatAppSettings appSettings)
this.DebugOut = appSettings.NetworkLogging;

this.TransportProtocol = appSettings.Protocol;
this.EnableProtocolFallback = appSettings.EnableProtocolFallback;

if (!appSettings.IsDefaultNameServer)
{
this.chatPeer.NameServerHost = appSettings.Server;
this.chatPeer.NameServerPortOverride = appSettings.Port;
}

return this.Connect(appSettings.AppId, appSettings.AppVersion, this.AuthValues);
return this.Connect(appSettings.AppIdChat, appSettings.AppVersion, this.AuthValues);
}

/// <summary>
Expand All @@ -247,7 +271,10 @@ public bool Connect(string appId, string appVersion, AuthenticationValues authVa
this.chatPeer.TimePingInterval = 3000;
this.DisconnectedCause = ChatDisconnectCause.None;

this.AuthValues = authValues;
if (authValues != null)
{
this.AuthValues = authValues;
}

this.AppId = appId;
this.AppVersion = appVersion;
Expand All @@ -269,6 +296,7 @@ public bool Connect(string appId, string appVersion, AuthenticationValues authVa
#endif

this.NameServerAddress = this.chatPeer.NameServerAddress;

bool isConnecting = this.chatPeer.Connect();
if (isConnecting)
{
Expand Down Expand Up @@ -1046,6 +1074,15 @@ void IPhotonPeerListener.OnStatusChanged(StatusCode statusCode)
case StatusCode.Disconnect:
switch (this.State)
{
case ChatState.ConnectWithFallbackProtocol:
this.EnableProtocolFallback = false; // the client does a fallback only one time
this.chatPeer.NameServerPortOverride = 0; // resets a value in the peer only (as we change the protocol, the port has to change, too)
this.chatPeer.TransportProtocol = (this.chatPeer.TransportProtocol == ConnectionProtocol.Tcp) ? ConnectionProtocol.Udp : ConnectionProtocol.Tcp;
this.Connect(this.AppId, this.AppVersion, null);

// the client now has to return, instead of break, to avoid further processing of the disconnect call
return;

case ChatState.Authenticated:
this.ConnectToFrontEnd();
// client disconnected from nameserver after authentication
Expand Down Expand Up @@ -1078,7 +1115,18 @@ void IPhotonPeerListener.OnStatusChanged(StatusCode statusCode)
case StatusCode.ExceptionOnConnect:
case StatusCode.SecurityExceptionOnConnect:
case StatusCode.EncryptionFailedToEstablish:
this.Disconnect(ChatDisconnectCause.ExceptionOnConnect);
this.DisconnectedCause = ChatDisconnectCause.ExceptionOnConnect;

// if enabled, the client can attempt to connect with another networking-protocol to check if that connects
if (this.EnableProtocolFallback && this.State == ChatState.ConnectingToNameServer)
{
this.State = ChatState.ConnectWithFallbackProtocol;
}
else
{
this.Disconnect(ChatDisconnectCause.ExceptionOnConnect);
}

break;
case StatusCode.Exception:
case StatusCode.ExceptionOnReceive:
Expand All @@ -1094,7 +1142,17 @@ void IPhotonPeerListener.OnStatusChanged(StatusCode statusCode)
this.Disconnect(ChatDisconnectCause.DisconnectByServerReasonUnknown);
break;
case StatusCode.TimeoutDisconnect:
this.Disconnect(ChatDisconnectCause.ClientTimeout);
this.DisconnectedCause = ChatDisconnectCause.ClientTimeout;

// if enabled, the client can attempt to connect with another networking-protocol to check if that connects
if (this.EnableProtocolFallback && this.State == ChatState.ConnectingToNameServer)
{
this.State = ChatState.ConnectWithFallbackProtocol;
}
else
{
this.Disconnect(ChatDisconnectCause.ClientTimeout);
}
break;
}
}
Expand Down Expand Up @@ -1424,6 +1482,11 @@ private bool AuthenticateOnFrontEnd()
else
{
Dictionary<byte, object> opParameters = new Dictionary<byte, object> { { (byte)ChatParameterCode.Secret, this.AuthValues.Token } };
if (this.PrivateChatHistoryLength > -1)
{
opParameters[(byte)ChatParameterCode.HistoryLength] = this.PrivateChatHistoryLength;
}

return this.chatPeer.SendOperation(ChatOperationCode.Authenticate, opParameters, SendOptions.SendReliable);
}
}
Expand Down Expand Up @@ -1517,7 +1580,7 @@ private void HandleUserSubscribedEvent(EventData eventData)
/// </summary>
/// <param name="channel">name of the channel to subscribe to</param>
/// <param name="lastMsgId">ID of the last received message from this channel when re subscribing to receive only missed messages, default is 0</param>
/// <param name="messagesFromHistory">how many missed messages to receive from history, default is none/-1</param>
/// <param name="messagesFromHistory">how many missed messages to receive from history, default is -1 (available history). 0 will get you no items. Positive values are capped by a server side limit.</param>
/// <param name="creationOptions">options to be used in case the channel to subscribe to will be created.</param>
/// <returns></returns>
public bool Subscribe(string channel, int lastMsgId = 0, int messagesFromHistory = -1, ChannelCreationOptions creationOptions = null)
Expand Down
32 changes: 24 additions & 8 deletions Assets/Photon/PhotonChat/Code/ChatPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public class ChatPeer : PhotonPeer
{
/// <summary>Name Server Host Name for Photon Cloud. Without port and without any prefix.</summary>
public string NameServerHost = "ns.exitgames.com";

/// <summary>Name Server for HTTP connections to the Photon Cloud. Includes prefix and port.</summary>
public string NameServerHttp = "http://ns.exitgamescloud.com:80/photon/n";


/// <summary>Name Server port per protocol (the UDP port is different than TCP, etc).</summary>
private static readonly Dictionary<ConnectionProtocol, int> ProtocolToNameServerPort = new Dictionary<ConnectionProtocol, int>() { { ConnectionProtocol.Udp, 5058 }, { ConnectionProtocol.Tcp, 4533 }, { ConnectionProtocol.WebSocket, 9093 }, { ConnectionProtocol.WebSocketSecure, 19093 } }; //, { ConnectionProtocol.RHttp, 6063 } };

Expand Down Expand Up @@ -95,6 +92,9 @@ private void ConfigUnitySockets()
#endif
}

/// <summary>If not zero, this is used for the name server port on connect. Independent of protocol (so this better matches). Set by ChatClient.ConnectUsingSettings.</summary>
/// <remarks>This is reset when the protocol fallback is used.</remarks>
public ushort NameServerPortOverride;

/// <summary>
/// Gets the NameServer Address (with prefix and port), based on the set protocol (this.UsedProtocol).
Expand All @@ -104,16 +104,18 @@ private string GetNameServerAddress()
{
var protocolPort = 0;
ProtocolToNameServerPort.TryGetValue(this.TransportProtocol, out protocolPort);

if (this.NameServerPortOverride != 0)
{
this.Listener.DebugReturn(DebugLevel.INFO, string.Format("Using NameServerPortInAppSettings as port for Name Server: {0}", this.NameServerPortOverride));
protocolPort = this.NameServerPortOverride;
}

switch (this.TransportProtocol)
{
case ConnectionProtocol.Udp:
case ConnectionProtocol.Tcp:
return string.Format("{0}:{1}", NameServerHost, protocolPort);
#if RHTTP
case ConnectionProtocol.RHttp:
return NameServerHttp;
#endif
case ConnectionProtocol.WebSocket:
return string.Format("ws://{0}:{1}", NameServerHost, protocolPort);
case ConnectionProtocol.WebSocketSecure:
Expand Down Expand Up @@ -319,6 +321,20 @@ public override string ToString()
{
return string.Format("AuthenticationValues Type: {3} UserId: {0}, GetParameters: {1} Token available: {2}", this.UserId, this.AuthGetParameters, !string.IsNullOrEmpty(this.Token), this.AuthType);
}

/// <summary>
/// Make a copy of the current object.
/// </summary>
/// <param name="copy">The object to be copied into.</param>
/// <returns>The copied object.</returns>
public AuthenticationValues CopyTo(AuthenticationValues copy)
{
copy.AuthType = this.AuthType;
copy.AuthGetParameters = this.AuthGetParameters;
copy.AuthPostData = this.AuthPostData;
copy.UserId = this.UserId;
return copy;
}
}


Expand Down
2 changes: 2 additions & 0 deletions Assets/Photon/PhotonChat/Code/ChatState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ public enum ChatState
Disconnecting,
/// <summary>The client is no longer connected (to any server).</summary>
Disconnected,
/// <summary>Client was unable to connect to Name Server and will attempt to connect with an alternative network protocol (TCP).</summary>
ConnectWithFallbackProtocol
}
}
10 changes: 3 additions & 7 deletions Assets/Photon/PhotonChat/Code/PhotonChat.asmdef
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
{
"name": "PhotonChat",
"references": [
"PhotonWebSocket"
],
"optionalUnityReferences": [],
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false
"excludePlatforms": []
}
10 changes: 10 additions & 0 deletions Assets/Photon/PhotonChat/Code/changes-chat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Exit Games GmbH - www.photonengine.com - forum.photonengine.com



Version 4.1.4.6 (16. November 2020)
Added: ChatClient.PrivateChatHistoryLength field. If set before you connect, this can be used to limit the number of private messages when the server (re)subscribes the client to (still alive) a private chat channel.
Added: Protocol Fallback option for Chat. Analog to the Realtime API, Chat can now try another protocol, if the initial connect to the Name Server fails. After the timeout or when an error happened, UDP will fallback to TCP. TCP will fallback to UDP.
Added: EnableProtocolFallback in ChatClient and ChatAppSettings. When using ConnectUsingSettings, the ChatClient's value gets set and used.
Changed: Connect(appid, appversion, authValues) will only apply the authvalues parameter, if that's non-null.
Changed: ChatAppSettings field AppId is now AppIdChat (matching the value in Realtime API AppSettings). The old name is currently just obsolete.
Added: ChatAppSettings.Port to override the Name Server Port if needed. Note: Chat does not support "Alternative Ports" yet (ports pre-defined per server).
Added: ChatPeer.NameServerPortOverride value to replace/override the default per-protocol port value (by the one in the AppSettings, e.g.).


Version 4.1.4.5 (02. September 2020)
Added: Option for extended features: Channels may send a user list, channels and users can have custom properties and there are web-forwarding flags. Needs compile define CHAT_EXTENDED. This also adds new methods to the IChatClientListener.
Changed: AuthenticationValues has been refined, analog to the changes in the Realtime API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public static ChatAppSettings GetChatSettings(this AppSettings appSettings)
{
return new ChatAppSettings
{
AppId = appSettings.AppIdChat,
AppIdChat = appSettings.AppIdChat,
AppVersion = appSettings.AppVersion,
FixedRegion = appSettings.IsBestRegion ? null : appSettings.FixedRegion,
NetworkLogging = appSettings.NetworkLogging,
Protocol = appSettings.Protocol,
Server = appSettings.IsDefaultNameServer ? null : appSettings.Server
EnableProtocolFallback = appSettings.EnableProtocolFallback,
Server = appSettings.IsDefaultNameServer ? null : appSettings.Server,
Port = (ushort)appSettings.Port
};
}
}
2 changes: 1 addition & 1 deletion Assets/Photon/PhotonChat/Demos/DemoChat/ChatGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void Start()
this.chatAppSettings = PhotonNetwork.PhotonServerSettings.AppSettings.GetChatSettings();
#endif

bool appIdPresent = !string.IsNullOrEmpty(this.chatAppSettings.AppId);
bool appIdPresent = !string.IsNullOrEmpty(this.chatAppSettings.AppIdChat);

this.missingAppIdErrorPanel.SetActive(!appIdPresent);
this.UserIdFormPanel.gameObject.SetActive(appIdPresent);
Expand Down
Binary file modified Assets/Photon/PhotonLibs/Metro/Photon3Unity3D.dll
Binary file not shown.
Binary file modified Assets/Photon/PhotonLibs/Photon3Unity3D.dll
Binary file not shown.
Loading

0 comments on commit 2955967

Please sign in to comment.