✨ added reason of disconnect at callback
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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<byte[]> OnData { get; set; }
|
||||
public Action OnConnected { get; set; }
|
||||
public Action<DisconnectReason> OnDisconnected { get; set; }
|
||||
public Action<RagonDisconnect> 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];
|
||||
|
||||
@@ -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<byte[]> OnData { get; set; }
|
||||
public Action OnConnected { get; set; }
|
||||
public Action<DisconnectReason> OnDisconnected { get; set; }
|
||||
public Action<RagonDisconnect> 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];
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* 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,
|
||||
}
|
||||
@@ -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<byte[]> OnData { get; set; }
|
||||
public Action OnConnected { get; set; }
|
||||
public Action<DisconnectReason> OnDisconnected { get; set; }
|
||||
public Action<RagonDisconnect> OnDisconnected { get; set; }
|
||||
public ulong BytesSent { get; }
|
||||
public ulong BytesReceived { get; }
|
||||
public int Ping { get; }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Ragon.Protocol
|
||||
{
|
||||
public enum RagonDisconnect
|
||||
{
|
||||
MANUAL,
|
||||
TIMEOUT,
|
||||
SERVER,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user