public PlayerJoinedWorldEventArgs([NotNull] Player player, World oldWorld, World newWorld, WorldChangeReason reason) { Player = player ?? throw new ArgumentNullException(nameof(player)); OldWorld = oldWorld; NewWorld = newWorld; Reason = reason; }
static void RaisePlayerJoinedWorldEvent(Player player, World oldWorld, WorldChangeReason reason) { var h = JoinedWorld; if (h != null) { h(null, new PlayerJoinedWorldEventArgs(player, oldWorld, player.World, reason)); } }
public PlayerJoinedWorldEventArgs([NotNull] Player player, World oldWorld, World newWorld, WorldChangeReason reason) { if (player == null) { throw new ArgumentNullException("player"); } Player = player; OldWorld = oldWorld; NewWorld = newWorld; Reason = reason; }
internal PlayerJoiningWorldEventArgs([NotNull] Player player, [CanBeNull] World oldWorld, [NotNull] World newWorld, WorldChangeReason reason, string textLine1, string textLine2) { Player = player ?? throw new ArgumentNullException(nameof(player)); OldWorld = oldWorld; NewWorld = newWorld ?? throw new ArgumentNullException(nameof(newWorld)); Reason = reason; TextLine1 = textLine1; TextLine2 = textLine2; }
internal PlayerJoinedWorldEventArgs([NotNull] Player player, [CanBeNull] World oldWorld, [NotNull] World newWorld, WorldChangeReason context) { if (player == null) { throw new ArgumentNullException("player"); } Player = player; OldWorld = oldWorld; NewWorld = newWorld; Context = context; }
static void RaisePlayerJoinedWorldEvent([NotNull] Player player, [CanBeNull] World oldWorld, [NotNull] World newWorld, WorldChangeReason reason) { if (player == null) { throw new ArgumentNullException("player"); } if (newWorld == null) { throw new ArgumentNullException("newWorld"); } var h = JoinedWorld; if (h != null) { h(null, new PlayerJoinedWorldEventArgs(player, oldWorld, newWorld, reason)); } }
internal PlayerJoiningWorldEventArgs([NotNull] Player player, [CanBeNull] World oldWorld, [NotNull] World newWorld, WorldChangeReason reason, string textLine1, string textLine2) { if (player == null) { throw new ArgumentNullException("player"); } if (newWorld == null) { throw new ArgumentNullException("newWorld"); } Player = player; OldWorld = oldWorld; NewWorld = newWorld; Reason = reason; TextLine1 = textLine1; TextLine2 = textLine2; }
static bool RaisePlayerJoiningWorldEvent([NotNull] Player player, [NotNull] World newWorld, WorldChangeReason reason) { if (player == null) { throw new ArgumentNullException("player"); } if (newWorld == null) { throw new ArgumentNullException("newWorld"); } var h = JoiningWorld; if (h == null) { return(false); } var e = new PlayerJoiningWorldEventArgs(player, player.World, newWorld, reason); h(null, e); return(e.Cancel); }
internal bool JoinWorldNow([NotNull] World newWorld, bool doUseWorldSpawn, WorldChangeReason reason) { if (newWorld == null) throw new ArgumentNullException("newWorld"); if (!Enum.IsDefined(typeof(WorldChangeReason), reason)) { throw new ArgumentOutOfRangeException("reason"); } if (Thread.CurrentThread != ioThread) { throw new InvalidOperationException("Player.JoinWorldNow may only be called from player's own thread. " + "Use Player.JoinWorld instead."); } string textLine1 = ConfigKey.ServerName.GetString(); string textLine2; if (IsUsingWoM && ConfigKey.WoMEnableEnvExtensions.Enabled() && !Heartbeat.ClassiCube()) { if (IP.Equals(IPAddress.Loopback)) { textLine2 = "cfg=localhost:" + Server.Port + "/" + newWorld.Name; } else { textLine2 = "cfg=" + Server.ExternalIP + ":" + Server.Port + "/" + newWorld.Name; } } else if (ClassiCube && ConfigKey.WoMEnableEnvExtensions.Enabled() && Heartbeat.ClassiCube()) { if (!newWorld.Hax) { textLine2 = "Loading world " + newWorld.ClassyName + "-hax"; } else { textLine2 = "Loading world " + newWorld.ClassyName; } } else { textLine2 = "Loading world " + newWorld.ClassyName; } if (RaisePlayerJoiningWorldEvent(this, newWorld, reason, textLine1, textLine2)) { Logger.Log(LogType.Warning, "Player.JoinWorldNow: Player {0} was prevented from joining world {1} by an event callback.", Name, newWorld.Name); return false; } World oldWorld = World; // remove player from the old world if (oldWorld != null && oldWorld != newWorld) { if (!oldWorld.ReleasePlayer(this)) { Logger.Log(LogType.Error, "Player.JoinWorldNow: Player asked to be released from its world, " + "but the world did not contain the player."); } } ResetVisibleEntities(); ClearLowPriotityOutputQueue(); Map map; // try to join the new world if (oldWorld != newWorld) { bool announce = (oldWorld != null) && (oldWorld.Name != newWorld.Name); map = newWorld.AcceptPlayer(this, announce); if (map == null) { return false; } } else { map = newWorld.LoadMap(); } World = newWorld; // Set spawn point if (doUseWorldSpawn) { Position = map.Spawn; } else { Position = postJoinPosition; } // Start sending over the level copy if (oldWorld != null) { SendNow(PacketWriter.MakeHandshake(this, textLine1, textLine2)); } writer.WriteMapBegin(); BytesSent++; // enable Nagle's algorithm (in case it was turned off by LowLatencyMode) // to avoid wasting bandwidth for map transfer client.NoDelay = false; // Fetch compressed map copy byte[] buffer = new byte[1024]; int mapBytesSent = 0; byte[] blockData; using (MemoryStream mapStream = new MemoryStream()) { map.GetCompressedCopy(mapStream, true); blockData = mapStream.ToArray(); } Logger.Log(LogType.Debug, "Player.JoinWorldNow: Sending compressed map ({0} bytes) to {1}.", blockData.Length, Name); // Transfer the map copy while (mapBytesSent < blockData.Length) { int chunkSize = blockData.Length - mapBytesSent; if (chunkSize > 1024) { chunkSize = 1024; } else { // CRC fix for ManicDigger for (int i = 0; i < buffer.Length; i++) { buffer[i] = 0; } } Array.Copy(blockData, mapBytesSent, buffer, 0, chunkSize); byte progress = (byte)(100 * mapBytesSent / blockData.Length); // write in chunks of 1024 bytes or less writer.WriteMapChunk(buffer, chunkSize, progress); BytesSent += 1028; mapBytesSent += chunkSize; } // Turn off Nagel's algorithm again for LowLatencyMode client.NoDelay = ConfigKey.LowLatencyMode.Enabled(); // Done sending over level copy writer.WriteMapEnd(map); BytesSent += 7; // Sets player's spawn point to map spawn writer.WriteAddEntity(255, this, map.Spawn); BytesSent += 74; // Teleport player to the target location // This allows preserving spawn rotation/look, and allows // teleporting player to a specific location (e.g. /TP or /Bring) writer.WriteTeleport(255, Position); BytesSent += 10; if (World.IsRealm && oldWorld == newWorld) { Message("Rejoined realm {0}", newWorld.ClassyName); } else if (World.IsRealm) { Message("Joined realm {0}", newWorld.ClassyName); if (World != WorldManager.MainWorld) { World.VisitCount++; } } if (!World.IsRealm && oldWorld == newWorld) { Message("Rejoined world {0}", newWorld.ClassyName); } else if (!World.IsRealm) { Message("Joined world {0}", newWorld.ClassyName); if (World != WorldManager.MainWorld) { World.VisitCount++; } } //revert game values if a player leaves a world RaisePlayerJoinedWorldEvent(this, oldWorld, reason); Info.tempDisplayedName = null; iName = null; GunMode = false; entityChanged = false; //FFA Info.isPlayingFFA = false; Info.gameDeathsFFA = 0; Info.gameKillsFFA = 0; //Infection Info.isPlayingInfection = false; Info.isInfected = false; //TDM Info.isPlayingTD = false; Info.isOnRedTeam = false; Info.isOnBlueTeam = false; Info.gameKills = 0; Info.gameDeaths = 0; //CTF Info.isPlayingCTF = false; Info.CTFRedTeam = false; Info.CTFBlueTeam = false; Info.CTFCaptures = 0; Info.CTFKills = 0; Info.hasRedFlag = false; Info.hasBlueFlag = false; Info.placingBlueFlag = false; Info.placingRedFlag = false; //reset all special messages Send(PacketWriter.MakeSpecialMessage((byte)100, "&f")); Send(PacketWriter.MakeSpecialMessage((byte)1, "&f")); Send(PacketWriter.MakeSpecialMessage((byte)2, "&f")); if (Heartbeat.ClassiCube() && ClassiCube) { //update mapedit values //Packet envSetMapAppearance = PacketWriter.MakeEnvSetMapAppearance(World.textureURL, World.sideBlock, World.edgeBlock, World.sideLevel); Packet sky = PacketWriter.MakeEnvSetColor((byte)0, World.SkyColorCC); Packet cloud = PacketWriter.MakeEnvSetColor((byte)1, World.CloudColorCC); Packet fog = PacketWriter.MakeEnvSetColor((byte)2, World.FogColorCC); Packet weather = PacketWriter.MakeEnvWeatherAppearance((byte)World.WeatherCC); Send(sky); Send(cloud); Send(fog); Send(weather); if (!World.Hax) { //Send(PacketWriter.MakeHackControl(1, 1, 1, 1, 1, -1)); Commented out until classicube clients support hax packet } //update bots foreach (Bot bot in Server.Bots) { if (bot.World == World) { Send(PacketWriter.MakeAddEntity(bot.ID, bot.Name, bot.Position)); if (bot.Model != "humanoid") { Send(PacketWriter.MakeChangeModel((byte)bot.ID, bot.Model)); } if (bot.Skin != "steve") { Send(PacketWriter.MakeExtAddEntity((byte)bot.ID, bot.Skin, bot.Skin)); } } } //update highlights if (oldWorld != null) { foreach (var highlightsToRemove in oldWorld.Highlights) { Send(PacketWriter.RemoveSelectionCuboid((byte)highlightsToRemove.Value.Item1)); } } foreach(var entry in World.Highlights) { Send(PacketWriter.MakeSelectionCuboid((byte)entry.Value.Item1, entry.Key, entry.Value.Item2, entry.Value.Item3, entry.Value.Item4, entry.Value.Item5)); } } // Done. Server.RequestGC(); return true; }
internal bool JoinWorldNow( [NotNull] World newWorld, bool doUseWorldSpawn, WorldChangeReason reason ) { if( newWorld == null ) throw new ArgumentNullException( "newWorld" ); if( !Enum.IsDefined( typeof( WorldChangeReason ), reason ) ) { throw new ArgumentOutOfRangeException( "reason" ); } if( Thread.CurrentThread != ioThread ) { throw new InvalidOperationException( "Player.JoinWorldNow may only be called from player's own thread. " + "Use Player.JoinWorld instead." ); } string textLine1 = ConfigKey.ServerName.GetString(); string textLine2; if( IsUsingWoM && ConfigKey.WoMEnableEnvExtensions.Enabled() ) { if( IP.Equals( IPAddress.Loopback ) ) { textLine2 = "cfg=localhost:" + Server.Port + "/" + newWorld.Name; } else { textLine2 = "cfg=" + Server.ExternalIP + ":" + Server.Port + "/" + newWorld.Name; } } else { textLine2 = "Loading world " + newWorld.ClassyName; } if( RaisePlayerJoiningWorldEvent( this, newWorld, reason, textLine1, textLine2 ) ) { Logger.Log( LogType.Warning, "Player.JoinWorldNow: Player {0} was prevented from joining world {1} by an event callback.", Name, newWorld.Name ); return false; } World oldWorld = World; // remove player from the old world if( oldWorld != null && oldWorld != newWorld ) { if( !oldWorld.ReleasePlayer( this ) ) { Logger.Log( LogType.Error, "Player.JoinWorldNow: Player asked to be released from its world, " + "but the world did not contain the player." ); } } ResetVisibleEntities(); ClearLowPriotityOutputQueue(); Map map; // try to join the new world if( oldWorld != newWorld ) { bool announce = (oldWorld != null) && (oldWorld.Name != newWorld.Name); map = newWorld.AcceptPlayer( this, announce ); if( map == null ) { return false; } } else { map = newWorld.LoadMap(); } World = newWorld; // Set spawn point if( doUseWorldSpawn ) { Position = map.Spawn; } else { Position = postJoinPosition; } // Start sending over the level copy if( oldWorld != null ) { SendNow( PacketWriter.MakeHandshake( this, textLine1, textLine2 ) ); } writer.WriteMapBegin(); BytesSent++; // enable Nagle's algorithm (in case it was turned off by LowLatencyMode) // to avoid wasting bandwidth for map transfer client.NoDelay = false; // Fetch compressed map copy byte[] buffer = new byte[1024]; int mapBytesSent = 0; byte[] blockData = map.GetCompressedCopy(); Logger.Log( LogType.Debug, "Player.JoinWorldNow: Sending compressed map ({0} bytes) to {1}.", blockData.Length, Name ); // Transfer the map copy while( mapBytesSent < blockData.Length ) { int chunkSize = blockData.Length - mapBytesSent; if( chunkSize > 1024 ) { chunkSize = 1024; } else { // CRC fix for ManicDigger for( int i = 0; i < buffer.Length; i++ ) { buffer[i] = 0; } } Array.Copy( blockData, mapBytesSent, buffer, 0, chunkSize ); byte progress = (byte)(100 * mapBytesSent / blockData.Length); // write in chunks of 1024 bytes or less writer.WriteMapChunk( buffer, chunkSize, progress ); BytesSent += 1028; mapBytesSent += chunkSize; } // Turn off Nagel's algorithm again for LowLatencyMode client.NoDelay = ConfigKey.LowLatencyMode.Enabled(); // Done sending over level copy writer.WriteMapEnd( map ); BytesSent += 7; // Sets player's spawn point to map spawn writer.WriteAddEntity( 255, this, map.Spawn ); BytesSent += 74; // Teleport player to the target location // This allows preserving spawn rotation/look, and allows // teleporting player to a specific location (e.g. /TP or /Bring) writer.WriteTeleport( 255, Position ); BytesSent += 10; if( oldWorld == newWorld ) { Message( "Rejoined world {0}", newWorld.ClassyName ); } else { Message( "Joined world {0}", newWorld.ClassyName ); string greeting = newWorld.Greeting; if( greeting != null ) { greeting = Server.ReplaceTextKeywords( this, greeting ); Message( "&R* {0}: {1}", newWorld.Name, greeting ); } } RaisePlayerJoinedWorldEvent( this, oldWorld, reason ); // Done. Server.RequestGC(); return true; }
public void JoinWorld( [NotNull] World newWorld, WorldChangeReason reason, Position position ) { if( newWorld == null ) throw new ArgumentNullException( "newWorld" ); if( !Enum.IsDefined( typeof( WorldChangeReason ), reason ) ) { throw new ArgumentOutOfRangeException( "reason" ); } lock( joinWorldLock ) { useWorldSpawn = false; postJoinPosition = position; forcedWorldToJoin = newWorld; worldChangeReason = reason; } }
public void JoinWorld( [NotNull] World newWorld, WorldChangeReason reason ) { if( newWorld == null ) throw new ArgumentNullException( "newWorld" ); lock( joinWorldLock ) { useWorldSpawn = true; postJoinPosition = Position.Zero; forcedWorldToJoin = newWorld; worldChangeReason = reason; } }
internal PlayerJoinedWorldEventArgs( [NotNull] Player player, [CanBeNull] World oldWorld, [NotNull] World newWorld, WorldChangeReason context ) { if( player == null ) throw new ArgumentNullException( "player" ); Player = player; OldWorld = oldWorld; NewWorld = newWorld; Context = context; }
static void RaisePlayerJoinedWorldEvent( Player player, World oldWorld, WorldChangeReason reason ) { var h = JoinedWorld; if( h != null ) h( null, new PlayerJoinedWorldEventArgs( player, oldWorld, player.World, reason ) ); }
internal bool JoinWorldNow([NotNull] World newWorld, bool doUseWorldSpawn, WorldChangeReason reason) { if (newWorld == null) throw new ArgumentNullException("newWorld"); if (!Enum.IsDefined(typeof(WorldChangeReason), reason)) { throw new ArgumentOutOfRangeException("reason"); } /*if (Thread.CurrentThread != ioThread) { throw new InvalidOperationException( "Player.JoinWorldNow may only be called from player's own thread. " + "Use Player.JoinWorld instead."); }*/ if (!StandingInPortal) { LastWorld = World; LastPosition = Position; } string textLine1 = "Loading world " + newWorld.ClassyName; string textLine2 = newWorld.MOTD ?? "Welcome!"; if (RaisePlayerJoiningWorldEvent(this, newWorld, reason, textLine1, textLine2)) { Logger.Log(LogType.Warning, "Player.JoinWorldNow: Player {0} was prevented from joining world {1} by an event callback.", Name, newWorld.Name); return false; } World oldWorld = World; // remove player from the old world if (oldWorld != null && oldWorld != newWorld) { if (!oldWorld.ReleasePlayer(this)) { Logger.Log(LogType.Error, "Player.JoinWorldNow: Player asked to be released from its world, " + "but the world did not contain the player."); } } ResetVisibleEntities(); ClearQueue(outputQueue); Map map; // try to join the new world if (oldWorld != newWorld) { bool announce = (oldWorld != null) && (oldWorld.Name != newWorld.Name); map = newWorld.AcceptPlayer(this, announce); if (map == null) return false; } else { map = newWorld.LoadMap(); } World = newWorld; // Set spawn point Position = doUseWorldSpawn ? map.Spawn : postJoinPosition; // Start sending over the level copy if (oldWorld != null) { SendNow(Packet.MakeHandshake(this, textLine1, textLine2)); } // needs to be sent before the client receives the map data if (Supports(CpeExtension.BlockDefinitions)) { BlockDefinition.SendGlobalDefinitions(this); } writer.Write(OpCode.MapBegin); BytesSent++; // enable Nagle's algorithm (in case it was turned off by LowLatencyMode) // to avoid wasting bandwidth for map transfer client.NoDelay = false; WriteWorldData(map); // Turn off Nagel's algorithm again for LowLatencyMode client.NoDelay = ConfigKey.LowLatencyMode.Enabled(); // Done sending over level copy writer.Write(OpCode.MapEnd); writer.Write((short)map.Width); writer.Write((short)map.Height); writer.Write((short)map.Length); BytesSent += 7; SendJoinCpeExtensions(); // Teleport player to the target location // This allows preserving spawn rotation/look, and allows // teleporting player to a specific location (e.g. /TP or /Bring) writer.Write(Packet.MakeTeleport(Packet.SelfId, Position).Bytes); BytesSent += 10; SendJoinMessage(oldWorld, newWorld); RaisePlayerJoinedWorldEvent(this, oldWorld, reason); Server.UpdateTabList(); Server.RequestGC(); return true; }
static void RaisePlayerJoinedWorldEvent( [NotNull] Player player, [CanBeNull] World oldWorld, [NotNull] World newWorld, WorldChangeReason reason ) { if( player == null ) throw new ArgumentNullException( "player" ); if( newWorld == null ) throw new ArgumentNullException( "newWorld" ); var h = JoinedWorld; if( h != null ) h( null, new PlayerJoinedWorldEventArgs( player, oldWorld, newWorld, reason ) ); }
private static void RaisePlayerJoinedWorldEvent(Player player, World oldWorld, WorldChangeReason reason) { var h = JoinedWorld; h?.Invoke(null, new PlayerJoinedWorldEventArgs(player, oldWorld, player.World, reason)); }
private static bool RaisePlayerJoiningWorldEvent([NotNull] Player player, [NotNull] World newWorld, WorldChangeReason reason, string textLine1, string textLine2) { if (player == null) { throw new ArgumentNullException(nameof(player)); } if (newWorld == null) { throw new ArgumentNullException(nameof(newWorld)); } var h = JoiningWorld; if (h == null) { return(false); } var e = new PlayerJoiningWorldEventArgs(player, player.World, newWorld, reason, textLine1, textLine2); h(null, e); return(e.Cancel); }
public PlayerJoinedWorldEventArgs( [NotNull] Player player, World oldWorld, World newWorld, WorldChangeReason reason ) { if( player == null ) throw new ArgumentNullException( "player" ); Player = player; OldWorld = oldWorld; NewWorld = newWorld; Reason = reason; }
static bool RaisePlayerJoiningWorldEvent( [NotNull] Player player, [NotNull] World newWorld, WorldChangeReason reason, string textLine1, string textLine2 ) { if( player == null ) throw new ArgumentNullException( "player" ); if( newWorld == null ) throw new ArgumentNullException( "newWorld" ); var h = JoiningWorld; if( h == null ) return false; var e = new PlayerJoiningWorldEventArgs( player, player.World, newWorld, reason, textLine1, textLine2 ); h( null, e ); return e.Cancel; }
internal PlayerJoiningWorldEventArgs( [NotNull] Player player, [CanBeNull] World oldWorld, [NotNull] World newWorld, WorldChangeReason context, string textLine1, string textLine2 ) { if( player == null ) throw new ArgumentNullException( "player" ); if( newWorld == null ) throw new ArgumentNullException( "newWorld" ); Player = player; OldWorld = oldWorld; NewWorld = newWorld; Context = context; TextLine1 = textLine1; TextLine2 = textLine2; }