public Server() { ServerHash = Hash.MD5(Guid.NewGuid().ToByteArray()); UseOfficalAuthentication = Settings.Default.UseOfficalAuthentication; Clients = new Dictionary<int, Client>(); Rand = new Random(); Logger = new Logger(this, Settings.Default.LogFile); PluginManager = new PluginManager(this, Settings.Default.PluginFolder); Items = new ItemDb(Settings.Default.ItemsFile); Recipes = Recipe.FromFile(Settings.Default.RecipesFile); SmeltingRecipes = SmeltingRecipe.FromFile(Settings.Default.SmeltingRecipesFile); ClientCommandHandler = new ClientCommandHandler(); ServerCommandHandler = new ServerCommandHandler(); if (Settings.Default.IrcEnabled) InitializeIrc(); }
public Server() { ServerHash = Hash.MD5(Guid.NewGuid().ToByteArray()); UseOfficalAuthentication = Settings.Default.UseOfficalAuthentication; Clients = new ConcurrentDictionary<int, Client>(); Rand = new Random(); Logger = new Logger(this, Settings.Default.LogFile); PluginManager = new PluginManager(this, Settings.Default.PluginFolder); Items = new ItemDb(Settings.Default.ItemsFile); Recipes = Recipe.FromFile(Settings.Default.RecipesFile); SmeltingRecipes = SmeltingRecipe.FromFile(Settings.Default.SmeltingRecipesFile); ClientCommandHandler = new ClientCommandHandler(); ServerCommandHandler = new ServerCommandHandler(); if (Settings.Default.IrcEnabled) InitializeIrc(); _AcceptEventArgs = new SocketAsyncEventArgs(); _AcceptEventArgs.Completed += Accept_Completion; _Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); }
public Server() { ChraftConfig.Load(); BanSystem = new BanSystem(); BanSystem.LoadBansAndWhiteList(); ClientsConnectionSlots = 30; Packet.Role = StreamRole.Server; Rand = new Random(); UseOfficalAuthentication = ChraftConfig.UseOfficalAuthentication; ServerHash = GetRandomServerHash(); EncryptionEnabled = ChraftConfig.EncryptionEnabled; EnableUserSightRadius = ChraftConfig.EnableUserSightRadius; Clients = new ConcurrentDictionary<int, Client>(); AuthClients = new ConcurrentDictionary<int, Client>(); Logger = new Logger(this, ChraftConfig.LogFile); PluginLogger = new PluginLogger(Logger); PluginManager = new PluginManager(this, ChraftConfig.PluginFolder); Items = new ItemDb(ChraftConfig.ItemsFile); Recipes = Recipe.FromXmlFile(ChraftConfig.RecipesFile); SmeltingRecipes = SmeltingRecipe.FromFile(ChraftConfig.SmeltingRecipesFile); ClientCommandHandler = new ClientCommandHandler(); ServerCommandHandler = new ServerCommandHandler(); PacketMap.Initialize(); _AcceptEventArgs = new SocketAsyncEventArgs(); _AcceptEventArgs.Completed += Accept_Completion; _Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); for(int i = 0; i < 10; ++i) { MapChunkPacket.DeflaterPool.Push(new Deflater(5)); } PlayersToSave = new ConcurrentQueue<Client>(); PlayersToSavePostponed = new ConcurrentQueue<Client>(); _generators = new Dictionary<string, IChunkGenerator>(); ServerKey = PacketCryptography.GenerateKeyPair(); }
public Server() { ChraftConfig.Load(); ClientsConnectionSlots = 30; Packet.Role = StreamRole.Server; Rand = new Random(); ServerHash = GetRandomServerHash(); UseOfficalAuthentication = ChraftConfig.UseOfficalAuthentication; Clients = new ConcurrentDictionary<int, Client>(); AuthClients = new ConcurrentDictionary<int, Client>(); Logger = new Logger(this, ChraftConfig.LogFile); PluginManager = new PluginManager(this, ChraftConfig.PluginFolder); Items = new ItemDb(ChraftConfig.ItemsFile); Recipes = Recipe.FromXmlFile(ChraftConfig.RecipesFile); SmeltingRecipes = SmeltingRecipe.FromFile(ChraftConfig.SmeltingRecipesFile); ClientCommandHandler = new ClientCommandHandler(); ServerCommandHandler = new ServerCommandHandler(); if (ChraftConfig.IrcEnabled) InitializeIrc(); PacketMap.Initialize(); _AcceptEventArgs = new SocketAsyncEventArgs(); _AcceptEventArgs.Completed += Accept_Completion; _Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); for(int i = 0; i < 10; ++i) { MapChunkPacket.DeflaterPool.Push(new Deflater(5)); } PlayersToSave = new ConcurrentQueue<Client>(); PlayersToSavePostponed = new ConcurrentQueue<Client>(); }
public void Use(IClient iClient, string commandName, string[] tokens) { Client client = iClient as Client; if (tokens.Length == 0) { client.SendMessage("Use " + ChatColor.Teal + "/help build" + ChatColor.White + " for a list of building commands."); client.SendMessage("Use " + ChatColor.Teal + "/help mod" + ChatColor.White + " for a list of moderation commands."); client.SendMessage("Use " + ChatColor.Teal + "/help information" + ChatColor.White + " for a list of information commands."); client.SendMessage("Use " + ChatColor.Teal + "/help other" + ChatColor.White + " for a list of other commands."); client.SendMessage("Use " + ChatColor.Teal + "/help short" + ChatColor.White + " for a list of shortcuts."); } else if (tokens.Length > 0) { string message; switch (tokens[0].ToLower()) { case "build": message = (from IClientCommand c in ClientCommandHandler.GetCommands() where c.Type == CommandType.Build && client.Owner.CanUseCommand(c) select c).Aggregate("", (current, c) => current + (", " + c.Name)); if (message == "") { client.SendMessage(ChatColor.Red + "There are no commands of this type that you can use."); return; } message = message.Remove(0, 1); client.SendMessage(message); break; case "mod": message = (from IClientCommand c in ClientCommandHandler.GetCommands() where c.Type == CommandType.Mod && client.Owner.CanUseCommand(c) select c).Aggregate("", (current, c) => current + (", " + c.Name)); if (message == "") { client.SendMessage(ChatColor.Red + "There are no commands of this type that you can use."); return; } message = message.Remove(0, 1); client.SendMessage(message); break; case "information": case "info": message = (from IClientCommand c in ClientCommandHandler.GetCommands() where c.Type == CommandType.Information && client.Owner.CanUseCommand(c) select c).Aggregate("", (current, c) => current + (", " + c.Name)); if (message == "") { client.SendMessage(ChatColor.Red + "There are no commands of this type that you can use."); return; } message = message.Remove(0, 1); client.SendMessage(message); break; case "other": message = (from IClientCommand c in ClientCommandHandler.GetCommands() where c.Type == CommandType.Other && client.Owner.CanUseCommand(c) select c).Aggregate("", (current, c) => current + (", " + c.Name)); if (message == "") { client.SendMessage(ChatColor.Red + "There are no commands of this type that you can use."); return; } message = message.Remove(0, 1); client.SendMessage(message); break; case "short": message = (from IClientCommand c in ClientCommandHandler.GetCommands() where client.Owner.CanUseCommand(c) && !string.IsNullOrEmpty(c.Shortcut) select c).Aggregate("", (current, c) => current + (", " + c.Shortcut)); if (message == "") { client.SendMessage(ChatColor.Red + "There are no commands of this type that you can use."); return; } message = message.Remove(0, 1); client.SendMessage(message); break; default: IClientCommand cmd; try { cmd = ClientCommandHandler.Find(tokens[0]) as IClientCommand; } catch (MultipleCommandsMatchException e) { client.SendMessage(ChatColor.Red + "Multiple commands has been found:"); foreach (var s in e.Commands) { client.SendMessage(string.Format(" {0}{1}", ChatColor.Red, s)); } return; } catch (CommandNotFoundException e) { client.SendMessage(e.Message); return; } try { cmd.Help(client); client.SendMessage("Type: " + cmd.Type.ToString()); if (client.Owner.CanUseCommand(cmd)) { client.SendMessage(ChatColor.BrightGreen + "You can use this command."); } else { client.SendMessage(ChatColor.Red + "You cannot use this command."); } } catch (Exception e) { client.SendMessage("There was an error while accessing the help for this command."); client.Owner.Server.Logger.Log(e); } break; } } }