public static void SetWeather(Player p, Level lvl, string value) { byte weather = 255; if (IsResetString(value)) { Player.Message(p, "Reset weather for {0} %Sto 0 (%SSun)", lvl.ColoredName); weather = 0; } else { if (byte.TryParse(value, out weather)) { } else if (value.CaselessEq("sun")) { weather = 0; } else if (value.CaselessEq("rain")) { weather = 1; } else if (value.CaselessEq("snow")) { weather = 2; } if (weather > 2) { Player.Message(p, "Weather can be either sun, rain, or snow."); return; } string type = weather == 0 ? "%SSun" : (weather == 1 ? "&1Rain" : "&fSnow"); Player.Message(p, "Set weather for {0} %Sto {1} ({2}%S)", lvl.ColoredName, weather, type); } lvl.Weather = weather; Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (pl.level == lvl && pl.HasCpeExt(CpeExt.EnvWeatherType)) pl.Send(Packet.EnvWeatherType(weather)); } }
public void OnChangedZone() { if (Supports(CpeExt.InstantMOTD)) { SendMapMotd(); } Zone zone = ZoneIn; for (int i = 0; i <= 4; i++) { string col = level.Config.GetColor(i); if (zone != null && zone.Config.GetColor(i) != "") { col = zone.Config.GetColor(i); } if (Supports(CpeExt.EnvColors)) { SendEnvColor((byte)i, col); } } for (EnvProp i = 0; i < EnvProp.Max; i++) { int value = level.Config.GetEnvProp(i); if (i == EnvProp.SidesBlock || i == EnvProp.EdgeBlock) { if (zone != null && zone.Config.GetEnvProp(i) != Block.Invalid) { value = zone.Config.GetEnvProp(i); } value = ConvertBlock((BlockID)value); } else { if (zone != null && zone.Config.GetEnvProp(i) != -1) { value = zone.Config.GetEnvProp(i); } } if (Supports(CpeExt.EnvMapAspect)) { Send(Packet.EnvMapProperty(i, value)); } } if (Supports(CpeExt.EnvWeatherType)) { int weather = level.Config.Weather; if (zone != null && zone.Config.Weather != -1) { weather = zone.Config.Weather; } Send(Packet.EnvWeatherType((byte)weather)); } }
internal static void UpdateWeather(Predicate <Player> selector, byte weather) { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (!selector(pl) || !pl.Supports(CpeExt.EnvWeatherType)) { continue; } pl.Send(Packet.EnvWeatherType(weather)); if (pl.ZoneIn != null) { pl.OnChangedZone(); } } }
public void SendCurrentEnv() { Zone zone = ZoneIn; for (int i = 0; i <= 5; i++) { string col = Server.Config.GetColor(i); if (level.Config.GetColor(i) != "") { col = level.Config.GetColor(i); } if (zone != null && zone.Config.GetColor(i) != "") { col = zone.Config.GetColor(i); } if (Supports(CpeExt.EnvColors)) { SendEnvColor((byte)i, col); } } if (Supports(CpeExt.EnvMapAspect)) { for (EnvProp i = 0; i < EnvProp.Max; i++) { int value = CurrentEnvProp(i, zone); Send(Packet.EnvMapProperty(i, value)); } } if (Supports(CpeExt.EnvWeatherType)) { int weather = CurrentEnvProp(EnvProp.Weather, zone); Send(Packet.EnvWeatherType((byte)weather)); } }
bool SendRawMapCore(Level oldLevel, Level level) { if (level.blocks == null) { return(false); } bool success = true; useCheckpointSpawn = false; lastCheckpointIndex = -1; LevelAccess access = level.BuildAccess.Check(this); AllowBuild = access == LevelAccess.Whitelisted || access == LevelAccess.Allowed; try { if (hasBlockDefs) { if (oldLevel != null && oldLevel != level) { RemoveOldLevelCustomBlocks(oldLevel); } BlockDefinition.SendLevelCustomBlocks(this); } SendRaw(Opcode.LevelInitialise); using (LevelChunkStream s = new LevelChunkStream(this)) LevelChunkStream.CompressMap(this, s); byte[] buffer = new byte[7]; buffer[0] = Opcode.LevelFinalise; NetUtils.WriteI16((short)level.Width, buffer, 1); NetUtils.WriteI16((short)level.Height, buffer, 3); NetUtils.WriteI16((short)level.Length, buffer, 5); Send(buffer); AFKCooldown = DateTime.UtcNow.AddSeconds(2); Loading = false; if (HasCpeExt(CpeExt.EnvWeatherType)) { Send(Packet.EnvWeatherType((byte)level.Weather)); } if (HasCpeExt(CpeExt.EnvColors)) { SendCurrentEnvColors(); } SendCurrentMapAppearance(); if (HasCpeExt(CpeExt.BlockPermissions)) { SendCurrentBlockPermissions(); } if (OnSendMap != null) { OnSendMap(this, buffer); } if (!level.guns && aiming) { aiming = false; ClearBlockchange(); } } catch (Exception ex) { success = false; PlayerActions.ChangeMap(this, Server.mainLevel); SendMessage("There was an error sending the map data, you have been sent to the main level."); Server.ErrorLog(ex); } finally { GC.Collect(); GC.WaitForPendingFinalizers(); } return(success); }