i read an article on vb.net today and it motivated me to make a bot, so to get other people started heres a packetbuffer class i wrote
'PacketBuffer class by Noodlez
Public Class PacketBuffer
Private buffer As String
Public Sub InsertDWORD(ByVal DWord As Int32) 'VB.Net provides types for DWord and Word
buffer = buffer & DWord.ToString
End Sub
Public Sub InsertWORD(ByVal Word As Int16)
buffer = buffer & Word.ToString
End Sub
Public Sub InsertBYTE(ByVal b As Byte)
buffer = buffer & b.ToString
End Sub
Public Sub InsertString(ByVal data As String, Optional ByVal NT As Boolean = True)
'NT = NullTerminated, if you don't want the string to be nullterminated just set
' that to false
If NT = False Then
buffer.Insert(Len(buffer), data)
Else
buffer.Insert(Len(buffer), data & vbNullChar)
End If
End Sub
Public Sub Clear()
buffer = ""
End Sub
Public Function SendPacket(ByVal Socket As LSock, ByVal PacketID As Byte) As Boolean
'feel free to replace LSock with whatever winsock class you use
'(and modify the function if necessary)
Dim length As Int16
length = Len(buffer) + 4
If Socket.State = LSock.Status.Connected Then
Socket.SendData(ChrW(255) & length.ToString & buffer)
Return True
End If
Clear()
Return False
End Function
End Class
enjoy
this is untested code, if you find error in my code, or make any optimizations please let me know
If you're basing this off of DarkMinion's PacketBuffer, then I recommend redesigning it (i didn't check it out), because his has a few flaws/problems you will run into when sending packets & et cetera
it does? i modified his only a little, and its worked fine for me for about 2 years now...
If anyone has actually tried this, it doesn't work. The 'ToString' method converts the object (Int32, Int16, both of which are an Integer and Short in VB.NET) to the literal string. For example, if 'myInt' was declared as Integer with a value of 12, then myInt.ToString() would return "12" as a string -- the same thing CStr(12) would do in VB6. Another thing, why don't you take advantage of VB.NET's overloading ability? Also, the class should be as abstract as possible, and not reference other objects such as LSock (a Winsock-like implementation in VB.NET). Seriously, this is horrible code and you consider testing it before you release anything. This is what causes confusion and is a fuels for much of the bad code that is already on this board.
Edit: grammar :\
didn't read anything about overloading, and thanks for pointing out what ToString does.
n00blar, this was straight off my head. mesiah, he was referring to the C++ packetbuffer (i think?)
kamikazaie, do you have a packetbuffer class i can see?
I generally hate giving out code for personal reasons. Though I will give you a hint as to what I did to accomplish this. Try taking a look at System.BitConverter.GetBytes(). If anyone knows an easier way, feel free to post away. My knowledge of the .NET Namespaces is not that great, nor do I have a hardcopy reference of them. I mostly just scour the internet for references.
i use copymemory w/ vb6. unless i'm horribly mistaken, you could use that in .net too.
Public Function MakeDWord(DWord As Int32)
CopyMemory MakeDWord, ByVal DWord, 4
End Function
or something like that. if you know any c, it helps to note that byref is implied, and is the same as the c & operator. so, you generally (always?) want to do "CopyMemory <destination>, ByVal <source>, <len(source)>", so that it takes the value of <source>, and copys <len(source)> bytes to a place in memory starting at <ByVal <source>>
oh by the way, if you write a string->word/dword function, make sure you check that its at least 2/4 bytes before calling copymemory...and save before you test it ;)
Does .NET have something equivalent to ByteBuffer?
Can some one explain why we have to convert longs and bytes to strings in order to send it to bnet?
QuoteCan some one explain why we have to convert longs and bytes to strings in order to send it to bnet?
The socket only accepts strings for input to be sent.
Instead of thinking it as a string input, think of it as a "raw input", or a binary input. Then, instead of thinking that you're converting the longs to a string, think that you're just making it so that you're able to send the long.
If you were using a good programming environment (example: not VB), you would just pass the address of data to be sent and the length of the data to be sent, and then the socket would then read and write the data as is (so, a long would be sent "as a long", instead of "as a string", in VB terms), to the network.
Just as long as the end result is the same, it really doesn't matter how you get the job done.
VB sucks and isn't a programming language.
For christ's sake, I'd rather write in JavaScript!
still gets the job done, i can do anything anybody else can do, might require a little more time and work, but it can be done.
with only 2 megabytes wasted space on your hard drive ;)
QuoteVB sucks and isn't a programming language.
For christ's sake, I'd rather write in JavaScript!
Hehe, you're a sucky fisherman. Everyone knows your old stinky bait.
What's your evaluation of PHP. I just did my own evaluation but yours should be interesting.
I personally think PHP is a good scripting language... Not much of an evaluation I guess.
Grok, that was one of my joke posts. But it gets the point across.
PHP owns. Why!? I'll compare to ASP, since you're a Microsoftie ;) I'll assume ASP is using vbscript unless otherwise noted.
1) It's one language you have to learn. Although vbscript is defacto for ASP, some people use other languages for it, thus forcing you to learn a new language or adapt to a different one when joining an ASP project.
2) It's syntactic sugar makes it great for database code. You just call mysql_fetch_array() and you get a key-value pairing of the database.
3) It's freakin easy ;) A lot of really stupid people on this forum have picked it up and write really good code in it.
4) There's way more support and way more hosts run it (at least our kind of hosts, I don't know about businesses)
5. Nice syntactic sugar with the $var being able to be inserted in strings
6) Its familiar to me, coming from a C/Java background, and it's familiar to perl/tcl programmers too.
7) Its syntax is easier to read from popular opinion, compared to vbs. Please refer to the BASIC vs C syntax wars.
8) Runs on all platforms, with full support on their website
9) Easily accessible documentation, goto www.php.net and type in the function name
10) Includes OOP, but discourages its use. Who would use OOP in a website!? Seems crazy to me, but I could be wrong.
11) No ActiveX! HURRAY!
Downsides of PHP:
1) Non-portable database code, sucks for porting. Example, I'm thinking about switching all of my sites I've designed to pgsql because it's way easier to use, but I have to recompile PHP and rewrite some code.
2) OOP coding blows.
3) A bit cryptic to read at first, but after getting used to it, C/perl programmers can read it very easily very quickly.
4) register_globals is sometimes on and sometimes off, and in procedures I have to use global [var].
As far as performance goes, I've seen several benchmarks, and realized that they're so close it doesn't matter too much. It's usually limited by the DBMS.
Vs. other server-side scripting:
JSP: What a really horrible idea. Why would anyone use JSP? Java isn't suited to writing web sites. JDBC sucks, it's strongly typed and forces you to catch exceptions and use OOP, and you have to COMPILE! your web pages. Not to mention there's a million versions and they're all a bitch to install. No thanks, I'd rather use ASP.
Java Servlets: Worse than JSP, because you can't embed HTML as easily as JSP. Basically, it's JSP but worse.
Perl: Too many single characters that do weird stuff. It's pretty standard though, so I don't know.
Python: Pretty ownage language, but I like the ones where you can easily embed HTML.
On the VB sucks topic, I'd like to note that VB only has the array data structure, and a bizzare Collection object.
Quote9) Easily accessible documentation, goto www.php.net and type in the function name
www.php.net/<function_name> is total ownage :)
Quotewww.php.net/<function_name> is total ownage :)
Whoa, didn't know that was possible! ;)
QuoteWhoa, didn't know that was possible! ;)
sure; map your 404s to a search script server-side :)