Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,093 changes: 4,093 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/package-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
REPOSITORY_URL: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
PROJECT_NAME: Networking
PROJECT_NAME: FluffyVoid.Networking
jobs:
build:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Networking.sln → FluffyVoid.Networking.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Networking", "Networking\Networking.csproj", "{9B154867-05CF-4C18-B61F-AD4DCC01B71F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluffyVoid.Networking", "FluffyVoid.Networking\FluffyVoid.Networking.csproj", "{9B154867-05CF-4C18-B61F-AD4DCC01B71F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
449 changes: 449 additions & 0 deletions FluffyVoid.Networking.sln.DotSettings

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latestmajor</LangVersion>
<LangVersion>13</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>FluffyVoid.Networking</AssemblyName>
Expand All @@ -12,10 +12,10 @@
<Authors>FluffyVoid</Authors>
<Description>C# tools and utilities for handling Networking operations in an application.</Description>
<Company>FluffyVoid</Company>
<AssemblyVersion>1.0.1</AssemblyVersion>
<FileVersion>1.0.1</FileVersion>
<AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.2</FileVersion>
<RepositoryUrl>https://github.com/ashiryn/Networking</RepositoryUrl>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand All @@ -27,8 +27,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluffyVoid.Logging" Version="1.0.1"/>
<PackageReference Include="FluffyVoid.Utilities" Version="1.0.3"/>
<PackageReference Include="FluffyVoid.Logging" Version="1.0.3"/>
<PackageReference Include="FluffyVoid.Utilities" Version="1.0.4" />
</ItemGroup>
<ItemGroup>
<None Include="bin/$(Configuration)/FluffyVoid.Networking.xml" Pack="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=udp_005Ceventarguments/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
84 changes: 84 additions & 0 deletions FluffyVoid.Networking/Udp/ClientConnectionInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
namespace FluffyVoid.Networking.Udp
{
/// <summary>
/// Data class used to store information about a clients connection
/// </summary>
public class ClientConnectionInformation : IUdpSerializable
{
/// <summary>
/// The id that was assigned to the client
/// </summary>
public short Id { get; private set; }
/// <summary>
/// The name of the client
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Whether the connection was successful or not
/// </summary>
public bool Successful { get; private set; }

/// <summary>
/// Default constructor for the data class ensuring proper deserialization
/// </summary>
public ClientConnectionInformation()
{
Name = string.Empty;
}
/// <summary>
/// Constructor used to initialize the data class with a clients name
/// </summary>
/// <remarks>
/// Most often used by the client to request a connection to the server
/// </remarks>
/// <param name="name">The name the client will be connecting as</param>
public ClientConnectionInformation(string name)
{
Name = name;
}
/// <summary>
/// Constructor used to initialize the data class
/// </summary>
/// <remarks>
/// Most often used by the server to inform the connecting client if the
/// connection was successful and their new client
/// ID
/// </remarks>
/// <param name="name">The name the client will be connecting as</param>
/// <param name="id">The id that is to be assigned to the client</param>
/// <param name="success">Whether the connection was successful or not</param>
public ClientConnectionInformation(string name, short id, bool success)
{
Name = name;
Id = id;
Successful = success;
}
/// <summary>
/// Deserialization method used to deserialize the data in this class from a
/// network byte stream
/// </summary>
/// <param name="e">
/// The serialization event arg to use in the deserialization
/// process
/// </param>
public void Deserialize(UdpDeserializerEventArgs e)
{
Name = e.Reader.ReadString();
Id = e.Reader.ReadShort();
Successful = e.Reader.ReadBool();
}

/// <summary>
/// Serialization method used to serialize the data in this class to a network
/// byte stream
/// </summary>
/// <param name="e">The serialization event arg to use in the serialization process</param>
public int Serialize(UdpSerializerEventArgs e)
{
int count = e.Writer.WriteString(Name);
count += e.Writer.WriteShort(Id);
count += e.Writer.WriteBool(Successful);
return count;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ namespace FluffyVoid.Networking.Udp
/// </summary>
public class ClientInformation
{
/// <summary>
/// The id assigned to the client
/// </summary>
public short Id { get; }
/// <summary>
/// The name of the client
/// </summary>
public string Name { get; }
/// <summary>
/// The ip endpoint address of the client
/// </summary>
public IPEndPoint Endpoint { get; }
/// <summary>
/// The id assigned to the client
/// </summary>
public short Id { get; }
/// <summary>
/// Whether the client is currently active via the heartbeat system
/// </summary>
public bool IsAlive { get; set; }
/// <summary>
/// The name of the client
/// </summary>
public string Name { get; }

/// <summary>
/// Constructor used to initialize the client information
Expand All @@ -32,10 +32,10 @@ public class ClientInformation
/// <param name="endPoint">The ip endpoint address of the client</param>
public ClientInformation(short id, string name, IPEndPoint endPoint)
{
Id = id;
Name = name;
Id = id;
Name = name;
Endpoint = endPoint;
IsAlive = true;
IsAlive = true;
}
}
}
77 changes: 77 additions & 0 deletions FluffyVoid.Networking/Udp/ClientMessageTagRegistration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using FluffyVoid.Utilities;

namespace FluffyVoid.Networking.Udp
{
/// <summary>
/// Serializable data class that a client can send to register receiving
/// messages for the desired tags only
/// </summary>
public class ClientMessageTagRegistration : IUdpSerializable
{
/// <summary>
/// The list of tags to register to
/// </summary>
private List<ushort> _tags;

/// <summary>
/// Constructor used to set up the tags to register
/// </summary>
/// <param name="tagsToRegister">Param list of tags to register</param>
public ClientMessageTagRegistration(params ushort[] tagsToRegister)
{
_tags = new List<ushort>(tagsToRegister);
}
/// <summary>
/// Constructor used to set up the tags to register to via enum
/// </summary>
/// <param name="tagsToRegister">Param list of enum tags to register</param>
public ClientMessageTagRegistration(params Enum[] tagsToRegister)
{
_tags = new List<ushort>(tagsToRegister.Select(x => x.ToUshort()));
}
/// <summary>
/// Constructor used to set up the tags to register
/// </summary>
/// <param name="tagsToRegister">Param list of tags to register</param>
public ClientMessageTagRegistration(List<ushort> tagsToRegister)
{
_tags = new List<ushort>(tagsToRegister);
}
/// <summary>
/// Constructor used to set up the tags to register to via enum
/// </summary>
/// <param name="tagsToRegister">Param list of enum tags to register</param>
public ClientMessageTagRegistration(List<Enum> tagsToRegister)
{
_tags = new List<ushort>(tagsToRegister.Select(x => x.ToUshort()));
}
/// <summary>
/// Deserializes the list of tags from an udp stream
/// </summary>
/// <param name="e">The deserializer args to use in deserializing the data</param>
public void Deserialize(UdpDeserializerEventArgs e)
{
ushort count = e.Reader.ReadUshort();
_tags = new List<ushort>();
for (int index = 0; index < count; ++index)
{
_tags.Add(e.Reader.ReadUshort());
}
}

/// <summary>
/// Serializes the list of tags to an udp stream
/// </summary>
/// <param name="e">The serializer args to use in serializing the data</param>
public int Serialize(UdpSerializerEventArgs e)
{
int count = e.Writer.WriteUshort((ushort)_tags.Count);
foreach (ushort currentTag in _tags)
{
count += e.Writer.WriteUshort(currentTag);
}

return count;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global

namespace FluffyVoid.Networking.Udp
{
/// <summary>
/// Event arg for use when a client has connected to an endpoint
/// </summary>
public class ClientConnectedEventArgs : EventArgs
{
/// <summary>
/// The client information to send with the event arg
/// </summary>
public ClientConnectionInformation ClientInfo { get; }

/// <summary>
/// Constructor used to initialize the event arg
/// </summary>
/// <param name="info">The client information data to store</param>
public ClientConnectedEventArgs(ClientConnectionInformation info)
{
ClientInfo = info;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global

namespace FluffyVoid.Networking.Udp
{
/// <summary>
/// Event arg for use when a client has disconnected from an endpoint
/// </summary>
public class ClientDisconnectedEventArgs : EventArgs
{
/// <summary>
/// The client information to send with the event arg
/// </summary>
public ClientConnectionInformation ClientInfo { get; }
/// <summary>
/// Whether the disconnect was initiated by the connected client or not
/// </summary>
public bool IsLocalDisconnect { get; }

/// <summary>
/// Constructor used to initialize the event arg
/// </summary>
/// <param name="isLocalDisconnect">
/// Whether the disconnect was initiated by the
/// connected client or not
/// </param>
/// <param name="info">The client information data to store</param>
public ClientDisconnectedEventArgs(bool isLocalDisconnect,
ClientConnectionInformation info)
{
IsLocalDisconnect = isLocalDisconnect;
ClientInfo = info;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
/// <summary>
/// Defines a contract for network message event args
/// </summary>
/// <typeparam name="TNetworkMessage">The type of network message the args is responsible for</typeparam>
public interface INetworkMessageEventArgs<TNetworkMessage>
/// <typeparam name="TNetworkMessage">
/// The type of network message the args is
/// responsible for
/// </typeparam>
public interface INetworkMessageEventArgs<out TNetworkMessage>
where TNetworkMessage : INetworkMessage
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace FluffyVoid.Networking.Udp
{
/// <summary>
/// Event arg used for deserializing custom classes from a UDP network stream
/// </summary>
public class UdpDeserializerEventArgs : EventArgs
{
/// <summary>
/// Reference to the UdpReader assigned to the network stream
/// </summary>
public UdpReader Reader { get; }

/// <summary>
/// Constructor used to pass the UdpReader as part of the event arg
/// </summary>
/// <param name="reader">The reader to assign to the event arg</param>
public UdpDeserializerEventArgs(UdpReader reader)
{
Reader = reader;
}
}
}
26 changes: 26 additions & 0 deletions FluffyVoid.Networking/Udp/EventArguments/UdpMessageEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace FluffyVoid.Networking.Udp
{
/// <summary>
/// Event arg for use when receiving a UDP message
/// </summary>
public class UdpMessageEventArgs
: EventArgs, INetworkMessageEventArgs<UdpMessage>
{
/// <summary>
/// The Udp message to send with the event arg
/// </summary>
public UdpMessage Message { get; }
/// <summary>
/// The tag associated with the message
/// </summary>
public ushort Tag => Message.Tag;
/// <summary>
/// Constructor used to initialize the event arg
/// </summary>
/// <param name="message">The udp message to store</param>
public UdpMessageEventArgs(UdpMessage message)
{
Message = message;
}
}
}
Loading
Loading