PageRenderTime 171ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Spammer3/Irc/Program.cs

#
C# | 221 lines | 205 code | 14 blank | 2 comment | 25 complexity | f8cc0b906c480b42f10ca1956c1fc480 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using doru;
  6. using System.Net.Sockets;
  7. using System.Diagnostics;
  8. using System.Threading;
  9. using System.IO;
  10. using System.Text.RegularExpressions;
  11. namespace Irc
  12. {
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. Spammer3.Setup();
  18. Program _Program = new Program();
  19. _Program.Start();
  20. }
  21. public static Random _Random = new Random();
  22. public Program()
  23. {
  24. if (File.Exists(host + "nicks.txt")) _nicklist = File.ReadAllLines(host + "nicks.txt").ToList();
  25. if (File.Exists(host + "nicksused.txt")) _nicksused = File.ReadAllLines(host + "nicksused.txt").ToList();
  26. }
  27. NetworkStream _NetworkStream;
  28. private void Client()
  29. {
  30. NetworkStream _NetworkStream = Connect();
  31. new Thread(delegate()
  32. {
  33. while (true)
  34. {
  35. _NetworkStream.WriteLine(Console.ReadLine());
  36. }
  37. }).Start();
  38. while (true)
  39. _NetworkStream.ReadLine().Trace();
  40. }
  41. public void Start()
  42. {
  43. string text = File.ReadAllText("IRC_servers.ini");
  44. MatchCollection _MatchCollection = Regex.Matches(text, @"SERVER:([\w\.-]+):(\d+)");
  45. List<string> serversused = new List<string>();
  46. if (File.Exists("serversused.txt")) serversused= File.ReadAllLines("serversused.txt").ToList();
  47. foreach (Match _Match in _MatchCollection)
  48. {
  49. if (!serversused.Contains(_Match.Groups[1].Value))
  50. {
  51. //Client();
  52. serversused.Add(_Match.Groups[1].Value);
  53. File.WriteAllLines("serversused.txt", serversused.ToArray());
  54. try
  55. {
  56. host = _Match.Groups[1].Value;
  57. port = int.Parse(_Match.Groups[2].Value);
  58. _NetworkStream = Connect();
  59. PopulateChannels();
  60. Trace.WriteLine("<<<<<<<<<<<<<<<<<<<Channels Populated>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
  61. Thread.Sleep(1000);
  62. PopulateNicks();
  63. Trace.WriteLine("<<<<<<<<<<<<<<<<<<<Nicks Populated>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
  64. Thread.Sleep(1000);
  65. SendPm();
  66. Trace.WriteLine("<<<<<<<<<<<<<<<<<<<Sending Sended>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
  67. }
  68. catch (IOException e) { e.Trace(); }
  69. catch (ExceptionB e) { e.Message.Trace(); }
  70. catch (SocketException e) { (host + e.Message).Trace(); }
  71. Thread.Sleep(1000);
  72. if(_Socket!=null) _Socket.Close();
  73. }
  74. }
  75. }
  76. public string[] _Tags = File.ReadAllLines("../tags.txt");
  77. string host = "irc.ablenet.org";
  78. public int port = 6667;
  79. Socket _Socket;
  80. private NetworkStream Connect()
  81. {
  82. //Socket _Socket = Proxy.Socks5Connect("localhost", 9050, "irc.tambov.ru", 7770);
  83. _Socket = new TcpClient(host, port).Client;
  84. _NetworkStream = new NetworkStream(_Socket);
  85. _NetworkStream.ReadTimeout = 10000;
  86. _NetworkStream.WriteLine(string.Format("NICK {0}", _Tags.Random())).Trace();
  87. _NetworkStream.WriteLine("USER " + _Tags.Random() + " " + _Tags.Random() + " server :" + _Tags.Random()).Trace();
  88. bool success = false;
  89. Thread _Thread = new Thread(delegate()
  90. {
  91. try
  92. {
  93. while (true)
  94. {
  95. string s = _NetworkStream.ReadLine().Trace();
  96. Match _Match = Regex.Match(s, @"PING \:(\w+)", RegexOptions.IgnoreCase);
  97. if (_Match.Success)
  98. {
  99. _NetworkStream.WriteLine(("PONG :" + _Match.Groups[1]).Trace());
  100. }
  101. if (Regex.Match(s, @":.+? 005").Success) success = true;
  102. }
  103. }
  104. catch (IOException) { }
  105. });
  106. _Thread.Start();
  107. _Thread.Join(5000);
  108. _Thread.Abort();
  109. if (!success) throw new ExceptionB("cannot connect to: " +host);
  110. _NetworkStream.WriteLine("codepage cp1251");
  111. Trace.WriteLine("<<<<<<<<<<<<<<<<<<<<<<<<<<<Connected>>>>>>>>>>>>>>>>>>>>>>>>");
  112. return new NetworkStream(_Socket);
  113. }
  114. List<string> _nicksused = new List<string>();
  115. private void SendPm()
  116. {
  117. foreach (string _nick in _nicklist)
  118. {
  119. if (!_nicksused.Contains(_nick))
  120. {
  121. _NetworkStream.WriteLine(("PRIVMSG " + _nick + " "+message).Trace());
  122. _nicksused.Add(_nick);
  123. File.WriteAllLines(host + "nicksused.txt", _nicksused.ToArray());
  124. Thread.Sleep(3000);
  125. while(_Socket.Available > 0)
  126. {
  127. string s = _NetworkStream.ReadLine().Trace();
  128. if (Regex.Match(s, @"\:.+? 439").Success)
  129. {
  130. Connect();
  131. }
  132. }
  133. }
  134. }
  135. }
  136. public const string message = @"http://code.google.com/p/counterstrike/ Silverlight multiplayer game join us!";
  137. List<String> _nicklist = new List<string>();
  138. private void PopulateNicks()
  139. {
  140. if (File.Exists(host + "_PostedChannels.txt")) _PostedChannels = File.ReadAllLines(host + "_PostedChannels.txt").ToList();
  141. string s = File.ReadAllText(host + "channel.txt", Encoding.Default);
  142. List<Asd> sortlist = new List<Asd>();
  143. foreach (Match m in Regex.Matches(s, @"(.+?) (\d+)"))
  144. {
  145. sortlist.Add(new Asd { a = int.Parse(m.Groups[2].Value), b = m.Groups[1].Value });
  146. }
  147. List<string> channels = (from a in sortlist orderby a.a descending select a.b).Take(5).ToList();
  148. string.Join(",", channels.ToArray()).Trace();
  149. foreach (string s1 in channels)
  150. {
  151. if (!_PostedChannels.Contains(s1))
  152. {
  153. Thread.Sleep(7000);
  154. _NetworkStream.WriteLine(("JOIN #" + s1).Trace());
  155. _NetworkStream.WriteLine("PART #" + s1 + " : "+message);
  156. while (true)
  157. {
  158. string s4 = _NetworkStream.ReadLine().Trace();
  159. Match _Match = Regex.Match(s4, @"\:.+? 353 .+? = #(.+?) \:(.+)");
  160. if (_Match.Success)
  161. {
  162. _PostedChannels.Add(_Match.Groups[1].Value);
  163. foreach (string s2 in _Match.Groups[2].Value.Trim().Split(' '))
  164. {
  165. string s3 = s2.Trim('+', '%', '@','&');
  166. if (!_nicklist.Contains(s3) && s3 != "ChanServ")
  167. {
  168. _nicklist.Add(s3);
  169. Trace.WriteLine("Added: " + s3);
  170. }
  171. }
  172. File.WriteAllLines(host + "nicks.txt", _nicklist.ToArray());
  173. break;
  174. }
  175. }
  176. File.WriteAllLines(host + "_PostedChannels.txt", _PostedChannels.ToArray());
  177. }
  178. }
  179. }
  180. public List<string> _PostedChannels = new List<string>();
  181. class Asd
  182. {
  183. public int a;
  184. public string b;
  185. }
  186. private void PopulateChannels()
  187. {
  188. _NetworkStream.WriteLine("list");
  189. List<string> list = new List<string>();
  190. if (File.Exists(host + "channel.txt")) list = File.ReadAllLines(host + "channel.txt").ToList();
  191. while (true)
  192. {
  193. string s = _NetworkStream.ReadLine().Trace();
  194. {
  195. Match _Match = Regex.Match(s, @"\:.+? 322 .+? #(.+?) (\d+?)");
  196. if (_Match.Success)
  197. {
  198. if (!list.Contains(s)) list.Add((_Match.Groups[1].Value + " " + _Match.Groups[2].Value).Trace());
  199. }
  200. }
  201. if (Regex.Match(s, @"\:.+? 323").Success)
  202. break;
  203. }
  204. File.WriteAllLines(host + "channel.txt", list.ToArray());
  205. }
  206. }
  207. }