Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 59963a05f3 | |||
| 7d4d7817f2 | |||
| 1c1b1e0a1f | |||
| 895671e30f | |||
| cfe82c0625 | |||
| b5ca9dc729 | |||
| 164247de4f | |||
| ac799bc583 | |||
| b8bd5f9cea | |||
| 4b5194918b | |||
| 426c3a52c2 | |||
| 16b2a60373 | |||
| 6cdc3080a2 |
@@ -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))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. packet serial ../gameplay ../map ../utilities
|
INCLUDES+=. packet_types ../gameplay ../map ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
@@ -17,8 +17,7 @@ OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
|||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
ar -crs $(OUT) $(OBJ)
|
ar -crs $(OUT) $(OBJ)
|
||||||
$(MAKE) -C packet
|
$(MAKE) -C packet_types
|
||||||
$(MAKE) -C serial
|
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013, 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#ifndef ENEMYPACKET_HPP_
|
|
||||||
#define ENEMYPACKET_HPP_
|
|
||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
|
||||||
|
|
||||||
struct EnemyPacket : SerialPacketBase {
|
|
||||||
//identify the enemy
|
|
||||||
int enemyIndex;
|
|
||||||
char handle[PACKET_STRING_SIZE];
|
|
||||||
char avatar[PACKET_STRING_SIZE];
|
|
||||||
|
|
||||||
//gameplay
|
|
||||||
Statistics stats;
|
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013, 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial_packet.hpp"
|
|
||||||
|
|
||||||
/* DOCS: Sanity check, read more
|
|
||||||
* Since most/all of the files in this directory are header files, I've created
|
|
||||||
* this source file as a "sanity check", to ensure that the above header files
|
|
||||||
* are written correctly via make.
|
|
||||||
*/
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013, 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#ifndef SERIALPACKETTYPE_HPP_
|
|
||||||
#define SERIALPACKETTYPE_HPP_
|
|
||||||
|
|
||||||
/* Key for the comments:
|
|
||||||
* request => response
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum class SerialPacketType {
|
|
||||||
//default: there is something wrong
|
|
||||||
NONE = 0,
|
|
||||||
|
|
||||||
//keep alive
|
|
||||||
//ping => pong
|
|
||||||
PING = 1,
|
|
||||||
PONG = 2,
|
|
||||||
|
|
||||||
//search for the server list
|
|
||||||
//none => server name, player count, version info (and source address)
|
|
||||||
BROADCAST_REQUEST = 3,
|
|
||||||
BROADCAST_RESPONSE = 4,
|
|
||||||
|
|
||||||
//try to join the server
|
|
||||||
//username, and password => client index, account index
|
|
||||||
JOIN_REQUEST = 5,
|
|
||||||
JOIN_RESPONSE = 6,
|
|
||||||
JOIN_REJECTION = 7,
|
|
||||||
|
|
||||||
//mass update of all surrounding content
|
|
||||||
//character.x, character.y => packet barrage
|
|
||||||
SYNCHRONIZE = 8,
|
|
||||||
|
|
||||||
//disconnect from the server
|
|
||||||
//autentication, account index => disconnect that account
|
|
||||||
DISCONNECT = 9,
|
|
||||||
|
|
||||||
//shut down the server
|
|
||||||
//autentication => disconnect, shutdown
|
|
||||||
SHUTDOWN = 10,
|
|
||||||
|
|
||||||
//map data
|
|
||||||
//room index, region.x, region.y => room index, region.x, region.y, region content
|
|
||||||
REGION_REQUEST = 11,
|
|
||||||
REGION_CONTENT = 12,
|
|
||||||
|
|
||||||
//combat data
|
|
||||||
//TODO: system incomplete
|
|
||||||
COMBAT_NEW = 13,
|
|
||||||
COMBAT_DELETE = 14,
|
|
||||||
COMBAT_UPDATE = 15,
|
|
||||||
|
|
||||||
COMBAT_ENTER_REQUEST = 16,
|
|
||||||
COMBAT_ENTER_RESPONSE = 17,
|
|
||||||
|
|
||||||
COMBAT_EXIT_REQUEST = 18,
|
|
||||||
COMBAT_EXIT_RESPONSE = 19,
|
|
||||||
|
|
||||||
//TODO: COMBAT info
|
|
||||||
|
|
||||||
COMBAT_REJECTION = 20,
|
|
||||||
|
|
||||||
//character data
|
|
||||||
//character data => etc.
|
|
||||||
CHARACTER_NEW = 21,
|
|
||||||
CHARACTER_DELETE = 22,
|
|
||||||
CHARACTER_UPDATE = 23,
|
|
||||||
|
|
||||||
//authentication, character index => character stats
|
|
||||||
CHARACTER_STATS_REQUEST= 24,
|
|
||||||
CHARACTER_STATS_RESPONSE = 25,
|
|
||||||
|
|
||||||
//character new => character rejection, disconnect?
|
|
||||||
CHARACTER_REJECTION = 26,
|
|
||||||
|
|
||||||
//enemy data
|
|
||||||
//enemy data => etc.
|
|
||||||
ENEMY_NEW = 27,
|
|
||||||
ENEMY_DELETE = 28,
|
|
||||||
ENEMY_UPDATE = 29,
|
|
||||||
|
|
||||||
ENEMY_STATS_REQUEST = 30,
|
|
||||||
ENEMY_STATS_RESPONSE = 31,
|
|
||||||
|
|
||||||
//enemy index => enemy doens't exist
|
|
||||||
ENEMY_REJECTION= 32,
|
|
||||||
|
|
||||||
//NOTE: more packet types go here
|
|
||||||
|
|
||||||
//not used
|
|
||||||
LAST
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "character_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void CharacterPacket::Serialize(void* buffer) {
|
||||||
|
serializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the character
|
||||||
|
serializeCopy(&buffer, &characterIndex, sizeof(int));
|
||||||
|
serializeCopy(&buffer, handle, PACKET_STRING_SIZE);
|
||||||
|
serializeCopy(&buffer, avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//the owner
|
||||||
|
serializeCopy(&buffer, &accountIndex, sizeof(int));
|
||||||
|
|
||||||
|
//location
|
||||||
|
serializeCopy(&buffer, &roomIndex, sizeof(int));
|
||||||
|
serializeCopy(&buffer, &origin.x, sizeof(double));
|
||||||
|
serializeCopy(&buffer, &origin.y, sizeof(double));
|
||||||
|
serializeCopy(&buffer, &motion.x, sizeof(double));
|
||||||
|
serializeCopy(&buffer, &motion.y, sizeof(double));
|
||||||
|
|
||||||
|
//stats structure
|
||||||
|
serializeCopyStatistics(&buffer, &stats);
|
||||||
|
|
||||||
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterPacket::Deserialize(void* buffer) {
|
||||||
|
deserializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the character
|
||||||
|
deserializeCopy(&buffer, &characterIndex, sizeof(int));
|
||||||
|
deserializeCopy(&buffer, handle, PACKET_STRING_SIZE);
|
||||||
|
deserializeCopy(&buffer, avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//the owner
|
||||||
|
deserializeCopy(&buffer, &accountIndex, sizeof(int));
|
||||||
|
|
||||||
|
//location
|
||||||
|
deserializeCopy(&buffer, &roomIndex, sizeof(int));
|
||||||
|
deserializeCopy(&buffer, &origin.x, sizeof(double));
|
||||||
|
deserializeCopy(&buffer, &origin.y, sizeof(double));
|
||||||
|
deserializeCopy(&buffer, &motion.x, sizeof(double));
|
||||||
|
deserializeCopy(&buffer, &motion.y, sizeof(double));
|
||||||
|
|
||||||
|
//stats structure
|
||||||
|
deserializeCopyStatistics(&buffer, &stats);
|
||||||
|
|
||||||
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef CHARACTERPACKET_HPP_
|
||||||
|
#define CHARACTERPACKET_HPP_
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
#include "vector2.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
class CharacterPacket : public SerialPacketBase {
|
||||||
|
public:
|
||||||
|
CharacterPacket() {}
|
||||||
|
~CharacterPacket() {}
|
||||||
|
|
||||||
|
//indentity
|
||||||
|
int SetCharacterIndex(int i) { return characterIndex = i; }
|
||||||
|
const char* SetHandle(const char* s)
|
||||||
|
{ return strncpy(handle, s, PACKET_STRING_SIZE); }
|
||||||
|
const char* SetAvatar(const char* s)
|
||||||
|
{ return strncpy(handle, s, PACKET_STRING_SIZE); }
|
||||||
|
|
||||||
|
int SetAccountIndex(int i) { return accountIndex = i; }
|
||||||
|
|
||||||
|
int GetCharacterIndex() { return characterIndex; }
|
||||||
|
const char* GetHandle() { return handle; }
|
||||||
|
const char* GetAvatar() { return avatar; }
|
||||||
|
|
||||||
|
int GetAccountIndex() { return accountIndex; }
|
||||||
|
|
||||||
|
//location
|
||||||
|
int SetRoomIndex(int i) { return roomIndex = i; }
|
||||||
|
Vector2 SetOrigin(Vector2 v) { return origin = v; }
|
||||||
|
Vector2 SetMotion(Vector2 v) { return motion = v; }
|
||||||
|
|
||||||
|
int GetRoomIndex() { return roomIndex; }
|
||||||
|
Vector2 GetOrigin() { return origin; }
|
||||||
|
Vector2 GetMotion() { return motion; }
|
||||||
|
|
||||||
|
//gameplay
|
||||||
|
Statistics* GetStatistics() { return &stats; }
|
||||||
|
|
||||||
|
virtual void Serialize(void* buffer) override;
|
||||||
|
virtual void Deserialize(void* buffer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//identify the character
|
||||||
|
int characterIndex;
|
||||||
|
char handle[PACKET_STRING_SIZE+1];
|
||||||
|
char avatar[PACKET_STRING_SIZE+1];
|
||||||
|
|
||||||
|
//the owner
|
||||||
|
int accountIndex;
|
||||||
|
|
||||||
|
//location
|
||||||
|
int roomIndex;
|
||||||
|
Vector2 origin;
|
||||||
|
Vector2 motion;
|
||||||
|
|
||||||
|
//gameplay
|
||||||
|
Statistics stats;
|
||||||
|
|
||||||
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+16
-7
@@ -19,13 +19,22 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef SERIALIZEUTIL_HPP_
|
#include "client_packet.hpp"
|
||||||
#define SERIALIZEUTIL_HPP_
|
|
||||||
|
|
||||||
#include <cstring>
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
//NOTE: The strange assignments here used in order to move the void* parameter
|
void ClientPacket::Serialize(void* buffer) {
|
||||||
#define SERIALIZE(buffer, data, size) memcpy(buffer, data, size); buffer = reinterpret_cast<char*>(buffer) + size;
|
serializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
#define DESERIALIZE(buffer, data, size) memcpy(data, buffer, size); buffer = reinterpret_cast<char*>(buffer) + size;
|
|
||||||
|
|
||||||
#endif
|
serializeCopy(&buffer, &clientIndex, sizeof(int));
|
||||||
|
serializeCopy(&buffer, &accountIndex, sizeof(int));
|
||||||
|
serializeCopy(&buffer, username, PACKET_STRING_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientPacket::Deserialize(void* buffer) {
|
||||||
|
deserializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
deserializeCopy(&buffer, &clientIndex, sizeof(int));
|
||||||
|
deserializeCopy(&buffer, &accountIndex, sizeof(int));
|
||||||
|
deserializeCopy(&buffer, username, PACKET_STRING_SIZE);
|
||||||
|
}
|
||||||
+22
-2
@@ -24,10 +24,30 @@
|
|||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
struct ClientPacket : SerialPacketBase {
|
#include <cstring>
|
||||||
|
|
||||||
|
class ClientPacket : public SerialPacketBase {
|
||||||
|
public:
|
||||||
|
ClientPacket() {}
|
||||||
|
~ClientPacket() {}
|
||||||
|
|
||||||
|
//accessors & mutators
|
||||||
|
int SetClientIndex(int i) { return clientIndex = i; }
|
||||||
|
int SetAccountIndex(int i) { return accountIndex = i; }
|
||||||
|
const char* SetUsername(const char* s)
|
||||||
|
{ return strncpy(username, s, PACKET_STRING_SIZE); }
|
||||||
|
|
||||||
|
int GetClientIndex() { return clientIndex; }
|
||||||
|
int GetAccountIndex() { return accountIndex; }
|
||||||
|
const char* GetUsername() { return username; }
|
||||||
|
|
||||||
|
virtual void Serialize(void* buffer) override;
|
||||||
|
virtual void Deserialize(void* buffer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
int clientIndex;
|
int clientIndex;
|
||||||
int accountIndex;
|
int accountIndex;
|
||||||
char username[PACKET_STRING_SIZE];
|
char username[PACKET_STRING_SIZE+1];
|
||||||
// char password[PACKET_STRING_SIZE]; //hashed, not currently used
|
// char password[PACKET_STRING_SIZE]; //hashed, not currently used
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../../gameplay ../../map ../../utilities
|
INCLUDES+=. .. ../../gameplay ../../map ../../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "region_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void RegionPacket::Serialize(void* buffer) {
|
||||||
|
serializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//format
|
||||||
|
serializeCopy(&buffer, &roomIndex, sizeof(int));
|
||||||
|
serializeCopy(&buffer, &x, sizeof(int));
|
||||||
|
serializeCopy(&buffer, &y, sizeof(int));
|
||||||
|
|
||||||
|
if (type != SerialPacketType::REGION_CONTENT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//tiles
|
||||||
|
for (int i = 0; i < REGION_WIDTH; i++) {
|
||||||
|
for (int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
|
for (int k = 0; k < REGION_DEPTH; k++) {
|
||||||
|
*reinterpret_cast<Region::type_t*>(buffer) = region->GetTile(i, j, k);
|
||||||
|
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//solids
|
||||||
|
serializeCopy(&buffer, region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegionPacket::Deserialize(void* buffer) {
|
||||||
|
deserializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//format
|
||||||
|
deserializeCopy(&buffer, &roomIndex, sizeof(int));
|
||||||
|
deserializeCopy(&buffer, &x, sizeof(int));
|
||||||
|
deserializeCopy(&buffer, &y, sizeof(int));
|
||||||
|
|
||||||
|
if (type != SerialPacketType::REGION_CONTENT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//an object to work on
|
||||||
|
region = new Region(x, y);
|
||||||
|
|
||||||
|
//tiles
|
||||||
|
for (int i = 0; i < REGION_WIDTH; i++) {
|
||||||
|
for (int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
|
for (int k = 0; k < REGION_DEPTH; k++) {
|
||||||
|
region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
||||||
|
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//solids
|
||||||
|
deserializeCopy(&buffer, region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||||
|
}
|
||||||
+30
-1
@@ -26,7 +26,36 @@
|
|||||||
|
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
|
||||||
struct RegionPacket : SerialPacketBase {
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
//define the memory footprint for the region's members
|
||||||
|
constexpr int REGION_TILE_FOOTPRINT = sizeof(Region::type_t) * REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH;
|
||||||
|
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
||||||
|
constexpr int REGION_METADATA_FOOTPRINT = sizeof(int) * 3;
|
||||||
|
|
||||||
|
class RegionPacket : public SerialPacketBase {
|
||||||
|
public:
|
||||||
|
RegionPacket() {}
|
||||||
|
~RegionPacket() {}
|
||||||
|
|
||||||
|
//location
|
||||||
|
int SetRoomIndex(int i) { return roomIndex = i; }
|
||||||
|
int SetX(int i) { return x = i; }
|
||||||
|
int SetY(int i) { return y = i; }
|
||||||
|
|
||||||
|
int GetRoomIndex() { return roomIndex; }
|
||||||
|
int GetX() { return x; }
|
||||||
|
int GetY() { return y; }
|
||||||
|
|
||||||
|
//the region itself
|
||||||
|
Region* SetRegion(Region* r) { return region = r; }
|
||||||
|
Region* GetRegion() { return region; }
|
||||||
|
|
||||||
|
virtual void Serialize(void* buffer) override;
|
||||||
|
virtual void Deserialize(void* buffer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
//location/identify the region
|
//location/identify the region
|
||||||
int roomIndex;
|
int roomIndex;
|
||||||
int x, y;
|
int x, y;
|
||||||
+1
-11
@@ -19,16 +19,6 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef SERVERPACKET_HPP_
|
|
||||||
#define SERVERPACKET_HPP_
|
|
||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
struct ServerPacket : SerialPacketBase {
|
//NOTE: This is a sanity check
|
||||||
//identify the server
|
|
||||||
char name[PACKET_STRING_SIZE];
|
|
||||||
int playerCount;
|
|
||||||
int version;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+18
-11
@@ -22,25 +22,32 @@
|
|||||||
#ifndef SERIALPACKETBASE_HPP_
|
#ifndef SERIALPACKETBASE_HPP_
|
||||||
#define SERIALPACKETBASE_HPP_
|
#define SERIALPACKETBASE_HPP_
|
||||||
|
|
||||||
#ifndef SERIALPACKET_HPP_
|
|
||||||
#error Cannot include this file without 'serial_packet.hpp'
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "serial_packet_type.hpp"
|
#include "serial_packet_type.hpp"
|
||||||
|
|
||||||
#include "SDL/SDL_net.h"
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
constexpr int NETWORK_VERSION = 20140701;
|
//The packets use a char array for string storage
|
||||||
constexpr int PACKET_STRING_SIZE = 100;
|
constexpr int PACKET_STRING_SIZE = 100;
|
||||||
|
|
||||||
struct SerialPacketBase {
|
class SerialPacketBase {
|
||||||
//members
|
public:
|
||||||
|
SerialPacketType SetType(SerialPacketType t) { return type = t; }
|
||||||
|
SerialPacketType GetType() { return type; }
|
||||||
|
|
||||||
|
IPaddress GetAddress() { return srcAddress; }
|
||||||
|
IPaddress* GetAddressPtr() { return &srcAddress; }
|
||||||
|
|
||||||
|
SerialPacketBase() {};
|
||||||
|
virtual ~SerialPacketBase() {};
|
||||||
|
|
||||||
|
virtual void Serialize(void* buffer) = 0;
|
||||||
|
virtual void Deserialize(void* buffer) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class UDPNetworkUtility;
|
||||||
|
|
||||||
SerialPacketType type;
|
SerialPacketType type;
|
||||||
IPaddress srcAddress;
|
IPaddress srcAddress;
|
||||||
|
|
||||||
virtual ~SerialPacketBase() {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SerialPacketBase SerialPacket;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+12
-12
@@ -19,24 +19,24 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#include "serial.hpp"
|
#include "server_packet.hpp"
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
void serializeServer(ServerPacket* packet, void* buffer) {
|
void ServerPacket::Serialize(void* buffer) {
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
serializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
//identify the server
|
//identify the server
|
||||||
SERIALIZE(buffer, &packet->name, PACKET_STRING_SIZE);
|
serializeCopy(&buffer, name, PACKET_STRING_SIZE);
|
||||||
SERIALIZE(buffer, &packet->playerCount, sizeof(int));
|
serializeCopy(&buffer, &playerCount, sizeof(int));
|
||||||
SERIALIZE(buffer, &packet->version, sizeof(int));
|
serializeCopy(&buffer, &version, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserializeServer(ServerPacket* packet, void* buffer) {
|
void ServerPacket::Deserialize(void* buffer) {
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
deserializeCopy(&buffer, &type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
//identify the server
|
//identify the server
|
||||||
DESERIALIZE(buffer, &packet->name, PACKET_STRING_SIZE);
|
deserializeCopy(&buffer, name, PACKET_STRING_SIZE);
|
||||||
DESERIALIZE(buffer, &packet->playerCount, sizeof(int));
|
deserializeCopy(&buffer, &playerCount, sizeof(int));
|
||||||
DESERIALIZE(buffer, &packet->version, sizeof(int));
|
deserializeCopy(&buffer, &version, sizeof(int));
|
||||||
}
|
}
|
||||||
+22
-15
@@ -19,28 +19,35 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef COMBATPACKET_HPP_
|
#ifndef SERVERPACKET_HPP_
|
||||||
#define COMBATPACKET_HPP_
|
#define SERVERPACKET_HPP_
|
||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
#include "combat_defines.hpp"
|
#include <cstring>
|
||||||
|
|
||||||
struct CombatPacket : SerialPacketBase {
|
class ServerPacket : public SerialPacketBase {
|
||||||
//identify the combat instance
|
public:
|
||||||
int combatIndex;
|
ServerPacket() {}
|
||||||
int difficulty;
|
~ServerPacket() {}
|
||||||
TerrainType terrainType;
|
|
||||||
|
|
||||||
//combatants
|
const char* SetName(const char* s)
|
||||||
int characterArray[COMBAT_MAX_CHARACTERS];
|
{ return strncpy(name, s, PACKET_STRING_SIZE); }
|
||||||
int enemyArray[COMBAT_MAX_ENEMIES];
|
int SetPlayerCount(int i) { return playerCount = i; }
|
||||||
|
int SetVersion(int i) { return version = i; }
|
||||||
|
|
||||||
//location
|
const char* GetName() { return name; }
|
||||||
int mapIndex;
|
int GetPlayerCount() { return playerCount; }
|
||||||
Vector2 origin;
|
int GetVersion() { return version; }
|
||||||
|
|
||||||
//TODO: gameplay components: rewards
|
virtual void Serialize(void* buffer) override;
|
||||||
|
virtual void Deserialize(void* buffer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//identify the server
|
||||||
|
char name[PACKET_STRING_SIZE+1];
|
||||||
|
int playerCount;
|
||||||
|
int version;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#config
|
|
||||||
INCLUDES+=. ../packet ../../gameplay ../../map ../../utilities
|
|
||||||
LIBS+=
|
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
|
||||||
CXXSRC=$(wildcard *.cpp)
|
|
||||||
|
|
||||||
#objects
|
|
||||||
OBJDIR=obj
|
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
|
||||||
|
|
||||||
#output
|
|
||||||
OUTDIR=../../..
|
|
||||||
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
|
||||||
|
|
||||||
#targets
|
|
||||||
all: $(OBJ) $(OUT)
|
|
||||||
ar -crs $(OUT) $(OBJ)
|
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUT): | $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR):
|
|
||||||
mkdir $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUTDIR):
|
|
||||||
mkdir $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.cpp
|
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) *.o *.a *.exe
|
|
||||||
|
|
||||||
rebuild: clean all
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
|
||||||
|
|
||||||
//simple type functions
|
|
||||||
void serializeType(SerialPacketBase* packet, void* buffer) {
|
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeType(SerialPacketBase* packet, void* buffer) {
|
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
}
|
|
||||||
|
|
||||||
//main switch functions
|
|
||||||
void serializePacket(SerialPacketBase* packet, void* buffer) {
|
|
||||||
switch(packet->type) {
|
|
||||||
//no extra data
|
|
||||||
case SerialPacketType::NONE:
|
|
||||||
case SerialPacketType::PING:
|
|
||||||
case SerialPacketType::PONG:
|
|
||||||
case SerialPacketType::BROADCAST_REQUEST:
|
|
||||||
|
|
||||||
//all rejections
|
|
||||||
case SerialPacketType::JOIN_REJECTION:
|
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
|
||||||
case SerialPacketType::ENEMY_REJECTION:
|
|
||||||
case SerialPacketType::COMBAT_REJECTION:
|
|
||||||
|
|
||||||
serializeType(packet, buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//character info
|
|
||||||
case SerialPacketType::CHARACTER_NEW:
|
|
||||||
case SerialPacketType::CHARACTER_DELETE:
|
|
||||||
case SerialPacketType::CHARACTER_UPDATE:
|
|
||||||
case SerialPacketType::CHARACTER_STATS_REQUEST:
|
|
||||||
case SerialPacketType::CHARACTER_STATS_RESPONSE:
|
|
||||||
serializeCharacter(static_cast<CharacterPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//client info
|
|
||||||
case SerialPacketType::JOIN_REQUEST:
|
|
||||||
case SerialPacketType::JOIN_RESPONSE:
|
|
||||||
case SerialPacketType::SYNCHRONIZE:
|
|
||||||
case SerialPacketType::DISCONNECT:
|
|
||||||
case SerialPacketType::SHUTDOWN:
|
|
||||||
serializeClient(static_cast<ClientPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//combat info
|
|
||||||
case SerialPacketType::COMBAT_NEW:
|
|
||||||
case SerialPacketType::COMBAT_DELETE:
|
|
||||||
case SerialPacketType::COMBAT_UPDATE:
|
|
||||||
|
|
||||||
case SerialPacketType::COMBAT_ENTER_REQUEST:
|
|
||||||
case SerialPacketType::COMBAT_ENTER_RESPONSE:
|
|
||||||
case SerialPacketType::COMBAT_EXIT_REQUEST:
|
|
||||||
case SerialPacketType::COMBAT_EXIT_RESPONSE:
|
|
||||||
|
|
||||||
serializeCombat(static_cast<CombatPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//enemy info
|
|
||||||
case SerialPacketType::ENEMY_NEW:
|
|
||||||
case SerialPacketType::ENEMY_DELETE:
|
|
||||||
case SerialPacketType::ENEMY_UPDATE:
|
|
||||||
case SerialPacketType::ENEMY_STATS_REQUEST:
|
|
||||||
case SerialPacketType::ENEMY_STATS_RESPONSE:
|
|
||||||
serializeEnemy(static_cast<EnemyPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//region info
|
|
||||||
case SerialPacketType::REGION_REQUEST:
|
|
||||||
serializeRegionFormat(static_cast<RegionPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SerialPacketType::REGION_CONTENT:
|
|
||||||
serializeRegionContent(static_cast<RegionPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//server info
|
|
||||||
case SerialPacketType::BROADCAST_RESPONSE:
|
|
||||||
serializeServer(static_cast<ServerPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializePacket(SerialPacketBase* packet, void* buffer) {
|
|
||||||
//find the type, so that you can actually deserialize the packet!
|
|
||||||
deserializeType(packet, buffer);
|
|
||||||
switch(packet->type) {
|
|
||||||
//no extra data
|
|
||||||
case SerialPacketType::NONE:
|
|
||||||
case SerialPacketType::PING:
|
|
||||||
case SerialPacketType::PONG:
|
|
||||||
case SerialPacketType::BROADCAST_REQUEST:
|
|
||||||
|
|
||||||
//all rejections
|
|
||||||
case SerialPacketType::JOIN_REJECTION:
|
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
|
||||||
case SerialPacketType::ENEMY_REJECTION:
|
|
||||||
case SerialPacketType::COMBAT_REJECTION:
|
|
||||||
|
|
||||||
//NOTHING
|
|
||||||
break;
|
|
||||||
|
|
||||||
//character info
|
|
||||||
case SerialPacketType::CHARACTER_NEW:
|
|
||||||
case SerialPacketType::CHARACTER_DELETE:
|
|
||||||
case SerialPacketType::CHARACTER_UPDATE:
|
|
||||||
case SerialPacketType::CHARACTER_STATS_REQUEST:
|
|
||||||
case SerialPacketType::CHARACTER_STATS_RESPONSE:
|
|
||||||
deserializeCharacter(static_cast<CharacterPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//client info
|
|
||||||
case SerialPacketType::JOIN_REQUEST:
|
|
||||||
case SerialPacketType::JOIN_RESPONSE:
|
|
||||||
case SerialPacketType::SYNCHRONIZE:
|
|
||||||
case SerialPacketType::DISCONNECT:
|
|
||||||
case SerialPacketType::SHUTDOWN:
|
|
||||||
deserializeClient(static_cast<ClientPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//combat info
|
|
||||||
case SerialPacketType::COMBAT_NEW:
|
|
||||||
case SerialPacketType::COMBAT_DELETE:
|
|
||||||
case SerialPacketType::COMBAT_UPDATE:
|
|
||||||
|
|
||||||
case SerialPacketType::COMBAT_ENTER_REQUEST:
|
|
||||||
case SerialPacketType::COMBAT_ENTER_RESPONSE:
|
|
||||||
case SerialPacketType::COMBAT_EXIT_REQUEST:
|
|
||||||
case SerialPacketType::COMBAT_EXIT_RESPONSE:
|
|
||||||
|
|
||||||
serializeCombat(static_cast<CombatPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//enemy info
|
|
||||||
case SerialPacketType::ENEMY_NEW:
|
|
||||||
case SerialPacketType::ENEMY_DELETE:
|
|
||||||
case SerialPacketType::ENEMY_UPDATE:
|
|
||||||
case SerialPacketType::ENEMY_STATS_REQUEST:
|
|
||||||
case SerialPacketType::ENEMY_STATS_RESPONSE:
|
|
||||||
serializeEnemy(static_cast<EnemyPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//region info
|
|
||||||
case SerialPacketType::REGION_REQUEST:
|
|
||||||
deserializeRegionFormat(static_cast<RegionPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SerialPacketType::REGION_CONTENT:
|
|
||||||
deserializeRegionContent(static_cast<RegionPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//server info
|
|
||||||
case SerialPacketType::BROADCAST_RESPONSE:
|
|
||||||
deserializeServer(static_cast<ServerPacket*>(packet), buffer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#ifndef SERIALIZE_HPP_
|
|
||||||
#define SERIALIZE_HPP_
|
|
||||||
|
|
||||||
#include "serial_packet.hpp"
|
|
||||||
|
|
||||||
#include "region.hpp"
|
|
||||||
#include "statistics.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
//Primary interface functions
|
|
||||||
void serializePacket(SerialPacketBase*, void* dest);
|
|
||||||
void deserializePacket(SerialPacketBase*, void* src);
|
|
||||||
|
|
||||||
void serializeType(SerialPacketBase*, void*);
|
|
||||||
void deserializeType(SerialPacketBase*, void*);
|
|
||||||
|
|
||||||
//utility functions, exposed
|
|
||||||
void serializeCharacter(CharacterPacket*, void*);
|
|
||||||
void serializeClient(ClientPacket*, void*);
|
|
||||||
void serializeCombat(CombatPacket*, void*);
|
|
||||||
void serializeEnemy(EnemyPacket*, void*);
|
|
||||||
void serializeRegionFormat(RegionPacket*, void*);
|
|
||||||
void serializeRegionContent(RegionPacket*, void*);
|
|
||||||
void serializeServer(ServerPacket*, void*);
|
|
||||||
void serializeStatistics(Statistics*, void*);
|
|
||||||
|
|
||||||
void deserializeCharacter(CharacterPacket*, void*);
|
|
||||||
void deserializeClient(ClientPacket*, void*);
|
|
||||||
void deserializeCombat(CombatPacket*, void*);
|
|
||||||
void deserializeEnemy(EnemyPacket*, void*);
|
|
||||||
void deserializeRegionFormat(RegionPacket*, void*);
|
|
||||||
void deserializeRegionContent(RegionPacket*, void*);
|
|
||||||
void deserializeServer(ServerPacket*, void*);
|
|
||||||
void deserializeStatistics(Statistics*, void*);
|
|
||||||
|
|
||||||
/* DOCS: PACKET_BUFFER_SIZE is the memory required to store serialized data
|
|
||||||
* DOCS: SerialPacketType::REGION_CONTENT is currently the largest packet type
|
|
||||||
* Serialized packet structure:
|
|
||||||
* SerialPacketType
|
|
||||||
* room index
|
|
||||||
* X & Y position
|
|
||||||
* tile data (3 layers)
|
|
||||||
* solid data (bitset)
|
|
||||||
* The constants declared here are used for networking ONLY
|
|
||||||
*/
|
|
||||||
|
|
||||||
constexpr int REGION_TILE_FOOTPRINT = sizeof(Region::type_t) * REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH;
|
|
||||||
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
|
||||||
constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_TILE_FOOTPRINT + REGION_SOLID_FOOTPRINT;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
|
||||||
|
|
||||||
void serializeCharacter(CharacterPacket* packet, void* buffer) {
|
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the character
|
|
||||||
SERIALIZE(buffer, &packet->characterIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
|
||||||
SERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
|
||||||
|
|
||||||
//the owner
|
|
||||||
SERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
|
||||||
|
|
||||||
//location
|
|
||||||
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
|
||||||
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
|
||||||
SERIALIZE(buffer, &packet->motion.x, sizeof(double));
|
|
||||||
SERIALIZE(buffer, &packet->motion.y, sizeof(double));
|
|
||||||
|
|
||||||
//stats structure
|
|
||||||
serializeStatistics(&packet->stats, buffer);
|
|
||||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeCharacter(CharacterPacket* packet, void* buffer) {
|
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the character
|
|
||||||
DESERIALIZE(buffer, &packet->characterIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
|
||||||
DESERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
|
||||||
|
|
||||||
//the owner
|
|
||||||
DESERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
|
||||||
|
|
||||||
//location
|
|
||||||
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
|
||||||
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
|
||||||
DESERIALIZE(buffer, &packet->motion.x, sizeof(double));
|
|
||||||
DESERIALIZE(buffer, &packet->motion.y, sizeof(double));
|
|
||||||
|
|
||||||
//stats structure
|
|
||||||
deserializeStatistics(&packet->stats, buffer);
|
|
||||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
|
||||||
|
|
||||||
void serializeClient(ClientPacket* packet, void* buffer) {
|
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
SERIALIZE(buffer, &packet->clientIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
|
|
||||||
// SERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeClient(ClientPacket* packet, void* buffer) {
|
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
DESERIALIZE(buffer, &packet->clientIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
|
|
||||||
// DESERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
|
||||||
|
|
||||||
void serializeCombat(CombatPacket* packet, void* buffer) {
|
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the combat instance
|
|
||||||
SERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
|
|
||||||
|
|
||||||
//combatants
|
|
||||||
SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
|
||||||
SERIALIZE(buffer, &packet->enemyArray, sizeof(int) * COMBAT_MAX_ENEMIES);
|
|
||||||
|
|
||||||
//location
|
|
||||||
SERIALIZE(buffer, &packet->mapIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
|
||||||
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
|
||||||
|
|
||||||
//TODO: gameplay components: rewards
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeCombat(CombatPacket* packet, void* buffer) {
|
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the combat instance
|
|
||||||
DESERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
|
|
||||||
|
|
||||||
//combatants
|
|
||||||
DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
|
||||||
DESERIALIZE(buffer, &packet->enemyArray, sizeof(int) * COMBAT_MAX_ENEMIES);
|
|
||||||
|
|
||||||
//location
|
|
||||||
DESERIALIZE(buffer, &packet->mapIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
|
||||||
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
|
||||||
|
|
||||||
//TODO: gameplay components: rewards
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
|
||||||
|
|
||||||
void serializeEnemy(EnemyPacket* packet, void* buffer) {
|
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the enemy
|
|
||||||
SERIALIZE(buffer, &packet->enemyIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
|
||||||
SERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
|
||||||
|
|
||||||
//gameplay
|
|
||||||
|
|
||||||
//stats structure
|
|
||||||
serializeStatistics(&packet->stats, buffer);
|
|
||||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeEnemy(EnemyPacket* packet, void* buffer) {
|
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the enemy
|
|
||||||
DESERIALIZE(buffer, &packet->enemyIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
|
||||||
DESERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
|
||||||
|
|
||||||
//stats structure
|
|
||||||
deserializeStatistics(&packet->stats, buffer);
|
|
||||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
|
||||||
|
|
||||||
void serializeRegionFormat(RegionPacket* packet, void* buffer) {
|
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//format
|
|
||||||
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->x, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->y, sizeof(int));
|
|
||||||
}
|
|
||||||
|
|
||||||
void serializeRegionContent(RegionPacket* packet, void* buffer) {
|
|
||||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//format
|
|
||||||
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->x, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &packet->y, sizeof(int));
|
|
||||||
|
|
||||||
//tiles
|
|
||||||
for (int i = 0; i < REGION_WIDTH; i++) {
|
|
||||||
for (int j = 0; j < REGION_HEIGHT; j++) {
|
|
||||||
for (int k = 0; k < REGION_DEPTH; k++) {
|
|
||||||
*reinterpret_cast<Region::type_t*>(buffer) = packet->region->GetTile(i, j, k);
|
|
||||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//solids
|
|
||||||
SERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
|
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//format
|
|
||||||
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->x, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->y, sizeof(int));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeRegionContent(RegionPacket* packet, void* buffer) {
|
|
||||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//format
|
|
||||||
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->x, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &packet->y, sizeof(int));
|
|
||||||
|
|
||||||
//an object to work on
|
|
||||||
packet->region = new Region(packet->x, packet->y);
|
|
||||||
|
|
||||||
//tiles
|
|
||||||
for (int i = 0; i < REGION_WIDTH; i++) {
|
|
||||||
for (int j = 0; j < REGION_HEIGHT; j++) {
|
|
||||||
for (int k = 0; k < REGION_DEPTH; k++) {
|
|
||||||
packet->region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
|
||||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//solids
|
|
||||||
DESERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
#include "serial_util.hpp"
|
|
||||||
|
|
||||||
void serializeStatistics(Statistics* stats, void* buffer) {
|
|
||||||
//integers
|
|
||||||
SERIALIZE(buffer, &stats->level, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->exp, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->maxHP, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->health, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->maxMP, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->mana, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->attack, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->defence, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->intelligence, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->resistance, sizeof(int));
|
|
||||||
SERIALIZE(buffer, &stats->speed, sizeof(int));
|
|
||||||
|
|
||||||
//floats
|
|
||||||
SERIALIZE(buffer, &stats->accuracy, sizeof(float));
|
|
||||||
SERIALIZE(buffer, &stats->evasion, sizeof(float));
|
|
||||||
SERIALIZE(buffer, &stats->luck, sizeof(float));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void deserializeStatistics(Statistics* stats, void* buffer) {
|
|
||||||
//integers
|
|
||||||
DESERIALIZE(buffer, &stats->level, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->exp, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->maxHP, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->health, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->maxMP, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->mana, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->attack, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->defence, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->intelligence, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->resistance, sizeof(int));
|
|
||||||
DESERIALIZE(buffer, &stats->speed, sizeof(int));
|
|
||||||
|
|
||||||
//floats
|
|
||||||
DESERIALIZE(buffer, &stats->accuracy, sizeof(float));
|
|
||||||
DESERIALIZE(buffer, &stats->evasion, sizeof(float));
|
|
||||||
DESERIALIZE(buffer, &stats->luck, sizeof(float));
|
|
||||||
}
|
|
||||||
@@ -22,23 +22,46 @@
|
|||||||
#ifndef SERIALPACKET_HPP_
|
#ifndef SERIALPACKET_HPP_
|
||||||
#define SERIALPACKET_HPP_
|
#define SERIALPACKET_HPP_
|
||||||
|
|
||||||
|
/* DOCS: serial_packet.hpp is used to define a number of required constants.
|
||||||
|
* These are used extensively by the server and client
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
#include "character_packet.hpp"
|
#include "character_packet.hpp"
|
||||||
#include "client_packet.hpp"
|
#include "client_packet.hpp"
|
||||||
#include "combat_packet.hpp"
|
|
||||||
#include "enemy_packet.hpp"
|
|
||||||
#include "region_packet.hpp"
|
#include "region_packet.hpp"
|
||||||
#include "server_packet.hpp"
|
#include "server_packet.hpp"
|
||||||
|
|
||||||
//NOTE: SerialPacket is defined in serial_packet_base.hpp
|
//SerialPacketBase is defined in serial_packet_base.hpp
|
||||||
|
typedef SerialPacketBase SerialPacket;
|
||||||
|
|
||||||
union MaxPacket {
|
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
|
||||||
|
constexpr int NETWORK_VERSION = 20140831;
|
||||||
|
|
||||||
|
//_MaxPacket Should not be used
|
||||||
|
union _MaxPacket {
|
||||||
CharacterPacket a;
|
CharacterPacket a;
|
||||||
ClientPacket b;
|
ClientPacket b;
|
||||||
CombatPacket c;
|
RegionPacket c;
|
||||||
EnemyPacket d;
|
ServerPacket d;
|
||||||
RegionPacket e;
|
|
||||||
ServerPacket f;
|
|
||||||
};
|
};
|
||||||
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
|
||||||
|
constexpr int MAX_PACKET_SIZE = sizeof(_MaxPacket);
|
||||||
|
|
||||||
|
/* DOCS: PACKET_BUFFER_SIZE is the memory required to store serialized data
|
||||||
|
* DOCS: SerialPacketType::REGION_CONTENT is currently the largest packet type
|
||||||
|
* Serialized RegionPacket structure:
|
||||||
|
* SerialPacketType
|
||||||
|
* room index (int)
|
||||||
|
* X & Y position (int)
|
||||||
|
* tile data (3 layers)
|
||||||
|
* solid data (bitset)
|
||||||
|
*/
|
||||||
|
|
||||||
|
constexpr int PACKET_BUFFER_SIZE =
|
||||||
|
sizeof(SerialPacketType) +
|
||||||
|
REGION_METADATA_FOOTPRINT +
|
||||||
|
REGION_TILE_FOOTPRINT +
|
||||||
|
REGION_SOLID_FOOTPRINT;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef SERIALPACKETTYPE_HPP_
|
||||||
|
#define SERIALPACKETTYPE_HPP_
|
||||||
|
|
||||||
|
/* DOCS: The headers indicate what packet type is used for each message
|
||||||
|
* different messages under the same header will carry different amounts of
|
||||||
|
* valid data, but it will still be carried in that packet's format.
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum class SerialPacketType {
|
||||||
|
//default: there is something wrong
|
||||||
|
NONE = 0,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//ServerPacket
|
||||||
|
// name, player count, version
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//heartbeat
|
||||||
|
PING,
|
||||||
|
PONG,
|
||||||
|
|
||||||
|
//Used for finding available servers
|
||||||
|
BROADCAST_REQUEST,
|
||||||
|
BROADCAST_RESPONSE,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//ClientPacket
|
||||||
|
// client index, account index, character index
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//Connecting to a server as a client
|
||||||
|
JOIN_REQUEST,
|
||||||
|
JOIN_RESPONSE,
|
||||||
|
JOIN_REJECTION,
|
||||||
|
|
||||||
|
//client requests all information from the server
|
||||||
|
SYNCHRONIZE,
|
||||||
|
|
||||||
|
//disconnect from the server
|
||||||
|
DISCONNECT,
|
||||||
|
|
||||||
|
//shut down the server
|
||||||
|
SHUTDOWN,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//RegionPacket
|
||||||
|
// room index, x, y, raw data
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//map data
|
||||||
|
REGION_REQUEST,
|
||||||
|
REGION_CONTENT,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//CharacterPacket
|
||||||
|
// handle, avatar, character index, account index,
|
||||||
|
// room index, origin, motion
|
||||||
|
// statistics
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//controlling characters
|
||||||
|
CHARACTER_NEW,
|
||||||
|
CHARACTER_DELETE,
|
||||||
|
CHARACTER_UPDATE,
|
||||||
|
|
||||||
|
//authentication, character index => character stats
|
||||||
|
CHARACTER_STATS_REQUEST,
|
||||||
|
CHARACTER_STATS_RESPONSE,
|
||||||
|
|
||||||
|
//reject a character request
|
||||||
|
CHARACTER_REJECTION,
|
||||||
|
|
||||||
|
//not used
|
||||||
|
LAST
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
#include "serial_packet_type.hpp"
|
||||||
|
|
||||||
|
#include "server_packet.hpp"
|
||||||
|
#include "client_packet.hpp"
|
||||||
|
#include "region_packet.hpp"
|
||||||
|
#include "character_packet.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
void serializePacket(SerialPacketBase* packet, void* data) {
|
||||||
|
switch(packet->GetType()) {
|
||||||
|
case SerialPacketType::PING:
|
||||||
|
case SerialPacketType::PONG:
|
||||||
|
case SerialPacketType::BROADCAST_REQUEST:
|
||||||
|
case SerialPacketType::BROADCAST_RESPONSE:
|
||||||
|
static_cast<ServerPacket*>(packet)->Serialize(data);
|
||||||
|
break;
|
||||||
|
case SerialPacketType::JOIN_REQUEST:
|
||||||
|
case SerialPacketType::JOIN_RESPONSE:
|
||||||
|
case SerialPacketType::JOIN_REJECTION:
|
||||||
|
case SerialPacketType::SYNCHRONIZE:
|
||||||
|
case SerialPacketType::DISCONNECT:
|
||||||
|
case SerialPacketType::SHUTDOWN:
|
||||||
|
static_cast<ClientPacket*>(packet)->Serialize(data);
|
||||||
|
break;
|
||||||
|
case SerialPacketType::REGION_REQUEST:
|
||||||
|
case SerialPacketType::REGION_CONTENT:
|
||||||
|
static_cast<RegionPacket*>(packet)->Serialize(data);
|
||||||
|
break;
|
||||||
|
case SerialPacketType::CHARACTER_NEW:
|
||||||
|
case SerialPacketType::CHARACTER_DELETE:
|
||||||
|
case SerialPacketType::CHARACTER_UPDATE:
|
||||||
|
case SerialPacketType::CHARACTER_STATS_REQUEST:
|
||||||
|
case SerialPacketType::CHARACTER_STATS_RESPONSE:
|
||||||
|
case SerialPacketType::CHARACTER_REJECTION:
|
||||||
|
static_cast<CharacterPacket*>(packet)->Serialize(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializePacket(SerialPacketBase* packet, void* data) {
|
||||||
|
//get the type
|
||||||
|
SerialPacketType type;
|
||||||
|
memcpy(&type, data, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case SerialPacketType::PING:
|
||||||
|
case SerialPacketType::PONG:
|
||||||
|
case SerialPacketType::BROADCAST_REQUEST:
|
||||||
|
case SerialPacketType::BROADCAST_RESPONSE:
|
||||||
|
static_cast<ServerPacket*>(packet)->Deserialize(data);
|
||||||
|
break;
|
||||||
|
case SerialPacketType::JOIN_REQUEST:
|
||||||
|
case SerialPacketType::JOIN_RESPONSE:
|
||||||
|
case SerialPacketType::JOIN_REJECTION:
|
||||||
|
case SerialPacketType::SYNCHRONIZE:
|
||||||
|
case SerialPacketType::DISCONNECT:
|
||||||
|
case SerialPacketType::SHUTDOWN:
|
||||||
|
static_cast<ClientPacket*>(packet)->Deserialize(data);
|
||||||
|
break;
|
||||||
|
case SerialPacketType::REGION_REQUEST:
|
||||||
|
case SerialPacketType::REGION_CONTENT:
|
||||||
|
static_cast<RegionPacket*>(packet)->Deserialize(data);
|
||||||
|
break;
|
||||||
|
case SerialPacketType::CHARACTER_NEW:
|
||||||
|
case SerialPacketType::CHARACTER_DELETE:
|
||||||
|
case SerialPacketType::CHARACTER_UPDATE:
|
||||||
|
case SerialPacketType::CHARACTER_STATS_REQUEST:
|
||||||
|
case SerialPacketType::CHARACTER_STATS_RESPONSE:
|
||||||
|
case SerialPacketType::CHARACTER_REJECTION:
|
||||||
|
static_cast<CharacterPacket*>(packet)->Deserialize(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void serializeCopy(void** bufferHead, void* data, int size) {
|
||||||
|
memcpy(*bufferHead, data, size);
|
||||||
|
(*bufferHead) = static_cast<void*>(static_cast<char*>(*bufferHead) + size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeCopy(void** bufferHead, void* data, int size) {
|
||||||
|
memcpy(data, *bufferHead, size);
|
||||||
|
(*bufferHead) = static_cast<void*>(static_cast<char*>(*bufferHead) + size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void serializeCopyStatistics(void** bufferHead, Statistics* stats) {
|
||||||
|
//integers
|
||||||
|
serializeCopy(bufferHead, &stats->level, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->exp, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->maxHP, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->health, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->maxMP, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->mana, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->attack, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->defence, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->intelligence, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->resistance, sizeof(int));
|
||||||
|
serializeCopy(bufferHead, &stats->speed, sizeof(int));
|
||||||
|
|
||||||
|
//floats
|
||||||
|
serializeCopy(bufferHead, &stats->accuracy, sizeof(float));
|
||||||
|
serializeCopy(bufferHead, &stats->evasion, sizeof(float));
|
||||||
|
serializeCopy(bufferHead, &stats->luck, sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeCopyStatistics(void** bufferHead, Statistics* stats) {
|
||||||
|
//integers
|
||||||
|
deserializeCopy(bufferHead, &stats->level, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->exp, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->maxHP, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->health, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->maxMP, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->mana, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->attack, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->defence, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->intelligence, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->resistance, sizeof(int));
|
||||||
|
deserializeCopy(bufferHead, &stats->speed, sizeof(int));
|
||||||
|
|
||||||
|
//floats
|
||||||
|
deserializeCopy(bufferHead, &stats->accuracy, sizeof(float));
|
||||||
|
deserializeCopy(bufferHead, &stats->evasion, sizeof(float));
|
||||||
|
deserializeCopy(bufferHead, &stats->luck, sizeof(float));
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013, 2014
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,32 +19,24 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef CHARACTERPACKET_HPP_
|
#ifndef SERIALIZEUTILITY_HPP_
|
||||||
#define CHARACTERPACKET_HPP_
|
#define SERIALIZEUTILITY_HPP_
|
||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
#include "vector2.hpp"
|
|
||||||
#include "statistics.hpp"
|
#include "statistics.hpp"
|
||||||
|
|
||||||
struct CharacterPacket : SerialPacketBase {
|
//NOTE: The naming conventions here are fucking terrible
|
||||||
//identify the character
|
|
||||||
int characterIndex;
|
|
||||||
char handle[PACKET_STRING_SIZE];
|
|
||||||
char avatar[PACKET_STRING_SIZE];
|
|
||||||
|
|
||||||
//the owner
|
//BUGFIX: There's really no way to escape this :(
|
||||||
int accountIndex;
|
void serializePacket(SerialPacketBase* packet, void* data);
|
||||||
|
void deserializePacket(SerialPacketBase* packet, void* data);
|
||||||
|
|
||||||
//location
|
//raw memcpy
|
||||||
int roomIndex;
|
void serializeCopy(void** bufferHead, void* data, int size);
|
||||||
Vector2 origin;
|
void deserializeCopy(void** bufferHead, void* data, int size);
|
||||||
Vector2 motion;
|
|
||||||
|
|
||||||
//gameplay
|
void serializeCopyStatistics(void** bufferHead, Statistics* stats);
|
||||||
Statistics stats;
|
void deserializeCopyStatistics(void** bufferHead, Statistics* stats);
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
#include "serial.hpp"
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -213,8 +213,11 @@ int UDPNetworkUtility::SendToAllChannels(SerialPacket* serialPacket) {
|
|||||||
int UDPNetworkUtility::Receive(SerialPacket* serialPacket) {
|
int UDPNetworkUtility::Receive(SerialPacket* serialPacket) {
|
||||||
memset(packet->data, 0, packet->maxlen);
|
memset(packet->data, 0, packet->maxlen);
|
||||||
int ret = SDLNet_UDP_Recv(socket, packet);
|
int ret = SDLNet_UDP_Recv(socket, packet);
|
||||||
deserializePacket(serialPacket, packet->data);
|
if (ret > 0) {
|
||||||
serialPacket->srcAddress = packet->address;
|
//BUG: This simply fails
|
||||||
|
deserializePacket(serialPacket, packet->data);
|
||||||
|
serialPacket->srcAddress = packet->address;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
throw(std::runtime_error("Unknown network error occured"));
|
throw(std::runtime_error("Unknown network error occured"));
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. accounts characters rooms ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
INCLUDES+=. accounts characters rooms ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities
|
||||||
LIBS+=server.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
LIBS+=server.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
//for PACKET_BUFFER_SIZE
|
#include "serial_packet.hpp"
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
//utility functions
|
//utility functions
|
||||||
#include "sql_utility.hpp"
|
#include "sql_utility.hpp"
|
||||||
@@ -179,7 +178,7 @@ void ServerApplication::Quit() {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
|
void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
|
||||||
switch(argPacket->type) {
|
switch(argPacket->GetType()) {
|
||||||
//basic connections
|
//basic connections
|
||||||
case SerialPacketType::BROADCAST_REQUEST:
|
case SerialPacketType::BROADCAST_REQUEST:
|
||||||
HandleBroadcastRequest(static_cast<SerialPacket*>(argPacket));
|
HandleBroadcastRequest(static_cast<SerialPacket*>(argPacket));
|
||||||
@@ -225,7 +224,7 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
//handle errors
|
//handle errors
|
||||||
default: {
|
default: {
|
||||||
std::string msg = "Unknown SerialPacketType encountered in the server: ";
|
std::string msg = "Unknown SerialPacketType encountered in the server: ";
|
||||||
msg += to_string_custom(static_cast<int>(argPacket->type));
|
msg += to_string_custom(static_cast<int>(argPacket->GetType()));
|
||||||
throw(std::runtime_error(msg));
|
throw(std::runtime_error(msg));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
+43
-43
@@ -31,22 +31,22 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket* const argPacket) {
|
|||||||
//send the server's data
|
//send the server's data
|
||||||
ServerPacket newPacket;
|
ServerPacket newPacket;
|
||||||
|
|
||||||
newPacket.type = SerialPacketType::BROADCAST_RESPONSE;
|
newPacket.SetType(SerialPacketType::BROADCAST_RESPONSE);
|
||||||
strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE);
|
newPacket.SetName(config["server.name"].c_str());
|
||||||
newPacket.playerCount = characterMgr.GetContainer()->size();
|
newPacket.SetPlayerCount(characterMgr.GetContainer()->size());
|
||||||
newPacket.version = NETWORK_VERSION;
|
newPacket.SetVersion(NETWORK_VERSION);
|
||||||
|
|
||||||
network.SendTo(&argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(argPacket->GetAddressPtr(), static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
||||||
//create the new client
|
//create the new client
|
||||||
ClientData newClient;
|
ClientData newClient;
|
||||||
newClient.address = argPacket->srcAddress;
|
newClient.address = argPacket->GetAddress();
|
||||||
|
|
||||||
//load the user account
|
//load the user account
|
||||||
//TODO: handle passwords
|
//TODO: handle passwords
|
||||||
int accountIndex = accountMgr.LoadAccount(argPacket->username, clientIndex);
|
int accountIndex = accountMgr.LoadAccount(argPacket->GetUsername(), clientIndex);
|
||||||
if (accountIndex < 0) {
|
if (accountIndex < 0) {
|
||||||
//TODO: send rejection packet
|
//TODO: send rejection packet
|
||||||
std::cerr << "Error: Account already loaded: " << accountIndex << std::endl;
|
std::cerr << "Error: Account already loaded: " << accountIndex << std::endl;
|
||||||
@@ -55,9 +55,9 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
|||||||
|
|
||||||
//send the client their info
|
//send the client their info
|
||||||
ClientPacket newPacket;
|
ClientPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::JOIN_RESPONSE;
|
newPacket.SetType(SerialPacketType::JOIN_RESPONSE);
|
||||||
newPacket.clientIndex = clientIndex;
|
newPacket.SetClientIndex(clientIndex);
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.SetAccountIndex(accountIndex);
|
||||||
|
|
||||||
network.SendTo(&newClient.address, static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(&newClient.address, static_cast<SerialPacket*>(&newPacket));
|
||||||
|
|
||||||
@@ -80,14 +80,14 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
|||||||
|
|
||||||
//forward to the specified client
|
//forward to the specified client
|
||||||
network.SendTo(
|
network.SendTo(
|
||||||
&clientMap[ accountMgr.GetAccount(argPacket->accountIndex)->GetClientIndex() ].address,
|
&clientMap[ accountMgr.GetAccount(argPacket->GetAccountIndex())->GetClientIndex() ].address,
|
||||||
static_cast<SerialPacket*>(argPacket)
|
static_cast<SerialPacket*>(argPacket)
|
||||||
);
|
);
|
||||||
|
|
||||||
//save and unload this account's characters
|
//save and unload this account's characters
|
||||||
//pump the unload message to all remaining clients
|
//pump the unload message to all remaining clients
|
||||||
characterMgr.UnloadCharacterIf([&](std::map<int, CharacterData>::iterator it) -> bool {
|
characterMgr.UnloadCharacterIf([&](std::map<int, CharacterData>::iterator it) -> bool {
|
||||||
if (argPacket->accountIndex == it->second.GetOwner()) {
|
if (argPacket->GetAccountIndex() == it->second.GetOwner()) {
|
||||||
PumpCharacterUnload(it->first);
|
PumpCharacterUnload(it->first);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -95,8 +95,8 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//erase the in-memory stuff
|
//erase the in-memory stuff
|
||||||
clientMap.erase(accountMgr.GetAccount(argPacket->accountIndex)->GetClientIndex());
|
clientMap.erase(accountMgr.GetAccount(argPacket->GetAccountIndex())->GetClientIndex());
|
||||||
accountMgr.UnloadAccount(argPacket->accountIndex);
|
accountMgr.UnloadAccount(argPacket->GetAccountIndex());
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetContainer()->size() << " accounts total" << std::endl;
|
std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetContainer()->size() << " accounts total" << std::endl;
|
||||||
@@ -115,8 +115,8 @@ void ServerApplication::HandleShutdown(SerialPacket* const argPacket) {
|
|||||||
running = false;
|
running = false;
|
||||||
|
|
||||||
//disconnect all clients
|
//disconnect all clients
|
||||||
SerialPacket newPacket;
|
ServerPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::DISCONNECT;
|
newPacket.SetType(SerialPacketType::DISCONNECT);
|
||||||
PumpPacket(&newPacket);
|
PumpPacket(&newPacket);
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
@@ -130,15 +130,15 @@ void ServerApplication::HandleShutdown(SerialPacket* const argPacket) {
|
|||||||
void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
||||||
RegionPacket newPacket;
|
RegionPacket newPacket;
|
||||||
|
|
||||||
newPacket.type = SerialPacketType::REGION_CONTENT;
|
newPacket.SetType(SerialPacketType::REGION_CONTENT);
|
||||||
newPacket.roomIndex = argPacket->roomIndex;
|
newPacket.SetRoomIndex(argPacket->GetRoomIndex());
|
||||||
newPacket.x = argPacket->x;
|
newPacket.SetX(argPacket->GetX());
|
||||||
newPacket.y = argPacket->y;
|
newPacket.SetY(argPacket->GetY());
|
||||||
|
|
||||||
newPacket.region = roomMgr.GetRoom(argPacket->roomIndex)->GetPager()->GetRegion(argPacket->x, argPacket->y);
|
newPacket.SetRegion(roomMgr.GetRoom(argPacket->GetRoomIndex())->GetPager()->GetRegion(argPacket->GetX(), argPacket->GetY() ));
|
||||||
|
|
||||||
//send the content
|
//send the content
|
||||||
network.SendTo(&argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(argPacket->GetAddressPtr(), static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -148,7 +148,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
|||||||
void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||||
//BUG: #27 Characters can be created with an invalid account index
|
//BUG: #27 Characters can be created with an invalid account index
|
||||||
//NOTE: misnomer, try to load the character first
|
//NOTE: misnomer, try to load the character first
|
||||||
int characterIndex = characterMgr.LoadCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
|
int characterIndex = characterMgr.LoadCharacter(argPacket->GetAccountIndex(), argPacket->GetHandle(), argPacket->GetAvatar());
|
||||||
|
|
||||||
if (characterIndex == -1) {
|
if (characterIndex == -1) {
|
||||||
//TODO: rejection packet
|
//TODO: rejection packet
|
||||||
@@ -164,7 +164,7 @@ void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
|||||||
|
|
||||||
//send this new character to all clients
|
//send this new character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::CHARACTER_NEW;
|
newPacket.SetType(SerialPacketType::CHARACTER_NEW);
|
||||||
CopyCharacterToPacket(&newPacket, characterIndex);
|
CopyCharacterToPacket(&newPacket, characterIndex);
|
||||||
PumpPacket(&newPacket);
|
PumpPacket(&newPacket);
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
|
|||||||
//NOTE: Disconnecting only unloads a character, this explicitly deletes it
|
//NOTE: Disconnecting only unloads a character, this explicitly deletes it
|
||||||
|
|
||||||
//Authenticate the owner is doing this
|
//Authenticate the owner is doing this
|
||||||
int characterIndex = characterMgr.LoadCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
|
int characterIndex = characterMgr.LoadCharacter(argPacket->GetAccountIndex(), argPacket->GetHandle(), argPacket->GetAvatar());
|
||||||
|
|
||||||
//if this is not your character
|
//if this is not your character
|
||||||
if (characterIndex == -2) {
|
if (characterIndex == -2) {
|
||||||
@@ -197,7 +197,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
||||||
CharacterData* character = characterMgr.GetCharacter(argPacket->characterIndex);
|
CharacterData* character = characterMgr.GetCharacter(argPacket->GetCharacterIndex());
|
||||||
|
|
||||||
//make a new character if this one doesn't exist
|
//make a new character if this one doesn't exist
|
||||||
if (!character) {
|
if (!character) {
|
||||||
@@ -208,11 +208,11 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//accept client-side logic
|
//accept client-side logic
|
||||||
character->SetRoomIndex(argPacket->roomIndex);
|
character->SetRoomIndex(argPacket->GetRoomIndex());
|
||||||
character->SetOrigin(argPacket->origin);
|
character->SetOrigin(argPacket->GetOrigin());
|
||||||
character->SetMotion(argPacket->motion);
|
character->SetMotion(argPacket->GetMotion());
|
||||||
|
|
||||||
*character->GetBaseStats() = argPacket->stats;
|
*character->GetBaseStats() = *argPacket->GetStatistics();
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
|
||||||
@@ -228,14 +228,14 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) {
|
|||||||
//NOTE: I quite dislike this function
|
//NOTE: I quite dislike this function
|
||||||
|
|
||||||
//send all of the server's data to this client
|
//send all of the server's data to this client
|
||||||
ClientData& client = clientMap[argPacket->clientIndex];
|
ClientData& client = clientMap[argPacket->GetClientIndex()];
|
||||||
|
|
||||||
//send all characters
|
//send all characters
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
newPacket.SetType(SerialPacketType::CHARACTER_UPDATE);
|
||||||
|
|
||||||
for (auto& it : *characterMgr.GetContainer()) {
|
for (auto& it : *characterMgr.GetContainer()) {
|
||||||
newPacket.characterIndex = it.first;
|
newPacket.SetCharacterIndex(it.first);
|
||||||
CopyCharacterToPacket(&newPacket, it.first);
|
CopyCharacterToPacket(&newPacket, it.first);
|
||||||
network.SendTo(&client.address, static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(&client.address, static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
@@ -258,8 +258,8 @@ void ServerApplication::PumpPacket(SerialPacket* const argPacket) {
|
|||||||
void ServerApplication::PumpCharacterUnload(int uid) {
|
void ServerApplication::PumpCharacterUnload(int uid) {
|
||||||
//delete the client-side character(s)
|
//delete the client-side character(s)
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::CHARACTER_DELETE;
|
newPacket.SetType(SerialPacketType::CHARACTER_DELETE);
|
||||||
newPacket.characterIndex = uid;
|
newPacket.SetCharacterIndex(uid);
|
||||||
PumpPacket(static_cast<SerialPacket*>(&newPacket));
|
PumpPacket(static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,12 +270,12 @@ void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: keep this up to date when the character changes
|
//TODO: keep this up to date when the character changes
|
||||||
packet->characterIndex = characterIndex;
|
packet->SetCharacterIndex(characterIndex);
|
||||||
strncpy(packet->handle, character->GetHandle().c_str(), PACKET_STRING_SIZE);
|
packet->SetHandle(character->GetHandle().c_str());
|
||||||
strncpy(packet->avatar, character->GetAvatar().c_str(), PACKET_STRING_SIZE);
|
packet->SetAvatar(character->GetAvatar().c_str());
|
||||||
packet->accountIndex = character->GetOwner();
|
packet->SetAccountIndex(character->GetOwner());
|
||||||
packet->roomIndex = character->GetRoomIndex();
|
packet->SetRoomIndex(character->GetRoomIndex());
|
||||||
packet->origin = character->GetOrigin();
|
packet->SetOrigin(character->GetOrigin());
|
||||||
packet->motion = character->GetMotion();
|
packet->SetMotion(character->GetMotion());
|
||||||
packet->stats = *character->GetBaseStats();
|
*packet->GetStatistics() = *character->GetBaseStats();
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
TODO: Reduce the verbosity of the network packets
|
||||||
TODO: encapsulate the data structures
|
TODO: encapsulate the data structures
|
||||||
TODO: Ping-pong and keep alive system
|
TODO: Ping-pong and keep alive system
|
||||||
TODO: Move the statistics into their own SQL table, instead of duplicating the structure a dozen times
|
TODO: Move the statistics into their own SQL table, instead of duplicating the structure a dozen times
|
||||||
|
|||||||
Reference in New Issue
Block a user