r106513 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106512‎ | r106513 | r106514 >
Date:18:23, 17 December 2011
Author:petrb
Status:deferred
Tags:
Comment:
Fixed several bugs
Modified paths:
  • /trunk/tools/wmib/Core.cs (modified) (history)

Diff [purge]

Index: trunk/tools/wmib/Core.cs
@@ -110,6 +110,14 @@
111111 return true;
112112 }
113113
 114+ public static string normalize(string name)
 115+ {
 116+ name = name.Replace("|", "\\|");
 117+ name = name.Replace("]", "\\]");
 118+ name = name.Replace("[", "\\[");
 119+ return name;
 120+ }
 121+
114122 /// <summary>
115123 /// New
116124 /// </summary>
@@ -765,7 +773,7 @@
766774 /// </summary>
767775 /// <param name="ex">Exception pointer</param>
768776 /// <param name="chan">Channel name</param>
769 - public static void handleException(Exception ex, string chan)
 777+ public static void handleException(Exception ex, string chan = "")
770778 {
771779 if (config.debugchan != null)
772780 {
@@ -951,41 +959,50 @@
952960 /// <param name="message">Message</param>
953961 public static void addChannel(config.channel chan, string user, string host, string message)
954962 {
955 - if (message.StartsWith("@add"))
 963+ try
956964 {
957 - if (chan.Users.isApproved(user, host, "admin"))
 965+ if (message.StartsWith("@add"))
958966 {
959 - if (message.Contains(" "))
 967+ if (chan.Users.isApproved(user, host, "admin"))
960968 {
961 - string channel=message.Substring(message.IndexOf(" ") + 1);
962 - if (channel.Contains(" ") || (channel.Contains("#") == false))
 969+ if (message.Contains(" "))
963970 {
964 - Message("Invalid name", chan.name);
965 - return;
966 - }
967 - foreach (config.channel cu in config.channels)
968 - {
969 - if (channel == cu.name)
 971+ string channel = message.Substring(message.IndexOf(" ") + 1);
 972+ if (channel.Contains(" ") || channel.Contains("|") || channel.Contains("/") || (channel.Contains("#") == false))
970973 {
 974+ Message("Invalid name", chan.name);
971975 return;
972976 }
 977+ foreach (config.channel cu in config.channels)
 978+ {
 979+ if (channel == cu.name)
 980+ {
 981+ return;
 982+ }
 983+ }
 984+ config.channels.Add(new config.channel(channel));
 985+ config.Save();
 986+ wd.WriteLine("JOIN " + channel);
 987+ wd.Flush();
 988+ System.Threading.Thread.Sleep(100);
 989+ config.channel Chan = getChannel(channel);
 990+ Chan.Users.addUser("admin", IRCTrust.normalize(user) + "!.*@" + host);
973991 }
974 - config.channels.Add(new config.channel(channel));
975 - config.Save();
976 - wd.WriteLine("JOIN " + channel);
977 - wd.Flush();
978 - System.Threading.Thread.Sleep(100);
979 - config.channel Chan = getChannel(channel);
980 - Chan.Users.addUser("admin", user + "!.*@" + host );
981 - } else
 992+ else
 993+ {
 994+ Message("Invalid name", chan.name);
 995+ }
 996+ }
 997+ else
982998 {
983 - Message("Invalid name", chan.name);
 999+ Message(messages.PermissionDenied, chan.name);
9841000 }
985 - } else
986 - {
987 - Message(messages.PermissionDenied, chan.name);
9881001 }
9891002 }
 1003+ catch (Exception b)
 1004+ {
 1005+
 1006+ }
9901007 }
9911008
9921009 /// <summary>
@@ -997,39 +1014,51 @@
9981015 /// <param name="message">Message</param>
9991016 public static void partChannel(config.channel chan, string user, string host, string message)
10001017 {
1001 - if (message == "@drop")
 1018+ try
10021019 {
1003 - if (chan.Users.isApproved(user, host, "admin"))
 1020+ if (message == "@drop")
10041021 {
1005 - wd.WriteLine("PART " + chan.name);
1006 - System.Threading.Thread.Sleep(100);
1007 - System.IO.File.Delete(chan.Users.File);
1008 - wd.Flush();
1009 - System.IO.File.Delete(chan.name + ".setting");
1010 - config.channels.Remove(chan);
1011 - config.Save();
1012 - return;
 1022+ if (chan.Users.isApproved(user, host, "admin"))
 1023+ {
 1024+ wd.WriteLine("PART " + chan.name);
 1025+ System.Threading.Thread.Sleep(100);
 1026+ wd.Flush();
 1027+ if (!System.IO.Directory.Exists(chan.log))
 1028+ {
 1029+ System.IO.Directory.Delete(chan.log, true);
 1030+ }
 1031+ System.IO.File.Delete(chan.name + ".setting");
 1032+ System.IO.File.Delete(chan.Users.File);
 1033+ config.channels.Remove(chan);
 1034+ config.Save();
 1035+ return;
 1036+ }
 1037+ else
 1038+ {
 1039+ Message(messages.PermissionDenied, chan.name);
 1040+ return;
 1041+ }
10131042 }
1014 - else
 1043+ if (message == "@part")
10151044 {
1016 - Message(messages.PermissionDenied, chan.name);
1017 - return;
 1045+ if (chan.Users.isApproved(user, host, "admin"))
 1046+ {
 1047+ wd.WriteLine("PART " + chan.name);
 1048+ System.Threading.Thread.Sleep(100);
 1049+ wd.Flush();
 1050+ config.channels.Remove(chan);
 1051+ config.Save();
 1052+ }
 1053+ else
 1054+ {
 1055+ Message(messages.PermissionDenied, chan.name);
 1056+ return;
 1057+ }
10181058 }
10191059 }
1020 - if (message == "@part")
 1060+ catch (Exception x)
10211061 {
1022 - if (chan.Users.isApproved(user, host, "admin"))
1023 - {
1024 - wd.WriteLine("PART " + chan.name);
1025 - System.Threading.Thread.Sleep(100);
1026 - wd.Flush();
1027 - config.channels.Remove(chan);
1028 - config.Save();
1029 - } else
1030 - {
1031 - Message(messages.PermissionDenied, chan.name);
1032 - return;
1033 - }
 1062+ handleException(x);
10341063 }
10351064 }
10361065
@@ -1118,7 +1147,7 @@
11191148 Message(messages.PermissionDenied, chan.name);
11201149 }
11211150 }
1122 - if (message.StartsWith("@channellist"))
 1151+ if (message == "@channellist")
11231152 {
11241153 string channels = "";
11251154 foreach (config.channel a in config.channels)
@@ -1340,7 +1369,7 @@
13411370 }
13421371 if (message.StartsWith(":" + delimiter.ToString() + "PING"))
13431372 {
1344 - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING " + message.Substring(message.IndexOf(delimiter.ToString() + "PING" + 6)));
 1373+ wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" + message.Substring(message.IndexOf(delimiter.ToString() + "PING")+5));
13451374 wd.Flush();
13461375 continue;
13471376 }
@@ -1366,7 +1395,7 @@
13671396 }
13681397 catch (System.IO.IOException xx)
13691398 {
1370 - Program.Log("Reconnecting, connection failed");
 1399+ Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace);
13711400 Reconnect();
13721401 }
13731402 catch (Exception xx)

Status & tagging log