Skip to content

desuqcafe/InhyeongFishySteamworks

 
 

Repository files navigation

FishySteamworks (Fork)

A Steamworks implementation for Fish-Networking.

This is a fork of the original FishySteamworks with bug fixes and quality of life improvements.


Changes From Original

Bug Fixes

  • Memory Leak Fix - Added missing ByteArrayPool.Store() call in ServerSocket.IterateIncoming() for client host packets. Buffers were being retrieved from the pool but never returned, causing unbounded memory growth during host gameplay.

  • Timeout Logic Fix - CONNECT_TIMEOUT_DURATION was 8000 (intended as milliseconds) but was being added to Time.unscaledTime (seconds), resulting in ~2+ hour timeouts instead of 8 seconds.

  • Deprecated Thread.Abort() Replacement - Replaced Thread.Abort() with modern async/await + CancellationToken pattern for safer, more reliable timeout cancellation.

Quality of Life Improvements

  • Configurable Connection Timeout - Connection timeout is now configurable via Inspector or SetConnectTimeout(int ms) / GetConnectTimeout() methods.

  • Buffer Pooling in Send() - Refactored CommonSocket.Send() to use pooled buffers instead of Array.Resize(), reducing GC allocations.

  • Steam ID Helpers

    • GetSteamID(int connectionId) - Get Steam ID from FishNet connection ID
    • GetConnectionId(ulong steamId) - Get FishNet connection ID from Steam ID
  • Steam Connection Events

    • OnSteamClientConnected(ulong steamId, int connectionId) - Fired when a Steam client connects
    • OnSteamClientDisconnected(ulong steamId, int connectionId) - Fired when a Steam client disconnects
  • LocalPacket.Dispose() - Added Dispose() method for clearer intent when returning buffers to pool.

  • BidirectionalDictionary Improvements

    • Added Clear() method
    • Made internal dictionaries readonly
    • Optimized Remove() methods using Dictionary.Remove(key, out value)
    • Simplified Add() methods by removing unnecessary ContainsKey() checks

Dependencies

Fish-Networking: https://github.com/FirstGearGames/FishNet

.NET 4.5x

These projects need to be installed and working before you can use this transport:

  1. Steamworks.NET - FishySteamworks relies on Steamworks.NET to communicate with the Steamworks API. Installation guide by Heathen Engineering.

Installation

  1. Download or clone this repository.
  2. Import into your Unity project.
  3. Set up your project as described below.

Setting Up

  1. Add FishySteamworks component to your NetworkManager object. Either remove other transports or add TransportManager and specify which transport to use.

  2. Choose Peer to Peer to connect using the Steam relay.

  3. Set your AppId. You may need to add SteamManager to your NetworkManager object; if you need a SteamManager to get started, import FishNet\Plugins\FishySteamworks\SteamManager.unitypackage.

    Some frameworks such as Heathen Engineering's use their own version of SteamManager. Please consult their Discord for more information on using their assets.


Usage

Host

You may host as server only, or client and server in a single executable.

Client

Clients connect to one another using the host's SteamID64. You can get this information within your Steam application:

  1. Open Steam
  2. Go to ViewSettingsInterface
  3. Ensure "Display web address bars when available" is checked
  4. View your profile within Steam
  5. Your SteamID64 is the large number at the end of your profile URL

Connecting to a host is as easy as putting the SteamID64 in the "Client Address" field of FishySteamworks and starting the client.

Alternatively, start client via code:

ClientManager.StartConnection(steamId64);

Steam ID Helpers (New)

// Get Steam ID from FishNet connection ID
ulong steamId = fishySteamworks.GetSteamID(connectionId);

// Get FishNet connection ID from Steam ID
int connectionId = fishySteamworks.GetConnectionId(steamId);

Steam Connection Events (New)

fishySteamworks.OnSteamClientConnected += (steamId, connectionId) =>
{
    Debug.Log($"Steam user {steamId} connected with connection ID {connectionId}");
};

fishySteamworks.OnSteamClientDisconnected += (steamId, connectionId) =>
{
    Debug.Log($"Steam user {steamId} disconnected");
};

Configurable Timeout (New)

// Set timeout to 10 seconds (in milliseconds)
fishySteamworks.SetConnectTimeout(10000);

// Get current timeout
int timeout = fishySteamworks.GetConnectTimeout();

Or configure via the Inspector on the FishySteamworks component.


Testing Two Builds Locally

Steam has limitations which prevent you from connecting to yourself locally over two builds. To do so, you must have two Steam accounts on two separate devices.

You may however run as server and client in a single executable. If you need to test using two builds (or editors) on a single device, you will have to use the default transport.


Credits

About

FishNet Steamworks transport with bug fixes and QoL improvements - configurable timeout, Steam ID helpers, connection events, and memory leak fixes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C# 100.0%