• Welcome to Valhalla Legends Archive.
 

Simple C# Bot...

Started by clamothe, April 27, 2004, 01:09 AM

Previous topic - Next topic

clamothe

Hey!  I'm starting to write a C# bot, but I have no idea how to parse or send Bnet packets in it!  I have used the packetbuffer class before.

My current code (I started a few hours ago :))
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;

namespace CsharpBot
{
   /// <summary>
   /// This is the main form for this shit :p
   /// </summary>
   public class Form1 : System.Windows.Forms.Form
   {
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.Container components = null;

      public Form1()
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();

         //
         // TODO: Add any constructor code after InitializeComponent call
         //
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         //
         // Form1
         //
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(456, 374);
         this.Name = "Form1";
         this.Text = "CovertBot";

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
         Application.Run(new Form1());
      }
   }


   public class MySocket
   {
      public string host = "uswest.battle.net";
      public int port = 6112;
      private Socket s;

      private static Socket ConnectSocket(string server, int port)
      {
         Socket s = null;
         IPHostEntry hostEntry = null;
       
         // Get host related information.
         hostEntry = Dns.Resolve(server);

         // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
         // an exception that occurs when the host IP Address is not compatible with the address family
         // (typical in the IPv6 case).
         foreach(IPAddress address in hostEntry.AddressList)
         {
            IPEndPoint ipe = new IPEndPoint(address, port);
            Socket tempSocket =
               new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            tempSocket.Connect(ipe);

            if(tempSocket.Connected)
            {
               s = tempSocket;
               break;
            }
            else
            {
               continue;
            }
         }
         return s;
      }

      public static int Connect()
      {
         if(host != "")
         {
            s = ConnectSocket(host, port);
         }

      }

      public static void Main(string[] args);
   }

}

As i said, I just started working on this.  Any ideas on how to parse and send packets in C#?

MyndFyre

#1
My Packet classes:

http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=display;threadid=4150;start=msg34300#msg34300

I suggest using the asynchronous BeginConnect(), BeginReceive(), and BeginSend() methods on the Socket class, because the others are blocking and can cause your client to slow down horribly.

Also, in this thread is the interface definition of a class I wrote called IncomingPacketStream:

http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=display;threadid=5042;start=msg42358#msg42358

Hope this helps.

[edit] These have both changed somewhat since the time of posting, but they are relatively the same.  Note that in my code, I have static Packet methods on both of the derived Packet classes for each specific kind of packet (for instance, BnetPacket.SID_AuthInfo(/* parameters */);
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

clamothe

Could you post an example about how to use these classes?

Thanks.

MyndFyre

Quote from: clamothe on April 28, 2004, 03:55 PM
Could you post an example about how to use these classes?

Thanks.

No.  The interfaces are defined very well.  If you want to use them, they shouldn't be too hard to figure out.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

c0ol

that first link doesnt work, can u repost it?

MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.