Server-side HandleRegionRequest() reimplemented
Note that this locally handles bug #35, and adds a new packet type: REGION_REJECTION
This commit is contained in:
@@ -87,8 +87,9 @@ private:
|
||||
// void HandleDisconnectForced(ClientPacket* const);
|
||||
void HandleShutdownRequest(ClientPacket* const);
|
||||
|
||||
//map management
|
||||
// void HandleRegionRequest(RegionPacket* const);
|
||||
//data management
|
||||
void HandleRegionRequest(RegionPacket* const);
|
||||
void SaveServerState();
|
||||
|
||||
//character management
|
||||
// void HandleCharacterNew(CharacterPacket* const);
|
||||
@@ -105,9 +106,6 @@ private:
|
||||
// void PumpCharacterUnload(int uid);
|
||||
// void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
||||
|
||||
//data management
|
||||
void SaveServerState();
|
||||
|
||||
//APIs and utilities
|
||||
sqlite3* database = nullptr;
|
||||
lua_State* luaState = nullptr;
|
||||
|
||||
@@ -268,11 +268,13 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
|
||||
case SerialPacketType::SHUTDOWN_REQUEST:
|
||||
HandleShutdownRequest(static_cast<ClientPacket*>(argPacket));
|
||||
break;
|
||||
/*
|
||||
|
||||
//data management & queries
|
||||
case SerialPacketType::REGION_REQUEST:
|
||||
// HandleRegionRequest(static_cast<RegionPacket*>(argPacket));
|
||||
HandleRegionRequest(static_cast<RegionPacket*>(argPacket));
|
||||
break;
|
||||
|
||||
/*
|
||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||
// HandleCharacterStatsRequest(static_cast<RegionPacket*>(argPacket));
|
||||
break;
|
||||
|
||||
+30
-14
@@ -88,7 +88,6 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) {
|
||||
|
||||
if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) {
|
||||
std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl;
|
||||
//TODO: rejection message?
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,14 +96,18 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) {
|
||||
|
||||
//Cannot load
|
||||
if (accountIndex < 0) {
|
||||
//build the message
|
||||
std::ostringstream msg;
|
||||
msg << "Account already loaded: " << argPacket->username;
|
||||
|
||||
//build the packet
|
||||
TextPacket newPacket;
|
||||
newPacket.type = SerialPacketType::LOGIN_REJECTION;
|
||||
// memset(newPacket.name, 0, PACKET_STRING_SIZE);
|
||||
strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE);
|
||||
network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket));
|
||||
|
||||
//log the error
|
||||
std::cerr << "Error message sent: " << msg << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,28 +250,45 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) {
|
||||
std::cout << "Shutdown signal accepted" << std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
//-------------------------
|
||||
//map management
|
||||
//data management
|
||||
//-------------------------
|
||||
|
||||
//SET: resources
|
||||
void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
||||
//get the region object, send a rejection on error
|
||||
RoomData* room = roomMgr.Get(argPacket->roomIndex);
|
||||
if (!room) {
|
||||
//build the error message
|
||||
std::ostringstream msg;
|
||||
msg << "Failed to find Region (" << argPacket->roomIndex << "," << argPacket->x << "," << argPacket->y << ");";
|
||||
msg << "Room " << argPacket->roomIndex << "does not exist";
|
||||
|
||||
//build the packet
|
||||
TextPacket newPacket;
|
||||
newPacket.type = SerialPacketType::REGION_REJECTION;
|
||||
strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE);
|
||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||
|
||||
//log the error
|
||||
std::cerr << "Error message sent: " << msg << std::endl;
|
||||
return;
|
||||
}
|
||||
Region* region = room->GetPager()->GetRegion(argPacket->x, argPacket->y);
|
||||
|
||||
//send the content
|
||||
RegionPacket newPacket;
|
||||
|
||||
newPacket.type = SerialPacketType::REGION_CONTENT;
|
||||
newPacket.roomIndex = argPacket->roomIndex;
|
||||
newPacket.x = argPacket->x;
|
||||
newPacket.y = argPacket->y;
|
||||
newPacket.region = region;
|
||||
|
||||
//BUG: possibly related to #35
|
||||
newPacket.region = roomMgr.Get(argPacket->roomIndex)->GetPager()->GetRegion(argPacket->x, argPacket->y);
|
||||
|
||||
//send the content
|
||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
//-------------------------
|
||||
//Character Management
|
||||
//-------------------------
|
||||
@@ -382,10 +402,6 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) {
|
||||
//TODO: more in HandleSynchronize()
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//utility methods
|
||||
//-------------------------
|
||||
|
||||
//SET: utility/manager
|
||||
void ServerApplication::CleanupLostConnection(int clientIndex) {
|
||||
//NOTE: This assumes each player has only one account and character at a time
|
||||
|
||||
Reference in New Issue
Block a user