Updated the client to use the packet methods
This commit is contained in:
@@ -21,7 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "client_application.hpp"
|
#include "client_application.hpp"
|
||||||
|
|
||||||
#include "serial.hpp"
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
|
INCLUDES+=. scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
|
||||||
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
|
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
+42
-42
@@ -269,7 +269,7 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
||||||
switch(argPacket->type) {
|
switch(argPacket->GetType()) {
|
||||||
case SerialPacketType::DISCONNECT:
|
case SerialPacketType::DISCONNECT:
|
||||||
HandleDisconnect(argPacket);
|
HandleDisconnect(argPacket);
|
||||||
break;
|
break;
|
||||||
@@ -287,7 +287,7 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
break;
|
break;
|
||||||
//handle errors
|
//handle errors
|
||||||
default:
|
default:
|
||||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->GetType())) ));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,21 +297,21 @@ void InWorld::HandleDisconnect(SerialPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||||
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
|
if (characterMap.find(argPacket->GetCharacterIndex()) != characterMap.end()) {
|
||||||
throw(std::runtime_error("Cannot create duplicate characters"));
|
throw(std::runtime_error("Cannot create duplicate characters"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//create the character object
|
//create the character object
|
||||||
Character& newCharacter = characterMap[argPacket->characterIndex];
|
Character& newCharacter = characterMap[argPacket->GetCharacterIndex()];
|
||||||
|
|
||||||
//fill out the character's members
|
//fill out the character's members
|
||||||
newCharacter.SetHandle(argPacket->handle);
|
newCharacter.SetHandle(argPacket->GetHandle());
|
||||||
newCharacter.SetAvatar(argPacket->avatar);
|
newCharacter.SetAvatar(argPacket->GetAvatar());
|
||||||
|
|
||||||
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
||||||
|
|
||||||
newCharacter.SetOrigin(argPacket->origin);
|
newCharacter.SetOrigin(argPacket->GetOrigin());
|
||||||
newCharacter.SetMotion(argPacket->motion);
|
newCharacter.SetMotion(argPacket->GetMotion());
|
||||||
newCharacter.SetBounds({
|
newCharacter.SetBounds({
|
||||||
CHARACTER_BOUNDS_X,
|
CHARACTER_BOUNDS_X,
|
||||||
CHARACTER_BOUNDS_Y,
|
CHARACTER_BOUNDS_Y,
|
||||||
@@ -319,14 +319,14 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
|||||||
CHARACTER_BOUNDS_HEIGHT
|
CHARACTER_BOUNDS_HEIGHT
|
||||||
});
|
});
|
||||||
|
|
||||||
(*newCharacter.GetStats()) = argPacket->stats;
|
*newCharacter.GetStats() = *argPacket->GetStatistics();
|
||||||
|
|
||||||
//bookkeeping code
|
//bookkeeping code
|
||||||
newCharacter.CorrectSprite();
|
newCharacter.CorrectSprite();
|
||||||
|
|
||||||
//catch this client's player object
|
//catch this client's player object
|
||||||
if (argPacket->accountIndex == accountIndex && !localCharacter) {
|
if (argPacket->GetAccountIndex() == accountIndex && !localCharacter) {
|
||||||
characterIndex = argPacket->characterIndex;
|
characterIndex = argPacket->GetCharacterIndex();
|
||||||
localCharacter = &newCharacter;
|
localCharacter = &newCharacter;
|
||||||
|
|
||||||
//setup the camera
|
//setup the camera
|
||||||
@@ -344,39 +344,39 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
|||||||
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
||||||
|
|
||||||
//catch this client's player object
|
//catch this client's player object
|
||||||
if (argPacket->characterIndex == characterIndex) {
|
if (argPacket->GetCharacterIndex() == characterIndex) {
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
localCharacter = nullptr;
|
localCharacter = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
characterMap.erase(argPacket->characterIndex);
|
characterMap.erase(argPacket->GetCharacterIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
||||||
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
|
if (characterMap.find(argPacket->GetCharacterIndex()) == characterMap.end()) {
|
||||||
std::cout << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl;
|
std::cout << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl;
|
||||||
HandleCharacterNew(argPacket);
|
HandleCharacterNew(argPacket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Character& character = characterMap[argPacket->characterIndex];
|
Character& character = characterMap[argPacket->GetCharacterIndex()];
|
||||||
|
|
||||||
//other characters moving
|
//other characters moving
|
||||||
if (argPacket->characterIndex != characterIndex) {
|
if (argPacket->GetCharacterIndex() != characterIndex) {
|
||||||
character.SetOrigin(argPacket->origin);
|
character.SetOrigin(argPacket->GetOrigin());
|
||||||
character.SetMotion(argPacket->motion);
|
character.SetMotion(argPacket->GetMotion());
|
||||||
character.CorrectSprite();
|
character.CorrectSprite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
|
void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
|
||||||
//replace existing regions
|
//replace existing regions
|
||||||
regionPager.UnloadRegion(argPacket->x, argPacket->y);
|
regionPager.UnloadRegion(argPacket->GetX(), argPacket->GetY());
|
||||||
regionPager.PushRegion(argPacket->region);
|
regionPager.PushRegion(argPacket->GetRegion());
|
||||||
|
|
||||||
//clean up after the serial code
|
//clean up after the serial code
|
||||||
delete argPacket->region;
|
delete argPacket->GetRegion();
|
||||||
argPacket->region = nullptr;
|
argPacket->SetRegion(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -387,9 +387,9 @@ void InWorld::RequestSynchronize() {
|
|||||||
ClientPacket newPacket;
|
ClientPacket newPacket;
|
||||||
|
|
||||||
//request a sync
|
//request a sync
|
||||||
newPacket.type = SerialPacketType::SYNCHRONIZE;
|
newPacket.SetType(SerialPacketType::SYNCHRONIZE);
|
||||||
newPacket.clientIndex = clientIndex;
|
newPacket.SetClientIndex(clientIndex);
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.SetAccountIndex(accountIndex);
|
||||||
|
|
||||||
//TODO: location, range for sync request
|
//TODO: location, range for sync request
|
||||||
|
|
||||||
@@ -400,15 +400,15 @@ void InWorld::SendPlayerUpdate() {
|
|||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
|
|
||||||
//pack the packet
|
//pack the packet
|
||||||
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
newPacket.SetType(SerialPacketType::CHARACTER_UPDATE);
|
||||||
|
|
||||||
newPacket.characterIndex = characterIndex;
|
newPacket.SetCharacterIndex(characterIndex);
|
||||||
//NOTE: omitting the handle and avatar here
|
//NOTE: omitting the handle and avatar here
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.SetAccountIndex(accountIndex);
|
||||||
newPacket.roomIndex = 0; //TODO: room index
|
newPacket.SetRoomIndex(0); //TODO: room index
|
||||||
newPacket.origin = localCharacter->GetOrigin();
|
newPacket.SetOrigin(localCharacter->GetOrigin());
|
||||||
newPacket.motion = localCharacter->GetMotion();
|
newPacket.SetMotion(localCharacter->GetMotion());
|
||||||
newPacket.stats = *localCharacter->GetStats();
|
*newPacket.GetStatistics() = *localCharacter->GetStats();
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
|
||||||
@@ -419,9 +419,9 @@ void InWorld::RequestDisconnect() {
|
|||||||
ClientPacket newPacket;
|
ClientPacket newPacket;
|
||||||
|
|
||||||
//send a disconnect request
|
//send a disconnect request
|
||||||
newPacket.type = SerialPacketType::DISCONNECT;
|
newPacket.SetType(SerialPacketType::DISCONNECT);
|
||||||
newPacket.clientIndex = clientIndex;
|
newPacket.SetClientIndex(clientIndex);
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.SetAccountIndex(accountIndex);
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
}
|
}
|
||||||
@@ -430,9 +430,9 @@ void InWorld::RequestShutDown() {
|
|||||||
ClientPacket newPacket;
|
ClientPacket newPacket;
|
||||||
|
|
||||||
//send a shutdown request
|
//send a shutdown request
|
||||||
newPacket.type = SerialPacketType::SHUTDOWN;
|
newPacket.SetType(SerialPacketType::SHUTDOWN);
|
||||||
newPacket.clientIndex = clientIndex;
|
newPacket.SetClientIndex(clientIndex);
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.SetAccountIndex(accountIndex);
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
}
|
}
|
||||||
@@ -441,10 +441,10 @@ void InWorld::RequestRegion(int roomIndex, int x, int y) {
|
|||||||
RegionPacket packet;
|
RegionPacket packet;
|
||||||
|
|
||||||
//pack the region's data
|
//pack the region's data
|
||||||
packet.type = SerialPacketType::REGION_REQUEST;
|
packet.SetType(SerialPacketType::REGION_REQUEST);
|
||||||
packet.roomIndex = roomIndex;
|
packet.SetRoomIndex(roomIndex);
|
||||||
packet.x = x;
|
packet.SetX(x);
|
||||||
packet.y = y;
|
packet.SetY(y);
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &packet);
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
||||||
switch(argPacket->type) {
|
switch(argPacket->GetType()) {
|
||||||
case SerialPacketType::BROADCAST_RESPONSE:
|
case SerialPacketType::BROADCAST_RESPONSE:
|
||||||
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
|
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
@@ -194,7 +194,7 @@ void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
break;
|
break;
|
||||||
//handle errors
|
//handle errors
|
||||||
default:
|
default:
|
||||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->GetType())) ));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,10 +202,10 @@ void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
||||||
//extract the data
|
//extract the data
|
||||||
ServerInformation server;
|
ServerInformation server;
|
||||||
server.address = argPacket->srcAddress;
|
server.address = argPacket->GetAddress();
|
||||||
server.name = argPacket->name;
|
server.name = argPacket->GetName();
|
||||||
server.playerCount = argPacket->playerCount;
|
server.playerCount = argPacket->GetPlayerCount();
|
||||||
server.version = argPacket->version;
|
server.version = argPacket->GetVersion();
|
||||||
|
|
||||||
//Checking compatibility
|
//Checking compatibility
|
||||||
server.compatible = server.version == NETWORK_VERSION;
|
server.compatible = server.version == NETWORK_VERSION;
|
||||||
@@ -215,17 +215,17 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
||||||
clientIndex = argPacket->clientIndex;
|
clientIndex = argPacket->GetClientIndex();
|
||||||
accountIndex = argPacket->accountIndex;
|
accountIndex = argPacket->GetAccountIndex();
|
||||||
network.Bind(&argPacket->srcAddress, Channels::SERVER);
|
network.Bind(argPacket->GetAddressPtr(), Channels::SERVER);
|
||||||
SetNextScene(SceneList::INWORLD);
|
SetNextScene(SceneList::INWORLD);
|
||||||
|
|
||||||
//send this player's character info
|
//send this player's character info
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::CHARACTER_NEW;
|
newPacket.SetType(SerialPacketType::CHARACTER_NEW);
|
||||||
strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
newPacket.SetHandle(config["client.handle"].c_str());
|
||||||
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
newPacket.SetAvatar(config["client.avatar"].c_str());
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.SetAccountIndex(accountIndex);
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,8 +235,8 @@ void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
|||||||
|
|
||||||
void LobbyMenu::SendBroadcastRequest() {
|
void LobbyMenu::SendBroadcastRequest() {
|
||||||
//broadcast to the network, or a specific server
|
//broadcast to the network, or a specific server
|
||||||
SerialPacket packet;
|
ServerPacket packet;
|
||||||
packet.type = SerialPacketType::BROADCAST_REQUEST;
|
packet.SetType(SerialPacketType::BROADCAST_REQUEST);
|
||||||
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
||||||
|
|
||||||
//reset the server list
|
//reset the server list
|
||||||
@@ -247,8 +247,8 @@ void LobbyMenu::SendBroadcastRequest() {
|
|||||||
void LobbyMenu::SendJoinRequest() {
|
void LobbyMenu::SendJoinRequest() {
|
||||||
//pack the packet
|
//pack the packet
|
||||||
ClientPacket packet;
|
ClientPacket packet;
|
||||||
packet.type = SerialPacketType::JOIN_REQUEST;
|
packet.SetType(SerialPacketType::JOIN_REQUEST);
|
||||||
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
packet.SetUsername(config["client.username"].c_str());
|
||||||
|
|
||||||
//join the selected server
|
//join the selected server
|
||||||
network.SendTo(&selection->address, &packet);
|
network.SendTo(&selection->address, &packet);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet ../../common/network/serial ../../common/ui ../../common/utilities
|
INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user