Index: trunk/tools/wmib/Core.cs |
— | — | @@ -110,6 +110,14 @@ |
111 | 111 | return true; |
112 | 112 | } |
113 | 113 | |
| 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 | + |
114 | 122 | /// <summary> |
115 | 123 | /// New |
116 | 124 | /// </summary> |
— | — | @@ -765,7 +773,7 @@ |
766 | 774 | /// </summary> |
767 | 775 | /// <param name="ex">Exception pointer</param> |
768 | 776 | /// <param name="chan">Channel name</param> |
769 | | - public static void handleException(Exception ex, string chan) |
| 777 | + public static void handleException(Exception ex, string chan = "") |
770 | 778 | { |
771 | 779 | if (config.debugchan != null) |
772 | 780 | { |
— | — | @@ -951,41 +959,50 @@ |
952 | 960 | /// <param name="message">Message</param> |
953 | 961 | public static void addChannel(config.channel chan, string user, string host, string message) |
954 | 962 | { |
955 | | - if (message.StartsWith("@add")) |
| 963 | + try |
956 | 964 | { |
957 | | - if (chan.Users.isApproved(user, host, "admin")) |
| 965 | + if (message.StartsWith("@add")) |
958 | 966 | { |
959 | | - if (message.Contains(" ")) |
| 967 | + if (chan.Users.isApproved(user, host, "admin")) |
960 | 968 | { |
961 | | - string channel=message.Substring(message.IndexOf(" ") + 1); |
962 | | - if (channel.Contains(" ") || (channel.Contains("#") == false)) |
| 969 | + if (message.Contains(" ")) |
963 | 970 | { |
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)) |
970 | 973 | { |
| 974 | + Message("Invalid name", chan.name); |
971 | 975 | return; |
972 | 976 | } |
| 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); |
973 | 991 | } |
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 |
982 | 998 | { |
983 | | - Message("Invalid name", chan.name); |
| 999 | + Message(messages.PermissionDenied, chan.name); |
984 | 1000 | } |
985 | | - } else |
986 | | - { |
987 | | - Message(messages.PermissionDenied, chan.name); |
988 | 1001 | } |
989 | 1002 | } |
| 1003 | + catch (Exception b) |
| 1004 | + { |
| 1005 | + |
| 1006 | + } |
990 | 1007 | } |
991 | 1008 | |
992 | 1009 | /// <summary> |
— | — | @@ -997,39 +1014,51 @@ |
998 | 1015 | /// <param name="message">Message</param> |
999 | 1016 | public static void partChannel(config.channel chan, string user, string host, string message) |
1000 | 1017 | { |
1001 | | - if (message == "@drop") |
| 1018 | + try |
1002 | 1019 | { |
1003 | | - if (chan.Users.isApproved(user, host, "admin")) |
| 1020 | + if (message == "@drop") |
1004 | 1021 | { |
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 | + } |
1013 | 1042 | } |
1014 | | - else |
| 1043 | + if (message == "@part") |
1015 | 1044 | { |
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 | + } |
1018 | 1058 | } |
1019 | 1059 | } |
1020 | | - if (message == "@part") |
| 1060 | + catch (Exception x) |
1021 | 1061 | { |
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); |
1034 | 1063 | } |
1035 | 1064 | } |
1036 | 1065 | |
— | — | @@ -1118,7 +1147,7 @@ |
1119 | 1148 | Message(messages.PermissionDenied, chan.name); |
1120 | 1149 | } |
1121 | 1150 | } |
1122 | | - if (message.StartsWith("@channellist")) |
| 1151 | + if (message == "@channellist") |
1123 | 1152 | { |
1124 | 1153 | string channels = ""; |
1125 | 1154 | foreach (config.channel a in config.channels) |
— | — | @@ -1340,7 +1369,7 @@ |
1341 | 1370 | } |
1342 | 1371 | if (message.StartsWith(":" + delimiter.ToString() + "PING")) |
1343 | 1372 | { |
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)); |
1345 | 1374 | wd.Flush(); |
1346 | 1375 | continue; |
1347 | 1376 | } |
— | — | @@ -1366,7 +1395,7 @@ |
1367 | 1396 | } |
1368 | 1397 | catch (System.IO.IOException xx) |
1369 | 1398 | { |
1370 | | - Program.Log("Reconnecting, connection failed"); |
| 1399 | + Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace); |
1371 | 1400 | Reconnect(); |
1372 | 1401 | } |
1373 | 1402 | catch (Exception xx) |