Index: trunk/tools/wmib/Core.cs |
— | — | @@ -25,6 +25,12 @@ |
26 | 26 | private static System.IO.StreamWriter wd; |
27 | 27 | private static List<user> User = new List<user>(); |
28 | 28 | |
| 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 | + |
29 | 35 | public class user |
30 | 36 | { |
31 | 37 | /// <summary> |
— | — | @@ -977,7 +983,7 @@ |
978 | 984 | } |
979 | 985 | } else |
980 | 986 | { |
981 | | - Message("Permission denied", chan.name); |
| 987 | + Message(messages.PermissionDenied, chan.name); |
982 | 988 | } |
983 | 989 | } |
984 | 990 | } |
— | — | @@ -991,7 +997,7 @@ |
992 | 998 | /// <param name="message">Message</param> |
993 | 999 | public static void partChannel(config.channel chan, string user, string host, string message) |
994 | 1000 | { |
995 | | - if (message.StartsWith("@drop")) |
| 1001 | + if (message == "@drop") |
996 | 1002 | { |
997 | 1003 | if (chan.Users.isApproved(user, host, "admin")) |
998 | 1004 | { |
— | — | @@ -1002,13 +1008,15 @@ |
1003 | 1009 | System.IO.File.Delete(chan.name + ".setting"); |
1004 | 1010 | config.channels.Remove(chan); |
1005 | 1011 | config.Save(); |
| 1012 | + return; |
1006 | 1013 | } |
1007 | 1014 | else |
1008 | 1015 | { |
1009 | | - Message("Permission denied", chan.name); |
| 1016 | + Message(messages.PermissionDenied, chan.name); |
| 1017 | + return; |
1010 | 1018 | } |
1011 | 1019 | } |
1012 | | - if (message.StartsWith("@part")) |
| 1020 | + if (message == "@part") |
1013 | 1021 | { |
1014 | 1022 | if (chan.Users.isApproved(user, host, "admin")) |
1015 | 1023 | { |
— | — | @@ -1019,33 +1027,44 @@ |
1020 | 1028 | config.Save(); |
1021 | 1029 | } else |
1022 | 1030 | { |
1023 | | - Message("Permission denied", chan.name); |
| 1031 | + Message(messages.PermissionDenied, chan.name); |
| 1032 | + return; |
1024 | 1033 | } |
1025 | 1034 | } |
1026 | 1035 | } |
1027 | 1036 | |
| 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> |
1028 | 1044 | public static void admin(config.channel chan, string user, string host, string message) |
1029 | 1045 | { |
1030 | | - if (message.StartsWith("@reload")) |
| 1046 | + if (message == "@reload") |
1031 | 1047 | { |
1032 | 1048 | if (chan.Users.isApproved(user, host, "admin")) |
1033 | 1049 | { |
1034 | 1050 | chan.LoadConfig(); |
1035 | 1051 | chan.Keys = new dictionary(chan.keydb, chan.name); |
1036 | 1052 | Message("Channel config was reloaded", chan.name); |
| 1053 | + return; |
1037 | 1054 | } |
1038 | 1055 | else |
1039 | 1056 | { |
1040 | | - Message("Permission denied", chan.name); |
| 1057 | + Message(messages.PermissionDenied, chan.name); |
| 1058 | + return; |
1041 | 1059 | } |
1042 | 1060 | } |
1043 | | - if (message.StartsWith("@logon")) |
| 1061 | + if (message == "@logon") |
1044 | 1062 | { |
1045 | 1063 | if (chan.Users.isApproved(user, host, "admin")) |
1046 | 1064 | { |
1047 | 1065 | if (chan.logged) |
1048 | 1066 | { |
1049 | 1067 | Message("Channel is already logged", chan.name); |
| 1068 | + return; |
1050 | 1069 | } |
1051 | 1070 | else |
1052 | 1071 | { |
— | — | @@ -1053,15 +1072,31 @@ |
1054 | 1073 | chan.logged = true; |
1055 | 1074 | chan.SaveConfig(); |
1056 | 1075 | config.Save(); |
| 1076 | + return; |
1057 | 1077 | } |
1058 | 1078 | } |
1059 | 1079 | else |
1060 | 1080 | { |
1061 | | - Message("Permission denied", chan.name); |
| 1081 | + Message(messages.PermissionDenied, chan.name); |
| 1082 | + return; |
1062 | 1083 | } |
1063 | 1084 | } |
1064 | | - if (message.StartsWith("@logoff")) |
| 1085 | + if (message == "@whoami") |
1065 | 1086 | { |
| 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 | + { |
1066 | 1101 | if (chan.Users.isApproved(user, host, "admin")) |
1067 | 1102 | { |
1068 | 1103 | if (!chan.logged) |
— | — | @@ -1075,11 +1110,12 @@ |
1076 | 1111 | config.Save(); |
1077 | 1112 | chan.SaveConfig(); |
1078 | 1113 | Message("Channel is not logged", chan.name); |
| 1114 | + return; |
1079 | 1115 | } |
1080 | 1116 | } |
1081 | 1117 | else |
1082 | 1118 | { |
1083 | | - Message("Permission denied", chan.name); |
| 1119 | + Message(messages.PermissionDenied, chan.name); |
1084 | 1120 | } |
1085 | 1121 | } |
1086 | 1122 | if (message.StartsWith("@channellist")) |
— | — | @@ -1092,13 +1128,14 @@ |
1093 | 1129 | Message("I am now in following channels: " + channels, chan.name); |
1094 | 1130 | return; |
1095 | 1131 | } |
1096 | | - if (message.StartsWith("@infobot-off")) |
| 1132 | + if (message == "@infobot-off") |
1097 | 1133 | { |
1098 | 1134 | if (chan.Users.isApproved(user, host, "admin")) |
1099 | 1135 | { |
1100 | 1136 | if (!chan.info) |
1101 | 1137 | { |
1102 | 1138 | Message("Channel had infobot disabled", chan.name); |
| 1139 | + return; |
1103 | 1140 | } |
1104 | 1141 | else |
1105 | 1142 | { |
— | — | @@ -1106,21 +1143,23 @@ |
1107 | 1144 | chan.info = false; |
1108 | 1145 | chan.SaveConfig(); |
1109 | 1146 | config.Save(); |
| 1147 | + return; |
1110 | 1148 | } |
1111 | 1149 | } |
1112 | 1150 | else |
1113 | 1151 | { |
1114 | | - Message("Permission denied", chan.name); |
| 1152 | + Message(messages.PermissionDenied, chan.name); |
1115 | 1153 | return; |
1116 | 1154 | } |
1117 | 1155 | } |
1118 | | - if (message.StartsWith("@infobot-on")) |
| 1156 | + if (message == "@infobot-on") |
1119 | 1157 | { |
1120 | 1158 | if (chan.Users.isApproved(user, host, "admin")) |
1121 | 1159 | { |
1122 | 1160 | if (!chan.logged) |
1123 | 1161 | { |
1124 | 1162 | Message("Infobot was already enabled :O", chan.name); |
| 1163 | + return; |
1125 | 1164 | } |
1126 | 1165 | else |
1127 | 1166 | { |
— | — | @@ -1128,16 +1167,19 @@ |
1129 | 1168 | config.Save(); |
1130 | 1169 | chan.SaveConfig(); |
1131 | 1170 | Message("Infobot enabled", chan.name); |
| 1171 | + return; |
1132 | 1172 | } |
1133 | 1173 | } |
1134 | 1174 | else |
1135 | 1175 | { |
1136 | | - Message("Permission denied", chan.name); |
| 1176 | + Message(messages.PermissionDenied, chan.name); |
| 1177 | + return; |
1137 | 1178 | } |
1138 | 1179 | } |
1139 | | - if (message.StartsWith("@commands")) |
| 1180 | + if (message == "@commands") |
1140 | 1181 | { |
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; |
1142 | 1184 | } |
1143 | 1185 | } |
1144 | 1186 | |
— | — | @@ -1161,8 +1203,11 @@ |
1162 | 1204 | } |
1163 | 1205 | if (message.StartsWith("@")) |
1164 | 1206 | { |
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 | + } |
1167 | 1212 | modifyRights(message, curr, nick, host); |
1168 | 1213 | addChannel(curr, nick, host, message); |
1169 | 1214 | admin(curr, nick, host, message); |