Rename Player.GlobalChat to a more logical Player.SendChatFrom, modularise vote functions for chat.

This commit is contained in:
UnknownShadow200 2016-02-10 23:06:21 +11:00
parent 912c63d2f5
commit 461d41ad0e
21 changed files with 88 additions and 79 deletions

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.Commands
if (Server.chatmod && !p.voice) { Player.SendMessage(p, "Chat moderation is on, you cannot emote."); return; }
if (Server.worldChat)
Player.GlobalChat(p, p.color + "*" + Colors.StripColours(p.DisplayName) + p.color + " " + message, false);
Player.SendChatFrom(p, p.color + "*" + Colors.StripColours(p.DisplayName) + p.color + " " + message, false);
else
Chat.GlobalChatLevel(p, p.color + "*" + Colors.StripColours(p.DisplayName) + p.color + " " + message, false);
//IRCBot.Say("*" + p.name + " " + message);

View File

@ -38,13 +38,13 @@ namespace MCGalaxy.Commands
if (!who.frozen)
{
who.frozen = true;
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " has been &bfrozen" + Server.DefaultColor + " by " + frozenby + Server.DefaultColor + ".", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " has been &bfrozen" + Server.DefaultColor + " by " + frozenby + Server.DefaultColor + ".", false);
Server.s.Log(who.name + " has been frozen by " + frozenby);
}
else
{
who.frozen = false;
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " has been &adefrosted" + Server.DefaultColor + " by " + frozenby + Server.DefaultColor + ".", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " has been &adefrosted" + Server.DefaultColor + " by " + frozenby + Server.DefaultColor + ".", false);
Server.s.Log(who.name + " has been defrosted by " + frozenby);
}
}

View File

@ -57,7 +57,7 @@ namespace MCGalaxy.Commands
{
Player.GlobalDespawn(p, true);
Chat.GlobalMessageOps("To Ops -" + p.color + p.DisplayName + Server.DefaultColor + "- is now &finvisible" + Server.DefaultColor + ".");
Player.GlobalChat(p, "&c- " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
Player.SendChatFrom(p, "&c- " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
(File.Exists("text/logout/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/logout/" + p.name + ".txt") : "Disconnected."), false);
Server.IRC.Say(p.DisplayName + " left the game (Disconnected.)");
if (!p.opchat)
@ -70,7 +70,7 @@ namespace MCGalaxy.Commands
{
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
Chat.GlobalMessageOps("To Ops -" + p.color + p.DisplayName + Server.DefaultColor + "- is now &8visible" + Server.DefaultColor + ".");
Player.GlobalChat(p, "&a+ " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
Player.SendChatFrom(p, "&a+ " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
(File.Exists("text/login/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/login/" + p.name + ".txt") : "joined the game."), false);
Server.IRC.Say(p.DisplayName + " joined the game");
if (p.opchat)

View File

@ -57,7 +57,7 @@ namespace MCGalaxy
{
writer.WriteLine(who.name.ToLower() + " " + who.level.name);
}
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " was &8jailed", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " was &8jailed", false);
}
else
{
@ -66,7 +66,7 @@ namespace MCGalaxy
who.jailed = false;
Command.all.Find("spawn").Use(who, "");
Player.SendMessage(p, "You freed " + who.name + " from jail");
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " was &afreed" + Server.DefaultColor + " from jail", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " was &afreed" + Server.DefaultColor + " from jail", false);
}
}
else

View File

@ -50,13 +50,13 @@ namespace MCGalaxy.Commands
{
who.joker = true;
if (stealth) { Chat.GlobalMessageOps(who.color + who.DisplayName + Server.DefaultColor + " is now STEALTH joker'd. "); return; }
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " is now a &aJ&bo&ck&5e&9r" + Server.DefaultColor + ".", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " is now a &aJ&bo&ck&5e&9r" + Server.DefaultColor + ".", false);
}
else
{
who.joker = false;
if (stealth) { Chat.GlobalMessageOps(who.color + who.DisplayName + Server.DefaultColor + " is now STEALTH Unjoker'd. "); return; }
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " is no longer a &aJ&bo&ck&5e&9r" + Server.DefaultColor + ".", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " is no longer a &aJ&bo&ck&5e&9r" + Server.DefaultColor + ".", false);
}
}
public override void Help(Player p)

View File

@ -47,7 +47,7 @@ namespace MCGalaxy.Commands
}
if (who.group.Permission >= p.group.Permission)
{
Player.GlobalChat(p,
Player.SendChatFrom(p,
p.color + p.DisplayName + "%S tried to kick " + who.color + who.DisplayName +
"%S but failed.",
false);

View File

@ -67,7 +67,7 @@ namespace MCGalaxy.Commands
if (who.muted)
{
who.muted = false;
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " has been &bun-muted", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " has been &bun-muted", false);
Extensions.DeleteLineWord("ranks/muted.txt", who.name.ToLower());
}
else
@ -77,7 +77,7 @@ namespace MCGalaxy.Commands
if (who != p) if (who.group.Permission >= p.group.Permission) { Player.SendMessage(p, "Cannot mute someone of a higher or equal rank."); return; }
}
who.muted = true;
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " has been &8muted", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " has been &8muted", false);
using (StreamWriter writer = new StreamWriter("ranks/muted.txt", true))
{
writer.WriteLine(who.name.ToLower());

View File

@ -33,7 +33,7 @@ namespace MCGalaxy.Commands
p.referee = false;
LevelPermission perm = Group.findPlayerGroup(name).Permission;
Player.GlobalDespawn(p, false);
Player.GlobalChat(p, p.color + p.name + Server.DefaultColor + " is no longer a referee", false);
Player.SendChatFrom(p, p.color + p.name + Server.DefaultColor + " is no longer a referee", false);
if (Server.zombie.GameInProgess())
{
Server.zombie.InfectPlayer(p);
@ -50,7 +50,7 @@ namespace MCGalaxy.Commands
else
{
p.referee = true;
Player.GlobalChat(p, p.color + p.name + Server.DefaultColor + " is now a referee", false);
Player.SendChatFrom(p, p.color + p.name + Server.DefaultColor + " is now a referee", false);
Player.GlobalDespawn(p, false);
if (Server.zombie.GameInProgess())
{

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Commands
if (who.group.Permission >= p.group.Permission)
{
Player.GlobalChat(p, p.color + p.DisplayName + " " + Server.DefaultColor + "tried to votekick " + who.color + who.DisplayName + " " + Server.DefaultColor + "but failed!", false);
Player.SendChatFrom(p, p.color + p.DisplayName + " " + Server.DefaultColor + "tried to votekick " + who.color + who.DisplayName + " " + Server.DefaultColor + "but failed!", false);
return;
}

View File

@ -40,7 +40,7 @@ namespace MCGalaxy.Commands
if (p.hidden)
{
Player.GlobalDespawn(p, true);
Player.GlobalChat(p, "&c- " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
Player.SendChatFrom(p, "&c- " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
(File.Exists("text/logout/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/logout/" + p.name + ".txt") : "Disconnected."), false);
Server.IRC.Say(p.name + " left the game (Disconnected.)");
if (!p.adminchat)
@ -52,7 +52,7 @@ namespace MCGalaxy.Commands
else
{
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false, "");
Player.GlobalChat(p, "&a+ " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
Player.SendChatFrom(p, "&a+ " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
(File.Exists("text/login/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/login/" + p.name + ".txt") : "joined the game."), false);
Server.IRC.Say(p.name + " joined the game");
if (p.adminchat)

View File

@ -127,9 +127,10 @@ namespace MCGalaxy.Commands {
foreach (Player pl in PlayerInfo.players) if (pl.level == oldLevel) { unloadOld = false; break; }
if (unloadOld && Server.AutoLoad) oldLevel.Unload(true);
}
CheckGamesJoin(p, lvl);
if (!p.hidden) {
Player.GlobalChat(p, p.color + "*" + p.DisplayName + Server.DefaultColor + " went to &b" + lvl.name, false);
Player.SendChatFrom(p, p.color + "*" + p.DisplayName + Server.DefaultColor + " went to &b" + lvl.name, false);
Server.IRC.Say(p.color + p.DisplayName + " %rwent to &8" + lvl.name, false, true);
}
}

View File

@ -80,7 +80,7 @@ namespace MCGalaxy.Commands
if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}
struct CatchPos { public ushort x, y, z; }
struct CatchPos { }
public override void Help(Player p)
{

View File

@ -102,7 +102,7 @@ namespace MCGalaxy.Commands
if (p == who) {
Player.SendMessage(p, "Undid your actions for the past &b" + seconds + " %Sseconds.");
} else {
Player.GlobalChat(who, who.color + who.DisplayName + "%S's actions for the past &b" + seconds + " seconds were undone.", false);
Player.SendChatFrom(who, who.color + who.DisplayName + "%S's actions for the past &b" + seconds + " seconds were undone.", false);
}
Server.s.Log(who.name + "'s actions for the past " + seconds + " seconds were undone.");
if (saveLevel != null) saveLevel.Save(true);

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands {
}
if (args.Length == 1) {
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " had their color removed.", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " had their color removed.", false);
who.color = who.group.color;
Database.AddParams("@Name", who.name);
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands {
string color = Colors.Parse(args[1]);
if (color == "") { Player.SendMessage(p, "There is no color \"" + message + "\"."); return; }
else if (color == who.color) { Player.SendMessage(p, p.DisplayName + " already has that color."); return; }
Player.GlobalChat(who, who.color + who.DisplayName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false);
Player.SendChatFrom(who, who.color + who.DisplayName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false);
who.color = color;
Database.AddParams("@Color", Colors.Name(color));

View File

@ -33,7 +33,7 @@ namespace MCGalaxy.Commands
{
message = message.Substring(message.IndexOf(' ') + 1);
//Player.GlobalMessage(player.color + player.voicestring + player.color + player.prefix + player.name + ": &f" + message);
Player.GlobalChat(player, message);
Player.SendChatFrom(player, message);
}
else
{

View File

@ -64,7 +64,7 @@ namespace MCGalaxy.Commands
}
if (Server.cheapMessage && !p.hidden)
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " has stopped being immortal", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " has stopped being immortal", false);
}
else
{
@ -78,7 +78,7 @@ namespace MCGalaxy.Commands
}
who.invincible = true;
if (Server.cheapMessage && !p.hidden)
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " " + Server.cheapMessageGiven, false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " " + Server.cheapMessageGiven, false);
}
}
public override void Help(Player p)

View File

@ -43,10 +43,10 @@ namespace MCGalaxy.Commands {
string newName = parts.Length > 1 ? parts[1] : "";
if (newName == "") {
who.DisplayName = who.name;
Player.GlobalChat(who, who.color + who.prefix + who.DisplayName + "%S has reverted their nick to their original name.", false);
Player.SendChatFrom(who, who.color + who.prefix + who.DisplayName + "%S has reverted their nick to their original name.", false);
} else {
if (newName.Length > 60) { Player.SendMessage(p, "Nick must be under 60 letters."); return; }
Player.GlobalChat(who, who.color + who.DisplayName + "%S has changed their nick to " + who.color + newName + "%S.", false);
Player.SendChatFrom(who, who.color + who.DisplayName + "%S has changed their nick to " + who.color + newName + "%S.", false);
who.DisplayName = newName;
}

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands {
}
if (args.Length == 1) {
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " had their title color removed.", false);
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " had their title color removed.", false);
who.titlecolor = "";
Database.AddParams("@Name", who.name);
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands {
string color = Colors.Parse(args[1]);
if (color == "") { Player.SendMessage(p, "There is no color \"" + args[1] + "\"."); return; }
else if (color == who.titlecolor) { Player.SendMessage(p, who.DisplayName + " already has that title color."); return; }
Player.GlobalChat(who, who.color + who.DisplayName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false);
Player.SendChatFrom(who, who.color + who.DisplayName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false);
who.titlecolor = color;
Database.AddParams("@Color", Colors.Name(color));

View File

@ -44,11 +44,11 @@ namespace MCGalaxy.Commands {
if (newTitle.Length > 17) { Player.SendMessage(p, "Title must be under 17 letters."); return; }
if (newTitle == "") {
Player.GlobalChat(who, who.color + who.prefix + who.name + " %Shad their title removed.", false);
Player.SendChatFrom(who, who.color + who.prefix + who.name + " %Shad their title removed.", false);
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET Title = '' WHERE Name = @Name");
} else {
Player.GlobalChat(who, who.color + who.name + " %Swas given the title of &b[" + newTitle + "%b]", false);
Player.SendChatFrom(who, who.color + who.name + " %Swas given the title of &b[" + newTitle + "%b]", false);
Database.AddParams("@Title", newTitle);
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET Title = @Title WHERE Name = @Name");

View File

@ -185,7 +185,7 @@ namespace MCGalaxy {
Lvl.SetTile(x, (ushort)(LiquidLevel - yy), z, Block.lava); //better fill the water above me
} else if (LiquidLevel - yy > y - 3) {
if (overlay[index] < 0.9f) {
byte block = yy < yy ? Block.lava : Block.rock;
byte block = yy < y ? Block.lava : Block.rock;
Lvl.SetTile(x, (ushort)(y - yy), z, block);
} else {
Lvl.SetTile(x, (ushort)(LiquidLevel - yy), (ushort)(z - 5), Block.lava); //killer lava

View File

@ -1464,7 +1464,7 @@ return;
case Block.fishlavashark: Chat.GlobalChatLevel(this, this.FullName + Server.DefaultColor + " was eaten by a ... LAVA SHARK?!", false); break;
case Block.rock:
if ( explode ) level.MakeExplosion(x, y, z, 1);
GlobalChat(this, this.FullName + Server.DefaultColor + customMessage, false);
SendChatFrom(this, this.FullName + Server.DefaultColor + customMessage, false);
break;
case Block.stone:
if ( explode ) level.MakeExplosion(x, y, z, 1);
@ -1499,7 +1499,8 @@ return;
}
if ( Server.deathcount )
if ( overallDeath > 0 && overallDeath % 10 == 0 ) GlobalChat(this, this.FullName + Server.DefaultColor + " has died &3" + overallDeath + " times", false);
if ( overallDeath > 0 && overallDeath % 10 == 0 )
SendChatFrom(this, this.FullName + Server.DefaultColor + " has died &3" + overallDeath + " times", false);
}
lastDeath = DateTime.Now;
@ -1647,23 +1648,10 @@ try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { }
return;
}
}
//CmdVoteKick core vote recorder
if ( Server.voteKickInProgress && text.Length == 1 ) {
if ( text.ToLower() == "y" ) {
this.voteKickChoice = VoteKickChoice.Yes;
SendMessage("Thanks for voting!");
return;
}
if ( text.ToLower() == "n" ) {
this.voteKickChoice = VoteKickChoice.No;
SendMessage("Thanks for voting!");
return;
}
}
if (VoteHandles(text)) return;
// Put this after vote collection so that people can vote even when chat is moderated
if ( Server.chatmod && !this.voice ) { this.SendMessage("Chat moderation is on, you cannot speak."); return; }
if ( Server.chatmod && !voice ) { this.SendMessage("Chat moderation is on, you cannot speak."); return; }
// Filter out bad words
if ( Server.profanityFilter ) {
@ -1785,7 +1773,7 @@ return;
newtext = text.Remove(0, 1).Trim();
Chat.GlobalChatWorld(this, newtext, true);
} else {
GlobalChat(this, newtext);
SendChatFrom(this, newtext);
}
Server.s.Log("<" + name + "> " + newtext);
//IRCBot.Say("<" + name + "> " + newtext);
@ -1807,7 +1795,7 @@ return;
return;
}
if ( Server.worldChat ) {
GlobalChat(this, text);
SendChatFrom(this, text);
} else {
Chat.GlobalChatLevel(this, text, true);
}
@ -1816,6 +1804,46 @@ return;
}
catch ( Exception e ) { Server.ErrorLog(e); Player.GlobalMessage("An error occurred: " + e.Message); }
}
bool VoteHandles(string text) {
if (Server.voteKickInProgress && text.Length == 1) {
if (text.ToLower() == "y") {
this.voteKickChoice = VoteKickChoice.Yes;
SendMessage("Thanks for voting!");
return true;
} else if (text.ToLower() == "n") {
this.voteKickChoice = VoteKickChoice.No;
SendMessage("Thanks for voting!");
return true;
}
}
if (Server.lava.HasPlayer(this) && Server.lava.HasVote(text.ToLower()) ) {
if (Server.lava.AddVote(this, text.ToLower())) {
SendMessage("Your vote for &5" + text.ToLower().Capitalize() + Server.DefaultColor + " has been placed. Thanks!");
Server.lava.map.ChatLevelOps(name + " voted for &5" + text.ToLower().Capitalize() + Server.DefaultColor + ".");
return true;
} else {
SendMessage("&cYou already voted!");
return true;
}
}
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.votingforlevel && Server.zombie.HandlesChatMessage(this, text))
return true;
return false;
}
public void HandleCommand(string cmd, string message) {
try {
if ( Server.verifyadmins ) {
@ -2036,34 +2064,14 @@ return;
PlayerInfo.players.ForEach(delegate(Player p) { if ( p.level == level ) { p.SendBlockchange(x, y, z, type, extType); } });
}
// THIS IS NOT FOR SENDING GLOBAL MESSAGES!!! IT IS TO SEND A MESSAGE FROM A SPECIFIED PLAYER!!!!!!!!!!!!!!
public static void GlobalChat(Player from, string message) { GlobalChat(from, message, true); }
public static void GlobalChat(Player from, string message, bool showname) {
[Obsolete("Use SendChatFrom() instead.")]
public static void GlobalChat(Player from, string message) { SendChatFrom(from, message, true); }
[Obsolete("Use SendChatFrom() instead.")]
public static void GlobalChat(Player from, string message, bool showname) { SendChatFrom(from, message, showname); }
public static void SendChatFrom(Player from, string message) { SendChatFrom(from, message, true); }
public static void SendChatFrom(Player from, string message, bool showname) {
if ( from == null ) return; // So we don't fucking derp the hell out!
if ( Server.lava.HasPlayer(from) && Server.lava.HasVote(message.ToLower()) ) {
if ( Server.lava.AddVote(from, message.ToLower()) ) {
SendMessage(from, "Your vote for &5" + message.ToLower().Capitalize() + Server.DefaultColor + " has been placed. Thanks!");
Server.lava.map.ChatLevelOps(from.name + " voted for &5" + message.ToLower().Capitalize() + Server.DefaultColor + ".");
return;
} else {
SendMessage(from, "&cYou already voted!");
return;
}
}
if (Server.voting) {
string test = message.ToLower();
if (CheckVote(test, from, "y", "yes", ref Server.YesVotes) ||
CheckVote(test, from, "n", "no", ref Server.NoVotes)) return;
if (!from.voice && (test == "y" || test == "n" || test == "yes" || test == "no")) {
from.SendMessage("Chat moderation is on while voting is on!"); return;
}
}
if (Server.votingforlevel && Server.zombie.HandlesChatMessage(from, message))
return;
if (Last50Chat.Count() == 50)
Last50Chat.RemoveAt(0);
@ -2319,7 +2327,7 @@ return;
}
else {
totalKicked++;
GlobalChat(this, "&c- " + color + prefix + DisplayName + Server.DefaultColor + " kicked (" + kickString + Server.DefaultColor + ").", false);
SendChatFrom(this, "&c- " + color + prefix + DisplayName + Server.DefaultColor + " kicked (" + kickString + Server.DefaultColor + ").", false);
//IRCBot.Say(name + " kicked (" + kickString + ").");
Server.s.Log(name + " kicked (" + kickString + ").");
}