public void ToPacket(WorldInfoPacket packet) { packet.WorldId = WorldId; packet.Created = packet.Modified = LastWriteTime; packet.Name = Name; packet.Description = Description; packet.Creator = Creator; packet.Genres = (int)(Genres & ~Genres.Virtual); packet.VotesUp = VotesUp; packet.VotesDown = VotesDown; packet.Downloads = Downloads; packet.Likes = NumLikes; packet.Comments = NumComments; packet.Permalink = Permalink; packet.MyVote = (int)MyVote; packet.FlaggedByMe = FlaggedByMe; packet.ThumbnailBytes = ThumbnailBytes; packet.CommentDetails = CommentDetails; packet.RowKey = RowKey; packet.PartitionKey = PartitionKey; packet.LastSaveTime = LastSaveTime; }
public void FromPacket(WorldInfoPacket packet) { WorldId = packet.WorldId; LastWriteTime = packet.Modified; Name = packet.Name; Description = packet.Description; Creator = packet.Creator; Genres = (Genres)packet.Genres; VotesUp = packet.VotesUp; VotesDown = packet.VotesDown; Downloads = packet.Downloads; NumLikes = packet.Likes; NumComments = packet.Comments; Permalink = packet.Permalink; MyVote = (Vote)packet.MyVote; FlaggedByMe = packet.FlaggedByMe; ThumbnailBytes = packet.ThumbnailBytes; CommentDetails = packet.CommentDetails; RowKey = packet.RowKey; PartitionKey = packet.PartitionKey; Checksum = packet.checksum; LastSaveTime = packet.LastSaveTime; }
/// <summary> /// Modifies outgoing packets to send fake data to the player. /// </summary> /// <param name="args"></param> private void OnSendBytes(SendBytesEventArgs args) { var player = TShock.Players[args.Socket.Id]; if (player == null || !player.IsBuildModeOn()) { return; } PacketTypes packetType = (PacketTypes)args.Buffer[2]; switch (packetType) { /// Invoked whenever the server sends WorldInfo data. /// Sending crafted data to the player such as: /// Setting time to noon, stopping rain, wind and sandstorm, /// as well as modifying world surface and rock layer height /// to display a surface background to the player. case PacketTypes.WorldInfo: { WorldInfoPacket packet = new WorldInfoPacket(); packet.time = 27000; packet.BitsByte1 = new BitsByte(true); // isDayTime = true packet.worldSurface = (short)Main.maxTilesY; packet.rockLayer = (short)Main.maxTilesY; packet.windSpeedTarget = 0; packet.maxRaining = 0; packet.IntendedSeverity = 0; packet.Write(new MemoryStream(args.Buffer, args.Offset, args.Count)); break; } /// Invoked whenever time is modified on the server. /// Sending crafted data to the player such as: /// Setting time to noon. case PacketTypes.TimeSet: { TimeSetPacket packet = new TimeSetPacket(); packet.dayTime = true; packet.time = 27000; packet.Write(new MemoryStream(args.Buffer, args.Offset, args.Count)); break; } /// Invoked whenever Server sends updated data of an NPC. /// Sending crafted data to the player such as: /// If NPC is not friendly, change its position to make them invisible for the player. case PacketTypes.NpcUpdate: { NPCUpdatePacket packet = new NPCUpdatePacket(); packet.Read(new MemoryStream(args.Buffer, args.Offset, args.Count)); if (!Main.npc[packet.npcIndex].active || Main.npc[packet.npcIndex].friendly) { return; } packet.position = new Microsoft.Xna.Framework.Vector2(); packet.velocity = new Microsoft.Xna.Framework.Vector2(); packet.Write(new MemoryStream(args.Buffer, args.Offset, args.Count)); break; } /// Invoked whenever Server sends updated data of a Projectile. /// Sending crafted data to the player such as: /// If projectile is hostile and it is not the player's projectile, change its position to make it invisible for the player. case PacketTypes.ProjectileNew: { ProjectileNewPacket projectilePacket = new ProjectileNewPacket(); projectilePacket.Read(new MemoryStream(args.Buffer, args.Offset, args.Count)); if (Main.projectile.First(e => e.identity == projectilePacket.Index && e.owner == projectilePacket.Owner).friendly) { return; } projectilePacket.Type = 0; projectilePacket.Write(new MemoryStream(args.Buffer, args.Offset, args.Count)); break; } } }