Valhalla Legends Forums Archive | .NET Platform | Simple C# Bot...

AuthorMessageTime
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 :))
[code]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);
   }

}
[/code]
As i said, I just started working on this. Any ideas on how to parse and send packets in C#?
April 27, 2004, 6:09 AM
Myndfyr
My Packet classes:

https://davnit.net/bnet/vL/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:

https://davnit.net/bnet/vL/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 */);
April 27, 2004, 1:24 PM
clamothe
Could you post an example about how to use these classes?

Thanks.
April 28, 2004, 8:55 PM
Myndfyr
[quote author=clamothe link=board=37;threadid=6500;start=0#msg57334 date=1083185755]
Could you post an example about how to use these classes?

Thanks.
[/quote]

No. The interfaces are defined very well. If you want to use them, they shouldn't be too hard to figure out.
April 29, 2004, 4:21 PM
c0ol
that first link doesnt work, can u repost it?
July 21, 2004, 1:48 AM
Myndfyr
[quote author=c0ol link=board=37;threadid=6500;start=0#msg71592 date=1090374504]
that first link doesnt work, can u repost it?
[/quote]
https://davnit.net/bnet/vL/phpbbs/index.php?board=45;action=display;threadid=4150
July 21, 2004, 2:32 AM

Search