Exemplo n.º 1
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,
                         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 = tPulse.Config.UseServerName ? tPulse.Config.ServerName : Main.worldName
                     };
         msg.PackFull(ms);
         SendRawData(ms.ToArray());
     }
 }
Exemplo n.º 2
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;
                }
            }
        }