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