diff --git a/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.dll b/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.dll
index 449965dd..2b4b71b1 100644
Binary files a/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.dll and b/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.dll differ
diff --git a/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.xml b/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.xml
index 8d519b00..cebc7046 100644
--- a/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.xml
+++ b/Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.xml
@@ -473,16 +473,42 @@
The to add.
The Message instance that the was added to.
+
+ Adds a to the message.
+ The to add.
+ The Message instance that the was added to.
+
+
+ Converts a given to bytes and adds them to the message's contents.
+ The to convert.
+
Retrieves a from the message.
The that was retrieved.
+
+ Retrieves a from the message.
+ The that was retrieved.
+
+
+ Retrieves a from the next 2 bytes, starting at the read position.
+ The converted .
+
+
+ Retrieves a from the message without moving the read position, allowing the same bytes to be read again.
+
Adds a array to the message.
The array to add.
Whether or not to include the length of the array in the message.
The Message instance that the array was added to.
+
+ Adds a array to the message.
+ The array to add.
+ Whether or not to include the length of the array in the message.
+ The Message instance that the array was added to.
+
Retrieves a array from the message.
The array that was retrieved.
@@ -492,24 +518,6 @@
The length of the array.
The array that was retrieved.
-
- Adds a to the message.
- The to add.
- The Message instance that the was added to.
-
-
- Retrieves a from the message.
- The that was retrieved.
-
-
- Retrieves a from the message without moving the read position, allowing the same bytes to be read again.
-
-
- Adds a array to the message.
- The array to add.
- Whether or not to include the length of the array in the message.
- The Message instance that the array was added to.
-
Retrieves a array from the message.
The array that was retrieved.
@@ -524,16 +532,39 @@
The to add.
The Message instance that the was added to.
+
+ Adds a to the message.
+ The to add.
+ The Message instance that the was added to.
+
+
+ Converts a given to bytes and adds them to the message's contents.
+ The to convert.
+
Retrieves an from the message.
The that was retrieved.
+
+ Retrieves a from the message.
+ The that was retrieved.
+
+
+ Retrieves an from the next 4 bytes, starting at the read position.
+ The converted .
+
Adds an array message.
The array to add.
Whether or not to include the length of the array in the message.
The Message instance that the array was added to.
+
+ Adds a array to the message.
+ The array to add.
+ Whether or not to include the length of the array in the message.
+ The Message instance that the array was added to.
+
Retrieves an array from the message.
The array that was retrieved.
@@ -543,21 +574,6 @@
The length of the array.
The array that was retrieved.
-
- Adds a to the message.
- The to add.
- The Message instance that the was added to.
-
-
- Retrieves a from the message.
- The that was retrieved.
-
-
- Adds a array to the message.
- The array to add.
- Whether or not to include the length of the array in the message.
- The Message instance that the array was added to.
-
Retrieves a array from the message.
The array that was retrieved.
@@ -572,16 +588,35 @@
The to add.
The Message instance that the was added to.
+
+ Adds a to the message.
+ The to add.
+ The Message instance that the was added to.
+
+
+ Converts a given to bytes and adds them to the message's contents.
+ The to convert.
+
Retrieves a from the message.
The that was retrieved.
+
+ Retrieves a from the message.
+ The that was retrieved.
+
Adds a array to the message.
The array to add.
Whether or not to include the length of the array in the message.
The Message instance that the array was added to.
+
+ Adds a array to the message.
+ The array to add.
+ Whether or not to include the length of the array in the message.
+ The Message instance that the array was added to.
+
Retrieves a array from the message.
The array that was retrieved.
@@ -591,21 +626,6 @@
The length of the array.
The array that was retrieved.
-
- Adds a to the message.
- The to add.
- The Message instance that the was added to.
-
-
- Retrieves a from the message.
- The that was retrieved.
-
-
- Adds a array to the message.
- The array to add.
- Whether or not to include the length of the array in the message.
- The Message instance that the array was added to.
-
Retrieves a array from the message.
The array that was retrieved.
@@ -749,11 +769,8 @@
The data to send.
The endpoint to send the data to.
-
- The method to use when sending data.
-
-
- The name to use when logging messages via .
+
+ The RudpSocket instance to use when sending data.
The round trip time of the connection. -1 if not calculated yet.
@@ -761,10 +778,9 @@
The smoothed round trip time of the connection. -1 if not calculated yet.
-
+
Handles initial setup.
- The method to use when sending data.
- The name to use when logging messages via .
+ The RudpSocket instance to use when sending data.
Updates which messages we've received acks for.
@@ -848,6 +864,9 @@
Base class for all RUDP connections.
+
+ Whether or not to output informational log messages. Error-related log messages ignore this setting.
+
The name to use when logging messages via
diff --git a/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.dll b/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.dll
index 449965dd..2b4b71b1 100644
Binary files a/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.dll and b/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.dll differ
diff --git a/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.xml b/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.xml
index 8d519b00..cebc7046 100644
--- a/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.xml
+++ b/Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.xml
@@ -473,16 +473,42 @@
The to add.
The Message instance that the was added to.
+
+ Adds a to the message.
+ The to add.
+ The Message instance that the was added to.
+
+
+ Converts a given to bytes and adds them to the message's contents.
+ The to convert.
+
Retrieves a from the message.
The that was retrieved.
+
+ Retrieves a from the message.
+ The that was retrieved.
+
+
+ Retrieves a from the next 2 bytes, starting at the read position.
+ The converted .
+
+
+ Retrieves a from the message without moving the read position, allowing the same bytes to be read again.
+
Adds a array to the message.
The array to add.
Whether or not to include the length of the array in the message.
The Message instance that the array was added to.
+
+ Adds a array to the message.
+ The array to add.
+ Whether or not to include the length of the array in the message.
+ The Message instance that the array was added to.
+
Retrieves a array from the message.
The array that was retrieved.
@@ -492,24 +518,6 @@
The length of the array.
The array that was retrieved.
-
- Adds a to the message.
- The to add.
- The Message instance that the was added to.
-
-
- Retrieves a from the message.
- The that was retrieved.
-
-
- Retrieves a from the message without moving the read position, allowing the same bytes to be read again.
-
-
- Adds a array to the message.
- The array to add.
- Whether or not to include the length of the array in the message.
- The Message instance that the array was added to.
-
Retrieves a array from the message.
The array that was retrieved.
@@ -524,16 +532,39 @@
The to add.
The Message instance that the was added to.
+
+ Adds a to the message.
+ The to add.
+ The Message instance that the was added to.
+
+
+ Converts a given to bytes and adds them to the message's contents.
+ The to convert.
+
Retrieves an from the message.
The that was retrieved.
+
+ Retrieves a from the message.
+ The that was retrieved.
+
+
+ Retrieves an from the next 4 bytes, starting at the read position.
+ The converted .
+
Adds an array message.
The array to add.
Whether or not to include the length of the array in the message.
The Message instance that the array was added to.
+
+ Adds a array to the message.
+ The array to add.
+ Whether or not to include the length of the array in the message.
+ The Message instance that the array was added to.
+
Retrieves an array from the message.
The array that was retrieved.
@@ -543,21 +574,6 @@
The length of the array.
The array that was retrieved.
-
- Adds a to the message.
- The to add.
- The Message instance that the was added to.
-
-
- Retrieves a from the message.
- The that was retrieved.
-
-
- Adds a array to the message.
- The array to add.
- Whether or not to include the length of the array in the message.
- The Message instance that the array was added to.
-
Retrieves a array from the message.
The array that was retrieved.
@@ -572,16 +588,35 @@
The to add.
The Message instance that the was added to.
+
+ Adds a to the message.
+ The to add.
+ The Message instance that the was added to.
+
+
+ Converts a given to bytes and adds them to the message's contents.
+ The to convert.
+
Retrieves a from the message.
The that was retrieved.
+
+ Retrieves a from the message.
+ The that was retrieved.
+
Adds a array to the message.
The array to add.
Whether or not to include the length of the array in the message.
The Message instance that the array was added to.
+
+ Adds a array to the message.
+ The array to add.
+ Whether or not to include the length of the array in the message.
+ The Message instance that the array was added to.
+
Retrieves a array from the message.
The array that was retrieved.
@@ -591,21 +626,6 @@
The length of the array.
The array that was retrieved.
-
- Adds a to the message.
- The to add.
- The Message instance that the was added to.
-
-
- Retrieves a from the message.
- The that was retrieved.
-
-
- Adds a array to the message.
- The array to add.
- Whether or not to include the length of the array in the message.
- The Message instance that the array was added to.
-
Retrieves a array from the message.
The array that was retrieved.
@@ -749,11 +769,8 @@
The data to send.
The endpoint to send the data to.
-
- The method to use when sending data.
-
-
- The name to use when logging messages via .
+
+ The RudpSocket instance to use when sending data.
The round trip time of the connection. -1 if not calculated yet.
@@ -761,10 +778,9 @@
The smoothed round trip time of the connection. -1 if not calculated yet.
-
+
Handles initial setup.
- The method to use when sending data.
- The name to use when logging messages via .
+ The RudpSocket instance to use when sending data.
Updates which messages we've received acks for.
@@ -848,6 +864,9 @@
Base class for all RUDP connections.
+
+ Whether or not to output informational log messages. Error-related log messages ignore this setting.
+
The name to use when logging messages via
diff --git a/RiptideNetworking/RiptideNetworking/Client.cs b/RiptideNetworking/RiptideNetworking/Client.cs
index 4b82cd8b..508b090f 100644
--- a/RiptideNetworking/RiptideNetworking/Client.cs
+++ b/RiptideNetworking/RiptideNetworking/Client.cs
@@ -75,11 +75,13 @@ public void Connect(string ip, ushort port, ActionQueue receiveActionQueue = nul
this.maxConnectionAttempts = maxConnectionAttempts;
connectionAttempts = 0;
remoteEndPoint = new IPEndPoint(IPAddress.Parse(ip), port);
- rudp = new Rudp(Send, LogName);
+ rudp = new Rudp(this);
- RiptideLogger.Log(LogName, $"Connecting to {remoteEndPoint}...");
StartListening();
connectionState = ConnectionState.connecting;
+
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, $"Connecting to {remoteEndPoint}...");
heartbeatTimer = new Timer(Heartbeat, null, 0, HeartbeatInterval);
}
@@ -191,7 +193,7 @@ internal override void Handle(byte[] data, IPEndPoint fromEndPoint, HeaderType h
HandleDisconnect();
break;
default:
- RiptideLogger.Log($"Unknown message header type '{headerType}'! Discarding {data.Length} bytes.");
+ RiptideLogger.Log("ERROR", $"Unknown message header type '{headerType}'! Discarding {data.Length} bytes.");
return;
}
}
@@ -224,7 +226,9 @@ public void Disconnect()
SendDisconnect();
LocalDisconnect();
- RiptideLogger.Log(LogName, "Disconnected.");
+
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, "Disconnected.");
}
/// Cleans up local objects on disconnection.
@@ -368,7 +372,8 @@ private void HandleDisconnect()
public event EventHandler Connected;
private void OnConnected(EventArgs e)
{
- RiptideLogger.Log(LogName, "Connected successfully!");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, "Connected successfully!");
if (receiveActionQueue == null)
Connected?.Invoke(this, e);
@@ -379,7 +384,8 @@ private void OnConnected(EventArgs e)
public event EventHandler ConnectionFailed;
private void OnConnectionFailed(EventArgs e)
{
- RiptideLogger.Log(LogName, "Connection to server failed!");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, "Connection to server failed!");
if (receiveActionQueue == null)
ConnectionFailed?.Invoke(this, e);
@@ -396,7 +402,8 @@ internal void OnMessageReceived(ClientMessageReceivedEventArgs e)
public event EventHandler Disconnected;
private void OnDisconnected(EventArgs e)
{
- RiptideLogger.Log(LogName, "Disconnected from server.");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, "Disconnected from server.");
if (receiveActionQueue == null)
Disconnected?.Invoke(this, e);
@@ -408,7 +415,8 @@ private void OnDisconnected(EventArgs e)
public event EventHandler ClientConnected;
private void OnClientConnected(ClientConnectedEventArgs e)
{
- RiptideLogger.Log(LogName, $"Client {e.Id} connected.");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, $"Client {e.Id} connected.");
if (receiveActionQueue == null)
ClientConnected?.Invoke(this, e);
@@ -419,7 +427,8 @@ private void OnClientConnected(ClientConnectedEventArgs e)
public event EventHandler ClientDisconnected;
private void OnClientDisconnected(ClientDisconnectedEventArgs e)
{
- RiptideLogger.Log(LogName, $"Client {e.Id} disconnected.");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, $"Client {e.Id} disconnected.");
if (receiveActionQueue == null)
ClientDisconnected?.Invoke(this, e);
diff --git a/RiptideNetworking/RiptideNetworking/Rudp.cs b/RiptideNetworking/RiptideNetworking/Rudp.cs
index d7b6043f..c237062e 100644
--- a/RiptideNetworking/RiptideNetworking/Rudp.cs
+++ b/RiptideNetworking/RiptideNetworking/Rudp.cs
@@ -28,10 +28,8 @@ internal class Rudp
/// The data to send.
/// The endpoint to send the data to.
internal delegate void Send(byte[] data, IPEndPoint toEndPoint);
- /// The method to use when sending data.
- private readonly Send send;
- /// The name to use when logging messages via .
- private readonly string logName;
+ /// The RudpSocket instance to use when sending data.
+ private readonly RudpSocket rudpSocket;
private short _rtt = -1;
/// The round trip time of the connection. -1 if not calculated yet.
@@ -48,12 +46,10 @@ internal short RTT
internal short SmoothRTT { get; set; } = -1;
/// Handles initial setup.
- /// The method to use when sending data.
- /// The name to use when logging messages via .
- internal Rudp(Send send, string logName)
+ /// The RudpSocket instance to use when sending data.
+ internal Rudp(RudpSocket rudpSocket)
{
- this.send = send;
- this.logName = logName;
+ this.rudpSocket = rudpSocket;
SendLockables = new SendLockables();
ReceiveLockables = new ReceiveLockables();
}
@@ -209,24 +205,28 @@ internal void TrySend()
if (sendAttempts >= maxSendAttempts)
{
// Send attempts exceeds max send attempts, so give up
- HeaderType headerType = (HeaderType)data[0];
- if (headerType == HeaderType.reliable)
+ if (rudp.rudpSocket.ShouldOutputInfoLogs)
{
-#if BIG_ENDIAN
- ushort messageId = (ushort)(data[4] | (data[3] << 8));
-#else
- ushort messageId = (ushort)(data[3] | (data[4] << 8));
-#endif
- RiptideLogger.Log(rudp.logName, $"No ack received for {headerType} message (ID: {messageId}) after {sendAttempts} attempt(s), delivery may have failed!");
+ HeaderType headerType = (HeaderType)data[0];
+ if (headerType == HeaderType.reliable)
+ {
+ #if BIG_ENDIAN
+ ushort messageId = (ushort)(data[4] | (data[3] << 8));
+ #else
+ ushort messageId = (ushort)(data[3] | (data[4] << 8));
+ #endif
+
+ RiptideLogger.Log(rudp.rudpSocket.LogName, $"No ack received for {headerType} message (ID: {messageId}) after {sendAttempts} attempt(s), delivery may have failed!");
+ }
+ else
+ RiptideLogger.Log(rudp.rudpSocket.LogName, $"No ack received for internal {headerType} message after {sendAttempts} attempt(s), delivery may have failed!");
}
- else
- RiptideLogger.Log(rudp.logName, $"No ack received for internal {headerType} message after {sendAttempts} attempt(s), delivery may have failed!");
Clear();
return;
}
- rudp.send(data, remoteEndPoint);
+ rudp.rudpSocket.Send(data, remoteEndPoint);
lastSendTime = DateTime.UtcNow;
sendAttempts++;
diff --git a/RiptideNetworking/RiptideNetworking/RudpSocket.cs b/RiptideNetworking/RiptideNetworking/RudpSocket.cs
index 5ad88453..911e38f7 100644
--- a/RiptideNetworking/RiptideNetworking/RudpSocket.cs
+++ b/RiptideNetworking/RiptideNetworking/RudpSocket.cs
@@ -19,6 +19,8 @@ enum ConnectionState : byte
/// Base class for all RUDP connections.
public abstract class RudpSocket
{
+ /// Whether or not to output informational log messages. Error-related log messages ignore this setting.
+ public bool ShouldOutputInfoLogs { get; set; } = true;
/// The name to use when logging messages via
public readonly string LogName;
diff --git a/RiptideNetworking/RiptideNetworking/Server.cs b/RiptideNetworking/RiptideNetworking/Server.cs
index 0c9382e0..6ea3676b 100644
--- a/RiptideNetworking/RiptideNetworking/Server.cs
+++ b/RiptideNetworking/RiptideNetworking/Server.cs
@@ -69,9 +69,11 @@ public void Start(ushort port, ushort maxClientCount, ActionQueue receiveActionQ
StartListening(port);
- RiptideLogger.Log(LogName, $"Started on port {port}.");
heartbeatTimer = new Timer(Heartbeat, null, 0, ClientHeartbeatInterval);
IsRunning = true;
+
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, $"Started on port {port}.");
}
/// Checks if clients have timed out. Called by .
@@ -188,7 +190,7 @@ internal override void Handle(byte[] data, IPEndPoint fromEndPoint, HeaderType h
HandleDisconnect(fromEndPoint);
break;
default:
- RiptideLogger.Log($"Unknown message header type '{headerType}'! Discarding {data.Length} bytes.");
+ RiptideLogger.Log("ERROR", $"Unknown message header type '{headerType}'! Discarding {data.Length} bytes.");
return;
}
}
@@ -301,7 +303,8 @@ public void DisconnectClient(ServerClient client)
lock (clients)
clients.Remove(client.remoteEndPoint);
- RiptideLogger.Log(LogName, $"Kicked {client.remoteEndPoint}.");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, $"Kicked {client.remoteEndPoint}.");
OnClientDisconnected(new ClientDisconnectedEventArgs(client.Id));
availableClientIds.Add(client.Id);
@@ -325,7 +328,9 @@ public void Stop()
heartbeatTimer.Change(Timeout.Infinite, Timeout.Infinite);
heartbeatTimer.Dispose();
StopListening();
- RiptideLogger.Log(LogName, "Server stopped.");
+
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, "Server stopped.");
}
#region Messages
@@ -383,7 +388,8 @@ private void SendClientDisconnected(ushort id)
public event EventHandler ClientConnected;
internal void OnClientConnected(ServerClientConnectedEventArgs e)
{
- RiptideLogger.Log(LogName, $"{e.Client.remoteEndPoint} connected successfully! Client ID: {e.Client.Id}");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, $"{e.Client.remoteEndPoint} connected successfully! Client ID: {e.Client.Id}");
if (receiveActionQueue == null)
ClientConnected?.Invoke(this, e);
@@ -402,7 +408,8 @@ internal void OnMessageReceived(ServerMessageReceivedEventArgs e)
public event EventHandler ClientDisconnected;
internal void OnClientDisconnected(ClientDisconnectedEventArgs e)
{
- RiptideLogger.Log(LogName, $"Client {e.Id} has disconnected.");
+ if (ShouldOutputInfoLogs)
+ RiptideLogger.Log(LogName, $"Client {e.Id} has disconnected.");
if (receiveActionQueue == null)
ClientDisconnected?.Invoke(this, e);
diff --git a/RiptideNetworking/RiptideNetworking/ServerClient.cs b/RiptideNetworking/RiptideNetworking/ServerClient.cs
index ecffd529..c45cd0d4 100644
--- a/RiptideNetworking/RiptideNetworking/ServerClient.cs
+++ b/RiptideNetworking/RiptideNetworking/ServerClient.cs
@@ -42,7 +42,7 @@ internal ServerClient(Server server, IPEndPoint endPoint, ushort id)
this.server = server;
remoteEndPoint = endPoint;
Id = id;
- Rudp = new Rudp(server.Send, this.server.LogName);
+ Rudp = new Rudp(server);
lastHeartbeat = DateTime.UtcNow;
connectionState = ConnectionState.connecting;
@@ -133,7 +133,7 @@ internal void HandleWelcomeReceived(Message message)
ushort id = message.GetUShort();
- if (Id != id)
+ if (Id != id && server.ShouldOutputInfoLogs)
RiptideLogger.Log(server.LogName, $"Client has assumed incorrect ID: {id}");
connectionState = ConnectionState.connected;