r107297 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107296‎ | r107297 | r107298 >
Date:22:59, 25 December 2011
Author:petrb
Status:deferred (Comments)
Tags:
Comment:
merged some things commited in past
simplified some stuff
fixed several security issues
moved one class from core
Modified paths:
  • /trunk/tools/wmib/Config.cs (modified) (history)
  • /trunk/tools/wmib/Core.cs (modified) (history)
  • /trunk/tools/wmib/DumpHtm.cs (modified) (history)
  • /trunk/tools/wmib/Program.cs (modified) (history)
  • /trunk/tools/wmib/WMIB.csproj (modified) (history)

Diff [purge]

Index: trunk/tools/wmib/DumpHtm.cs
@@ -8,8 +8,16 @@
99 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1010 //GNU General Public License for more details.
1111
 12+
 13+
1214 using System;
 15+using System.Collections.Generic;
 16+using System.IO;
 17+using System.Text;
 18+using System.Threading;
 19+using System.Net;
1320
 21+
1422 namespace wmib
1523 {
1624 public class HtmlDump
@@ -18,12 +26,10 @@
1927 /// Channel name
2028 /// </summary>
2129 public config.channel Channel;
22 -
2330 /// <summary>
2431 /// Dump
2532 /// </summary>
2633 public string dumpname;
27 -
2834 // This function is called on start of bot
2935 public static void Start()
3036 {
@@ -31,15 +37,16 @@
3238 {
3339 foreach (config.channel chan in config.channels)
3440 {
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+ }
3947 }
40 - System.Threading.Thread.Sleep(320000);
 48+ Thread.Sleep(320000);
4149 }
4250 }
43 -
4451 /// <summary>
4552 /// Constructor
4653 /// </summary>
@@ -98,12 +105,13 @@
99106 {
100107 try
101108 {
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";
104112 Channel.Keys.locked = true;
105113 if (Channel.Keys.text.Count > 0)
106114 {
107 - foreach (irc.dictionary.item Key in Channel.Keys.text)
 115+ foreach (dictionary.item Key in Channel.Keys.text)
108116 {
109117 text = text + AddLine(Key.key, Key.text);
110118 }
@@ -111,7 +119,7 @@
112120 Channel.Keys.locked = false;
113121 text = text + "<table>\n";
114122 text = text + CreateFooter();
115 - System.IO.File.WriteAllText(dumpname, text);
 123+ File.WriteAllText(dumpname, text);
116124 }
117125 catch (Exception b)
118126 {
Index: trunk/tools/wmib/Config.cs
@@ -10,6 +10,7 @@
1111
1212 // Created by Petr Bena benapetr@gmail.com
1313
 14+using System;
1415 using System.Collections.Generic;
1516 using System.IO;
1617
@@ -36,7 +37,7 @@
3738 /// <summary>
3839 /// Keys
3940 /// </summary>
40 - public irc.dictionary Keys;
 41+ public dictionary Keys;
4142
4243 /// <summary>
4344 /// Configuration text
@@ -76,17 +77,17 @@
7778 return;
7879 }
7980 conf = File.ReadAllText(conf_file);
80 - if (parseConfig(conf, "keysdb") != "")
 81+ if (config.parseConfig(conf, "keysdb") != "")
8182 {
82 - keydb = (parseConfig(conf, "keysdb"));
 83+ keydb = (config.parseConfig(conf, "keysdb"));
8384 }
84 - if (parseConfig(conf, "logged") != "")
 85+ if (config.parseConfig(conf, "logged") != "")
8586 {
86 - logged = bool.Parse(parseConfig(conf, "logged"));
 87+ logged = bool.Parse(config.parseConfig(conf, "logged"));
8788 }
88 - if (parseConfig(conf, "infodb") != "")
 89+ if (config.parseConfig(conf, "infodb") != "")
8990 {
90 - info = bool.Parse(parseConfig(conf, "infodb"));
 91+ info = bool.Parse(config.parseConfig(conf, "infodb"));
9192 }
9293 }
9394
@@ -111,7 +112,7 @@
112113 conf = "";
113114 keydb = Name + ".db";
114115 info = true;
115 - logged = true;
 116+ logged = false;
116117 name = Name;
117118 LoadConfig();
118119 if (!Directory.Exists("log"))
@@ -122,7 +123,7 @@
123124 {
124125 Directory.CreateDirectory("log/" + Name);
125126 }
126 - Keys = new irc.dictionary(keydb, name);
 127+ Keys = new dictionary(keydb, name);
127128 log = "log/" + Name + "/";
128129 Users = new irc.IRCTrust(name);
129130 }
@@ -178,39 +179,46 @@
179180 /// </summary>
180181 public static void Load()
181182 {
182 - text = File.ReadAllText("wmib");
183 - foreach (string x in parseConfig(text, "channels").Replace("\n", "").Split(','))
 183+ try
184184 {
185 - string config = x.Replace(" ", "");
186 - if (config != "")
 185+ text = File.ReadAllText("wmib");
 186+ foreach (string x in parseConfig(text, "channels").Replace("\n", "").Split(','))
187187 {
188 - channels.Add(new channel(config));
 188+ string name = x.Replace(" ", "");
 189+ if (!(name == ""))
 190+ {
 191+ channels.Add(new channel(name));
 192+ }
189193 }
 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");
190199 }
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)
197201 {
198 - Directory.CreateDirectory(DumpDir);
 202+ irc.handleException(ex);
199203 }
 204+ if (!Directory.Exists(config.DumpDir))
 205+ {
 206+ Directory.CreateDirectory(config.DumpDir);
 207+ }
 208+
200209 }
201 -
202210 public static string text;
203 -
204211 /// <summary>
205212 /// Network
206213 /// </summary>
 214+ ///
207215 public static string network = "irc.freenode.net";
208 -
209216 /// <summary>
210217 /// Nick name
211218 /// </summary>
 219+ ///
212220 public static string username = "wm-bot";
213221
214 - public static string debugchan = "";
 222+ public static string debugchan = null;
215223
216224 /// <summary>
217225 /// Login name
Index: trunk/tools/wmib/Program.cs
@@ -11,18 +11,21 @@
1212 // Created by Petr Bena benapetr@gmail.com
1313
1414 using System;
 15+using System.Collections.Generic;
 16+using System.Text;
 17+using System.Net;
1518
 19+
1620 namespace wmib
1721 {
18 - internal class Program
 22+ class Program
1923 {
20 - public static bool Log(string msg)
 24+ public static bool Log(string msg )
2125 {
2226 Console.WriteLine("LOG: " + msg);
2327 return false;
2428 }
25 -
26 - private static void Main(string[] args)
 29+ static void Main(string[] args)
2730 {
2831 Log("Connecting");
2932 config.Load();
Index: trunk/tools/wmib/Core.cs
@@ -10,10 +10,12 @@
1111
1212 using System;
1313 using System.Collections.Generic;
14 -using System.IO;
15 -using System.Text.RegularExpressions;
1614 using System.Threading;
 15+using System.Text.RegularExpressions;
 16+using System.Net;
 17+using System.IO;
1718
 19+
1820 namespace wmib
1921 {
2022 public class misc
@@ -34,14 +36,14 @@
3537 return true;
3638 }
3739 }
38 -
3940 public class irc
4041 {
 42+ public static Thread _Queue;
4143 private static System.Net.Sockets.NetworkStream data;
4244 public static Thread dumphtmt;
4345 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;
4648 private static List<user> User = new List<user>();
4749
4850 public class messages
@@ -56,12 +58,10 @@
5759 /// Regex
5860 /// </summary>
5961 public string name;
60 -
6162 /// <summary>
6263 /// Level
6364 /// </summary>
6465 public string level;
65 -
6666 /// <summary>
6767 /// Constructor
6868 /// </summary>
@@ -74,30 +74,73 @@
7575 }
7676 }
7777
 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+
78124 public class RegexCheck
79125 {
80126 public string value;
81127 public string regex;
82128 public bool searching;
83 - public bool result;
84 -
 129+ public bool result = false;
85130 public RegexCheck(string Regex, string Data)
86131 {
87132 result = false;
88133 value = Data;
89134 regex = Regex;
90135 }
91 -
92136 private void Run()
93137 {
94138 Regex c = new Regex(regex);
95139 result = c.Match(value).Success;
96140 searching = false;
97141 }
98 -
99142 public int IsMatch()
100143 {
101 - Thread quick = new Thread(Run);
 144+ Thread quick = new Thread(new ThreadStart(Run));
102145 searching = true;
103146 quick.Start();
104147 int check = 0;
@@ -105,30 +148,36 @@
106149 {
107150 check++;
108151 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+ }
112157 }
113 - return result ? 1 : 0;
 158+ if (result)
 159+ {
 160+ return 1;
 161+ }
 162+ return 0;
114163 }
115164 }
116165
117166 public class IRCTrust
118167 {
 168+ private List<user> GlobalUsers = new List<user>();
119169 /// <summary>
120170 /// List of all users in a channel
121171 /// </summary>
122172 private List<user> Users = new List<user>();
123 -
 173+
124174 /// <summary>
125175 /// Channel this class belong to
126176 /// </summary>
127177 public string _Channel;
128 -
129178 /// <summary>
130179 /// File where data are stored
131180 /// </summary>
132 - public string DataFile;
 181+ public string File;
133182
134183 /// <summary>
135184 /// Constructor
@@ -137,14 +186,20 @@
138187 public IRCTrust(string channel)
139188 {
140189 // Load
141 - DataFile = channel + "_user";
142 - if (!File.Exists(DataFile))
 190+ File = channel + "_user";
 191+ if (!System.IO.File.Exists(File))
143192 {
144193 // Create db
145194 Program.Log("Creating user file for " + channel);
146 - File.WriteAllText(DataFile, "");
 195+ System.IO.File.WriteAllText(File, "");
147196 }
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");
149204 _Channel = channel;
150205 foreach (string x in db)
151206 {
@@ -156,6 +211,18 @@
157212 Users.Add(new user(level, name));
158213 }
159214 }
 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+ }
160227 }
161228
162229 /// <summary>
@@ -164,10 +231,10 @@
165232 /// <returns></returns>
166233 public bool Save()
167234 {
168 - File.WriteAllText(DataFile, "");
 235+ System.IO.File.WriteAllText(File, "");
169236 foreach (user u in Users)
170237 {
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");
172239 }
173240 return true;
174241 }
@@ -256,6 +323,18 @@
257324 {
258325 user lv = new user("null", "");
259326 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+ }
260339 foreach (user b in Users)
261340 {
262341 RegexCheck id = new RegexCheck(b.name, user);
@@ -279,7 +358,7 @@
280359 string users_ok = "";
281360 foreach (user b in Users)
282361 {
283 - users_ok += users_ok + " " + b.name + ",";
 362+ users_ok = users_ok + " " + b.name + ",";
284363 }
285364 Message("I trust: " + users_ok, _Channel);
286365 }
@@ -334,500 +413,6 @@
335414 }
336415 }
337416
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 -
832417 /// <summary>
833418 /// Ping
834419 /// </summary>
@@ -885,7 +470,7 @@
886471 {
887472 if (config.debugchan != null)
888473 {
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);
890475 }
891476 Program.Log(ex.Message + ex.Source + ex.StackTrace);
892477 }
@@ -953,8 +538,7 @@
954539 {
955540 if (rights_info.Length < 3)
956541 {
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);
959543 return 0;
960544 }
961545 if (!(rights_info[2] == "admin" || rights_info[2] == "trusted"))
@@ -973,16 +557,19 @@
974558 if (channel.Users.addUser(rights_info[2], rights_info[1]))
975559 {
976560 Message("Successfuly added " + rights_info[1], channel.name);
 561+ return 0;
977562 }
978563 }
979564 else
980565 {
981566 Message("You are not autorized to perform this, sorry", channel.name);
 567+ return 0;
982568 }
983569 }
984570 if (message.StartsWith("@trusted"))
985571 {
986572 channel.Users.listAll();
 573+ return 0;
987574 }
988575 if (message.StartsWith("@trustdel"))
989576 {
@@ -995,8 +582,11 @@
996583 channel.Users.delUser(rights_info[1]);
997584 return 0;
998585 }
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+ }
1001591 }
1002592 Message("Invalid user", channel.name);
1003593 }
@@ -1025,18 +615,13 @@
1026616 string log;
1027617 if (!noac)
1028618 {
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";
1032620 }
1033621 else
1034622 {
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";
1038624 }
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);
1041626 }
1042627 }
1043628 catch (Exception er)
@@ -1061,16 +646,9 @@
1062647 return false;
1063648 }
1064649
1065 - /// <summary>
1066 - ///
1067 - /// </summary>
1068 - /// <param name="name"></param>
1069 - /// <returns></returns>
1070650 public static bool validFile(string name)
1071651 {
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("*"));
1075653 }
1076654
1077655 /// <summary>
@@ -1086,42 +664,44 @@
1087665 {
1088666 if (message.StartsWith("@add"))
1089667 {
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"))
1111669 {
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+ }
1113699 }
 700+ Message(messages.PermissionDenied, chan.name);
1114701 }
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);
1122702 }
1123 - catch (Exception)
 703+ catch (Exception b)
1124704 {
1125 -
 705+ handleException(b);
1126706 }
1127707 }
1128708
@@ -1143,18 +723,26 @@
1144724 wd.WriteLine("PART " + chan.name);
1145725 Thread.Sleep(100);
1146726 wd.Flush();
1147 - if (!Directory.Exists(chan.log))
 727+ try
1148728 {
1149 - Directory.Delete(chan.log, true);
 729+ if (Directory.Exists(chan.log))
 730+ {
 731+ Directory.Delete(chan.log, true);
 732+ }
1150733 }
 734+ catch (Exception)
 735+ { }
1151736 File.Delete(chan.name + ".setting");
1152 - File.Delete(chan.Users.DataFile);
 737+ File.Delete(chan.Users.File);
1153738 config.channels.Remove(chan);
1154739 config.Save();
1155740 return;
1156741 }
1157 - Message(messages.PermissionDenied, chan.name);
1158 - return;
 742+ else
 743+ {
 744+ Message(messages.PermissionDenied, chan.name);
 745+ return;
 746+ }
1159747 }
1160748 if (message == "@part")
1161749 {
@@ -1165,12 +753,10 @@
1166754 wd.Flush();
1167755 config.channels.Remove(chan);
1168756 config.Save();
1169 - }
1170 - else
1171 - {
1172 - Message(messages.PermissionDenied, chan.name);
1173757 return;
1174758 }
 759+ Message(messages.PermissionDenied, chan.name);
 760+ return;
1175761 }
1176762 }
1177763 catch (Exception x)
@@ -1197,9 +783,30 @@
1198784 Message("Channel config was reloaded", chan.name);
1199785 return;
1200786 }
1201 - Message(messages.PermissionDenied, chan.name);
1202 - return;
 787+ else
 788+ {
 789+ Message(messages.PermissionDenied, chan.name);
 790+ return;
 791+ }
1203792 }
 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+ }
1204811 if (message == "@logon")
1205812 {
1206813 if (chan.Users.isApproved(user, host, "admin"))
@@ -1209,14 +816,20 @@
1210817 Message("Channel is already logged", chan.name);
1211818 return;
1212819 }
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);
1217832 return;
1218833 }
1219 - Message(messages.PermissionDenied, chan.name);
1220 - return;
1221834 }
1222835 if (message == "@whoami")
1223836 {
@@ -1226,8 +839,11 @@
1227840 Message("You are unknown to me :)", chan.name);
1228841 return;
1229842 }
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+ }
1232848 }
1233849
1234850 if (message == "@logoff")
@@ -1239,13 +855,20 @@
1240856 Message("Channel was already not logged", chan.name);
1241857 return;
1242858 }
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);
1247871 return;
1248872 }
1249 - Message(messages.PermissionDenied, chan.name);
1250873 }
1251874 if (message == "@channellist")
1252875 {
@@ -1266,14 +889,20 @@
1267890 Message("Channel had infobot disabled", chan.name);
1268891 return;
1269892 }
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);
1274905 return;
1275906 }
1276 - Message(messages.PermissionDenied, chan.name);
1277 - return;
1278907 }
1279908 if (message == "@infobot-on")
1280909 {
@@ -1284,20 +913,24 @@
1285914 Message("Infobot was already enabled :O", chan.name);
1286915 return;
1287916 }
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);
1292929 return;
1293930 }
1294 - Message(messages.PermissionDenied, chan.name);
1295 - return;
1296931 }
1297932 if (message == "@commands")
1298933 {
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);
1302935 return;
1303936 }
1304937 }
@@ -1343,18 +976,23 @@
1344977 /// <returns></returns>
1345978 public static bool Reconnect()
1346979 {
 980+ _Queue.Abort();
1347981 data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream();
1348982 rd = new StreamReader(data, System.Text.Encoding.UTF8);
1349983 wd = new StreamWriter(data);
1350984 wd.WriteLine("USER " + config.name + " 8 * :" + config.name);
1351985 wd.WriteLine("NICK " + config.username);
1352986 Authenticate();
 987+ _Queue = new Thread(new ThreadStart(SlowQueue.Run));
1353988 foreach (config.channel ch in config.channels)
1354989 {
1355990 Thread.Sleep(2000);
1356991 wd.WriteLine("JOIN " + ch.name);
1357992 }
 993+ SlowQueue.newmessages.Clear();
 994+ SlowQueue.messages.Clear();
1358995 wd.Flush();
 996+ _Queue.Start();
1359997 return false;
1360998 }
1361999
@@ -1362,20 +1000,22 @@
13631001 /// Connection
13641002 /// </summary>
13651003 /// <returns></returns>
1366 - public static int Connect()
 1004+ public static void Connect()
13671005 {
13681006 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);
13711009
1372 - dumphtmt = new Thread(HtmlDump.Start);
 1010+ _Queue = new Thread(new ThreadStart(SlowQueue.Run));
 1011+ dumphtmt = new Thread(new ThreadStart(HtmlDump.Start));
13731012 dumphtmt.Start();
1374 - check_thread = new Thread(Ping);
 1013+ check_thread = new Thread(new ThreadStart(Ping));
13751014 check_thread.Start();
13761015
13771016 wd.WriteLine("USER " + config.name + " 8 * :" + config.name);
13781017 wd.WriteLine("NICK " + config.username);
13791018
 1019+ _Queue.Start();
13801020 Thread.Sleep(2000);
13811021
13821022 Authenticate();
@@ -1389,10 +1029,12 @@
13901030 }
13911031 }
13921032 wd.Flush();
 1033+ string text = "";
13931034 string nick = "";
13941035 string host = "";
 1036+ string message = "";
13951037 string channel = "";
1396 - const char delimiter = (char) 001;
 1038+ char delimiter = (char)001;
13971039
13981040 while (true)
13991041 {
@@ -1400,26 +1042,28 @@
14011043 {
14021044 while (!rd.EndOfStream)
14031045 {
1404 - string text = rd.ReadLine();
 1046+ text = rd.ReadLine();
14051047 if (text.StartsWith(":"))
14061048 {
14071049 string check = text.Substring(text.IndexOf(" "));
1408 - if (!check.StartsWith(" 005"))
 1050+ if (check.StartsWith(" 005"))
14091051 {
 1052+
 1053+ }
 1054+ else
 1055+ {
14101056 if (text.Contains("PRIVMSG"))
14111057 {
14121058 string info = text.Substring(1, text.IndexOf(" :", 1) - 1);
 1059+ string info_host;
14131060 // we got a message here :)
14141061 if (text.Contains("!") && text.Contains("@"))
14151062 {
14161063 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("@"));
14201065 }
1421 - string info_host = info.Substring(info.IndexOf("PRIVMSG "));
 1066+ info_host = info.Substring(info.IndexOf("PRIVMSG "));
14221067
1423 - string message;
14241068 if (info_host.Contains("#"))
14251069 {
14261070 channel = info_host.Substring(info_host.IndexOf("#"));
@@ -1427,45 +1071,45 @@
14281072 message = message.Substring(message.IndexOf(" :") + 2);
14291073 if (message.Contains(delimiter.ToString() + "ACTION"))
14301074 {
1431 - getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel,
1432 - host, nick);
 1075+ getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel, host, nick);
14331076 continue;
14341077 }
1435 - getMessage(channel, nick, host, message);
1436 - continue;
 1078+ else
 1079+ {
 1080+ getMessage(channel, nick, host, message);
 1081+ continue;
 1082+ }
14371083 }
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
14421085 {
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+ }
14471113 }
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 - }
14701114 }
14711115 if (text.Contains("PING "))
14721116 {
@@ -1479,7 +1123,7 @@
14801124 Program.Log("Reconnecting, end of data stream");
14811125 Reconnect();
14821126 }
1483 - catch (IOException xx)
 1127+ catch (System.IO.IOException xx)
14841128 {
14851129 Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace);
14861130 Reconnect();
@@ -1489,9 +1133,7 @@
14901134 handleException(xx, channel);
14911135 }
14921136 }
1493 - return 0;
14941137 }
1495 -
14961138 public static int Disconnect()
14971139 {
14981140 wd.Flush();
Index: trunk/tools/wmib/WMIB.csproj
@@ -3,16 +3,20 @@
44 <PropertyGroup>
55 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66 <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>
810 <OutputType>Exe</OutputType>
9 - <NoStandardLibraries>false</NoStandardLibraries>
10 - <AssemblyName>ConsoleApplication</AssemblyName>
 11+ <AppDesignerFolder>Properties</AppDesignerFolder>
 12+ <RootNamespace>wmib</RootNamespace>
 13+ <AssemblyName>wmib</AssemblyName>
1114 <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
1215 <TargetFrameworkProfile>
1316 </TargetFrameworkProfile>
1417 <FileAlignment>512</FileAlignment>
1518 </PropertyGroup>
1619 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
 20+ <PlatformTarget>x86</PlatformTarget>
1721 <DebugSymbols>true</DebugSymbols>
1822 <DebugType>full</DebugType>
1923 <Optimize>false</Optimize>
@@ -20,20 +24,16 @@
2125 <DefineConstants>DEBUG;TRACE</DefineConstants>
2226 <ErrorReport>prompt</ErrorReport>
2327 <WarningLevel>4</WarningLevel>
24 - <PlatformTarget>x86</PlatformTarget>
2528 </PropertyGroup>
2629 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
 30+ <PlatformTarget>x86</PlatformTarget>
2731 <DebugType>pdbonly</DebugType>
2832 <Optimize>true</Optimize>
2933 <OutputPath>bin\Release\</OutputPath>
3034 <DefineConstants>TRACE</DefineConstants>
3135 <ErrorReport>prompt</ErrorReport>
3236 <WarningLevel>4</WarningLevel>
33 - <PlatformTarget>x86</PlatformTarget>
3437 </PropertyGroup>
35 - <PropertyGroup>
36 - <RootNamespace>WMIB</RootNamespace>
37 - </PropertyGroup>
3838 <ItemGroup>
3939 <Reference Include="System" />
4040 <Reference Include="System.Data" />
@@ -43,13 +43,19 @@
4444 <Compile Include="Config.cs" />
4545 <Compile Include="Core.cs" />
4646 <Compile Include="DumpHtm.cs" />
 47+ <Compile Include="Infobot.cs" />
4748 <Compile Include="Program.cs" />
 49+ <Compile Include="Properties\AssemblyInfo.cs" />
4850 </ItemGroup>
4951 <ItemGroup>
5052 <None Include="app.config" />
5153 </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+ -->
5662 </Project>
\ No newline at end of file

Comments

#Comment by Petrb (talk | contribs)   23:10, 25 December 2011

string text, message are declared before while because of performance reasons, I don't like the idea that garbage collector will need to clean up the strings generated from every loop, however if you think that it's wrong feel free to put it back

#Comment by Reedy (talk | contribs)   23:26, 25 December 2011

You realise strings are immutable, right? A new string object is created everytime you alter (add, remove etc) the string.

If you're wanting to get performance out of building really long strings, use a StringBuilder, though, unless this is 10,000's, it's not really necessary, but is somewhat best practise, so either way.

They would be garbage collected every iteration anyway, it's not used outside the scope of the loop, so not initialising it outside the loop, to then reset it in the loop is better

Status & tagging log