Ejemplo n.º 1
0
        public Boolean isUserConnected(String token)
        {
            if (OnlineUsers.ContainsKey(token))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// User whisper is user is not muted
        /// </summary>
        void UserWhisper(OnlineUser user, CommandPacket command)
        {
            User backendUser = Users[user.Username];
            var  arguments   = command.arguments;

            if (arguments.Count != 2)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_arguments_error"]
                    .Replace("$COUNT$", "2")
                    );
                return;
            }
            else if (!OnlineUsers.ContainsKey(arguments[0]))
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_tell_targetOffline"]
                    .Replace("$NAME$", arguments[0])
                    );
                return;
            }
            else if (backendUser.muteTime > DateTime.Now)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["user_muted"]
                    );
                return;
            }
            WhisperMessage(user, OnlineUsers[arguments[0]], arguments[1]);
            ServerMessage("server", user, $"\\8rYou -> \"{Users[arguments[0]].nickname}\\8r\"\\rr: {arguments[1]}");
            Info($"\\8r<{backendUser.nickname}\\8r> -> <{Users[arguments[0]].nickname}\\8r> \\rr{arguments[1]}");
        }
Ejemplo n.º 3
0
        public void disconnectClient(String token)
        {
            if (OnlineUsers.ContainsKey(token))
            {
                Client clientRemoved;
                OnlineUsers.TryRemove(token, out clientRemoved);
                Console.WriteLine("[UserManager] Client disconnected!");

                try
                {
                    PresencePacket p = new PresencePacket();
                    p.connected = false;
                    p.name      = getUsernameFromToken(token);
                    foreach (KeyValuePair <String, Client> entry in OnlineUsers)
                    {
                        entry.Value.SendPacket(p);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Unset admin
        /// </summary>
        void AdminUnsetAdmin(OnlineUser user, CommandPacket command)
        {
            User backendUser = Users[user.Username];
            var  arguments   = command.arguments;

            //  Permission check
            if (backendUser.permissionLevel < 2)
            {
                PermissionDeniedMessage(user);
                return;
            }
            //  Syntax check
            if (arguments.Count != 1)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_arguments_error"]
                    .Replace("$COUNT$", "1")
                    );
                return;
            }
            //  Check if the user is exist
            if (!Users.ContainsKey(arguments[0]))
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_userNotExist"]
                    .Replace("$NAME$", arguments[0])
                    );
                return;
            }
            //  Check permission level
            User target = Users[arguments[0]];

            if (target.permissionLevel == 0)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_unsetadmin_notAdmin"]
                    .Replace("$NICK$", target.nickname)
                    .Replace("$NAME$", target.username)
                    );
                return;
            }
            //  Check permission level
            if (target.permissionLevel >= backendUser.permissionLevel)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_higherPermission"]
                    .Replace("$NICK$", target.nickname)
                    .Replace("$NAME$", target.username)
                    );
                return;
            }

            Users[arguments[0]].permissionLevel = 0;
            Info(
                $"{backendUser.nickname}\\rr({backendUser.username}\\rr)" +
                $" dismissed {target.nickname}\\rr({target.username}\\rr)" +
                " from the server administrator position."
                );
            Broadcast(
                "server",
                langFile["command_unsetadmin_broadcast"]
                .Replace("$NICK$", target.nickname)
                .Replace("$NAME$", target.username)
                );
            if (OnlineUsers.ContainsKey(arguments[0]))
            {
                ServerMessage(
                    "server",
                    OnlineUsers[arguments[0]],
                    langFile["command_unsetadmin_message"]
                    );
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Admin mute user
        /// </summary>
        void AdminMute(OnlineUser user, CommandPacket command)
        {
            User backendUser = Users[user.Username];
            var  arguments   = command.arguments;

            //  Permission check
            if (backendUser.permissionLevel < 1)
            {
                PermissionDeniedMessage(user);
                return;
            }
            //  Syntax check
            if (arguments.Count != 2)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_arguments_error"]
                    .Replace("$COUNT$", "2")
                    );
                return;
            }
            //  Check if the user is exist
            if (!Users.ContainsKey(arguments[0]))
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_userNotExist"]
                    .Replace("$NAME$", arguments[0])
                    );
                return;
            }
            //  Check permission level
            User target = Users[arguments[0]];

            if (target.permissionLevel >= backendUser.permissionLevel)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_higherPermission"]
                    .Replace("$NICK$", target.nickname)
                    .Replace("$NAME$", target.username)
                    );
                return;
            }
            //  Convert time
            DateTime time;

            if (!TypeConvert.TryGetTime(arguments[1], out time))
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_invalidTimeFormat"]
                    );
                return;
            }
            //  Calculate time
            DateTime untilTime = DateTime.Now.AddTicks(time.Ticks);

            target.muteTime = untilTime;
            Info(
                $"{backendUser.nickname}\\rr({backendUser.username}\\rr)" +
                $" muted {target.nickname}\\rr({target.username}\\rr)."
                );
            Broadcast(
                "server",
                langFile["command_mute_broadcast"]
                .Replace("$NICK$", target.nickname)
                .Replace("$NAME$", target.username)
                .Replace("$TIME$", untilTime.ToString("yyyy/MM/dd HH:mm:ss"))
                );
            if (OnlineUsers.ContainsKey(arguments[0]))
            {
                ServerMessage(
                    "server",
                    OnlineUsers[arguments[0]],
                    langFile["command_mute_message"]
                    .Replace("$TIME$", untilTime.ToString("yyyy/MM/dd HH:mm:ss"))
                    );
            }
        }
Ejemplo n.º 6
0
        void AdminUnmute(OnlineUser user, CommandPacket command)
        {
            User backendUser = Users[user.Username];
            var  arguments   = command.arguments;

            //  Permission check
            if (backendUser.permissionLevel < 1)
            {
                PermissionDeniedMessage(user);
                return;
            }
            //  Syntax check
            if (arguments.Count != 1)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_arguments_error"]
                    .Replace("$COUNT$", "1")
                    );
                return;
            }
            //  Check if the user is exist
            if (!Users.ContainsKey(arguments[0]))
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_userNotExist"]
                    .Replace("$NAME$", arguments[0])
                    );
                return;
            }
            //  Check permission level
            User target = Users[arguments[0]];

            if (target.permissionLevel >= backendUser.permissionLevel)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_higherPermission"]
                    .Replace("$NICK$", target.nickname)
                    .Replace("$NAME$", target.username)
                    );
                return;
            }
            //  Check if is unmutable
            if (target.muteTime < DateTime.Now)
            {
                ServerMessage(
                    "server",
                    user,
                    langFile["command_unmute_notMuted"]
                    .Replace("$NICK$", target.nickname)
                    .Replace("$NAME$", target.username)
                    );
                return;
            }

            target.muteTime = DateTime.MinValue;
            Info(
                $"{backendUser.nickname}\\rr({backendUser.username}\\rr)" +
                $" unmuted {target.nickname}\\rr({target.username}\\rr)."
                );
            Broadcast(
                "server",
                langFile["command_unmute_broadcast"]
                .Replace("$NICK$", target.nickname)
                .Replace("$NAME$", target.username)
                );
            if (OnlineUsers.ContainsKey(arguments[0]))
            {
                ServerMessage(
                    "server",
                    OnlineUsers[arguments[0]],
                    langFile["command_unmute_message"]
                    );
            }
        }