Page 1 of 1

01 - kali's beginning programming guide

Posted: 10 Jul 2017, 12:04
by kali
So with all the hullabaloo about the new Ragnarok servers by Gravity, I thought this would be a great time to start inspiring people to start learning *actual* programming, instead of just being a script kiddie.

Programming is the future, and if I can even get some of your interest because it happens to be related to a game you play, then that's just bonus points.

I'm thinking of doing this as a series of sorts, and I'll try to cover stuff that will be both generally useful in programming, as well as stuff that's specific to openkore and of course, ragnarok. If anyone wants to help out by suggesting topics they want covered (serious suggestions only please. you all know i have a short fuse) please do so. And if anyone wants to answer questions feel free to do so as well.

So first lesson would be the network packets. If you've played around with Wireshark or WPE Pro, you've probably seen something like this:

Code: Select all

00000000  76 0a 18 00 00 00 75 73 65 72 6e 61 6d 65 00 00  |v.....username..|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 b9 2a  |...............*|
00000030  20 24 a9 31 59 db f6 77 fa b7 35 66 a3 a2 06 81  | $.1Y..w..5f....|
00000040  e9 a5 16 63 9f dc 6d 7e 73 d7 55 d8 f8 00 0f 00  |...c..m~s.U.....|
In Openkore parlance, we'd call this packet 0x0A76

But why do we call it 0x0A76 ? Why not call it 76 0a (the way it shows up in the network sniffer)? Why do we write it in reverse?

This is called Endianeness and most microporcessor code (stuff used by programming languages like C) come in the Little Endian format. See https://en.wikipedia.org/wiki/Endianness for a good explanation.

So there, we have packet 0x0A76 which is two bytes, packed in VAX byte order (aka Little Endian). https://apidock.com/ruby/Array/pack is a good reference for the various packing "formats" you can use. I know that OpenKore is in Perl, but Ruby gets a lot of inspiration from Perl so it has most of the powerful stuff that Perl has.

Another advantage of Ruby is that it's a bit easier to learn than Perl, so I'll be using Ruby for examples. Programming skills are transferable no matter the language, so don't get worried that you're wasting your time. You'll find that concepts are generally the same everywhere.

If you're feeling up to it, read up on http://openkore.com/index.php/Network_subsystem then come back here.

Okay, from that wiki article you'll know that the ragnarok network protocol (at least the older ones) came in "packets."

What's a packet?

Ask a Brazillian and they'll tell you the correct answer. It's basically a package of bytes. Bytes are just characters (like this wall of text). So they're like sentences in a language that only computers understand.

We have what we call internally in OpenKore as a "packet switch" although Message ID is a more appropriate name for it. The Message ID identifies a packet so the receiver knows what the package should contain. It's like the title of a book, or a label in a container.

There's a big problem though. TCP is a streaming protocol, meaning you never really disconnect from your partner. So if there are packets heading your way, how do you know when a packet ends and when a packet starts?

That's where `recvpackets.txt` comes in. This file is a table of packet lengths; it basically acts as a measuring type to find out where to cut the stream so we know we have a complete packet. If the lengths are wrong, then we won't be able to cut the stream in the correct place, and kore will get confused.

Next time we'll talk about AES-128, Rijndael, symmetric encryption, and why you shouldn't play ragnarok using free wifi hotspots.

Re: 01 - kali's beginning programming guide

Posted: 12 Jul 2017, 18:50
by RPA_Guy
Thanks for the starters. I'll be waiting for the next post.

Re: 01 - kali's beginning programming guide

Posted: 17 Jul 2017, 02:32
by jojonarte
Looks good bro. Learned a lot in one post, I'm anticipating the next topic.

Re: 01 - kali's beginning programming guide

Posted: 19 Jul 2017, 01:24
by raskal007
Thank you for this Kali. I'm in IT and in production support/product development for a multinational firm but as you know you can't really pick which technology/programming language you get to specialize in if you are someone like me. This guide is awesome for those who want to learn something new and interesting as well as related to the game we love. Can't wait for the next post. :D

Re: 01 - kali's beginning programming guide

Posted: 26 Jul 2017, 11:13
by Myself379
Thank you for this Kali, it really open "insights" instead of the tutorials, and we're fiddle with our heads to understand what it really means (like teach English to a Japanese), where the grammar and sentences is different between those two.

Re: 01 - kali's beginning programming guide

Posted: 10 Jan 2018, 10:46
by kenjan16
can you continue this guide,.. im interested. im a programmer but not good with packets. so this is a good starting guide

Re: 01 - kali's beginning programming guide

Posted: 03 Jul 2018, 04:48
by taskeox
hi kali, it's been a long while since you've posted this.
I was wondering if you'd have the time to write more about it?

Thank you for the first part, it was inspirational and educational.