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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*
/Close Enough!/[Ll]ibrary/
/Close Enough!/Library/
/Close Enough!/[Tt]emp/
/Close Enough!/[Oo]bj/
/Close Enough!/[Bb]uild/
/Close Enough!/[Bb]uilds/
/Close Enough!/Assets/AssetStoreTools*

# Visual Studio 2015 cache directory
/.vs/
Expand All @@ -12,6 +13,7 @@
ExportedObj/
.consulo/
*.csproj
*metadata*
*.unityproj
*.sln
*.suo
Expand All @@ -22,6 +24,7 @@ ExportedObj/
*.booproj
*.svd
*.pdb
*UnityTempFile*

# Unity3D generated meta files
*.pidb.meta
Expand Down
10 changes: 10 additions & 0 deletions Close Enough!/Assets/Photon Unity Networking.meta

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

10 changes: 10 additions & 0 deletions Close Enough!/Assets/Photon Unity Networking/Editor.meta

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
// ----------------------------------------------------------------------------
// <copyright file="AccountService.cs" company="Exit Games GmbH">
// Photon Cloud Account Service - Copyright (C) 2012 Exit Games GmbH
// </copyright>
// <summary>
// Provides methods to register a new user-account for the Photon Cloud and
// get the resulting appId.
// </summary>
// <author>developer@exitgames.com</author>
// ----------------------------------------------------------------------------

#if UNITY_EDITOR

using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using ExitGames.Client.Photon;
using Newtonsoft.Json;


public class AccountService
{
private const string ServiceUrl = "https://service.exitgames.com/AccountExt/AccountServiceExt.aspx";

private Action<AccountService> registrationCallback; // optional (when using async reg)

public string Message { get; private set; } // msg from server (in case of success, this is the appid)

protected internal Exception Exception { get; set; } // exceptions in account-server communication

public string AppId { get; private set; }

public string AppId2 { get; private set; }

public int ReturnCode { get; private set; } // 0 = OK. anything else is a error with Message

public enum Origin : byte { ServerWeb = 1, CloudWeb = 2, Pun = 3, Playmaker = 4 };

/// <summary>
/// Creates a instance of the Account Service to register Photon Cloud accounts.
/// </summary>
public AccountService()
{
WebRequest.DefaultWebProxy = null;
ServicePointManager.ServerCertificateValidationCallback = Validator;
}

public static bool Validator(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
{
return true; // any certificate is ok in this case
}

/// <summary>
/// Attempts to create a Photon Cloud Account.
/// Check ReturnCode, Message and AppId to get the result of this attempt.
/// </summary>
/// <param name="email">Email of the account.</param>
/// <param name="origin">Marks which channel created the new account (if it's new).</param>
/// <param name="serviceType">Defines which type of Photon-service is being requested.</param>
public void RegisterByEmail(string email, Origin origin, string serviceType = null)
{
this.registrationCallback = null;
this.AppId = string.Empty;
this.AppId2 = string.Empty;
this.Message = string.Empty;
this.ReturnCode = -1;

string result;
try
{
WebRequest req = HttpWebRequest.Create(this.RegistrationUri(email, (byte)origin, serviceType));
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

// now read result
StreamReader reader = new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
catch (Exception ex)
{
this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
this.Exception = ex;
return;
}

this.ParseResult(result);
}

/// <summary>
/// Attempts to create a Photon Cloud Account asynchronously.
/// Once your callback is called, check ReturnCode, Message and AppId to get the result of this attempt.
/// </summary>
/// <param name="email">Email of the account.</param>
/// <param name="origin">Marks which channel created the new account (if it's new).</param>
/// <param name="serviceType">Defines which type of Photon-service is being requested.</param>
/// <param name="callback">Called when the result is available.</param>
public void RegisterByEmailAsync(string email, Origin origin, string serviceType, Action<AccountService> callback = null)
{
this.registrationCallback = callback;
this.AppId = string.Empty;
this.AppId2 = string.Empty;
this.Message = string.Empty;
this.ReturnCode = -1;

try
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(this.RegistrationUri(email, (byte)origin, serviceType));
req.Timeout = 5000; // TODO: The Timeout property has no effect on asynchronous requests made with the BeginGetResponse
req.BeginGetResponse(this.OnRegisterByEmailCompleted, req);
}
catch (Exception ex)
{
this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
this.Exception = ex;
if (this.registrationCallback != null)
{
this.registrationCallback(this);
}
}
}

/// <summary>
/// Internal callback with result of async HttpWebRequest (in RegisterByEmailAsync).
/// </summary>
/// <param name="ar"></param>
private void OnRegisterByEmailCompleted(IAsyncResult ar)
{
try
{
HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse;

if (response != null && response.StatusCode == HttpStatusCode.OK)
{
// no error. use the result
StreamReader reader = new StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd();

this.ParseResult(result);
}
else
{
// a response but some error on server. show message
this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
}
}
catch (Exception ex)
{
// not even a response. show message
this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
this.Exception = ex;
}

if (this.registrationCallback != null)
{
this.registrationCallback(this);
}
}

/// <summary>
/// Creates the service-call Uri, escaping the email for security reasons.
/// </summary>
/// <param name="email">Email of the account.</param>
/// <param name="origin">1 = server-web, 2 = cloud-web, 3 = PUN, 4 = playmaker</param>
/// <param name="serviceType">Defines which type of Photon-service is being requested. Options: "", "voice", "chat"</param>
/// <returns>Uri to call.</returns>
private Uri RegistrationUri(string email, byte origin, string serviceType)
{
if (serviceType == null)
{
serviceType = string.Empty;
}

string emailEncoded = Uri.EscapeDataString(email);
string uriString = string.Format("{0}?email={1}&origin={2}&serviceType={3}", ServiceUrl, emailEncoded, origin, serviceType);

return new Uri(uriString);
}

/// <summary>
/// Reads the Json response and applies it to local properties.
/// </summary>
/// <param name="result"></param>
private void ParseResult(string result)
{
if (string.IsNullOrEmpty(result))
{
this.Message = "Server's response was empty. Please register through account website during this service interruption.";
return;
}

Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(result);
if (values == null)
{
this.Message = "Service temporarily unavailable. Please register through account website.";
return;
}

int returnCodeInt = -1;
string returnCodeString = string.Empty;
string message;
string messageDetailed;

values.TryGetValue("ReturnCode", out returnCodeString);
values.TryGetValue("Message", out message);
values.TryGetValue("MessageDetailed", out messageDetailed);

int.TryParse(returnCodeString, out returnCodeInt);

this.ReturnCode = returnCodeInt;
if (returnCodeInt == 0)
{
// returnCode == 0 means: all ok. message is new AppId
this.AppId = message;
if (PhotonEditorUtils.HasVoice)
{
this.AppId2 = messageDetailed;
}
}
else
{
// any error gives returnCode != 0
this.AppId = string.Empty;
if (PhotonEditorUtils.HasVoice)
{
this.AppId2 = string.Empty;
}
this.Message = message;
}
}
}
#endif

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

Loading