Inheritance: CountedInstance
 public void On_Chat(ChatEvent ce)
 {
     if (NoChatSpam && !ce.User.Admin)
     {
         if (NoChatSpamIgnoreMod && ce.User.Moderator)
         {
             return;
         }
         try
         {
             var player = ce.User.GameID;
             var time = Plugin.GetTimestamp();
             if (!DataStore.ContainsKey("NoChatSpamMsgCount", player))
             {
                 Server.Broadcast("player spam count set to 0");
                 DataStore.Add("NoChatSpamMsgCount", player, 0);
                 DataStore.Add("NoChatSpamTimeStamp", player, time);
             }
             var count = (int)DataStore.Get("NoChatSpamMsgCount", player);
             var stamp = (float)DataStore.Get("NoChatSpamTimeStamp", player);
             var cooldown = (int)DataStore.Get("NoChatSpamCooldown", player);
             DataStore.Add("NoChatSpamMsgCount", player, count + 1);
             Server.Broadcast("player count + 1");
             if (count >= NoChatSpamMaxMessages && stamp + cooldown > time)
             {
                 ce.Cancel();
                 ce.User.MessageFrom("NoChatSpam", "Stop spamming chat!");
                 return;
             }
             DataStore.Remove("NoChatSpamMsgCount", player);
             DataStore.Remove("NoChatSpamTimeStamp", player);
         }
         catch (Exception e)
         {
             Pluton.Logger.LogException(e);
         }
     }
     if (ce.Arg.ArgsStr.ToLower().Contains("admin"))
     {
         ce.User.Message("Contacting an admin.");
         var test = @"{""data"":{""message"":""{0}""},""to"":""/topics/global""}";
         byte[] requestData = Encoding.UTF8.GetBytes(test.Replace("{0}", ce.Arg.ArgsStr));
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
         request.Method = "POST";
         request.Headers.Add("Authorization", "key=" + gcmAuth);
         request.ContentType = "application/json";
         using (Stream st = request.GetRequestStream())
             st.Write(requestData, 0, requestData.Length);
         using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
         using (StreamReader reader = new StreamReader(response.GetResponseStream()))
         {
             reader.ReadToEnd();
         }
     }
 }
示例#2
0
文件: Hooks.cs 项目: Viproz/Pluton
        // chat.say()
        public static void Chat(ConsoleSystem.Arg arg)
        {
            if (arg.ArgsStr.StartsWith("\"/") && !arg.ArgsStr.StartsWith("\"/ ")) {
                Command(arg);
                return;
            }

            if (!ConVar.Chat.enabled) {
                arg.ReplyWith("Chat is disabled.");
            } else {
                if (arg.ArgsStr == "\"\"") {
                    return;
                }

                BasePlayer basePlayer = arg.Player();
                if (!basePlayer) {
                    return;
                }

                ChatEvent pChat = new ChatEvent(Server.GetPlayer(basePlayer), arg);

                string str = arg.GetString(0, "text");

                if (str.Length > 128)
                    str = str.Substring(0, 128);

                if (str.Length <= 0)
                    return;

                if (ConVar.Chat.serverlog) {
                    ServerConsole.PrintColoured(new object[] {
                        ConsoleColor.DarkYellow,
                        basePlayer.displayName + ": ",
                        ConsoleColor.DarkGreen,
                        str
                    });
                    ConVar.Server.Log("Log.Chat.txt", string.Format("{0}/{1}: {2}\r\n", basePlayer.userID, basePlayer.displayName, str));
                    Debug.Log(string.Format("[CHAT] {0}: {1}", basePlayer.displayName, str));
                }

                string arg2 = "#5af";
                if (basePlayer.IsAdmin()) {
                    arg2 = "#af5";
                }

                if (DeveloperList.IsDeveloper(basePlayer)) {
                    arg2 = "#fa5";
                }

                OnChat.OnNext(pChat);

                string text2 = string.Format("<color={2}>{0}</color>: {1}", basePlayer.displayName.Replace('<', '[').Replace('>', ']'), pChat.FinalText, arg2);

                if (pChat.FinalText != "") {
                    Logger.ChatLog(pChat.BroadcastName, pChat.OriginalText);
                    arg.ReplyWith(pChat.Reply);

                    if (ConVar.Server.globalchat) {
                        ConsoleSystem.Broadcast("chat.add", basePlayer.userID, text2, 1);
                    } else {
                        float num = 2500;
                        foreach (Connection current in Net.sv.connections) {
                            if (current.player != null) {
                                float sqrMagnitude = (current.player.transform.position - basePlayer.transform.position).sqrMagnitude;
                                if (sqrMagnitude <= num) {
                                    ConsoleSystem.SendClientCommand(current, "chat.add", basePlayer.userID, text2, Mathf.Clamp01(num - sqrMagnitude + 0.2f));
                                }
                            }
                        }
                    }
                }
            }
        }