Exemplo n.º 1
0
        public override IEnumerator Initialize()
        {
            networkServerSimple = new WrappedNetworkServerSimple();

            networkServerSimple.RegisterHandler(GameMsgType.UpdateCritterInput, HandeUpdateCritterInput);

            networkServerSimple.OnClientConnected    += OnClientConnected;
            networkServerSimple.OnClientDisconnected += OnClientDisconnected;
            networkServerSimple.RegisterHandler(GameMsgType.Effects, HandleEffectReceived);

            networkServerSimple.Initialize();
            networkServerSimple.Listen(CONNECTION_PORT);
            _isConnected = true;

            Debug.Log("Server Initialized");

            CurrentPlayer.isServer         = true;
            CurrentPlayer.ID               = 0;
            CurrentPlayer.IsSelf           = true;
            CurrentPlayer.ServerConnection = this;

            CurrentPlayer.PostCritterStatePacket += (p) =>
            {
                PostCritterStatePacket(p, CurrentPlayer);
            };

            activePlayers.Add(CurrentPlayer);

            OnPlayerConnect?.Invoke(CurrentPlayer);

            UpdateActivePlayers();

            yield break;
        }
Exemplo n.º 2
0
        public override void Shutdown()
        {
            OnPlayerDisconnect     = null;
            OnPlayerConnect        = null;
            OnActivePlayersUpdated = null;

            if (networkServerSimple == null)
            {
                return;
            }
            networkServerSimple.ClearHandlers();
            networkServerSimple.DisconnectAllConnections();
            networkServerSimple.Stop();
            networkServerSimple = null;

            _isConnected = false;
        }