예제 #1
0
        public void Interpret(INetworkMediator netHost, EndPoint sender, IMessage message)
        {
            var m = (ForgeReceiptAcknowledgementMessage)message;

            netHost.MessageBus.MessageConfirmed(sender, m.ReceiptSignature);
            m.Sent();
        }
        public void Interpret(INetworkMediator netHost, EndPoint sender, IMessage message)
        {
            var response = AbstractFactory.Get <INetworkTypeFactory>().GetNew <IChallengeResponseMessage>();

            response.GenerateResponse((IChallengeMessage)message);
            netHost.MessageBus.SendReliableMessage(response, netHost.SocketFacade.ManagedSocket, sender);
        }
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var engine = (IEngineFacade)netMediator.EngineProxy;
            int count  = engine.EntityRepository.Count;
            var msg    = new SendEntitiesToNewPlayerMessage();

            msg.EntityCount      = count;
            msg.Ids              = new int[count];
            msg.PrefabIds        = new int[count];
            msg.Positions        = new Vector3[count];
            msg.Rotations        = new Quaternion[count];
            msg.Scales           = new Vector3[count];
            msg.SceneIdentifiers = new string[count];
            int i   = 0;
            var itr = engine.EntityRepository.GetEnumerator();

            while (itr.MoveNext())
            {
                if (itr.Current != null)
                {
                    var t = itr.Current.OwnerGameObject.transform;
                    msg.Ids[i]              = itr.Current.Id;
                    msg.PrefabIds[i]        = itr.Current.PrefabId;
                    msg.Positions[i]        = t.position;
                    msg.Rotations[i]        = t.rotation;
                    msg.Scales[i]           = t.localScale;
                    msg.SceneIdentifiers[i] = itr.Current.SceneIdentifier;
                }
                i++;
            }
            netMediator.SendReliableMessage(msg, sender);
        }
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var           m      = (UpdatePlayerMessage)message;
            IEngineFacade engine = (IEngineFacade)netMediator.EngineProxy;

            try
            {
                IUnityEntity e            = engine.EntityRepository.Get(m.EntityId);
                var          interpolator = e.OwnerGameObject.GetComponent <ICharacterInterpolater>();
                Vector3      rot          = e.OwnerGameObject.transform.eulerAngles;
                rot.y = m.RotationY;
                if (interpolator == null)
                {
                    e.OwnerGameObject.transform.position    = m.Position;
                    e.OwnerGameObject.transform.eulerAngles = rot;
                }
                else
                {
                    Vector3 camRot = interpolator.CameraTransform.localEulerAngles;
                    camRot.x = m.RotationX;
                    interpolator.UpdateInterpolation(m.Position, Quaternion.Euler(rot.x, rot.y, rot.z),
                                                     Quaternion.Euler(camRot.x, camRot.y, camRot.z));
                }
            }
            catch (EntityNotFoundException ex)
            {
                // TODO:  This is getting called before the entity exists
                netMediator.EngineProxy.Logger.LogException(ex);
            }
        }
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var           msg    = (SpawnEntityMessage)message;
            IEngineFacade engine = (IEngineFacade)netMediator.EngineProxy;

            EntitySpawnner.SpawnEntityFromMessage(engine, msg);
        }
        private static ServerListingEntry[] GetEntriesArrayFromCurrentPlayers(INetworkMediator netContainer)
        {
            var entries = new List <ServerListingEntry>();

            if (netContainer.PlayerRepository.Count > 0)
            {
                using (var e = netContainer.PlayerRepository.GetEnumerator())
                {
                    while (e.MoveNext())
                    {
                        var player = (NetworkPlayer)e.Current;
                        if (player.IsRegisteredServer)
                        {
                            var ep = (IPEndPoint)player.EndPoint;
                            entries.Add(new ServerListingEntry
                            {
                                Address = ep.Address.ToString(),
                                Port    = (ushort)ep.Port
                            });
                        }
                    }
                }
            }
            return(entries.ToArray());
        }
        public void Interpret(INetworkMediator netContainer, EndPoint sender, IMessage message)
        {
            var registryMessage = new ForgeServerRegistryMessage();

            registryMessage.Entries = GetEntriesArrayFromCurrentPlayers(netContainer);
            netContainer.MessageBus.SendReliableMessage(registryMessage,
                                                        netContainer.SocketFacade.ManagedSocket, sender);
        }
 public void StartServer(ushort port, int maxPlayers, INetworkMediator netMediator)
 {
     networkMediator = netMediator;
     _socket.Listen(port, MAX_PARALLEL_CONNECTION_REQUEST);
     CancellationSource = new CancellationTokenSource();
     NetPlayerId        = AbstractFactory.Get <INetworkTypeFactory>().GetNew <IPlayerSignature>();
     Task.Run(ReadNetwork, CancellationSource.Token);
 }
예제 #9
0
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var mapLoadResponseMessage = new MapLoadResponseMessage()
            {
                MapId = SceneManager.GetActiveScene().name
            };

            netMediator.MessageBus.SendReliableMessage(mapLoadResponseMessage, netMediator.SocketFacade.ManagedSocket, sender);
        }
예제 #10
0
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var responseMessage = (MapLoadResponseMessage)message;

            Debug.Log($"Map Load Response Received - { responseMessage.MapId }");
            SceneManager.LoadScene(responseMessage.MapId);
            // Now request the entities from the server
            //netMediator.SendReliableMessage(new GetAllEntitiesRequestMessage());
        }
예제 #11
0
 public void SetMediator(INetworkMediator networkMediator)
 {
     if (_networkMediator != null)
     {
         throw new MessageBussNetworkMediatorAlreadyAssignedException();
     }
     _networkMediator = networkMediator;
     _networkMediator.PlayerRepository.onPlayerRemovedSubscription += PlayerRemovedFromRepository;
     _messageRepeater.Start(_networkMediator);
 }
예제 #12
0
        public void Interpret(INetworkMediator netHost, EndPoint sender, IMessage message)
        {
            var player          = netHost.PlayerRepository.GetPlayer(sender);
            var identityMessage = new ForgeNetworkIdentityMessage
            {
                Identity = player.Id
            };

            netHost.MessageBus.SendReliableMessage(identityMessage, netHost.SocketFacade.ManagedSocket, sender);
        }
예제 #13
0
 public void StartPinging(INetworkMediator networkMediator)
 {
     if (networkMediator.SocketFacade is ISocketServerFacade)
     {
         throw new ArgumentException($"The ForgePinger can only be used on a client");
     }
     _sourceSyncCtx   = SynchronizationContext.Current;
     _networkMediator = networkMediator;
     Task.Run(PingAtInterval, _networkMediator.SocketFacade.CancellationSource.Token);
 }
예제 #14
0
        public void StartClient(string address, ushort port, INetworkMediator netMediator)
        {
            networkMediator = netMediator;
            _socket.Connect(address, port);
            CancellationSource = new CancellationTokenSource();
            Task.Run(ReadNetwork, CancellationSource.Token);
            BMSByte buffer = new BMSByte();

            buffer.Append(new byte[] { 1 });
            _socket.Send(_socket.EndPoint, buffer);
        }
예제 #15
0
        public static void RunMessageLocally(
            this INetworkMediator netMediator, IMessage message)
        {
            var interpreter = message.Interpreter;

            if (ShouldInterpret(netMediator, interpreter))
            {
                interpreter.Interpret(netMediator,
                                      netMediator.SocketFacade.ManagedSocket.EndPoint, message);
            }
        }
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var identityMessage = (ForgeNetworkIdentityMessage)message;
            var clientContainer = (ISocketClientFacade)netMediator.SocketFacade;

            clientContainer.NetPlayerId = identityMessage.Identity;
            var engineReadyMessage = new ForgeReadyForEngineMessage();

            ((ISocketClientFacade)netMediator.SocketFacade).Established(netMediator);
            netMediator.EngineProxy.NetworkingEstablished();
            netMediator.MessageBus.SendReliableMessage(engineReadyMessage, netMediator.SocketFacade.ManagedSocket, sender);
        }
예제 #17
0
        public void Interpret(INetworkMediator netMediator,
                              EndPoint sender, IMessage message)
        {
            var m  = (ChatMessage)message;
            var cl = GameObject.FindObjectOfType <ChatListener>();

            cl.PrintMessage(m.Name, m.Text);
            if (netMediator.IsServer)
            {
                netMediator.ForwardToOtherClients(sender, message);
            }
        }
 public void Interpret(INetworkMediator netHost, EndPoint sender, IMessage message)
 {
     try
     {
         INetPlayer player = netHost.PlayerRepository.GetPlayer(sender);
         if (!player.IsInEngine)
         {
             player.IsInEngine = true;
         }
     }
     catch (PlayerNotFoundException) { }
 }
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var  m    = (CreatePlayerMessage)message;
            bool isMe = netMediator.SocketFacade.NetPlayerId.Equals(m.OwningPlayer);

            if (!isMe)
            {
                m.PrefabId = m.ProxyPrefabId;
            }
            IEngineFacade engine = (IEngineFacade)netMediator.EngineProxy;
            var           e      = EntitySpawner.SpawnEntityFromMessage(engine, m);

            onPlayerCreated?.Invoke(e, m.OwningPlayer);
        }
예제 #20
0
        public void Interpret(INetworkMediator netContainer, EndPoint sender, IMessage message)
        {
            var response = (IChallengeResponseMessage)message;

            if (!response.ValidateResponse())
            {
                return;
            }
            try
            {
                var serverContainer = (ISocketServerFacade)netContainer.SocketFacade;
                serverContainer.ChallengeSuccess(netContainer, sender);
            }
            catch (PlayerNotFoundException) { }
        }
 public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
 {
     try
     {
         INetPlayer player = netMediator.PlayerRepository.GetPlayer(sender);
         if (!player.IsInEngine)
         {
             player.IsInEngine = true;
         }
     }
     catch (PlayerNotFoundException ex)
     {
         netMediator.EngineProxy.Logger.LogException(ex);
     }
 }
        public void ChallengeSuccess(INetworkMediator netContainer, EndPoint endpoint)
        {
            INetPlayer player;
            ForgeNetworkIdentityMessage netIdentity;

            lock (_challengedPlayers)
            {
                player = _challengedPlayers.GetPlayer(endpoint);
                netContainer.PlayerRepository.AddPlayer(player);
                netIdentity = new ForgeNetworkIdentityMessage
                {
                    Identity = player.Id
                };
                _challengedPlayers.RemovePlayer(player);
            }
            netContainer.MessageBus.SendReliableMessage(netIdentity, ManagedSocket, endpoint);
        }
예제 #23
0
        public static void ForwardToOtherClients(this INetworkMediator netMediator,
                                                 EndPoint sender, IMessage message)
        {
            if (!netMediator.IsServer)
            {
                throw new SocketNotServerException("Tried to forward a message" +
                                                   "to connected clients, but the current socket is not a server");
            }
            var itr = netMediator.PlayerRepository.GetEnumerator();

            while (itr.MoveNext())
            {
                if (itr.Current != null && itr.Current.EndPoint != sender)
                {
                    netMediator.SendReliableMessage(message, itr.Current.EndPoint);
                }
            }
        }
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var           sceneEntities = GameObject.FindObjectsOfType <NetworkEntity>() as IUnityEntity[];
            var           m             = (SendEntitiesToNewPlayerMessage)message;
            IEngineFacade engine        = (IEngineFacade)netMediator.EngineProxy;

            for (int i = 0; i < m.EntityCount; i++)
            {
                if (string.IsNullOrEmpty(m.SceneIdentifiers[i]))
                {
                    // Don't load an entity that already exists (from DontDestroyOnLoad)
                    if (!engine.EntityRepository.Exists(m.Ids[i]))
                    {
                        EntitySpawner.SpawnEntityFromData(engine, m.Ids[i], m.PrefabIds[i], m.Positions[i], m.Rotations[i], m.Scales[i]);
                    }
                }
                else
                {
                    SetupEntityAlreadyInScene(sceneEntities, m, i, engine);
                }
            }
        }
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            INetPlayer player = netMediator.PlayerRepository.GetPlayer(sender);

            GameObject.FindObjectOfType <ComplexSampleNetwork>().PlayerJoined(player);
        }
예제 #26
0
 public void Start(INetworkMediator networkMediator)
 {
     _networkMediator      = networkMediator;
     _socketTokenSourceRef = _networkMediator.SocketFacade.CancellationSource;
     Task.Run(RepeatInBackground, _socketTokenSourceRef.Token);
 }
예제 #27
0
 public void Interpret(INetworkMediator netContainer, EndPoint sender, IMessage message)
 {
     // Nothing to do here, we have already updated the player timestamp
 }
 public void StartWatching(INetworkMediator mediator)
 {
     _networkMediator = mediator;
     _sourceSyncCtx   = SynchronizationContext.Current;
     Task.Run(WatchForTimeouts, _networkMediator.SocketFacade.CancellationSource.Token);
 }
예제 #29
0
 public void Established(INetworkMediator netMediator)
 {
     _serverPing.StartPinging(netMediator);
 }
예제 #30
0
        public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message)
        {
            var m = (MapChangedMessage)message;

            SceneManager.LoadScene(m.MapName);
        }