A Steamworks implementation for Fish-Networking.
This is a fork of the original FishySteamworks with bug fixes and quality of life improvements.
-
Memory Leak Fix - Added missing
ByteArrayPool.Store()call inServerSocket.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_DURATIONwas 8000 (intended as milliseconds) but was being added toTime.unscaledTime(seconds), resulting in ~2+ hour timeouts instead of 8 seconds. -
Deprecated Thread.Abort() Replacement - Replaced
Thread.Abort()with modernasync/await+CancellationTokenpattern for safer, more reliable timeout cancellation.
-
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 ofArray.Resize(), reducing GC allocations. -
Steam ID Helpers
GetSteamID(int connectionId)- Get Steam ID from FishNet connection IDGetConnectionId(ulong steamId)- Get FishNet connection ID from Steam ID
-
Steam Connection Events
OnSteamClientConnected(ulong steamId, int connectionId)- Fired when a Steam client connectsOnSteamClientDisconnected(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 usingDictionary.Remove(key, out value) - Simplified
Add()methods by removing unnecessaryContainsKey()checks
- Added
Fish-Networking: https://github.com/FirstGearGames/FishNet
.NET 4.5x
These projects need to be installed and working before you can use this transport:
- Steamworks.NET - FishySteamworks relies on Steamworks.NET to communicate with the Steamworks API. Installation guide by Heathen Engineering.
- Download or clone this repository.
- Import into your Unity project.
- Set up your project as described below.
-
Add
FishySteamworkscomponent to your NetworkManager object. Either remove other transports or add TransportManager and specify which transport to use. -
Choose Peer to Peer to connect using the Steam relay.
-
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.
You may host as server only, or client and server in a single executable.
Clients connect to one another using the host's SteamID64. You can get this information within your Steam application:
- Open Steam
- Go to View → Settings → Interface
- Ensure "Display web address bars when available" is checked
- View your profile within Steam
- 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);// Get Steam ID from FishNet connection ID
ulong steamId = fishySteamworks.GetSteamID(connectionId);
// Get FishNet connection ID from Steam ID
int connectionId = fishySteamworks.GetConnectionId(steamId);fishySteamworks.OnSteamClientConnected += (steamId, connectionId) =>
{
Debug.Log($"Steam user {steamId} connected with connection ID {connectionId}");
};
fishySteamworks.OnSteamClientDisconnected += (steamId, connectionId) =>
{
Debug.Log($"Steam user {steamId} disconnected");
};// 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.
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.
- Original FishySteamworks by FirstGearGames
- Thank you Heathen Engineering for your support