public static NextClient CreateClient(FizzySteamworks transport, string host) { NextClient c = new NextClient(transport); c.OnConnected += () => transport.OnClientConnected.Invoke(); c.OnDisconnected += () => transport.OnClientDisconnected.Invoke(); c.OnReceivedData += (data, ch) => transport.OnClientDataReceived.Invoke(new ArraySegment <byte>(data), ch); try { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif c.Connect(host); } catch (Exception ex) { Debug.LogException(ex); c.OnConnectionFailed(); } return(c); }
private void Awake() { const string fileName = "steam_appid.txt"; if (File.Exists(fileName)) { string content = File.ReadAllText(fileName); if (content != SteamAppID) { File.WriteAllText(fileName, SteamAppID.ToString()); Debug.Log($"Updating {fileName}. Previous: {content}, new SteamAppID {SteamAppID}"); } } else { File.WriteAllText(fileName, SteamAppID.ToString()); Debug.Log($"New {fileName} written with SteamAppID {SteamAppID}"); } if (UseNextGenSteamNetworking) { SteamNetworkingUtils.InitRelayNetworkAccess(); } Debug.Assert(Channels != null && Channels.Length > 0, "No channel configured for FizzySteamworks."); Invoke(nameof(FetchSteamID), 1f); }
public static NextServer CreateServer(FizzySteamworks transport, int maxConnections) { NextServer s = new NextServer(maxConnections); s.OnConnected += (id) => transport.OnServerConnected.Invoke(id); s.OnDisconnected += (id) => transport.OnServerDisconnected.Invoke(id); s.OnReceivedData += (id, data, ch) => transport.OnServerDataReceived.Invoke(id, new ArraySegment <byte>(data), ch); s.OnReceivedError += (id, exception) => transport.OnServerError.Invoke(id, exception); try { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif } catch (Exception ex) { Debug.LogException(ex); } s.Host(); return(s); }
///// Methods ///// //private string _test = string.Empty; private void Awake() { if (SteamClient.IsValid) { return; } Dispatch.OnException = (e) => { UnityEngine.Debug.LogError(e.Message); UnityEngine.Debug.Log(e.StackTrace); }; //Steamworks.Dispatch.OnDebugCallback = (type, str, server) => //{ // UnityEngine.Debug.Log($"[Callback {type} {(server ? "server" : "client")}]"); // UnityEngine.Debug.Log($"{str}"); //}; //SteamNetworkingUtils.DebugLevel = NetDebugOutput.Everything; //SteamNetworkingUtils.OnDebugOutput += (e1, e2) => //{ // UnityEngine.Debug.Log(e1 + ":" + e2); // _test += e1 + "::" + e2 + "\n"; //}; //Steamworks.Dispatch.OnDebugCallback = (type, str, server) => //{ // UnityEngine.Debug.Log($"[Callback {type} {(server ? "server" : "client")}]"); // UnityEngine.Debug.Log(str); // UnityEngine.Debug.Log($""); // _test += $"[Callback {type} {(server ? "server" : "client")}]\n"; // _test += $"{str}\n"; // _test += $"\n\n"; //}; try { SteamClient.Init(Structure.AppId); } catch (System.Exception e) { ExceptionMessage = e.ToString(); Debug.LogError(e.ToString()); return; } if (!SteamApps.IsSubscribedToApp(Structure.AppId)) { Application.Quit(); } SteamNetworkingUtils.InitRelayNetworkAccess(); Initialized = true; }
private void FetchSteamID() { if (SteamManager.Initialized) { if (UseNextGenSteamNetworking) { SteamNetworkingUtils.InitRelayNetworkAccess(); } SteamUserID = SteamUser.GetSteamID().m_SteamID; } }
public void Startup() { InitializeModules(); SetupLobby(); SteamNetworkingUtils.InitRelayNetworkAccess(); isInitialized = true; Started?.Invoke(); isRunning = true; Debug.Log("Server Started"); }
private void FetchSteamID() { if (SteamClient.IsValid) { if (UseNextGenSteamNetworking) { SteamNetworkingUtils.InitRelayNetworkAccess(); } SteamUserID = SteamClient.SteamId; } }
public SteamSocket(SteamOptions options, bool isServer) { Debug.Log("Starting up FizzySteam Socket..."); if (options.useSteamRelay) { SteamNetworkingUtils.InitRelayNetworkAccess(); } _steamOptions = options; _isServer = isServer; _steamSocketManager = new SteamSocketManager(options, isServer); }
private void InitRelayNetworkAccess() { try { if (UseNextGenSteamNetworking) { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif } } catch { } }
public override void ServerStart() { try { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif InitRelayNetworkAccess(); if (ClientActive()) { Debug.LogError("Transport already running as client!"); return; } if (!ServerActive()) { if (UseNextGenSteamNetworking) { Debug.Log($"Starting server [SteamSockets]."); server = NextServer.CreateServer(this, NetworkManager.singleton.maxConnections); } else { Debug.Log($"Starting server [DEPRECATED SteamNetworking]. Relay enabled: {AllowSteamRelay}"); #if UNITY_SERVER SteamGameServerNetworking.AllowP2PPacketRelay(AllowSteamRelay); #else SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); #endif server = LegacyServer.CreateServer(this, NetworkManager.singleton.maxConnections); } } else { Debug.LogError("Server already started!"); } } catch (Exception ex) { Debug.LogException(ex); return; } }
public override bool Available() { try { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif return(true); } catch { return(false); } }
public override void ClientConnect(string address) { try { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif InitRelayNetworkAccess(); if (ServerActive()) { Debug.LogError("Transport already running as server!"); return; } if (!ClientActive() || client.Error) { if (UseNextGenSteamNetworking) { Debug.Log($"Starting client [SteamSockets], target address {address}."); client = NextClient.CreateClient(this, address); } else { Debug.Log($"Starting client [DEPRECATED SteamNetworking], target address {address}. Relay enabled: {AllowSteamRelay}"); SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); client = LegacyClient.CreateClient(this, address); } } else { Debug.LogError("Client already running!"); } } catch (Exception ex) { Debug.LogError("Exception: " + ex.Message + ". Client could not be started."); OnClientDisconnected.Invoke(); } }