My Theory on keymovements
Well, I was laying down in my bed and I was thinking about how Key movements was
done on eflyff and I came up with a theory on key movement. This is what I came up with
Theory #1
Alright. here's my first Theory. I believe that there's a set of packets sent once either A,W,S,D is pressed.
Once the packets is sent from the client, the server reads it and shifts the co-ordinate of the player by 1
or something like that
Example.
You press A and maybe this is sent from the client
Code:
06 00 00 00 21 00 00 15
(6 being the length and 15 the command )
Once that's done the server reads, parses it and acts accordingly)
I'll explain my Theory in more detail when I come home from school tomorrow.
I'm tired x_x
Re: My Theory on keymovements
seriously did not a single person learn from my source?
Code:
case 0xffffff00: return Players::handleClickMoving(this,buf+8);
case 0xffffff01: return Players::handleKeyMoving(this,buf+8,len-8,0xca); //regular move
case 0xffffff02: return Players::handleKeyMoving(this,buf+8,len-8,0xcb); //jump
case 0xffffff03: return Players::handleKeyMoving(this,buf+8,len-8,0xcc); //fly??
case 0xffffff05: return Players::handleKeyMoving(this,buf+8,len-8,0xc8); //walking into an object
case 0xffffff06: return Players::handleKeyMoving(this,buf+8,len-8,0xc9); //fly
which goes to one source command
Code:
bool Players::handleKeyMoving(Player* player, unsigned char* packet, int len, int type){
player->setPos(getPos(packet),false);
player->setMotion(getInt(packet+28));
player->setStance(getInt(packet+32));
player->setAction(getInt(packet+36));
//printf("[%d] movement: x: %4.2f, y: %4.2f, z: %4.2f, motion: %x, stance: %x, action: %x\n",player->getId(),player->getPos(false).x,player->getPos(false).y,player->getPos(false).z,player->getMotion(),player->getStance(),player->getAction());
Movers::inDirectMove(player,packet,len,type);
return true;
}
Code:
void Movers::inDirectMove(Mover* mover, unsigned char* packet, int size, int type){
Mover* following = mover->getFollowing();
if(following!=NULL){
following->removeFollower(mover);
mover->setFollowing(NULL);
}
vector<Player*> players = Players::getPlayersWhoHaveThisMoverSpawned(mover);
for(unsigned i=0;i<players.size();i++){
if(players.at(i) == (Player*)mover)
continue;
MoverPacket::inDirectMove(mover,packet,size,type,players.at(i));
}
players.clear();
}
This then goes to the packet command.
Code:
void MoverPacket::inDirectMove(Mover* mover, unsigned char* packet, int size, int type, Player* player){
Packet pak = Packet();
pak.setPlayer(player);
pak.addHeader(mover,type);
pak.addBytesHex(packet,size);
pak.completePacket();
pak.packetSend();
}
Code:
void MoverPacket::directMove(Mover* mover, Player* player){
Packet pak = Packet();
pak.setPlayer(player);
pak.addHeader(mover,0xc1);
pak.addPos(mover->getPos(false));
pak.addByte(1);
pak.completePacket();
pak.packetSend();
}
as you can see there is two packets. the first I really don't know off hand.But the second one sends the packet every time you hit the key. And when you hold down the key it sends the packets continuously until you let go. After the character stops it sends one more packet for the final position.
That's about all I really know. I haven't got into the flying part, but from what I understand, its the same thing but with a player state changed from walking to flying as shown in the command parameter of the keyMovement function.
I hope that helps a little bit. I'm not saying its inronclad, but its pretty close to it.