Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using FluorineFx;
  6. using FluorineFx.Messaging.Adapter;
  7. using FluorineFx.Messaging.Api.Service;
  8. using FluorineFx.Net;
  9. using System.Threading;
  10. using System.IO;
  11.  
  12. namespace TinyChat_SPam
  13. {
  14. class Client : IPendingServiceCallback
  15. {
  16. private static Random rand = new Random();
  17. static string[] colors = { "#1965b6", "#32a5d9", "#7db257", "#a78901", "#9d5bb5", "#5c1a7a", "#c53332", "#821615", "#a08f23", "#487d21", "#c356a3" };
  18. static int colorIndex = 0;
  19.  
  20. public NetConnection mNetConnection;
  21. private Thread thdHandler;
  22.  
  23. public string roomName;
  24. public bool FlagDone = false;
  25.  
  26. public const string MsgPath = "message.txt";
  27.  
  28. public Client()
  29. {
  30. }
  31.  
  32. public Client(string roomName)
  33. {
  34. mNetConnection = new NetConnection();
  35. mNetConnection.OnConnect += OnConnect;
  36. mNetConnection.OnDisconnect += OnDisconnect;
  37. this.roomName = roomName;
  38. }
  39.  
  40. public void SetHandler(Thread thdHandler)
  41. {
  42. this.thdHandler = thdHandler;
  43. }
  44.  
  45. private void OnConnect(object sender, EventArgs e)
  46. {
  47. if (mNetConnection.Connected)
  48. {
  49. Console.WriteLine("Connected.");
  50. Thread.Sleep(200);
  51. SetNick(GetRandomString(8));
  52.  
  53. Thread.Sleep(200);
  54. foreach (string msg in File.ReadAllLines(MsgPath))
  55. {
  56. SendMessage(new Message(msg));
  57. Thread.Sleep(200);
  58. }
  59. }
  60. FlagDone = true;
  61. }
  62.  
  63. private void OnDisconnect(object sender, EventArgs e)
  64. {
  65. Console.WriteLine("Disconnected.");
  66. thdHandler.Abort();
  67. }
  68.  
  69. private void SetNick(string name)
  70. {
  71. mNetConnection.Call("nick", this, name);
  72. }
  73.  
  74. private void SendMessage(Message message)
  75. {
  76. colorIndex++;
  77.  
  78. if (colorIndex >= colors.Length)
  79. {
  80. colorIndex = 0;
  81. }
  82. string tmp = message.Format(',');
  83. string[] param = new string[] { tmp, colors[colorIndex] + ",en" };
  84. mNetConnection.Call("privmsg", this, param);
  85. }
  86.  
  87. private string GetRandomString(int length)
  88. {
  89. Thread.Sleep(25);
  90. rand = new Random(DateTime.Now.Millisecond / new Random().Next(2, 5));
  91. string tmpString = "";
  92. while (length-- > 0)
  93. {
  94. tmpString += (char)rand.Next('a', 'z');
  95. }
  96.  
  97. return tmpString;
  98. }
  99.  
  100. public void ResultReceived(IPendingServiceCall call)
  101. {
  102. throw new NotImplementedException();
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement