Пример #1
0
        public void Spectate(NetPlayer target)
        {
            if (SpectateTarget == target)
            {
                return;
            }

            bool wasSpectating = SpectateTarget != null;

            SpectateTarget = target;

            // Send message to connection to start/stop spectating target
            var netMessage = server.CreateMessage();

            netMessage.Write(MessageType.SpectateTarget);
            netMessage.Write(target?.Id ?? 0);

            Peer.SendMessage(netMessage, NetDeliveryMethod.ReliableOrdered, 0);

            netMessage = server.CreateMessage();

            if (target != null && !wasSpectating) // Started spectating
            {
                // Stop people from spectating this player
                foreach (var netPlayer in server.Players.Values)
                {
                    if (netPlayer.SpectateTarget == this)
                    {
                        netPlayer.Spectate(null);
                    }
                }

                // Broadcast message to all other peers to remove this peers player (if he wasn't spectating already, otherwise he would already be despawned)
                netMessage.Write(MessageType.RemovePlayer);
                netMessage.Write(Id);

                server.Broadcast(netMessage, NetDeliveryMethod.ReliableOrdered, 0, Peer);
            }
            else if (target == null) // Stopped spectating
            {
                // Broadcast message to all other peers to add this peers player
                netMessage.Write(MessageType.CreatePlayer);
                netMessage.Write(Id);
                netMessage.Write(Name);
                netMessage.Write(Movement);
                netMessage.Write(Wins);
                netMessage.Write(Goldness);
                netMessage.WriteRgbaColor(PotColor);
                server.Broadcast(netMessage, NetDeliveryMethod.ReliableOrdered, 0, Peer);
            }
        }
            public bool Execute(GameServer server, Player plr, string[] args)
            {
                Task.Factory.StartNew(() =>
                {
                    var message = "Reloading shop, server may lag for a short period of time...";

                    if (plr == null)
                    {
                        Console.WriteLine(message);
                    }
                    else
                    {
                        plr.SendConsoleMessage(S4Color.Green + message);
                    }

                    server.BroadcastNotice(message);

                    server.ResourceCache.Clear(ResourceCacheType.Shop);
                    var shop    = server.ResourceCache.GetShop();
                    var version = shop.Version;
                    server.Broadcast(new NewShopUpdateCheckAckMessage
                    {
                        Date01 = version,
                        Date02 = version,
                        Date03 = version,
                        Date04 = version,
                        Unk    = 0
                    });
                    #region NewShopPrice

                    using (var w = new BinaryWriter(new MemoryStream()))
                    {
                        w.Serialize(shop.Prices.Values.ToArray());

                        server.Broadcast(new NewShopUpdataInfoAckMessage
                        {
                            Type = ShopResourceType.NewShopPrice,
                            Data = w.ToArray(),
                            Date = version
                        });
                    }

                    #endregion

                    #region NewShopEffect

                    using (var w = new BinaryWriter(new MemoryStream()))
                    {
                        w.Serialize(shop.Effects.Values.ToArray());

                        server.Broadcast(new NewShopUpdataInfoAckMessage
                        {
                            Type = ShopResourceType.NewShopEffect,
                            Data = w.ToArray(),
                            Date = version
                        });
                    }

                    #endregion

                    #region NewShopItem

                    using (var w = new BinaryWriter(new MemoryStream()))
                    {
                        w.Serialize(shop.Items.Values.ToArray());

                        server.Broadcast(new NewShopUpdataInfoAckMessage
                        {
                            Type = ShopResourceType.NewShopItem,
                            Data = w.ToArray(),
                            Date = version
                        });
                    }

                    #endregion

                    // ToDo
                    using (var w = new BinaryWriter(new MemoryStream()))
                    {
                        w.Write(0);

                        server.Broadcast(new NewShopUpdataInfoAckMessage
                        {
                            Type = ShopResourceType.NewShopUniqueItem,
                            Data = w.ToArray(),
                            Date = version
                        });
                    }

                    server.Broadcast(new NewShopUpdateEndAckMessage());
                    message = "Shop reload completed";
                    server.BroadcastNotice(message);
                    if (plr == null)
                    {
                        Console.WriteLine(message);
                    }
                    else
                    {
                        plr.SendConsoleMessage(S4Color.Green + message);
                    }
                });
                return(true);
            }