Jump to content
Eternal Lands Official Forums
Sign in to follow this  
nicky

Some tough questions, maybe you can help?

Recommended Posts

Hi, i heard that charn was written in vb.net and was interested, as i never heard of anyone putting much time into socket programming for VB.net. I spoke with WizzKidd and he confirmed this, but understandably did not go into any details or have any places other then this forum to discuss vb.net bots for EL, so I was hoping some of you nice folks would discuss with me some of the issues I have run into with VB.net while trying to port the C code and some java ports I have found to VB.net. Here are the issues I run into:

 

1. I am not sure how to add the null byte at the end of the login string with vb.net

 

2. When parsing messages, I have gotten this far, and am unable to figure out what i am doing wrong:

 

I read the first byte (0) which is supposted to indicate RAW_TEXT, then i get the next 2 bytes which lead me to read the channel (3) then "Test Server." with a character on the beginning, which i assume is the text color.

 

Next it appears that I am sent a PING_RESPONSE (60) then the next two bytes indicate to read 5 more bytes which I do, but i can never seem to get past this ping message to read any more stream, it usually doesnt jive with any other protocol messages.

 

Here is a bit of the code i'm talking about, i'll condense it so you can see what im doing:

 

Public b_out As BinaryWriter

Public b_in As BinaryReader

Public tcpNet As TcpClient

Public tcpStream As NetworkStream

Public hostEntry As IPHostEntry

hostEntry = Dns.GetHostEntry(My.Settings.Server)

address = hostEntry.AddressList(0)

Dim endpoint As IPEndPoint = New IPEndPoint(address, My.Settings.Port)

tcpNet = New TcpClient

tcpNet.Connect(endpoint)

If tcpNet.Connected Then

tcpStream = tcpNet.GetStream

b_out = New BinaryWriter(tcpStream)

b_in = New BinaryReader(tcpStream)

' this next set of lines are supposed to occur upon connect according to the source,

' but i dont know of any way to test if it is recieved properly

b_out.Write(Protocol.server_SEND_OPENING_SCREEN)

Dim one As Short = 1

Dim onebyte() As Byte = BitConverter.GetBytes(one)

b_out.Write(onebyte, 0, 2)

b_out.Flush()

' now i should start looping to read the incoming stream

While tcpNet.Connected

If tcpStream.DataAvailable Then

Dim msg As Byte = b_in.ReadByte() ' read in the message type

Dim msglen As Short = b_in.ReadInt16 + 2 ' after reading the message length, the source adds 2 to this number?

Select Case msg

Case Protocol.RAW_TEXT ' msg = 0

Dim channel As Byte = b_in.ReadByte() ' grab the channel

Dim rt_tmp() As Byte = b_in.ReadBytes(msglen - 4) ' grab the text

Dim txtmessage As String = Encoding.ASCII.GetString(rt_tmp, 0, rt_tmp.Length) ' turn the byte array into a string

 

Case Protocol.PING_REQUEST

b_out.Write(Protocol.PING_REQUEST) ' apparently i just reply to it

b_out.Write(msglen)

Dim b() As Byte = b_in.ReadBytes(msglen - 3) ' read in the accompanying data, this always seems to change

b_out.Write(
:)
' write it back to the server

b_out.Flush()

 

Case Protocol.LOG_IN_OK ' i havent gotten this message yet in my testing

Dim b() As Byte = b_in.ReadBytes(msglen - 3)

 

Case Protocol.LOG_IN_NOT_OK ' havent gotten this one either

Dim b() As Byte = b_in.ReadBytes(msglen - 3)

End Select

End If

End While

End If

 

' Here is my login code:

 

Private Sub Login()

Dim loginstring As String = My.Settings.Username & " " & My.Settings.Password

b_out.Write(Protocol.server_LOG_IN)

Dim shrt As Short = loginstring.Length + 3

b_out.Write(shrt)

b_out.Write(loginstring)

b_out.Write(0) ' this can't be right, but i couldnt get the \0 to work at the end of the loginstring

b_out.Flush()

End Sub

 

 

I don't expect anyone to fix this for me, but ANY ideas on how bytes may be handled differently from C and Java to VB, or where I am going wrong on reading or writing to the byte stream would be greatly appreciated. I'm not a C programmer, but have spent plenty of time reading it. I worked on it for 3 days strait, 4-5 hours a day to get myself to this point, and ANY help would be appreciated.

 

I Looked at the SDL_Net library and was not able to reference it in my VB project, nor find a suitable port to the dot.net framework.

 

Also, if someone (or more then one) is interested in helping me solve these initial hurdles, I am willing to release all of the finished product code as free for all to use to help advance bot features and functionality by those of us who use VB rather then other, perhaps more difficult to learn languages.

 

Thanks in advance for any constructive comments or help.

 

my in-game name is crosis, feel free to drop me a pm or add me to your buddy list, as im kinda new and dont have a guild or many freinds in EL yet.

 

Oh, i also have a case Else statement to capture all the other messages i don't catch yet and writes those bytes ot a logging screen, logging code was removed from this post.

Share this post


Link to post
Share on other sites

You need to look at other Bot code or the Client code better. you do not send SEND_OPENING_SCREEN to the server in order to login, and ALL packets include size data as part of the protocol. Any error in the protocol will disconnect you from the server.

Share this post


Link to post
Share on other sites

You need to look at other Bot code or the Client code better. you do not send SEND_OPENING_SCREEN to the server in order to login, and ALL packets include size data as part of the protocol. Any error in the protocol will disconnect you from the server.

 

I understand. I included the SEND_OPENING_SCREEN as part of my socket connection code, as that is what the C code and other bots do right after they connect to the server.

 

The login code is a seperate sub that i included at the end of the post, i hit a cmd button to actually do the login.

 

Thanks for taking the time to have a look, i really appreciate it!

Share this post


Link to post
Share on other sites

Ok, after completely re-writing my app to display the various bytes being sent to me, and intelligently parsing them so i could visualize what i was working with, i was able to get my reading/writing to sockets code working. i was able to log in and have been coding to handle the huge influx of server messages that come in one you log in.

 

I thought i was stuck, but it just took an additional day.

 

Perhaps once i have a good base for a working bot, out of the box, then i'll create a project for it on one of the development sites to share with everyone else.

 

Thanks to the person who posted back to me, i appreciate the help.

Share this post


Link to post
Share on other sites

Just wanted to let you folks know that i figured it out last night and have already coded the parsing of many messages.

 

If anyone is interested in using vb to write a bot, let me know and I'll share what i've learned so far. I dont really have enough done to justify posting it online yet, but i will when i have a working bot.

Share this post


Link to post
Share on other sites

First thing i would do is recomend that you download Ethereal

It is a network packet analyser and allows you to capture all the packets.

First you should capture an output of you connecting to the server with the official client as a reference of what the data should. Next capture your bot connecting to the server, compare the data they sends and try and hack your code to get it to outputs to match.

 

I run a bot written in java so the syntaxes are resonably simular to what you have and i have had simular problems to you.

 

One problem that i have had is that java was sending all data imediately, it would send a packet specifying the type, then a packet with the data length then a packet with the data. the server doesn't like this as this should be sent as a single packet. Java has a "BufferedOutputStream" which is a wrapper around the imput stream that puts the data into a buffer, when all the data has been put in you call flush which will send the full buffer.

 

You also need a default case for packets that it does not understand where it should just read and ignore those packets (or print them out for debugging :D ). it would get confused if it finds something that it doesn't know.

 

If you need any help ask me, though i have not used .net but .net is soo close to java as they copied lots of the design ideas that my code is really simular to your code. so you could send it to me if you get stuck.

Share this post


Link to post
Share on other sites

Great dns_server, i really appreciate it. I have one other person interested in looking at what i've got so far. I think i may be able to buffer the binarywriter stream and call it's flush() when the command has been assembled. I did use Ethereal a little bit, but i tend to make more progress by trial and error trying to copy th source.

 

My largest hurdle so far is figuring out what SDL_SwapLE16 does, I google it and get nothing but code samples, no explanation of the function's use. Sometimes i feel i may not be storing the proper number in my variables because i'm not reading the big ends and little ends in the proper order.

 

I'm packing up a zip with the .net source. i'll include a readme on running it.

 

if you could PM me an email to send it to i'll send it out today.

THanks

Share this post


Link to post
Share on other sites

Great dns_server, i really appreciate it. I have one other person interested in looking at what i've got so far. I think i may be able to buffer the binarywriter stream and call it's flush() when the command has been assembled. I did use Ethereal a little bit, but i tend to make more progress by trial and error trying to copy th source.

 

My largest hurdle so far is figuring out what SDL_SwapLE16 does, I google it and get nothing but code samples, no explanation of the function's use. Sometimes i feel i may not be storing the proper number in my variables because i'm not reading the big ends and little ends in the proper order.

 

I'm packing up a zip with the .net source. i'll include a readme on running it.

 

if you could PM me an email to send it to i'll send it out today.

THanks

That routine swap the bytes IF you aren't on an Intel type machine, since you are on an Wintel system, it just grabs the bytes in the normal Intel order.

Share this post


Link to post
Share on other sites

Just wanted to let you folks know that i figured it out last night and have already coded the parsing of many messages.

 

If anyone is interested in using vb to write a bot, let me know and I'll share what i've learned so far. I dont really have enough done to justify posting it online yet, but i will when i have a working bot.

 

 

I was Interested in building one in Mono with c#, So i'm really interested in that one.

 

Pm me or mail me at

 

francis.belanger[at]gmail.com

 

thanks a lot :hehe:

Share this post


Link to post
Share on other sites

Just wanted to let you folks know that i figured it out last night and have already coded the parsing of many messages.

 

If anyone is interested in using vb to write a bot, let me know and I'll share what i've learned so far. I dont really have enough done to justify posting it online yet, but i will when i have a working bot.

 

 

I was Interested in building one in Mono with c#, So i'm really interested in that one.

 

Pm me or mail me at

 

francis.belanger[at]gmail.com

 

thanks a lot :hehe:

 

I've got the bot working well. Keep in mind the interface and routines revolve around discovering how the byte stream works and how to parse and respond. The ultimite goal is to provide a wrapper class and type structures so that one could just create a bot class, handle and respond to events and send commands without needing to know the underlying workings. I've submitted an application to sourceforge to upload the code, and the code works in these areas currently:

 

Connecting

Logging in and maintaining heartbeat in an acceptable manner.

Reading and parsing messages, even ones that are not currently handled by a case statement

I have quite a few of the messages handled by case statements, parsed and loaded the message data into vars to be passed to routines or events that are raised.

Created structures to hold known actors and details gathered about them

 

 

Coming next:

Basic work around handling PM's is done, but when i respond i get logged off, so i need to touch up the bytes im sending.

Database or XML based rules for responding to PM's, creating rules that contain routine names to call when a rule is met

Event logging to DB or xml

 

One of the goals i have is to make this project work with MONO if possible, so anyone running under mono, please let me know of bugs (suggest fixes too?). This solution is written under dot.net framework 2.0 and contains some of the new interface features like dockable toolbarstrips. If this will not work under mono, perhaps we can come to a solution that works for everyone.

 

I'll post here when the source is available for download.

 

Thanks

Share this post


Link to post
Share on other sites

Thanks a lot I'll follow your progress. As per .net framework 2.0, i'm not sure it's supported yet in mono. At least no released a version supporting it entirely.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×