Esempio n. 1
0
        public void SendWorld(int playerId)
        {
            var player = Players[playerId];

            //Send(new PauseGamePacket
            //{
            //    Reason = $"{player.Username} is downloading the world",
            //    ExceptID = playerId
            //});

            Log.WriteLine("Sending world to player " + playerId);

            IsSendingWorld = true;

            byte[] world = World.Serialize();

            Packet packet = new WorldDataPacket
            {
                Data = world
            };
            var msg = packet.GetMessage(Server);

            PacketLog.LogSend(packet);

            player.Connection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, 0);

            player.Connection.SendMessage(CircuitStatePacket.Build(true).GetMessage(Server), NetDeliveryMethod.ReliableOrdered, 0);
        }
Esempio n. 2
0
        public void broadcastInfo()
        {
            Log.debug("Broadcasting world info.");

            // World data packet is the same for everyone, so go ahead and prepare it

            /*String saveFile = SaveGame.loaded.player.Name + "_" + SaveGame.loaded.uniqueIDForThisGame;
             * string worldPath = Path.Combine(new string[]
             *                  {
             *                          Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
             *                          "StardewValley",
             *                          "Saves",
             *                          saveFile,
             *                          saveFile
             *                  });
             * String xml = File.ReadAllText(worldPath);*/
            MemoryStream tmp = new MemoryStream();

            SaveGame.serializer.Serialize(tmp, SaveGame.loaded);
            WorldDataPacket world = new WorldDataPacket(Encoding.UTF8.GetString(tmp.ToArray()));

            foreach (Client client in clients)
            {
                // Send other farmers first
                OtherFarmerDataPacket others = new OtherFarmerDataPacket();

                /*string savePath = Path.Combine(new string[]
                 *          {
                 *                  Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                 *                  "StardewValley",
                 *                  "Saves",
                 *                  saveFile,
                 *                  "SaveGameInfo"
                 *          });
                 * String myXml = File.ReadAllText(savePath);*/
                others.others.Add(0, Util.serialize <SFarmer>(SaveGame.loaded.player));

                foreach (Client other in clients)
                {
                    if (client == other)
                    {
                        continue;
                    }
                    others.others.Add(other.id, other.farmerXml);
                }
                client.send(others);

                // Send world info
                client.send(world);

                client.stage = Client.NetStage.Playing;
            }

            lastTimeSync = DateTime.Now;
        }
Esempio n. 3
0
        public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context)
        {
            WorldDataPacket        worldDataPacket  = (WorldDataPacket)packet;
            ClientProcessorContext processorContext = (ClientProcessorContext)context;

            processorContext.Client.WorldStateManager.UpdateWorldData(worldDataPacket.World);

            Debug.Log("Informing the server that we've started loading the world data");
            ClientLoadingStartedPacket clientLoadingStartedPacket = new ClientLoadingStartedPacket();

            processorContext.Client.SendPacket(clientLoadingStartedPacket);
        }
Esempio n. 4
0
        private void DeliverWorldData()
        {
            Console.WriteLine("Delivering world data...");
            WorldStateData  worldStateData  = server.WorldStateManager.GetWorldData();
            WorldDataPacket worldDataPacket = new WorldDataPacket(worldStateData);

            foreach (KeyValuePair <Guid, Player> kvp in playerQueue)
            {
                server.SendPacketToPlayer(worldDataPacket, kvp.Key);
            }

            playerQueue.Clear();
        }
        public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context)
        {
            ServerProcessorContext processorContext = (ServerProcessorContext)context;
            WorldDataPacket        worldDataPacket  = (WorldDataPacket)packet;

            Player?simulationOwner = processorContext.Server.SimulationManager.GetSimulationOwner();

            if (simulationOwner == null || sourcePlayerId != simulationOwner.Value.Id)
            {
                //Deny request if client isn't the simulation owner
                return;
            }

            processorContext.Server.WorldStateManager.OnWorldDataReceived(worldDataPacket.World);
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context)
        {
            ClientProcessorContext clientProcessor   = (ClientProcessorContext)context;
            SimulationManager      simulationManager = clientProcessor.Client.SimulationManager;
            Player?player = simulationManager.GetSimulationOwner();

            if (player.HasValue && clientProcessor.Client.LocalPlayer.HasValue && clientProcessor.Client.LocalPlayer.Value != player.Value)
            {
                return; // Not the simulation owner
            }
            GameStateGame gameStateGame = GameManager.getInstance().getGameState() as GameStateGame;

            string         xmlData        = WorldSerializer.Serialize(gameStateGame);
            WorldStateData worldStateData = new WorldStateData(xmlData);

            WorldDataPacket worldDataPacket = new WorldDataPacket(worldStateData);

            clientProcessor.Client.SendPacket(worldDataPacket);
        }