Server state query works, client doesn't use the result yet
Both sides of this message uses QUERY_CHARACTER_EXISTS because I'm just trying to push forward, without worrying about mistakes I might be making. I just want to merge this back into the main branch so I can say that I've actually done something over the last few months.
This commit is contained in:
@@ -86,6 +86,11 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
|
||||
newPacket.accountIndex = accountIndex;
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
|
||||
//query the world state
|
||||
memset(&newPacket, 0, MAX_PACKET_SIZE);
|
||||
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
|
||||
//debug
|
||||
//
|
||||
}
|
||||
@@ -250,6 +255,9 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
||||
case SerialPacketType::CHARACTER_DELETE:
|
||||
HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
|
||||
break;
|
||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||
HandleCharacterQueryExists(static_cast<CharacterPacket*>(argPacket));
|
||||
break;
|
||||
|
||||
//rejection messages
|
||||
case SerialPacketType::REGION_REJECTION:
|
||||
@@ -394,4 +402,12 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
|
||||
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||
//TODO: HandleCharacterDelete()
|
||||
std::cout << "HandleCharacterDelete" << std::endl;
|
||||
}
|
||||
|
||||
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
|
||||
//TODO: HandleCharacterQueryExists()
|
||||
std::cout << "HandleCharacterQueryExists" << std::endl;
|
||||
//NOTE: preexisting characters will result in query responses
|
||||
//NOTE: new characters will result in create messages
|
||||
//NOTE: this client's character will exist in both
|
||||
}
|
||||
@@ -94,6 +94,7 @@ protected:
|
||||
//character management
|
||||
void HandleCharacterCreate(CharacterPacket* const);
|
||||
void HandleCharacterDelete(CharacterPacket* const);
|
||||
void HandleCharacterQueryExists(CharacterPacket* const);
|
||||
|
||||
//indexes
|
||||
int& clientIndex;
|
||||
|
||||
@@ -93,6 +93,8 @@ private:
|
||||
|
||||
//data management
|
||||
void HandleRegionRequest(RegionPacket* const);
|
||||
void HandleCharacterExists(CharacterPacket* const);
|
||||
|
||||
void SaveServerState();
|
||||
|
||||
//character management
|
||||
|
||||
@@ -71,6 +71,16 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||
}
|
||||
|
||||
void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) {
|
||||
//respond with all character data
|
||||
CharacterPacket newPacket;
|
||||
for (auto& it : *characterMgr.GetContainer()) {
|
||||
CopyCharacterToPacket(&newPacket, it.first);
|
||||
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Character Management
|
||||
//-------------------------
|
||||
|
||||
@@ -279,6 +279,9 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
|
||||
case SerialPacketType::REGION_REQUEST:
|
||||
HandleRegionRequest(static_cast<RegionPacket*>(argPacket));
|
||||
break;
|
||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||
HandleCharacterExists(static_cast<CharacterPacket*>(argPacket));
|
||||
break;
|
||||
|
||||
//character management
|
||||
case SerialPacketType::CHARACTER_CREATE:
|
||||
|
||||
@@ -101,73 +101,4 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
||||
|
||||
PumpPacket(argPacket);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//mismanagement
|
||||
//-------------------------
|
||||
|
||||
//SET: delete
|
||||
void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) {
|
||||
//TODO: compensate for large distances
|
||||
//NOTE: I quite dislike this function
|
||||
|
||||
//send all of the server's data to this client
|
||||
ClientData* client = clientMgr.Get(argPacket->clientIndex);
|
||||
|
||||
//send all characters
|
||||
CharacterPacket newPacket;
|
||||
newPacket.type = SerialPacketType::CHARACTER_SET_ORIGIN;
|
||||
|
||||
for (auto& it : *characterMgr.GetContainer()) {
|
||||
CopyCharacterToPacket(&newPacket, it.first);
|
||||
network.SendTo(client->GetAddress(), static_cast<SerialPacket*>(&newPacket));
|
||||
}
|
||||
|
||||
//TODO: more in HandleSynchronize()
|
||||
}
|
||||
|
||||
//SET: utility/manager
|
||||
void ServerApplication::CleanupLostConnection(int clientIndex) {
|
||||
//NOTE: This assumes each player has only one account and character at a time
|
||||
//TODO: handle multiple characters (bots, etc.)
|
||||
|
||||
//send a disconnection message just in case
|
||||
ClientPacket newPacket;
|
||||
newPacket.type = SerialPacketType::DISCONNECT_FORCED;
|
||||
network.SendTo(clientMgr.Get(clientIndex)->GetAddress(), &newPacket);
|
||||
|
||||
//find the account
|
||||
int accountIndex = -1;
|
||||
for (auto& it : *accountMgr.GetContainer()) {
|
||||
if (it.second.GetClientIndex() == clientIndex) {
|
||||
accountIndex = it.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//find the character
|
||||
int characterIndex = -1;
|
||||
for (auto& it : *characterMgr.GetContainer()) {
|
||||
if (it.second.GetOwner() == accountIndex) {
|
||||
characterIndex = it.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//clean up this mess
|
||||
characterMgr.Unload(characterIndex);
|
||||
accountMgr.Unload(accountIndex);
|
||||
clientMgr.Unload(clientIndex);
|
||||
|
||||
PumpCharacterUnload(characterIndex);
|
||||
|
||||
//output a message
|
||||
std::cerr << "Connection lost: " << std::endl;
|
||||
std::cerr << "\tClient: " << clientIndex << std::endl;
|
||||
std::cerr << "\tAccount: " << accountIndex << std::endl;
|
||||
std::cerr << "\tCharacter: " << characterIndex << std::endl;
|
||||
std::cout << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
||||
}
|
||||
|
||||
//TODO: remove this terminate comment
|
||||
//*/
|
||||
*/
|
||||
Reference in New Issue
Block a user