SendNow() public method

Send packet to player (not thread safe, sync, immediate). Should NEVER be used from any thread other than this session's ioThread. Not thread-safe (for performance reason).
public SendNow ( Packet packet ) : void
packet Packet
return void
Example #1
0
 void WritePacket()
 {
     Packet.WriteI16((short)index, data, 1);
     data[1027] = chunkValue;
     player.SendNow(new Packet(data));
     index = 0;
 }
Example #2
0
 static bool HandleDeny(Player p, Zone zone, ref bool deniedZone, Position newPos)
 {
     if (!zone.Controller.Check(p.Info) || zone.Controller.MinRank >= p.Info.Rank)
     {
         if (!zone.Bounds.Contains(p.lastValidPosition.BlockX, p.lastValidPosition.BlockY, (p.lastValidPosition.Z - 32) / 32))
         {
             p.lastValidPosition = p.Position;
         }
         if (zone.Bounds.Contains(newPos.BlockX, newPos.BlockY, (newPos.Z - 32) / 32))
         {
             deniedZone = true;
             if (zone.Controller.MinRank.NextRankUp != null)
             {
                 SendZoneMessage(p, "&WYou must be at least rank " + zone.Controller.MinRank.NextRankUp.Name + "&W to enter this area.");
             }
             else
             {
                 SendZoneMessage(p, "&WNo rank may enter this area.");
             }
             p.SendNow(p.TeleportPacket(Packet.SelfId, p.lastValidPosition));
             return(true);
         }
     }
     return(false);
 }
Example #3
0
 static void Send(Player dst, bool sendNow, Packet p)
 {
     if (sendNow)
     {
         dst.SendNow(p);
     }
     else
     {
         dst.Send(p);
     }
 }
 internal static void SendNowInventoryOrder(Player p)
 {
     BlockDefinition[] defs = p.World.BlockDefs;
     for (int i = (int)Block.Air + 1; i < defs.Length; i++)
     {
         BlockDefinition def = defs[i];
         if (def != null && def.InventoryOrder >= 0)
         {
             p.SendNow(Packet.SetInventoryOrder((byte)i, (byte)def.InventoryOrder));
         }
     }
 }
 internal static void SendNowBlocks(Player p)
 {
     BlockDefinition[] defs = p.World.BlockDefs;
     for (int i = (int)Block.Air + 1; i < defs.Length; i++)
     {
         BlockDefinition def = defs[i];
         if (def == null)
         {
             continue;
         }
         p.SendNow(GetPacket(p, def));
     }
 }
 internal static void SendNowRemoveOldBlocks(Player p, World oldWorld)
 {
     BlockDefinition[] defs = oldWorld.BlockDefs;
     for (int i = (int)Block.Air + 1; i < defs.Length; i++)
     {
         BlockDefinition def = defs[i];
         if (def == null || def == GlobalDefs[i])
         {
             continue;
         }
         p.SendNow(Packet.MakeRemoveBlockDefinition((byte)i));
     }
 }
Example #7
0
 public static void SendGlobalDefinitions(Player p) {
     for (int i = (int)Map.MaxCustomBlockType + 1; i < GlobalDefinitions.Length; i++) {
         BlockDefinition def = GlobalDefinitions[i];
         if (def == null) continue;
         
         if (p.Supports(CpeExtension.BlockDefinitionsExt) && def.Shape != 0)
             p.SendNow(Packet.MakeDefineBlockExt(def));
         else
             p.SendNow(Packet.MakeDefineBlock(def));
         p.SendNow(Packet.MakeSetBlockPermission(
             (Block)def.BlockID, true, true));
     }
 }
Example #8
0
 private static void PlaceHandler(Player player, CommandReader cmd) {
     bool isConsole = (player == Player.Console);
     if (isConsole && cmd.Count < 6) {
         player.Message("When used by console /Place requires a world name.");
         player.Message("/Place [x] [y] [z] [block] [world]");
         return;
     }
     Block block = Block.Stone;
     if (!isConsole && player.LastUsedBlockType != Block.None)
     	block = player.LastUsedBlockType;
     Vector3I coords;
     int x, y, z;
     if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) {
         if (cmd.HasNext) {
             string last = cmd.Next();
             if (!Map.GetBlockByName(last, false, out block)) {
                 player.Message("\"{0}\" is not a valid block type", last);
                 return;
             }
         }
         coords = new Vector3I(x, y, z);
     } else if (isConsole) {
         player.Message("Invalid coordinates!");
         return;
     } else {
         cmd.Rewind();
         if (cmd.HasNext) {
             string last = cmd.Next();
             if (!Map.GetBlockByName(last, false, out block)) {
                 player.Message("\"{0}\" is not a valid block type", last);
                 return;
             }
         }
         coords = new Vector3I(player.Position.X / 32, player.Position.Y / 32, (player.Position.Z - 64) / 32);
     }
     World world;
     if (player == Player.Console) {
         string worldName = cmd.Next();
         if (string.IsNullOrEmpty(worldName)) {
             player.Message("Console must specify a world!");
         }
         world = WorldManager.FindWorldOrPrintMatches(player, worldName);
         if (world == null)
             return;
     } else {
         world = player.World;
     }
     bool unLoad = false;
     if (!world.IsLoaded) {
         world.LoadMap();
         unLoad = true;
     }
     coords.X = Math.Min(world.map.Width - 1, Math.Max(0, coords.X));
     coords.Y = Math.Min(world.map.Length - 1, Math.Max(0, coords.Y));
     coords.Z = Math.Min(world.map.Height - 1, Math.Max(0, coords.Z));
     
     if (player == Player.Console) {
         BlockUpdate blockUpdate = new BlockUpdate(player, coords, block);
         player.Info.ProcessBlockPlaced((byte)block);
         world.map.QueueUpdate(blockUpdate);
         player.RaisePlayerPlacedBlockEvent(player, world.map, coords, block, world.map.GetBlock(coords), BlockChangeContext.Manual, true);
     } else {
         player.SendNow(Packet.MakeSetBlock(coords, block, player));
         player.PlaceBlockWithEvents(coords, ClickAction.Build, block);
     }
     if (!isConsole) 
         player.Message("{0} placed at {1}", block.ToString(), coords.ToString());
     if (unLoad) {
         world.UnloadMap(true);
     }
 }