Merge branch 'tweaks'; nothing major

This commit is contained in:
Kayne Ruse
2014-04-29 13:12:39 +10:00
19 changed files with 196 additions and 166 deletions
+2 -2
View File
@@ -119,10 +119,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
activeScene = new OptionsMenu(&config);
break;
case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&config, &network, &clientIndex, &playerIndex);
activeScene = new LobbyMenu(&config, &network, &clientIndex, &characterIndex);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&config, &network, &clientIndex, &playerIndex);
activeScene = new InWorld(&config, &network, &clientIndex, &characterIndex);
break;
case SceneList::INCOMBAT:
activeScene = new InCombat();
+1 -1
View File
@@ -48,7 +48,7 @@ private:
ConfigUtility config;
UDPNetworkUtility network;
int clientIndex = -1;
int playerIndex = -1;
int characterIndex = -1;
};
#endif
+38 -38
View File
@@ -31,11 +31,11 @@
//Public access members
//-------------------------
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argPlayerIndex):
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
playerIndex(*argPlayerIndex)
characterIndex(*argCharacterIndex)
{
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
@@ -67,7 +67,7 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
char buffer[PACKET_STRING_SIZE];
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
packet.clientInfo.clientIndex = clientIndex;
packet.clientInfo.playerIndex = playerIndex;
packet.clientInfo.characterIndex = characterIndex;
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
@@ -252,14 +252,14 @@ void InWorld::HandlePacket(SerialPacket packet) {
case SerialPacket::Type::REGION_CONTENT:
HandleRegionContent(packet);
break;
case SerialPacket::Type::PLAYER_UPDATE:
HandlePlayerUpdate(packet);
case SerialPacket::Type::CHARACTER_UPDATE:
HandleCharacterUpdate(packet);
break;
case SerialPacket::Type::PLAYER_NEW:
HandlePlayerNew(packet);
case SerialPacket::Type::CHARACTER_NEW:
HandleCharacterNew(packet);
break;
case SerialPacket::Type::PLAYER_DELETE:
HandlePlayerDelete(packet);
case SerialPacket::Type::CHARACTER_DELETE:
HandleCharacterDelete(packet);
break;
//handle errors
default:
@@ -271,7 +271,7 @@ void InWorld::HandlePacket(SerialPacket packet) {
void InWorld::HandleDisconnect(SerialPacket packet) {
network.Unbind(Channels::SERVER);
clientIndex = -1;
playerIndex = -1;
characterIndex = -1;
SetNextScene(SceneList::MAINMENU);
}
@@ -285,34 +285,34 @@ void InWorld::HandleRegionContent(SerialPacket packet) {
packet.regionInfo.region = nullptr;
}
void InWorld::HandlePlayerUpdate(SerialPacket packet) {
if (playerCharacters.find(packet.playerInfo.playerIndex) == playerCharacters.end()) {
HandlePlayerNew(packet);
void InWorld::HandleCharacterUpdate(SerialPacket packet) {
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
HandleCharacterNew(packet);
return;
}
//update only if the message didn't originate from here
if (packet.playerInfo.clientIndex != clientIndex) {
playerCharacters[packet.playerInfo.playerIndex].SetPosition(packet.playerInfo.position);
playerCharacters[packet.playerInfo.playerIndex].SetMotion(packet.playerInfo.motion);
if (packet.characterInfo.clientIndex != clientIndex) {
playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position);
playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion);
}
playerCharacters[packet.playerInfo.playerIndex].ResetDirection();
playerCharacters[packet.characterInfo.characterIndex].ResetDirection();
}
void InWorld::HandlePlayerNew(SerialPacket packet) {
if (playerCharacters.find(packet.playerInfo.playerIndex) != playerCharacters.end()) {
throw(std::runtime_error("Cannot create duplicate players"));
void InWorld::HandleCharacterNew(SerialPacket packet) {
if (playerCharacters.find(packet.characterInfo.characterIndex) != playerCharacters.end()) {
throw(std::runtime_error("Cannot create duplicate characters"));
}
//TODO: set the handle
playerCharacters[packet.playerInfo.playerIndex].GetSprite()->LoadSurface(config["dir.sprites"] + packet.playerInfo.avatar, 4, 4);
playerCharacters[packet.playerInfo.playerIndex].SetPosition(packet.playerInfo.position);
playerCharacters[packet.playerInfo.playerIndex].SetMotion(packet.playerInfo.motion);
playerCharacters[packet.playerInfo.playerIndex].ResetDirection();
//TODO: set the player's handle
playerCharacters[packet.characterInfo.characterIndex].GetSprite()->LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4);
playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position);
playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion);
playerCharacters[packet.characterInfo.characterIndex].ResetDirection();
//catch this client's player object
if (packet.playerInfo.playerIndex == playerIndex && !localCharacter) {
localCharacter = &playerCharacters[playerIndex];
if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) {
localCharacter = &playerCharacters[characterIndex];
//setup the camera
camera.width = GetScreen()->w;
@@ -323,16 +323,16 @@ void InWorld::HandlePlayerNew(SerialPacket packet) {
}
}
void InWorld::HandlePlayerDelete(SerialPacket packet) {
if (playerCharacters.find(packet.playerInfo.playerIndex) == playerCharacters.end()) {
throw(std::runtime_error("Cannot delete non-existant players"));
void InWorld::HandleCharacterDelete(SerialPacket packet) {
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
throw(std::runtime_error("Cannot delete non-existant characters"));
}
playerCharacters.erase(packet.playerInfo.playerIndex);
playerCharacters.erase(packet.characterInfo.characterIndex);
//catch this client's player object
if (packet.playerInfo.playerIndex == playerIndex) {
playerIndex = -1;
if (packet.characterInfo.characterIndex == characterIndex) {
characterIndex = -1;
localCharacter = nullptr;
}
}
@@ -346,11 +346,11 @@ void InWorld::SendPlayerUpdate() {
char buffer[PACKET_BUFFER_SIZE];
//pack the packet
packet.meta.type = SerialPacket::Type::PLAYER_UPDATE;
packet.playerInfo.clientIndex = clientIndex;
packet.playerInfo.playerIndex = playerIndex;
packet.playerInfo.position = localCharacter->GetPosition();
packet.playerInfo.motion = localCharacter->GetMotion();
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
packet.characterInfo.clientIndex = clientIndex;
packet.characterInfo.characterIndex = characterIndex;
packet.characterInfo.position = localCharacter->GetPosition();
packet.characterInfo.motion = localCharacter->GetMotion();
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
+4 -4
View File
@@ -74,9 +74,9 @@ protected:
//Network handlers
void HandlePacket(SerialPacket);
void HandleDisconnect(SerialPacket);
void HandlePlayerNew(SerialPacket);
void HandlePlayerDelete(SerialPacket);
void HandlePlayerUpdate(SerialPacket);
void HandleCharacterNew(SerialPacket);
void HandleCharacterDelete(SerialPacket);
void HandleCharacterUpdate(SerialPacket);
void HandleRegionContent(SerialPacket);
//Server control
@@ -92,7 +92,7 @@ protected:
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& playerIndex;
int& characterIndex;
//graphics
Image buttonImage;
+5 -5
View File
@@ -30,11 +30,11 @@
//Public access members
//-------------------------
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argPlayerIndex):
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
playerIndex(*argPlayerIndex)
characterIndex(*argCharacterIndex)
{
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
@@ -119,7 +119,7 @@ void LobbyMenu::Render(SDL_Surface* const screen) {
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
}
//TODO: ping?
//ping?
}
}
@@ -162,7 +162,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//pack the packet
packet.meta.type = SerialPacket::Type::JOIN_REQUEST;
strncpy(packet.clientInfo.player, config["client.player"].c_str(), PACKET_STRING_SIZE);
strncpy(packet.clientInfo.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
strncpy(packet.clientInfo.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
strncpy(packet.clientInfo.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
@@ -221,7 +221,7 @@ void LobbyMenu::HandlePacket(SerialPacket packet) {
break;
case SerialPacket::Type::JOIN_RESPONSE:
clientIndex = packet.clientInfo.clientIndex;
playerIndex = packet.clientInfo.playerIndex;
characterIndex = packet.clientInfo.characterIndex;
network.Bind(&packet.meta.srcAddress, Channels::SERVER);
SetNextScene(SceneList::INWORLD);
break;
+1 -1
View File
@@ -65,7 +65,7 @@ protected:
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& playerIndex;
int& characterIndex;
//members
Image image;
+28 -28
View File
@@ -54,10 +54,10 @@ void serializeClient(SerialPacket* packet, char* buffer) {
//indexes
SERIALIZE(buffer, &packet->clientInfo.clientIndex, sizeof(int));
SERIALIZE(buffer, &packet->clientInfo.playerIndex, sizeof(int));
SERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int));
//texts
SERIALIZE(buffer, packet->clientInfo.player, PACKET_STRING_SIZE);
SERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE);
SERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
SERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
}
@@ -90,22 +90,22 @@ void serializeRegionContent(SerialPacket* packet, char* buffer) {
}
}
void serializePlayer(SerialPacket* packet, char* buffer) {
void serializeCharacter(SerialPacket* packet, char* buffer) {
SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
//indexes
SERIALIZE(buffer, &packet->playerInfo.clientIndex, sizeof(int));
SERIALIZE(buffer, &packet->playerInfo.playerIndex, sizeof(int));
SERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int));
SERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int));
//texts
SERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
SERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
//vectors
SERIALIZE(buffer, &packet->playerInfo.position.x, sizeof(double));
SERIALIZE(buffer, &packet->playerInfo.position.y, sizeof(double));
SERIALIZE(buffer, &packet->playerInfo.motion.x, sizeof(double));
SERIALIZE(buffer, &packet->playerInfo.motion.y, sizeof(double));
SERIALIZE(buffer, &packet->characterInfo.position.x, sizeof(double));
SERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double));
SERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double));
SERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double));
}
//-------------------------
@@ -130,10 +130,10 @@ void deserializeClient(SerialPacket* packet, char* buffer) {
//indexes
DESERIALIZE(buffer, &packet->clientInfo.clientIndex, sizeof(int));
DESERIALIZE(buffer, &packet->clientInfo.playerIndex, sizeof(int));
DESERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int));
//texts
DESERIALIZE(buffer, packet->clientInfo.player, PACKET_STRING_SIZE);
DESERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE);
DESERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
DESERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
}
@@ -173,22 +173,22 @@ void deserializeRegionContent(SerialPacket* packet, char* buffer) {
}
}
void deserializePlayer(SerialPacket* packet, char* buffer) {
void deserializeCharacter(SerialPacket* packet, char* buffer) {
DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
//indexes
DESERIALIZE(buffer, &packet->playerInfo.clientIndex, sizeof(int));
DESERIALIZE(buffer, &packet->playerInfo.playerIndex, sizeof(int));
DESERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int));
DESERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int));
//texts
DESERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
DESERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
//vectors
DESERIALIZE(buffer, &packet->playerInfo.position.x, sizeof(double));
DESERIALIZE(buffer, &packet->playerInfo.position.y, sizeof(double));
DESERIALIZE(buffer, &packet->playerInfo.motion.x, sizeof(double));
DESERIALIZE(buffer, &packet->playerInfo.motion.y, sizeof(double));
DESERIALIZE(buffer, &packet->characterInfo.position.x, sizeof(double));
DESERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double));
DESERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double));
DESERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double));
}
//-------------------------
@@ -228,11 +228,11 @@ void serialize(SerialPacket* packet, void* buffer) {
serializeRegionContent(packet, reinterpret_cast<char*>(buffer));
break;
//Player info
case SerialPacket::Type::PLAYER_NEW:
case SerialPacket::Type::PLAYER_DELETE:
case SerialPacket::Type::PLAYER_UPDATE:
serializePlayer(packet, reinterpret_cast<char*>(buffer));
//Character info
case SerialPacket::Type::CHARACTER_NEW:
case SerialPacket::Type::CHARACTER_DELETE:
case SerialPacket::Type::CHARACTER_UPDATE:
serializeCharacter(packet, reinterpret_cast<char*>(buffer));
break;
}
}
@@ -272,11 +272,11 @@ void deserialize(SerialPacket* packet, void* buffer) {
deserializeRegionContent(packet, reinterpret_cast<char*>(buffer));
break;
//Player info
case SerialPacket::Type::PLAYER_NEW:
case SerialPacket::Type::PLAYER_DELETE:
case SerialPacket::Type::PLAYER_UPDATE:
deserializePlayer(packet, reinterpret_cast<char*>(buffer));
//Character info
case SerialPacket::Type::CHARACTER_NEW:
case SerialPacket::Type::CHARACTER_DELETE:
case SerialPacket::Type::CHARACTER_UPDATE:
deserializeCharacter(packet, reinterpret_cast<char*>(buffer));
break;
}
}
+10 -10
View File
@@ -63,10 +63,10 @@ union SerialPacket {
REGION_REQUEST = 10,
REGION_CONTENT = 11,
//Player movement, etc.
PLAYER_NEW = 12,
PLAYER_DELETE = 13,
PLAYER_UPDATE = 14,
//Character movement, etc.
CHARACTER_NEW = 12,
CHARACTER_DELETE = 13,
CHARACTER_UPDATE = 14,
//TODO: combat packets
};
@@ -89,8 +89,8 @@ union SerialPacket {
struct ClientInformation {
Metadata meta;
int clientIndex;
int playerIndex;
char player[PACKET_STRING_SIZE];
int characterIndex;
char username[PACKET_STRING_SIZE];
char handle[PACKET_STRING_SIZE];
char avatar[PACKET_STRING_SIZE];
}clientInfo;
@@ -103,17 +103,17 @@ union SerialPacket {
Region* region;
}regionInfo;
//information about a player
struct PlayerInformation {
//information about a character
struct CharacterInformation {
Metadata meta;
int clientIndex;
int playerIndex;
int characterIndex;
char handle[PACKET_STRING_SIZE];
char avatar[PACKET_STRING_SIZE];
int mapIndex;
Vector2 position;
Vector2 motion;
}playerInfo;
}characterInfo;
//defaults
SerialPacket() {
+7 -7
View File
@@ -170,29 +170,29 @@ void EditorScene::HandleMenuOption(int entry, int drop) {
case 0: //File
switch(drop) {
case 0:
//TODO: NEW
//NEW
break;
case 1:
//TODO: OPEN
//OPEN
break;
case 2:
//TODO: SAVE
//SAVE
break;
case 3:
//TODO: CLOSE
//CLOSE
break;
}
break;
case 1: //Edit
switch(drop) {
case 0:
//TODO: SET TILE
//SET TILE
break;
case 1:
//TODO: SET BRUSH
//SET BRUSH
break;
case 2:
//TODO: SCRIPT
//SCRIPT
break;
}
break;
+1 -1
View File
@@ -23,7 +23,7 @@ map.pager.height = 20
map.pager.depth = 3
#player options
client.player = Kayne Ruse
client.username = Kayne Ruse
client.handle = Ratstail91
client.avatar = elliot2.bmp
+3 -3
View File
@@ -1,5 +1,3 @@
--TODO: The SQL startup script needs revising
-------------------------
--Server
-------------------------
@@ -7,7 +5,8 @@
CREATE TABLE IF NOT EXISTS UserAccounts (
uid INTEGER PRIMARY KEY AUTOINCREMENT,
username varchar(100) UNIQUE,
password varchar(100), --NOTE: DO NOT DO THIS!!
--TODO: server-client security
-- password varchar(100),
blacklisted BIT DEFAULT 0,
whitelisted BIT DEFAULT 1
);
@@ -50,6 +49,7 @@ CREATE TABLE IF NOT EXISTS PlayerCharacters (
uid INTEGER PRIMARY KEY AUTOINCREMENT,
--metadata
owner INTEGER REFERENCES UserAccounts(uid),
handle varchar(100) UNIQUE,
avatar varchar(100),
birth timestamp NOT NULL DEFAULT (datetime()),
@@ -19,6 +19,6 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "player_entry.hpp"
#include "character_data.hpp"
int PlayerEntry::uidCounter = 0;
int CharacterData::uidCounter = 0;
@@ -19,8 +19,8 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef PLAYERENTRY_HPP_
#define PLAYERENTRY_HPP_
#ifndef CHARACTERDATA_HPP_
#define CHARACTERDATA_HPP_
//POD members
#include "bbox.hpp"
@@ -28,10 +28,10 @@
#include <string>
struct PlayerEntry {
struct CharacterData {
//metadata
int clientIndex;
std::string player;
std::string username;
std::string handle;
std::string avatar;
@@ -19,6 +19,6 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "client_entry.hpp"
#include "client_data.hpp"
int ClientEntry::uidCounter = 0;
int ClientData::uidCounter = 0;
@@ -19,12 +19,12 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CLIENTENTRY_HPP_
#define CLIENTENTRY_HPP_
#ifndef CLIENTDATA_HPP_
#define CLIENTDATA_HPP_
#include "SDL/SDL_net.h"
struct ClientEntry {
struct ClientData {
IPaddress address = {0,0};
static int uidCounter;
};
+7 -7
View File
@@ -23,8 +23,8 @@
#define SERVERAPPLICATION_HPP_
//server specific stuff
#include "client_entry.hpp"
#include "player_entry.hpp"
#include "client_data.hpp"
#include "character_data.hpp"
//maps
#include "map_allocator.hpp"
@@ -68,10 +68,10 @@ private:
void HandleSynchronize(SerialPacket);
void HandleDisconnect(SerialPacket);
void HandleShutdown(SerialPacket);
void HandlePlayerUpdate(SerialPacket);
void HandleCharacterUpdate(SerialPacket);
void HandleRegionRequest(SerialPacket);
//TODO: a function that only sends to players in a certain proximity
//TODO: a function that only sends to characters in a certain proximity
void PumpPacket(SerialPacket);
//TODO: manage the database
@@ -83,12 +83,12 @@ private:
lua_State* luaState = nullptr;
//server tables
std::map<int, ClientEntry> clientMap;
std::map<int, PlayerEntry> playerMap;
std::map<int, ClientData> clientMap;
std::map<int, CharacterData> characterMap;
//maps
//TODO: I need to handle multiple map objects
//TODO: Unload regions that are distant from any players
//TODO: Unload regions that are distant from any characters
RegionPager<LuaAllocator, LuaFormat> regionPager;
//misc
+46 -46
View File
@@ -33,7 +33,7 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket packet) {
packet.meta.type = SerialPacket::Type::BROADCAST_RESPONSE;
packet.serverInfo.networkVersion = NETWORK_VERSION;
snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str());
packet.serverInfo.playerCount = playerMap.size();
packet.serverInfo.playerCount = characterMap.size();
//bounce this packet
char buffer[PACKET_BUFFER_SIZE];
@@ -43,41 +43,41 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket packet) {
void ServerApplication::HandleJoinRequest(SerialPacket packet) {
//create the new client
ClientEntry newClient;
ClientData newClient;
newClient.address = packet.meta.srcAddress;
//TODO: move this into the player management code
//create the new player
PlayerEntry newPlayer;
newPlayer.clientIndex = ClientEntry::uidCounter;
newPlayer.player = packet.clientInfo.player;
newPlayer.handle = packet.clientInfo.handle;
newPlayer.avatar = packet.clientInfo.avatar;
//TODO: move this into the character management code
//create the new character
CharacterData newCharacter;
newCharacter.clientIndex = ClientData::uidCounter;
newCharacter.username = packet.clientInfo.username;
newCharacter.handle = packet.clientInfo.handle;
newCharacter.avatar = packet.clientInfo.avatar;
//send the client their info
packet.meta.type = SerialPacket::Type::JOIN_RESPONSE;
packet.clientInfo.clientIndex = ClientEntry::uidCounter;
packet.clientInfo.playerIndex = PlayerEntry::uidCounter;
packet.clientInfo.clientIndex = ClientData::uidCounter;
packet.clientInfo.characterIndex = CharacterData::uidCounter;
//bounce this packet
char buffer[PACKET_BUFFER_SIZE];
serialize(&packet, buffer);
network.Send(&newClient.address, buffer, PACKET_BUFFER_SIZE);
//send the new player to all clients
packet.meta.type = SerialPacket::Type::PLAYER_NEW;
packet.playerInfo.playerIndex = PlayerEntry::uidCounter;
strncpy(packet.playerInfo.handle, newPlayer.handle.c_str(), PACKET_STRING_SIZE);
strncpy(packet.playerInfo.avatar, newPlayer.avatar.c_str(), PACKET_STRING_SIZE);
packet.playerInfo.position = newPlayer.position;
packet.playerInfo.motion = newPlayer.motion;
//send the new character to all clients
packet.meta.type = SerialPacket::Type::CHARACTER_NEW;
packet.characterInfo.characterIndex = CharacterData::uidCounter;
strncpy(packet.characterInfo.handle, newCharacter.handle.c_str(), PACKET_STRING_SIZE);
strncpy(packet.characterInfo.avatar, newCharacter.avatar.c_str(), PACKET_STRING_SIZE);
packet.characterInfo.position = newCharacter.position;
packet.characterInfo.motion = newCharacter.motion;
PumpPacket(packet);
//finished this routine
clientMap[ClientEntry::uidCounter] = newClient;
playerMap[PlayerEntry::uidCounter] = newPlayer;
ClientEntry::uidCounter++;
PlayerEntry::uidCounter++;
clientMap[ClientData::uidCounter] = newClient;
characterMap[CharacterData::uidCounter] = newCharacter;
ClientData::uidCounter++;
CharacterData::uidCounter++;
std::cout << "Connect, total: " << clientMap.size() << std::endl;
}
@@ -88,16 +88,16 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) {
SerialPacket newPacket;
char buffer[PACKET_BUFFER_SIZE];
//players
newPacket.meta.type = SerialPacket::Type::PLAYER_UPDATE;
for (auto& it : playerMap) {
//TODO: update this for the expanded PlayerEntry structure
newPacket.playerInfo.playerIndex = it.first;
snprintf(newPacket.playerInfo.handle, PACKET_STRING_SIZE, "%s", it.second.handle.c_str());
snprintf(newPacket.playerInfo.avatar, PACKET_STRING_SIZE, "%s", it.second.avatar.c_str());
newPacket.playerInfo.mapIndex = it.second.mapIndex;
newPacket.playerInfo.position = it.second.position;
newPacket.playerInfo.motion = it.second.motion;
//characters
newPacket.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
for (auto& it : characterMap) {
//TODO: update this for the expanded CharacterData structure
newPacket.characterInfo.characterIndex = it.first;
snprintf(newPacket.characterInfo.handle, PACKET_STRING_SIZE, "%s", it.second.handle.c_str());
snprintf(newPacket.characterInfo.avatar, PACKET_STRING_SIZE, "%s", it.second.avatar.c_str());
newPacket.characterInfo.mapIndex = it.second.mapIndex;
newPacket.characterInfo.position = it.second.position;
newPacket.characterInfo.motion = it.second.motion;
serialize(&newPacket, buffer);
network.Send(&clientMap[packet.clientInfo.clientIndex].address, buffer, PACKET_BUFFER_SIZE);
}
@@ -105,7 +105,7 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) {
void ServerApplication::HandleDisconnect(SerialPacket packet) {
//TODO: authenticate who is disconnecting/kicking
//TODO: define the difference between unloading and deletng a player
//TODO: define the difference between unloading and deletng a character
//disconnect the specified client
char buffer[PACKET_BUFFER_SIZE];
@@ -115,21 +115,21 @@ void ServerApplication::HandleDisconnect(SerialPacket packet) {
//prep the delete packet
SerialPacket delPacket;
delPacket.meta.type = SerialPacket::Type::PLAYER_DELETE;
delPacket.meta.type = SerialPacket::Type::CHARACTER_DELETE;
//delete server and client side players
erase_if(playerMap, [&](std::pair<int, PlayerEntry> it) -> bool {
//find the internal players to delete
//delete server and client side characters
erase_if(characterMap, [&](std::pair<int, CharacterData> it) -> bool {
//find the internal characters to delete
if (it.second.clientIndex == packet.clientInfo.clientIndex) {
//send the delete player command to all clients
delPacket.playerInfo.playerIndex = it.first;
//send the delete characters command to all clients
delPacket.characterInfo.characterIndex = it.first;
PumpPacket(delPacket);
//delete this player object
//delete this characters object
return true;
}
//don't delete this player object
//don't delete this characters object
return false;
});
@@ -152,15 +152,15 @@ void ServerApplication::HandleShutdown(SerialPacket packet) {
std::cout << "Shutdown signal accepted" << std::endl;
}
void ServerApplication::HandlePlayerUpdate(SerialPacket packet) {
void ServerApplication::HandleCharacterUpdate(SerialPacket packet) {
//TODO: this should be moved elsewhere
if (playerMap.find(packet.playerInfo.playerIndex) == playerMap.end()) {
throw(std::runtime_error("Cannot update a non-existant player"));
if (characterMap.find(packet.characterInfo.characterIndex) == characterMap.end()) {
throw(std::runtime_error("Cannot update a non-existant character"));
}
//TODO: the server needs it's own movement system too
playerMap[packet.playerInfo.playerIndex].position = packet.playerInfo.position;
playerMap[packet.playerInfo.playerIndex].motion = packet.playerInfo.motion;
characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position;
characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion;
PumpPacket(packet);
}
+2 -2
View File
@@ -154,8 +154,8 @@ void ServerApplication::HandlePacket(SerialPacket packet) {
case SerialPacket::Type::SHUTDOWN:
HandleShutdown(packet);
break;
case SerialPacket::Type::PLAYER_UPDATE:
HandlePlayerUpdate(packet);
case SerialPacket::Type::CHARACTER_UPDATE:
HandleCharacterUpdate(packet);
break;
case SerialPacket::Type::REGION_REQUEST:
HandleRegionRequest(packet);
+30
View File
@@ -0,0 +1,30 @@
I need to keep the documentation up to date. Namey, the GDD is getting out of date.
--Naming conventions--
I need to define the differences between several different terms i.e. naming conventions.
I may also need to rewrite some variable names.
* User: This is the individual who is playing the game
* Player: A synonym for a user
* Character: This is the actual player character in the game
* Username: This is the name of the player; ususally kept private
* Handle: This is the name of a character
* Avatar: This is the name of the sprite used by a character
--ServerApplication's methods--
These interact with the database file, making the server a persistent system.
* CreateUserAccount
* LoadUserAccount
* SaveUserAccount
* UnloadUserAccount
* DeleteUserAccount
* CreateCharacter
* LoadCharacter
* SaveCharacter
* UnloadCharacter
* DeleteCharacter