Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SteamKit2;
- using System.Collections.Generic;
- using SteamTrade;
- using System;
- using System.Timers;
- using System.Net;
- using System.Globalization;
- namespace SteamBot
- {
- public class KeyUserHandler : UserHandler
- {
- enum States { Hello, AfterHello, DecidedQuestion, UserQuestion, WaitingForCode };
- States state = States.Hello;
- Timer timer = new Timer();
- Timer timer2 = new Timer();
- Timer timer3 = new Timer();
- public KeyUserHandler(Bot bot, SteamID sid) : base(bot, sid)
- {
- }
- public override void OnLoginCompleted()
- {
- }
- public override bool OnFriendAdd()
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, SMSConfig.GetString("friendadd"));
- timer.Stop();
- timer = new Timer();
- timer.Elapsed += ResetTimerElapsed;
- timer.Interval = 30000;
- timer.Start();
- state = States.AfterHello;
- return true;
- }
- public override void OnFriendRemove()
- {
- }
- public static IPEndPoint CreateIPEndPoint(string endPoint)
- {
- string[] ep = endPoint.Split(':');
- if (ep.Length < 2) throw new FormatException("Invalid endpoint format");
- IPAddress ip;
- if (ep.Length > 2)
- {
- if (!IPAddress.TryParse(string.Join(":", ep, 0, ep.Length - 1), out ip))
- {
- throw new FormatException("Invalid ip-adress");
- }
- }
- else
- {
- if (!IPAddress.TryParse(ep[0], out ip))
- {
- throw new FormatException("Invalid ip-adress");
- }
- }
- int port;
- if (!int.TryParse(ep[ep.Length - 1], NumberStyles.None, NumberFormatInfo.CurrentInfo, out port))
- {
- throw new FormatException("Invalid port");
- }
- return new IPEndPoint(ip, port);
- }
- int messages = 0;
- public override void OnMessage(string message, EChatEntryType type)
- {
- timer.Stop();
- timer = new Timer();
- timer.Elapsed += ResetTimerElapsed;
- timer.Interval = 60000;
- timer.Start();
- timer3.Stop();
- timer3 = new Timer();
- timer3.Elapsed += SpamTimerElapsed;
- timer3.Interval = 4000;
- timer3.Start();
- messages++;
- if (messages == 10)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, "Przestań spamować!");
- state = States.AfterHello;
- return;
- }
- else if (messages > 10) return;
- if (message.ToLower() == "debug")
- {
- foreach (SMSConfig.SMSPacket packet in SMSConfig.Packets)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, packet.code + " - " + packet.rcon);
- }
- CSSRcon rcon = new CSSRcon();
- rcon.Connect(CreateIPEndPoint(SMSConfig.GetString("ip")), SMSConfig.GetString("password"));
- rcon.ServerCommand("say dupa123");
- return;
- }
- if (message.ToLower() == "hwdp")
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, "Zostałeś namierzony!");
- Bot.SteamFriends.SendChatMessage(OtherSID, type, "Pawian już po Ciebie jedzie!");
- return;
- }
- if (state == States.Hello)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("hello"));
- state = States.AfterHello;
- return;
- }
- else if (state == States.DecidedQuestion)
- {
- if (message.ToLower() == "tak" || message.ToLower() == "yes" || message.ToLower() == "ofc" || message.ToLower() == "jasne" || message.ToLower() == "oczywiscie" || message.ToLower() == "yup")
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("entercode"));
- state = States.WaitingForCode;
- }
- else if (message.ToLower() == "nie" || message.ToLower() == "no" || message.ToLower() == "nope")
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, "Szkoda. Może innym razem.");
- state = States.AfterHello;
- }
- else
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, "Poprostu powiedz tak albo nie :)");
- }
- return;
- }
- else if (state == States.WaitingForCode)
- {
- Log.Warn("Wprowadzono kod: " + message);
- bool done = false;
- try
- {
- foreach (SMSConfig.SMSPacket packet in SMSConfig.Packets)
- {
- string response = new WebClient().DownloadString("http://mintshost.pl/sms.php?kod=" + message + "&email=" + SMSConfig.GetString("email") + "&sms=" + packet.code);
- if (response == "1")
- {
- done = true;
- Log.Warn("Kod poprawny: " + message);
- CSSRcon rcon = new CSSRcon();
- rcon.Connect(CreateIPEndPoint(SMSConfig.GetString("ip")), SMSConfig.GetString("password"));
- rcon.ServerCommand(packet.rcon.Replace("%steamid%", OtherSID.Render()));
- break;
- }
- }
- }
- catch
- { }
- if (!done)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("invalidcode"));
- }
- else
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("thanks"));
- state = States.AfterHello;
- }
- return;
- }
- if (message.ToLower() == "help")
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("help"));
- }
- else if (message.ToLower() == "vip")
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("vip"));
- timer2.Stop();
- timer2 = new Timer();
- timer2.Elapsed += DecidedTimerElapsed;
- timer2.Interval = 2000;
- timer2.Start();
- }
- else if (message.ToLower() == "supervip")
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("supervip"));
- timer2.Stop();
- timer2 = new Timer();
- timer2.Elapsed += DecidedTimerElapsed;
- timer2.Interval = 2000;
- timer2.Start();
- }
- else if (message.ToLower().IndexOf("mam") != -1 || message.ToLower().IndexOf("kod") != -1)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("entercode"));
- state = States.WaitingForCode;
- }
- else
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, type, SMSConfig.GetString("invalidcommand"));
- }
- }
- public void ResetTimerElapsed(object sender, ElapsedEventArgs e)
- {
- timer.Stop();
- state = States.Hello;
- }
- public void DecidedTimerElapsed(object sender, ElapsedEventArgs e)
- {
- timer2.Stop();
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "To jak? Zdecydowany?");
- state = States.DecidedQuestion;
- }
- public void SpamTimerElapsed(object sender, ElapsedEventArgs e)
- {
- timer3.Stop();
- messages = 0;
- }
- public override bool OnTradeRequest()
- {
- return true;
- }
- public override void OnTradeError(string error)
- {
- }
- public override void OnTradeTimeout()
- {
- }
- public override void OnTradeInit()
- {
- }
- public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
- {
- }
- public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
- {
- }
- public override void OnTradeMessage(string message)
- {
- }
- public override void OnTradeReady(bool ready)
- {
- }
- public override void OnTradeAccept()
- {
- }
- public override void OnTradeClose()
- {
- }
- public bool Validate()
- {
- return true;
- }
- bool hasDuplicateID(List<ulong> list)
- {
- var hashset = new HashSet<ulong>();
- foreach (var id in list)
- {
- if (!hashset.Add(id))
- {
- return true;
- }
- }
- return false;
- }
- public void TradeCountInventory(bool message)
- {
- }
- public void ReInit()
- {
- }
- public void Advertise(EChatEntryType type)
- {
- }
- private void OnTimerElapsed(object source, ElapsedEventArgs e, EChatEntryType type)
- {
- }
- private void OnInviteTimerElapsed(object source, ElapsedEventArgs e, EChatEntryType type)
- {
- }
- public void ResetTrade(bool message)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement