示例#1
0
        /// <summary>
        ///     Start connecting to Steam
        /// </summary>
        private void StartSteamConnection()
        {
            ReleaseSteamConnection();

            var c = SteamClient = new SteamClient();

            DotaGCHandler.Bootstrap(c, Games.DOTA2);

            SteamUser    = c.GetHandler <SteamUser>();
            SteamFriends = c.GetHandler <SteamFriends>();

            var cb = _cbManager = new CallbackManager(c);

            SetupSteamCallbacks(cb);
            SetupDotaGcCallbacks(cb);

            c.Connect();
            _cbThreadCtr++;
            _procThread = new Thread(SteamThread);
            _procThread.Start(this);
        }
示例#2
0
 /// <summary>
 ///     Create a game client attached to an existing DOTA gc handler.
 /// </summary>
 /// <param name="gc">existing GC handler</param>
 /// <param name="cb">callback manager</param>
 /// <param name="publicIp">optionally help out by specifying the public ip address</param>
 public DotaGameClient(DotaGCHandler gc, CallbackManager cb, IPAddress publicIp = null)
 {
     Callbacks            = cb;
     _registeredCallbacks = new List <CallbackBase>();
     _gameConnectTokens   = new Queue <byte[]>(11);
     DotaGc = gc;
     RegisterCallbacks();
     if (DotaGc.SteamClient.IsConnected)
     {
         FetchAppTicket();
     }
     if (publicIp != null)
     {
         publicIP = publicIp;
     }
     else if (DotaGc.SteamClient.IsConnected)
     {
         CheckPublicIP();
     }
     EntityBuilder = DotaEntitySet.Associate(new DotaEntityPool.Builder());
     Controllers   = new List <IDotaGameController>(1);
 }
示例#3
0
        private async Task Run()
        {
            try
            {
                if (File.Exists("config.json"))
                {
                    using (var sr = new StreamReader("config.json"))
                    {
                        string jsonString = string.Empty;
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            jsonString += line;
                        }
                        botConfig = JsonConvert.DeserializeObject <ConfigModel>(jsonString);
                        if (string.IsNullOrEmpty(botConfig.login))
                        {
                            Console.WriteLine("ERROR: Steam login is empty");
                            await Task.Delay(3000);

                            return;
                        }
                        if (string.IsNullOrEmpty(botConfig.password))
                        {
                            Console.WriteLine("ERROR: Steam password is empty");
                            await Task.Delay(3000);

                            return;
                        }
                        if (string.IsNullOrEmpty(botConfig.msgText))
                        {
                            Console.WriteLine("ERROR: Message content is empty");
                            await Task.Delay(3000);

                            return;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("ERROR: config.json file is not found");
                    await Task.Delay(3000);

                    return;
                }
                if (File.Exists("chat_regions.txt"))
                {
                    chatRegions = File.ReadAllLines("chat_regions.txt");
                }

                //DebugLog.AddListener(new DebugListener());
                //DebugLog.Enabled = true;
                //create our steamclient instance
                var cellid = 0u;

                // if we've previously connected and saved our cellid, load it.
                if (File.Exists("cellid.txt"))
                {
                    if (!uint.TryParse(File.ReadAllText("cellid.txt"), out cellid))
                    {
                        Console.WriteLine("Error parsing cellid from cellid.txt. Continuing with cellid 0.");
                        cellid = 0;
                    }
                    else
                    {
                        Console.WriteLine($"Using persisted cell ID {cellid}");
                    }
                }
                var configuration = SteamConfiguration.Create((config) =>
                {
                    config.WithServerListProvider(new FileStorageServerListProvider("servers_list.bin"));
                    config.WithCellID(cellid);
                });

                steamClient = new SteamClient(configuration);
                DotaGCHandler.Bootstrap(steamClient);
                dota = steamClient.GetHandler <DotaGCHandler>();

                // create the callback manager which will route callbacks to function calls
                manager = new CallbackManager(steamClient);

                // get the steamuser handler, which is used for logging on after successfully connecting
                steamUser = steamClient.GetHandler <SteamUser>();

                // register a few callbacks we're interested in
                // these are registered upon creation to a callback manager, which will then route the callbacks
                // to the functions specified
                manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
                manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);

                manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
                manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);
                manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
                manager.Subscribe <DotaGCHandler.BeginSessionResponse>(OnBeginSession);
                manager.Subscribe <DotaGCHandler.ConnectionStatus>(OnConnectionStatus);
                manager.Subscribe <DotaGCHandler.JoinChatChannelResponse>(OnJoinChatChannel);
                manager.Subscribe <DotaGCHandler.ChatChannelListResponse>(OnChatChannelList);
                manager.Subscribe <DotaGCHandler.GCWelcomeCallback>(OnDotaWelcome);

                isRunning = true;
                Console.WriteLine("Connecting to Steam...");

                // initiate the connection
                steamClient.Connect();
                while (isRunning)
                {
                    manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception occured: {ex.GetType()}: {ex.Message}");
                dotaIsReady = false;
                steamClient.Disconnect();
            }
            await Task.Delay(-1);
        }
示例#4
0
        /// <summary>
        /// Connects to steam & logs in the bot account.
        /// This is SYNCHRONOUS.
        /// </summary>
        public void Connect()
        {
            client.Connect();
            doLoop = true;
            messageLoop.Start();

            // wait for successful connection
            while (true)
            {
                if (Connected)
                {
                    break;
                }
            }

            user.LogOn(new SteamUser.LogOnDetails {
                Username = username,
                Password = password,
            });

            //wait for successful login
            while (true)
            {
                if (LoggedIn)
                {
                    break;
                }
            }

            DotaGCHandler.Bootstrap(client, Dota2.Base.Data.Games.DOTA2);
            dota = client.GetHandler <DotaGCHandler>();

            //wait for successful dota connection
            bool retry = false;

            do
            {
                retry = false;
                if (ConnectToDota())
                {
                    UpdateStatus(DotaClientStatus.Normal, "Dota: Connected.");
                }
                else
                {
                    retry = this.parameters.dota_reconnect;
                    if (retry)
                    {
                        UpdateStatus(DotaClientStatus.Warning, "Dota: Connection Failed. Retrying...");
                        continue;
                    }
                    else
                    {
                        UpdateStatus(DotaClientStatus.Fatal, "Dota: Connection Failed.");
                        return;
                    }
                }

                if (dota.Lobby != null)
                {
                    UpdateStatus(DotaClientStatus.Warning, "Lobby: Already in a lobby. Leaving...");
                    dota.LeaveLobby();
                    while (dota.Lobby == null)
                    {
                        Thread.Sleep(10);
                    }
                    UpdateStatus(DotaClientStatus.Warning, "Dota: Reconnecting...");
                    dota.Stop();
                    Thread.Sleep(7000);
                    retry = true;
                }
            } while (retry);
        }