Пример #1
0
        public void Update()
        {
            if (_connectStarted.Elapsed.TotalSeconds > 120)
            {
                _bot?.Disconnect();
                Status = ConnectionStatus.Disconnected;
            }

            if (Status != ConnectionStatus.Disconnected)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(Program.Settings.Username) ||
                string.IsNullOrWhiteSpace(Program.Settings.Password))
            {
                return;
            }

            _hasConnected = false;
            _connectStarted.Restart();
            Program.Logger.Info("Connecting");

            _bot = new SteamBot(Program.Settings.Username, Program.Settings.Password, Program.Settings.AuthCode);

            _bot.OnConnected     += BotConnected;
            _bot.OnDisconnected  += BotDisconnected;
            _bot.OnFriendRequest += BotFriendRequest;
            _bot.OnPrivateEnter  += BotPrivateEnter;
            _bot.OnChatInvite    += BotChatInvite;

            _bot.Connect();
            Status = ConnectionStatus.Connecting;
        }
Пример #2
0
        private static BufferedMachine <Event, State> MakeMachine(
            SteamBot bot, Client client)
        {
            Machines.Call connect = () => {
                bot.Connect();
            };
            Machines.Call open = () => {
                bot.SetFriendsOnline(bot.Logon.Username);
                client.Launch(Games.DotaGameId);
            };
            Machines.Call sayHello = () => {
                client.SayHello();
            };
            Machines.Call leaveLobby = () => {
                if (client.Lobby.connect == null)
                {
                    client.LeaveLobby();
                }
                else
                {
                    client.AbandonCurrentGame();
                }
            };
            Machines.Call getTicket = () => {
                client.GetAppTicket();
            };
            Machines.Call createLobby = () => {
                client.CreateLobby("cow");
            };
            Machines.Call joinRadiant = () => {
                client.JoinLobbySlot(
                    SteamKit2.GC.Dota.Internal.DOTA_GC_TEAM.DOTA_GC_TEAM_GOOD_GUYS);
            };
            Machines.Call startLobby = () => {
                client.LaunchLobby();
            };
            Machines.Call getAuth = () => {
                client.CreateAuthTicket();
                client.Auth();
            };
            Machines.Call beginSession = () => {
                client.BeginGameServerSession();
            };
            Machines.Call join = () => {
                string[] split    = client.Lobby.connect.Split(':');
                var      endpoint = new IPEndPoint(IPAddress.Parse(split[0]), Int16.Parse(split[1]));

                Lara.Join(new ConnectionDetails()
                {
                    Endpoint            = endpoint,
                    SteamId             = bot.Client.SteamID.ConvertToUInt64(),
                    Nickname            = bot.Logon.Username,
                    SteamworksSessionId = client.SteamworksSessionId,
                    Ticket = client.TicketForServer,
                    Secret = client.Lobby.pass_key
                }, new AshlyController());
            };

            Func <State, Machines.MachineBinding <Event, State> > Start =
                Machines.Start <Event, State>;
            Func <State, Machines.MachineStateBinding <Event, State> > In =
                Machines.In <Event, State>;
            Func <Event, Machines.MachineTransitionBinding <Event, State> > On =
                Machines.On <Event, State>;
            var unbuffered = Start(State.CONCEIVED)
                             .Add(In(State.CONCEIVED)
                                  .Add(On(Event.OPEN_REQUEST).Transit(State.CONNECTING_TO_STEAM)))
                             .Add(In(State.CONNECTING_TO_STEAM)
                                  .Entry(connect)
                                  .Add(On(Event.CONNECTED_TO_STEAM).Transit(State.OPENING))
                                  .Add(On(Event.DISCONNECTED_FROM_STEAM).Call(connect).Transit(State.CONNECTING_TO_STEAM)))
                             .Add(In(State.OPENING)
                                  .Entry(open)
                                  .Add(On(Event.PLAYING_STATE_OPENED).Transit(State.CONNECTING)))
                             .Add(In(State.CONNECTING)
                                  .Entry(sayHello)
                                  .Add(On(Event.WELCOMED).Transit(State.GETTING_TICKET))
                                  .Add(On(Event.WELCOMED_STALE_LOBBY).Transit(State.IN_STALE_LOBBY)))
                             .Add(In(State.IN_STALE_LOBBY)
                                  .Entry(leaveLobby)
                                  .Add(On(Event.LEFT_LOBBY).Transit(State.GETTING_TICKET)))
                             .Add(In(State.GETTING_TICKET)
                                  .Entry(getTicket)
                                  .Add(On(Event.GOT_APP_TICKET).Transit(State.DOTA_HOME)))
                             .Add(In(State.DOTA_HOME)
                                  .Entry(createLobby)
                                  .Add(On(Event.CREATED_LOBBY).Transit(State.IN_LOBBY)))
                             .Add(In(State.IN_LOBBY)
                                  .Entry(joinRadiant)
                                  .Add(On(Event.LOBBY_READY).Transit(State.LOBBY_STARTING)))
                             .Add(In(State.LOBBY_STARTING)
                                  .Entry(startLobby)
                                  .Add(On(Event.SERVER_RUNNING).Transit(State.GETTING_AUTH)))
                             .Add(In(State.GETTING_AUTH)
                                  .Entry(getAuth)
                                  .Add(On(Event.GOT_AUTH).Transit(State.GETTING_SESSION)))
                             .Add(In(State.GETTING_SESSION)
                                  .Entry(beginSession)
                                  .Add(On(Event.GOT_SESSION).Transit(State.JOINING_GAME)))
                             .Add(In(State.JOINING_GAME)
                                  .Entry(join))
                             .Build();

            return(new BufferedMachine <Event, State>(unbuffered));
        }
Пример #3
0
        public void Update()
        {
            if (_connectStarted.Elapsed.TotalSeconds > 120)
            {
                if (_bot != null)
                {
                    _bot.Disconnect();
                }
                Status = ConnectionStatus.Disconnected;
            }

            if (Status != ConnectionStatus.Disconnected)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(Program.Settings.Username) ||
                string.IsNullOrWhiteSpace(Program.Settings.Password))
            {
                return;
            }

            _hasConnected = false;
            _connectStarted.Restart();
            Program.Logger.Info("Connecting");

            _bot              = new SteamBot(Program.Settings.Username, Program.Settings.Password, Program.Settings.AuthCode);
            _bot.OnConnected += sender =>
            {
                _hasConnected = true;
                _connectStarted.Stop();

                _bot.DisplayName  = Program.Settings.PersonaName;
                _bot.PersonaState = EPersonaState.Online;
                Status            = ConnectionStatus.Connected;

                Program.Logger.Info("Connected");
            };

            _bot.OnDisconnected += (sender, reason) =>
            {
                if (reason == SteamBotDisconnectReason.SteamGuard)
                {
                    Thread.Sleep(TimeSpan.FromMinutes(2)); // TODO: need a better way of entering steamguard auth
                }
                if (_hasConnected)
                {
                    Program.Logger.InfoFormat("Disconnected {0}", reason);
                    _hasConnected = false;
                }

                Status = ConnectionStatus.Disconnected;
            };

            _bot.OnFriendRequest += (sender, user) => _bot.AddFriend(user.Id);

            _bot.OnPrivateEnter += (sender, chat) =>
            {
                chat.OnMessage += (chatSender, messageSender, message) =>
                                  Command.Handle(new CommandTarget(chatSender, messageSender), message, "");
            };

            _bot.OnChatInvite += (sender, chat, @by) =>
            {
                if (chat.Id.IsIndividualAccount)
                {
                    _bot.Join(chat.Id);
                }
            };

            _bot.Connect();
            Status = ConnectionStatus.Connecting;
        }