コード例 #1
0
        public bool RequestWorldData()
        {
            WorldDataRequestPacket worldDataRequestPacket = new WorldDataRequestPacket();

            client.SendPacket(worldDataRequestPacket);
            return(true);
        }
コード例 #2
0
        public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context)
        {
            WorldDataRequestPacket   worldDataRequestPacket   = (WorldDataRequestPacket)packet;
            ServerProcessorContext   processorContext         = (ServerProcessorContext)context;
            PlayerManager            playerManager            = processorContext.Server.PlayerManager;
            SimulationManager        simulationManager        = processorContext.Server.SimulationManager;
            TimeManager              timeManager              = processorContext.Server.TimeManager;
            WorldRequestQueueManager worldRequestQueueManager = processorContext.Server.WorldRequestQueueManager;
            WorldStateManager        worldStateManager        = processorContext.Server.WorldStateManager;

            if (!playerManager.PlayerExists(sourcePlayerId))
            {
                // Players can not ask for a copy of the world before they authenticate
                return;
            }

            Player sourcePlayer = playerManager.GetPlayer(sourcePlayerId);

            if (sourcePlayer.State != PlayerState.ConnectedMainMenu)
            {
                // Invalid state
                return;
            }

            // We pause the game and lock time management until everyone has finished loading
            timeManager.FreezeTime();

            Player?simulationOwner = simulationManager.GetSimulationOwner();

            if (simulationOwner != null && simulationOwner.Value != sourcePlayer && worldStateManager.RequestWorldData())
            {
                // The server can get a newer world state
                // add the client to the queue and wait
                worldRequestQueueManager.EnqueuePlayer(sourcePlayer);
            }
            else
            {
                // The state we have is already the newest
                WorldStateData  worldStateData  = worldStateManager.GetWorldData();
                WorldDataPacket worldDataPacket = new WorldDataPacket(worldStateData);
                processorContext.Server.SendPacketToPlayer(worldDataPacket, sourcePlayerId);
            }
        }
コード例 #3
0
        public bool RequestWorldData()
        {
            Player?player = server.SimulationManager.GetSimulationOwner();

            if (player == null)
            {
                return(false); // Can't request world data, there are no simulation owners
            }
            if (dataRequestInProgress)
            {
                return(true);
            }

            Console.WriteLine("Requesting world data...");
            WorldDataRequestSent?.Invoke(this, new System.EventArgs());
            dataRequestInProgress = true;
            WorldDataRequestPacket worldDataRequestPacket = new WorldDataRequestPacket();

            server.SendPacketToPlayer(worldDataRequestPacket, player.Value.Id);
            return(true);
        }
コード例 #4
0
        public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context)
        {
            ClientProcessorContext processorContext   = (ClientProcessorContext)context;
            AuthenticatePacket     authenticatePacket = (AuthenticatePacket)packet;
            PlayerManager          playerManager      = processorContext.Client.PlayerManager;

            if (!authenticatePacket.AuthenticationSuccessful)
            {
                switch (authenticatePacket.ErrorReason.Value)
                {
                case AuthenticationErrorReason.UsernameTaken:
                    MessageBoxOk.Show(null, "Failed to join game", "Failed to connect to the server: Username is already taken");
                    break;

                case AuthenticationErrorReason.IncorrectPassword:
                    MessageBoxOk.Show(null, "Failed to join game", "Failed to connect to the server: Incorrect password");
                    break;

                case AuthenticationErrorReason.IllegalUsername:
                    MessageBoxOk.Show(null, "Failed to join game", "Failed to connect to the server: Username contains disallowed characters");
                    break;
                }

                processorContext.Client.RequestDisconnect();
                return;
            }

            processorContext.Client.LocalPlayer = authenticatePacket.LocalPlayer.Value;
            processorContext.Client.SimulationManager.OnSimulationOwnerUpdated(authenticatePacket.SimulationOwner);
            foreach (Player player in authenticatePacket.Players)
            {
                playerManager.OnPlayerAdded(player); // Sync players
            }
            Debug.Log("Sending world data request");
            WorldDataRequestPacket worldDataRequestPacket = new WorldDataRequestPacket();

            processorContext.Client.SendPacket(worldDataRequestPacket);
        }