01 - kali's beginning programming guide

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
kali
OpenKore Monk
OpenKore Monk
Posts: 457
Joined: 04 Apr 2008, 10:10

01 - kali's beginning programming guide

#1 Post 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.
Got your topic trashed by a mod?

Trashing topics is one click, and moving a topic to its proper forum is a lot harder. You expend the least effort in deciding where to post, mods expend the least effort by trashing.

Have a nice day.

RPA_Guy
Noob
Noob
Posts: 1
Joined: 08 Jul 2017, 21:31
Noob?: Yes

Re: 01 - kali's beginning programming guide

#2 Post by RPA_Guy »

Thanks for the starters. I'll be waiting for the next post.

jojonarte
Noob
Noob
Posts: 1
Joined: 09 Jul 2017, 19:19
Noob?: Yes

Re: 01 - kali's beginning programming guide

#3 Post by jojonarte »

Looks good bro. Learned a lot in one post, I'm anticipating the next topic.

raskal007
Noob
Noob
Posts: 1
Joined: 03 Jul 2017, 08:32
Noob?: Yes

Re: 01 - kali's beginning programming guide

#4 Post 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

Myself379
Human
Human
Posts: 24
Joined: 05 Oct 2010, 09:46
Noob?: No

Re: 01 - kali's beginning programming guide

#5 Post 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.

kenjan16
Noob
Noob
Posts: 1
Joined: 12 Jan 2015, 09:09
Noob?: Yes

Re: 01 - kali's beginning programming guide

#6 Post by kenjan16 »

can you continue this guide,.. im interested. im a programmer but not good with packets. so this is a good starting guide

taskeox
Human
Human
Posts: 20
Joined: 09 Jun 2012, 04:45
Noob?: No

Re: 01 - kali's beginning programming guide

#7 Post 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.

Post Reply