public static void SendNotification(AdminNotification notification, ulong receiver)
        {
            if (!isInitialized)
            {
                return;
            }

            var notificationMessage = new MessageAdminNotification()
            {
                Notification = notification
            };

            ConnectionHelper.SendMessageToPlayer(receiver, notificationMessage);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/forceban\s+(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["Key"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyPlayer selectedPlayer = null;

                var findPlayer = players.FirstOrDefault(p => p.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase));
                if (findPlayer != null)
                {
                    selectedPlayer = findPlayer;
                }

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    var listplayers = new List <IMyPlayer>();
                    MyAPIGateway.Players.GetPlayers(listplayers, p => p.IdentityId == cacheList[index - 1].IdentityId);
                    selectedPlayer = listplayers.FirstOrDefault();
                }

                if (selectedPlayer == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "ForceBan", "No player named {0} found.", playerName);
                    return(true);
                }

                ChatCommandLogic.Instance.ServerCfg.Config.ForceBannedPlayers.Add(new Player()
                {
                    SteamId    = selectedPlayer.SteamUserId,
                    PlayerName = selectedPlayer.DisplayName
                });

                ConnectionHelper.SendMessageToPlayer(selectedPlayer.SteamUserId, new MessageForceDisconnect {
                    SteamId = selectedPlayer.SteamUserId, Ban = true
                });
                MyAPIGateway.Utilities.SendMessage(steamId, "Server", "{0} player Forcebanned", selectedPlayer.DisplayName);

                return(true);
            }

            return(false);
        }
示例#3
0
        /// <summary>
        /// Sends the given amount of chat entries to the client to display the chat history.
        /// </summary>
        /// <param name="receiver">The Steamid of the receiving client.</param>
        /// <param name="entryCount">The amount of entries that are requested.</param>
        public void SendChatHistory(ulong receiver, uint entryCount)
        {
            // we just append new chat messages to the log. To get the most recent on top we have to sort it.
            List <ChatMessage> cache = new List <ChatMessage>(_globalChatLogFile.ChatMessages.OrderByDescending(m => m.Date));

            // we have to make sure that we don't throw an exception
            int range = (int)entryCount;

            if (cache.Count < entryCount)
            {
                range = cache.Count;
            }

            var msgHistory = new MessageChatHistory
            {
                ChatHistory = cache.GetRange(0, range)
            };

            ConnectionHelper.SendMessageToPlayer(receiver, msgHistory);
        }