Skip to content

Commit

Permalink
5.1.1 Patch (#273)
Browse files Browse the repository at this point in the history
* added print for logs in godot

* modified directives for godot logs

* added godot platform declaration

* Fixed compiler issues with Godot and an issue where the wrapper didn't save and load profile data

* Changed saving and loading to Godot FileAccess, since the more generic way didn't work on MacOS

* Fix for the JsonFX DotNet 8 bug

* Update README.md

Remove the part about duplicate symbols for Godot as that issue has been resolved in a previous PR.

* Cleaned up several warnings (#272)

---------

Co-authored-by: bitheadCody <codym@bitheads.com>
Co-authored-by: bitHeads-Brad <bradleyf@bitheads.com>
Co-authored-by: bitHeads-Brad <107872746+bitHeads-Brad@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 24, 2023
1 parent 6c466f9 commit 403279f
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,10 @@ public void ClearSavedProfileID()
data[OperationParam.AuthenticateServiceAuthenticateGameVersion.Value] = _client.AppVersion;
data[OperationParam.AuthenticateServiceAuthenticateBrainCloudVersion.Value] = Version.GetVersion();

#if DOT_NET || GODOT
#if DOT_NET
data["clientLib"] = "csharp";
#elif GODOT
data["clientLib"] = "csharp-godot";
#else
data["clientLib"] = "csharp-unity";
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,9 @@ internal void Log(string log, bool bypassLogEnabled = false)
}
else
{
#if !(DOT_NET || GODOT)
#if GODOT
Godot.GD.Print(formattedLog);
#elif !DOT_NET
Debug.Log(formattedLog);
#elif !XAMARIN
Console.WriteLine(formattedLog);
Expand Down Expand Up @@ -1355,7 +1357,9 @@ private void initializeHelper(string serverURL, string secretKey, string appId,

if (error != null)
{
#if !(DOT_NET || GODOT)
#if GODOT
Godot.GD.Print("ERROR | Failed to initialize brainCloud - " + error);
#elif !DOT_NET
Debug.LogError("ERROR | Failed to initialize brainCloud - " + error);
#elif !XAMARIN
Console.WriteLine("ERROR | Failed to initialize brainCloud - " + error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2524,8 +2524,8 @@ protected virtual void AuthFailureCallback(int statusCode, int reasonCode, strin

private void SaveData()
{
#if DOT_NET || GODOT
string prefix = string.IsNullOrEmpty(WrapperName).Equals("") ? "" : WrapperName + ".";
#if DOT_NET
string prefix = string.IsNullOrEmpty(WrapperName) ? "" : WrapperName + ".";
string fileName = prefix + WrapperData.FileName;

IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
Expand All @@ -2538,7 +2538,15 @@ private void SaveData()
writer.WriteLine(file);
}
}
#else
#elif GODOT
string prefix = string.IsNullOrEmpty(WrapperName) ? "" : WrapperName + ".";
string path = "user://" + prefix + WrapperData.FileName;

Godot.FileAccess fileAccess = Godot.FileAccess.Open(path, Godot.FileAccess.ModeFlags.Write);
string file = JsonWriter.Serialize(_wrapperData);
fileAccess.StoreString(file);
fileAccess.Close();
#else
string prefix = string.IsNullOrEmpty(WrapperName) ? "" : WrapperName + ".";
PlayerPrefs.SetString(prefix + PREFS_PROFILE_ID, _wrapperData.ProfileId);
PlayerPrefs.SetString(prefix + PREFS_ANONYMOUS_ID, _wrapperData.AnonymousId);
Expand All @@ -2549,7 +2557,7 @@ private void SaveData()

private void LoadData()
{
#if DOT_NET || GODOT
#if DOT_NET
string prefix = string.IsNullOrEmpty(WrapperName) ? "" : WrapperName + ".";
string fileName = prefix + WrapperData.FileName;

Expand All @@ -2568,9 +2576,24 @@ private void LoadData()
}

//parse
_wrapperData = JsonReader.Deserialize<WrapperData>(file);
if(!string.IsNullOrEmpty(file))
_wrapperData = JsonReader.Deserialize<WrapperData>(file);
}
#else
#elif GODOT
string prefix = string.IsNullOrEmpty(WrapperName) ? "" : WrapperName + ".";
string path = "user://" + prefix + WrapperData.FileName;
string file = "";

if(Godot.FileAccess.FileExists(path))
{
Godot.FileAccess fileAccess = Godot.FileAccess.Open(path, Godot.FileAccess.ModeFlags.Read);
file = fileAccess.GetAsText();
fileAccess.Close();
}

if(!string.IsNullOrEmpty(file))
_wrapperData = JsonReader.Deserialize<WrapperData>(file);
#else
string prefix = string.IsNullOrEmpty(WrapperName) ? "" : WrapperName + ".";
_wrapperData.ProfileId = PlayerPrefs.GetString(prefix + PREFS_PROFILE_ID);
_wrapperData.AnonymousId = PlayerPrefs.GetString(prefix + PREFS_ANONYMOUS_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2378,9 +2378,9 @@ public bool IsAuthenticateRequestInProgress()
[Serializable]
internal class JsonResponseBundleV2
{
[JsonName("packetId")] public long packetId;
[JsonName("responses")] public Dictionary<string, object>[] responses;
[JsonName("events")] public Dictionary<string, object>[] events;
[JsonName("packetId")] public long packetId = 0;
[JsonName("responses")] public Dictionary<string, object>[] responses = null;
[JsonName("events")] public Dictionary<string, object>[] events = null;

public JsonResponseBundleV2() { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private bool send(string in_message, bool in_bLogMessage = true)
private void startReceivingWebSocket()
{
bool sslEnabled = (bool)m_endpoint["ssl"];
string url = (sslEnabled ? "wss://" : "ws://") + m_endpoint["host"] as string + ":" + (int)m_endpoint["port"] + getUrlQueryParameters();
string url = (sslEnabled ? "wss://" : "ws://") + (m_endpoint["host"] as string) + ":" + (int)m_endpoint["port"] + getUrlQueryParameters();
setupWebSocket(url);
}

Expand Down
11 changes: 0 additions & 11 deletions BrainCloudClient/Assets/BrainCloud/Client/BrainCloud/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,8 @@ public static double GetUTCOffsetForCurrentTimeZone()
double utcOffset = 0;
try
{
#if NET_4_1
TimeZoneInfo localZone = TimeZoneInfo.Local;
utcOffset = localZone.BaseUtcOffset.TotalHours;
#else
DateTime baseUTC = new DateTime();
// Re : warning CS0618: 'TimeZone' is obsolete: 'System.TimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo instead.'
// Set the API Compatibility Level to .NET 4.x within Project Settings
TimeZone localZone = TimeZone.CurrentTimeZone;
DateTime localTime = localZone.ToLocalTime(baseUTC);
// Calculate the local time and UTC offset
TimeSpan localOffset = localZone.GetUtcOffset(localTime);
utcOffset = localOffset.TotalHours;
#endif
}
catch (Exception)
{
Expand Down
12 changes: 9 additions & 3 deletions BrainCloudClient/Assets/BrainCloud/JsonFx/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,12 +988,18 @@ protected virtual void WriteArrayItem(object item)

protected virtual void WriteObject(IDictionary value)
{
this.WriteDictionary((IEnumerable)value);
// :BF .Net 8 Fix, if you get the IDictionaryEnumerator here before casting the value to an IEnumerable the Enumerator is correctly returned
IDictionaryEnumerator enumerator = value.GetEnumerator() as IDictionaryEnumerator;
this.WriteDictionary((IEnumerable)value, enumerator);
}

protected virtual void WriteDictionary(IEnumerable value)
protected virtual void WriteDictionary(IEnumerable value, IDictionaryEnumerator enumerator = null)
{
IDictionaryEnumerator enumerator = value.GetEnumerator() as IDictionaryEnumerator;
if (enumerator == null)
{
enumerator = value.GetEnumerator() as IDictionaryEnumerator;
}

if (enumerator == null)
{
throw new JsonSerializationException(String.Format(JsonWriter.ErrorIDictionaryEnumerator, value.GetType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

#if !GODOT

[assembly: AssemblyTitle("websocket-sharp")]
[assembly: AssemblyDescription("A C# implementation of the WebSocket protocol client and server")]
[assembly: AssemblyConfiguration("")]
Expand All @@ -17,10 +19,8 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

#if !(DOT_NET || GODOT)
[assembly: AssemblyVersion("1.0.2")] //.* does not support unity 2020 deterministic builds. The .* here is not even necessary for us to have either.
#else
[assembly: AssemblyVersion("1.0.2")]

#endif

// The following attributes are used to specify the signing key for the assembly,
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ Initial support has been implemented to make this library compatible for those d

![screenshot](/screenshots/GodotProjectFileSystem.png)

**Note** that Godot may complain about "duplicate attributes" in the `AssemblyInfo.cs` file. If this is the case then comment out or delete the duplicated/erroneous lines and it should build successfully.

![screenshot](/screenshots/GodotAssemblyInfoIssue.png)

2. Create a new script to act as the brainCloud manager; in the `_Ready()` function of this script, create a new `BrainCloudWrapper` and initialize the app with the appropriate app ID and secret by calling `BrainCloudWrapper.Init(url, secretKey, appId, version)`.

3. In order to receive responses, be sure to call `BrainCloudWrapper.Update()` from the `_Process(double delta)` function of this script.
Expand Down

0 comments on commit 403279f

Please sign in to comment.