Exemplo n.º 1
0
        public static void StartInvasion(int musicType, IReadOnlyList <KeyValuePair <int, ISet <int> > > spawnInfo)
        {
            var myworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            if (Main.netMode == 0)
            {
                myworld.Logic.StartInvasion(musicType, spawnInfo);
            }
            else if (Main.netMode == 1)
            {
                ClientPacketHandlers.SendInvasionRequestFromClient(musicType, spawnInfo);
            }
            else if (Main.netMode == 2)
            {
                string spawnInfoEnc = JsonConvert.SerializeObject(spawnInfo);

                myworld.Logic.StartInvasion(musicType, spawnInfo);

                for (int i = 0; i < Main.player.Length; i++)
                {
                    Player player = Main.player[i];
                    if (player == null || !player.active)
                    {
                        continue;
                    }

                    ServerPacketHandlers.SendInvasionFromServer(player, musicType, spawnInfoEnc);
                }
            }
        }
Exemplo n.º 2
0
        public ServerConnector(string ip, int port)
            : base(ip, port)
        {
            m_handlers = new ServerPacketHandlers(this);

            OnInitialize();
        }
Exemplo n.º 3
0
        public static void EndInvasion()
        {
            var myworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            if (Main.netMode == 0)
            {
                myworld.Logic.EndInvasion();
            }
            else if (Main.netMode == 1)
            {
                ClientPacketHandlers.SendEndInvasionRequestFromClient();
            }
            else if (Main.netMode == 2)
            {
                myworld.Logic.EndInvasion();

                for (int i = 0; i < Main.player.Length; i++)
                {
                    Player player = Main.player[i];
                    if (player == null || !player.active)
                    {
                        continue;
                    }

                    ServerPacketHandlers.SendEndInvasionFromServer(player);
                }
            }
        }
Exemplo n.º 4
0
        ////////////////

        public override void HandlePacket(BinaryReader reader, int player_who)
        {
            if (Main.netMode == 1)                  // Client
            {
                ClientPacketHandlers.HandlePacket(this, reader);
            }
            else if (Main.netMode == 2)                     // Server
            {
                ServerPacketHandlers.HandlePacket(this, reader, player_who);
            }
        }
Exemplo n.º 5
0
        ////////////////

        public override void HandlePacket(BinaryReader reader, int playerWho)
        {
            if (Main.netMode == 1)
            {
                ClientPacketHandlers.RoutePacket(this, reader);
            }
            else if (Main.netMode == 2)
            {
                ServerPacketHandlers.RoutePacket(this, reader, playerWho);
            }
        }
Exemplo n.º 6
0
        ////////////////

        public override void HandlePacket(BinaryReader reader, int playerWho)
        {
            try {
                if (Main.netMode == 1)
                {
                    ClientPacketHandlers.HandlePacket(reader);
                }
                else if (Main.netMode == 2)
                {
                    ServerPacketHandlers.HandlePacket(reader, playerWho);
                }
            } catch (Exception e) {
                LogHelpers.Log("HandlePacket " + e.ToString());
            }
        }
Exemplo n.º 7
0
        public bool Execute(string[] paramsList)
        {
            try
            {
                Assembly assembly = Assembly.GetAssembly(typeof(AssemblyHelper));

                PacketHandlers.SearchPacketHandler(assembly);
                ServerPacketHandlers.SearchPacketHandler(assembly);

                return(true);
            }
            catch (Exception ex)
            {
                log.Error("搜索处理类失败!", ex);
            }

            return(false);
        }
Exemplo n.º 8
0
        private void UpdateEndSigns()
        {
            var mymod = TheLunaticMod.Instance;

            if (this.HaveWeEndSigns())
            {
                int halfDaysLeft = (mymod.Config.DaysUntil * 2) - this.HalfDaysElapsed;
                int rand         = Main.rand.Next(halfDaysLeft * 60 * 54);

                if (Main.netMode != 1 && rand == 0)                     // Not client
                {
                    int duration = (int)(120 + (60 * 4 * Main.rand.NextFloat()));

                    if (Main.netMode == 2)                              // Server
                    {
                        ServerPacketHandlers.BroadcastEndSignFromServer(duration);
                    }
                    else if (Main.netMode == 0)                                 // Single-player
                    {
                        this.ApplyEndSignForMe(duration);
                    }
                }

                if (Main.netMode != 2)                      // Not server
                {
                    if (halfDaysLeft != 0)
                    {
                        double days = (double)this.HalfDaysElapsed + WorldStateHelpers.GetDayOrNightPercentDone();
                        days -= mymod.Config.DaysUntil;
                        mymod.Sky.TintScale = (float)days / (float)mymod.Config.DaysUntil;
                    }
                    else
                    {
                        mymod.Sky.TintScale = 0;
                    }
                }
            }
            else if (Main.netMode != 2)                         // Not server
            {
                mymod.Sky.TintScale = 0;
            }
        }
Exemplo n.º 9
0
 protected virtual void OnInitialize()
 {
     m_handlers = new ServerPacketHandlers(this);
 }