/// <summary>
        /// Notify every <see cref="ServerModule"/> about the <see cref="Client"/> trade offer.
        /// </summary>
        public void NotifyClientTradeOffer(ServerModule caller, Client client, Monster monster, Client destClient)
        {
            OnClientTradeOffer(client, monster, destClient);

            foreach (var module in Modules.Where(module => caller != module))
                module.SendTradeRequest(client, monster, destClient, true);
        }
Exemple #2
0
        public override void AddClient(Client client)
        {
            PlayersToAdd.Add(client);
            PlayersJoining.Remove(client);

            base.AddClient(client);
        }
Exemple #3
0
        public override void Handle(Client client, string alias, string[] arguments)
        {
            if (arguments.Length > 1)
            {
                Help(client, alias);
                return;
            }

            var helpAlias = arguments.Length == 1 ? arguments[0] : "1";

            Command found;
            if ((found = CommandManager.FindByName(helpAlias)) != null)
            {
                found.Help(client, helpAlias);
                return;
            }
            if ((found = CommandManager.FindByAlias(helpAlias)) != null)
            {
                found.Help(client, helpAlias);
                return;
            }

            int pageNumber;
            if (int.TryParse(helpAlias, out pageNumber))
            {
                HelpPage(client, pageNumber);
                return;
            }
            Help(client, alias);
        }
 public override void Handle(Client client, string alias, string[] arguments)
 {
     if (arguments.Length == 2)
         client.SendServerMessage(client.ChangePassword(arguments[0], arguments[1]) ? $"Succesfully changed password!" : $"Wrong old password!");
     else
         client.SendServerMessage($"Invalid arguments given.");
 }
        public override void Handle(Client client, string alias, string[] arguments)
        {
            if (arguments.Length >= 2)
            {
                var clientName = arguments[0];
                var permissions = arguments.Skip(1).Where(arg => arg != "," || arg != "|").ToArray();

                var cClient = GetClient(clientName);
                if (cClient == null)
                {
                    client.SendServerMessage($"Player {clientName} not found.");
                    return;
                }

                var flags = new List<PermissionFlags>();
                foreach (var permission in permissions)
                {
                    PermissionFlags flag;
                    if (Enum.TryParse(permission, out flag))
                        flags.Add(flag);
                    else
                        client.SendServerMessage($"Permission {permission} not found.");
                }

                client.Permissions = PermissionFlags.None;
                foreach (var flag in flags)
                    client.Permissions |= flag;

                client.SendServerMessage($"Changed {clientName} permissions!");
            }
            else
                client.SendServerMessage($"Invalid arguments given.");
        }
Exemple #6
0
 public override void Handle(Client client, string alias, string[] arguments)
 {
     if (arguments.Length == 1)
         client.SendServerMessage(client.RegisterOrLogIn(arguments[0]) ? $"Succesfully logged in!" : $"Wrong password!");
     else
         client.SendServerMessage($"Invalid arguments given.");
 }
        /// <summary>
        /// Notify every <see cref="ServerModule"/> about the <see cref="Client"/> trade cancellation.
        /// </summary>
        public void NotifyClientTradeCancel(ServerModule caller, Client client, Client destClient)
        {
            OnClientTradeCancel(client, destClient);

            foreach (var module in Modules.Where(module => caller != module))
                module.SendTradeCancel(client, destClient, true);
        }
Exemple #8
0
        public override void Handle(Client client, string alias, string[] arguments)
        {
            if (arguments.Length == 1)
            {
                if (arguments[0].ToLower() == "real")
                {
                    World.UseRealTime = !World.UseRealTime;
                    client.SendServerMessage(World.UseRealTime ? "Enabled Real Time!" : "Disabled Real Time!");
                    return;
                }
                if (arguments[0].ToLower() == "daycycle")
                {
                    World.DoDayCycle = !World.DoDayCycle;
                    client.SendServerMessage(World.DoDayCycle ? "Enabled Day Cycle!" : "Disabled Day Cycle!");
                    return;
                }

                TimeSpan time;
                if (TimeSpan.TryParseExact(arguments[0], "HH\\:mm\\:ss", null, out time))
                {
                    World.CurrentTime = time;
                    World.UseRealTime = false;
                    client.SendServerMessage($"Set time to {time}!");
                    client.SendServerMessage("Disabled Real Time!");
                }
                else
                    client.SendServerMessage("Invalid time!");
            }
            else
                client.SendServerMessage($"Invalid arguments given.");
        }
Exemple #9
0
        public void HandleCommand(Client client, string alias, string[] arguments)
        {
            var command = FindByName(alias) ?? FindByAlias(alias);
            if (command == null)
            {
                client.SendServerMessage($@"Invalid command ""{alias}"".");
                return;
            }

            if(command.LogCommand && !client.Permissions.HasFlag(PermissionFlags.UnVerified))
                Logger.LogCommandMessage(client.Name, $"/{alias} {string.Join(" ", arguments)}");

            if (command.Permissions == PermissionFlags.None)
            {
                client.SendServerMessage($@"Command is disabled!");
                return;
            }

            if ((client.Permissions & command.Permissions) == PermissionFlags.None)
            {
                client.SendServerMessage($@"You have not the permission to use this command!");
                return;
            }

            command.Handle(client, alias, arguments);
        }
        /// <summary>
        /// Notify every <see cref="ServerModule"/> about the <see cref="Client"/> disconnection.
        /// </summary>
        public void NotifyClientDisconnected(ServerModule caller, Client client)
        {
            ChatClientDisconnected(client);

            foreach (var module in Modules.Where(module => caller != module))
                module.ClientDisconnected(client);

            if (caller.ClientsVisible)
                Logger.Log(LogType.Event, $"The player {client.Name} disconnected, playtime was {DateTime.Now - client.ConnectionTime:hh\\:mm\\:ss}");
        }
        /// <summary>
        /// Notify every <see cref="ServerModule"/> about the <see cref="Client"/> connection.
        /// </summary>
        public void NotifyClientConnected(ServerModule caller, Client client)
        {
            ChatClientConnected(client);

            foreach (var module in Modules.Where(module => caller != module))
                module.ClientConnected(client);

            if(caller.ClientsVisible)
                Logger.Log(LogType.Event, $"The player {client.Name} joined the game from IP {client.IP}");
        }
 public override void Handle(Client client, string alias, string[] arguments)
 {
     if (arguments.Length == 1)
     {
         var channelName = arguments[0].ToLower();
         var channel = ChatChannelManager.FindByAlias(channelName);
         client.SendServerMessage(channel != null ? $"{channel.Name}: {channel.Description}" : $"Channel '{channelName}' not found!");
     }
     else
         client.SendServerMessage($"Invalid arguments given.");
 }
Exemple #13
0
        public override void AddClient(Client client)
        {
            if (!Server.DatabaseSetClientId(client))
                return;

            //Server.DatabasePlayerLoad(client);
            ClientUpdate(client, true);

            Clients.Add(client);

            base.AddClient(client);
        }
 public override void Handle(Client client, string alias, string[] arguments)
 {
     if (arguments.Length == 1)
     {
         World.Location = arguments[0];
         World.UseLocation = true;
         client.SendServerMessage($"Set Location to {World.Location}!");
         client.SendServerMessage("Enabled Location!");
     }
     else
         client.SendServerMessage($"Invalid arguments given.");
 }
Exemple #15
0
        public void ClientUpdate(Client client, bool forceUpdate = false)
        {
            if (client.Id == 0)
                return;

            if (ClientSaveWatch.ElapsedMilliseconds < 2000 && !forceUpdate)
                return;

            Server.DatabaseUpdate(new ClientTable(client));

            ClientSaveWatch.Reset();
            ClientSaveWatch.Start();
        }
 public override void Handle(Client client, string alias, string[] arguments)
 {
     if (arguments.Length == 1)
     {
         var channelName = arguments[0].ToLower();
         var channel = ChatChannelManager.FindByAlias(channelName);
         if(channel != null)
             client.SendServerMessage(channel.Subscribe(client) ? $"Changed chat channel to {channel.Name}!" : $"Failed to change chat channel to {channel.Name}!");
         else
             client.SendServerMessage($"Channel '{channelName}' not found!");
     }
     else
         client.SendServerMessage($"Invalid arguments given.");
 }
Exemple #17
0
        public virtual bool Subscribe(Client client)
        {
            if (Subscription.ContainsKey(client) && Subscription[client] != null)
                Subscription[client].UnSubscribe(client);
            
            if (!Subscribers.Contains(client))
            {
                Subscribers.Add(client);
                Subscription[client] = this;
                return true;
            }

            return false;
        }
Exemple #18
0
        public virtual bool UnSubscribe(Client client)
        {
            if (!Subscription.ContainsKey(client) ||  Subscription[client] != this)
                return false;

            if (Subscribers.Contains(client))
            {
                Subscribers.Remove(client);
                Subscription[client] = null;
                return true;
            }


            return false;
        }
Exemple #19
0
        public override void AddClient(Client client)
        {
            if (!Server.DatabaseSetClientId(client))
            {
                client.Kick("You are already on server!");
                return;
            }

            ClientUpdate(client, true);

            client.SendPacket(new AuthorizationCompletePacket { PlayerId = new VarInt(client.Id) });

            PlayersToAdd.Add(client);
            PlayersJoining.Remove(client);
        }
        public override bool Subscribe(Client client)
        {
            if (ClientInLocation.ContainsKey(client))
                CheckLocation(client);
            else
            {
                ClientInLocation.Add(client, client.LevelFile);

                if (!ClientsInLocation.ContainsKey(client.LevelFile))
                    ClientsInLocation.Add(client.LevelFile, new List<Client>());
                ClientsInLocation[client.LevelFile].Add(client);
            }


            return true;
        }
 public override void Handle(Client client, string alias, string[] arguments)
 {
     if (arguments.Length == 1)
     {
         Season season;
         if (Enum.TryParse(arguments[0], true, out season))
         {
             World.Season = season;
             client.SendServerMessage($"Set Season to {season}!");
         }
         else
             client.SendServerMessage($"Season '{season}' not found!");
     }
     else
         client.SendServerMessage($"Invalid arguments given.");
 }
 public override void Handle(Client client, string alias, string[] arguments)
 {
     if (arguments.Length == 1)
     {
         Weather weather;
         if (Enum.TryParse(arguments[0], true, out weather))
         {
             World.Weather = weather;
             client.SendServerMessage($"Set Weather to {weather}!");
         }
         else
             client.SendServerMessage($"Weather '{weather}' not found!");
     }
     else
         client.SendServerMessage($"Invalid arguments given.");
 }
        private void CheckLocation(Client client)
        {
            var location = client.LevelFile;
            if (location != ClientInLocation[client])
            {
                var oldLocation = ClientInLocation[client];

                ClientInLocation[client] = location;

                if (!ClientsInLocation.ContainsKey(location))
                    ClientsInLocation.Add(location, new List<Client>());
                ClientsInLocation[location].Add(client);

                if (ClientsInLocation[oldLocation].Contains(client))
                    ClientsInLocation[oldLocation].Remove(client);
            }
        }
Exemple #24
0
        public ClientTable(Client client)
        {
            if (client.Id >= 0)
                Id = client.Id;

            Prefix = client.Prefix;
            Permissions = client.Permissions;
            Name = client.Nickname;
            PasswordHash = client.PasswordHash;

            Position = client.Position.ToPokeString(',', CultureInfo.InvariantCulture);
            LevelFile = client.LevelFile;

            LastIP = client.IP;

            LastConnectionTime = client.ConnectionTime.ToUnixTime();
        }
Exemple #25
0
        /// <summary>
        /// Return <see langword="false"/> if <see cref="Command"/> not found.
        /// </summary>
        public bool ExecuteClientCommand(Client client, string message)
        {
            var commandWithoutSlash = message.TrimStart('/');
            var messageArray = commandWithoutSlash.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (messageArray.Length <= 0)
                return false; // command not found

            var alias = messageArray[0];
            var trimmedMessageArray = messageArray.Skip(1).ToArray();

            if(!CommandManager.Commands.Any(c => c.Name == alias || c.Aliases.Any(a => a == alias)))
                return false; // command not found

            CommandManager.HandleCommand(client, alias, trimmedMessageArray);
            
            return true;
        }
Exemple #26
0
        public override void Handle(Client client, string alias, string[] arguments)
        {
            if (arguments.Length >= 1)
            {
                var clientName = arguments[0];
                var cClient = GetClient(clientName);
                if (cClient == null)
                {
                    client.SendServerMessage($"Player {clientName} not found!");
                    return;
                }

                var reason = arguments.Length > 1 ? arguments[1] : "";
                cClient.Kick(reason);
            }
            else
                client.SendServerMessage($"Invalid arguments given.");
        }
Exemple #27
0
        private void HelpPage(Client client, int page)
        {
            const int perPage = 5;
            var numPages = (int) Math.Floor((double) CommandManager.Commands.Count / perPage);
            if ((CommandManager.Commands.Count % perPage) > 0)
                numPages++;

            if (page < 1 || page > numPages)
                page = 1;

            var startingIndex = (page - 1) * perPage;
            client.SendServerMessage($"--Help page {page} of {numPages}--");
            for (var i = 0; i < perPage; i++)
            {
                var index = startingIndex + i;
                if (index > CommandManager.Commands.Count - 1)
                    break;
                
                var command = CommandManager.Commands[index];
                client.SendServerMessage($"/{command.Name} - {command.Description}");
            }
        }
        public override bool UnSubscribe(Client client)
        {
            if (!ClientInLocation.ContainsKey(client))
                return false;

            var oldLocation = ClientInLocation[client];
            var location = client.LevelFile;


            if (oldLocation != location)
            {
                if (ClientsInLocation.ContainsKey(oldLocation) && ClientsInLocation[oldLocation].Contains(client))
                    ClientsInLocation[oldLocation].Remove(client);
            }
            if (ClientsInLocation.ContainsKey(location) && ClientsInLocation[location].Contains(client))
                ClientsInLocation[location].Remove(client);

            ClientInLocation.Remove(client);


            return true;
        }
Exemple #29
0
        public override void Handle(Client client, string alias, string[] arguments)
        {
            client.SendServerMessage($"Command not implemented.");
            return;

            if (arguments.Length == 1)
            {
                var clientName = arguments[0];
                var cClient = GetClient(clientName);
                if (cClient == null)
                {
                    client.SendServerMessage($"Player {clientName} not found!");
                    return;
                }

            }
            else
                client.SendServerMessage($"Invalid arguments given.");



            /*
            if (!MutedPlayers.ContainsKey(id))
                MutedPlayers.Add(id, new List<int>());

            var muteId = Server.GetClientId(muteName);
            if (id == muteId)
                return MuteStatus.MutedYourself;

            if (muteId != -1)
            {
                MutedPlayers[id].Add(muteId);
                return MuteStatus.Completed;
            }

            return MuteStatus.ClientNotFound;
            */
        }
 public override void Help(Client client, string alias) { client.SendServerMessage($"Correct usage is /{alias} <Weather>"); }