diff --git a/Ragon.Client.Simulation/Sources/Game.cs b/Ragon.Client.Simulation/Sources/Game.cs index feca145..a785029 100644 --- a/Ragon.Client.Simulation/Sources/Game.cs +++ b/Ragon.Client.Simulation/Sources/Game.cs @@ -1,5 +1,7 @@  +using Ragon.Protocol; + namespace Ragon.Client.Simulation; public class Game : IRagonListener @@ -63,7 +65,7 @@ public class Game : IRagonListener RagonLog.Trace("Left"); } - public void OnDisconnected(RagonClient client) + public void OnDisconnected(RagonClient client, RagonDisconnect ragonDisconnect) { RagonLog.Trace("Disconnected"); } diff --git a/Ragon.Client.Simulation/Sources/IO/RagonENetConnection.cs b/Ragon.Client.Simulation/Sources/IO/RagonENetConnection.cs index d9bedb0..dce87d9 100644 --- a/Ragon.Client.Simulation/Sources/IO/RagonENetConnection.cs +++ b/Ragon.Client.Simulation/Sources/IO/RagonENetConnection.cs @@ -16,6 +16,7 @@ using ENet; +using Ragon.Protocol; using Event = ENet.Event; using EventType = ENet.EventType; @@ -31,7 +32,7 @@ namespace Ragon.Client public Action OnData { get; set; } public Action OnConnected { get; set; } - public Action OnDisconnected { get; set; } + public Action OnDisconnected { get; set; } public ulong BytesSent { get; } public ulong BytesReceived { get; } public int Ping { get; } @@ -98,10 +99,10 @@ namespace Ragon.Client OnConnected?.Invoke(); break; case EventType.Disconnect: - OnDisconnected?.Invoke(DisconnectReason.MANUAL); + OnDisconnected?.Invoke(RagonDisconnect.SERVER); break; case EventType.Timeout: - OnDisconnected?.Invoke(DisconnectReason.TIMEOUT); + OnDisconnected?.Invoke(RagonDisconnect.TIMEOUT); break; case EventType.Receive: var data = new byte[_netEvent.Packet.Length]; diff --git a/Ragon.Client.Simulation/Sources/IO/RagonNullConnection.cs b/Ragon.Client.Simulation/Sources/IO/RagonNullConnection.cs index 2ca2758..3ab94ef 100644 --- a/Ragon.Client.Simulation/Sources/IO/RagonNullConnection.cs +++ b/Ragon.Client.Simulation/Sources/IO/RagonNullConnection.cs @@ -16,6 +16,7 @@ using ENet; +using Ragon.Protocol; using Event = ENet.Event; using EventType = ENet.EventType; @@ -31,7 +32,7 @@ namespace Ragon.Client public Action OnData { get; set; } public Action OnConnected { get; set; } - public Action OnDisconnected { get; set; } + public Action OnDisconnected { get; set; } public ulong BytesSent { get; } public ulong BytesReceived { get; } public int Ping { get; } @@ -99,10 +100,10 @@ namespace Ragon.Client OnConnected?.Invoke(); break; case EventType.Disconnect: - OnDisconnected?.Invoke(DisconnectReason.MANUAL); + OnDisconnected?.Invoke(RagonDisconnect.SERVER); break; case EventType.Timeout: - OnDisconnected?.Invoke(DisconnectReason.TIMEOUT); + OnDisconnected?.Invoke(RagonDisconnect.TIMEOUT); break; case EventType.Receive: var data = new byte[_netEvent.Packet.Length]; diff --git a/Ragon.Client/Sources/IO/DisconnectReason.cs b/Ragon.Client/Sources/IO/DisconnectReason.cs deleted file mode 100644 index af1901d..0000000 --- a/Ragon.Client/Sources/IO/DisconnectReason.cs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2023 Eduard Kargin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Ragon.Client; - -public enum DisconnectReason -{ - MANUAL, - TIMEOUT, -} \ No newline at end of file diff --git a/Ragon.Client/Sources/IO/INetworkConnection.cs b/Ragon.Client/Sources/IO/INetworkConnection.cs index f32b730..b25ddd8 100644 --- a/Ragon.Client/Sources/IO/INetworkConnection.cs +++ b/Ragon.Client/Sources/IO/INetworkConnection.cs @@ -15,6 +15,8 @@ */ +using Ragon.Protocol; + namespace Ragon.Client; public interface INetworkConnection: IRagonConnection @@ -23,7 +25,7 @@ public interface INetworkConnection: IRagonConnection public INetworkChannel Unreliable { get; } public Action OnData { get; set; } public Action OnConnected { get; set; } - public Action OnDisconnected { get; set; } + public Action OnDisconnected { get; set; } public ulong BytesSent { get; } public ulong BytesReceived { get; } public int Ping { get; } diff --git a/Ragon.Client/Sources/Listener/IRagonConnectionListener.cs b/Ragon.Client/Sources/Listener/IRagonConnectionListener.cs index ec4e06a..fd295db 100644 --- a/Ragon.Client/Sources/Listener/IRagonConnectionListener.cs +++ b/Ragon.Client/Sources/Listener/IRagonConnectionListener.cs @@ -14,10 +14,12 @@ * limitations under the License. */ +using Ragon.Protocol; + namespace Ragon.Client; public interface IRagonConnectionListener { void OnConnected(RagonClient client); - void OnDisconnected(RagonClient client); + void OnDisconnected(RagonClient client, RagonDisconnect reason); } \ No newline at end of file diff --git a/Ragon.Client/Sources/RagonClient.cs b/Ragon.Client/Sources/RagonClient.cs index 6c71258..bcb1058 100644 --- a/Ragon.Client/Sources/RagonClient.cs +++ b/Ragon.Client/Sources/RagonClient.cs @@ -110,7 +110,7 @@ namespace Ragon.Client _room.Cleanup(); _connection.Disconnect(); - OnDisconnected(DisconnectReason.MANUAL); + OnDisconnected(RagonDisconnect.MANUAL); } public void Update(float dt) @@ -181,11 +181,11 @@ namespace Ragon.Client _status = RagonStatus.CONNECTED; } - private void OnDisconnected(DisconnectReason reason) + private void OnDisconnected(RagonDisconnect reason) { RagonLog.Trace($"Disconnected: {reason}"); - _listenerList.OnDisconnected(); + _listenerList.OnDisconnected(reason); _status = RagonStatus.DISCONNECTED; } diff --git a/Ragon.Client/Sources/RagonListenerList.cs b/Ragon.Client/Sources/RagonListenerList.cs index 134bd62..4e33d07 100644 --- a/Ragon.Client/Sources/RagonListenerList.cs +++ b/Ragon.Client/Sources/RagonListenerList.cs @@ -14,6 +14,8 @@ * limitations under the License. */ +using Ragon.Protocol; + namespace Ragon.Client { internal class RagonListenerList @@ -210,10 +212,10 @@ namespace Ragon.Client listener.OnConnected(_client); } - public void OnDisconnected() + public void OnDisconnected(RagonDisconnect disconnect) { foreach (var listener in _connectionListeners) - listener.OnDisconnected(_client); + listener.OnDisconnected(_client, disconnect); } } } \ No newline at end of file diff --git a/Ragon.Protocol/Sources/RagonDisconnect.cs b/Ragon.Protocol/Sources/RagonDisconnect.cs new file mode 100644 index 0000000..0a68055 --- /dev/null +++ b/Ragon.Protocol/Sources/RagonDisconnect.cs @@ -0,0 +1,9 @@ +namespace Ragon.Protocol +{ + public enum RagonDisconnect + { + MANUAL, + TIMEOUT, + SERVER, + } +} \ No newline at end of file