I’m trying to make a SteamRE bot which uses XNA, now, I just created a new XNA project, and slapped the SteamRE example code on it, if I run it, it works fine, but the thing is, it doesn’t actually start up the XNA window, so it can’t look for keyboard handling, etc.
If I remove the while(true) loop it works, but it won’t connect.
Here is my code, if you guys could look at this and maybe help me out, it would be great.
namespace Steam
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
string userName = "username";
string passWord = "password";
SteamClient steamClient = new SteamClient(); // initialize our client
SteamUser steamUser;
SteamFriends steamFriends;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
steamUser = steamClient.GetHandler<SteamUser>(); // we'll use this later to logon
steamFriends = steamClient.GetHandler<SteamFriends>();
}
protected override void UnloadContent()
{
}
KeyboardState oldState = Keyboard.GetState();
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
ConnectSteam();
base.Update(gameTime);
}
public void ConnectSteam()
{
steamClient.Connect(); // connect to the steam network
while (true)
{
CallbackMsg msg = steamClient.WaitForCallback(true); // block and wait until a callback is posted
msg.Handle<SteamClient.ConnectCallback>(callback =>
{
// the Handle function will call this lambda method for this callback
if (callback.Result != EResult.OK)
{
Console.WriteLine("Failed. 1");
}
//break; // the connect result wasn't OK, so something failed
// we've successfully connected to steam3, so lets logon with our details
Console.WriteLine("Connected to Steam3.");
steamUser.LogOn(new SteamUser.LogOnDetails
{
Username = userName,
Password = passWord,
});
Console.WriteLine("Logged on.");
});
msg.Handle<SteamUser.LogOnCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
Console.WriteLine("Failed. 2");
}
// we've now logged onto Steam3
});
}
}
public void ConnectToFPP()
{
KeyboardState newState = Keyboard.GetState(); // get the newest state
// handle the input
if (oldState.IsKeyUp(Keys.Space) && newState.IsKeyDown(Keys.Space))
{
steamFriends.JoinChat(110338190871147670);
}
oldState = newState; // set the new state as the old state for next time
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
Thanks!
The problem as far as I see it is that, unless you need to constantly connect, you need to break out of your ConnectSteam code whenever you have actually connected.
Or, you could have an isConnected variable (very pseudocod-ish):