r106503 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106502‎ | r106503 | r106504 >
Date:11:18, 17 December 2011
Author:petrb
Status:deferred
Tags:
Comment:
Implemented new feature to check a user id
Modified paths:
  • /trunk/tools/wmib/Core.cs (modified) (history)

Diff [purge]

Index: trunk/tools/wmib/Core.cs
@@ -25,6 +25,12 @@
2626 private static System.IO.StreamWriter wd;
2727 private static List<user> User = new List<user>();
2828
 29+ public class messages
 30+ {
 31+ public static readonly string PermissionDenied = "Permission denied";
 32+ public static readonly string Authorization = "You are not authorized to perform this, sorry";
 33+ }
 34+
2935 public class user
3036 {
3137 /// <summary>
@@ -977,7 +983,7 @@
978984 }
979985 } else
980986 {
981 - Message("Permission denied", chan.name);
 987+ Message(messages.PermissionDenied, chan.name);
982988 }
983989 }
984990 }
@@ -991,7 +997,7 @@
992998 /// <param name="message">Message</param>
993999 public static void partChannel(config.channel chan, string user, string host, string message)
9941000 {
995 - if (message.StartsWith("@drop"))
 1001+ if (message == "@drop")
9961002 {
9971003 if (chan.Users.isApproved(user, host, "admin"))
9981004 {
@@ -1002,13 +1008,15 @@
10031009 System.IO.File.Delete(chan.name + ".setting");
10041010 config.channels.Remove(chan);
10051011 config.Save();
 1012+ return;
10061013 }
10071014 else
10081015 {
1009 - Message("Permission denied", chan.name);
 1016+ Message(messages.PermissionDenied, chan.name);
 1017+ return;
10101018 }
10111019 }
1012 - if (message.StartsWith("@part"))
 1020+ if (message == "@part")
10131021 {
10141022 if (chan.Users.isApproved(user, host, "admin"))
10151023 {
@@ -1019,33 +1027,44 @@
10201028 config.Save();
10211029 } else
10221030 {
1023 - Message("Permission denied", chan.name);
 1031+ Message(messages.PermissionDenied, chan.name);
 1032+ return;
10241033 }
10251034 }
10261035 }
10271036
 1037+ /// <summary>
 1038+ /// Display admin command
 1039+ /// </summary>
 1040+ /// <param name="chan"></param>
 1041+ /// <param name="user"></param>
 1042+ /// <param name="host"></param>
 1043+ /// <param name="message"></param>
10281044 public static void admin(config.channel chan, string user, string host, string message)
10291045 {
1030 - if (message.StartsWith("@reload"))
 1046+ if (message == "@reload")
10311047 {
10321048 if (chan.Users.isApproved(user, host, "admin"))
10331049 {
10341050 chan.LoadConfig();
10351051 chan.Keys = new dictionary(chan.keydb, chan.name);
10361052 Message("Channel config was reloaded", chan.name);
 1053+ return;
10371054 }
10381055 else
10391056 {
1040 - Message("Permission denied", chan.name);
 1057+ Message(messages.PermissionDenied, chan.name);
 1058+ return;
10411059 }
10421060 }
1043 - if (message.StartsWith("@logon"))
 1061+ if (message == "@logon")
10441062 {
10451063 if (chan.Users.isApproved(user, host, "admin"))
10461064 {
10471065 if (chan.logged)
10481066 {
10491067 Message("Channel is already logged", chan.name);
 1068+ return;
10501069 }
10511070 else
10521071 {
@@ -1053,15 +1072,31 @@
10541073 chan.logged = true;
10551074 chan.SaveConfig();
10561075 config.Save();
 1076+ return;
10571077 }
10581078 }
10591079 else
10601080 {
1061 - Message("Permission denied", chan.name);
 1081+ Message(messages.PermissionDenied, chan.name);
 1082+ return;
10621083 }
10631084 }
1064 - if (message.StartsWith("@logoff"))
 1085+ if (message == "@whoami")
10651086 {
 1087+ user current = chan.Users.getUser(user + "!@" + host);
 1088+ if(current.level == "null")
 1089+ {
 1090+ Message("You are unknown to me :)", chan.name);
 1091+ return;
 1092+ } else
 1093+ {
 1094+ Message("You are " + current.level + " identified by name " + current.name, chan.name);
 1095+ return;
 1096+ }
 1097+ }
 1098+
 1099+ if (message == "@logoff")
 1100+ {
10661101 if (chan.Users.isApproved(user, host, "admin"))
10671102 {
10681103 if (!chan.logged)
@@ -1075,11 +1110,12 @@
10761111 config.Save();
10771112 chan.SaveConfig();
10781113 Message("Channel is not logged", chan.name);
 1114+ return;
10791115 }
10801116 }
10811117 else
10821118 {
1083 - Message("Permission denied", chan.name);
 1119+ Message(messages.PermissionDenied, chan.name);
10841120 }
10851121 }
10861122 if (message.StartsWith("@channellist"))
@@ -1092,13 +1128,14 @@
10931129 Message("I am now in following channels: " + channels, chan.name);
10941130 return;
10951131 }
1096 - if (message.StartsWith("@infobot-off"))
 1132+ if (message == "@infobot-off")
10971133 {
10981134 if (chan.Users.isApproved(user, host, "admin"))
10991135 {
11001136 if (!chan.info)
11011137 {
11021138 Message("Channel had infobot disabled", chan.name);
 1139+ return;
11031140 }
11041141 else
11051142 {
@@ -1106,21 +1143,23 @@
11071144 chan.info = false;
11081145 chan.SaveConfig();
11091146 config.Save();
 1147+ return;
11101148 }
11111149 }
11121150 else
11131151 {
1114 - Message("Permission denied", chan.name);
 1152+ Message(messages.PermissionDenied, chan.name);
11151153 return;
11161154 }
11171155 }
1118 - if (message.StartsWith("@infobot-on"))
 1156+ if (message == "@infobot-on")
11191157 {
11201158 if (chan.Users.isApproved(user, host, "admin"))
11211159 {
11221160 if (!chan.logged)
11231161 {
11241162 Message("Infobot was already enabled :O", chan.name);
 1163+ return;
11251164 }
11261165 else
11271166 {
@@ -1128,16 +1167,19 @@
11291168 config.Save();
11301169 chan.SaveConfig();
11311170 Message("Infobot enabled", chan.name);
 1171+ return;
11321172 }
11331173 }
11341174 else
11351175 {
1136 - Message("Permission denied", chan.name);
 1176+ Message(messages.PermissionDenied, chan.name);
 1177+ return;
11371178 }
11381179 }
1139 - if (message.StartsWith("@commands"))
 1180+ if (message == "@commands")
11401181 {
1141 - Message("Commands: channellist, trusted, trustadd, trustdel, infobot-off, infobot-on, drop, add, reload, logon, logoff", chan.name);
 1182+ Message("Commands: channellist, trusted, trustadd, trustdel, infobot-off, infobot-on, drop, whoami, add, reload, logon, logoff", chan.name);
 1183+ return;
11421184 }
11431185 }
11441186
@@ -1161,8 +1203,11 @@
11621204 }
11631205 if (message.StartsWith("@"))
11641206 {
1165 - curr.Keys.Find(message, curr);
1166 - curr.Keys.RSearch(message, curr);
 1207+ if (curr.info)
 1208+ {
 1209+ curr.Keys.Find(message, curr);
 1210+ curr.Keys.RSearch(message, curr);
 1211+ }
11671212 modifyRights(message, curr, nick, host);
11681213 addChannel(curr, nick, host, message);
11691214 admin(curr, nick, host, message);

Status & tagging log