Implemented server-side HandleSetCharacter*(); untested
This commit is contained in:
@@ -163,14 +163,114 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
|
||||
//character movement
|
||||
//-------------------------
|
||||
|
||||
//TODO: ? Could replace this verbosity with a "verify" method, taking a client, account and character ptr as arguments
|
||||
|
||||
void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket) {
|
||||
//TODO
|
||||
//get the specified objects
|
||||
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
|
||||
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex);
|
||||
|
||||
if (!accountData || !characterData) {
|
||||
throw(std::runtime_error("Failed to set character room, missing data"));
|
||||
}
|
||||
|
||||
//get this account's client
|
||||
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex());
|
||||
|
||||
//check for fraud
|
||||
if (clientData->GetAddress() != argPacket->srcAddress) {
|
||||
std::cerr << "Falsified set character origin targeting uid(" << argPacket->characterIndex << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//check if allowed
|
||||
if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) {
|
||||
//TODO: send to the client?
|
||||
std::cerr << "Failed to set character room due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//set the character's room, zero it's origin, zero it's motion
|
||||
//TODO: Set the origin here
|
||||
characterData->SetRoom(argPacket->roomIndex);
|
||||
characterData->SetOrigin({0, 0});
|
||||
characterData->SetMotion({0, 0});
|
||||
|
||||
//update the clients
|
||||
CharacterPacket newPacket;
|
||||
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
||||
newPacket.type = SerialPacketType::CHARACTER_SET_ROOM;
|
||||
PumpPacket(&newPacket);
|
||||
}
|
||||
|
||||
void ServerApplication::HandleCharacterSetOrigin(CharacterPacket* const argPacket) {
|
||||
//TODO
|
||||
//get the specified objects
|
||||
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
|
||||
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex);
|
||||
|
||||
if (!accountData || !characterData) {
|
||||
throw(std::runtime_error("Failed to set character origin, missing data"));
|
||||
}
|
||||
|
||||
//get this account's client
|
||||
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex());
|
||||
|
||||
//check for fraud
|
||||
if (clientData->GetAddress() != argPacket->srcAddress) {
|
||||
std::cerr << "Falsified set character origin targeting uid(" << argPacket->characterIndex << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//check if allowed
|
||||
if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) {
|
||||
//TODO: send to the client?
|
||||
std::cerr << "Failed to set character origin due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//set the character's origin, zero it's motion
|
||||
characterData->SetOrigin(argPacket->origin);
|
||||
characterData->SetMotion({0, 0});
|
||||
|
||||
//update the clients
|
||||
CharacterPacket newPacket;
|
||||
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
||||
newPacket.type = SerialPacketType::CHARACTER_SET_ORIGIN;
|
||||
PumpPacket(&newPacket);
|
||||
}
|
||||
|
||||
void ServerApplication::HandleCharacterSetMotion(CharacterPacket* const argPacket) {
|
||||
//TODO
|
||||
//get the specified objects
|
||||
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
|
||||
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex);
|
||||
|
||||
if (!accountData || !characterData) {
|
||||
throw(std::runtime_error("Failed to set character motion, missing data"));
|
||||
}
|
||||
|
||||
//get this account's client
|
||||
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex());
|
||||
|
||||
//check for fraud
|
||||
if (clientData->GetAddress() != argPacket->srcAddress) {
|
||||
std::cerr << "Falsified set character motion targeting uid(" << argPacket->characterIndex << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//check if allowed
|
||||
if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) {
|
||||
//TODO: send to the client?
|
||||
std::cerr << "Failed to set character motion due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//set the character's origin and motion
|
||||
characterData->SetOrigin(argPacket->origin);
|
||||
characterData->SetMotion(argPacket->motion);
|
||||
|
||||
//update the clients
|
||||
CharacterPacket newPacket;
|
||||
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
||||
newPacket.type = SerialPacketType::CHARACTER_SET_MOTION;
|
||||
PumpPacket(&newPacket);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user