public static void ExecuteCommand(Server server, RemoteClient user, string text) { string name = text.Substring(1); if (string.IsNullOrEmpty(name)) return; var parameters = new string[0]; var userText = ""; if (name.Contains(" ")) { name = name.Remove(name.IndexOf(' ')); userText = text.Substring(text.IndexOf(' ') + 1); parameters = userText.Split(' '); } var command = GetCommand(name); if (command == null) { user.SendChat(ChatColors.Red + "That command was not found."); return; } if (!MayUseCommand(command, user, server)) { user.SendChat(ChatColors.Red + "You do not have permission to use that command."); return; } command.Execute(server, user, userText, parameters); }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { if (parameters.Length != 1) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help difficulty for more information."); return; } Difficulty value; int num; if (int.TryParse(text, out num)) { if (num < 0 || num > 3) { user.SendChat(ChatColors.Red + "Invalid difficulty specified."); return; } value = (Difficulty)num; } else { if (!Enum.TryParse<Difficulty>(text, true, out value)) { user.SendChat(ChatColors.Red + "Invalid difficulty specified."); return; } } //user.World.Difficulty = value; // TODO server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " sets difficulty of " + user.World.Name + " to " + value.ToString()); }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { bool add = false; var current = server.MinecraftServer.Level.Time; long? time = null; if (parameters.Length == 0) { user.SendChat("The current time is " + current + ", or " + LongToTimeString(current)); return; } if (parameters[0].ToLower() == "day") time = 0; else if (parameters[0].ToLower() == "night") time = 12000; else if (parameters[0].ToLower() == "noon") time = 6000; else if (parameters[0].ToLower() == "midnight") time = 18000; else { string timeString; if (parameters[0].ToLower() == "set" && parameters.Length > 1) timeString = parameters[1]; else if (parameters[0].ToLower() == "add" && parameters.Length > 1) { timeString = parameters[1]; add = true; } else timeString = parameters[0]; if (timeString.Contains(":")) { try { time = TimeStringToLong(timeString); } catch { } } else { long _time; if (long.TryParse(timeString, out _time)) time = _time; } if (add) time += current; } if (time == null) { user.SendChat(ChatColors.Red + "Invalid time specified."); return; } time = time.Value % 24000; server.MinecraftServer.Level.Time = time.Value; // TODO: Add event listener in Craft.Net server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " set the time in " + user.World.Name + " to " + time.Value + ", or " + LongToTimeString(time.Value)); }
public void SendClientEntities(RemoteClient client) { foreach (var entity in GetEntitiesInRange(client.Entity, MaxClientDistance)) { if (entity != client.Entity) client.TrackEntity(entity); } }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { if (parameters.Length != 1) { user.SendChat(ChatColors.Red + "Invalid parameters. Use /help op for more information."); return; } // TODO }
public PlayerManager(RemoteClient client, MinecraftServer server) { Client = client; Server = server; SendInventoryUpdates = true; client.Entity.PickUpItem += Entity_PickUpItem; client.Entity.Inventory.WindowChange += Inventory_WindowChange; client.PropertyChanged += client_PropertyChanged; }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { if (parameters.Length == 0) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help say for more information."); return; } var format = server.SettingsProvider.Get<string>("chat.broadcast.format"); server.MinecraftServer.SendChat(string.Format(format, text)); }
// TODO: Attempt to move these into Level proper public static void LoadPlayer(this Level level, RemoteClient client) { if (string.IsNullOrEmpty(level.BaseDirectory)) { CreateNewPlayer(level, client); return; } Directory.CreateDirectory(Path.Combine(level.BaseDirectory, "players")); if (File.Exists(Path.Combine(level.BaseDirectory, "players", client.Username + ".dat"))) { try { var file = new NbtFile(Path.Combine(level.BaseDirectory, "players", client.Username + ".dat")); // TODO: Consder trying to serialize this, maybe use AutoMapper? client.Entity = new PlayerEntity(client.Username); client.GameMode = (GameMode)file.RootTag["playerGameType"].IntValue; client.Entity.SelectedSlot = file.RootTag["SelectedItemSlot"].ShortValue; client.Entity.SpawnPoint = new Vector3( file.RootTag["SpawnX"].IntValue, file.RootTag["SpawnY"].IntValue, file.RootTag["SpawnZ"].IntValue); client.Entity.Food = (short)file.RootTag["foodLevel"].IntValue; client.Entity.FoodExhaustion = file.RootTag["foodExhaustionLevel"].FloatValue; client.Entity.FoodSaturation = file.RootTag["foodSaturationLevel"].FloatValue; client.Entity.Health = file.RootTag["Health"].ShortValue; foreach (var tag in (NbtList)file.RootTag["Inventory"]) { client.Entity.Inventory[Level.DataSlotToNetworkSlot(tag["Slot"].ByteValue)] = new ItemStack( tag["id"].ShortValue, (sbyte)tag["Count"].ByteValue, tag["Damage"].ShortValue, tag["tag"] as NbtCompound); } client.Entity.Position = new Vector3( file.RootTag["Pos"][0].DoubleValue, file.RootTag["Pos"][1].DoubleValue, file.RootTag["Pos"][2].DoubleValue); client.Entity.Yaw = file.RootTag["Rotation"][0].FloatValue; client.Entity.Pitch = file.RootTag["Rotation"][1].FloatValue; client.Entity.Velocity = new Vector3( file.RootTag["Motion"][0].DoubleValue, file.RootTag["Motion"][1].DoubleValue, file.RootTag["Motion"][2].DoubleValue); } catch { CreateNewPlayer(level, client); } } else CreateNewPlayer(level, client); }
public static bool MayUseCommand(Command command, RemoteClient user, Server server) { if (user is ConsoleClient) return true; var groups = server.GetUserGroups(user.Username); foreach (var group in groups) { if (command.AllowedGroups.Contains(group)) return true; } return false; }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { string player = user.Username; Vector3 target; if (parameters.Length < 1 || parameters.Length > 4) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help tp for more information."); return; } if (parameters.Length == 1) { var client = server.MinecraftServer.GetClient(parameters[0]); } }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { if (parameters.Length < 2) { user.SendChat(ChatColors.Red + "Insufficient parameters. Use \"/help tell\" for more information."); return; } var client = server.MinecraftServer.GetClient(parameters[0]); if (client == null) { user.SendChat(parameters[0] + " is not online."); return; } var format = server.SettingsProvider.Get<string>("chat.private.format"); client.SendChat(string.Format(format, user.Username, client.Username, text)); }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { if (parameters.Length != 1) { user.SendChat(ChatColors.Red + "Invalid parameters. Use /help op for more information."); return; } var groups = server.GetUserGroups(parameters[0]); if (!groups.Contains("server.op")) { user.SendChat(ChatColors.Red + "User is not an op."); return; } groups.Remove("server.op"); server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " removes " + parameters[0] + " from server.op group."); server.SetUserGroups(parameters[0], groups); }
public static void SavePlayer(this Level level, RemoteClient client) { if (string.IsNullOrEmpty(level.BaseDirectory)) return; try { Directory.CreateDirectory(Path.Combine(level.BaseDirectory, "players")); var file = new NbtFile(); file.RootTag.Add(new NbtInt("playerGameType", (int)client.GameMode)); file.RootTag.Add(new NbtShort("SelectedItemSlot", client.Entity.SelectedSlot)); file.RootTag.Add(new NbtInt("SpawnX", (int)client.Entity.SpawnPoint.X)); file.RootTag.Add(new NbtInt("SpawnY", (int)client.Entity.SpawnPoint.Y)); file.RootTag.Add(new NbtInt("SpawnZ", (int)client.Entity.SpawnPoint.Z)); file.RootTag.Add(new NbtInt("foodLevel", client.Entity.Food)); file.RootTag.Add(new NbtFloat("foodExhaustionLevel", client.Entity.FoodExhaustion)); file.RootTag.Add(new NbtFloat("foodSaturationLevel", client.Entity.FoodSaturation)); file.RootTag.Add(new NbtShort("Health", client.Entity.Health)); var inventory = new NbtList("Inventory", NbtTagType.Compound); var slots = client.Entity.Inventory.GetSlots(); for (int i = 0; i < slots.Length; i++) { var slot = (ItemStack)slots[i].Clone(); slot.Index = Level.NetworkSlotToDataSlot(i); if (!slot.Empty) inventory.Add(slot.ToNbt()); } file.RootTag.Add(inventory); var position = new NbtList("Pos", NbtTagType.Double); position.Add(new NbtDouble(client.Entity.Position.X)); position.Add(new NbtDouble(client.Entity.Position.Y)); position.Add(new NbtDouble(client.Entity.Position.Z)); file.RootTag.Add(position); var rotation = new NbtList("Rotation", NbtTagType.Float); rotation.Add(new NbtFloat(client.Entity.Yaw)); rotation.Add(new NbtFloat(client.Entity.Pitch)); file.RootTag.Add(rotation); var velocity = new NbtList("Motion", NbtTagType.Double); velocity.Add(new NbtDouble(client.Entity.Velocity.X)); velocity.Add(new NbtDouble(client.Entity.Velocity.Y)); velocity.Add(new NbtDouble(client.Entity.Velocity.Z)); file.RootTag.Add(velocity); file.SaveToFile(Path.Combine(level.BaseDirectory, "players", client.Username + ".dat"), NbtCompression.None); } catch { } // If exceptions happen here, the entire server dies }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { if (parameters.Length > 2 || parameters.Length == 0) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help speed for more information."); return; } if (parameters[0].ToLower() == "reset") { user.Entity.Abilities.WalkingSpeed = 12; user.Entity.Abilities.FlyingSpeed = 24; return; } string player = user.Username; int speed; if (parameters.Length == 2) { player = parameters[0]; if (!int.TryParse(parameters[1], out speed)) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help speed for more information."); return; } } else { if (!int.TryParse(parameters[0], out speed)) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help speed for more information."); return; } } var client = server.MinecraftServer.GetClient(player); if (client == null) { user.SendChat(ChatColors.Red + player + " is not online."); return; } client.Entity.Abilities.WalkingSpeed = (byte)speed; client.Entity.Abilities.FlyingSpeed = (byte)(speed * 2); }
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)); } }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { Server = server; if (parameters.Length != 0) { user.SendChat(ChatColors.Red + "Invalid parameters. Use /help repl for more information."); return; } if (ReplContext.Self != null) { user.SendChat(ChatColors.Red + ReplContext.Self.Username + " is currently in REPL mode. Only one user may be in REPL mode at a time."); // TODO: Upgrade Mono.CSharp to Mono 3.0 and support several REPLs at once return; } server.ChatMessage -= HandleChatMessage; server.ChatMessage += HandleChatMessage; server.MinecraftServer.PlayerLoggedOut += (s, e) => { if (Evaluators.ContainsKey(e.Username)) Evaluators.Remove(e.Username); ReplContext.Self = null; }; Evaluators[user.Username] = new Evaluator(new CompilerContext(new CompilerSettings(), new MinecraftReportPrinter(user))); Evaluators[user.Username].ReferenceAssembly(typeof(Server).Assembly); Evaluators[user.Username].ReferenceAssembly(typeof(MinecraftServer).Assembly); Evaluators[user.Username].ReferenceAssembly(typeof(Craft.Net.Networking.IPacket).Assembly); Evaluators[user.Username].ReferenceAssembly(typeof(World).Assembly); Evaluators[user.Username].ReferenceAssembly(typeof(IServer).Assembly); Evaluators[user.Username].InteractiveBaseClass = typeof(ReplContext); Evaluators[user.Username].Run("using Craft.Net"); Evaluators[user.Username].Run("using Craft.Net.Data"); Evaluators[user.Username].Run("using Craft.Net.Data.Blocks"); Evaluators[user.Username].Run("using Craft.Net.Data.Items"); Evaluators[user.Username].Run("using Craft.Net.Server"); Evaluators[user.Username].Run("using PartyCraft"); ReplContext.Self = user; ReplContext.Server = server; user.SendChat(ChatColors.Blue + "Entering C# Interactive Mode"); user.SendChat(ChatColors.Blue + "Use `Exit()` to exit REPL mode."); }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { string player = user.Username; GameMode gameMode; if (parameters.Length == 0 || parameters.Length > 2) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help gamemode for more information."); return; } int value; if (int.TryParse(parameters[0], out value)) { if (value < 0 || value > 2) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help gamemode for more information."); return; } gameMode = (GameMode)value; } else { if (!Enum.TryParse<GameMode>(parameters[0], true, out gameMode)) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help gamemode for more information."); return; } } if (parameters.Length == 2) player = parameters[1]; var client = server.MinecraftServer.GetClient(player); if (client == null) { user.SendChat(ChatColors.Red + player + " is not online."); // TODO: Set it anyway return; } client.GameMode = gameMode; server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " sets " + player + " to " + gameMode + " mode."); }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { string player = user.Username; int x = (int)user.Entity.Position.X; int y = (int)user.Entity.Position.Y; int z = (int)user.Entity.Position.Z; if (parameters.Length == 1) player = parameters[0]; else if (parameters.Length == 3) { if (!int.TryParse(parameters[0], out x) && !int.TryParse(parameters[1], out y) && !int.TryParse(parameters[2], out z)) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help spawnpoint for more information."); return; } } else if (parameters.Length == 4) { player = parameters[0]; if (!int.TryParse(parameters[1], out x) && !int.TryParse(parameters[2], out y) && !int.TryParse(parameters[3], out z)) { user.SendChat(ChatColors.Red + "Incorrect usage. Use /help spawnpoint for more information."); return; } } var client = server.MinecraftServer.GetClient(player); if (player == null) { user.SendChat(ChatColors.Red + player + " is not online."); // TODO: Set it anyway return; } client.Entity.SpawnPoint = new Vector3(x, y, z); server.SendChatToGroup("server.op", user.Username + " set " + player + " spawn point to " + client.Entity.SpawnPoint); }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { int page = -1; if (parameters.Length == 0) page = 1; if (parameters.Length > 1) { user.SendChat(ChatColors.Red + "Incorrect usage. Use \"/help\" for more information."); return; } if (page != -1 || int.TryParse(parameters[0], out page)) { page--; int pages = Commands.Count / CommandsPerPage; if (page >= pages) { user.SendChat(ChatColors.Red + "No further commands. Use \"/help\" for more information."); return; } user.SendChat(ChatColors.DarkGreen + "Command List (page " + (page + 1) + " of " + pages + ")"); foreach (var c in Commands.Skip(page * CommandsPerPage).Take(CommandsPerPage)) user.SendChat(ChatColors.DarkCyan + "/" + c.DefaultCommand); return; } var command = GetCommand(parameters[0]); if (command == null) { user.SendChat(ChatColors.Red + "Command not found."); return; } string[] lines = command.Documentation.Split('\n'); user.SendChat(ChatColors.DarkGreen + "Documentation for /" + command.DefaultCommand + ":"); foreach (var line in lines) user.SendChat(ChatColors.DarkCyan + line); if (!MayUseCommand(command, user, server)) user.SendChat(ChatColors.Red + "You are not permitted to use this command."); }
public void MoveClientToWorld(RemoteClient client, World world, Vector3? spawnPoint = null) { if (client.World == world) return; lock (client.LoadedChunks) client.PauseChunkUpdates = true; EntityManager.Despawn(client.Entity); while (client.KnownEntities.Any()) client.ForgetEntity(EntityManager.GetEntityById(client.KnownEntities[0])); EntityManager.Update(); EntityManager.SpawnEntity(world, client.Entity); client.UnloadAllChunks(); // TODO: Allow player to save their positions in each world if (spawnPoint == null) client.Entity.Position = world.WorldGenerator.SpawnPoint; else client.Entity.Position = spawnPoint.Value; client.UpdateChunks(true); 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)); EntityManager.SendClientEntities(client); lock (client.LoadedChunks) client.PauseChunkUpdates = false; }
public MinecraftReportPrinter(RemoteClient client) { Client = client; }
// TODO: CommandContext class public abstract void Execute(Server server, RemoteClient user, string text, params string[] parameters);
private void DoClientUpdates(RemoteClient client) { // Update keep alive, chunks, etc if (client.LastKeepAliveSent.AddSeconds(20) < DateTime.Now) { client.SendPacket(new KeepAlivePacket(MathHelper.Random.Next())); client.LastKeepAliveSent = DateTime.Now; // TODO: Confirm keep alive } if (client.BlockBreakStartTime != null) { byte progress = (byte)((DateTime.Now - client.BlockBreakStartTime.Value).TotalMilliseconds / client.BlockBreakStageTime); var knownClients = EntityManager.GetKnownClients(client.Entity); foreach (var c in knownClients) { c.SendPacket(new BlockBreakAnimationPacket(client.Entity.EntityId, client.ExpectedBlockToMine.X, client.ExpectedBlockToMine.Y, client.ExpectedBlockToMine.Z, progress)); } } if (NextChunkUpdate < DateTime.Now) // Once per second { // Update chunks if (client.Settings.ViewDistance < client.Settings.MaxViewDistance) { client.Settings.ViewDistance++; client.ForceUpdateChunksAsync(); } } }
private void HandlePacket(RemoteClient client, IPacket packet) { if (PacketHandlers[packet.Id] == null) return; //throw new InvalidOperationException("No packet handler registered for 0x" + packet.Id.ToString("X2")); PacketHandlers[packet.Id](client, this, packet); }
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 HandlePacket(RemoteClient client, IPacket packet) { if (!PacketHandlers.ContainsKey(packet.GetType())) return; //throw new InvalidOperationException("No packet handler registered for 0x" + packet.Id.ToString("X2")); PacketHandlers[packet.GetType()](client, this, packet); }
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(); } }
protected void AcceptClientAsync(IAsyncResult result) { lock (NetworkLock) { if (Listener == null) return; // Server shutting down var client = new RemoteClient(Listener.EndAcceptTcpClient(result)); client.NetworkStream = client.NetworkClient.GetStream(); client.NetworkManager = new NetworkManager(client.NetworkStream); Clients.Add(client); Listener.BeginAcceptTcpClient(AcceptClientAsync, null); } }
public ConnectionEstablishedEventArgs(RemoteClient client) { Client = client; PermitConnection = true; DisconnectReason = "You are banned."; }
/// <summary> /// Run when a plugin message is recieved. /// </summary> public abstract void MessageRecieved(RemoteClient client, byte[] data);
public override void Execute(Server server, RemoteClient user, string userText, params string[] parameters) { server.MinecraftServer.SendChat(string.Format(server.SettingsProvider.Get<string>("chat.self.format"), user.Username, userText)); }
public override void Execute(Server server, RemoteClient user, string text, params string[] parameters) { Process.GetCurrentProcess().Kill(); // TODO: Friendly kick message }