Ejemplo n.º 1
0
 void SendWorldInfo(int tilex, int tiley, bool fakeid)
 {
     using (var ms = new MemoryStream())
     {
         var msg = new WorldInfoMsg
         {
             Time = (int)Main.time,
             DayTime = Main.dayTime,
             MoonPhase = (byte)Main.moonPhase,
             BloodMoon = Main.bloodMoon,
             MaxTilesX = Main.maxTilesX,
             MaxTilesY = Main.maxTilesY,
             SpawnX = tilex,
             SpawnY = tiley,
             WorldSurface = (int)Main.worldSurface,
             RockLayer = (int)Main.rockLayer,
             //Sending a fake world id causes the client to not be able to find a stored spawnx/y.
             //This fixes the bed spawn point bug. With a fake world id it wont be able to find the bed spawn.
             WorldID = !fakeid ? Main.worldID : -1,
             WorldFlags = (WorldGen.shadowOrbSmashed ? WorldInfoFlag.OrbSmashed : WorldInfoFlag.None) |
             (NPC.downedBoss1 ? WorldInfoFlag.DownedBoss1 : WorldInfoFlag.None) |
             (NPC.downedBoss2 ? WorldInfoFlag.DownedBoss2 : WorldInfoFlag.None) |
             (NPC.downedBoss3 ? WorldInfoFlag.DownedBoss3 : WorldInfoFlag.None) |
             (Main.hardMode ? WorldInfoFlag.HardMode : WorldInfoFlag.None) |
             (NPC.downedClown ? WorldInfoFlag.DownedClown : WorldInfoFlag.None),
             WorldName = Main.worldName
         };
         msg.PackFull(ms);
         SendRawData(ms.ToArray());
     }
 }
Ejemplo n.º 2
0
        void SendTeleport(int tilex, int tiley)
        {
            var msg = new WorldInfoMsg
            {
                Time = (int)Main.time,
                DayTime = Main.dayTime,
                MoonPhase = (byte)Main.moonPhase,
                BloodMoon = Main.bloodMoon,
                MaxTilesX = Main.maxTilesX,
                MaxTilesY = Main.maxTilesY,
                SpawnX = tilex,
                SpawnY = tiley,
                WorldSurface = (int)Main.worldSurface,
                RockLayer = (int)Main.rockLayer,
                WorldID = Main.worldID,
                WorldFlags = (WorldGen.shadowOrbSmashed ? WorldInfoFlag.OrbSmashed : WorldInfoFlag.None) |
                (NPC.downedBoss1 ? WorldInfoFlag.DownedBoss1 : WorldInfoFlag.None) |
                (NPC.downedBoss2 ? WorldInfoFlag.DownedBoss2 : WorldInfoFlag.None) |
                (NPC.downedBoss3 ? WorldInfoFlag.DownedBoss3 : WorldInfoFlag.None),
                WorldName = Main.worldName
            };

            using (var ms = new MemoryStream())
            {
                msg.PackFull(ms);
                SendRawData(ms.ToArray());
            }
        }
Ejemplo n.º 3
0
        private void NetHooks_SendData(SendDataEventArgs e)
        {
            if (e.MsgID == PacketTypes.Disconnect)
            {
                Action<ServerSock, string> senddisconnect = (sock, str) =>
                                                                {
                                                                    if (sock == null || !sock.active)
                                                                        return;
                                                                    sock.kill = true;
                                                                    using (var ms = new MemoryStream())
                                                                    {
                                                                        new DisconnectMsg {Reason = str}.PackFull(ms);
                                                                        SendBytesBufferless(sock, ms.ToArray());
                                                                    }
                                                                };

                if (e.remoteClient != -1)
                {
                    senddisconnect(Netplay.serverSock[e.remoteClient], e.text);
                }
                else
                {
                    for (int i = 0; i < Netplay.serverSock.Length; i++)
                    {
                        if (e.ignoreClient != -1 && e.ignoreClient == i)
                            continue;

                        senddisconnect(Netplay.serverSock[i], e.text);
                    }
                }
                e.Handled = true;
            }
            if (e.MsgID == PacketTypes.WorldInfo)
            {
                if (e.remoteClient == -1) return;
                var player = Players[e.remoteClient];
                if (player == null) return;
                if (Config.UseServerName)
                {
                    using (var ms = new MemoryStream())
                    {
                        var msg = new WorldInfoMsg
                        {
                            Time = (int)Main.time,
                            DayTime = Main.dayTime,
                            MoonPhase = (byte)Main.moonPhase,
                            BloodMoon = Main.bloodMoon,
                            MaxTilesX = Main.maxTilesX,
                            MaxTilesY = Main.maxTilesY,
                            SpawnX = Main.spawnTileX,
                            SpawnY = Main.spawnTileY,
                            WorldSurface = (int)Main.worldSurface,
                            RockLayer = (int)Main.rockLayer,
                            WorldID = Main.worldID,
                            WorldFlags =
                                (WorldGen.shadowOrbSmashed ? WorldInfoFlag.OrbSmashed : WorldInfoFlag.None) |
                                (NPC.downedBoss1 ? WorldInfoFlag.DownedBoss1 : WorldInfoFlag.None) |
                                (NPC.downedBoss2 ? WorldInfoFlag.DownedBoss2 : WorldInfoFlag.None) |
                                (NPC.downedBoss3 ? WorldInfoFlag.DownedBoss3 : WorldInfoFlag.None) |
                                (Main.hardMode ? WorldInfoFlag.HardMode : WorldInfoFlag.None) |
                                (NPC.downedClown ? WorldInfoFlag.DownedClown : WorldInfoFlag.None),
                            WorldName = Config.ServerName
                        };
                        msg.PackFull(ms);
                        player.SendRawData(ms.ToArray());
                    }
                    e.Handled = true;
                }
            }
        }
Ejemplo n.º 4
0
 public void SendWorldInfo(int tilex, int tiley, bool fakeid)
 {
     using (var ms = new MemoryStream())
     {
         var msg = new WorldInfoMsg
         {
             Time = (int)Main.time,
             DayTime = Main.dayTime,
             MoonPhase = (byte)Main.moonPhase,
             BloodMoon = Main.bloodMoon,
             Eclipse = Main.eclipse,
             MaxTilesX = (short)Main.maxTilesX,
             MaxTilesY = (short)Main.maxTilesY,
             SpawnX = (short)Main.spawnTileX,
             SpawnY = (short)Main.spawnTileY,
             WorldSurface = (short)Main.worldSurface,
             RockLayer = (short)Main.rockLayer,
             //Sending a fake world id causes the client to not be able to find a stored spawnx/y.
             //This fixes the bed spawn point bug. With a fake world id it wont be able to find the bed spawn.
             WorldID = Main.worldID,
             MoonType = (byte)Main.moonType,
             TreeX0 = Main.treeX[0],
             TreeX1 = Main.treeX[1],
             TreeX2 = Main.treeX[2],
             TreeStyle0 = (byte)Main.treeStyle[0],
             TreeStyle1 = (byte)Main.treeStyle[1],
             TreeStyle2 = (byte)Main.treeStyle[2],
             TreeStyle3 = (byte)Main.treeStyle[3],
             CaveBackX0 = Main.caveBackX[0],
             CaveBackX1 = Main.caveBackX[1],
             CaveBackX2 = Main.caveBackX[2],
             CaveBackStyle0 = (byte)Main.caveBackStyle[0],
             CaveBackStyle1 = (byte)Main.caveBackStyle[1],
             CaveBackStyle2 = (byte)Main.caveBackStyle[2],
             CaveBackStyle3 = (byte)Main.caveBackStyle[3],
             SetBG0 = (byte)WorldGen.treeBG,
             SetBG1 = (byte)WorldGen.corruptBG,
             SetBG2 = (byte)WorldGen.jungleBG,
             SetBG3 = (byte)WorldGen.snowBG,
             SetBG4 = (byte)WorldGen.hallowBG,
             SetBG5 = (byte)WorldGen.crimsonBG,
             SetBG6 = (byte)WorldGen.desertBG,
             SetBG7 = (byte)WorldGen.oceanBG,
             IceBackStyle = (byte)Main.iceBackStyle,
             JungleBackStyle = (byte)Main.jungleBackStyle,
             HellBackStyle = (byte)Main.hellBackStyle,
             WindSpeed = Main.windSpeed,
             NumberOfClouds = (byte)Main.numClouds,
             BossFlags = (WorldGen.shadowOrbSmashed ? BossFlags.OrbSmashed : BossFlags.None) |
                         (NPC.downedBoss1 ? BossFlags.DownedBoss1 : BossFlags.None) |
                         (NPC.downedBoss2 ? BossFlags.DownedBoss2 : BossFlags.None) |
                         (NPC.downedBoss3 ? BossFlags.DownedBoss3 : BossFlags.None) |
                         (Main.hardMode ? BossFlags.HardMode : BossFlags.None) |
                         (NPC.downedClown ? BossFlags.DownedClown : BossFlags.None) |
                         (Main.ServerSideCharacter ? BossFlags.ServerSideCharacter : BossFlags.None) |
                         (NPC.downedPlantBoss ? BossFlags.DownedPlantBoss : BossFlags.None),
             BossFlags2 = (NPC.downedMechBoss1 ? BossFlags2.DownedMechBoss1 : BossFlags2.None) |
                          (NPC.downedMechBoss2 ? BossFlags2.DownedMechBoss2 : BossFlags2.None) |
                          (NPC.downedMechBoss3 ? BossFlags2.DownedMechBoss3 : BossFlags2.None) |
                          (NPC.downedMechBossAny ? BossFlags2.DownedMechBossAny : BossFlags2.None) |
                          (Main.cloudBGActive == 1f ? BossFlags2.CloudBg : BossFlags2.None) |
                          (WorldGen.crimson ? BossFlags2.Crimson : BossFlags2.None) |
                          (Main.pumpkinMoon ? BossFlags2.PumpkinMoon : BossFlags2.None) |
                          (Main.snowMoon ? BossFlags2.SnowMoon : BossFlags2.None),
             Rain = Main.maxRaining,
             WorldName = TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName
         };
         msg.PackFull(ms);
         SendRawData(ms.ToArray());
     }
 }
Ejemplo n.º 5
0
        private void NetHooks_SendData(SendDataEventArgs e)
        {
            if (e.MsgId == PacketTypes.Disconnect)
            {
                Action<ServerSock, string> senddisconnect = (sock, str) =>
                                                                {
                                                                    if (sock == null || !sock.active)
                                                                        return;
                                                                    sock.kill = true;
                                                                    using (var ms = new MemoryStream())
                                                                    {
                                                                        new DisconnectMsg { Reason = str }.PackFull(ms);
                                                                        SendBytesBufferless(sock, ms.ToArray());
                                                                    }
                                                                };

                if (e.remoteClient != -1)
                {
                    senddisconnect(Netplay.serverSock[e.remoteClient], e.text);
                }
                else
                {
                    for (int i = 0; i < Netplay.serverSock.Length; i++)
                    {
                        if (e.ignoreClient != -1 && e.ignoreClient == i)
                            continue;

                        senddisconnect(Netplay.serverSock[i], e.text);
                    }
                }
                e.Handled = true;
                return;
            }
            else if (e.MsgId == PacketTypes.WorldInfo)
            {
                if (e.remoteClient == -1) return;
                var player = Players[e.remoteClient];
                if (player == null) return;
                using (var ms = new MemoryStream())
                {
                    var msg = new WorldInfoMsg
                    {
                        Time = (int)Main.time,
                        DayTime = Main.dayTime,
                        MoonPhase = (byte)Main.moonPhase,
                        BloodMoon = Main.bloodMoon,
                        Eclipse = Main.eclipse,
                        MaxTilesX = (short)Main.maxTilesX,
                        MaxTilesY = (short)Main.maxTilesY,
                        SpawnX = (short)Main.spawnTileX,
                        SpawnY = (short)Main.spawnTileY,
                        WorldSurface = (short)Main.worldSurface,
                        RockLayer = (short)Main.rockLayer,
                        //Sending a fake world id causes the client to not be able to find a stored spawnx/y.
                        //This fixes the bed spawn point bug. With a fake world id it wont be able to find the bed spawn.
                        WorldID = Main.worldID,
                        MoonType = (byte)Main.moonType,
                        TreeX0 = Main.treeX[0],
                        TreeX1 = Main.treeX[1],
                        TreeX2 = Main.treeX[2],
                        TreeStyle0 = (byte)Main.treeStyle[0],
                        TreeStyle1 = (byte)Main.treeStyle[1],
                        TreeStyle2 = (byte)Main.treeStyle[2],
                        TreeStyle3 = (byte)Main.treeStyle[3],
                        CaveBackX0 = Main.caveBackX[0],
                        CaveBackX1 = Main.caveBackX[1],
                        CaveBackX2 = Main.caveBackX[2],
                        CaveBackStyle0 = (byte)Main.caveBackStyle[0],
                        CaveBackStyle1 = (byte)Main.caveBackStyle[1],
                        CaveBackStyle2 = (byte)Main.caveBackStyle[2],
                        CaveBackStyle3 = (byte)Main.caveBackStyle[3],
                        SetBG0 = (byte)WorldGen.treeBG,
                        SetBG1 = (byte)WorldGen.corruptBG,
                        SetBG2 = (byte)WorldGen.jungleBG,
                        SetBG3 = (byte)WorldGen.snowBG,
                        SetBG4 = (byte)WorldGen.hallowBG,
                        SetBG5 = (byte)WorldGen.crimsonBG,
                        SetBG6 = (byte)WorldGen.desertBG,
                        SetBG7 = (byte)WorldGen.oceanBG,
                        IceBackStyle = (byte)Main.iceBackStyle,
                        JungleBackStyle = (byte)Main.jungleBackStyle,
                        HellBackStyle = (byte)Main.hellBackStyle,
                        WindSpeed = Main.windSpeed,
                        NumberOfClouds = (byte)Main.numClouds,
                        BossFlags = (WorldGen.shadowOrbSmashed ? BossFlags.OrbSmashed : BossFlags.None) |
                                    (NPC.downedBoss1 ? BossFlags.DownedBoss1 : BossFlags.None) |
                                    (NPC.downedBoss2 ? BossFlags.DownedBoss2 : BossFlags.None) |
                                    (NPC.downedBoss3 ? BossFlags.DownedBoss3 : BossFlags.None) |
                                    (Main.hardMode ? BossFlags.HardMode : BossFlags.None) |
                                    (NPC.downedClown ? BossFlags.DownedClown : BossFlags.None) |
                                    (Main.ServerSideCharacter ? BossFlags.ServerSideCharacter : BossFlags.None) |
                                    (NPC.downedPlantBoss ? BossFlags.DownedPlantBoss : BossFlags.None),
                        BossFlags2 = (NPC.downedMechBoss1 ? BossFlags2.DownedMechBoss1 : BossFlags2.None) |
                                     (NPC.downedMechBoss2 ? BossFlags2.DownedMechBoss2 : BossFlags2.None) |
                                     (NPC.downedMechBoss3 ? BossFlags2.DownedMechBoss3 : BossFlags2.None) |
                                     (NPC.downedMechBossAny ? BossFlags2.DownedMechBossAny : BossFlags2.None) |
                                     (Main.cloudBGActive >= 1f ? BossFlags2.CloudBg : BossFlags2.None) |
                                     (WorldGen.crimson ? BossFlags2.Crimson : BossFlags2.None) |
                                     (Main.pumpkinMoon ? BossFlags2.PumpkinMoon : BossFlags2.None) |
                                     (Main.snowMoon ? BossFlags2.SnowMoon : BossFlags2.None) ,
                        Rain = Main.maxRaining,
                        WorldName = TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName
                    };
                    msg.PackFull(ms);
                    player.SendRawData(ms.ToArray());
                }
                e.Handled = true;
                return;
            }
            else if (e.MsgId == PacketTypes.PlayerHp)
            {
                if (Main.player[(byte)e.number].statLife <= 0)
                {
                    e.Handled = true;
                    return;
                }
            }
        }