static bool CursedLand(Client player, PlayerBlockPlacement placement) { SlotItem i = player.Session.ActiveItem; if (i != null && i.ItemID == BlockID.Bucket) { var pps = new PlayerPositionLookClient(); pps.Position = placement.BlockPosition.CloneDouble(); pps.OnGround = false; pps.Position.Y += 1.1; pps.Position.X += 0.5; pps.Position.Z += 0.5; pps.Pitch = Math.PI / 2; pps.Yaw = player.Session.Yaw; player.FromClient(pps); var ppc = new PlayerPositionLookServer(pps.Position); ppc.Pitch = Math.PI / 2; ppc.Yaw = player.Session.Yaw; player.SendToClient(ppc); } BlockChange bc = new BlockChange(placement.BlockPosition.Offset(placement.FaceDirection), BlockID.Air); player.SendToClient(bc); //Block all actions return(true); }
public void OnTerrainModified(BlockChange change) { foreach (Handshake h in handshakes.Values) { h.TerrainChanges.Add(change); } }
public void SetBlock(Block block, bool broadcast = true, bool applyPhysics = true) { var chunk = Generator.GenerateChunkColumn(new Vector2((int)block.Coordinates.X >> 4, (int)block.Coordinates.Z >> 4)); chunk.SetBlock(Mod(block.Coordinates.X), (int)block.Coordinates.Y, Mod(block.Coordinates.Z), block); chunk.IsDirty = true; if (applyPhysics) { ApplyPhysics((int)block.Coordinates.X, (int)block.Coordinates.Y, (int)block.Coordinates.Z); } if (!broadcast) { return; } var packet = new BlockChange(null) { BlockId = block.Id, MetaData = block.Metadata, Location = block.Coordinates }; BroadcastPacket(packet); }
/// <summary> /// Prevent block modification, aplies to all, residents should never get called here /// </summary> public static bool ProtectBlockBreak(VanillaSession session, WorldRegion region, PlayerDigging d) { if (IsBlockProtected(session, region) == false) { return(false); } //Block single click from outside the adventure mode if (d.Status == PlayerDigging.StatusEnum.StartedDigging) { return(true); } if (d.Status != PlayerDigging.StatusEnum.FinishedDigging) { return(false); } //Old method - not needed BlockChange bc = new BlockChange(d.Position, BlockID.Bedrock); session.Player.SendToClient(bc); //New method - Works /* * PlayerDigging pd = new PlayerDigging(); * pd.Position = d.Position; * pd.Face = Face.Down; * pd.Status = PlayerDigging.StatusEnum.CheckBlock; * session.FromClient(pd); */ return(true); }
internal async Task SendBlockChangeAsync(BlockChange b) { this.Logger.LogMessage($"Sending block change to {Player.Username}"); await PacketHandler.CreateAsync(b, this.MinecraftStream); this.Logger.LogMessage($"Block change sent to {Player.Username}"); }
private void Terrain_OnModified(object sender, BlockChange e) { // Relay terrain modification to each client foreach (NetConnectionSnapshotState state in snapshotComponent.ConnectionStates.Values) { state.WorldSnapshot.TerrainSnapshot.AddChange(e); } }
public bool Setup() { //TODO: (in order) LoadEvents(); Logger.Init(); Logger.Log("Starting Server"); SQLiteDB = new SQLiteDatabase(); // UpdateDB(); //ItemDB = new ItemDB(); LoadFiles(); Properties.Load("properties/server.properties"); Command.InitCore(); BlockChange.InitAll(); Physics.Handlers.InitAll(); Plugin.Load(); Command.SortCommands(); //Get latest developerlist new Thread(new ThreadStart(UpdateDevs)).Start(); //load groups consolePlayer = new ConsolePlayer(s); consolePlayer.SetUsername(ConsoleName); //Group.DefaultGroup = new DefaultGroup(); //debug Group.LoadGroups(); BanList.AddRange(Properties.LoadList("properties/banned.txt")); if (usewhitelist) { WhiteList.AddRange(Properties.LoadList("properties/whitelist.txt")); } if (useviplist) { VIPList.AddRange(Properties.LoadList("properties/viplist.txt")); } loadLevels(); loadCleanUp(); try { IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); listen = new Socket(endpoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); listen.Bind(endpoint); listen.Listen(int.MaxValue); listen.BeginAccept(new AsyncCallback(Accept), null); return(true); } catch (SocketException e) { Logger.Log(e.Message + e.StackTrace); return(false); } catch (Exception e) { Logger.Log(e.Message + e.StackTrace); return(false); } }
public static bool GameManager_ChangeBlocks_Prefix(GameManager __instance, PlatformUserIdentifierAbs persistentPlayerId, List <BlockChangeInfo> _blocksToChange) { try { return(BlockChange.ProcessBlockChange(__instance, persistentPlayerId, _blocksToChange)); } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in Injections.GameManager_ChangeBlocks_Prefix: {0}", e.Message)); } return(true); }
static bool DiggProtect(Client player, PlayerDigging pd) { if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging) { BlockChange bc = new BlockChange(pd.Position.Offset(pd.Face), BlockID.Fire); player.SendToClient(bc); player.TellAbove(Chat.Purple, "You are still in spawn"); return(true); } return(false); }
public override int GetHashCode() { int result = BlockedId != null?BlockedId.GetHashCode() : 0; result = (31 * result) + (StateName != null ? StateName.GetHashCode() : 0); result = (31 * result) + (Service != null ? Service.GetHashCode() : 0); result = (31 * result) + BlockChange.GetHashCode(); result = (31 * result) + BlockEntitlement.GetHashCode(); result = (31 * result) + BlockBilling.GetHashCode(); result = (31 * result) + (EffectiveDate != null ? EffectiveDate.GetHashCode() : 0); result = (31 * result) + Type.GetHashCode(); return(result); }
public void EditNextFrame(BlockChange change) { Vector3Int position = change.position; byte type = change.type; if (position.x >= 0 && position.x < VoxelSettings.ChunkSizeX && position.y >= 0 && position.y < VoxelSettings.ChunkSizeY && position.z >= 0 && position.z < VoxelSettings.ChunkSizeZ) { editQueue.Add(new BlockChange(position, type)); } else { SafeDebug.LogError(string.Format("Out of Bounds: chunk: {0}, localVoxel: {1}, Function: EditNextFrame", chunkPosition, position)); } }
public override bool Equals(object o) { if (this == o) { return(true); } if (!(o is BlockingState)) { return(false); } BlockingState that = (BlockingState)o; if (BlockedId != null ? !BlockedId.Equals(that.BlockedId) : that.BlockedId != null) { return(false); } if (StateName != null ? !StateName.Equals(that.StateName) : that.StateName != null) { return(false); } if (Service != null ? !Service.Equals(that.Service) : that.Service != null) { return(false); } if (!BlockChange.Equals(that.BlockChange)) { return(false); } if (!BlockEntitlement.Equals(that.BlockEntitlement)) { return(false); } if (!BlockBilling.Equals(that.BlockBilling)) { return(false); } if (EffectiveDate != null ? EffectiveDate.CompareTo(that.EffectiveDate) != 0 : that.EffectiveDate != null) { return(false); } return(Type == that.Type); }
public void SetBlock(Block block, bool broadcast = true, bool applyPhysics = true) { var chunk = Generator.GenerateChunkColumn(new ChunkCoordinates((int)block.Coordinates.X >> 4, (int)block.Coordinates.Z >> 4)); chunk.SetBlock((int)block.Coordinates.X & 0x0f, (int)block.Coordinates.Y & 0x7f, (int)block.Coordinates.Z & 0x0f, block); chunk.IsDirty = true; if (applyPhysics) { ApplyPhysics((int)block.Coordinates.X, (int)block.Coordinates.Y, (int)block.Coordinates.Z); } if (!broadcast) { return; } BlockChange.Broadcast(block, this); }
public override void SetBlock(Block block, Level level, bool broadcast) { ChunkColumn c; lock (ChunkCache) { if ( !ChunkCache.TryGetValue(new Tuple <int, int>((int)block.Coordinates.X >> 4, (int)block.Coordinates.Z >> 4), out c)) { throw new Exception("No chunk found!"); } } c.SetBlock(((int)block.Coordinates.X & 0x0f), ((int)block.Coordinates.Y & 0x7f), ((int)block.Coordinates.Z & 0x0f), block); if (!broadcast) { return; } BlockChange.Broadcast(block, level); }
public void SetBlock(Block block, bool broadcast = true, bool applyPhysics = true) { var chunk = Generator.GenerateChunkColumn(new Vector2((int) block.Coordinates.X >> 4, (int) block.Coordinates.Z >> 4)); chunk.SetBlock(Mod(block.Coordinates.X), (int)block.Coordinates.Y, Mod(block.Coordinates.Z), block); chunk.IsDirty = true; if (applyPhysics) ApplyPhysics((int) block.Coordinates.X, (int) block.Coordinates.Y, (int) block.Coordinates.Z); if (!broadcast) return; var packet = new BlockChange(null) { BlockId = block.Id, MetaData = block.Metadata, Location = block.Coordinates }; BroadcastPacket(packet); }
public void OnBlockChange(BlockChange packet) { }
private void InvokeBlockChange(BlockChange packet) { packetListener.OnBlockChange(packet); }
public void NetThread() { SessionIDRequest sessionID = new SessionIDRequest(Storage.Network.UserName, Storage.Network.Password); sessionID.SendRequest(); SharedSecretGenerator sharedSecret = new SharedSecretGenerator(); //random byte[16] gen Timer positionUpdater = new Timer(PositionSender, null, Timeout.Infinite, 50); //create position updater Socket networkSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); networkSocket.Connect(Storage.Network.Server, Storage.Network.Port); _stream = new EnhancedStream(networkSocket); Handshake handshake = new Handshake(_stream); handshake.Send(Storage.Network.UserName, Storage.Network.Server, Storage.Network.Port); // connect Storage.Network.IsConnected = true; while (Storage.Network.IsConnected) { switch (_packetIDbuffer = (byte)_stream.ReadByte()) { case 0x00: KeepAlive keepAlive = new KeepAlive(_stream); break; case 0x01: LoginRequest loginRequest = new LoginRequest(_stream); //positionUpdater.Change(0, 50); ClientSettings clientSettings = new ClientSettings(_stream); clientSettings.Send(); break; case 0x03: ChatMessage chatMessage = new ChatMessage(_stream); break; case 0x04: TimeUpdate timeUpdate = new TimeUpdate(_stream); break; case 0x05: EntityEquipment entityEquipment = new EntityEquipment(_stream); break; case 0x06: SpawnPosition spawnPosition = new SpawnPosition(_stream); break; case 0x08: UpdateHealth updateHealth = new UpdateHealth(_stream); break; case 0x09: RespawnPacket respawnPacket = new RespawnPacket(_stream); break; case 0x0D: _playerPositionLook = new PlayerPositionLook(_stream); break; case 0x10: HeldItemChange heldItemChange = new HeldItemChange(_stream); break; case 0x11: UseBed useBed = new UseBed(_stream); break; case 0x12: Animation animation = new Animation(_stream); break; case 0x14: SpawnNamedEntity spawnNamedEntity = new SpawnNamedEntity(_stream); break; case 0x16: CollectItem collectItem = new CollectItem(_stream); break; case 0x17: SpawnObjectVehicle spawnObjectVehicle = new SpawnObjectVehicle(_stream); break; case 0x18: SpawnMob spawnMob = new SpawnMob(_stream); break; case 0x19: SpawnPainting spawnPainting = new SpawnPainting(_stream); break; case 0x1A: SpawnExperienceOrb spawnExperienceOrb = new SpawnExperienceOrb(_stream); break; case 0x1C: EntityVelocity entityVelocity = new EntityVelocity(_stream); break; case 0x1D: DestroyEntity destroyEntity = new DestroyEntity(_stream); break; case 0x1E: Entity entity = new Entity(_stream); break; case 0x1F: EntityRelativeMove entityRelativeMove = new EntityRelativeMove(_stream); break; case 0x20: EntityLook entityLook = new EntityLook(_stream); break; case 0x21: EntityLookRelativeMove entityLookRelativeMove = new EntityLookRelativeMove(_stream); break; case 0x22: EntityTeleport entityTeleport = new EntityTeleport(_stream); break; case 0x23: EntityHeadLook entityHeadLook = new EntityHeadLook(_stream); break; case 0x26: EntityStatus entityStatus = new EntityStatus(_stream); break; case 0x27: AttachEntity attachEntity = new AttachEntity(_stream); break; case 0x28: EntityMetadata entityMetadata = new EntityMetadata(_stream); break; case 0x29: EntityEffect entityEffect = new EntityEffect(_stream); break; case 0x2A: RemoveEntityEffect removeEntityEffect = new RemoveEntityEffect(_stream); break; case 0x2B: SetExperience setExperience = new SetExperience(_stream); break; case 0x33: ChunkData mapChunk = new ChunkData(_stream); break; case 0x34: MultiBlockChange multiBlockChange = new MultiBlockChange(_stream); break; case 0x35: BlockChange blockChange = new BlockChange(_stream); break; case 0x36: BlockAction blockAction = new BlockAction(_stream); break; case 0x37: BlockBreakAnimation blockBreakAnimation = new BlockBreakAnimation(_stream); break; case 0x38: MapChunkBulk mapChunkBulk = new MapChunkBulk(_stream); break; case 0x3C: Explosion explosion = new Explosion(_stream); break; case 0x3D: SoundParticleEffect soundParticleEffect = new SoundParticleEffect(_stream); break; case 0x3E: NamedSoundEffect namedSoundEffect = new NamedSoundEffect(_stream); break; case 0x46: ChangeGameState changeGameState = new ChangeGameState(_stream); break; case 0x47: Thunderbolt thunderbolt = new Thunderbolt(_stream); break; case 0x64: OpenWindow openWindow = new OpenWindow(_stream); break; case 0x65: CloseWindow closeWindow = new CloseWindow(_stream); break; case 0x67: SetSlot setSlot = new SetSlot(_stream); break; case 0x68: SetWindowItems setWindowItems = new SetWindowItems(_stream); break; case 0x69: UpdateWindowProperty updateWindowProperty = new UpdateWindowProperty(_stream); break; case 0x6A: ConfirmTransaction confirmTransaction = new ConfirmTransaction(_stream); break; case 0x6B: CreativeInventoryAction creativeInventoryAction = new CreativeInventoryAction(_stream); break; case 0x6C: EnchantItem enchantItem = new EnchantItem(_stream); break; case 0x82: UpdateSign updateSign = new UpdateSign(_stream); break; case 0x83: ItemData itemData = new ItemData(_stream); break; case 0x84: UpdateTileEntity updateTileEntity = new UpdateTileEntity(_stream); break; case 0xC8: IncrementStatistic incrementStatistic = new IncrementStatistic(_stream); break; case 0xC9: PlayerListItem playerListItem = new PlayerListItem(_stream); break; case 0xCA: PlayerAbilities playerAbilities = new PlayerAbilities(_stream); break; case 0xCB: TabComplete tabcomplete = new TabComplete(_stream); break; case 0xFA: PluginMessage pluginMessage = new PluginMessage(_stream); break; case 0xFC: EncryptionKeyResponse encryptionKeyResponse = new EncryptionKeyResponse(_stream); encryptionKeyResponse.Get(); _stream = new AesStream(networkSocket, _stream, sharedSecret.Get); ClientStatuses clientStatuses = new ClientStatuses(_stream); clientStatuses.Send(0); break; case 0xFD: EncryptionKeyRequest encryptionKeyRequest = new EncryptionKeyRequest(_stream, sharedSecret.Get, sessionID.GetID(), Storage.Network.UserName); // encryptionKeyResponse = new EncryptionKeyResponse(_stream); encryptionKeyResponse.Send(encryptionKeyRequest.GetEncSharedSecret(), encryptionKeyRequest.GetEncToken()); break; case 0xFF: positionUpdater = null; DisconnectKick disconnectKick = new DisconnectKick(_stream); networkSocket.Disconnect(false); break; default: throw new Exception("We got a Unknown Packet (" + _packetIDbuffer + ")from the Server. This should not happen: Error in Packet parser"); } } }
public void AddChange(BlockChange change) { changes.Add(change); }
private async Task ServerLoop() { var keepaliveticks = 0; while (!_cts.IsCancellationRequested) { await Task.Delay(50); TotalTicks++; await Events.InvokeServerTick(); keepaliveticks++; if (keepaliveticks > 200) { var keepaliveid = DateTime.Now.Millisecond; foreach (var clnt in this.Clients.Where(x => x.State == ClientState.Play).ToList()) { await Task.Factory.StartNew(async() => { await clnt.ProcessKeepAlive(keepaliveid); }); } keepaliveticks = 0; } if (_chatmessages.Count > 0) { foreach (var players in this.OnlinePlayers) { if (_chatmessages.TryPeek(out QueueChat msg)) { await Task.Factory.StartNew(async() => { await players.SendMessageAsync(msg.Message, msg.Position); }); } } _chatmessages.TryDequeue(out QueueChat chat); } if (_diggers.Count > 0) { if (_diggers.TryPeek(out PlayerDigging d)) { foreach (var clnt in Clients) { var b = new BlockChange(d.Location, BlockRegistry.G(Materials.Air).Id); await clnt.SendBlockChangeAsync(b); } } _diggers.TryDequeue(out PlayerDigging dd); } // TODO use blockface values to determine where block should be placed if (_placed.Count > 0) { if (_placed.TryPeek(out PlayerBlockPlacement pbp)) { foreach (var clnt in Clients) { var location = pbp.Location; var b = new BlockChange(pbp.Location, BlockRegistry.G(Materials.Cobblestone).Id); await clnt.SendBlockChangeAsync(b); } } _placed.TryDequeue(out PlayerBlockPlacement pbpn); } if (Config.Baah.HasValue) { foreach (var player in this.OnlinePlayers) { var pos = new Position(player.Transform.X * 8, player.Transform.Y * 8, player.Transform.Z * 8); await player.SendSoundAsync(461, pos, SoundCategory.Master, 1.0f, 1.0f); } } foreach (var client in Clients) { if (!client.Tcp.Connected) { this.Clients.TryRemove(client); continue; } //if (client.State == ClientState.Play) // await world.UpdateChunksForClient(client); } } }