From 8bc7dbf7610bfb7b9721b89f35e1ce8b5fa0d483 Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:22:26 -0600 Subject: [PATCH 01/18] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9537b8a9..437e90b4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.usertasks .DS_Store .vs/ +.idea/ #Mono Project Files *.pidb From 9fd15a5f84a8fbab3702dbb512e60b6002146ce1 Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:25:51 -0600 Subject: [PATCH 02/18] Update package.json --- package.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 0334e3b7..59811b5c 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,17 @@ { - "name": "io.colyseus.sdk", + "name": "com.gosynthschool.io.colyseus.sdk", "version": "0.14.18", - "displayName": "Colyseus SDK", - "description": "Colyseus Multiplayer SDK for Unity", + "displayName": "Colyseus SDK - Synthesis", + "description": "Colyseus Multiplayer SDK for Unity - Synthesis", "unity": "2019.1", "license": "MIT", "category": "Networking", "repository": { "type": "git", - "url": "https://github.com/colyseus/colyseus-unity-sdk.git" + "url": "https://github.com/gosynthschool/colyseus-unity-sdk.git" + }, + "publishConfig": { + "registry":"https://npm.pkg.github.com/@gosynthschool" }, "author": { "name": "Colyseus", From a5c8fa126fd6b6ecd7e709e81ee788a6f68d9faa Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Mon, 1 Aug 2022 17:37:10 -0600 Subject: [PATCH 03/18] fix https fallback to http --- Runtime/Scripts/ColyseusRequest.cs | 34 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Runtime/Scripts/ColyseusRequest.cs b/Runtime/Scripts/ColyseusRequest.cs index df9f522f..55c84572 100644 --- a/Runtime/Scripts/ColyseusRequest.cs +++ b/Runtime/Scripts/ColyseusRequest.cs @@ -35,17 +35,17 @@ public async Task Request(string uriMethod, string uriPath, string uriQu { req.uploadHandler = data; } - + foreach (KeyValuePair pair in _serverSettings.HeadersDictionary) { req.SetRequestHeader(pair.Key, pair.Value); } - + if (!string.IsNullOrEmpty(Token)) { req.SetRequestHeader("Authorization", "Bearer " + Token); } - + // req.uploadHandler = new UploadHandlerRaw(bytes); req.downloadHandler = new DownloadHandlerBuffer(); await req.SendWebRequest(); @@ -58,19 +58,25 @@ public async Task Request(string uriMethod, string uriPath, string uriQu { if (_serverSettings.useSecureProtocol) { - //We failed to make this call with a secure protocol, try with non-secure and if that works we'll stick with it - _serverSettings.useSecureProtocol = false; - LSLog.LogError($"Failed to make request to {req.url} with secure protocol, trying again without!"); - return await Request(uriMethod, uriPath, uriQuery, Token, data); + //We failed to make this call with a secure protocol, try again + LSLog.LogError($"Failed to make request to {req.url} with secure protocol, trying again!"); + try + { + return await Request(uriMethod, uriPath, uriQuery, Token, data); + } + catch + { + LSLog.LogError($"Failed RETRY to make request to {req.url}."); + } } else { throw new Exception(req.error); } } - + string json = req.downloadHandler.text; - + return json; } ; } @@ -87,18 +93,18 @@ public async Task Request(string uriMethod, string uriPath, Dictionary pair in _serverSettings.HeadersDictionary) { req.SetRequestHeader(pair.Key, pair.Value); } - + if (headers != null) { foreach (KeyValuePair header in headers) @@ -106,7 +112,7 @@ public async Task Request(string uriMethod, string uriPath, Dictionary Request(string uriMethod, string uriPath, Dictionary Date: Wed, 3 Aug 2022 15:34:00 -0600 Subject: [PATCH 04/18] Create README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..cd74c724 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Synthesis Fork of Colyseus-Unity-SDK + +**When updating this fork, in order to make your changes bubble up to games consuming this package, you must do the following in each:** + +1. In the `manifest.json` file, remove the line for this package `"com.gosynthschool.io.colyseus.sdk": "https://github.com/gosynthschool/colyseus-unity-sdk.git#synthesis-changes",`. +2. Give unity editor focus and let it refresh packages. +3. In the `manifest.json` file, add the line you removed for this package in step 1 back. +4. Give unity editor focus and let it refresh packages. +5. You should see the `client` `packages-lock.json` file has updated with a new commit hash for this package. \ No newline at end of file From 294f96775a49c1fda9b9b20760a30d00601ae325 Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:35:36 -0600 Subject: [PATCH 05/18] readme instructions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd74c724..a02c3bf2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **When updating this fork, in order to make your changes bubble up to games consuming this package, you must do the following in each:** 1. In the `manifest.json` file, remove the line for this package `"com.gosynthschool.io.colyseus.sdk": "https://github.com/gosynthschool/colyseus-unity-sdk.git#synthesis-changes",`. -2. Give unity editor focus and let it refresh packages. +2. Give the Unity Editor focus and let it refresh packages. 3. In the `manifest.json` file, add the line you removed for this package in step 1 back. -4. Give unity editor focus and let it refresh packages. +4. Give Unity Editor focus and let it refresh packages. 5. You should see the `client` `packages-lock.json` file has updated with a new commit hash for this package. \ No newline at end of file From 767a7ccf1e0973a1366f7a9bd1caa9683ae2a5cb Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:35:49 -0600 Subject: [PATCH 06/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a02c3bf2..13c108d2 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ 2. Give the Unity Editor focus and let it refresh packages. 3. In the `manifest.json` file, add the line you removed for this package in step 1 back. 4. Give Unity Editor focus and let it refresh packages. -5. You should see the `client` `packages-lock.json` file has updated with a new commit hash for this package. \ No newline at end of file +5. You should see the `client/` `packages-lock.json` file has updated with a new commit hash for this package. \ No newline at end of file From 1b823172738c0006cd739590e3cf6ca64f017157 Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:37:29 -0600 Subject: [PATCH 07/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 13c108d2..1cd2eac1 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ 2. Give the Unity Editor focus and let it refresh packages. 3. In the `manifest.json` file, add the line you removed for this package in step 1 back. 4. Give Unity Editor focus and let it refresh packages. -5. You should see the `client/` `packages-lock.json` file has updated with a new commit hash for this package. \ No newline at end of file +5. You should see the `client/simName/Packages/packages-lock.json` file has updated with a new commit hash for this package. \ No newline at end of file From 89c412fa459b2099ca66eddf888e5976f1e95348 Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:37:57 -0600 Subject: [PATCH 08/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1cd2eac1..bb16e3ee 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Synthesis Fork of Colyseus-Unity-SDK -**When updating this fork, in order to make your changes bubble up to games consuming this package, you must do the following in each:** +**When updating this fork, in order to make your changes bubble up to games consuming this package, you must do the following in each game:** 1. In the `manifest.json` file, remove the line for this package `"com.gosynthschool.io.colyseus.sdk": "https://github.com/gosynthschool/colyseus-unity-sdk.git#synthesis-changes",`. 2. Give the Unity Editor focus and let it refresh packages. From 27437f80db2bfb24bbdce2d9fe3b4d3fc441f5cc Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:46:47 -0600 Subject: [PATCH 09/18] Update README.md Co-authored-by: Ipsquiggle --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb16e3ee..5ebdc904 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **When updating this fork, in order to make your changes bubble up to games consuming this package, you must do the following in each game:** -1. In the `manifest.json` file, remove the line for this package `"com.gosynthschool.io.colyseus.sdk": "https://github.com/gosynthschool/colyseus-unity-sdk.git#synthesis-changes",`. +1. In the `manifest.json` file of each game, remove the line for this package `"com.gosynthschool.io.colyseus.sdk": "https://github.com/gosynthschool/colyseus-unity-sdk.git#synthesis-changes",`. 2. Give the Unity Editor focus and let it refresh packages. 3. In the `manifest.json` file, add the line you removed for this package in step 1 back. 4. Give Unity Editor focus and let it refresh packages. From 963bf9ae77af69a1307b10628144f35bc22ff063 Mon Sep 17 00:00:00 2001 From: Graham Jans Date: Fri, 5 Aug 2022 19:53:27 -0700 Subject: [PATCH 10/18] Add missing meta file to silence editor errors --- README.md.meta | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md.meta diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 00000000..3b0a0dbb --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 77ab74859c46ef14e9766df2cb1a5726 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 2cde836340d0a965a03fdb63562da7453aa942d8 Mon Sep 17 00:00:00 2001 From: Kristen Montesano <93609781+kristensynthesis@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:23:18 -0600 Subject: [PATCH 11/18] Update ColyseusRequest.cs --- Runtime/Scripts/ColyseusRequest.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Runtime/Scripts/ColyseusRequest.cs b/Runtime/Scripts/ColyseusRequest.cs index 55c84572..ec1b8d82 100644 --- a/Runtime/Scripts/ColyseusRequest.cs +++ b/Runtime/Scripts/ColyseusRequest.cs @@ -59,7 +59,7 @@ public async Task Request(string uriMethod, string uriPath, string uriQu if (_serverSettings.useSecureProtocol) { //We failed to make this call with a secure protocol, try again - LSLog.LogError($"Failed to make request to {req.url} with secure protocol, trying again!"); + LSLog.LogError($"Failed to make request to {req.url}, trying again!"); try { return await Request(uriMethod, uriPath, uriQuery, Token, data); @@ -124,10 +124,16 @@ public async Task Request(string uriMethod, string uriPath, Dictionary Date: Thu, 18 Aug 2022 18:38:23 -0600 Subject: [PATCH 12/18] Update Runtime/Scripts/ColyseusRequest.cs --- Runtime/Scripts/ColyseusRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Scripts/ColyseusRequest.cs b/Runtime/Scripts/ColyseusRequest.cs index ec1b8d82..8f8df90c 100644 --- a/Runtime/Scripts/ColyseusRequest.cs +++ b/Runtime/Scripts/ColyseusRequest.cs @@ -128,7 +128,7 @@ public async Task Request(string uriMethod, string uriPath, Dictionary Date: Fri, 19 Aug 2022 11:48:57 -0600 Subject: [PATCH 13/18] Update ColyseusRequest.cs --- Runtime/Scripts/ColyseusRequest.cs | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Runtime/Scripts/ColyseusRequest.cs b/Runtime/Scripts/ColyseusRequest.cs index 8f8df90c..959c354e 100644 --- a/Runtime/Scripts/ColyseusRequest.cs +++ b/Runtime/Scripts/ColyseusRequest.cs @@ -58,16 +58,8 @@ public async Task Request(string uriMethod, string uriPath, string uriQu { if (_serverSettings.useSecureProtocol) { - //We failed to make this call with a secure protocol, try again - LSLog.LogError($"Failed to make request to {req.url}, trying again!"); - try - { - return await Request(uriMethod, uriPath, uriQuery, Token, data); - } - catch - { - LSLog.LogError($"Failed RETRY to make request to {req.url}."); - } + //We failed to make this call with a secure protocol + LSLog.LogError($"Failed to make request to {req.url}."); } else { @@ -124,16 +116,8 @@ public async Task Request(string uriMethod, string uriPath, Dictionary Date: Thu, 2 Feb 2023 12:32:47 -0800 Subject: [PATCH 14/18] Add logging to websockets and propagate errors up to the client --- .editorconfig | 4 +- Runtime/Scripts/Room/ColyseusRoom.cs | 48 ++++++++++---------- Runtime/WebSocket/WebSocket.cs | 15 ++++-- package.json | 68 ++++++++++++++-------------- 4 files changed, 71 insertions(+), 64 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9bc50990..32f26a06 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true -indent_style = tab +indent_style = space indent_size = 4 [*.{js,ts}] @@ -10,5 +10,5 @@ indent_style = space indent_size = 2 [*.{cs}] -indent_style = tab +indent_style = space indent_size = 4 diff --git a/Runtime/Scripts/Room/ColyseusRoom.cs b/Runtime/Scripts/Room/ColyseusRoom.cs index 2aae26d8..6875dd07 100644 --- a/Runtime/Scripts/Room/ColyseusRoom.cs +++ b/Runtime/Scripts/Room/ColyseusRoom.cs @@ -157,7 +157,7 @@ public async Task Leave(bool consented = true) { if (consented) { - await colyseusConnection.Send(new[] {ColyseusProtocol.LEAVE_ROOM}); + await colyseusConnection.Send(new[] { ColyseusProtocol.LEAVE_ROOM }); } else { @@ -195,10 +195,7 @@ public void SetConnection(ColyseusConnection colyseusConnection) this.colyseusConnection.OnClose += code => OnLeave?.Invoke(code); - // TODO: expose WebSocket error code! - // Connection.OnError += (code, message) => OnError?.Invoke(code, message); - - this.colyseusConnection.OnError += message => OnError?.Invoke(0, message); + this.colyseusConnection.OnError += (code, message) => OnError?.Invoke(code, message); this.colyseusConnection.OnMessage += bytes => ParseMessage(bytes); } @@ -221,7 +218,7 @@ public void SetState(byte[] encodedState, int offset) /// Message type public async Task Send(byte type) { - await colyseusConnection.Send(new[] {ColyseusProtocol.ROOM_DATA, type}); + await colyseusConnection.Send(new[] { ColyseusProtocol.ROOM_DATA, type }); } /// @@ -234,7 +231,7 @@ public async Task Send(byte type, object message) MemoryStream serializationOutput = new MemoryStream(); MsgPack.Serialize(message, serializationOutput, SerializationOptions.SuppressTypeInformation); - byte[] initialBytes = {ColyseusProtocol.ROOM_DATA, type}; + byte[] initialBytes = { ColyseusProtocol.ROOM_DATA, type }; byte[] encodedMessage = serializationOutput.ToArray(); byte[] bytes = new byte[initialBytes.Length + encodedMessage.Length]; @@ -360,7 +357,7 @@ protected async void ParseMessage(byte[] bytes) { try { - serializer = (IColyseusSerializer) new ColyseusNoneSerializer(); + serializer = (IColyseusSerializer)new ColyseusNoneSerializer(); } catch (Exception e) { @@ -372,36 +369,37 @@ protected async void ParseMessage(byte[] bytes) if (bytes.Length > offset) { - try { - serializer.Handshake(bytes, offset); - } - catch (Exception e) - { - await Leave(false); - OnError?.Invoke(ColyseusErrorCode.SCHEMA_MISMATCH, e.Message); - return; - } + try + { + serializer.Handshake(bytes, offset); + } + catch (Exception e) + { + await Leave(false); + OnError?.Invoke(ColyseusErrorCode.SCHEMA_MISMATCH, e.Message); + return; + } } OnJoin?.Invoke(); // Acknowledge JOIN_ROOM - await colyseusConnection.Send(new[] {ColyseusProtocol.JOIN_ROOM}); + await colyseusConnection.Send(new[] { ColyseusProtocol.JOIN_ROOM }); } else if (code == ColyseusProtocol.ERROR) { - Iterator it = new Iterator {Offset = 1}; + Iterator it = new Iterator { Offset = 1 }; float errorCode = Decode.DecodeNumber(bytes, it); string errorMessage = Decode.DecodeString(bytes, it); - OnError?.Invoke((int) errorCode, errorMessage); + OnError?.Invoke((int)errorCode, errorMessage); } else if (code == ColyseusProtocol.ROOM_DATA_SCHEMA) { - Iterator it = new Iterator {Offset = 1}; + Iterator it = new Iterator { Offset = 1 }; float typeId = Decode.DecodeNumber(bytes, it); Type messageType = ColyseusContext.GetInstance().Get(typeId); - Schema.Schema message = (Schema.Schema) Activator.CreateInstance(messageType); + Schema.Schema message = (Schema.Schema)Activator.CreateInstance(messageType); message.Decode(bytes, it); @@ -423,7 +421,7 @@ protected async void ParseMessage(byte[] bytes) } else if (code == ColyseusProtocol.ROOM_STATE) { - SetState(bytes, 1); + SetState(bytes, 1); } else if (code == ColyseusProtocol.ROOM_STATE_PATCH) { @@ -434,7 +432,7 @@ protected async void ParseMessage(byte[] bytes) IColyseusMessageHandler handler = null; object type; - Iterator it = new Iterator {Offset = 1}; + Iterator it = new Iterator { Offset = 1 }; if (Decode.NumberCheck(bytes, it)) { @@ -491,4 +489,4 @@ protected void DisplaySerializerErrorHelp(Exception e, string helpMessage) throw e; } } -} \ No newline at end of file +} diff --git a/Runtime/WebSocket/WebSocket.cs b/Runtime/WebSocket/WebSocket.cs index 2cdb6be5..0e7cd088 100644 --- a/Runtime/WebSocket/WebSocket.cs +++ b/Runtime/WebSocket/WebSocket.cs @@ -83,7 +83,7 @@ namespace NativeWebSocket { public delegate void WebSocketOpenEventHandler(); public delegate void WebSocketMessageEventHandler(byte[] data); - public delegate void WebSocketErrorEventHandler(string errorMsg); + public delegate void WebSocketErrorEventHandler(int closeCode, string errorMsg); public delegate void WebSocketCloseEventHandler(int closeCode); public enum WebSocketCloseCode @@ -258,6 +258,7 @@ public Task Connect () { } public void CancelConnection () { + Debug.Log('WebSocket.CancelConnection()'); if (State == WebSocketState.Open) Close (WebSocketCloseCode.Abnormal); } @@ -400,7 +401,7 @@ public async Task Connect() } catch (Exception ex) { - OnError?.Invoke(ex.Message); + OnError?.Invoke((int)WebSocketCloseCode.Abnormal, "Excpetion in Websocket Connect!\n" + ex.Message); OnClose?.Invoke((int)WebSocketCloseCode.Abnormal); } finally @@ -567,6 +568,7 @@ public async Task Receive() { int closeCode = (int)WebSocketCloseCode.Abnormal; await new WaitForBackgroundThread(); + string errorMessage = null; ArraySegment buffer = new ArraySegment(new byte[8192]); try @@ -609,19 +611,26 @@ public async Task Receive() else if (result.MessageType == WebSocketMessageType.Close) { await Close(); + errorMessage = "Closing connection normally with code " + result.CloseStatus; + closeCode = (int)result.CloseStatus; break; } } } } - catch (Exception) + catch (Exception ex) { m_TokenSource.Cancel(); + errorMessage = "Exception encountered in websocket! " + ex.Message; } finally { await new WaitForUpdate(); + if (errorMessage != null) + { + OnError?.Invoke(closeCode, errorMessage); + } OnClose?.Invoke(closeCode); } } diff --git a/package.json b/package.json index 59811b5c..d7cca6a7 100644 --- a/package.json +++ b/package.json @@ -1,36 +1,36 @@ { - "name": "com.gosynthschool.io.colyseus.sdk", - "version": "0.14.18", - "displayName": "Colyseus SDK - Synthesis", - "description": "Colyseus Multiplayer SDK for Unity - Synthesis", - "unity": "2019.1", - "license": "MIT", - "category": "Networking", - "repository": { - "type": "git", - "url": "https://github.com/gosynthschool/colyseus-unity-sdk.git" - }, - "publishConfig": { - "registry":"https://npm.pkg.github.com/@gosynthschool" - }, - "author": { - "name": "Colyseus", - "email": "contact@lucidsight.com", - "url": "https://colyseus.io/" - }, - "keywords": [ - "colyseus", - "multiplayer", - "networking", - "authoritative", - "netcode" - ], - "dependencies": {}, - "samples": [ - { - "displayName": "Example", - "description": "Colyseus Example", - "path": "Runtime/Example~" - } - ] + "name": "com.gosynthschool.io.colyseus.sdk", + "version": "0.14.20-synthesis-changes", + "displayName": "Colyseus SDK - Synthesis", + "description": "Colyseus Multiplayer SDK for Unity - Synthesis", + "unity": "2019.1", + "license": "MIT", + "category": "Networking", + "repository": { + "type": "git", + "url": "https://github.com/gosynthschool/colyseus-unity-sdk.git" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com/@gosynthschool" + }, + "author": { + "name": "Colyseus", + "email": "contact@lucidsight.com", + "url": "https://colyseus.io/" + }, + "keywords": [ + "colyseus", + "multiplayer", + "networking", + "authoritative", + "netcode" + ], + "dependencies": {}, + "samples": [ + { + "displayName": "Example", + "description": "Colyseus Example", + "path": "Runtime/Example~" + } + ] } From 0adbe818ba31ac085ae9a0949396e734176d8982 Mon Sep 17 00:00:00 2001 From: Graham Jans Date: Thu, 2 Feb 2023 13:28:02 -0800 Subject: [PATCH 15/18] fix compiler error --- Runtime/WebSocket/WebSocket.cs | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/WebSocket/WebSocket.cs b/Runtime/WebSocket/WebSocket.cs index 0e7cd088..2a0ef7e6 100644 --- a/Runtime/WebSocket/WebSocket.cs +++ b/Runtime/WebSocket/WebSocket.cs @@ -258,7 +258,7 @@ public Task Connect () { } public void CancelConnection () { - Debug.Log('WebSocket.CancelConnection()'); + Debug.Log("WebSocket.CancelConnection()"); if (State == WebSocketState.Open) Close (WebSocketCloseCode.Abnormal); } diff --git a/package.json b/package.json index d7cca6a7..bf1aafda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.gosynthschool.io.colyseus.sdk", - "version": "0.14.20-synthesis-changes", + "version": "0.14.21-synthesis-changes", "displayName": "Colyseus SDK - Synthesis", "description": "Colyseus Multiplayer SDK for Unity - Synthesis", "unity": "2019.1", From db8a82d41f3b820ab84a4af0e6486e5c0ad362ce Mon Sep 17 00:00:00 2001 From: Graham Jans Date: Thu, 2 Feb 2023 14:54:35 -0800 Subject: [PATCH 16/18] Fix another compiler error --- Runtime/WebSocket/WebSocket.cs | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Runtime/WebSocket/WebSocket.cs b/Runtime/WebSocket/WebSocket.cs index 2a0ef7e6..6a672993 100644 --- a/Runtime/WebSocket/WebSocket.cs +++ b/Runtime/WebSocket/WebSocket.cs @@ -324,8 +324,8 @@ public void DelegateOnMessageEvent (byte[] data) { this.OnMessage?.Invoke (data); } - public void DelegateOnErrorEvent (string errorMsg) { - this.OnError?.Invoke (errorMsg); + public void DelegateOnErrorEvent (int code, string errorMsg) { + this.OnError?.Invoke (code, errorMsg); } public void DelegateOnCloseEvent (int closeCode) { @@ -746,7 +746,7 @@ public static void DelegateOnErrorEvent (int instanceId, System.IntPtr errorPtr) if (instances.TryGetValue (instanceId, out instanceRef)) { string errorMsg = Marshal.PtrToStringAuto (errorPtr); - instanceRef.DelegateOnErrorEvent (errorMsg); + instanceRef.DelegateOnErrorEvent (0, errorMsg); } diff --git a/package.json b/package.json index bf1aafda..1d9de61f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.gosynthschool.io.colyseus.sdk", - "version": "0.14.21-synthesis-changes", + "version": "0.14.22-synthesis-changes", "displayName": "Colyseus SDK - Synthesis", "description": "Colyseus Multiplayer SDK for Unity - Synthesis", "unity": "2019.1", From 4f0b46fdb84c25f0fa3471ca314c6ca9626f00f6 Mon Sep 17 00:00:00 2001 From: Graham Jans Date: Fri, 3 Feb 2023 16:25:22 -0800 Subject: [PATCH 17/18] Revert "Add logging to websockets and propagate errors up to the client" This reverts commits: db8a82d41f3b820ab84a4af0e6486e5c0ad362ce 0adbe818ba31ac085ae9a0949396e734176d8982 c6666cdf63427bfd1c4cd084b40b881f3489cec7 --- .editorconfig | 4 +- Runtime/Scripts/Room/ColyseusRoom.cs | 48 ++++++++++---------- Runtime/WebSocket/WebSocket.cs | 21 +++------ package.json | 68 ++++++++++++++-------------- 4 files changed, 67 insertions(+), 74 deletions(-) diff --git a/.editorconfig b/.editorconfig index 32f26a06..9bc50990 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true -indent_style = space +indent_style = tab indent_size = 4 [*.{js,ts}] @@ -10,5 +10,5 @@ indent_style = space indent_size = 2 [*.{cs}] -indent_style = space +indent_style = tab indent_size = 4 diff --git a/Runtime/Scripts/Room/ColyseusRoom.cs b/Runtime/Scripts/Room/ColyseusRoom.cs index 6875dd07..2aae26d8 100644 --- a/Runtime/Scripts/Room/ColyseusRoom.cs +++ b/Runtime/Scripts/Room/ColyseusRoom.cs @@ -157,7 +157,7 @@ public async Task Leave(bool consented = true) { if (consented) { - await colyseusConnection.Send(new[] { ColyseusProtocol.LEAVE_ROOM }); + await colyseusConnection.Send(new[] {ColyseusProtocol.LEAVE_ROOM}); } else { @@ -195,7 +195,10 @@ public void SetConnection(ColyseusConnection colyseusConnection) this.colyseusConnection.OnClose += code => OnLeave?.Invoke(code); - this.colyseusConnection.OnError += (code, message) => OnError?.Invoke(code, message); + // TODO: expose WebSocket error code! + // Connection.OnError += (code, message) => OnError?.Invoke(code, message); + + this.colyseusConnection.OnError += message => OnError?.Invoke(0, message); this.colyseusConnection.OnMessage += bytes => ParseMessage(bytes); } @@ -218,7 +221,7 @@ public void SetState(byte[] encodedState, int offset) /// Message type public async Task Send(byte type) { - await colyseusConnection.Send(new[] { ColyseusProtocol.ROOM_DATA, type }); + await colyseusConnection.Send(new[] {ColyseusProtocol.ROOM_DATA, type}); } /// @@ -231,7 +234,7 @@ public async Task Send(byte type, object message) MemoryStream serializationOutput = new MemoryStream(); MsgPack.Serialize(message, serializationOutput, SerializationOptions.SuppressTypeInformation); - byte[] initialBytes = { ColyseusProtocol.ROOM_DATA, type }; + byte[] initialBytes = {ColyseusProtocol.ROOM_DATA, type}; byte[] encodedMessage = serializationOutput.ToArray(); byte[] bytes = new byte[initialBytes.Length + encodedMessage.Length]; @@ -357,7 +360,7 @@ protected async void ParseMessage(byte[] bytes) { try { - serializer = (IColyseusSerializer)new ColyseusNoneSerializer(); + serializer = (IColyseusSerializer) new ColyseusNoneSerializer(); } catch (Exception e) { @@ -369,37 +372,36 @@ protected async void ParseMessage(byte[] bytes) if (bytes.Length > offset) { - try - { - serializer.Handshake(bytes, offset); - } - catch (Exception e) - { - await Leave(false); - OnError?.Invoke(ColyseusErrorCode.SCHEMA_MISMATCH, e.Message); - return; - } + try { + serializer.Handshake(bytes, offset); + } + catch (Exception e) + { + await Leave(false); + OnError?.Invoke(ColyseusErrorCode.SCHEMA_MISMATCH, e.Message); + return; + } } OnJoin?.Invoke(); // Acknowledge JOIN_ROOM - await colyseusConnection.Send(new[] { ColyseusProtocol.JOIN_ROOM }); + await colyseusConnection.Send(new[] {ColyseusProtocol.JOIN_ROOM}); } else if (code == ColyseusProtocol.ERROR) { - Iterator it = new Iterator { Offset = 1 }; + Iterator it = new Iterator {Offset = 1}; float errorCode = Decode.DecodeNumber(bytes, it); string errorMessage = Decode.DecodeString(bytes, it); - OnError?.Invoke((int)errorCode, errorMessage); + OnError?.Invoke((int) errorCode, errorMessage); } else if (code == ColyseusProtocol.ROOM_DATA_SCHEMA) { - Iterator it = new Iterator { Offset = 1 }; + Iterator it = new Iterator {Offset = 1}; float typeId = Decode.DecodeNumber(bytes, it); Type messageType = ColyseusContext.GetInstance().Get(typeId); - Schema.Schema message = (Schema.Schema)Activator.CreateInstance(messageType); + Schema.Schema message = (Schema.Schema) Activator.CreateInstance(messageType); message.Decode(bytes, it); @@ -421,7 +423,7 @@ protected async void ParseMessage(byte[] bytes) } else if (code == ColyseusProtocol.ROOM_STATE) { - SetState(bytes, 1); + SetState(bytes, 1); } else if (code == ColyseusProtocol.ROOM_STATE_PATCH) { @@ -432,7 +434,7 @@ protected async void ParseMessage(byte[] bytes) IColyseusMessageHandler handler = null; object type; - Iterator it = new Iterator { Offset = 1 }; + Iterator it = new Iterator {Offset = 1}; if (Decode.NumberCheck(bytes, it)) { @@ -489,4 +491,4 @@ protected void DisplaySerializerErrorHelp(Exception e, string helpMessage) throw e; } } -} +} \ No newline at end of file diff --git a/Runtime/WebSocket/WebSocket.cs b/Runtime/WebSocket/WebSocket.cs index 6a672993..2cdb6be5 100644 --- a/Runtime/WebSocket/WebSocket.cs +++ b/Runtime/WebSocket/WebSocket.cs @@ -83,7 +83,7 @@ namespace NativeWebSocket { public delegate void WebSocketOpenEventHandler(); public delegate void WebSocketMessageEventHandler(byte[] data); - public delegate void WebSocketErrorEventHandler(int closeCode, string errorMsg); + public delegate void WebSocketErrorEventHandler(string errorMsg); public delegate void WebSocketCloseEventHandler(int closeCode); public enum WebSocketCloseCode @@ -258,7 +258,6 @@ public Task Connect () { } public void CancelConnection () { - Debug.Log("WebSocket.CancelConnection()"); if (State == WebSocketState.Open) Close (WebSocketCloseCode.Abnormal); } @@ -324,8 +323,8 @@ public void DelegateOnMessageEvent (byte[] data) { this.OnMessage?.Invoke (data); } - public void DelegateOnErrorEvent (int code, string errorMsg) { - this.OnError?.Invoke (code, errorMsg); + public void DelegateOnErrorEvent (string errorMsg) { + this.OnError?.Invoke (errorMsg); } public void DelegateOnCloseEvent (int closeCode) { @@ -401,7 +400,7 @@ public async Task Connect() } catch (Exception ex) { - OnError?.Invoke((int)WebSocketCloseCode.Abnormal, "Excpetion in Websocket Connect!\n" + ex.Message); + OnError?.Invoke(ex.Message); OnClose?.Invoke((int)WebSocketCloseCode.Abnormal); } finally @@ -568,7 +567,6 @@ public async Task Receive() { int closeCode = (int)WebSocketCloseCode.Abnormal; await new WaitForBackgroundThread(); - string errorMessage = null; ArraySegment buffer = new ArraySegment(new byte[8192]); try @@ -611,26 +609,19 @@ public async Task Receive() else if (result.MessageType == WebSocketMessageType.Close) { await Close(); - errorMessage = "Closing connection normally with code " + result.CloseStatus; - closeCode = (int)result.CloseStatus; break; } } } } - catch (Exception ex) + catch (Exception) { m_TokenSource.Cancel(); - errorMessage = "Exception encountered in websocket! " + ex.Message; } finally { await new WaitForUpdate(); - if (errorMessage != null) - { - OnError?.Invoke(closeCode, errorMessage); - } OnClose?.Invoke(closeCode); } } @@ -746,7 +737,7 @@ public static void DelegateOnErrorEvent (int instanceId, System.IntPtr errorPtr) if (instances.TryGetValue (instanceId, out instanceRef)) { string errorMsg = Marshal.PtrToStringAuto (errorPtr); - instanceRef.DelegateOnErrorEvent (0, errorMsg); + instanceRef.DelegateOnErrorEvent (errorMsg); } diff --git a/package.json b/package.json index 1d9de61f..59811b5c 100644 --- a/package.json +++ b/package.json @@ -1,36 +1,36 @@ { - "name": "com.gosynthschool.io.colyseus.sdk", - "version": "0.14.22-synthesis-changes", - "displayName": "Colyseus SDK - Synthesis", - "description": "Colyseus Multiplayer SDK for Unity - Synthesis", - "unity": "2019.1", - "license": "MIT", - "category": "Networking", - "repository": { - "type": "git", - "url": "https://github.com/gosynthschool/colyseus-unity-sdk.git" - }, - "publishConfig": { - "registry": "https://npm.pkg.github.com/@gosynthschool" - }, - "author": { - "name": "Colyseus", - "email": "contact@lucidsight.com", - "url": "https://colyseus.io/" - }, - "keywords": [ - "colyseus", - "multiplayer", - "networking", - "authoritative", - "netcode" - ], - "dependencies": {}, - "samples": [ - { - "displayName": "Example", - "description": "Colyseus Example", - "path": "Runtime/Example~" - } - ] + "name": "com.gosynthschool.io.colyseus.sdk", + "version": "0.14.18", + "displayName": "Colyseus SDK - Synthesis", + "description": "Colyseus Multiplayer SDK for Unity - Synthesis", + "unity": "2019.1", + "license": "MIT", + "category": "Networking", + "repository": { + "type": "git", + "url": "https://github.com/gosynthschool/colyseus-unity-sdk.git" + }, + "publishConfig": { + "registry":"https://npm.pkg.github.com/@gosynthschool" + }, + "author": { + "name": "Colyseus", + "email": "contact@lucidsight.com", + "url": "https://colyseus.io/" + }, + "keywords": [ + "colyseus", + "multiplayer", + "networking", + "authoritative", + "netcode" + ], + "dependencies": {}, + "samples": [ + { + "displayName": "Example", + "description": "Colyseus Example", + "path": "Runtime/Example~" + } + ] } From 0ac6706e063cec368b640f83caf3461cf2ec8d02 Mon Sep 17 00:00:00 2001 From: Graham Jans Date: Fri, 3 Feb 2023 16:29:06 -0800 Subject: [PATCH 18/18] Bump version number for publishing to complete the revert --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 59811b5c..c89b155a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.gosynthschool.io.colyseus.sdk", - "version": "0.14.18", + "version": "0.14.23-synthesis-changes", "displayName": "Colyseus SDK - Synthesis", "description": "Colyseus Multiplayer SDK for Unity - Synthesis", "unity": "2019.1", @@ -11,7 +11,7 @@ "url": "https://github.com/gosynthschool/colyseus-unity-sdk.git" }, "publishConfig": { - "registry":"https://npm.pkg.github.com/@gosynthschool" + "registry": "https://npm.pkg.github.com/@gosynthschool" }, "author": { "name": "Colyseus",