예제 #1
0
        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);
        }
예제 #2
0
        public override void ServerStart()
        {
            if (!SteamManager.Initialized)
            {
                Debug.LogError("SteamWorks not initialized. Server could not be started.");
                return;
            }

            FetchSteamID();

            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}");
                    SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay);
                    server = LegacyServer.CreateServer(this, NetworkManager.singleton.maxConnections);
                }
            }
            else
            {
                Debug.LogError("Server already started!");
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        public static NextServer CreateServer(FizzyFacepunch 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);

            if (!SteamClient.IsValid)
            {
                Debug.LogError("SteamWorks not initialized.");
            }

            s.Host();

            return(s);
        }