コード例 #1
0
ファイル: Hellion.cs プロジェクト: generalwrex/HES_REWRITE
        /// <summary>
        /// Starts Hellion Dedicated in its own thread
        /// </summary>
        /// <param name="args">command line arg passthrough</param>
        /// <returns>the thread!</returns>
        public Thread Start()
        {
            //Log.Instance.Info(HES.Localization.Sentences["LoadingDedicated"]);

            serverThread = new Thread(new ThreadStart(ServerThread))
            {
                IsBackground     = true,
                CurrentCulture   = CultureInfo.InvariantCulture,
                CurrentUICulture = CultureInfo.InvariantCulture
            };
            try
            {
                // Start the thread!
                serverThread.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Hellion Extended Server [SERVER THREAD ERROR] : " + ex.ToString());
                return(null);
            }

            while (!Server.WorldInitialized)
            {
                Thread.Sleep(1000);
            }

            OnServerStarted?.Invoke();

            return(serverThread);
        }
コード例 #2
0
 //send event upward
 private void Server_OnServerStarted(object sender, ServerEventArgs e)
 {
     OnServerStarted.Invoke(this, new SimulatorEventArgs(e.Message));
     server.acceptClient().ContinueWith(x => {
         server.receiveSessionData();
     });
 }
コード例 #3
0
ファイル: NetworkManager.cs プロジェクト: Fangh/ChessVR
 public void StartServer()
 {
     server = new Telepathy.Server();
     server.Start(port);
     isServer = true;
     OnServerStarted?.Invoke();
 }
コード例 #4
0
        private void OnVoiceServerStarted()
        {
            foreach (var player in _api.getAllPlayers())
            {
                RegisterPlayer(player);
            }

            OnServerStarted?.Invoke();
        }
コード例 #5
0
        public TcpListener startServer()
        {
            server = new TcpListener(IPAddress.Parse(IP), Port);

            server.Start();
            OnServerStarted.Invoke(this, new ServerEventArgs("Server started."));

            return(server);
        }
コード例 #6
0
        public override void OnStartServer()
        {
            base.OnStartServer();

            _serverMessaging = new ServerMessaging(this);
            Players          = new ServerConnectedPlayers(_serverMessaging, this, _userName);

            OnServerStarted?.Invoke();

            Debug.Log("Server Started");
        }
コード例 #7
0
 private void OnWsServerStarted(object sender, ServerStateEventArgs e)
 {
     if (OnServerStarted == null)
     {
         _logger?.LogDebug("WebSocket server [{id}] started and listening on http://{ip}:{port}/", e.Id, _ipAddress, _port);
     }
     else
     {
         OnServerStarted?.Invoke(sender, e);
     }
 }
コード例 #8
0
 private void SetIsRunning(bool run = true)
 {
     m_isRunning = run;
     if (run)
     {
         OnServerStarted?.Invoke();
     }
     else
     {
         OnServerStopped?.Invoke();
     }
 }
コード例 #9
0
        public void StartServer()
        {
            var topology = new HostTopology(_connectionConfig, 1);

            _socketId = NetworkTransport.AddHost(topology, _socketPort);

            Debug.Log("Socket Open. Socket id: " + _socketId);

            if (OnServerStarted != null)
            {
                OnServerStarted.Invoke();
            }
        }
コード例 #10
0
        public void Start()
        {
            if (IsRunning)
            {
                throw new Exception("server is already running");
            }

            IsRunning = true;
            ServerSocket.Bind(IP);
            ServerSocket.Listen(32);

            OnServerStarted?.Invoke();
            AcceptClient();
        }
コード例 #11
0
        public void Start()
        {
            if (Started)
            {
                throw new VoiceServerAlreadyStartedException();
            }

            if (NativeWrapper.StartNativeServer() == false)
            {
                throw new VoiceServerNotStartedException();
            }

            Started = true;
            InvokeProtectedEvent(() => OnServerStarted?.Invoke());
        }
コード例 #12
0
ファイル: Server.cs プロジェクト: rachartier/HAL
        public void StartUniqueClientType <TClient>(string savePath)
            where TClient : TcpClientSavedState
        {
            server.Start();
            OnServerStarted?.Invoke(this, null);

            while (isRunning)
            {
                var client          = server.AcceptTcpClient();
                var tcpOpenedStream = (TClient)Activator.CreateInstance(typeof(TClient), client, savePath);

                connectionManager.AddTcpClient(tcpOpenedStream);
            }

            OnServerClosed?.Invoke(this, null);
        }
コード例 #13
0
    private void OnMapLoaded(Scene scene, LoadSceneMode loadSceneMode)
    {
        SceneManager.sceneLoaded -= OnMapLoaded;

        var camera        = Object.Instantiate(OsFps.Instance.CameraPrefab);
        var uiCullingMask = 1 << 5;

        camera.GetComponent <Camera>().cullingMask = uiCullingMask;

        var dedicatedServerScreenComponent = Object.Instantiate(
            OsFps.Instance.DedicatedServerScreenPrefab, OsFps.Instance.CanvasObject.transform
            ).GetComponent <DedicatedServerScreenComponent>();

        OsFps.Instance.MenuStack.Push(dedicatedServerScreenComponent);

        ServerPeer.ShouldSendStateSnapshots = true;
        OnServerStarted?.Invoke();
    }
コード例 #14
0
        /// <summary>
        /// 启动服务
        /// </summary>
        /// 时间:2016/6/7 22:54
        /// 备注:
        /// <exception cref="System.InvalidOperationException">未能成功创建Socket服务类型。</exception>
        public void Start()
        {
            listener = GetCorrectSocket();
            #region 解决UDP错误10054:远程主机强迫关闭了一个现有的连接
            if (Protocol == SocketProtocol.UDP)
            {
                uint IOC_IN            = 0x80000000;
                uint IOC_VENDOR        = 0x18000000;
                uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
                listener.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
                listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            }
            #endregion
            if (listener != null)
            {
                listener.Bind(this.Endpoint);

                if (this.Protocol == SocketProtocol.TCP)
                {
                    listener.Listen(this.MaxQueuedConnections);
                    listener.BeginAccept(new AsyncCallback(ClientConnected), listener);
                }
                else if (Protocol == SocketProtocol.UDP)
                {
                    SocketConnectionInfo _connection = new SocketConnectionInfo();
                    _connection.Buffer = new byte[SocketConnectionInfo.BufferSize];
                    _connection.Socket = listener;
                    ipeSender          = new IPEndPoint(IPAddress.Any, this.Port);
                    listener.BeginReceiveFrom(_connection.Buffer, 0, _connection.Buffer.Length, SocketFlags.None, ref ipeSender, new AsyncCallback(DataReceived), _connection);
                }

                SocketServerStartedEventArgs _arg = new SocketServerStartedEventArgs
                {
                    Protocol     = this.Protocol,
                    SocketServer = this.Endpoint,
                    StartedTime  = DateTime.Now
                };
                OnServerStarted.RaiseEvent(this, _arg);
            }
            else
            {
                throw new InvalidOperationException("未能成功创建Socket服务类型。");
            }
        }
コード例 #15
0
        /// <inheritdoc />
        public async Task OnGameStart()
        {
            OnServerStarting?.Invoke(this, EventArgs.Empty);

            if (!ApplicationBase.StartServer())
            {
                string error = $"Failed to start server on Details: {ApplicationBase.ServerAddress}";

                if (ApplicationBase.Logger.IsErrorEnabled)
                {
                    ApplicationBase.Logger.Error(error);
                }

                throw new InvalidOperationException(error);
            }

            TaskCompletionSource <object> completionSource = new TaskCompletionSource <object>();

#pragma warning disable 4014
            Task.Factory.StartNew(async() =>
#pragma warning restore 4014
            {
                completionSource.SetResult(null);

                await ApplicationBase.BeginListening()
                .ConfigureAwaitFalseVoid();

                if (ApplicationBase.Logger.IsWarnEnabled)
                {
                    ApplicationBase.Logger.Warn($"Server is shutting down.");
                }
            }, TaskCreationOptions.LongRunning);

            await completionSource.Task;

            //This is the closest we can get to "started" without GladNet exposing event API
            OnServerStarted?.Invoke(this, EventArgs.Empty);
        }
コード例 #16
0
        /// <inheritdoc/>
        public void Start(BaseClientRepository clientRepository, int maxClients, int port = Constants.DefaultPort)
        {
            ClientRepository = clientRepository;
            MaxClients       = maxClients;
            Port             = port;

            if (_packetHandler.Get(0) == null)
            {
                _packetHandler.AddPacketHandler(0, clientRepository.HandleWelcomeReceived);
            }
            InitServerData();

            _tcpListener = new TcpListener(IPAddress.Any, Port);
            _tcpListener.Start();
            _tcpListener.BeginAcceptTcpClient(new AsyncCallback(TCPConnectCallback), null);

            UdpListener = new UdpClient(Port);
            UdpListener.BeginReceive(UDPReceiveCallback, null);

            IsRunning = true;

            OnServerStarted?.Invoke(this, new EventArgs());
        }
コード例 #17
0
ファイル: NetworkServer.cs プロジェクト: EmreBugday99/NetSync
 /// <summary>
 /// When server gets started and begins listening for new connections.
 /// </summary>
 /// <param name="server">The NetworkServer that started.</param>
 private void ServerStarted(NetworkServer server)
 {
     _isActive = true;
     OnServerStarted?.Invoke(server);
 }
コード例 #18
0
 void IServerListener.onServerStarted() => OnServerStarted?.Invoke();
コード例 #19
0
 public static void InvokeServerStarted()
 {
     OnServerStarted?.Invoke();
 }
コード例 #20
0
 protected void OnServerStart(NetworkServer server)
 => OnServerStarted?.Invoke(server);
コード例 #21
0
 //send event upward
 private void Server_OnServerStarted(object sender, ServerEventArgs e)
 {
     OnServerStarted.Invoke(this, new SimulatorEventArgs(e.Message));
 }
コード例 #22
0
 /// <summary>
 ///     Handle server started notification
 /// </summary>
 protected virtual void OnStarted()
 {
     OnServerStarted?.Invoke(this, new ServerStateEventArgs(Id));
 }
コード例 #23
0
 internal static void OnServerStarted_Call(ServerConfig serverConfig) => OnServerStarted?.Invoke(serverConfig);
コード例 #24
0
 public override void OnStartServer()
 {
     base.OnStartServer();
     SetupServerNetworkMessages();
     OnServerStarted?.Invoke();
 }
コード例 #25
0
        /// <summary>
        ///     Starts local server based on given or local configuration.
        /// </summary>
        public static void StartServer(QNetConfiguration configuration = null)
        {
            if (IsServerActive)
            {
                throw new InvalidOperationException(
                          "QNet is unable to start server while there is already active instance of server.");
            }
            if (configuration == null)
            {
                configuration = new QNetConfiguration();
            }

            var hostIsActive = IsHostActive;

            Server = new QNetServer();
            Server = InternalStartPeer(Server, configuration, () =>
            {
                QNetHandlerStack.RegisterServerHandlers(Server);
                OnServerRegisterHeaders?.Invoke();
            });
            OnServerPrepare?.Invoke();

            Server.OnBeforeMessage += message =>
            {
                // server should always send the server frame to the client!
                message.Write(QNetTime.ServerFrame);
            };

            Server.OnConnectionAuthorizing += (QNetConnection connection, QNetMessageWriter writer, ref bool refuse) =>
            {
                writer.WriteInt32(QNetTime.TickRate);
                writer.WriteUInt32(QNetTime.ServerFrame);

                OnServerAuthorizePlayer?.Invoke(connection, writer, ref refuse);
            };

            Server.OnConnectionReady += reader =>
            {
                // read player nickname and create its QNetPlayer instance
                var nickname = reader.ReadString();
                var token    = reader.ReadUInt32();
                var version  = reader.ReadString();
                if (JEMBuild.BuildVersion != version)
                {
                    JEMLogger.LogError(
                        $"Newly received connection don't have right version of the game -> {version} ( is {JEMBuild.BuildVersion} )");
                    Server.CloseConnection(reader.Connection, "InvalidBuildVersion");
                }
                else
                {
                    if (IsHostActive && (reader.Connection.ConnectionIdentity == 0 ||
                                         reader.Connection.ConnectionIdentity == Client.ConnectionIdentity))
                    {
                        HostClientConnection = reader.Connection;
                        JEMLogger.Log("QNetUnity received host client connection.");
                    }

                    if (QNetPlayer.GetQNetPlayerByToken(token) != null)
                    {
                        JEMLogger.LogError("Newly received connection is using already used token. Disconnecting!");
                        Server.CloseConnection(reader.Connection, "TokenAlreadyInUse");
                        return;
                    }

                    var qNetPlayer = QNetPlayer.CreateQNetPlayer(reader.Connection.ConnectionIdentity, nickname, token);
                    if (qNetPlayer == null)
                    {
                        JEMLogger.LogError(
                            "Newly received connection don't have his QNetPlayer instance. Disconnecting!");
                        Server.CloseConnection(reader.Connection, "InternalQNetPlayerError");
                        return;
                    }

                    OnServerNewPlayer?.Invoke(qNetPlayer, reader);
                    QNetServerConnectionInit.PrepareNewConnection(reader.Connection);
                }
            };

            Server.OnConnectionLost += (connection, reason) =>
            {
                var qNetPlayer = QNetPlayer.GetQNetPlayer(connection);
                if (qNetPlayer != null) // if QNetPlayer of this connection not exists, just ignore
                {
                    OnServerPlayerLost?.Invoke(qNetPlayer, reason);

                    // the only thing to do here is to tag player as not ready (if ready)
                    if (qNetPlayer.Ready)
                    {
                        qNetPlayer.TagAsNotReady();
                    }

                    // and remove QNetPlayer from local machine
                    QNetPlayer.DestroyQNetPlayer(qNetPlayer);
                }
            };

            Server.OnServerStop += reason =>
            {
                // server has been stopped, try to de-initialize game
                if (!ShuttingDownByApplicationQuit)
                {
                    QNetGameInitializer.DeInitialize(() => { OnServerShutdown?.Invoke(hostIsActive); });
                }
                else
                {
                    OnServerShutdown?.Invoke(hostIsActive);
                }

                IsServerActive = false;
                IsHostActive   = false;
            };

            IsServerActive = true;
            OnServerStarted?.Invoke();
        }
コード例 #26
0
 private void ServerStart()
 {
     OnServerStarted?.Invoke();
 }