Beispiel #1
0
        public bool SetSimulationOwner(Player?player)
        {
            Guid?playerId;

            if (player != null)
            {
                if (player.Value.State != PlayerState.ConnectedReady)
                {
                    return(false);
                }

                playerId = player.Value.Id;
                Console.WriteLine("New simulation owner: " + player.Value.Id);
            }
            else
            {
                playerId = null;
                Console.WriteLine("New simulation owner: None");
            }


            simulationOwner = player;

            SimulationOwnerChangedPacket simulationOwnerChangedPacket = new SimulationOwnerChangedPacket(playerId);

            server.SendPacketToAll(simulationOwnerChangedPacket);

            SimulationOwnerUpdatedEventArgs simulationOwnerUpdatedEventArgs = new SimulationOwnerUpdatedEventArgs(playerId);

            SimulationOwnerUpdated?.Invoke(this, simulationOwnerUpdatedEventArgs);

            return(true);
        }
        public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context)
        {
            SimulationOwnerChangedPacket simulationOwnerChangedPacket = (SimulationOwnerChangedPacket)packet;
            ClientProcessorContext       processorContext             = (ClientProcessorContext)context;
            PlayerManager     playerManager     = processorContext.Client.PlayerManager;
            SimulationManager simulationManager = processorContext.Client.SimulationManager;

            if (simulationOwnerChangedPacket.PlayerId != null)
            {
                Debug.Log($"Setting new simulation owner to {simulationOwnerChangedPacket.PlayerId.Value}");
                Player player = playerManager.GetPlayer(simulationOwnerChangedPacket.PlayerId.Value);
                simulationManager.OnSimulationOwnerUpdated(player);
                MessageLog.Show($"New simulation owner: {player.Name}", null, MessageLogFlags.MessageSoundNormal);
            }
            else
            {
                // No simulation owner
                simulationManager.OnSimulationOwnerUpdated(null);
                Debug.Log("Setting new simulation owner to none");
            }
        }