Merge branch 'client-fix' into develop (read more)
The entire repository builds cleanly, but the client is still broken and incompatible with the server. Still, I'm merging this build into develop. I don't know if the client runs correctly. Much of the modifications since branching from master are untested.
This commit is contained in:
@@ -124,7 +124,7 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
||||
activeScene = new OptionsMenu(&config);
|
||||
break;
|
||||
case SceneList::LOBBYMENU:
|
||||
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex);
|
||||
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
|
||||
break;
|
||||
case SceneList::INWORLD:
|
||||
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
|
||||
|
||||
+41
-38
@@ -85,11 +85,10 @@ void InCombat::FrameStart() {
|
||||
}
|
||||
|
||||
void InCombat::Update(double delta) {
|
||||
SerialPacket packet;
|
||||
|
||||
//suck in all waiting packets
|
||||
while(network.Receive(&packet)) {
|
||||
HandlePacket(packet);
|
||||
//suck in and process all waiting packets
|
||||
char packetBuffer[MAX_PACKET_SIZE];
|
||||
while(network.Receive(reinterpret_cast<SerialPacket*>(packetBuffer))) {
|
||||
HandlePacket(reinterpret_cast<SerialPacket*>(packetBuffer));
|
||||
}
|
||||
|
||||
//TODO: more
|
||||
@@ -154,19 +153,19 @@ void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
//Network handlers
|
||||
//-------------------------
|
||||
|
||||
void InCombat::HandlePacket(SerialPacket packet) {
|
||||
switch(packet.meta.type) {
|
||||
case SerialPacket::Type::DISCONNECT:
|
||||
HandleDisconnect(packet);
|
||||
void InCombat::HandlePacket(SerialPacket* const argPacket) {
|
||||
switch(argPacket->type) {
|
||||
case SerialPacketType::DISCONNECT:
|
||||
HandleDisconnect(argPacket);
|
||||
break;
|
||||
//handle errors
|
||||
default:
|
||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InCombat: " + to_string_custom(int(packet.meta.type))));
|
||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InCombat: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InCombat::HandleDisconnect(SerialPacket) {
|
||||
void InCombat::HandleDisconnect(SerialPacket* const) {
|
||||
SetNextScene(SceneList::RESTART);
|
||||
}
|
||||
|
||||
@@ -177,52 +176,56 @@ void InCombat::HandleDisconnect(SerialPacket) {
|
||||
//-------------------------
|
||||
|
||||
void InCombat::RequestSynchronize() {
|
||||
SerialPacket packet;
|
||||
ClientPacket newPacket;
|
||||
|
||||
//request a sync
|
||||
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
newPacket.type = SerialPacketType::SYNCHRONIZE;
|
||||
newPacket.clientIndex = clientIndex;
|
||||
newPacket.accountIndex = accountIndex;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
void InCombat::SendPlayerUpdate() {
|
||||
SerialPacket packet;
|
||||
CharacterPacket newPacket;
|
||||
|
||||
//pack the packet
|
||||
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
||||
packet.characterInfo.clientIndex = clientIndex;
|
||||
packet.characterInfo.accountIndex = accountIndex;
|
||||
packet.characterInfo.characterIndex = characterIndex;
|
||||
// packet.characterInfo.position = localCharacter->position;
|
||||
// packet.characterInfo.motion = localCharacter->motion;
|
||||
//TODO: stats
|
||||
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
newPacket.characterIndex = characterIndex;
|
||||
//handle, avatar
|
||||
newPacket.accountIndex = accountIndex;
|
||||
// newPacket.roomIndex = localCharacter->roomIndex;
|
||||
// newPacket.origin = localCharacter->origin;
|
||||
// newPacket.motion = localCharacter->motion;
|
||||
// newPacket.stats = localCharacter->stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
void InCombat::RequestDisconnect() {
|
||||
SerialPacket packet;
|
||||
ClientPacket newPacket;
|
||||
|
||||
//send a disconnect request
|
||||
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
newPacket.type = SerialPacketType::DISCONNECT;
|
||||
newPacket.clientIndex = clientIndex;
|
||||
newPacket.accountIndex = accountIndex;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
void InCombat::RequestShutdown() {
|
||||
SerialPacket packet;
|
||||
ClientPacket newPacket;
|
||||
|
||||
//send a shutdown request
|
||||
packet.meta.type = SerialPacket::Type::SHUTDOWN;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
newPacket.type = SerialPacketType::SHUTDOWN;
|
||||
newPacket.clientIndex = clientIndex;
|
||||
newPacket.accountIndex = accountIndex;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ protected:
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//Network handlers
|
||||
void HandlePacket(SerialPacket);
|
||||
void HandleDisconnect(SerialPacket);
|
||||
void HandlePacket(SerialPacket* const);
|
||||
void HandleDisconnect(SerialPacket* const);
|
||||
//TODO: more network handlers
|
||||
|
||||
//Server control
|
||||
|
||||
+93
-85
@@ -22,6 +22,7 @@
|
||||
#include "in_world.hpp"
|
||||
|
||||
#include "channels.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -93,11 +94,10 @@ void InWorld::FrameStart() {
|
||||
}
|
||||
|
||||
void InWorld::Update(double delta) {
|
||||
SerialPacket packet;
|
||||
|
||||
//suck in all waiting packets
|
||||
while(network.Receive(&packet)) {
|
||||
HandlePacket(packet);
|
||||
//suck in and process all waiting packets
|
||||
char packetBuffer[MAX_PACKET_SIZE];
|
||||
while(network.Receive(reinterpret_cast<SerialPacket*>(packetBuffer))) {
|
||||
HandlePacket(reinterpret_cast<SerialPacket*>(packetBuffer));
|
||||
}
|
||||
|
||||
//update the characters
|
||||
@@ -248,76 +248,55 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
//Network handlers
|
||||
//-------------------------
|
||||
|
||||
void InWorld::HandlePacket(SerialPacket packet) {
|
||||
switch(packet.meta.type) {
|
||||
case SerialPacket::Type::DISCONNECT:
|
||||
HandleDisconnect(packet);
|
||||
void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
||||
switch(argPacket->type) {
|
||||
case SerialPacketType::DISCONNECT:
|
||||
HandleDisconnect(argPacket);
|
||||
break;
|
||||
case SerialPacket::Type::REGION_CONTENT:
|
||||
HandleRegionContent(packet);
|
||||
case SerialPacketType::CHARACTER_NEW:
|
||||
HandleCharacterNew(dynamic_cast<CharacterPacket*>(argPacket));
|
||||
break;
|
||||
case SerialPacket::Type::CHARACTER_UPDATE:
|
||||
HandleCharacterUpdate(packet);
|
||||
case SerialPacketType::CHARACTER_DELETE:
|
||||
HandleCharacterDelete(dynamic_cast<CharacterPacket*>(argPacket));
|
||||
break;
|
||||
case SerialPacket::Type::CHARACTER_NEW:
|
||||
HandleCharacterNew(packet);
|
||||
case SerialPacketType::CHARACTER_UPDATE:
|
||||
HandleCharacterUpdate(dynamic_cast<CharacterPacket*>(argPacket));
|
||||
break;
|
||||
case SerialPacket::Type::CHARACTER_DELETE:
|
||||
HandleCharacterDelete(packet);
|
||||
case SerialPacketType::REGION_CONTENT:
|
||||
HandleRegionContent(dynamic_cast<RegionPacket*>(argPacket));
|
||||
break;
|
||||
//handle errors
|
||||
default:
|
||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(int(packet.meta.type))));
|
||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InWorld::HandleDisconnect(SerialPacket packet) {
|
||||
void InWorld::HandleDisconnect(SerialPacket* const argPacket) {
|
||||
SetNextScene(SceneList::RESTART);
|
||||
}
|
||||
|
||||
void InWorld::HandleRegionContent(SerialPacket packet) {
|
||||
//replace existing regions
|
||||
regionPager.UnloadRegion(packet.regionInfo.x, packet.regionInfo.y);
|
||||
regionPager.PushRegion(packet.regionInfo.region);
|
||||
packet.regionInfo.region = nullptr;
|
||||
}
|
||||
|
||||
void InWorld::HandleCharacterUpdate(SerialPacket packet) {
|
||||
if (characterMap.find(packet.characterInfo.characterIndex) == characterMap.end()) {
|
||||
HandleCharacterNew(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
//update only if the message didn't originate from here
|
||||
if (packet.characterInfo.clientIndex != clientIndex) {
|
||||
characterMap[packet.characterInfo.characterIndex].origin = packet.characterInfo.origin;
|
||||
characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion;
|
||||
}
|
||||
characterMap[packet.characterInfo.characterIndex].CorrectSprite();
|
||||
}
|
||||
|
||||
void InWorld::HandleCharacterNew(SerialPacket packet) {
|
||||
if (characterMap.find(packet.characterInfo.characterIndex) != characterMap.end()) {
|
||||
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
|
||||
throw(std::runtime_error("Cannot create duplicate characters"));
|
||||
}
|
||||
|
||||
//create the character object
|
||||
CharacterData& character = characterMap[packet.characterInfo.characterIndex];
|
||||
CharacterData& character = characterMap[argPacket->characterIndex];
|
||||
|
||||
//set the members
|
||||
character.handle = packet.characterInfo.handle;
|
||||
character.avatar = packet.characterInfo.avatar;
|
||||
character.handle = argPacket->handle;
|
||||
character.avatar = argPacket->avatar;
|
||||
character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4);
|
||||
character.mapIndex = packet.characterInfo.mapIndex;
|
||||
character.origin = packet.characterInfo.origin;
|
||||
character.motion = packet.characterInfo.motion;
|
||||
character.stats = packet.characterInfo.stats;
|
||||
character.roomIndex = argPacket->roomIndex;
|
||||
character.origin = argPacket->origin;
|
||||
character.motion = argPacket->motion;
|
||||
character.stats = argPacket->stats;
|
||||
|
||||
character.CorrectSprite();
|
||||
|
||||
//catch this client's player object
|
||||
if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) {
|
||||
if (argPacket->characterIndex == characterIndex && !localCharacter) {
|
||||
localCharacter = &character;
|
||||
|
||||
//setup the camera
|
||||
@@ -331,15 +310,39 @@ void InWorld::HandleCharacterNew(SerialPacket packet) {
|
||||
}
|
||||
}
|
||||
|
||||
void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
||||
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
||||
//catch this client's player object
|
||||
if (packet.characterInfo.characterIndex == characterIndex) {
|
||||
if (argPacket->characterIndex == characterIndex) {
|
||||
characterIndex = -1;
|
||||
localCharacter = nullptr;
|
||||
}
|
||||
|
||||
characterMap.erase(packet.characterInfo.characterIndex);
|
||||
characterMap.erase(argPacket->characterIndex);
|
||||
}
|
||||
|
||||
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
||||
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
|
||||
HandleCharacterNew(argPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
CharacterData& character = characterMap[argPacket->characterIndex];
|
||||
|
||||
//TODO: review this
|
||||
if (argPacket->characterIndex != characterIndex) {
|
||||
character.roomIndex = argPacket->roomIndex;
|
||||
character.origin = argPacket->origin;
|
||||
character.motion = argPacket->motion;
|
||||
character.CorrectSprite();
|
||||
}
|
||||
}
|
||||
|
||||
void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
|
||||
//replace existing regions
|
||||
regionPager.UnloadRegion(argPacket->x, argPacket->y);
|
||||
regionPager.PushRegion(argPacket->region);
|
||||
argPacket->region = nullptr;
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -347,63 +350,68 @@ void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
||||
//-------------------------
|
||||
|
||||
void InWorld::RequestSynchronize() {
|
||||
SerialPacket packet;
|
||||
ClientPacket newPacket;
|
||||
|
||||
//request a sync
|
||||
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
newPacket.type = SerialPacketType::SYNCHRONIZE;
|
||||
newPacket.clientIndex = clientIndex;
|
||||
newPacket.accountIndex = accountIndex;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
void InWorld::SendPlayerUpdate() {
|
||||
SerialPacket packet;
|
||||
CharacterPacket newPacket;
|
||||
|
||||
//pack the packet
|
||||
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
||||
packet.characterInfo.clientIndex = clientIndex;
|
||||
packet.characterInfo.accountIndex = accountIndex;
|
||||
packet.characterInfo.characterIndex = characterIndex;
|
||||
packet.characterInfo.origin = localCharacter->origin;
|
||||
packet.characterInfo.motion = localCharacter->motion;
|
||||
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
newPacket.characterIndex = characterIndex;
|
||||
//handle, avatar
|
||||
newPacket.accountIndex = accountIndex;
|
||||
newPacket.roomIndex = localCharacter->roomIndex;
|
||||
newPacket.origin = localCharacter->origin;
|
||||
newPacket.motion = localCharacter->motion;
|
||||
newPacket.stats = localCharacter->stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
void InWorld::RequestDisconnect() {
|
||||
SerialPacket packet;
|
||||
ClientPacket newPacket;
|
||||
|
||||
//send a disconnect request
|
||||
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
newPacket.type = SerialPacketType::DISCONNECT;
|
||||
newPacket.clientIndex = clientIndex;
|
||||
newPacket.accountIndex = accountIndex;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
void InWorld::RequestShutDown() {
|
||||
SerialPacket packet;
|
||||
ClientPacket newPacket;
|
||||
|
||||
//send a shutdown request
|
||||
packet.meta.type = SerialPacket::Type::SHUTDOWN;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
newPacket.type = SerialPacketType::SHUTDOWN;
|
||||
newPacket.clientIndex = clientIndex;
|
||||
newPacket.accountIndex = accountIndex;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
void InWorld::RequestRegion(int mapIndex, int x, int y) {
|
||||
SerialPacket packet;
|
||||
void InWorld::RequestRegion(int roomIndex, int x, int y) {
|
||||
RegionPacket packet;
|
||||
|
||||
//pack the region's data
|
||||
packet.meta.type = SerialPacket::Type::REGION_REQUEST;
|
||||
packet.regionInfo.mapIndex = mapIndex;
|
||||
packet.regionInfo.x = x;
|
||||
packet.regionInfo.y = y;
|
||||
packet.type = SerialPacketType::REGION_REQUEST;
|
||||
packet.roomIndex = roomIndex;
|
||||
packet.x = x;
|
||||
packet.y = y;
|
||||
|
||||
network.SendTo(Channels::SERVER, &packet);
|
||||
}
|
||||
|
||||
+8
-10
@@ -23,8 +23,6 @@
|
||||
#define INWORLD_HPP_
|
||||
|
||||
//maps
|
||||
#include "map_allocator.hpp"
|
||||
#include "map_file_format.hpp"
|
||||
#include "region_pager.hpp"
|
||||
|
||||
//networking
|
||||
@@ -80,19 +78,19 @@ protected:
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//Network handlers
|
||||
void HandlePacket(SerialPacket);
|
||||
void HandleDisconnect(SerialPacket);
|
||||
void HandleCharacterNew(SerialPacket);
|
||||
void HandleCharacterDelete(SerialPacket);
|
||||
void HandleCharacterUpdate(SerialPacket);
|
||||
void HandleRegionContent(SerialPacket);
|
||||
void HandlePacket(SerialPacket* const);
|
||||
void HandleDisconnect(SerialPacket* const);
|
||||
void HandleCharacterNew(CharacterPacket* const);
|
||||
void HandleCharacterDelete(CharacterPacket* const);
|
||||
void HandleCharacterUpdate(CharacterPacket* const);
|
||||
void HandleRegionContent(RegionPacket* const);
|
||||
|
||||
//Server control
|
||||
void RequestSynchronize();
|
||||
void SendPlayerUpdate();
|
||||
void RequestDisconnect();
|
||||
void RequestShutDown();
|
||||
void RequestRegion(int mapIndex, int x, int y);
|
||||
void RequestRegion(int roomIndex, int x, int y);
|
||||
|
||||
//utilities
|
||||
void UpdateMap();
|
||||
@@ -112,7 +110,7 @@ protected:
|
||||
TileSheet tileSheet;
|
||||
|
||||
//map
|
||||
RegionPager<BlankAllocator, DummyFormat> regionPager;
|
||||
RegionPager regionPager;
|
||||
|
||||
//UI
|
||||
Button disconnectButton;
|
||||
|
||||
+41
-37
@@ -34,14 +34,12 @@ LobbyMenu::LobbyMenu(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
int* const argAccountIndex
|
||||
):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
clientIndex(*argClientIndex),
|
||||
accountIndex(*argAccountIndex),
|
||||
characterIndex(*argCharacterIndex)
|
||||
accountIndex(*argAccountIndex)
|
||||
{
|
||||
//setup the utility objects
|
||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
@@ -87,9 +85,9 @@ void LobbyMenu::FrameStart() {
|
||||
|
||||
void LobbyMenu::Update(double delta) {
|
||||
//suck in and process all waiting packets
|
||||
SerialPacket packet;
|
||||
while(network.Receive(&packet)) {
|
||||
HandlePacket(packet);
|
||||
char packetBuffer[MAX_PACKET_SIZE];
|
||||
while(network.Receive(reinterpret_cast<SerialPacket*>(packetBuffer))) {
|
||||
HandlePacket(reinterpret_cast<SerialPacket*>(packetBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +147,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
if (search.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
//broadcast to the network, or a specific server
|
||||
SerialPacket packet;
|
||||
packet.meta.type = SerialPacket::Type::BROADCAST_REQUEST;
|
||||
packet.type = SerialPacketType::BROADCAST_REQUEST;
|
||||
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
||||
|
||||
//reset the server list
|
||||
@@ -159,11 +157,9 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
|
||||
else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) {
|
||||
//pack the packet
|
||||
SerialPacket packet;
|
||||
packet.meta.type = SerialPacket::Type::JOIN_REQUEST;
|
||||
strncpy(packet.clientInfo.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(packet.clientInfo.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(packet.clientInfo.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
||||
ClientPacket packet;
|
||||
packet.type = SerialPacketType::JOIN_REQUEST;
|
||||
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
||||
|
||||
//join the selected server
|
||||
network.SendTo(&selection->address, &packet);
|
||||
@@ -176,6 +172,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
|
||||
else if (
|
||||
//has the user selected a server on the list?
|
||||
//TODO: replace with regular collision checker
|
||||
button.x > listBox.x &&
|
||||
button.x < listBox.x + listBox.w &&
|
||||
button.y > listBox.y &&
|
||||
@@ -204,34 +201,41 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
//Network handlers
|
||||
//-------------------------
|
||||
|
||||
void LobbyMenu::HandlePacket(SerialPacket packet) {
|
||||
switch(packet.meta.type) {
|
||||
case SerialPacket::Type::BROADCAST_RESPONSE: {
|
||||
//extract the data
|
||||
ServerInformation server;
|
||||
server.address = packet.meta.srcAddress;
|
||||
server.networkVersion = packet.serverInfo.networkVersion;
|
||||
server.name = packet.serverInfo.name;
|
||||
server.playerCount = packet.serverInfo.playerCount;
|
||||
|
||||
//NOTE: Check compatibility here
|
||||
server.compatible = server.networkVersion == NETWORK_VERSION;
|
||||
|
||||
//push
|
||||
serverInfo.push_back(server);
|
||||
}
|
||||
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
||||
switch(argPacket->type) {
|
||||
case SerialPacketType::BROADCAST_RESPONSE:
|
||||
HandleBroadcastResponse(dynamic_cast<ServerPacket*>(argPacket));
|
||||
break;
|
||||
case SerialPacket::Type::JOIN_RESPONSE:
|
||||
clientIndex = packet.clientInfo.clientIndex;
|
||||
accountIndex = packet.clientInfo.accountIndex;
|
||||
characterIndex = packet.clientInfo.characterIndex;
|
||||
network.Bind(&packet.meta.srcAddress, Channels::SERVER);
|
||||
SetNextScene(SceneList::INWORLD);
|
||||
case SerialPacketType::JOIN_RESPONSE:
|
||||
HandleJoinResponse(dynamic_cast<ClientPacket*>(argPacket));
|
||||
break;
|
||||
|
||||
//handle errors
|
||||
default:
|
||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(int(packet.meta.type))));
|
||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
||||
//extract the data
|
||||
ServerInformation server;
|
||||
server.address = argPacket->srcAddress;
|
||||
server.name = argPacket->name;
|
||||
server.playerCount = argPacket->playerCount;
|
||||
server.version = argPacket->version;
|
||||
|
||||
//NOTE: Check compatibility here
|
||||
server.compatible = server.version == NETWORK_VERSION;
|
||||
|
||||
//push
|
||||
serverInfo.push_back(server);
|
||||
}
|
||||
|
||||
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
||||
clientIndex = argPacket->clientIndex;
|
||||
accountIndex = argPacket->accountIndex;
|
||||
network.Bind(&argPacket->srcAddress, Channels::SERVER);
|
||||
SetNextScene(SceneList::INWORLD);
|
||||
|
||||
//TODO: send this player's character info
|
||||
}
|
||||
@@ -22,13 +22,13 @@
|
||||
#ifndef LOBBYMENU_HPP_
|
||||
#define LOBBYMENU_HPP_
|
||||
|
||||
//graphics & utilities
|
||||
//graphics & ui
|
||||
#include "image.hpp"
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
#include "config_utility.hpp"
|
||||
|
||||
//network
|
||||
//utilities
|
||||
#include "config_utility.hpp"
|
||||
#include "udp_network_utility.hpp"
|
||||
|
||||
//client
|
||||
@@ -44,8 +44,7 @@ public:
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
int* const argAccountIndex
|
||||
);
|
||||
~LobbyMenu();
|
||||
|
||||
@@ -64,14 +63,15 @@ protected:
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//Network handlers
|
||||
void HandlePacket(SerialPacket);
|
||||
void HandlePacket(SerialPacket* const);
|
||||
void HandleBroadcastResponse(ServerPacket* const);
|
||||
void HandleJoinResponse(ClientPacket* const);
|
||||
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
int& characterIndex;
|
||||
|
||||
//members
|
||||
Image image;
|
||||
@@ -83,9 +83,9 @@ protected:
|
||||
//server list
|
||||
struct ServerInformation {
|
||||
IPaddress address;
|
||||
int networkVersion;
|
||||
std::string name;
|
||||
int playerCount;
|
||||
int version;
|
||||
bool compatible;
|
||||
};
|
||||
|
||||
|
||||
@@ -63,7 +63,25 @@ Region* RegionPager::FindRegion(int x, int y) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Region* RegionPager::PushRegion(Region* const region) {
|
||||
if (
|
||||
region->GetX() != snapToBase(REGION_WIDTH, region->GetX()) ||
|
||||
region->GetY() != snapToBase(REGION_HEIGHT, region->GetY())
|
||||
)
|
||||
{
|
||||
throw(std::runtime_error("Pushed region does not conform to the region grid"));
|
||||
}
|
||||
|
||||
regionList.push_front(region);
|
||||
return regionList.front();
|
||||
}
|
||||
|
||||
Region* RegionPager::LoadRegion(int x, int y) {
|
||||
//only work if using lua
|
||||
if (!luaState) {
|
||||
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||
}
|
||||
|
||||
//load the region if possible
|
||||
|
||||
//snap the coords
|
||||
@@ -97,6 +115,11 @@ Region* RegionPager::LoadRegion(int x, int y) {
|
||||
}
|
||||
|
||||
Region* RegionPager::SaveRegion(int x, int y) {
|
||||
//only work if using lua
|
||||
if (!luaState) {
|
||||
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||
}
|
||||
|
||||
//snap the coords
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
@@ -118,6 +141,11 @@ Region* RegionPager::SaveRegion(int x, int y) {
|
||||
}
|
||||
|
||||
Region* RegionPager::CreateRegion(int x, int y) {
|
||||
//only work if using lua
|
||||
if (!luaState) {
|
||||
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||
}
|
||||
|
||||
//snap the coords
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
@@ -143,6 +171,11 @@ Region* RegionPager::CreateRegion(int x, int y) {
|
||||
}
|
||||
|
||||
void RegionPager::UnloadRegion(int x, int y) {
|
||||
//only work if using lua
|
||||
if (!luaState) {
|
||||
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||
}
|
||||
|
||||
//snap the coords
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
//TODO: split this into two: "RegionPagerBase" and "RegionPagerLua"
|
||||
class RegionPager {
|
||||
public:
|
||||
RegionPager() = default;
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
//region manipulation
|
||||
Region* GetRegion(int x, int y);
|
||||
Region* FindRegion(int x, int y);
|
||||
Region* PushRegion(Region* const);
|
||||
|
||||
Region* LoadRegion(int x, int y);
|
||||
Region* SaveRegion(int x, int y);
|
||||
|
||||
@@ -38,8 +38,6 @@ struct SerialPacketBase {
|
||||
SerialPacketType type;
|
||||
IPaddress srcAddress;
|
||||
|
||||
typedef SerialPacketType Type;
|
||||
|
||||
virtual ~SerialPacketBase() {};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user