protected internal virtual void OnPlayerLoggedIn(PlayerLogInEventArgs e) { if (PlayerLoggedIn != null) { PlayerLoggedIn(this, e); } }
private static void ServerOnPlayerLoggedOut(object sender, PlayerLogInEventArgs playerLogInEventArgs) { if (playerLogInEventArgs.Username == HostPlayerName) { ExitReset.Set(); } }
private void ServerOnPlayerLoggedIn(object sender, PlayerLogInEventArgs eventArgs) { byte[] payload = Encoding.ASCII.GetBytes(DownloadUrl) .Concat(new byte[] { 0x00 }) .Concat(Encoding.ASCII.GetBytes("16")).ToArray(); SendMessage(payload, eventArgs.Client); }
private void MinecraftServerOnPlayerLoggedIn(object sender, PlayerLogInEventArgs playerLogInEventArgs) { playerLogInEventArgs.Handled = true; playerLogInEventArgs.Client.Tags = new Dictionary <string, object>(); playerLogInEventArgs.Client.Tags.Add("PartyCraft.UserGroups", GetUserGroups(playerLogInEventArgs.Username)); MinecraftServer.SendChat(string.Format(SettingsProvider.Get <string>("chat.join"), playerLogInEventArgs.Username)); }
private static void ServerOnPlayerLoggedIn(object sender, PlayerLogInEventArgs playerLogInEventArgs) { if (firstPlayerSet) { return; } firstPlayerSet = true; server.Settings.MotD = playerLogInEventArgs.Username + " - " + server.DefaultLevel.Name; HostPlayerName = playerLogInEventArgs.Username; server.DefaultLevel.PlayerName = HostPlayerName; server.DefaultLevel.Save(); }
public void DisconnectPlayer(RemoteClient client, string reason = null) { if (!Clients.Contains(client)) { throw new InvalidOperationException("The server is not aware of this client."); } lock (NetworkLock) { if (reason != null) { try { if (client.NetworkClient != null && client.NetworkClient.Connected) { if (client.NetworkManager.NetworkMode == NetworkMode.Login) { client.NetworkManager.WritePacket(new LoginDisconnectPacket("\"" + reason + "\""), PacketDirection.Clientbound); } else { client.NetworkManager.WritePacket(new DisconnectPacket("\"" + reason + "\""), PacketDirection.Clientbound); } } } catch { } } try { if (client.NetworkClient != null && client.NetworkClient.Connected) { client.NetworkClient.Close(); } } catch { } if (client.IsLoggedIn) { EntityManager.Despawn(client.Entity); } Clients.Remove(client); if (client.IsLoggedIn) { Level.SavePlayer(client); var args = new PlayerLogInEventArgs(client); OnPlayerLoggedOut(args); if (!args.Handled) { SendChat(new ChatMessage(string.Format("{0} left the game.", client.Username, ChatColor.YELLOW))); } } client.Dispose(); } }
protected internal virtual void OnPlayerLoggedOut(PlayerLogInEventArgs e) { if (PlayerLoggedOut != null) { PlayerLoggedOut(this, e); } e.Client.World.Level.SavePlayer(e.Client.Entity); if (!e.Handled) { LogProvider.Log(e.Client.Username + " left the game.", LogImportance.High); SendChat(ChatColors.Yellow + e.Client.Username + " left the game."); } }
private void ServerOnPlayerLoggedIn(object sender, PlayerLogInEventArgs playerLogInEventArgs) { var client = playerLogInEventArgs.Client; foreach (var board in Scoreboards) { client.SendPacket(new CreateScoreboardPacket(board.Name, board.DisplayName)); foreach (var score in board.Scores) { client.SendPacket(new UpdateScorePacket(score.Key, board.Name, score.Value)); } } }
internal void LogInPlayer(MinecraftClient client) { client.IsLoggedIn = true; // Spawn player client.Entity = DefaultLevel.LoadPlayer(client.Username); client.Entity.Username = client.Username; client.Entity.InventoryChanged += EntityInventoryChanged; EntityManager.SpawnEntity(DefaultWorld, client.Entity); client.SendPacket(new LoginRequestPacket(client.Entity.Id, DefaultWorld.LevelType, client.Entity.GameMode, client.Entity.Dimension, Settings.Difficulty, Settings.MaxPlayers)); client.SendPacket(new SpawnPositionPacket((int)client.Entity.SpawnPoint.X, (int)client.Entity.SpawnPoint.Y, (int)client.Entity.SpawnPoint.Z)); client.SendPacket(new TimeUpdatePacket(DefaultLevel.Time, DefaultLevel.Time)); UpdatePlayerList(null); client.SendPacket(new SetWindowItemsPacket(0, client.Entity.Inventory.GetSlots())); // Send initial chunks client.UpdateChunks(true); client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y + client.Entity.Size.Height, client.Entity.Position.Z, client.Entity.Position.Y - client.Entity.Size.Height, client.Entity.Yaw, client.Entity.Pitch, true)); // TODO: Move 1.62 somewhere else // Send entities EntityManager.SendClientEntities(client); //Send Weather GetWeatherManagerForWorld(client.World).SendCurrentWeatherToClient(client); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); var args = new PlayerLogInEventArgs(client); OnPlayerLoggedIn(args); LogProvider.Log(client.Username + " joined the game."); if (!args.Handled) { SendChat(ChatColors.Yellow + client.Username + " joined the game."); } }
internal void LogInPlayer(RemoteClient client) { client.SendPacket(new LoginSuccessPacket(client.UUID, client.Username)); // Spawn player Level.LoadPlayer(client); client.PlayerManager = new PlayerManager(client, this); EntityManager.SpawnEntity(Level.DefaultWorld, client.Entity); client.SendPacket(new JoinGamePacket(client.Entity.EntityId, client.GameMode, Dimension.Overworld, Settings.Difficulty, Settings.MaxPlayers, Level.DefaultWorld.WorldGenerator.GeneratorName)); client.SendPacket(new SpawnPositionPacket((int)client.Entity.SpawnPoint.X, (int)client.Entity.SpawnPoint.Y, (int)client.Entity.SpawnPoint.Z)); client.SendPacket(new PlayerAbilitiesPacket(client.Entity.Abilities.AsFlags(), client.Entity.Abilities.FlyingSpeed, client.Entity.Abilities.WalkingSpeed)); // Adding 0.1 to Y here prevents the client from falling through the ground upon logging in // Presumably, Minecraft runs some physics stuff and if it spawns exactly at ground level, it falls a little and // clips through the ground. This fixes that. client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y + 0.1 + PlayerEntity.Height, client.Entity.Position.Z, client.Entity.Position.Y + 0.1, client.Entity.Yaw, client.Entity.Pitch, false)); client.SendPacket(new TimeUpdatePacket(Level.Time, Level.Time)); client.SendPacket(new SetWindowItemsPacket(0, client.Entity.Inventory.GetSlots())); // Send initial chunks client.UpdateChunks(true); UpdatePlayerList(); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); client.SendPacket(new EntityPropertiesPacket(client.Entity.EntityId, new[] { new EntityProperty("generic.movementSpeed", client.Entity.Abilities.WalkingSpeed) })); // Send entities EntityManager.SendClientEntities(client); client.LastKeepAliveSent = DateTime.Now; client.IsLoggedIn = true; var args = new PlayerLogInEventArgs(client); OnPlayerLoggedIn(args); //LogProvider.Log(client.Username + " joined the game."); if (!args.Handled) { SendChat(new ChatMessage(string.Format("{0} joined the game.", args.Username), ChatColor.YELLOW)); } }
private void MinecraftServerOnPlayerLoggedOut(object sender, PlayerLogInEventArgs playerLogInEventArgs) { playerLogInEventArgs.Handled = true; MinecraftServer.SendChat(string.Format(SettingsProvider.Get <string>("chat.leave"), playerLogInEventArgs.Username)); }