mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 07:11:04 -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) {
|
protected void HandleGo(Player p, RoundsGame game) {
|
||||||
if (game.Running) {
|
if (!game.Running) {
|
||||||
Player.Message(p, "{0} is not running", game.GameName);
|
Player.Message(p, "{0} is not running", game.GameName);
|
||||||
} else {
|
} else {
|
||||||
PlayerActions.ChangeMap(p, game.Map);
|
PlayerActions.ChangeMap(p, game.Map);
|
||||||
|
@ -166,7 +166,6 @@ namespace MCGalaxy.Games {
|
|||||||
|
|
||||||
public bool HandlesMessage(Player p, string message) {
|
public bool HandlesMessage(Player p, string message) {
|
||||||
if (!Voting) return false;
|
if (!Voting) return false;
|
||||||
message = message.ToLower();
|
|
||||||
|
|
||||||
return
|
return
|
||||||
Player.CheckVote(message, p, "1", "one", ref Votes1) ||
|
Player.CheckVote(message, p, "1", "one", ref Votes1) ||
|
||||||
|
@ -790,8 +790,7 @@ namespace MCGalaxy.Games
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TntWarsGame GameIn(Player p)
|
public static TntWarsGame GameIn(Player p) {
|
||||||
{
|
|
||||||
TntWarsGame it = TntWarsGame.Find(p.level);
|
TntWarsGame it = TntWarsGame.Find(p.level);
|
||||||
if (it != null) return it;
|
if (it != null) return it;
|
||||||
it = FindFromGameNumber(p.CurrentTntGameNumber);
|
it = FindFromGameNumber(p.CurrentTntGameNumber);
|
||||||
|
@ -48,6 +48,7 @@ namespace MCGalaxy.Games {
|
|||||||
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
|
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
|
||||||
OnJoinedLevelEvent.Register(HandleJoinedLevel, Priority.High);
|
OnJoinedLevelEvent.Register(HandleJoinedLevel, Priority.High);
|
||||||
|
|
||||||
|
OnPlayerChatEvent.Register(HandlePlayerChat, Priority.High);
|
||||||
OnSQLSaveEvent.Register(SavePlayerStats, Priority.High);
|
OnSQLSaveEvent.Register(SavePlayerStats, Priority.High);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ namespace MCGalaxy.Games {
|
|||||||
OnPlayerSpawningEvent.Unregister(HandlePlayerSpawning);
|
OnPlayerSpawningEvent.Unregister(HandlePlayerSpawning);
|
||||||
OnJoinedLevelEvent.Unregister(HandleJoinedLevel);
|
OnJoinedLevelEvent.Unregister(HandleJoinedLevel);
|
||||||
|
|
||||||
|
OnPlayerChatEvent.Unregister(HandlePlayerChat);
|
||||||
OnSQLSaveEvent.Unregister(SavePlayerStats);
|
OnSQLSaveEvent.Unregister(SavePlayerStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +166,31 @@ namespace MCGalaxy.Games {
|
|||||||
name += " (map: " + Map.MapName + ")";
|
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) {
|
void HandleBlockChange(Player p, ushort x, ushort y, ushort z, BlockID block, bool placing) {
|
||||||
if (p.level != Map) return;
|
if (p.level != Map) return;
|
||||||
BlockID old = Map.GetBlock(x, y, z);
|
BlockID old = Map.GetBlock(x, y, z);
|
||||||
@ -203,7 +230,6 @@ namespace MCGalaxy.Games {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool NotPillaring(BlockID b, BlockID old) {
|
bool NotPillaring(BlockID b, BlockID old) {
|
||||||
byte collide = Map.CollideType(b);
|
byte collide = Map.CollideType(b);
|
||||||
if (collide == CollideType.WalkThrough) return true;
|
if (collide == CollideType.WalkThrough) return true;
|
||||||
@ -252,6 +278,7 @@ namespace MCGalaxy.Games {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SavePlayerStats(Player p) {
|
void SavePlayerStats(Player p) {
|
||||||
ZSData data = TryGet(p);
|
ZSData data = TryGet(p);
|
||||||
if (data == null || data.TotalRoundsSurvived == 0 && data.TotalInfected == 0) return;
|
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) {
|
public override bool HandlesChatMessage(Player p, string message) {
|
||||||
if (!Running || (p.level == null || p.level != Map)) return false;
|
if (!Running || p.level != Map) return false;
|
||||||
if (Picker.Voting && Picker.HandlesMessage(p, message)) return true;
|
return Picker.HandlesMessage(p, message);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveAssociatedBounties(Player p) {
|
void RemoveAssociatedBounties(Player p) {
|
||||||
|
@ -486,14 +486,20 @@ namespace MCGalaxy {
|
|||||||
// People who are muted can't speak or vote
|
// People who are muted can't speak or vote
|
||||||
if (muted) { SendMessage("You are muted."); return; } //Muted: Only allow commands
|
if (muted) { SendMessage("You are muted."); return; } //Muted: Only allow commands
|
||||||
|
|
||||||
// Filter out bad words
|
if (Server.voting) {
|
||||||
if (ServerConfig.ProfanityFiltering) text = ProfanityFilter.Parse(text);
|
if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) ||
|
||||||
|
CheckVote(text, this, "n", "no", ref Server.NoVotes)) return;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsHandledMessage(text)) 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
|
// 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; }
|
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;
|
if (ChatModes.Handle(this, text)) return;
|
||||||
|
|
||||||
if (text[0] == ':' && PlayingTntWars) {
|
if (text[0] == ':' && PlayingTntWars) {
|
||||||
@ -543,11 +549,6 @@ namespace MCGalaxy {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partialMessage.Length > 0 && !(IsPartialSpaced(text) || IsPartialJoined(text))) {
|
|
||||||
text = partialMessage + text;
|
|
||||||
partialMessage = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsPartialSpaced(text)) {
|
if (IsPartialSpaced(text)) {
|
||||||
partialMessage += text.Substring(0, text.Length - 2) + " ";
|
partialMessage += text.Substring(0, text.Length - 2) + " ";
|
||||||
SendMessage("&3Partial message: &f" + partialMessage);
|
SendMessage("&3Partial message: &f" + partialMessage);
|
||||||
@ -556,6 +557,9 @@ namespace MCGalaxy {
|
|||||||
partialMessage += text.Substring(0, text.Length - 2);
|
partialMessage += text.Substring(0, text.Length - 2);
|
||||||
SendMessage("&3Partial message: &f" + partialMessage);
|
SendMessage("&3Partial message: &f" + partialMessage);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (partialMessage.Length > 0) {
|
||||||
|
text = partialMessage + text;
|
||||||
|
partialMessage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
text = Regex.Replace(text, " +", " ");
|
text = Regex.Replace(text, " +", " ");
|
||||||
@ -591,11 +595,11 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
int sep = text.IndexOf(' ');
|
int sep = text.IndexOf(' ');
|
||||||
if (sep == -1) {
|
if (sep == -1) {
|
||||||
HandleCommand(text.ToLower(), "");
|
HandleCommand(text, "");
|
||||||
} else {
|
} else {
|
||||||
string cmd = text.Substring(0, sep).ToLower();
|
string cmd = text.Substring(0, sep);
|
||||||
string msg = text.Substring(sep + 1);
|
string args = text.Substring(sep + 1);
|
||||||
HandleCommand(cmd, msg);
|
HandleCommand(cmd, args);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -613,29 +617,13 @@ namespace MCGalaxy {
|
|||||||
return lines.Length > 0 ? lines[rnd.Next(lines.Length)] : text;
|
return lines.Length > 0 ? lines[rnd.Next(lines.Length)] : text;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHandledMessage(string text) {
|
public void HandleCommand(string cmd, string args) {
|
||||||
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) {
|
|
||||||
cmd = cmd.ToLower();
|
cmd = cmd.ToLower();
|
||||||
try {
|
try {
|
||||||
Command command = GetCommand(ref cmd, ref message);
|
Command command = GetCommand(ref cmd, ref args);
|
||||||
if (command == null) return;
|
if (command == null) return;
|
||||||
|
|
||||||
Thread thread = new Thread(() => UseCommand(command, message));
|
Thread thread = new Thread(() => UseCommand(command, args));
|
||||||
thread.Name = "MCG_Command";
|
thread.Name = "MCG_Command";
|
||||||
thread.IsBackground = true;
|
thread.IsBackground = true;
|
||||||
thread.Start();
|
thread.Start();
|
||||||
@ -651,12 +639,12 @@ namespace MCGalaxy {
|
|||||||
foreach (string raw in cmds) {
|
foreach (string raw in cmds) {
|
||||||
string[] parts = raw.SplitSpaces(2);
|
string[] parts = raw.SplitSpaces(2);
|
||||||
string cmd = parts[0].ToLower();
|
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;
|
if (command == null) return;
|
||||||
|
|
||||||
messages.Add(message); commands.Add(command);
|
messages.Add(args); commands.Add(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread thread = new Thread(() => UseCommands(commands, messages));
|
Thread thread = new Thread(() => UseCommands(commands, messages));
|
||||||
|
@ -378,14 +378,17 @@ namespace MCGalaxy {
|
|||||||
CurrentAmountOfTnt--;
|
CurrentAmountOfTnt--;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool CheckVote(string message, Player p, string a, string b, ref int totalVotes) {
|
internal static bool CheckVote(string msg, Player p, string a, string b, ref int totalVotes) {
|
||||||
if (!p.voted && (message == a || message == b)) {
|
if (!(msg.CaselessEq(a) || msg.CaselessEq(b))) return false;
|
||||||
|
|
||||||
|
if (p.voted) {
|
||||||
|
Player.Message(p, "&cYou have already voted!");
|
||||||
|
} else {
|
||||||
totalVotes++;
|
totalVotes++;
|
||||||
Player.Message(p, Colors.red + "Thanks for voting!");
|
Player.Message(p, "&aThanks for voting!");
|
||||||
p.voted = true;
|
p.voted = true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckForMessageSpam() {
|
public void CheckForMessageSpam() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user