DB: now block changes by IRC properly log to BlockDB, including the irc user's nick.

This commit is contained in:
UnknownShadow200 2016-12-24 19:09:35 +11:00
parent 8f89e79afe
commit 9e419f71fb
10 changed files with 50 additions and 37 deletions

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Commands {
bool addToList = p.parseEmotes != Server.parseSmiley; bool addToList = p.parseEmotes != Server.parseSmiley;
if (!addToList) Server.noEmotes.Remove(p.name); if (!addToList) Server.noEmotes.Remove(p.name);
else Server.noEmotes.AddOrReplace(p.name); else Server.noEmotes.AddIfNotExists(p.name);
Server.noEmotes.Save(); Server.noEmotes.Save();
Player.Message(p, "Emote parsing is {0}.", p.parseEmotes ? "enabled" : "disabled"); Player.Message(p, "Emote parsing is {0}.", p.parseEmotes ? "enabled" : "disabled");
} }

View File

@ -40,7 +40,7 @@ namespace MCGalaxy.Commands
Player.SendChatFrom(who, who.ColoredName + " %Swas &bfrozen %Sby " + frozenby + "%S.", false); Player.SendChatFrom(who, who.ColoredName + " %Swas &bfrozen %Sby " + frozenby + "%S.", false);
Server.s.Log(who.name + " was frozen by " + frozenby); Server.s.Log(who.name + " was frozen by " + frozenby);
Player.AddNote(who.name, p, "F"); Player.AddNote(who.name, p, "F");
Server.frozen.AddOrReplace(who.name); Server.frozen.AddIfNotExists(who.name);
} else { } else {
Player.SendChatFrom(who, who.ColoredName + " %Swas &adefrosted %Sby " + frozenby + "%S.", false); Player.SendChatFrom(who, who.ColoredName + " %Swas &adefrosted %Sby " + frozenby + "%S.", false);
Server.s.Log(who.name + " was defrosted by " + frozenby); Server.s.Log(who.name + " was defrosted by " + frozenby);

View File

@ -66,7 +66,7 @@ namespace MCGalaxy.Commands {
Player.SendChatFrom(p, "&c- " + p.FullName + " %S" + discMsg, false); Player.SendChatFrom(p, "&c- " + p.FullName + " %S" + discMsg, false);
Server.IRC.Say(p.DisplayName + " %Sleft the game (" + discMsg + "%S)"); Server.IRC.Say(p.DisplayName + " %Sleft the game (" + discMsg + "%S)");
if (messageOps && !p.opchat) opchat.Use(p, message); if (messageOps && !p.opchat) opchat.Use(p, message);
Server.hidden.AddOrReplace(p.name); Server.hidden.AddIfNotExists(p.name);
} else { } else {
Entities.GlobalSpawn(p, false); Entities.GlobalSpawn(p, false);
p.otherRankHidden = false; p.otherRankHidden = false;

View File

@ -50,7 +50,7 @@ namespace MCGalaxy.Commands.Moderation {
} }
who.muted = true; who.muted = true;
Player.SendChatFrom(who, who.ColoredName + " %Swas &8muted", false); Player.SendChatFrom(who, who.ColoredName + " %Swas &8muted", false);
Server.muted.AddOrReplace(who.name); Server.muted.AddIfNotExists(who.name);
Player.AddNote(who.name, p, "M"); Player.AddNote(who.name, p, "M");
} }
Server.muted.Save(); Server.muted.Save();

View File

@ -48,7 +48,7 @@ namespace MCGalaxy.Commands {
Server.lockdown.Remove(args[1]); Server.lockdown.Remove(args[1]);
Chat.MessageOps("Unlocked by: " + srcName); Chat.MessageOps("Unlocked by: " + srcName);
} else { } else {
Server.lockdown.AddOrReplace(args[1]); Server.lockdown.AddIfNotExists(args[1]);
Chat.MessageOps("Locked by: " + srcName); Chat.MessageOps("Locked by: " + srcName);
} }
Server.lockdown.Save(); Server.lockdown.Save();

View File

@ -51,5 +51,13 @@ namespace MCGalaxy.DB {
} }
return ids; return ids;
} }
public static int InvalidNameID(string name) {
bool added = Server.invalidIds.AddIfNotExists(name);
if (added) Server.invalidIds.Save();
int index = Server.invalidIds.All().IndexOf(name.ToLower());
return int.MaxValue - index;
}
} }
} }

View File

@ -14,12 +14,13 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using MCGalaxy.Commands; using MCGalaxy.Commands;
using MCGalaxy.DB;
using Sharkbite.Irc; using Sharkbite.Irc;
namespace MCGalaxy { namespace MCGalaxy {
@ -301,7 +302,7 @@ namespace MCGalaxy {
if (!whoCmd || (DateTime.UtcNow - last).TotalSeconds <= 1) return false; if (!whoCmd || (DateTime.UtcNow - last).TotalSeconds <= 1) return false;
try { try {
Player p = MakeIRCPlayer(nick); Player p = MakeIRCPlayer(nick, null);
CmdPlayers.DisplayPlayers(p, "", false, false); CmdPlayers.DisplayPlayers(p, "", false, false);
} catch (Exception e) { } catch (Exception e) {
Server.ErrorLog(e); Server.ErrorLog(e);
@ -312,13 +313,13 @@ namespace MCGalaxy {
return true; return true;
} }
bool HandleIRCCommand(string nick, string logNick, string cmdName, string cmdArgs) { bool HandleIRCCommand(string nick, string userNick, string cmdName, string cmdArgs) {
Command cmd = Command.all.Find(cmdName); Command cmd = Command.all.Find(cmdName);
Player p = MakeIRCPlayer(nick); Player p = MakeIRCPlayer(nick, userNick);
if (cmd == null) { Player.Message(p, "Unknown command!"); return false; } if (cmd == null) { Player.Message(p, "Unknown command!"); return false; }
string logCmd = cmdArgs == "" ? cmdName : cmdName + " " + cmdArgs; string logCmd = cmdArgs == "" ? cmdName : cmdName + " " + cmdArgs;
Server.s.Log("IRC Command: /" + logCmd + " (by " + logNick + ")"); Server.s.Log("IRC Command: /" + logCmd + " (by " + userNick + ")");
try { try {
if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return false; } if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return false; }
@ -349,13 +350,17 @@ namespace MCGalaxy {
return true; return true;
} }
static Player MakeIRCPlayer(string ircNick) { static Player MakeIRCPlayer(string ircNick, string userNick) {
Player p = new Player("IRC"); Player p = new Player("IRC");
p.group = Group.findPerm(Server.ircControllerRank); p.group = Group.findPerm(Server.ircControllerRank);
if (p.group == null) if (p.group == null)
p.group = Group.findPerm(LevelPermission.Nobody); p.group = Group.findPerm(LevelPermission.Nobody);
p.ircNick = ircNick; p.ircNick = ircNick;
p.color = "&a"; return p; p.color = "&a";
if (userNick != null)
p.UserID = NameConverter.InvalidNameID("(IRC " + userNick + ")");
return p;
} }
void Listener_OnRegistered() { void Listener_OnRegistered() {

View File

@ -51,16 +51,17 @@ namespace MCGalaxy {
public int Count { get { lock (locker) return players.Count; } } public int Count { get { lock (locker) return players.Count; } }
/// <summary> Adds or replaces the given name, /// <summary> Adds or replaces the given name. </summary>
/// returning the index of the item within the list. </summary> /// <returns> Whether the given player name was added to the list. </returns>
public void AddOrReplace(string p) { public bool AddIfNotExists(string p) {
p = p.ToLower(); p = p.ToLower();
lock (locker) { lock (locker) {
int idx = players.IndexOf(p); int idx = players.IndexOf(p);
if (idx >= 0) return; if (idx >= 0) return false;
players.Add(p); players.Add(p);
} }
return true;
} }
public string FindMatches(Player p, string name, string type, out int matches) { public string FindMatches(Player p, string name, string type, out int matches) {

View File

@ -17,6 +17,7 @@
*/ */
using System; using System;
using System.Data; using System.Data;
using MCGalaxy.DB;
using MCGalaxy.SQL; using MCGalaxy.SQL;
namespace MCGalaxy { namespace MCGalaxy {
@ -52,9 +53,7 @@ namespace MCGalaxy {
string id = ids.Rows[0]["ID"].ToString(); string id = ids.Rows[0]["ID"].ToString();
p.UserID = PlayerData.ParseInt(id); p.UserID = PlayerData.ParseInt(id);
} else { } else {
Server.invalidIds.AddOrReplace(p.name); p.UserID = NameConverter.InvalidNameID(p.name);
int index = Server.invalidIds.All().IndexOf(p.name.ToLower());
p.UserID = int.MaxValue - index;
} }
} }
} }

View File

@ -137,7 +137,7 @@ namespace MCGalaxy.Tasks {
for (int i = 0; i < files.Length; i++) { for (int i = 0; i < files.Length; i++) {
File.Delete(files[i]); File.Delete(files[i]);
string level = Path.GetFileName(files[i]); string level = Path.GetFileName(files[i]);
Server.lockdown.AddOrReplace(level); Server.lockdown.AddIfNotExists(level);
} }
Server.lockdown.Save(); Server.lockdown.Save();