Advertisement
Guest User

Untitled

a guest
May 4th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using BNSharp;
  6. using BNSharp.Net;
  7. using Meebey.SmartIrc4net;
  8.  
  9. namespace BNSharpTest
  10. {
  11. class Program
  12. {
  13. private IrcClient irccli = new IrcClient();
  14. public string msg = "";
  15. public static string msg2 = "";
  16. public static string specialmsg = "";
  17. static void Main(string[] args)
  18. {
  19. Console.WriteLine("Logging on with Starcraft; enter CD key.");
  20. string cdKey = "7090376332276";
  21. Console.WriteLine("Enter account name:");
  22. string acct = "OmnimagaIRC";
  23. Console.WriteLine("Enter account password for {0}:", acct);
  24. string password = "<removed>";
  25. Settings set = new Settings() { CdKey1 = cdKey, Username = acct, Password = password, CdKeyOwner = acct };
  26.  
  27. BattleNetClient client = new BattleNetClient(set);
  28. client.Connected += delegate { Console.WriteLine("--- CONNECTED"); };
  29. client.Error += new BNSharp.ErrorEventHandler(client_Error);
  30. client.EnteredChat += new EnteredChatEventHandler(client_EnteredChat);
  31. client.LoginSucceeded += new EventHandler(client_LoginSucceeded);
  32. client.LoginFailed += new LoginFailedEventHandler(client_LoginFailed);
  33. client.ServerBroadcast += new ServerChatEventHandler(client_ServerBroadcast);
  34. client.ServerErrorReceived += new ServerChatEventHandler(client_ServerErrorReceived);
  35. client.UserShown += new UserEventHandler(client_UserShown);
  36. client.UserJoined += new UserEventHandler(client_UserJoined);
  37. client.UserLeft += new UserEventHandler(client_UserLeft);
  38. client.UserSpoke += new ChatMessageEventHandler(client_UserSpoke);
  39. client.UserEmoted += new ChatMessageEventHandler(client_UserEmoted);
  40. client.ClientCheckPassed += delegate { Console.WriteLine("--- VERSIONING PASSED"); };
  41. client.ClientCheckFailed += new ClientCheckFailedEventHandler(client_ClientCheckFailed);
  42. client.JoinedChannel += new ServerChatEventHandler(client_JoinedChannel);
  43. client.WardentUnhandled += delegate { Console.WriteLine("--- WARNING: Warden requested and unhandled!!"); };
  44. client.MessageSent += new ChatMessageEventHandler(client_MessageSent);
  45. client.Disconnected += delegate { Console.WriteLine("--- DISCONNECTED"); };
  46. BattleNetClientResources.IncomingBufferPool.NewBufferAllocated += new EventHandler(BufferAllocated);
  47. BattleNetClientResources.OutgoingBufferPool.NewBufferAllocated += new EventHandler(BufferAllocated);
  48.  
  49.  
  50. Console.WriteLine("Events hooked up; press <enter> to connect.");
  51. Console.ReadLine();
  52.  
  53.  
  54. Console.WriteLine("Type /exit to quit.");
  55.  
  56. Program linker = new Program(client);
  57.  
  58.  
  59. }
  60. public Program(BattleNetClient client)
  61. {
  62. client.Connect();
  63. irccli.OnConnected += new EventHandler(OnConnected);
  64. irccli.OnChannelMessage += new IrcEventHandler(OnChannelMessage);
  65. irccli.OnQueryMessage += new IrcEventHandler(OnQueryMessage);
  66. irccli.OnJoin += new JoinEventHandler(OnJoin);
  67. irccli.OnKick += new KickEventHandler(OnKick);
  68. irccli.OnPart += new PartEventHandler(OnPart);
  69. irccli.OnQuit += new QuitEventHandler(OnQuit);
  70. irccli.OnChannelAction += new ActionEventHandler(OnAction);
  71. Boolean firstloop = true;
  72. while (true)
  73. {
  74. if (msg != "")
  75. {
  76. client.SendMessage(msg);
  77. msg = "";
  78. }
  79. if (msg2 != "")
  80. {
  81. irccli.SendMessage(SendType.Message, "#Omnimaga", msg2);
  82. msg2 = "";
  83. }
  84. if (specialmsg != "")
  85. {
  86. client.SendMessage("/Join Omnimaga");
  87. specialmsg = "";
  88. }
  89. if (firstloop)
  90. {
  91. irccli.Connect("irc.efnet.net", 6667);
  92. firstloop = !firstloop;
  93. }
  94. irccli.ListenOnce(false);
  95. }
  96.  
  97.  
  98. string text;
  99. bool exit = false;
  100.  
  101.  
  102.  
  103. client.Close();
  104. Console.WriteLine("Disconnected; press <enter> to exit.");
  105. Console.ReadLine();
  106.  
  107.  
  108. }
  109. void OnAction(object sender, ActionEventArgs e)
  110. {
  111. msg = "<" + e.Data.Nick + " " + e.ActionMessage + ">";
  112. }
  113. void OnJoin(object sender, JoinEventArgs e)
  114. {
  115. msg = e.Data.Nick + " Has Joined #Omnimaga";
  116. }
  117. void OnPart(object sender, PartEventArgs e)
  118. {
  119. if (e.Data.Message != null)
  120. {
  121. msg = e.Data.Nick + " Has Left #Omnimaga Stating" + e.Data.Message;
  122. }
  123. else
  124. {
  125. msg = e.Data.Nick + " Has Left #Omnimaga";
  126. }
  127. }
  128. void OnQuit(object sender, QuitEventArgs e)
  129. {
  130. if (e.Data.Message != null)
  131. {
  132. msg = e.Data.Nick + " Has Left #Omnimaga Stating" + e.Data.Message;
  133. }
  134. else
  135. {
  136. msg = e.Data.Nick + " Has Left #Omnimaga";
  137. }
  138. }
  139. void OnKick(object sender, KickEventArgs e)
  140. {
  141. msg = e.Whom + " Was kicked from #Omnimaga By " + e.Data.Nick + " Because of " + e.Data.Message;
  142. }
  143. void OnConnected(object sender, EventArgs e)
  144. {
  145. Console.WriteLine("Connected");
  146. irccli.Login("OmniSCBot", "OmniSCBot", 0, "OmniSCBot");
  147. Console.WriteLine("Login Processed");
  148. irccli.WriteLine("join #omnimaga\n");
  149. irccli.ListenOnce();
  150. }
  151. void OnChannelMessage(object sender, IrcEventArgs e)
  152. {
  153. Console.WriteLine(e.Data.Type + ":");
  154. Console.WriteLine("(" + e.Data.Channel + ") <" +
  155. e.Data.Nick + "> " + e.Data.Message);
  156. msg = "<" + e.Data.Nick + "> " + e.Data.Message;
  157.  
  158. }
  159.  
  160. void OnQueryMessage(object sender, IrcEventArgs e)
  161. {
  162. Console.WriteLine(e.Data.Type + ":");
  163. Console.WriteLine("(private) <" + e.Data.Nick + "> " +
  164. e.Data.Message);
  165. }
  166.  
  167. static void client_MessageSent(object sender, ChatMessageEventArgs e)
  168. {
  169. if (e.EventType == ChatEventType.Emote)
  170. {
  171. Console.WriteLine("<{0} {1}>", e.Username, e.Text);
  172. }
  173. else
  174. {
  175. Console.WriteLine("[{0}]: {1}", e.Username, e.Text);
  176. }
  177. }
  178.  
  179.  
  180. static void BufferAllocated(object sender, EventArgs e)
  181. {
  182. Console.WriteLine("=+=+= BUFFER ALLOCATED =+=+=");
  183. Console.WriteLine((sender as BufferPool).Name);
  184. }
  185.  
  186.  
  187. static void client_JoinedChannel(object sender, ServerChatEventArgs e)
  188. {
  189. Console.WriteLine("CHANNEL: {0}", e.Text);
  190. specialmsg = "GO! GO! GO!";
  191. }
  192.  
  193.  
  194. static void client_ClientCheckFailed(object sender, ClientCheckFailedEventArgs e)
  195. {
  196. Console.WriteLine("--- VERSIONING FAILED {0}:", e.Reason);
  197. Console.WriteLine(e.AdditionalInformation);
  198. }
  199.  
  200.  
  201. static void client_UserEmoted(object sender, ChatMessageEventArgs e)
  202. {
  203. Console.WriteLine("<{0} {1}>", e.Username, e.Text);
  204. msg2 = "<" + e.Username + " " +e.Text + ">";
  205. }
  206.  
  207.  
  208. static void client_UserSpoke(object sender, ChatMessageEventArgs e)
  209. {
  210. Console.WriteLine("{0}: {1}", e.Username, e.Text);
  211. msg2 = "<" + e.Username + "> " + e.Text;
  212. }
  213.  
  214. static void client_UserLeft(object sender, UserEventArgs e)
  215. {
  216. Console.WriteLine("USER LEFT: {0}", e.User.Username);
  217. msg2 = e.User.Username + " Left the Omnimaga Starcraft Channel.";
  218. }
  219.  
  220.  
  221. static void client_UserJoined(object sender, UserEventArgs e)
  222. {
  223. Console.WriteLine("USER JOIN: {0} ({1})", e.User.Username, e.User.Stats.LiteralText);
  224. msg2 = e.User.Username + " Joined the Omnimaga Starcraft Channel.";
  225. }
  226.  
  227.  
  228. static void client_UserShown(object sender, UserEventArgs e)
  229. {
  230. Console.WriteLine("USER: {0} ({1})", e.User.Username, e.User.Stats.LiteralText);
  231. }
  232.  
  233.  
  234. static void client_ServerErrorReceived(object sender, ServerChatEventArgs e)
  235. {
  236. Console.WriteLine("SERVER ERROR: {0}", e.Text);
  237. }
  238.  
  239.  
  240. static void client_ServerBroadcast(object sender, ServerChatEventArgs e)
  241. {
  242. Console.WriteLine("SERVER: {0}", e.Text);
  243. }
  244.  
  245.  
  246. static void client_LoginFailed(object sender, LoginFailedEventArgs e)
  247. {
  248. Console.WriteLine("--- LOGIN FAILED:");
  249. }
  250.  
  251.  
  252. static void client_LoginSucceeded(object sender, EventArgs e)
  253. {
  254. Console.WriteLine("--- LOGIN SUCCEEDED");
  255. }
  256.  
  257.  
  258. static void client_EnteredChat(object sender, EnteredChatEventArgs e)
  259. {
  260. Console.WriteLine("Entered chat as {0}", e.UniqueUsername);
  261. }
  262.  
  263.  
  264. static void client_Error(object sender, BNSharp.ErrorEventArgs e)
  265. {
  266. Console.WriteLine("ERROR: {0}", e.Error);
  267. }
  268. }
  269.  
  270.  
  271. class Settings : IBattleNetSettings
  272. {
  273. #region IBattleNetSettings Members
  274.  
  275.  
  276. public string Client
  277. {
  278. get
  279. {
  280. return "STAR";
  281. }
  282. set
  283. {
  284.  
  285. }
  286. }
  287.  
  288.  
  289. public int VersionByte
  290. {
  291. get
  292. {
  293. return 0xd1;
  294. }
  295. set
  296. {
  297.  
  298. }
  299. }
  300.  
  301.  
  302. public string CdKey1
  303. {
  304. get;
  305. set;
  306. }
  307.  
  308.  
  309. public string CdKey2
  310. {
  311. get
  312. {
  313. return null;
  314. }
  315. set
  316. {
  317.  
  318. }
  319. }
  320.  
  321.  
  322. public string GameExe
  323. {
  324. get
  325. {
  326. return @"C:\Gamefiles\STAR\Starcraft.exe";
  327. }
  328. set
  329. {
  330.  
  331. }
  332. }
  333.  
  334.  
  335. public string GameFile2
  336. {
  337. get
  338. {
  339. return @"C:\Gamefiles\STAR\Storm.dll";
  340. }
  341. set
  342. {
  343.  
  344. }
  345. }
  346.  
  347.  
  348. public string GameFile3
  349. {
  350. get
  351. {
  352. return @"C:\Gamefiles\STAR\Battle.snp";
  353. }
  354. set
  355. {
  356.  
  357. }
  358. }
  359.  
  360.  
  361. public string Username
  362. {
  363. get;
  364. set;
  365. }
  366.  
  367.  
  368. public string ImageFile
  369. {
  370. get
  371. {
  372. return @"C:\Gamefiles\STAR\STAR.bin";
  373. }
  374. set
  375. {
  376.  
  377. }
  378. }
  379.  
  380.  
  381. public string Password
  382. {
  383. get;
  384. set;
  385. }
  386.  
  387.  
  388. public string Server
  389. {
  390. get
  391. {
  392. return "uswest.battle.net";
  393. }
  394. set
  395. {
  396.  
  397. }
  398. }
  399.  
  400.  
  401. public int Port
  402. {
  403. get
  404. {
  405. return 6112;
  406. }
  407. set
  408. {
  409.  
  410. }
  411. }
  412.  
  413.  
  414. public string CdKeyOwner
  415. {
  416. get;
  417. set;
  418. }
  419.  
  420.  
  421. #endregion
  422.  
  423.  
  424. #region IBattleNetSettings Members
  425.  
  426.  
  427.  
  428.  
  429. public BNSharp.BattleNet.PingType PingMethod
  430. {
  431. get { return BNSharp.BattleNet.PingType.Normal; }
  432. set { }
  433. }
  434.  
  435.  
  436. #endregion
  437. }
  438. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement