Beispiel #1
0
        /// <summary>
        /// Removes the specified client from the game, usually due to a disconnect. This also cleans up their votes and other game data.
        /// </summary>
        /// <param name="c">The client to remove.</param>
        public void RemoveClient(Client c)
        {
            // Remove this client's votes if they have any.
            if (ActiveRound != null)
            {
                ActiveRound.Votes.RemoveAll(v => v.ClientID == c.Info.ID && v.ClientName == c.Info.Name);
            }

            if (Admins.Contains(c))
            {
                Admins.Remove(c);
            }
            // Some race case is going on here... we need to check if there's even anything to remove.
            if (Clients.Count > 0)
            {
                Clients.Remove(c);
            }

            c = null;

            if (Clients.All(cl => cl.Info.IsSpectator) && ActiveRound != null)
            {
                DiscardActiveRound();
                BroadcastError(c, "RoundStopped", "There are no more non-spectator players, so the current round has been automatically discarded.");
            }

            // Check that every person hasn't already voted.
            CheckVoteCount();
        }
Beispiel #2
0
        public static void UserInfo(Message msg, string[] args)
        {
            var bu     = Methods.GetUser(msg, args);
            var status = "User without a single game";

            if (bu.Gamecount > 0)
            {
                status = "Player";
            }
            if (Admins.Contains(bu.Telegramid))
            {
                status = "Bot Admin";
            }
            if (Devs.ToList().Contains((int)bu.Telegramid))
            {
                status = "Bot Developer";
            }
            Bot.Reply(
                $"{bu.LinkedName}{Environment.NewLine}" +
                $" - @{bu.Username}{Environment.NewLine}" +
                $" - <code>{bu.Telegramid}</code>{Environment.NewLine}" +
                $" - Gamecount: <b>{bu.Gamecount}</b>{Environment.NewLine}" +
                $" - Achievement count: <b>{bu.Achievements.Count(x => x == '|') + 1}</b>{Environment.NewLine}" +
                $" - Status: {status}"

                , msg);
        }
Beispiel #3
0
        public bool IsAdmin(string userName)
        {
            var userService = IoC.Get <IUserService>();

            var user = userService.Get(userName);

            return(Admins.Contains(user.Id));
        }
Beispiel #4
0
        bool CheckPermission <T>(SteamID sender, T cmd) where T : struct
        {
            var  attrs          = EnumUtils.GetAttributeOfType <CommandAttribute>(cmd as Enum);
            bool isAdminCommand =
                attrs != null && attrs.Permissions == BotPermission.Admin;

            return(!isAdminCommand || Admins.Contains(sender));
        }
 public void RemoveMemberFromChatroom(Member kicking, Guest guestToKick)
 {
     if (kicking.ID == Creator)
     {
         MembersInChatroom.Remove(guestToKick.ID);
     }
     else if (Admins.Contains(kicking.ID))
     {
         MembersInChatroom.Remove(guestToKick.ID);
     }
 }
Beispiel #6
0
        private int PromoteAdmin(BotMessage msg, int state)
        {
            switch (state)
            {
            case 1:
            {
                if (msg.Kind == MessageKind.Text)
                {
                    long targetID;

                    if (long.TryParse(msg.Text, out targetID))
                    {
                        var target = new MessageSender()
                        {
                            Platform = msg.Sender.Platform, ID = targetID
                        };

                        if (Admins.Contains(target))
                        {
                            Speak(msg.Sender.Platform, msg.Sender.ID, $"This user already is an admin.");
                            return(0);
                        }

                        AddAdmin(target);
                        Speak(msg.Sender, $"That user is now an admin!");
                    }
                    else
                    {
                        Speak(msg.Sender, $"You should give me an {msg.Sender.Platform} user ID please...");
                    }
                }
                else
                {
                    Speak(msg.Sender, $"You should give me an {msg.Sender.Platform} user ID please...");
                }

                return(0);
            }

            default:
            {
                Speak(msg.Sender, $"Who should be promoted to admin?");
                return(1);
            }
            }

            foreach (var entry in _groupList)
            {
                Speak(msg.Sender.Platform, msg.Sender.ID, $"{entry.Value} => {entry.Key}");
            }

            return(0);
        }
Beispiel #7
0
 private Access AccessLevel(OnMessageReceivedArgs evnt)
 {
     if (Admins.Contains(evnt.ChatMessage.Username))
     {
         return(Access.Admin);
     }
     else if (evnt.ChatMessage.IsModerator)
     {
         return(Access.Moderator);
     }
     else
     {
         return(Access.User);
     }
 }
Beispiel #8
0
        public async Task OnGetAsync()
        {
            ViewData["Title"] = "Home page";

            Admins = await _userManager.GetUsersInRoleAsync("Admin");

            Employees = await _userManager.GetUsersInRoleAsync("Employee");

            Customers = await _userManager.GetUsersInRoleAsync("Customer");

            NonRoleUsers = _userManager.Users.ToList();

            NonRoleUsers = NonRoleUsers
                           .Where(user => !Admins.Contains(user, new UserComparer()) && !Employees.Contains(user, new UserComparer()) && !Customers.Contains(user, new UserComparer()))
                           .ToList();

            IsUsers = Admins.Count() + Employees.Count + Customers.Count() + NonRoleUsers.Count() > 0;
        }
Beispiel #9
0
        public static void ListCommands(Message msg, string[] args)
        {
            var bu = Methods.GetUser(msg, args);

            var res = $"<b>User commands:</b>{Environment.NewLine}" +
                      $"{string.Join(Environment.NewLine, Bot.Commands.Where(x => !x.AdminOnly & !x.DevOnly).Select(x => x.Trigger))}";

            if (Admins.Contains(bu.Telegramid))
            {
                res += $"{Environment.NewLine}{Environment.NewLine}<b>Bot admin commands:</b>" +
                       $"{Environment.NewLine}{string.Join(Environment.NewLine, Bot.Commands.Where(x => x.AdminOnly).Select(x => x.Trigger))}";
            }

            if (Devs.ToList().Contains((int)bu.Telegramid))
            {
                res += $"{Environment.NewLine}{Environment.NewLine}<b>Bot Dev Commands:</b>" +
                       $"{Environment.NewLine}{string.Join(Environment.NewLine, Bot.Commands.Where(x => x.DevOnly).Select(x => x.Trigger))}";
            }

            Bot.Reply(res, msg);
        }
Beispiel #10
0
 public bool IsAdmin(int id)
 {
     return(Admins.Contains(id));
 }
Beispiel #11
0
        public static void MessageHandler(Message msg)
        {
            try
            {
                if (!Groups.Any(x => x.Id == msg.Chat.Id) && msg.Chat.Type != ChatType.Private)
                {
                    Bot.Reply("Hey there! This bot isn't for every group! If you want to farm achievements with me, join a group in @WWAchievement! <b>Bye.</b>", msg);
                    Bot.Api.LeaveChatAsync(msg.Chat.Id);
                    Bot.Send($"<b>{msg.From.FirstName} {msg.From.LastName}</b> (@{msg.From.Username}) (<code>{msg.From.Id}</code>) just interacted me with me in <b>{msg.Chat.Title}</b> (<code>{msg.Chat.Id}</code>), which I left because it isn't an allowed group.", testgroup.Id);
                    return;
                }
                if (DateTime.UtcNow.AddSeconds(-5) > msg.Date.ToUniversalTime())
                {
                    return;
                }

                if (msg.Chat.Type == ChatType.Supergroup)
                {
                    var grp = Groups.First(x => x.Id == msg.Chat.Id);
                    if (msg.Chat.Title.FormatHTML() != grp.Name)
                    {
                        grp.Name = msg.Chat.Title.FormatHTML();
                        SQL.ChangeGroup(grp);
                    }
                    if (Games.Any(x => x.GroupId == grp.Id))
                    {
                        Games.First(x => x.GroupId == grp.Id).LastUpdate = DateTime.UtcNow;
                    }
                }

                var text = msg.Text;
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                var args = text.Contains(' ')
                    ? new[] { text.Split(' ')[0], text.Remove(0, text.IndexOf(' ') + 1) }
                    : new[] { text, null };

                if (!args[0].StartsWith("!") & !args[0].StartsWith("/") & args[0].ToLower() != "#ping")
                {
                    return;
                }

                var cmd = args[0].StartsWith("/") | args[0].StartsWith("!")
                    ? args[0].ToLower().Remove(0, 1).Replace('@' + Bot.Me.Username.ToLower(), "").Replace("@werewolfbot", "")
                    : args[0].ToLower().Replace('@' + Bot.Me.Username.ToLower(), "").Replace("@werewolfbot", "");

                var command = Bot.Commands.FirstOrDefault(x => String.Equals(x.Trigger, cmd, StringComparison.CurrentCultureIgnoreCase));
                if (command == null)
                {
                    return;
                }

                if (msg.Chat.Id == TranslationGroup && !Admins.Contains(msg.From.Id))
                {
                    Bot.Reply("You may not use commands in here!", msg);
                    return;
                }

                if (command.DevOnly & !Devs.Contains(msg.From.Id))
                {
                    Bot.Reply(Methods.GetString(msg, "NotDev"), msg);
                    return;
                }

                if (command.AdminOnly & !Admins.Contains(msg.From.Id))
                {
                    Bot.Reply(Methods.GetString(msg, "NotAdmin"), msg);
                    return;
                }

                if (command.InGroupOnly & msg.Chat.Type != ChatType.Supergroup)
                {
                    Bot.Reply(Methods.GetString(msg, "MustUseInGroup"), msg);
                    return;
                }

                if (command.InGameOnly)
                {
                    if (msg.Chat.Type != ChatType.Supergroup)
                    {
                        Bot.Reply(Methods.GetString(msg, "MustUseInGroup"), msg);
                        return;
                    }

                    var g = Games.FirstOrDefault(x => x.GroupId == msg.Chat.Id);

                    if (g == null)
                    {
                        Bot.Reply(Methods.GetString(msg, "MustUseInGame"), msg);
                        return;
                    }
                }

                command.Method.Invoke(msg, args);
            }
            catch (Exception e)
            {
                e.Log(true);
                return;
            }
        }
Beispiel #12
0
        public static void CallbackHandler(CallbackQuery call)
        {
            try
            {
                if (call.Message.Date.ToUniversalTime() < StartTime)
                {
                    Bot.AnswerCallback(call, Methods.GetString(call.Message, "OutdatedQuery"));
                    Bot.Edit(call.Message, call.Message.Text);
                    return;
                }

                var text = call.Data;
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                var args = text.Contains('|')
                    ? new[] { text.Split('|')[0], text.Remove(0, text.IndexOf('|') + 1) }
                    : new[] { text, null };

                var callback = Bot.Callbacks.FirstOrDefault(x => String.Equals(x.Trigger, args[0], StringComparison.CurrentCultureIgnoreCase));
                if (callback == null)
                {
                    return;
                }

                if (callback.DevOnly & !Devs.Contains(call.From.Id))
                {
                    Bot.AnswerCallback(call, "You aren't a bot dev!");
                    return;
                }

                if (callback.AdminOnly & !Admins.Contains(call.From.Id))
                {
                    Bot.AnswerCallback(call, "You aren't a bot admin!");
                    return;
                }

                if (callback.RequiresConfirm)
                {
                    var bu = call.From.GetOrMakeBotUser();
                    if (bu.CallbackChoice == call.Data)
                    {
                        bu.CallbackChoice = "";
                    }
                    else
                    {
                        bu.CallbackChoice = call.Data;
                        Timer t = new Timer(new TimerCallback(delegate { if (bu.CallbackChoice == call.Data)
                                                                         {
                                                                             bu.CallbackChoice = "";
                                                                         }
                                                              }), null, 10000, Timeout.Infinite);
                        Bot.AnswerCallback(call, Methods.GetString(call.Message, "ClickAgainConfirm"), true);
                        return;
                    }
                }

                callback.Method.Invoke(call, args);
            }
            catch (Exception e)
            {
                e.Log(true);
                return;
            }
        }
Beispiel #13
0
        /// <summary>
        /// Handles the incoming calling from the native side.
        /// </summary>
        private static object HandleCalling(string key, object[] args)
        {
            try
            {
                if (key == "call-event")
                {
                    int typeId = System.Convert.ToInt32(args[0]);
                    if (typeId == 7 || typeId == 6)
                    {
                        return(true);
                    }
                    EventType type = (EventType)typeId;

                    bool flag = true;
                    PluginManager.IteratePlugins(plugin =>
                    {
                        if (plugin == null || plugin.State == PluginState.Failed)
                        {
                            return;
                        }
                        PluginDomain domain = PluginManager.GetDomain(plugin);
                        if (domain == null)
                        {
                            Logger.Fatal("Could not get plugin domain for loaded plugin {PLUGIN}!", plugin.Display);
                            return;
                        }

                        object[] objArgs = ParseEventArgs(domain, type, args);
                        if (!domain.Server.CallEvent(type, objArgs))
                        {
                            flag = false;
                        }

                        if (type == EventType.PlayerQuit)
                        {
                            domain.Server.PlayerPool.RemoveEntity((Player)objArgs[0]);
                        }
                        else if (type == EventType.PlayerSteamAuth)
                        {
                            Player player = (Player)objArgs[0];
                            lock (Admins)
                            {
                                player.IsAdmin = Admins.Contains(player.SteamID);
                            }
                        }
                        else if (type == EventType.ConsoleInput)
                        {
                            ConsoleManager.PollInput((string)objArgs[0]);
                        }
                    });

                    return(flag);
                }

                if (key == "call-remote")
                {
                    int      player     = System.Convert.ToInt32(args[0]);
                    string   pluginId   = (string)args[1];
                    string   name       = (string)args[2];
                    object[] remoteArgs = new object[args.Length - 3];
                    for (int i = 3; i < args.Length; i++)
                    {
                        remoteArgs[i - 3] = args[i];
                    }

                    Plugin plugin = PluginManager.GetPlugin(pluginId);
                    if (plugin != null)
                    {
                        PluginManager.GetDomain(plugin)?.Server.FireRemoteEvent(name, player, remoteArgs);
                    }

                    return(null);
                }

                if (key == "call-command")
                {
                    string pluginId = (string)args[0];
                    int    player   = System.Convert.ToInt32(args[1]);
                    string name     = (string)args[2];
                    string line     = (string)args[3];
                    if (pluginId == "native")
                    {
                        return(null);
                    }

                    Plugin plugin = PluginManager.GetPlugin(pluginId);
                    if (plugin != null)
                    {
                        PluginManager.GetDomain(plugin)?.Server.FireCommand(player, name, line);
                    }

                    return(null);
                }

                if (key == "call-timer")
                {
                    string id = (string)args[0];
                    Timer.CallTimer(id);
                    return(null);
                }

                if (key == "call-delay")
                {
                    string id = (string)args[0];
                    Timer.CallDelay(id);
                    return(null);
                }

                if (key == "interop")
                {
                    string   pluginId = (string)args[0];
                    string   funcName = (string)args[1];
                    object[] @params  = new object[args.Length - 2];
                    for (int i = 2; i < args.Length; i++)
                    {
                        @params[i - 2] = args[i];
                    }

                    Plugin plugin = PluginManager.GetPlugin(pluginId);
                    return(plugin != null?PluginManager.GetDomain(plugin)?.Server.FireExportable(funcName, @params) : null);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex,
                             "An error occurred while handling a call {CALLNAME} from the native side! The data which was excepted is the following when debug enabled!",
                             key);
                Logger.Debug("Data for the Call:\n{DATA}", Json.ToJson(args, Json.Flag.Pretty));
            }

            return(null);
        }
Beispiel #14
0
 public bool IsAdmin(MessageSender sender)
 {
     return(Admins.Contains(sender));
 }
Beispiel #15
0
        public OrganizationInfo2(Organization organization,
                                 User You)

            : base(organization.Id,
                   organization.Name,
                   organization.Description,
                   organization.Website,
                   organization.EMail,
                   organization.Telephone,
                   organization.Address,
                   organization.GeoLocation,
                   _ => organization.Tags,
                   organization.IsDisabled,

                   null,

                   organization.User2OrganizationEdges,
                   organization.Organization2OrganizationInEdges,
                   organization.Organization2OrganizationOutEdges,

                   organization.CustomData,
                   organization.AttachedFiles,
                   organization.JSONLDContext,
                   organization.DataSource,
                   organization.LastChange)

        {
            this.You = You;
            //this.Admins                          = _User2Organization_InEdges.Where(_ => _.EdgeLabel == User2OrganizationEdgeTypes.IsAdmin). SafeSelect(edge => edge.Source).ToArray();
            //this.Members                         = _User2Organization_InEdges.Where(_ => _.EdgeLabel == User2OrganizationEdgeTypes.IsMember).SafeSelect(edge => edge.Source).ToArray();
            //this.Guests                          = _User2Organization_InEdges.Where(_ => _.EdgeLabel == User2OrganizationEdgeTypes.IsGuest). SafeSelect(edge => edge.Source).ToArray();

            void CheckAccessRights(Organization OOORg,
                                   ref Boolean _YouAreMemberRecursion,
                                   ref Boolean _YouCanAddMembersRecursion,
                                   ref Boolean _YouCanCreateChildOrganizationsRecursion)
            {
                foreach (var parent in OOORg.ParentOrganizations)
                {
                    CheckAccessRights(parent,
                                      ref _YouAreMemberRecursion,
                                      ref _YouCanAddMembersRecursion,
                                      ref _YouCanCreateChildOrganizationsRecursion);
                }

                if (_YouAreMemberRecursion == false && (OOORg.Members.Contains(You) || OOORg.Admins.Contains(You)))
                {
                    _YouAreMemberRecursion = true;
                }

                if (_YouCanAddMembersRecursion == false && OOORg.Admins.Contains(You))
                {
                    _YouCanAddMembersRecursion = true;
                }

                if (_YouCanCreateChildOrganizationsRecursion == false && OOORg.Admins.Contains(You))
                {
                    _YouCanCreateChildOrganizationsRecursion = true;
                }
            }

            var __YouAreMemberRecursion     = false;
            var __YouCanAddMembersRecursion = false;
            var __YouCanCreateChildOrganizationsRecursion = false;

            CheckAccessRights(this,
                              ref __YouAreMemberRecursion,
                              ref __YouCanAddMembersRecursion,
                              ref __YouCanCreateChildOrganizationsRecursion);

            this.YouAreMember     = __YouAreMemberRecursion || Admins.Contains(You) || Members.Contains(You);
            this.YouCanAddMembers = __YouCanAddMembersRecursion || Admins.Contains(You);
            this.YouCanCreateChildOrganizations = __YouCanCreateChildOrganizationsRecursion || Admins.Contains(You);

            #region GetChilds(Org, ...)

            IEnumerable <OrganizationInfo> GetChilds(Organization Org,
                                                     Boolean YouAreMemberRecursion,
                                                     Boolean YouCanAddMembersRecursion,
                                                     Boolean YouCanCreateChildOrganizationsRecursion)

            => Org.Organization2OrganizationInEdges.
            Where(edge => edge.EdgeLabel == Organization2OrganizationEdgeLabel.IsChildOf).
            SafeSelect(edge => new OrganizationInfo(edge.Source,
                                                    You,
                                                    YouAreMemberRecursion,
                                                    YouCanAddMembersRecursion,
                                                    YouCanCreateChildOrganizationsRecursion));

            #endregion

            #region CheckYouMembership(OrgInfo)

            Boolean CheckYouMembership(OrganizationInfo OrgInfo)
            {
                if (OrgInfo.internalChilds == null || OrgInfo.internalChilds.Count == 0)
                {
                    return(OrgInfo.YouAreMember);
                }

                var res = OrgInfo.YouAreMember;

                foreach (var ChildOrg in OrgInfo.Childs.ToArray())
                {
                    var resOfChild = CheckYouMembership(ChildOrg);

                    // Remove all child organizations if the given user is no direct member!
                    if (!resOfChild)
                    {
                        OrgInfo.internalChilds.Remove(ChildOrg);
                    }

                    res |= resOfChild;
                }

                return(res);
            }

            #endregion

            var childInfos = GetChilds(organization,
                                       this.YouAreMember,
                                       this.YouCanAddMembers,
                                       this.YouCanCreateChildOrganizations).ToList();

            foreach (var childInfo in childInfos)
            {
                CheckYouMembership(childInfo);
            }

            this.internalChilds = childInfos.Where(org => org.YouAreMember || org.internalChilds.Count > 0).ToList();
        }
Beispiel #16
0
        private void ParseChatCommand(ShootManiaXMLRPC.Structs.PlayerChat PC)
        {
            if (PC.Text == "!admins")
            {
                foreach (string admin in Admins)
                {
                    ChatSendServerMessage("Admin : " + admin);
                }
            }
            else if (PC.Text == "!players" &&
                     Admins.Contains(PC.Login))
            {
                foreach (var player in ServerManager.Server.GetPlayerList(100, 0))
                {
                    if (player.PlayerId > 0)
                    {
                        ChatSendServerMessage("[" + player.PlayerId + "] " + player.Nickname);
                    }
                }
            }
            else if (PC.Text.StartsWith("!addadmin") &&
                     Admins.Contains(PC.Login))
            {
                string admin = PC.Text.Replace("!addadmin ", string.Empty);

                if (!Admins.Contains(admin))
                {
                    Admins.Add(admin);
                    SaveAdmins();
                    ChatSendServerMessage("Admin added : " + admin);
                }
                else
                {
                    ChatSendServerMessage("Admin already exist : " + admin);
                }
            }
            else if (PC.Text.StartsWith("!deladmin") &&
                     Admins.Contains(PC.Login))
            {
                string admin = PC.Text.Replace("!deladmin ", string.Empty);

                if (admin != PC.Login)
                {
                    if (Admins.Contains(admin))
                    {
                        Admins.Remove(admin);
                        SaveAdmins();
                        ChatSendServerMessage("Admin removed : " + admin);
                    }
                    else
                    {
                        ChatSendServerMessage("Admin not found : " + admin);
                    }
                }
                else
                {
                    ChatSendServerMessage("You can't remove yourself !");
                }
            }
            else if (PC.Text == "!restartmap" &&
                     Admins.Contains(PC.Login))
            {
                ChatSendServerMessage("Restart map ...");
                ServerManager.Server.RestartMap(false);
            }
            else if (PC.Text == "!nextmap" &&
                     Admins.Contains(PC.Login))
            {
                ChatSendServerMessage("Next map ...");
                ServerManager.Server.NextMap(false);
            }
            else if (PC.Text.StartsWith("!map ") &&
                     Admins.Contains(PC.Login))
            {
                string newMap = PC.Text.Replace("!map ", string.Empty);

                foreach (var map in ServerManager.Server.GetMapList(1000, 0))
                {
                    if (map.FileName.ToLower().Contains(newMap.ToLower()))
                    {
                        ChatSendServerMessage("Map found : " + map.Name);
                        ServerManager.Server.ChooseNextMap(map.FileName);
                        ServerManager.Server.NextMap(false);
                        return;
                    }
                }

                ChatSendServerMessage("No map found with the pattern : " + newMap);
            }
            else if (PC.Text.StartsWith("!kick ") &&
                     Admins.Contains(PC.Login))
            {
                try {
                    int PlayerId = Convert.ToInt32(PC.Text.Replace("!kick ", string.Empty));

                    ServerManager.Server.KickId(PlayerId, "Kicked by admin");
                    ChatSendServerMessage("Played kicked");
                } catch {
                    ChatSendServerMessage("Invalid player id !");
                }
            }
            else if (PC.Text.StartsWith("!ban ") &&
                     Admins.Contains(PC.Login))
            {
                try {
                    int PlayerId = Convert.ToInt32(PC.Text.Replace("!ban ", string.Empty));

                    ServerManager.Server.BanId(PlayerId, "Banned by admin");
                    ChatSendServerMessage("Played banned");
                } catch {
                    ChatSendServerMessage("Invalid player id !");
                }
            }
            else if (PC.Text.StartsWith("!password ") &&
                     Admins.Contains(PC.Login))
            {
                string newPassword = PC.Text.Replace("!password ", string.Empty);

                ServerManager.Server.SetServerPassword(newPassword);
                ChatSendServerMessage("Password set to : " + newPassword);
            }
        }