• Welcome to Valhalla Legends Archive.
 
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - dave

#1
Hey, thanks for your answer!
But before adding some "add chat text" function I need to build up a working connection to BNET, and so far this doesn't work :/

Somehow I managed to get the invoke working.

        delegate void del(string text);
        private void bnet_chat_add(string text)
        {
            if (InvokeRequired)
            {
                del d = new del(bnet_chat_add);
                this.Invoke(d, new object[] { text });
            }
            lstB_bnet_chat.Items.Add(text);
        }


But as soon as I try to connect, the application freezes and I get a error message which says something like:
"No data can be written into the transmission connection: An existing connection was closed by the remote host."

Someone got an idea?

Regards Dave
#2
Hey guys,

just tried to build it the way MyndFyre explained it. But somehow I'm not able to get it to work.
Never worked with threads this way, only used the background worked and got it always to work somehow.
... and even don't know how "Invoke" works.

Maybe someone of you guys could tell me, what I have to change. Here is the code without "Invoke".
Sorry. I hope I'm not annoying.

Thanks in advance.
Best Regards, Dave


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BNSharp;
using BNSharp.Net;
using BNSharp.BattleNet;
using BNSharp.MBNCSUtil;
using BNSharp.Plugins;


namespace DIV_Gamelist_Bot
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        BattleNetClient client;
        string bnet_chat_message = "";

        class Settings : IBattleNetSettings
        {
            #region IBattleNetSettings Members

            public string CdKey1
            {
                get { return ""; }
                set { }
            }
            public string CdKey2 { get; set; }
            public string CdKeyOwner
            {
                get
                {
                    return "YOU DONT KNOW";
                }
                set { }
            }
            public string Client
            {
                get
                {
                    return "WAR3";
                }
                set { }
            }
            public string GameExe
            {
                get
                {
                    return @"Game\War3.exe";
                }
                set { }
            }
            public string GameFile2
            {
                get
                {
                    return @"Game\Storm.dll";
                }
                set { }
            }
            public string GameFile3
            {
                get
                {
                    return @"Game\Game.dll";
                }
                set { }
            }
            public string ImageFile { get; set; }
            public string Password { get; set; }
            public PingType PingMethod { get; set; }
            public int Port { get; set; }
            public string Server { get; set; }
            public string Username { get; set; }
            public int VersionByte
            {
                get
                {
                    return 0x17;
                }
                set { }
            }

            #endregion
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string realm = txtB_bnet_realm.Text;
            int rport = Convert.ToInt32(txtB_bnet_port.Text);
            string rockey = txtB_bnet_key.Text;
            string user = txtB_bnet_user.Text;
            string pwd = txtB_bnet_pass.Text;
            Settings set = new Settings() { CdKey1 = rockey, Server = realm, Port = rport, Username = user, Password = pwd };

            client = new BattleNetClient(set);
            client.Connected += delegate { bnet_chat_add("--- CONNECTED"); };
            client.Error += new ErrorEventHandler(client_Error);
            client.EnteredChat += new EnteredChatEventHandler(client_EnteredChat);
            client.LoginSucceeded += new EventHandler(client_LoginSucceeded);
            client.LoginFailed += new LoginFailedEventHandler(client_LoginFailed);
            client.ServerBroadcast += new ServerChatEventHandler(client_ServerBroadcast);
            client.ServerErrorReceived += new ServerChatEventHandler(client_ServerErrorReceived);
            client.UserShown += new UserEventHandler(client_UserShown);
            client.UserJoined += new UserEventHandler(client_UserJoined);
            client.UserLeft += new UserEventHandler(client_UserLeft);
            client.UserSpoke += new ChatMessageEventHandler(client_UserSpoke);
            client.UserEmoted += new ChatMessageEventHandler(client_UserEmoted);
            client.ClientCheckPassed += delegate { bnet_chat_add("--- VERSIONING PASSED"); };
            client.ClientCheckFailed += new ClientCheckFailedEventHandler(client_ClientCheckFailed);
            client.JoinedChannel += new ServerChatEventHandler(client_JoinedChannel);
            client.WardentUnhandled += delegate { bnet_chat_add("--- WARNING: Warden requested and unhandled!!"); };
            client.MessageSent += new ChatMessageEventHandler(client_MessageSent);
            client.Disconnected += delegate { bnet_chat_add("--- DISCONNECTED"); };

            bnet_chat_add("Battle.Net - Bot Settings loaded.");
        }

        #region BNET EVENTHANDLERS
        private void client_MessageSent(object sender, ChatMessageEventArgs e)
        {
            if (e.EventType == ChatEventType.Emote)
            {
                bnet_chat_add("<{0} {1}>" + e.Username + e.Text);
            }
            else
            {
                bnet_chat_add("[{0}]: {1}" + e.Username + e.Text);
            }
        }

        private void client_JoinedChannel(object sender, ServerChatEventArgs e)
        {
            bnet_chat_add("CHANNEL: {0}" + e.Text);
        }

        private void client_ClientCheckFailed(object sender, ClientCheckFailedEventArgs e)
        {
            bnet_chat_add("--- VERSIONING FAILED {0}:" + e.Reason);
            bnet_chat_add(e.AdditionalInformation);
        }

        private void client_UserEmoted(object sender, ChatMessageEventArgs e)
        {
            bnet_chat_add("<{0} {1}>" + e.Username + e.Text);
        }

        private void client_UserSpoke(object sender, ChatMessageEventArgs e)
        {
            bnet_chat_add("{0}: {1}" + e.Username + e.Text);
        }

        private void client_UserLeft(object sender, UserEventArgs e)
        {
            bnet_chat_add("USER LEFT: {0}" + e.User.Username);
        }

        private void client_UserJoined(object sender, UserEventArgs e)
        {
            bnet_chat_add("USER JOIN: {0} ({1})" + e.User.Username + e.User.Stats);
        }

        private void client_UserShown(object sender, UserEventArgs e)
        {
            bnet_chat_add("USER: {0} ({1})" + e.User.Username + e.User.Stats);
        }

        private void client_ServerErrorReceived(object sender, ServerChatEventArgs e)
        {
            bnet_chat_add("SERVER ERROR: {0}" + e.Text);
        }

        private void client_ServerBroadcast(object sender, ServerChatEventArgs e)
        {
            bnet_chat_add("SERVER: {0}" + e.Text);
        }

        private void client_LoginFailed(object sender, EventArgs e)
        {
            bnet_chat_add("--- LOGIN FAILED:");
        }

        private void client_LoginSucceeded(object sender, EventArgs e)
        {
            bnet_chat_add("--- LOGIN SUCCEEDED");
        }

        private void client_EnteredChat(object sender, EnteredChatEventArgs e)
        {
            bnet_chat_add("Entered chat as {0}" + e.UniqueUsername);
        }

        private void client_Error(object sender, ErrorEventArgs e)
        {
            bnet_chat_add("ERROR: {0}" + e.Error);
        }

        #endregion

        private void btn_bnet_connect_Click(object sender, EventArgs e)
        {
            client.Connect();

            string text;
            bool exit = false;
            do
            {
                text = bnet_chat_message;
                bnet_chat_message = "";
                if (!text.Equals("/exit", StringComparison.Ordinal))
                {
                    client.SendMessage(text);
                }
                else
                {
                    exit = true;
                }
            } while (!exit);

            client.Close();
            bnet_chat_add("Disconnected :(");

        }

        private void bnet_chat_add(string text)
        {
            lstB_bnet_chat.Items.Add(text);
        }

        private void txtB_bnet_msg_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13) bnet_chat_message = txtB_bnet_msg.Text;
            txtB_bnet_msg.Text = "";
        }
    }
}
#3
Hey MyndFyre[vL] ,

you pointed it out, this is exactly my problem using the B# documentation.
Gonna try to implent it the way you've explained it.

Thanks a lot!!!

Regards Dave
#4
Hi everyone,

I've already searched the forum, but could'nt find any helpful solution for me.  :-\

I'm searching a source code for a C# BNET channel bot. A easy form-based example project, which is using MBNCSUtil or B# would make me really happy.
I've already found this: http://www.jinxbot.net/wiki/index.php?title=How_to_develop_a_Battle.net_client_in_10_minutes
But since it's only command line and an old version, it doesn't help me much. Even I couldn't get a form-based application to work with this tutorial.

So, if someone got a example project or a source code of a working bot for me, you guys would make me the happiest guy in this forum!
Thanks in advance!!!

Best Regards
Dave