• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Javascript tibia client under development

Nazgulzeh

Member
Joined
Feb 19, 2015
Messages
5
Reaction score
10
Intro

Currently I'm working on a client that will run on the browser using javascript. I have done several tests and I think it is totally viable, I've made a little game that emulate the way we play tibia and it worked out pretty well. So if there is someone interested in taking part on it please contact me, it will be open source but by now I have just a bunch of functions so I will keep it private until it a bit more organized.

-----
Now, I'm facing some issues with XTEA and I will explain on the bottom of this topic.
-----

Technologies

Ok I will like I have to make an overview of what I'm aiming to achieve and how, so lets begin. The little game I'm made was like a very simple version of bomberman, you can see it here: https://github.com/thiagomorato/BomberPY

The version on github uses JQuery, CSS2 and AJAX calls to communicate with a python server. The last week I took some time to work on it and I'm just moved to use pure Javascript, CSS3, and websockets. It worked out pretty well, I well that I think I can do a whole tibia client with it. It is not on github the new version as it needs some code cleaning and polishing.

All the animation will be handled by the CSS3 now, the keyframes, transactions and animations made it clear to me that I should drop the JQuery off. I could achieve the same results without some javascript craziness I was using before.

But now you might be wondering how are he going to connect the javascript with the sockets of a tibia server? Well it turns out that there is some "bridges" that takes form a websocket and sends to a socket and vice versa. The one I'm using is https://github.com/kanaka/websockify and so far I have nothing to complain.

This think might look bad at a first glance to need a bridge between the client and the server. Well I think ask the users to setup it would be very bad but we can set it up on the server or even better between the user and the server in a internet route that improves the latency as proxies do. Also it would be possible to program the server itself to deal with websockets, however I have no knowledge to intent that.

So, these are the technologies I'm willing to use, any suggestion will be welcome.

Protocol

For simplicity sake I'm using the protocol 8.6 and also there is plenty of ots running on it. Also I'm using as base this C++ client here: https://github.com/edubart/otclient

Believe it or not the RSA encryption is already done and my tests shows I'm doing it right. What I did to prove it was doing fine was:

Generate a new RSA key pair;
Extract the modulus and exponent and convert to decimal;
Convert it to decimal to and added to the C++ client.
Open WireShark and listen to localhost
Open the C++ client and set password and account to "aaaaaa"point it to a local socket written in python
Get the data from WireShark and remove all the stuff that wasn't encrypted on the begging of the message
Send it to another script in python and decrypts the the message,
Then I could see the 41414141 of the former "aaaaa" from account and password.

Ok so it proves that the python script is decrypting it right.

When I sent the data from my javascript encrypted with the public key and exponent of the key pair it get decrypted perfectly. So If the it decrypted both the C++ and JavaScript I assume the RSA encryption is just fine.

The issue

Now it comes to where I'm not able advance. If I send the my login packet to the server with the same XTEA key it always returns me the same response, and if I use a random XTEA key it always respond me with different data. Because of that I assume the server is able to get the XTEA key and encrypt the message. The issue is that I just can't decrypt no matter what I try. The "library" I'm using to do it is this one: http://www.movable-type.co.uk/scripts/tea.html . But I've modified it to instead of input and output strings it inputs an array of 8 bit ints and outputs the same.

Well this topic have got bigger than I thought and it is getting late, tomorrow I will put here some of my code so you guys might help me on that. How ever if someone have some experience with XTEA and have some guide lines please share with us.

Thanks!
 
Quick update, what was messing with the XTEA was in fact the RSA padding. I was considering the max size of the message to be encrypted by the RSA as 117 but infact it was 128. I feel a bit dumb about it but also happy that now I'm able to talk with the server. Expect some other updates and maybe some code during this weekend : P.
 
Looking forward to seeing this in action. What rendering mechanism are you planning to use?
 
Hey, I intend to rely on the browser DOM, using images and CSS animations. Something similar to what I've achieved in my little game up ahead.

Also I have some updates:

Now I'm able to get the MOTD and character list, what I get:

MOTD: Welcome to the MegaTibia!

Char List Item:
[Object]0: Object
name: "Asdf Asdfasdf"
world: "MegaTibia"
worldIp: Array[4]
0: 167
1: 114
2: 100
3: 16​
length: 4
worldPort: 7172​

And also connect to the game server and get:

The char postion: Object {x: 32957, y: 32076, z: 7}

The map information, itens, chars and npcs

Char: Object
direction: 2
emblem: 0
health: 100
id: 269099837
light: Object
color: 0
intencity: 0​
name: "Asdf Asdfasdf"
outfit: Object
addons: 0
body: 114
feet: 88
head: 88
legs: 114
lookType: 134​
passable: true
removeId: 0
shield: 0
skull: 0
speed: 234
NPC: Object
direction: 3
emblem: 0
health: 100
id: -2147482152
light: Object
color: 0
intencity: 0​
name: "Training Assistant"
outfit: Object
addons: 0
body: 23
feet: 116
head: 95
legs: 22
lookType: 160​
passable: false
removeId: 0
shield: 0
skull: 0
speed: 100​

Also I can get the itens ID. This part is not quite fine yet, some where it gets out of sync and messes everything up. I'm moving to another country by now so it might take some time until I can work on it. My plan is to have a basic protocol functionality and then start working on the rendering part. As soon I have some simple example working I will open the code.
 
Plan putting it up on github or keeping to yourself? Id be interested to see the workings of the protocol.
 
I can admit this sounds oddly interesting :)
I just got 1 tip, make it smooth :) I mean so it isn't too heavy to use if it would be playable in the future :)
 
Just one small question, why not try to do it like OTC? Supporting alot more versions etc.
Atleast try to keep the "major" versions, a couple of the 7.x versions, 8.54, 8.6 aswell as the latest.
Would really like to see the code :p
 
"Nazgulzeh was last seen: Feb 26, 2015", too bad..
 
This past year was quite heavy and I couldn't dedicate too much time to this project, none in fact. Anyway this weekend I just went back to it and see if I could make it work again. And I could, I got excited to see that I had managed to grab all map data, I didn't remember I got this far. So I got that map and tried to do some rendering using the .dat file and the .spr file. This is the result:
1KNhdFI.jpg


Again the code is a mess I have to organize it before uploading it to my github profile.
 
Back
Top