• 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!

Developer's question about client>server communication

Wiesiek92

New Member
Joined
Jul 15, 2010
Messages
5
Reaction score
0
Hi guys,
I'm a webdeveloper specialized in php / javascript / html and css (i know some as3 too). Last times i was thinking about creating a tibia-alike flash game but not to "dream about stars" i'll go more like step by step. At the start i'd like to create something basic like 100x100 field without any elements on it where u would login (not register) with a name (just checking if the same name is not online) and kind of basic spell to attack (and hp ofc) nothing else for start. My question is how does client communicate with server and vice versa (yes via udp packets i know). To be exact my questions are:
1. How does server notify client what happend (get dmg'd/healed/some1 did enter the screen/move)?
2. How does client request updating the screen or its server sending packets to client when something happens (does server sends packet to client on any nearby event (for example 15 sqm range) or does client request "update" each ... ms (or right after last answer) and then server responds with (for example) what happen or sends empty answer(nothing happend)?
3. As for now its what mostly burns my brain i'll ask if you got any ready solutions (kind of flash YATC i havent heard about) or mo/mmo flash/js game framework?
4. Any tips?

I'm not another kid having a wish of making own game, played with few game frameworks like oogre or xna, did some basic games in flash or jquery and im kind of "missing old good game" and atleast im a programmist so I could have a point of starting a project like this. Ofc if I started i'd post here everything constantly :).

Regards/Wiesiek.

PS. Move to another board if i picked wrong one.
 
In order to understand how the server exactly works, you have to have a background on how networking works (asynchrnous networking).
OpenTibia uses boost asio which is kind of hard to use and may be painful at the beginning.

Here's a simple explanation tree of how this works:
Server ----> Waiting for connections ---> Got a connection? Accepted. ---> Read RSA and so on. Can't verify? Close connection. ---> After X seconds the server sends PING to verify that the client is still alive, the client must respond with PONG to verify that it's still alive or the server closes the connection. -----> Wait for more connections asynchrnounsly, this means other connections are still alive and they're still communicating togther.

Now to answer your questions:
To be exact my questions are:
1. How does server notify client what happend (get dmg'd/healed/some1 did enter the screen/move)?
The server does send information about the player to the client on every change happens to the player:
[cpp]void ProtocolGame::AddPlayerStats(NetworkMessage_ptr msg)
{
msg->AddByte(0xA0);

msg->AddU16(player->getHealth());
msg->AddU16(player->getPlayerInfo(PLAYERINFO_MAXHEALTH));

msg->AddU32(uint32_t(player->getFreeCapacity() * 100));
msg->AddU32(uint32_t(player->getCapacity() * 100));

msg->AddU64(player->getExperience());

msg->AddU16(player->getPlayerInfo(PLAYERINFO_LEVEL));
msg->AddByte(player->getPlayerInfo(PLAYERINFO_LEVELPERCENT));

msg->AddU16(player->getMana());
msg->AddU16(player->getPlayerInfo(PLAYERINFO_MAXMANA));

msg->AddByte(player->getMagicLevel());
msg->AddByte(player->getBaseMagicLevel());
msg->AddByte(player->getPlayerInfo(PLAYERINFO_MAGICLEVELPERCENT));

msg->AddByte(player->getPlayerInfo(PLAYERINFO_SOUL));

msg->AddU16(0x9D8); // stamina minutes

msg->AddU16(player->getBaseSpeed());

Condition* condition = player->getCondition(CONDITION_REGENERATION);
msg->AddU16(condition ? condition->getTicks() / 1000 : 0x00);

msg->AddU16(player->getOfflineTrainingTime() / 60 / 1000);
}[/cpp]

2. How does client request updating the screen or its server sending packets to client when something happens (does server sends packet to client on any nearby event (for example 15 sqm range) or does client request "update" each ... ms (or right after last answer) and then server responds with (for example) what happen or sends empty answer(nothing happend)?
The Client sends information when its local player does something, not when something happens near the player, otherwise it would be an infinite loop (if you know what I mean).
The server handles all the players, that is, when a player moves it sends packets to all other surronding players (clients) telling them what has happened; the client responds by rerendering the screen or whatsoever.

3. As for now its what mostly burns my brain i'll ask if you got any ready solutions (kind of flash YATC i havent heard about) or mo/mmo flash/js game framework?
4. Any tips?
Download OTclient sources or YATC and TFS and check out protocolgame and networkmessage.

Oh S&*t 18th april.
 
Last edited:
Back
Top