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); }
static void server_PlayerLoggedIn(object sender, PlayerLogInEventArgs e) { if (e.Client.Entity.Inventory.Empty) { e.Client.Entity.Inventory.Hotbar[0] = new ItemStack(CobblestoneBlock.BlockId, 64); e.Client.Entity.Inventory.Hotbar[1] = new ItemStack(CobblestoneBlock.BlockId, 64); e.Client.Entity.Inventory.Hotbar[2] = new ItemStack(DirtBlock.BlockId, 32); } }
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(); }
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)); } }
private void SocketRecieveAsync(IAsyncResult result) { var client = (MinecraftClient)result.AsyncState; SocketError error; int length = client.Socket.EndReceive(result, out error) + client.RecieveBufferIndex; if (error != SocketError.Success || !client.Socket.Connected || length == client.RecieveBufferIndex) { if (error != SocketError.Success) Log("Socket error: " + error); client.IsDisconnected = true; } else { try { IEnumerable<Packet> packets = PacketReader.TryReadPackets(ref client, length); foreach (Packet packet in packets) packet.HandlePacket(this, client); if (!client.IsDisconnected) { client.Socket.BeginReceive(client.RecieveBuffer, client.RecieveBufferIndex, client.RecieveBuffer.Length - client.RecieveBufferIndex, SocketFlags.None, SocketRecieveAsync, client); } } catch (InvalidOperationException e) { client.IsDisconnected = true; Log("Disconnected client with protocol error. " + e.Message); } catch (NotImplementedException) { client.IsDisconnected = true; Log("Disconnected client using unsupported features."); } } if (client.IsDisconnected) { lock (Clients) { if (client.Socket.Connected) client.Socket.BeginDisconnect(false, null, null); if (client.KeepAliveTimer != null) client.KeepAliveTimer.Dispose(); if (client.IsLoggedIn) { foreach (MinecraftClient remainingClient in Clients) { if (remainingClient.IsLoggedIn) { remainingClient.SendPacket(new PlayerListItemPacket( client.Username, false, 0)); } } DefaultLevel.SavePlayer(client.Entity); var args = new PlayerLogInEventArgs(client); OnPlayerLoggedOut(args); if (!args.Handled) SendChat(client.Username + " logged out."); EntityManager.DespawnEntity(client.Entity); } Clients.Remove(client); } ProcessSendQueue(); } }
protected internal virtual void OnPlayerLoggedOut(PlayerLogInEventArgs e) { if (PlayerLoggedOut != null) PlayerLoggedOut(this, e); if (!e.Handled) SendChat(ChatColors.Yellow + e.Client.Username + " left the game."); }
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, DefaultLevel.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.Position.Z, client.Entity.Position.Y - 1.62, client.Entity.Yaw, client.Entity.Pitch, true)); // TODO: Move 1.62 somewhere else // Send entities EntityManager.SendClientEntities(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."); client.StartWorkers(); }
private void MinecraftServerOnPlayerLoggedOut(object sender, PlayerLogInEventArgs playerLogInEventArgs) { playerLogInEventArgs.Handled = true; MinecraftServer.SendChat(string.Format(SettingsProvider.Get<string>("chat.leave"), playerLogInEventArgs.Username)); }
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(ChatColors.Yellow + client.Username + " joined the game."); }
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)); }
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 OnPlayerLoggedOut (object s, PlayerLogInEventArgs e) { e.Handled = true; this.SendChat ("A player has left the game: " + e.Username); }
private void OnPlayerLoggedIn (object s, PlayerLogInEventArgs e) { e.Handled = true; this.SendChat ("A player has joined the game: " + e.Username); this.SendConsoleMessage (string.Format(e.Username + " has joined the server into world " + e.Client.World + " with gamemode " + e.Client.GameMode + ".")); e.Client.SendChat (string.Format("[MOTD] {0}", this.ingameMOTD)); }
private static void ServerOnPlayerLoggedOut(object sender, PlayerLogInEventArgs playerLogInEventArgs) { if (playerLogInEventArgs.Username == HostPlayerName) ExitReset.Set(); }
internal void LogInPlayer(MinecraftClient client) { client.IsLoggedIn = true; // Spawn player client.Entity = DefaultLevel.LoadPlayer(client.Username); client.Entity.Username = client.Username; client.Entity.InventoryChanged += Entity_InventoryChanged; EntityManager.SpawnEntity(DefaultWorld, client.Entity); client.SendPacket(new LoginPacket(client.Entity.Id, DefaultWorld.LevelType, DefaultLevel.GameMode, client.Entity.Dimension, this.Difficulty, MaxPlayers)); // Send initial chunks client.UpdateChunks(true); client.SendPacket(new PlayerPositionAndLookPacket( client.Entity.Position, client.Entity.Yaw, client.Entity.Pitch, true)); client.SendQueue.Last().OnPacketSent += (sender, e) => { client.ReadyToSpawn = true; }; // Send entities EntityManager.SendClientEntities(client); client.SendPacket(new SetWindowItemsPacket(0, client.Entity.Inventory)); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); client.SendPacket(new SpawnPositionPacket(client.Entity.SpawnPoint)); client.SendPacket(new TimeUpdatePacket(DefaultLevel.Time)); UpdatePlayerList(null); // Should also process send queue var args = new PlayerLogInEventArgs(client); OnPlayerLoggedIn(args); Log(client.Username + " logged in."); if (!args.Handled) SendChat(client.Username + " logged in."); }
protected internal virtual void OnPlayerLoggedOut(PlayerLogInEventArgs e) { if (PlayerLoggedOut != null) PlayerLoggedOut(this, e); }
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(string.Format(ChatColors.Yellow + "{0} left the game.", client.Username)); } client.Dispose(); } }