mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 06:43:25 -04:00
don't allow duplicate vote messages
This commit is contained in:
parent
c2022c589a
commit
9055b26afd
@ -46,7 +46,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
}
|
||||
|
||||
protected void HandleGo(Player p, RoundsGame game) {
|
||||
if (game.Running) {
|
||||
if (!game.Running) {
|
||||
Player.Message(p, "{0} is not running", game.GameName);
|
||||
} else {
|
||||
PlayerActions.ChangeMap(p, game.Map);
|
||||
|
@ -166,7 +166,6 @@ namespace MCGalaxy.Games {
|
||||
|
||||
public bool HandlesMessage(Player p, string message) {
|
||||
if (!Voting) return false;
|
||||
message = message.ToLower();
|
||||
|
||||
return
|
||||
Player.CheckVote(message, p, "1", "one", ref Votes1) ||
|
||||
|
@ -790,8 +790,7 @@ namespace MCGalaxy.Games
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TntWarsGame GameIn(Player p)
|
||||
{
|
||||
public static TntWarsGame GameIn(Player p) {
|
||||
TntWarsGame it = TntWarsGame.Find(p.level);
|
||||
if (it != null) return it;
|
||||
it = FindFromGameNumber(p.CurrentTntGameNumber);
|
||||
|
@ -48,6 +48,7 @@ namespace MCGalaxy.Games {
|
||||
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
|
||||
OnJoinedLevelEvent.Register(HandleJoinedLevel, Priority.High);
|
||||
|
||||
OnPlayerChatEvent.Register(HandlePlayerChat, Priority.High);
|
||||
OnSQLSaveEvent.Register(SavePlayerStats, Priority.High);
|
||||
}
|
||||
|
||||
@ -66,6 +67,7 @@ namespace MCGalaxy.Games {
|
||||
OnPlayerSpawningEvent.Unregister(HandlePlayerSpawning);
|
||||
OnJoinedLevelEvent.Unregister(HandleJoinedLevel);
|
||||
|
||||
OnPlayerChatEvent.Unregister(HandlePlayerChat);
|
||||
OnSQLSaveEvent.Unregister(SavePlayerStats);
|
||||
}
|
||||
|
||||
@ -164,6 +166,31 @@ namespace MCGalaxy.Games {
|
||||
name += " (map: " + Map.MapName + ")";
|
||||
}
|
||||
|
||||
void HandlePlayerChat(Player p, string message) {
|
||||
if (p.level != Map || message.Length <= 1) return;
|
||||
|
||||
if (message[0] == '~') {
|
||||
message = message.Substring(1);
|
||||
|
||||
if (Get(p).Infected) {
|
||||
Chat.MessageChat(ChatScope.Level, p, "λNICK &cto zombies%S: " + message,
|
||||
Map, (pl, arg) => pl.Game.Referee || Get(pl).Infected);
|
||||
} else {
|
||||
Chat.MessageChat(ChatScope.Level, p, "λNICK &ato humans%S: " + message,
|
||||
Map, (pl, arg) => pl.Game.Referee || !Get(pl).Infected);
|
||||
}
|
||||
p.cancelchat = true;
|
||||
} else if (message[0] == '`') {
|
||||
if (p.Game.Team == null) {
|
||||
Player.Message(p, "You are not on a team, so cannot send a team message.");
|
||||
} else {
|
||||
p.Game.Team.Message(p, message.Substring(1));
|
||||
}
|
||||
p.cancelchat = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HandleBlockChange(Player p, ushort x, ushort y, ushort z, BlockID block, bool placing) {
|
||||
if (p.level != Map) return;
|
||||
BlockID old = Map.GetBlock(x, y, z);
|
||||
@ -201,8 +228,7 @@ namespace MCGalaxy.Games {
|
||||
Player.Message(p, "Blocks Left: &4" + data.BlocksLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool NotPillaring(BlockID b, BlockID old) {
|
||||
byte collide = Map.CollideType(b);
|
||||
@ -238,7 +264,7 @@ namespace MCGalaxy.Games {
|
||||
Chat.MessageFromOps(p, " &cWarning: λNICK %Sis pillaring!");
|
||||
Command.Find("Take").Use(null, p.name + " 10 Auto fine for pillaring");
|
||||
Player.Message(p, " &cThe next time you pillar, you will be &4kicked&c.");
|
||||
} else {
|
||||
} else {
|
||||
ModAction action = new ModAction(p.name, null, ModActionType.Kicked, "Auto kick for pillaring");
|
||||
OnModActionEvent.Call(action);
|
||||
p.Kick("No pillaring allowed!");
|
||||
@ -252,6 +278,7 @@ namespace MCGalaxy.Games {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void SavePlayerStats(Player p) {
|
||||
ZSData data = TryGet(p);
|
||||
if (data == null || data.TotalRoundsSurvived == 0 && data.TotalInfected == 0) return;
|
||||
|
@ -278,28 +278,8 @@ namespace MCGalaxy.Games {
|
||||
}
|
||||
|
||||
public override bool HandlesChatMessage(Player p, string message) {
|
||||
if (!Running || (p.level == null || p.level != Map)) return false;
|
||||
if (Picker.Voting && Picker.HandlesMessage(p, message)) return true;
|
||||
|
||||
if (message[0] == '~' && message.Length > 1) {
|
||||
message = message.Substring(1);
|
||||
|
||||
if (Get(p).Infected) {
|
||||
Chat.MessageChat(ChatScope.Level, p, "λNICK &cto zombies%S: " + message,
|
||||
Map, (pl, arg) => pl.Game.Referee || Get(pl).Infected);
|
||||
} else {
|
||||
Chat.MessageChat(ChatScope.Level, p, "λNICK &ato humans%S: " + message,
|
||||
Map, (pl, arg) => pl.Game.Referee || !Get(pl).Infected);
|
||||
}
|
||||
return true;
|
||||
} else if (message[0] == '`' && message.Length > 1) {
|
||||
if (p.Game.Team == null) {
|
||||
Player.Message(p, "You are not on a team, so cannot send a team message."); return true;
|
||||
}
|
||||
p.Game.Team.Message(p, message.Substring(1));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (!Running || p.level != Map) return false;
|
||||
return Picker.HandlesMessage(p, message);
|
||||
}
|
||||
|
||||
void RemoveAssociatedBounties(Player p) {
|
||||
|
@ -486,13 +486,19 @@ namespace MCGalaxy {
|
||||
// People who are muted can't speak or vote
|
||||
if (muted) { SendMessage("You are muted."); return; } //Muted: Only allow commands
|
||||
|
||||
// Filter out bad words
|
||||
if (ServerConfig.ProfanityFiltering) text = ProfanityFilter.Parse(text);
|
||||
|
||||
if (IsHandledMessage(text)) return;
|
||||
if (Server.voting) {
|
||||
if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) ||
|
||||
CheckVote(text, this, "n", "no", ref Server.NoVotes)) return;
|
||||
}
|
||||
|
||||
if (Server.lava.HandlesChatMessage(this, text)) return;
|
||||
if (Server.zombie.HandlesChatMessage(this, text)) return;
|
||||
|
||||
// Put this after vote collection so that people can vote even when chat is moderated
|
||||
if (Server.chatmod && !voice) { SendMessage("Chat moderation is on, you cannot speak."); return; }
|
||||
|
||||
// Filter out bad words
|
||||
if (ServerConfig.ProfanityFiltering) text = ProfanityFilter.Parse(text);
|
||||
|
||||
if (ChatModes.Handle(this, text)) return;
|
||||
|
||||
@ -543,11 +549,6 @@ namespace MCGalaxy {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (partialMessage.Length > 0 && !(IsPartialSpaced(text) || IsPartialJoined(text))) {
|
||||
text = partialMessage + text;
|
||||
partialMessage = "";
|
||||
}
|
||||
|
||||
if (IsPartialSpaced(text)) {
|
||||
partialMessage += text.Substring(0, text.Length - 2) + " ";
|
||||
SendMessage("&3Partial message: &f" + partialMessage);
|
||||
@ -556,6 +557,9 @@ namespace MCGalaxy {
|
||||
partialMessage += text.Substring(0, text.Length - 2);
|
||||
SendMessage("&3Partial message: &f" + partialMessage);
|
||||
return true;
|
||||
} else if (partialMessage.Length > 0) {
|
||||
text = partialMessage + text;
|
||||
partialMessage = "";
|
||||
}
|
||||
|
||||
text = Regex.Replace(text, " +", " ");
|
||||
@ -591,11 +595,11 @@ namespace MCGalaxy {
|
||||
|
||||
int sep = text.IndexOf(' ');
|
||||
if (sep == -1) {
|
||||
HandleCommand(text.ToLower(), "");
|
||||
HandleCommand(text, "");
|
||||
} else {
|
||||
string cmd = text.Substring(0, sep).ToLower();
|
||||
string msg = text.Substring(sep + 1);
|
||||
HandleCommand(cmd, msg);
|
||||
string cmd = text.Substring(0, sep);
|
||||
string args = text.Substring(sep + 1);
|
||||
HandleCommand(cmd, args);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -613,29 +617,13 @@ namespace MCGalaxy {
|
||||
return lines.Length > 0 ? lines[rnd.Next(lines.Length)] : text;
|
||||
}
|
||||
|
||||
bool IsHandledMessage(string text) {
|
||||
if (Server.voting) {
|
||||
string test = text.ToLower();
|
||||
if (CheckVote(test, this, "y", "yes", ref Server.YesVotes) ||
|
||||
CheckVote(test, this, "n", "no", ref Server.NoVotes)) return true;
|
||||
|
||||
if (!voice && (test == "y" || test == "n" || test == "yes" || test == "no")) {
|
||||
SendMessage("Chat moderation is on while voting is on!"); return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Server.lava.HandlesChatMessage(this, text)) return true;
|
||||
if (Server.zombie.HandlesChatMessage(this, text)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void HandleCommand(string cmd, string message) {
|
||||
public void HandleCommand(string cmd, string args) {
|
||||
cmd = cmd.ToLower();
|
||||
try {
|
||||
Command command = GetCommand(ref cmd, ref message);
|
||||
Command command = GetCommand(ref cmd, ref args);
|
||||
if (command == null) return;
|
||||
|
||||
Thread thread = new Thread(() => UseCommand(command, message));
|
||||
Thread thread = new Thread(() => UseCommand(command, args));
|
||||
thread.Name = "MCG_Command";
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
@ -651,12 +639,12 @@ namespace MCGalaxy {
|
||||
foreach (string raw in cmds) {
|
||||
string[] parts = raw.SplitSpaces(2);
|
||||
string cmd = parts[0].ToLower();
|
||||
string message = parts.Length > 1 ? parts[1] : "";
|
||||
string args = parts.Length > 1 ? parts[1] : "";
|
||||
|
||||
Command command = GetCommand(ref cmd, ref message);
|
||||
Command command = GetCommand(ref cmd, ref args);
|
||||
if (command == null) return;
|
||||
|
||||
messages.Add(message); commands.Add(command);
|
||||
messages.Add(args); commands.Add(command);
|
||||
}
|
||||
|
||||
Thread thread = new Thread(() => UseCommands(commands, messages));
|
||||
|
@ -378,14 +378,17 @@ namespace MCGalaxy {
|
||||
CurrentAmountOfTnt--;
|
||||
}
|
||||
|
||||
internal static bool CheckVote(string message, Player p, string a, string b, ref int totalVotes) {
|
||||
if (!p.voted && (message == a || message == b)) {
|
||||
internal static bool CheckVote(string msg, Player p, string a, string b, ref int totalVotes) {
|
||||
if (!(msg.CaselessEq(a) || msg.CaselessEq(b))) return false;
|
||||
|
||||
if (p.voted) {
|
||||
Player.Message(p, "&cYou have already voted!");
|
||||
} else {
|
||||
totalVotes++;
|
||||
Player.Message(p, Colors.red + "Thanks for voting!");
|
||||
Player.Message(p, "&aThanks for voting!");
|
||||
p.voted = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CheckForMessageSpam() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user