Advertisement
szymski

Untitled

Nov 15th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.05 KB | None | 0 0
  1. using SteamKit2;
  2. using System.Collections.Generic;
  3. using SteamTrade;
  4. using System;
  5. using System.Timers;
  6. using System.Net;
  7. using System.Globalization;
  8.  
  9. namespace SteamBot
  10. {
  11. public class KeyUserHandler : UserHandler
  12. {
  13. enum States { Hello, AfterHello, DecidedQuestion, UserQuestion, WaitingForCode };
  14. States state = States.Hello;
  15.  
  16. Timer timer = new Timer();
  17. Timer timer2 = new Timer();
  18. Timer timer3 = new Timer();
  19.  
  20. public KeyUserHandler(Bot bot, SteamID sid) : base(bot, sid)
  21. {
  22.  
  23. }
  24.  
  25. public override void OnLoginCompleted()
  26. {
  27. }
  28.  
  29. public override bool OnFriendAdd()
  30. {
  31. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, SMSConfig.GetString("friendadd"));
  32. timer.Stop();
  33. timer = new Timer();
  34. timer.Elapsed += ResetTimerElapsed;
  35. timer.Interval = 30000;
  36. timer.Start();
  37. state = States.AfterHello;
  38. return true;
  39. }
  40.  
  41. public override void OnFriendRemove()
  42. {
  43.  
  44. }
  45.  
  46. public static IPEndPoint CreateIPEndPoint(string endPoint)
  47. {
  48. string[] ep = endPoint.Split(':');
  49. if (ep.Length < 2) throw new FormatException("Invalid endpoint format");
  50. IPAddress ip;
  51. if (ep.Length > 2)
  52. {
  53. if (!IPAddress.TryParse(string.Join(":", ep, 0, ep.Length - 1), out ip))
  54. {
  55. throw new FormatException("Invalid ip-adress");
  56. }
  57. }
  58. else
  59. {
  60. if (!IPAddress.TryParse(ep[0], out ip))
  61. {
  62. throw new FormatException("Invalid ip-adress");
  63. }
  64. }
  65. int port;
  66. if (!int.TryParse(ep[ep.Length - 1], NumberStyles.None, NumberFormatInfo.CurrentInfo, out port))
  67. {
  68. throw new FormatException("Invalid port");
  69. }
  70. return new IPEndPoint(ip, port);
  71. }
  72.  
  73. int messages = 0;
  74.  
  75. public override void OnMessage(string message, EChatEntryType type)
  76. {
  77. timer.Stop();
  78. timer = new Timer();
  79. timer.Elapsed += ResetTimerElapsed;
  80. timer.Interval = 60000;
  81. timer.Start();
  82. timer3.Stop();
  83. timer3 = new Timer();
  84. timer3.Elapsed += SpamTimerElapsed;
  85. timer3.Interval = 4000;
  86. timer3.Start();
  87.  
  88. messages++;
  89.  
  90. if (messages == 10)
  91. {
  92. Bot.SteamFriends.SendChatMessage(OtherSID, type, "Przestań spamować!");
  93. state = States.AfterHello;
  94. return;
  95. }
  96. else if (messages > 10) return;
  97.  
  98. if (message.ToLower() == "debug")
  99. {
  100. foreach (SMSConfig.SMSPacket packet in SMSConfig.Packets)
  101. {
  102. Bot.SteamFriends.SendChatMessage(OtherSID, type, packet.code + " - " + packet.rcon);
  103. }
  104. CSSRcon rcon = new CSSRcon();
  105. rcon.Connect(CreateIPEndPoint(SMSConfig.GetString("ip")), SMSConfig.GetString("password"));
  106. rcon.ServerCommand("say dupa123");
  107. return;
  108. }
  109.  
  110. if (message.ToLower() == "hwdp")
  111. {
  112. Bot.SteamFriends.SendChatMessage(OtherSID, type, "Zostałeś namierzony!");
  113. Bot.SteamFriends.SendChatMessage(OtherSID, type, "Pawian już po Ciebie jedzie!");
  114. return;
  115. }
  116.  
  117. if (state == States.Hello)
  118. {
  119. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("hello"));
  120. state = States.AfterHello;
  121. return;
  122. }
  123. else if (state == States.DecidedQuestion)
  124. {
  125. if (message.ToLower() == "tak" || message.ToLower() == "yes" || message.ToLower() == "ofc" || message.ToLower() == "jasne" || message.ToLower() == "oczywiscie" || message.ToLower() == "yup")
  126. {
  127. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("entercode"));
  128. state = States.WaitingForCode;
  129. }
  130. else if (message.ToLower() == "nie" || message.ToLower() == "no" || message.ToLower() == "nope")
  131. {
  132. Bot.SteamFriends.SendChatMessage(OtherSID, type, "Szkoda. Może innym razem.");
  133. state = States.AfterHello;
  134. }
  135. else
  136. {
  137. Bot.SteamFriends.SendChatMessage(OtherSID, type, "Poprostu powiedz tak albo nie :)");
  138. }
  139. return;
  140. }
  141. else if (state == States.WaitingForCode)
  142. {
  143. Log.Warn("Wprowadzono kod: " + message);
  144. bool done = false;
  145. try
  146. {
  147. foreach (SMSConfig.SMSPacket packet in SMSConfig.Packets)
  148. {
  149. string response = new WebClient().DownloadString("http://mintshost.pl/sms.php?kod=" + message + "&email=" + SMSConfig.GetString("email") + "&sms=" + packet.code);
  150. if (response == "1")
  151. {
  152. done = true;
  153. Log.Warn("Kod poprawny: " + message);
  154. CSSRcon rcon = new CSSRcon();
  155. rcon.Connect(CreateIPEndPoint(SMSConfig.GetString("ip")), SMSConfig.GetString("password"));
  156. rcon.ServerCommand(packet.rcon.Replace("%steamid%", OtherSID.Render()));
  157. break;
  158. }
  159. }
  160. }
  161. catch
  162. { }
  163. if (!done)
  164. {
  165. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("invalidcode"));
  166. }
  167. else
  168. {
  169. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("thanks"));
  170. state = States.AfterHello;
  171. }
  172. return;
  173. }
  174.  
  175. if (message.ToLower() == "help")
  176. {
  177. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("help"));
  178. }
  179. else if (message.ToLower() == "vip")
  180. {
  181. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("vip"));
  182. timer2.Stop();
  183. timer2 = new Timer();
  184. timer2.Elapsed += DecidedTimerElapsed;
  185. timer2.Interval = 2000;
  186. timer2.Start();
  187. }
  188. else if (message.ToLower() == "supervip")
  189. {
  190. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("supervip"));
  191. timer2.Stop();
  192. timer2 = new Timer();
  193. timer2.Elapsed += DecidedTimerElapsed;
  194. timer2.Interval = 2000;
  195. timer2.Start();
  196. }
  197. else if (message.ToLower().IndexOf("mam") != -1 || message.ToLower().IndexOf("kod") != -1)
  198. {
  199. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("entercode"));
  200. state = States.WaitingForCode;
  201. }
  202. else
  203. {
  204. Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("invalidcommand"));
  205. }
  206. }
  207.  
  208. public void ResetTimerElapsed(object sender, ElapsedEventArgs e)
  209. {
  210. timer.Stop();
  211. state = States.Hello;
  212. }
  213.  
  214. public void DecidedTimerElapsed(object sender, ElapsedEventArgs e)
  215. {
  216. timer2.Stop();
  217. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "To jak? Zdecydowany?");
  218. state = States.DecidedQuestion;
  219. }
  220.  
  221. public void SpamTimerElapsed(object sender, ElapsedEventArgs e)
  222. {
  223. timer3.Stop();
  224. messages = 0;
  225. }
  226.  
  227. public override bool OnTradeRequest()
  228. {
  229. return true;
  230. }
  231.  
  232. public override void OnTradeError(string error)
  233. {
  234. }
  235.  
  236. public override void OnTradeTimeout()
  237. {
  238. }
  239.  
  240. public override void OnTradeInit()
  241. {
  242.  
  243. }
  244.  
  245. public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
  246. {
  247.  
  248. }
  249.  
  250. public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
  251. {
  252.  
  253. }
  254.  
  255. public override void OnTradeMessage(string message)
  256. {
  257.  
  258. }
  259.  
  260. public override void OnTradeReady(bool ready)
  261. {
  262.  
  263. }
  264.  
  265. public override void OnTradeAccept()
  266. {
  267.  
  268. }
  269.  
  270. public override void OnTradeClose()
  271. {
  272.  
  273. }
  274.  
  275. public bool Validate()
  276. {
  277. return true;
  278. }
  279.  
  280.  
  281. bool hasDuplicateID(List<ulong> list)
  282. {
  283. var hashset = new HashSet<ulong>();
  284. foreach (var id in list)
  285. {
  286. if (!hashset.Add(id))
  287. {
  288. return true;
  289. }
  290. }
  291. return false;
  292. }
  293.  
  294.  
  295. public void TradeCountInventory(bool message)
  296. {
  297.  
  298. }
  299.  
  300. public void ReInit()
  301. {
  302.  
  303. }
  304.  
  305. public void Advertise(EChatEntryType type)
  306. {
  307.  
  308. }
  309.  
  310. private void OnTimerElapsed(object source, ElapsedEventArgs e, EChatEntryType type)
  311. {
  312.  
  313. }
  314.  
  315. private void OnInviteTimerElapsed(object source, ElapsedEventArgs e, EChatEntryType type)
  316. {
  317.  
  318. }
  319.  
  320. public void ResetTrade(bool message)
  321. {
  322.  
  323. }
  324. }
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement