Index: trunk/tools/wmib/DumpHtm.cs |
— | — | @@ -8,8 +8,16 @@ |
9 | 9 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | 10 | //GNU General Public License for more details. |
11 | 11 | |
| 12 | + |
| 13 | + |
12 | 14 | using System; |
| 15 | +using System.Collections.Generic; |
| 16 | +using System.IO; |
| 17 | +using System.Text; |
| 18 | +using System.Threading; |
| 19 | +using System.Net; |
13 | 20 | |
| 21 | + |
14 | 22 | namespace wmib |
15 | 23 | { |
16 | 24 | public class HtmlDump |
— | — | @@ -18,12 +26,10 @@ |
19 | 27 | /// Channel name |
20 | 28 | /// </summary> |
21 | 29 | public config.channel Channel; |
22 | | - |
23 | 30 | /// <summary> |
24 | 31 | /// Dump |
25 | 32 | /// </summary> |
26 | 33 | public string dumpname; |
27 | | - |
28 | 34 | // This function is called on start of bot |
29 | 35 | public static void Start() |
30 | 36 | { |
— | — | @@ -31,15 +37,16 @@ |
32 | 38 | { |
33 | 39 | foreach (config.channel chan in config.channels) |
34 | 40 | { |
35 | | - if (!chan.Keys.update) continue; |
36 | | - HtmlDump dump = new HtmlDump(chan); |
37 | | - dump.Make(); |
38 | | - chan.Keys.update = false; |
| 41 | + if (chan.Keys.update) |
| 42 | + { |
| 43 | + HtmlDump dump = new HtmlDump(chan); |
| 44 | + dump.Make(); |
| 45 | + chan.Keys.update = false; |
| 46 | + } |
39 | 47 | } |
40 | | - System.Threading.Thread.Sleep(320000); |
| 48 | + Thread.Sleep(320000); |
41 | 49 | } |
42 | 50 | } |
43 | | - |
44 | 51 | /// <summary> |
45 | 52 | /// Constructor |
46 | 53 | /// </summary> |
— | — | @@ -98,12 +105,13 @@ |
99 | 106 | { |
100 | 107 | try |
101 | 108 | { |
102 | | - string text = CreateHeader(); |
103 | | - text += "<table border=1 width=100%>\n<tr><td width=10%>Key</td><td>Value</td></tr>\n"; |
| 109 | + string text; |
| 110 | + text = CreateHeader(); |
| 111 | + text = text + "<table border=1 width=100%>\n<tr><td width=10%>Key</td><td>Value</td></tr>\n"; |
104 | 112 | Channel.Keys.locked = true; |
105 | 113 | if (Channel.Keys.text.Count > 0) |
106 | 114 | { |
107 | | - foreach (irc.dictionary.item Key in Channel.Keys.text) |
| 115 | + foreach (dictionary.item Key in Channel.Keys.text) |
108 | 116 | { |
109 | 117 | text = text + AddLine(Key.key, Key.text); |
110 | 118 | } |
— | — | @@ -111,7 +119,7 @@ |
112 | 120 | Channel.Keys.locked = false; |
113 | 121 | text = text + "<table>\n"; |
114 | 122 | text = text + CreateFooter(); |
115 | | - System.IO.File.WriteAllText(dumpname, text); |
| 123 | + File.WriteAllText(dumpname, text); |
116 | 124 | } |
117 | 125 | catch (Exception b) |
118 | 126 | { |
Index: trunk/tools/wmib/Config.cs |
— | — | @@ -10,6 +10,7 @@ |
11 | 11 | |
12 | 12 | // Created by Petr Bena benapetr@gmail.com |
13 | 13 | |
| 14 | +using System; |
14 | 15 | using System.Collections.Generic; |
15 | 16 | using System.IO; |
16 | 17 | |
— | — | @@ -36,7 +37,7 @@ |
37 | 38 | /// <summary> |
38 | 39 | /// Keys |
39 | 40 | /// </summary> |
40 | | - public irc.dictionary Keys; |
| 41 | + public dictionary Keys; |
41 | 42 | |
42 | 43 | /// <summary> |
43 | 44 | /// Configuration text |
— | — | @@ -76,17 +77,17 @@ |
77 | 78 | return; |
78 | 79 | } |
79 | 80 | conf = File.ReadAllText(conf_file); |
80 | | - if (parseConfig(conf, "keysdb") != "") |
| 81 | + if (config.parseConfig(conf, "keysdb") != "") |
81 | 82 | { |
82 | | - keydb = (parseConfig(conf, "keysdb")); |
| 83 | + keydb = (config.parseConfig(conf, "keysdb")); |
83 | 84 | } |
84 | | - if (parseConfig(conf, "logged") != "") |
| 85 | + if (config.parseConfig(conf, "logged") != "") |
85 | 86 | { |
86 | | - logged = bool.Parse(parseConfig(conf, "logged")); |
| 87 | + logged = bool.Parse(config.parseConfig(conf, "logged")); |
87 | 88 | } |
88 | | - if (parseConfig(conf, "infodb") != "") |
| 89 | + if (config.parseConfig(conf, "infodb") != "") |
89 | 90 | { |
90 | | - info = bool.Parse(parseConfig(conf, "infodb")); |
| 91 | + info = bool.Parse(config.parseConfig(conf, "infodb")); |
91 | 92 | } |
92 | 93 | } |
93 | 94 | |
— | — | @@ -111,7 +112,7 @@ |
112 | 113 | conf = ""; |
113 | 114 | keydb = Name + ".db"; |
114 | 115 | info = true; |
115 | | - logged = true; |
| 116 | + logged = false; |
116 | 117 | name = Name; |
117 | 118 | LoadConfig(); |
118 | 119 | if (!Directory.Exists("log")) |
— | — | @@ -122,7 +123,7 @@ |
123 | 124 | { |
124 | 125 | Directory.CreateDirectory("log/" + Name); |
125 | 126 | } |
126 | | - Keys = new irc.dictionary(keydb, name); |
| 127 | + Keys = new dictionary(keydb, name); |
127 | 128 | log = "log/" + Name + "/"; |
128 | 129 | Users = new irc.IRCTrust(name); |
129 | 130 | } |
— | — | @@ -178,39 +179,46 @@ |
179 | 180 | /// </summary> |
180 | 181 | public static void Load() |
181 | 182 | { |
182 | | - text = File.ReadAllText("wmib"); |
183 | | - foreach (string x in parseConfig(text, "channels").Replace("\n", "").Split(',')) |
| 183 | + try |
184 | 184 | { |
185 | | - string config = x.Replace(" ", ""); |
186 | | - if (config != "") |
| 185 | + text = File.ReadAllText("wmib"); |
| 186 | + foreach (string x in parseConfig(text, "channels").Replace("\n", "").Split(',')) |
187 | 187 | { |
188 | | - channels.Add(new channel(config)); |
| 188 | + string name = x.Replace(" ", ""); |
| 189 | + if (!(name == "")) |
| 190 | + { |
| 191 | + channels.Add(new channel(name)); |
| 192 | + } |
189 | 193 | } |
| 194 | + username = parseConfig(text, "username"); |
| 195 | + network = parseConfig(text, "network"); |
| 196 | + login = parseConfig(text, "nick"); |
| 197 | + debugchan = parseConfig(text, "debug"); |
| 198 | + password = parseConfig(text, "password"); |
190 | 199 | } |
191 | | - username = parseConfig(text, "username"); |
192 | | - network = parseConfig(text, "network"); |
193 | | - login = parseConfig(text, "nick"); |
194 | | - debugchan = parseConfig(text, "debug"); |
195 | | - password = parseConfig(text, "password"); |
196 | | - if (!Directory.Exists(DumpDir)) |
| 200 | + catch (Exception ex) |
197 | 201 | { |
198 | | - Directory.CreateDirectory(DumpDir); |
| 202 | + irc.handleException(ex); |
199 | 203 | } |
| 204 | + if (!Directory.Exists(config.DumpDir)) |
| 205 | + { |
| 206 | + Directory.CreateDirectory(config.DumpDir); |
| 207 | + } |
| 208 | + |
200 | 209 | } |
201 | | - |
202 | 210 | public static string text; |
203 | | - |
204 | 211 | /// <summary> |
205 | 212 | /// Network |
206 | 213 | /// </summary> |
| 214 | + /// |
207 | 215 | public static string network = "irc.freenode.net"; |
208 | | - |
209 | 216 | /// <summary> |
210 | 217 | /// Nick name |
211 | 218 | /// </summary> |
| 219 | + /// |
212 | 220 | public static string username = "wm-bot"; |
213 | 221 | |
214 | | - public static string debugchan = ""; |
| 222 | + public static string debugchan = null; |
215 | 223 | |
216 | 224 | /// <summary> |
217 | 225 | /// Login name |
Index: trunk/tools/wmib/Program.cs |
— | — | @@ -11,18 +11,21 @@ |
12 | 12 | // Created by Petr Bena benapetr@gmail.com |
13 | 13 | |
14 | 14 | using System; |
| 15 | +using System.Collections.Generic; |
| 16 | +using System.Text; |
| 17 | +using System.Net; |
15 | 18 | |
| 19 | + |
16 | 20 | namespace wmib |
17 | 21 | { |
18 | | - internal class Program |
| 22 | + class Program |
19 | 23 | { |
20 | | - public static bool Log(string msg) |
| 24 | + public static bool Log(string msg ) |
21 | 25 | { |
22 | 26 | Console.WriteLine("LOG: " + msg); |
23 | 27 | return false; |
24 | 28 | } |
25 | | - |
26 | | - private static void Main(string[] args) |
| 29 | + static void Main(string[] args) |
27 | 30 | { |
28 | 31 | Log("Connecting"); |
29 | 32 | config.Load(); |
Index: trunk/tools/wmib/Core.cs |
— | — | @@ -10,10 +10,12 @@ |
11 | 11 | |
12 | 12 | using System; |
13 | 13 | using System.Collections.Generic; |
14 | | -using System.IO; |
15 | | -using System.Text.RegularExpressions; |
16 | 14 | using System.Threading; |
| 15 | +using System.Text.RegularExpressions; |
| 16 | +using System.Net; |
| 17 | +using System.IO; |
17 | 18 | |
| 19 | + |
18 | 20 | namespace wmib |
19 | 21 | { |
20 | 22 | public class misc |
— | — | @@ -34,14 +36,14 @@ |
35 | 37 | return true; |
36 | 38 | } |
37 | 39 | } |
38 | | - |
39 | 40 | public class irc |
40 | 41 | { |
| 42 | + public static Thread _Queue; |
41 | 43 | private static System.Net.Sockets.NetworkStream data; |
42 | 44 | public static Thread dumphtmt; |
43 | 45 | public static Thread check_thread; |
44 | | - public static StreamReader rd; |
45 | | - private static StreamWriter wd; |
| 46 | + public static System.IO.StreamReader rd; |
| 47 | + private static System.IO.StreamWriter wd; |
46 | 48 | private static List<user> User = new List<user>(); |
47 | 49 | |
48 | 50 | public class messages |
— | — | @@ -56,12 +58,10 @@ |
57 | 59 | /// Regex |
58 | 60 | /// </summary> |
59 | 61 | public string name; |
60 | | - |
61 | 62 | /// <summary> |
62 | 63 | /// Level |
63 | 64 | /// </summary> |
64 | 65 | public string level; |
65 | | - |
66 | 66 | /// <summary> |
67 | 67 | /// Constructor |
68 | 68 | /// </summary> |
— | — | @@ -74,30 +74,73 @@ |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
| 78 | + public class SlowQueue |
| 79 | + { |
| 80 | + public struct Message |
| 81 | + { |
| 82 | + public string message; |
| 83 | + public string channel; |
| 84 | + } |
| 85 | + public static List<Message> messages = new List<Message>(); |
| 86 | + public static List<Message> newmessages = new List<Message>(); |
| 87 | + private static bool locked; |
| 88 | + |
| 89 | + public static void DeliverMessage(string Message, string Channel) |
| 90 | + { |
| 91 | + Message text = new Message(); |
| 92 | + text.message = Message; |
| 93 | + text.channel = Channel; |
| 94 | + if (locked) |
| 95 | + { |
| 96 | + newmessages.Add(text); |
| 97 | + return; |
| 98 | + } |
| 99 | + messages.Add(text); |
| 100 | + } |
| 101 | + |
| 102 | + public static void Run() |
| 103 | + { |
| 104 | + while (true) |
| 105 | + { |
| 106 | + locked = true; |
| 107 | + foreach (Message message in messages) |
| 108 | + { |
| 109 | + irc.Message(message.message, message.channel); |
| 110 | + Thread.Sleep(2000); |
| 111 | + } |
| 112 | + messages.Clear(); |
| 113 | + locked = false; |
| 114 | + foreach (Message message in newmessages) |
| 115 | + { |
| 116 | + messages.Add(message); |
| 117 | + } |
| 118 | + newmessages.Clear(); |
| 119 | + Thread.Sleep(200); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
78 | 124 | public class RegexCheck |
79 | 125 | { |
80 | 126 | public string value; |
81 | 127 | public string regex; |
82 | 128 | public bool searching; |
83 | | - public bool result; |
84 | | - |
| 129 | + public bool result = false; |
85 | 130 | public RegexCheck(string Regex, string Data) |
86 | 131 | { |
87 | 132 | result = false; |
88 | 133 | value = Data; |
89 | 134 | regex = Regex; |
90 | 135 | } |
91 | | - |
92 | 136 | private void Run() |
93 | 137 | { |
94 | 138 | Regex c = new Regex(regex); |
95 | 139 | result = c.Match(value).Success; |
96 | 140 | searching = false; |
97 | 141 | } |
98 | | - |
99 | 142 | public int IsMatch() |
100 | 143 | { |
101 | | - Thread quick = new Thread(Run); |
| 144 | + Thread quick = new Thread(new ThreadStart(Run)); |
102 | 145 | searching = true; |
103 | 146 | quick.Start(); |
104 | 147 | int check = 0; |
— | — | @@ -105,30 +148,36 @@ |
106 | 149 | { |
107 | 150 | check++; |
108 | 151 | Thread.Sleep(10); |
109 | | - if (check <= 50) continue; |
110 | | - quick.Abort(); |
111 | | - return 2; |
| 152 | + if (check > 50) |
| 153 | + { |
| 154 | + quick.Abort(); |
| 155 | + return 2; |
| 156 | + } |
112 | 157 | } |
113 | | - return result ? 1 : 0; |
| 158 | + if (result) |
| 159 | + { |
| 160 | + return 1; |
| 161 | + } |
| 162 | + return 0; |
114 | 163 | } |
115 | 164 | } |
116 | 165 | |
117 | 166 | public class IRCTrust |
118 | 167 | { |
| 168 | + private List<user> GlobalUsers = new List<user>(); |
119 | 169 | /// <summary> |
120 | 170 | /// List of all users in a channel |
121 | 171 | /// </summary> |
122 | 172 | private List<user> Users = new List<user>(); |
123 | | - |
| 173 | + |
124 | 174 | /// <summary> |
125 | 175 | /// Channel this class belong to |
126 | 176 | /// </summary> |
127 | 177 | public string _Channel; |
128 | | - |
129 | 178 | /// <summary> |
130 | 179 | /// File where data are stored |
131 | 180 | /// </summary> |
132 | | - public string DataFile; |
| 181 | + public string File; |
133 | 182 | |
134 | 183 | /// <summary> |
135 | 184 | /// Constructor |
— | — | @@ -137,14 +186,20 @@ |
138 | 187 | public IRCTrust(string channel) |
139 | 188 | { |
140 | 189 | // Load |
141 | | - DataFile = channel + "_user"; |
142 | | - if (!File.Exists(DataFile)) |
| 190 | + File = channel + "_user"; |
| 191 | + if (!System.IO.File.Exists(File)) |
143 | 192 | { |
144 | 193 | // Create db |
145 | 194 | Program.Log("Creating user file for " + channel); |
146 | | - File.WriteAllText(DataFile, ""); |
| 195 | + System.IO.File.WriteAllText(File, ""); |
147 | 196 | } |
148 | | - string[] db = File.ReadAllLines(channel + "_user"); |
| 197 | + if (!System.IO.File.Exists("admins")) |
| 198 | + { |
| 199 | + // Create db |
| 200 | + Program.Log("Creating user file for admins"); |
| 201 | + System.IO.File.WriteAllText("admins", ""); |
| 202 | + } |
| 203 | + string[] db = System.IO.File.ReadAllLines(channel + "_user"); |
149 | 204 | _Channel = channel; |
150 | 205 | foreach (string x in db) |
151 | 206 | { |
— | — | @@ -156,6 +211,18 @@ |
157 | 212 | Users.Add(new user(level, name)); |
158 | 213 | } |
159 | 214 | } |
| 215 | + string[] dba = System.IO.File.ReadAllLines("admins"); |
| 216 | + _Channel = channel; |
| 217 | + foreach (string x in dba) |
| 218 | + { |
| 219 | + if (x.Contains(config.separator)) |
| 220 | + { |
| 221 | + string[] info = x.Split(Char.Parse(config.separator)); |
| 222 | + string level = info[1]; |
| 223 | + string name = decode(info[0]); |
| 224 | + GlobalUsers.Add(new user(level, name)); |
| 225 | + } |
| 226 | + } |
160 | 227 | } |
161 | 228 | |
162 | 229 | /// <summary> |
— | — | @@ -164,10 +231,10 @@ |
165 | 232 | /// <returns></returns> |
166 | 233 | public bool Save() |
167 | 234 | { |
168 | | - File.WriteAllText(DataFile, ""); |
| 235 | + System.IO.File.WriteAllText(File, ""); |
169 | 236 | foreach (user u in Users) |
170 | 237 | { |
171 | | - File.AppendAllText(DataFile, encode(u.name) + config.separator + u.level + "\n"); |
| 238 | + System.IO.File.AppendAllText(File, encode(u.name) + config.separator + u.level + "\n"); |
172 | 239 | } |
173 | 240 | return true; |
174 | 241 | } |
— | — | @@ -256,6 +323,18 @@ |
257 | 324 | { |
258 | 325 | user lv = new user("null", ""); |
259 | 326 | int current = 0; |
| 327 | + foreach (user b in GlobalUsers) |
| 328 | + { |
| 329 | + RegexCheck id = new RegexCheck(b.name, user); |
| 330 | + if (id.IsMatch() == 1) |
| 331 | + { |
| 332 | + if (getLevel(b.level) > current) |
| 333 | + { |
| 334 | + current = getLevel(b.level); |
| 335 | + lv = b; |
| 336 | + } |
| 337 | + } |
| 338 | + } |
260 | 339 | foreach (user b in Users) |
261 | 340 | { |
262 | 341 | RegexCheck id = new RegexCheck(b.name, user); |
— | — | @@ -279,7 +358,7 @@ |
280 | 359 | string users_ok = ""; |
281 | 360 | foreach (user b in Users) |
282 | 361 | { |
283 | | - users_ok += users_ok + " " + b.name + ","; |
| 362 | + users_ok = users_ok + " " + b.name + ","; |
284 | 363 | } |
285 | 364 | Message("I trust: " + users_ok, _Channel); |
286 | 365 | } |
— | — | @@ -334,500 +413,6 @@ |
335 | 414 | } |
336 | 415 | } |
337 | 416 | |
338 | | - public class dictionary |
339 | | - { |
340 | | - /// <summary> |
341 | | - /// Data file |
342 | | - /// </summary> |
343 | | - public string datafile = ""; |
344 | | - |
345 | | - // if we need to update dump |
346 | | - public bool update = true; |
347 | | - |
348 | | - /// <summary> |
349 | | - /// Locked |
350 | | - /// </summary> |
351 | | - public bool locked; |
352 | | - |
353 | | - public class item |
354 | | - { |
355 | | - /// <summary> |
356 | | - /// Text |
357 | | - /// </summary> |
358 | | - public string text; |
359 | | - |
360 | | - /// <summary> |
361 | | - /// Key |
362 | | - /// </summary> |
363 | | - public string key; |
364 | | - |
365 | | - public string user; |
366 | | - public string locked; |
367 | | - |
368 | | - /// <summary> |
369 | | - /// Constructor |
370 | | - /// </summary> |
371 | | - /// <param name="Key">Key</param> |
372 | | - /// <param name="Text">Text of the key</param> |
373 | | - /// <param name="User">User who created the key</param> |
374 | | - /// <param name="Lock">If key is locked or not</param> |
375 | | - public item(string Key, string Text, string User, string Lock = "false") |
376 | | - { |
377 | | - text = Text; |
378 | | - key = Key; |
379 | | - locked = Lock; |
380 | | - user = User; |
381 | | - } |
382 | | - } |
383 | | - |
384 | | - public class staticalias |
385 | | - { |
386 | | - /// <summary> |
387 | | - /// Name |
388 | | - /// </summary> |
389 | | - public string Name; |
390 | | - |
391 | | - /// <summary> |
392 | | - /// Key |
393 | | - /// </summary> |
394 | | - public string Key; |
395 | | - |
396 | | - /// <summary> |
397 | | - /// Constructor |
398 | | - /// </summary> |
399 | | - /// <param name="name">Alias</param> |
400 | | - /// <param name="key">Key</param> |
401 | | - public staticalias(string name, string key) |
402 | | - { |
403 | | - Name = name; |
404 | | - Key = key; |
405 | | - } |
406 | | - } |
407 | | - |
408 | | - /// <summary> |
409 | | - /// List of all items in class |
410 | | - /// </summary> |
411 | | - public List<item> text = new List<item>(); |
412 | | - |
413 | | - /// <summary> |
414 | | - /// List of all aliases we want to use |
415 | | - /// </summary> |
416 | | - public List<staticalias> Alias = new List<staticalias>(); |
417 | | - |
418 | | - /// <summary> |
419 | | - /// Channel name |
420 | | - /// </summary> |
421 | | - public string Channel; |
422 | | - |
423 | | - private bool running; |
424 | | - private string search_key; |
425 | | - |
426 | | - /// <summary> |
427 | | - /// Load it |
428 | | - /// </summary> |
429 | | - public void Load() |
430 | | - { |
431 | | - text.Clear(); |
432 | | - if (!File.Exists(datafile)) |
433 | | - { |
434 | | - // Create db |
435 | | - File.WriteAllText(datafile, ""); |
436 | | - } |
437 | | - |
438 | | - string[] db = File.ReadAllLines(datafile); |
439 | | - foreach (string x in db) |
440 | | - { |
441 | | - if (x.Contains(config.separator)) |
442 | | - { |
443 | | - string[] info = x.Split(Char.Parse(config.separator)); |
444 | | - string type = info[2]; |
445 | | - string value = info[1]; |
446 | | - string name = info[0]; |
447 | | - if (type == "key") |
448 | | - { |
449 | | - string locked = info[3]; |
450 | | - text.Add(new item(name, value, "", locked)); |
451 | | - } |
452 | | - else |
453 | | - { |
454 | | - Alias.Add(new staticalias(name, value)); |
455 | | - } |
456 | | - } |
457 | | - } |
458 | | - } |
459 | | - |
460 | | - /// <summary> |
461 | | - /// Constructor |
462 | | - /// </summary> |
463 | | - /// <param name="database"></param> |
464 | | - /// <param name="channel"></param> |
465 | | - public dictionary(string database, string channel) |
466 | | - { |
467 | | - datafile = database; |
468 | | - Channel = channel; |
469 | | - Load(); |
470 | | - } |
471 | | - |
472 | | - /// <summary> |
473 | | - /// Save to a file |
474 | | - /// </summary> |
475 | | - public void Save() |
476 | | - { |
477 | | - update = true; |
478 | | - try |
479 | | - { |
480 | | - File.WriteAllText(datafile, ""); |
481 | | - foreach (staticalias key in Alias) |
482 | | - { |
483 | | - File.AppendAllText(datafile, |
484 | | - key.Name + config.separator + key.Key + config.separator + "alias" + "\n"); |
485 | | - } |
486 | | - foreach (item key in text) |
487 | | - { |
488 | | - File.AppendAllText(datafile, |
489 | | - key.key + config.separator + key.text + config.separator + "key" + |
490 | | - config.separator + key.locked + config.separator + key.user + "\n"); |
491 | | - } |
492 | | - } |
493 | | - catch (Exception b) |
494 | | - { |
495 | | - handleException(b, Channel); |
496 | | - } |
497 | | - } |
498 | | - |
499 | | - /// <summary> |
500 | | - /// Get value of key |
501 | | - /// </summary> |
502 | | - /// <param name="key">Key</param> |
503 | | - /// <returns></returns> |
504 | | - public string getValue(string key) |
505 | | - { |
506 | | - foreach (item data in text) |
507 | | - { |
508 | | - if (data.key == key) |
509 | | - { |
510 | | - return decode(data.text); |
511 | | - } |
512 | | - } |
513 | | - return ""; |
514 | | - } |
515 | | - |
516 | | - /// <summary> |
517 | | - /// Print a value to channel if found this message doesn't need to be a valid command |
518 | | - /// </summary> |
519 | | - /// <param name="name">Name</param> |
520 | | - /// <param name="user">User</param> |
521 | | - /// <param name="chan">Channel</param> |
522 | | - /// <param name="host">Host name</param> |
523 | | - /// <returns></returns> |
524 | | - public bool print(string name, string user, config.channel chan, string host) |
525 | | - { |
526 | | - if (!name.StartsWith("!")) |
527 | | - { |
528 | | - return true; |
529 | | - } |
530 | | - name = name.Substring(1); |
531 | | - if (name.Contains(" ")) |
532 | | - { |
533 | | - string[] parm = name.Split(' '); |
534 | | - if (parm[1] == "is") |
535 | | - { |
536 | | - config.channel _Chan = getChannel(Channel); |
537 | | - if (chan.Users.isApproved(user, host, "info")) |
538 | | - { |
539 | | - if (parm.Length < 3) |
540 | | - { |
541 | | - Message("It would be cool to give me also a text of key", Channel); |
542 | | - return true; |
543 | | - } |
544 | | - string key = name.Substring(name.IndexOf(" is") + 4); |
545 | | - setKey(key, parm[0], ""); |
546 | | - } |
547 | | - else |
548 | | - { |
549 | | - Message("You are not autorized to perform this, sorry", Channel); |
550 | | - } |
551 | | - return false; |
552 | | - } |
553 | | - if (parm[1] == "alias") |
554 | | - { |
555 | | - config.channel _Chan = getChannel(Channel); |
556 | | - if (chan.Users.isApproved(user, host, "info")) |
557 | | - { |
558 | | - if (parm.Length < 3) |
559 | | - { |
560 | | - Message("It would be cool to give me also a name of key", Channel); |
561 | | - return true; |
562 | | - } |
563 | | - aliasKey(name.Substring(name.IndexOf(" alias") + 7), parm[0], ""); |
564 | | - } |
565 | | - else |
566 | | - { |
567 | | - Message("You are not autorized to perform this, sorry", Channel); |
568 | | - } |
569 | | - return false; |
570 | | - } |
571 | | - if (parm[1] == "unalias") |
572 | | - { |
573 | | - config.channel _Chan = getChannel(Channel); |
574 | | - if (chan.Users.isApproved(user, host, "info")) |
575 | | - { |
576 | | - foreach (staticalias b in Alias) |
577 | | - { |
578 | | - if (b.Name == parm[0]) |
579 | | - { |
580 | | - Alias.Remove(b); |
581 | | - Message("Alias removed", Channel); |
582 | | - Save(); |
583 | | - return false; |
584 | | - } |
585 | | - } |
586 | | - return false; |
587 | | - } |
588 | | - Message("You are not autorized to perform this, sorry", Channel); |
589 | | - return false; |
590 | | - } |
591 | | - if (parm[1] == "del") |
592 | | - { |
593 | | - if (chan.Users.isApproved(user, host, "info")) |
594 | | - { |
595 | | - rmKey(parm[0], ""); |
596 | | - } |
597 | | - else |
598 | | - { |
599 | | - Message("You are not autorized to perform this, sorry", Channel); |
600 | | - } |
601 | | - return false; |
602 | | - } |
603 | | - } |
604 | | - string User = ""; |
605 | | - if (name.Contains("|")) |
606 | | - { |
607 | | - User = name.Substring(name.IndexOf("|")); |
608 | | - User = User.Replace("|", ""); |
609 | | - User = User.Replace(" ", ""); |
610 | | - name = name.Substring(0, name.IndexOf("|")); |
611 | | - } |
612 | | - string[] p = name.Split(' '); |
613 | | - int parameters = p.Length; |
614 | | - string keyv = getValue(p[0]); |
615 | | - if (keyv != "") |
616 | | - { |
617 | | - if (parameters > 1) |
618 | | - { |
619 | | - int curr = 1; |
620 | | - while (parameters > curr) |
621 | | - { |
622 | | - keyv = keyv.Replace("$" + curr.ToString(), p[curr]); |
623 | | - curr++; |
624 | | - } |
625 | | - } |
626 | | - if (User == "") |
627 | | - { |
628 | | - Message(keyv, Channel); |
629 | | - } |
630 | | - else |
631 | | - { |
632 | | - Message(User + ": " + keyv, Channel); |
633 | | - } |
634 | | - return true; |
635 | | - } |
636 | | - foreach (staticalias b in Alias) |
637 | | - { |
638 | | - if (b.Name == p[0]) |
639 | | - { |
640 | | - keyv = getValue(b.Key); |
641 | | - if (keyv != "") |
642 | | - { |
643 | | - if (parameters > 1) |
644 | | - { |
645 | | - int curr = 1; |
646 | | - while (parameters > curr) |
647 | | - { |
648 | | - keyv = keyv.Replace("$" + curr.ToString(), p[curr]); |
649 | | - curr++; |
650 | | - } |
651 | | - } |
652 | | - if (User == "") |
653 | | - { |
654 | | - Message(keyv, Channel); |
655 | | - } |
656 | | - else |
657 | | - { |
658 | | - Message(User + ":" + keyv, Channel); |
659 | | - } |
660 | | - return true; |
661 | | - } |
662 | | - } |
663 | | - } |
664 | | - return true; |
665 | | - } |
666 | | - |
667 | | - private void StartSearch() |
668 | | - { |
669 | | - Regex value = new Regex(search_key, RegexOptions.Compiled); |
670 | | - string results = ""; |
671 | | - foreach (item data in text) |
672 | | - { |
673 | | - if (data.key == search_key || value.Match(data.text).Success) |
674 | | - { |
675 | | - results = results + data.key + ", "; |
676 | | - } |
677 | | - } |
678 | | - if (results == "") |
679 | | - { |
680 | | - Message("No results found! :|", Channel); |
681 | | - } |
682 | | - else |
683 | | - { |
684 | | - Message("Results: " + results, Channel); |
685 | | - } |
686 | | - running = false; |
687 | | - } |
688 | | - |
689 | | - /// <summary> |
690 | | - /// Search |
691 | | - /// </summary> |
692 | | - /// <param name="key">Key</param> |
693 | | - /// <param name="Chan"></param> |
694 | | - public void RSearch(string key, config.channel Chan) |
695 | | - { |
696 | | - if (!key.StartsWith("@regsearch")) |
697 | | - { |
698 | | - return; |
699 | | - } |
700 | | - if (!misc.IsValidRegex(key)) |
701 | | - { |
702 | | - Message("This is pretty bad regex", Chan.name); |
703 | | - return; |
704 | | - } |
705 | | - if (key.Length < 11) |
706 | | - { |
707 | | - Message("Could you please tell me what I should search for :P", Chan.name); |
708 | | - return; |
709 | | - } |
710 | | - search_key = key.Substring(11); |
711 | | - running = true; |
712 | | - Thread th = new Thread(StartSearch); |
713 | | - th.Start(); |
714 | | - int check = 1; |
715 | | - while (running) |
716 | | - { |
717 | | - check++; |
718 | | - Thread.Sleep(10); |
719 | | - if (check > 80) |
720 | | - { |
721 | | - th.Abort(); |
722 | | - Message("Search took more than 800 micro seconds try a better regex", Channel); |
723 | | - running = false; |
724 | | - return; |
725 | | - } |
726 | | - } |
727 | | - } |
728 | | - |
729 | | - public void Find(string key, config.channel Chan) |
730 | | - { |
731 | | - if (!key.StartsWith("@search")) |
732 | | - { |
733 | | - return; |
734 | | - } |
735 | | - if (key.Length < 9) |
736 | | - { |
737 | | - Message("Could you please tell me what I should search for :P", Chan.name); |
738 | | - return; |
739 | | - } |
740 | | - key = key.Substring(8); |
741 | | - string results = ""; |
742 | | - foreach (item data in text) |
743 | | - { |
744 | | - if (data.key == key || data.text.Contains(key)) |
745 | | - { |
746 | | - results = results + data.key + ", "; |
747 | | - } |
748 | | - } |
749 | | - if (results == "") |
750 | | - { |
751 | | - Message("No results found! :|", Chan.name); |
752 | | - } |
753 | | - else |
754 | | - { |
755 | | - Message("Results: " + results, Chan.name); |
756 | | - } |
757 | | - } |
758 | | - |
759 | | - /// <summary> |
760 | | - /// Save a new key |
761 | | - /// </summary> |
762 | | - /// <param name="Text">Text</param> |
763 | | - /// <param name="key">Key</param> |
764 | | - /// <param name="user">User who created it</param> |
765 | | - public void setKey(string Text, string key, string user) |
766 | | - { |
767 | | - while (locked) |
768 | | - { |
769 | | - Thread.Sleep(200); |
770 | | - } |
771 | | - try |
772 | | - { |
773 | | - foreach (item data in text) |
774 | | - { |
775 | | - if (data.key == key) |
776 | | - { |
777 | | - Message("Key exist!", Channel); |
778 | | - return; |
779 | | - } |
780 | | - } |
781 | | - text.Add(new item(key, encode(Text), user, "false")); |
782 | | - Message("Key was added!", Channel); |
783 | | - Save(); |
784 | | - } |
785 | | - catch (Exception b) |
786 | | - { |
787 | | - handleException(b, Channel); |
788 | | - } |
789 | | - } |
790 | | - |
791 | | - /// <summary> |
792 | | - /// Alias |
793 | | - /// </summary> |
794 | | - /// <param name="key">Key</param> |
795 | | - /// <param name="al">Alias</param> |
796 | | - /// <param name="user">User</param> |
797 | | - public void aliasKey(string key, string al, string user) |
798 | | - { |
799 | | - foreach (staticalias stakey in this.Alias) |
800 | | - { |
801 | | - if (stakey.Name == al) |
802 | | - { |
803 | | - Message("Alias is already existing!", Channel); |
804 | | - return; |
805 | | - } |
806 | | - } |
807 | | - this.Alias.Add(new staticalias(al, key)); |
808 | | - Message("Successfully created", Channel); |
809 | | - Save(); |
810 | | - } |
811 | | - |
812 | | - public void rmKey(string key, string user) |
813 | | - { |
814 | | - while (locked) |
815 | | - { |
816 | | - Thread.Sleep(200); |
817 | | - } |
818 | | - foreach (item keys in text) |
819 | | - { |
820 | | - if (keys.key == key) |
821 | | - { |
822 | | - text.Remove(keys); |
823 | | - Message("Successfully removed " + key, Channel); |
824 | | - Save(); |
825 | | - return; |
826 | | - } |
827 | | - } |
828 | | - Message("Unable to find the specified key in db", Channel); |
829 | | - } |
830 | | - } |
831 | | - |
832 | 417 | /// <summary> |
833 | 418 | /// Ping |
834 | 419 | /// </summary> |
— | — | @@ -885,7 +470,7 @@ |
886 | 471 | { |
887 | 472 | if (config.debugchan != null) |
888 | 473 | { |
889 | | - Message("DEBUG Exception: " + ex.Message + " I feel crushed, uh :|", config.debugchan); |
| 474 | + SlowQueue.DeliverMessage("DEBUG Exception: " + ex.Message + " I feel crushed, uh :|", config.debugchan); |
890 | 475 | } |
891 | 476 | Program.Log(ex.Message + ex.Source + ex.StackTrace); |
892 | 477 | } |
— | — | @@ -953,8 +538,7 @@ |
954 | 539 | { |
955 | 540 | if (rights_info.Length < 3) |
956 | 541 | { |
957 | | - Message("Wrong number of parameters, go fix it - example @trustadd regex (admin|trusted)", |
958 | | - channel.name); |
| 542 | + Message("Wrong number of parameters, go fix it - example @trustadd regex (admin|trusted)", channel.name); |
959 | 543 | return 0; |
960 | 544 | } |
961 | 545 | if (!(rights_info[2] == "admin" || rights_info[2] == "trusted")) |
— | — | @@ -973,16 +557,19 @@ |
974 | 558 | if (channel.Users.addUser(rights_info[2], rights_info[1])) |
975 | 559 | { |
976 | 560 | Message("Successfuly added " + rights_info[1], channel.name); |
| 561 | + return 0; |
977 | 562 | } |
978 | 563 | } |
979 | 564 | else |
980 | 565 | { |
981 | 566 | Message("You are not autorized to perform this, sorry", channel.name); |
| 567 | + return 0; |
982 | 568 | } |
983 | 569 | } |
984 | 570 | if (message.StartsWith("@trusted")) |
985 | 571 | { |
986 | 572 | channel.Users.listAll(); |
| 573 | + return 0; |
987 | 574 | } |
988 | 575 | if (message.StartsWith("@trustdel")) |
989 | 576 | { |
— | — | @@ -995,8 +582,11 @@ |
996 | 583 | channel.Users.delUser(rights_info[1]); |
997 | 584 | return 0; |
998 | 585 | } |
999 | | - Message("You are not autorized to perform this, sorry", channel.name); |
1000 | | - return 0; |
| 586 | + else |
| 587 | + { |
| 588 | + Message("You are not autorized to perform this, sorry", channel.name); |
| 589 | + return 0; |
| 590 | + } |
1001 | 591 | } |
1002 | 592 | Message("Invalid user", channel.name); |
1003 | 593 | } |
— | — | @@ -1025,18 +615,13 @@ |
1026 | 616 | string log; |
1027 | 617 | if (!noac) |
1028 | 618 | { |
1029 | | - log = "[" + timedateToString(DateTime.Now.Hour) + ":" + |
1030 | | - timedateToString(DateTime.Now.Minute) + ":" + |
1031 | | - timedateToString(DateTime.Now.Second) + "] * " + user + " " + message + "\n"; |
| 619 | + log = "[" + timedateToString(DateTime.Now.Hour) + ":" + timedateToString(DateTime.Now.Minute) + ":" + timedateToString(DateTime.Now.Second) + "] * " + user + " " + message + "\n"; |
1032 | 620 | } |
1033 | 621 | else |
1034 | 622 | { |
1035 | | - log = "[" + timedateToString(DateTime.Now.Hour) + ":" + |
1036 | | - timedateToString(DateTime.Now.Minute) + ":" + |
1037 | | - timedateToString(DateTime.Now.Second) + "] " + "<" + user + ">\t " + message + "\n"; |
| 623 | + log = "[" + timedateToString(DateTime.Now.Hour) + ":" + timedateToString(DateTime.Now.Minute) + ":" + timedateToString(DateTime.Now.Second) + "] " + "<" + user + ">\t " + message + "\n"; |
1038 | 624 | } |
1039 | | - File.AppendAllText( |
1040 | | - channel.log + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + ".txt", log); |
| 625 | + File.AppendAllText(channel.log + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + ".txt", log); |
1041 | 626 | } |
1042 | 627 | } |
1043 | 628 | catch (Exception er) |
— | — | @@ -1061,16 +646,9 @@ |
1062 | 647 | return false; |
1063 | 648 | } |
1064 | 649 | |
1065 | | - /// <summary> |
1066 | | - /// |
1067 | | - /// </summary> |
1068 | | - /// <param name="name"></param> |
1069 | | - /// <returns></returns> |
1070 | 650 | public static bool validFile(string name) |
1071 | 651 | { |
1072 | | - return |
1073 | | - !(name.Contains(" ") || name.Contains("?") || name.Contains("|") || name.Contains("/") || |
1074 | | - name.Contains("\\") || name.Contains(">") || name.Contains("<") || name.Contains("*")); |
| 652 | + return !(name.Contains(" ") || name.Contains("?") || name.Contains("|") || name.Contains("/") || name.Contains("\\") || name.Contains(">") || name.Contains("<") || name.Contains("*")); |
1075 | 653 | } |
1076 | 654 | |
1077 | 655 | /// <summary> |
— | — | @@ -1086,42 +664,44 @@ |
1087 | 665 | { |
1088 | 666 | if (message.StartsWith("@add")) |
1089 | 667 | { |
1090 | | - return; |
1091 | | - } |
1092 | | - if (!chan.Users.isApproved(user, host, "admin")) |
1093 | | - { |
1094 | | - Message(messages.PermissionDenied, chan.name); |
1095 | | - return; |
1096 | | - } |
1097 | | - if (!message.Contains(" ")) |
1098 | | - { |
1099 | | - Message("Invalid name", chan.name); |
1100 | | - return; |
1101 | | - } |
1102 | | - string channel = message.Substring(message.IndexOf(" ") + 1); |
1103 | | - if (!validFile(channel) || (channel.Contains("#") == false)) |
1104 | | - { |
1105 | | - Message("Invalid name", chan.name); |
1106 | | - return; |
1107 | | - } |
1108 | | - foreach (config.channel cu in config.channels) |
1109 | | - { |
1110 | | - if (channel == cu.name) |
| 668 | + if (chan.Users.isApproved(user, host, "admin")) |
1111 | 669 | { |
1112 | | - return; |
| 670 | + if (message.Contains(" ")) |
| 671 | + { |
| 672 | + string channel = message.Substring(message.IndexOf(" ") + 1); |
| 673 | + if (!validFile(channel) || (channel.Contains("#") == false)) |
| 674 | + { |
| 675 | + Message("Invalid name", chan.name); |
| 676 | + return; |
| 677 | + } |
| 678 | + foreach (config.channel cu in config.channels) |
| 679 | + { |
| 680 | + if (channel == cu.name) |
| 681 | + { |
| 682 | + return; |
| 683 | + } |
| 684 | + } |
| 685 | + config.channels.Add(new config.channel(channel)); |
| 686 | + config.Save(); |
| 687 | + wd.WriteLine("JOIN " + channel); |
| 688 | + wd.Flush(); |
| 689 | + Thread.Sleep(100); |
| 690 | + config.channel Chan = getChannel(channel); |
| 691 | + Chan.Users.addUser("admin", IRCTrust.normalize(user) + "!.*@" + host); |
| 692 | + return; |
| 693 | + } |
| 694 | + else |
| 695 | + { |
| 696 | + Message("Invalid name", chan.name); |
| 697 | + return; |
| 698 | + } |
1113 | 699 | } |
| 700 | + Message(messages.PermissionDenied, chan.name); |
1114 | 701 | } |
1115 | | - config.channels.Add(new config.channel(channel)); |
1116 | | - config.Save(); |
1117 | | - wd.WriteLine("JOIN " + channel); |
1118 | | - wd.Flush(); |
1119 | | - Thread.Sleep(100); |
1120 | | - config.channel Chan = getChannel(channel); |
1121 | | - Chan.Users.addUser("admin", IRCTrust.normalize(user) + "!.*@" + host); |
1122 | 702 | } |
1123 | | - catch (Exception) |
| 703 | + catch (Exception b) |
1124 | 704 | { |
1125 | | - |
| 705 | + handleException(b); |
1126 | 706 | } |
1127 | 707 | } |
1128 | 708 | |
— | — | @@ -1143,18 +723,26 @@ |
1144 | 724 | wd.WriteLine("PART " + chan.name); |
1145 | 725 | Thread.Sleep(100); |
1146 | 726 | wd.Flush(); |
1147 | | - if (!Directory.Exists(chan.log)) |
| 727 | + try |
1148 | 728 | { |
1149 | | - Directory.Delete(chan.log, true); |
| 729 | + if (Directory.Exists(chan.log)) |
| 730 | + { |
| 731 | + Directory.Delete(chan.log, true); |
| 732 | + } |
1150 | 733 | } |
| 734 | + catch (Exception) |
| 735 | + { } |
1151 | 736 | File.Delete(chan.name + ".setting"); |
1152 | | - File.Delete(chan.Users.DataFile); |
| 737 | + File.Delete(chan.Users.File); |
1153 | 738 | config.channels.Remove(chan); |
1154 | 739 | config.Save(); |
1155 | 740 | return; |
1156 | 741 | } |
1157 | | - Message(messages.PermissionDenied, chan.name); |
1158 | | - return; |
| 742 | + else |
| 743 | + { |
| 744 | + Message(messages.PermissionDenied, chan.name); |
| 745 | + return; |
| 746 | + } |
1159 | 747 | } |
1160 | 748 | if (message == "@part") |
1161 | 749 | { |
— | — | @@ -1165,12 +753,10 @@ |
1166 | 754 | wd.Flush(); |
1167 | 755 | config.channels.Remove(chan); |
1168 | 756 | config.Save(); |
1169 | | - } |
1170 | | - else |
1171 | | - { |
1172 | | - Message(messages.PermissionDenied, chan.name); |
1173 | 757 | return; |
1174 | 758 | } |
| 759 | + Message(messages.PermissionDenied, chan.name); |
| 760 | + return; |
1175 | 761 | } |
1176 | 762 | } |
1177 | 763 | catch (Exception x) |
— | — | @@ -1197,9 +783,30 @@ |
1198 | 784 | Message("Channel config was reloaded", chan.name); |
1199 | 785 | return; |
1200 | 786 | } |
1201 | | - Message(messages.PermissionDenied, chan.name); |
1202 | | - return; |
| 787 | + else |
| 788 | + { |
| 789 | + Message(messages.PermissionDenied, chan.name); |
| 790 | + return; |
| 791 | + } |
1203 | 792 | } |
| 793 | + if (message == "@refresh") |
| 794 | + { |
| 795 | + if (chan.Users.isApproved(user, host, "admin")) |
| 796 | + { |
| 797 | + _Queue.Abort(); |
| 798 | + SlowQueue.newmessages.Clear(); |
| 799 | + _Queue = new System.Threading.Thread(new System.Threading.ThreadStart(SlowQueue.Run)); |
| 800 | + SlowQueue.messages.Clear(); |
| 801 | + _Queue.Start(); |
| 802 | + Message("Message queue was reloaded", chan.name); |
| 803 | + return; |
| 804 | + } |
| 805 | + else |
| 806 | + { |
| 807 | + Message(messages.PermissionDenied, chan.name); |
| 808 | + return; |
| 809 | + } |
| 810 | + } |
1204 | 811 | if (message == "@logon") |
1205 | 812 | { |
1206 | 813 | if (chan.Users.isApproved(user, host, "admin")) |
— | — | @@ -1209,14 +816,20 @@ |
1210 | 817 | Message("Channel is already logged", chan.name); |
1211 | 818 | return; |
1212 | 819 | } |
1213 | | - Message("Channel is now logged", chan.name); |
1214 | | - chan.logged = true; |
1215 | | - chan.SaveConfig(); |
1216 | | - config.Save(); |
| 820 | + else |
| 821 | + { |
| 822 | + Message("Channel is now logged", chan.name); |
| 823 | + chan.logged = true; |
| 824 | + chan.SaveConfig(); |
| 825 | + config.Save(); |
| 826 | + return; |
| 827 | + } |
| 828 | + } |
| 829 | + else |
| 830 | + { |
| 831 | + SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name); |
1217 | 832 | return; |
1218 | 833 | } |
1219 | | - Message(messages.PermissionDenied, chan.name); |
1220 | | - return; |
1221 | 834 | } |
1222 | 835 | if (message == "@whoami") |
1223 | 836 | { |
— | — | @@ -1226,8 +839,11 @@ |
1227 | 840 | Message("You are unknown to me :)", chan.name); |
1228 | 841 | return; |
1229 | 842 | } |
1230 | | - Message("You are " + current.level + " identified by name " + current.name, chan.name); |
1231 | | - return; |
| 843 | + else |
| 844 | + { |
| 845 | + Message("You are " + current.level + " identified by name " + current.name, chan.name); |
| 846 | + return; |
| 847 | + } |
1232 | 848 | } |
1233 | 849 | |
1234 | 850 | if (message == "@logoff") |
— | — | @@ -1239,13 +855,20 @@ |
1240 | 856 | Message("Channel was already not logged", chan.name); |
1241 | 857 | return; |
1242 | 858 | } |
1243 | | - chan.logged = false; |
1244 | | - config.Save(); |
1245 | | - chan.SaveConfig(); |
1246 | | - Message("Channel is not logged", chan.name); |
| 859 | + else |
| 860 | + { |
| 861 | + chan.logged = false; |
| 862 | + config.Save(); |
| 863 | + chan.SaveConfig(); |
| 864 | + Message("Channel is not logged", chan.name); |
| 865 | + return; |
| 866 | + } |
| 867 | + } |
| 868 | + else |
| 869 | + { |
| 870 | + SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name); |
1247 | 871 | return; |
1248 | 872 | } |
1249 | | - Message(messages.PermissionDenied, chan.name); |
1250 | 873 | } |
1251 | 874 | if (message == "@channellist") |
1252 | 875 | { |
— | — | @@ -1266,14 +889,20 @@ |
1267 | 890 | Message("Channel had infobot disabled", chan.name); |
1268 | 891 | return; |
1269 | 892 | } |
1270 | | - Message("Infobot disabled", chan.name); |
1271 | | - chan.info = false; |
1272 | | - chan.SaveConfig(); |
1273 | | - config.Save(); |
| 893 | + else |
| 894 | + { |
| 895 | + Message("Infobot disabled", chan.name); |
| 896 | + chan.info = false; |
| 897 | + chan.SaveConfig(); |
| 898 | + config.Save(); |
| 899 | + return; |
| 900 | + } |
| 901 | + } |
| 902 | + else |
| 903 | + { |
| 904 | + SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name); |
1274 | 905 | return; |
1275 | 906 | } |
1276 | | - Message(messages.PermissionDenied, chan.name); |
1277 | | - return; |
1278 | 907 | } |
1279 | 908 | if (message == "@infobot-on") |
1280 | 909 | { |
— | — | @@ -1284,20 +913,24 @@ |
1285 | 914 | Message("Infobot was already enabled :O", chan.name); |
1286 | 915 | return; |
1287 | 916 | } |
1288 | | - chan.info = true; |
1289 | | - config.Save(); |
1290 | | - chan.SaveConfig(); |
1291 | | - Message("Infobot enabled", chan.name); |
| 917 | + else |
| 918 | + { |
| 919 | + chan.info = true; |
| 920 | + config.Save(); |
| 921 | + chan.SaveConfig(); |
| 922 | + Message("Infobot enabled", chan.name); |
| 923 | + return; |
| 924 | + } |
| 925 | + } |
| 926 | + else |
| 927 | + { |
| 928 | + SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name); |
1292 | 929 | return; |
1293 | 930 | } |
1294 | | - Message(messages.PermissionDenied, chan.name); |
1295 | | - return; |
1296 | 931 | } |
1297 | 932 | if (message == "@commands") |
1298 | 933 | { |
1299 | | - Message( |
1300 | | - "Commands: channellist, trusted, trustadd, trustdel, infobot-off, infobot-on, drop, whoami, add, reload, logon, logoff", |
1301 | | - chan.name); |
| 934 | + Message("Commands: channellist, trusted, trustadd, trustdel, infobot-off, refresh, infobot-on, drop, whoami, add, reload, logon, logoff", chan.name); |
1302 | 935 | return; |
1303 | 936 | } |
1304 | 937 | } |
— | — | @@ -1343,18 +976,23 @@ |
1344 | 977 | /// <returns></returns> |
1345 | 978 | public static bool Reconnect() |
1346 | 979 | { |
| 980 | + _Queue.Abort(); |
1347 | 981 | data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
1348 | 982 | rd = new StreamReader(data, System.Text.Encoding.UTF8); |
1349 | 983 | wd = new StreamWriter(data); |
1350 | 984 | wd.WriteLine("USER " + config.name + " 8 * :" + config.name); |
1351 | 985 | wd.WriteLine("NICK " + config.username); |
1352 | 986 | Authenticate(); |
| 987 | + _Queue = new Thread(new ThreadStart(SlowQueue.Run)); |
1353 | 988 | foreach (config.channel ch in config.channels) |
1354 | 989 | { |
1355 | 990 | Thread.Sleep(2000); |
1356 | 991 | wd.WriteLine("JOIN " + ch.name); |
1357 | 992 | } |
| 993 | + SlowQueue.newmessages.Clear(); |
| 994 | + SlowQueue.messages.Clear(); |
1358 | 995 | wd.Flush(); |
| 996 | + _Queue.Start(); |
1359 | 997 | return false; |
1360 | 998 | } |
1361 | 999 | |
— | — | @@ -1362,20 +1000,22 @@ |
1363 | 1001 | /// Connection |
1364 | 1002 | /// </summary> |
1365 | 1003 | /// <returns></returns> |
1366 | | - public static int Connect() |
| 1004 | + public static void Connect() |
1367 | 1005 | { |
1368 | 1006 | data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
1369 | | - rd = new StreamReader(data, System.Text.Encoding.UTF8); |
1370 | | - wd = new StreamWriter(data); |
| 1007 | + rd = new System.IO.StreamReader(data, System.Text.Encoding.UTF8); |
| 1008 | + wd = new System.IO.StreamWriter(data); |
1371 | 1009 | |
1372 | | - dumphtmt = new Thread(HtmlDump.Start); |
| 1010 | + _Queue = new Thread(new ThreadStart(SlowQueue.Run)); |
| 1011 | + dumphtmt = new Thread(new ThreadStart(HtmlDump.Start)); |
1373 | 1012 | dumphtmt.Start(); |
1374 | | - check_thread = new Thread(Ping); |
| 1013 | + check_thread = new Thread(new ThreadStart(Ping)); |
1375 | 1014 | check_thread.Start(); |
1376 | 1015 | |
1377 | 1016 | wd.WriteLine("USER " + config.name + " 8 * :" + config.name); |
1378 | 1017 | wd.WriteLine("NICK " + config.username); |
1379 | 1018 | |
| 1019 | + _Queue.Start(); |
1380 | 1020 | Thread.Sleep(2000); |
1381 | 1021 | |
1382 | 1022 | Authenticate(); |
— | — | @@ -1389,10 +1029,12 @@ |
1390 | 1030 | } |
1391 | 1031 | } |
1392 | 1032 | wd.Flush(); |
| 1033 | + string text = ""; |
1393 | 1034 | string nick = ""; |
1394 | 1035 | string host = ""; |
| 1036 | + string message = ""; |
1395 | 1037 | string channel = ""; |
1396 | | - const char delimiter = (char) 001; |
| 1038 | + char delimiter = (char)001; |
1397 | 1039 | |
1398 | 1040 | while (true) |
1399 | 1041 | { |
— | — | @@ -1400,26 +1042,28 @@ |
1401 | 1043 | { |
1402 | 1044 | while (!rd.EndOfStream) |
1403 | 1045 | { |
1404 | | - string text = rd.ReadLine(); |
| 1046 | + text = rd.ReadLine(); |
1405 | 1047 | if (text.StartsWith(":")) |
1406 | 1048 | { |
1407 | 1049 | string check = text.Substring(text.IndexOf(" ")); |
1408 | | - if (!check.StartsWith(" 005")) |
| 1050 | + if (check.StartsWith(" 005")) |
1409 | 1051 | { |
| 1052 | + |
| 1053 | + } |
| 1054 | + else |
| 1055 | + { |
1410 | 1056 | if (text.Contains("PRIVMSG")) |
1411 | 1057 | { |
1412 | 1058 | string info = text.Substring(1, text.IndexOf(" :", 1) - 1); |
| 1059 | + string info_host; |
1413 | 1060 | // we got a message here :) |
1414 | 1061 | if (text.Contains("!") && text.Contains("@")) |
1415 | 1062 | { |
1416 | 1063 | nick = info.Substring(0, info.IndexOf("!")); |
1417 | | - host = info.Substring(info.IndexOf("@") + 1, |
1418 | | - info.IndexOf(" ", info.IndexOf("@")) - 1 - |
1419 | | - info.IndexOf("@")); |
| 1064 | + host = info.Substring(info.IndexOf("@") + 1, info.IndexOf(" ", info.IndexOf("@")) - 1 - info.IndexOf("@")); |
1420 | 1065 | } |
1421 | | - string info_host = info.Substring(info.IndexOf("PRIVMSG ")); |
| 1066 | + info_host = info.Substring(info.IndexOf("PRIVMSG ")); |
1422 | 1067 | |
1423 | | - string message; |
1424 | 1068 | if (info_host.Contains("#")) |
1425 | 1069 | { |
1426 | 1070 | channel = info_host.Substring(info_host.IndexOf("#")); |
— | — | @@ -1427,45 +1071,45 @@ |
1428 | 1072 | message = message.Substring(message.IndexOf(" :") + 2); |
1429 | 1073 | if (message.Contains(delimiter.ToString() + "ACTION")) |
1430 | 1074 | { |
1431 | | - getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel, |
1432 | | - host, nick); |
| 1075 | + getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel, host, nick); |
1433 | 1076 | continue; |
1434 | 1077 | } |
1435 | | - getMessage(channel, nick, host, message); |
1436 | | - continue; |
| 1078 | + else |
| 1079 | + { |
| 1080 | + getMessage(channel, nick, host, message); |
| 1081 | + continue; |
| 1082 | + } |
1437 | 1083 | } |
1438 | | - message = text.Substring(text.IndexOf("PRIVMSG")); |
1439 | | - message = message.Substring(message.IndexOf(":")); |
1440 | | - // private message |
1441 | | - if (message.StartsWith(":" + delimiter.ToString() + "FINGER")) |
| 1084 | + else |
1442 | 1085 | { |
1443 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "FINGER" + |
1444 | | - " I am a bot don't finger me"); |
1445 | | - wd.Flush(); |
1446 | | - continue; |
| 1086 | + message = text.Substring(text.IndexOf("PRIVMSG")); |
| 1087 | + message = message.Substring(message.IndexOf(":")); |
| 1088 | + // private message |
| 1089 | + if (message.StartsWith(":" + delimiter.ToString() + "FINGER")) |
| 1090 | + { |
| 1091 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "FINGER" + " I am a bot don't finger me"); |
| 1092 | + wd.Flush(); |
| 1093 | + continue; |
| 1094 | + } |
| 1095 | + if (message.StartsWith(":" + delimiter.ToString() + "TIME")) |
| 1096 | + { |
| 1097 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "TIME " + System.DateTime.Now.ToString()); |
| 1098 | + wd.Flush(); |
| 1099 | + continue; |
| 1100 | + } |
| 1101 | + if (message.StartsWith(":" + delimiter.ToString() + "PING")) |
| 1102 | + { |
| 1103 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" + message.Substring(message.IndexOf(delimiter.ToString() + "PING") + 5)); |
| 1104 | + wd.Flush(); |
| 1105 | + continue; |
| 1106 | + } |
| 1107 | + if (message.StartsWith(":" + delimiter.ToString() + "VERSION")) |
| 1108 | + { |
| 1109 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "VERSION " + config.version); |
| 1110 | + wd.Flush(); |
| 1111 | + continue; |
| 1112 | + } |
1447 | 1113 | } |
1448 | | - if (message.StartsWith(":" + delimiter.ToString() + "TIME")) |
1449 | | - { |
1450 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "TIME " + |
1451 | | - DateTime.Now.ToString()); |
1452 | | - wd.Flush(); |
1453 | | - continue; |
1454 | | - } |
1455 | | - if (message.StartsWith(":" + delimiter.ToString() + "PING")) |
1456 | | - { |
1457 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" + |
1458 | | - message.Substring( |
1459 | | - message.IndexOf(delimiter.ToString() + "PING") + 5)); |
1460 | | - wd.Flush(); |
1461 | | - continue; |
1462 | | - } |
1463 | | - if (message.StartsWith(":" + delimiter.ToString() + "VERSION")) |
1464 | | - { |
1465 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "VERSION " + |
1466 | | - config.version); |
1467 | | - wd.Flush(); |
1468 | | - continue; |
1469 | | - } |
1470 | 1114 | } |
1471 | 1115 | if (text.Contains("PING ")) |
1472 | 1116 | { |
— | — | @@ -1479,7 +1123,7 @@ |
1480 | 1124 | Program.Log("Reconnecting, end of data stream"); |
1481 | 1125 | Reconnect(); |
1482 | 1126 | } |
1483 | | - catch (IOException xx) |
| 1127 | + catch (System.IO.IOException xx) |
1484 | 1128 | { |
1485 | 1129 | Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace); |
1486 | 1130 | Reconnect(); |
— | — | @@ -1489,9 +1133,7 @@ |
1490 | 1134 | handleException(xx, channel); |
1491 | 1135 | } |
1492 | 1136 | } |
1493 | | - return 0; |
1494 | 1137 | } |
1495 | | - |
1496 | 1138 | public static int Disconnect() |
1497 | 1139 | { |
1498 | 1140 | wd.Flush(); |
Index: trunk/tools/wmib/WMIB.csproj |
— | — | @@ -3,16 +3,20 @@ |
4 | 4 | <PropertyGroup> |
5 | 5 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
6 | 6 | <Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
7 | | - <ProjectGuid>{95595B08-C192-473E-A7F2-E2B202BBBEFC}</ProjectGuid> |
| 7 | + <ProductVersion>8.0.30703</ProductVersion> |
| 8 | + <SchemaVersion>2.0</SchemaVersion> |
| 9 | + <ProjectGuid>{69FFE45E-1CA0-47E5-92D9-4C8E2EDBE911}</ProjectGuid> |
8 | 10 | <OutputType>Exe</OutputType> |
9 | | - <NoStandardLibraries>false</NoStandardLibraries> |
10 | | - <AssemblyName>ConsoleApplication</AssemblyName> |
| 11 | + <AppDesignerFolder>Properties</AppDesignerFolder> |
| 12 | + <RootNamespace>wmib</RootNamespace> |
| 13 | + <AssemblyName>wmib</AssemblyName> |
11 | 14 | <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> |
12 | 15 | <TargetFrameworkProfile> |
13 | 16 | </TargetFrameworkProfile> |
14 | 17 | <FileAlignment>512</FileAlignment> |
15 | 18 | </PropertyGroup> |
16 | 19 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> |
| 20 | + <PlatformTarget>x86</PlatformTarget> |
17 | 21 | <DebugSymbols>true</DebugSymbols> |
18 | 22 | <DebugType>full</DebugType> |
19 | 23 | <Optimize>false</Optimize> |
— | — | @@ -20,20 +24,16 @@ |
21 | 25 | <DefineConstants>DEBUG;TRACE</DefineConstants> |
22 | 26 | <ErrorReport>prompt</ErrorReport> |
23 | 27 | <WarningLevel>4</WarningLevel> |
24 | | - <PlatformTarget>x86</PlatformTarget> |
25 | 28 | </PropertyGroup> |
26 | 29 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> |
| 30 | + <PlatformTarget>x86</PlatformTarget> |
27 | 31 | <DebugType>pdbonly</DebugType> |
28 | 32 | <Optimize>true</Optimize> |
29 | 33 | <OutputPath>bin\Release\</OutputPath> |
30 | 34 | <DefineConstants>TRACE</DefineConstants> |
31 | 35 | <ErrorReport>prompt</ErrorReport> |
32 | 36 | <WarningLevel>4</WarningLevel> |
33 | | - <PlatformTarget>x86</PlatformTarget> |
34 | 37 | </PropertyGroup> |
35 | | - <PropertyGroup> |
36 | | - <RootNamespace>WMIB</RootNamespace> |
37 | | - </PropertyGroup> |
38 | 38 | <ItemGroup> |
39 | 39 | <Reference Include="System" /> |
40 | 40 | <Reference Include="System.Data" /> |
— | — | @@ -43,13 +43,19 @@ |
44 | 44 | <Compile Include="Config.cs" /> |
45 | 45 | <Compile Include="Core.cs" /> |
46 | 46 | <Compile Include="DumpHtm.cs" /> |
| 47 | + <Compile Include="Infobot.cs" /> |
47 | 48 | <Compile Include="Program.cs" /> |
| 49 | + <Compile Include="Properties\AssemblyInfo.cs" /> |
48 | 50 | </ItemGroup> |
49 | 51 | <ItemGroup> |
50 | 52 | <None Include="app.config" /> |
51 | 53 | </ItemGroup> |
52 | | - <Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" /> |
53 | | - <ProjectExtensions> |
54 | | - <VisualStudio AllowExistingFolder="true" /> |
55 | | - </ProjectExtensions> |
| 54 | + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
| 55 | + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
| 56 | + Other similar extension points exist, see Microsoft.Common.targets. |
| 57 | + <Target Name="BeforeBuild"> |
| 58 | + </Target> |
| 59 | + <Target Name="AfterBuild"> |
| 60 | + </Target> |
| 61 | + --> |
56 | 62 | </Project> |
\ No newline at end of file |