Merge branch 'account'
Added the "accountIndex" variable to the SerialPacket.
This commit is contained in:
@@ -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, &characterIndex);
|
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::INWORLD:
|
case SceneList::INWORLD:
|
||||||
activeScene = new InWorld(&config, &network, &clientIndex, &characterIndex);
|
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::INCOMBAT:
|
case SceneList::INCOMBAT:
|
||||||
activeScene = new InCombat();
|
activeScene = new InCombat();
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ private:
|
|||||||
ConfigUtility config;
|
ConfigUtility config;
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility network;
|
||||||
int clientIndex = -1;
|
int clientIndex = -1;
|
||||||
|
int accountIndex = -1;
|
||||||
int characterIndex = -1;
|
int characterIndex = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,11 @@
|
|||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex):
|
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex):
|
||||||
config(*argConfig),
|
config(*argConfig),
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex)
|
characterIndex(*argCharacterIndex)
|
||||||
{
|
{
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
@@ -62,11 +63,13 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
|
|||||||
//TODO: add the tilesheet to the map system?
|
//TODO: add the tilesheet to the map system?
|
||||||
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
||||||
|
|
||||||
|
//TODO: move this into it's own function
|
||||||
//request a sync
|
//request a sync
|
||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
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.accountIndex = accountIndex;
|
||||||
packet.clientInfo.characterIndex = characterIndex;
|
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);
|
||||||
@@ -263,7 +266,7 @@ void InWorld::HandlePacket(SerialPacket packet) {
|
|||||||
break;
|
break;
|
||||||
//handle errors
|
//handle errors
|
||||||
default:
|
default:
|
||||||
throw(std::runtime_error("Unknown SerialPacket::Type encountered"));
|
throw(std::runtime_error(std::string() + "Unknown SerialPacket::Type encountered in InWorld: " + to_string_custom(int(packet.meta.type))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,6 +274,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;
|
||||||
|
accountIndex = -1;
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
SetNextScene(SceneList::MAINMENU);
|
SetNextScene(SceneList::MAINMENU);
|
||||||
}
|
}
|
||||||
@@ -323,6 +327,7 @@ void InWorld::HandleCharacterNew(SerialPacket packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
||||||
|
//TODO: authenticate
|
||||||
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
|
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
|
||||||
throw(std::runtime_error("Cannot delete non-existant characters"));
|
throw(std::runtime_error("Cannot delete non-existant characters"));
|
||||||
}
|
}
|
||||||
@@ -347,6 +352,7 @@ void InWorld::SendPlayerUpdate() {
|
|||||||
//pack the packet
|
//pack the packet
|
||||||
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
||||||
packet.characterInfo.clientIndex = clientIndex;
|
packet.characterInfo.clientIndex = clientIndex;
|
||||||
|
packet.characterInfo.accountIndex = accountIndex;
|
||||||
packet.characterInfo.characterIndex = characterIndex;
|
packet.characterInfo.characterIndex = characterIndex;
|
||||||
packet.characterInfo.position = localCharacter->GetPosition();
|
packet.characterInfo.position = localCharacter->GetPosition();
|
||||||
packet.characterInfo.motion = localCharacter->GetMotion();
|
packet.characterInfo.motion = localCharacter->GetMotion();
|
||||||
@@ -361,7 +367,7 @@ void InWorld::RequestDisconnect() {
|
|||||||
|
|
||||||
//send a disconnect request
|
//send a disconnect request
|
||||||
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
||||||
packet.clientInfo.clientIndex = clientIndex;
|
packet.clientInfo.accountIndex = accountIndex;
|
||||||
serialize(&packet, buffer);
|
serialize(&packet, buffer);
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
@@ -372,7 +378,7 @@ void InWorld::RequestShutDown() {
|
|||||||
|
|
||||||
//send a shutdown request
|
//send a shutdown request
|
||||||
packet.meta.type = SerialPacket::Type::SHUTDOWN;
|
packet.meta.type = SerialPacket::Type::SHUTDOWN;
|
||||||
packet.clientInfo.clientIndex = clientIndex;
|
packet.clientInfo.accountIndex = accountIndex;
|
||||||
serialize(&packet, buffer);
|
serialize(&packet, buffer);
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
class InWorld : public BaseScene {
|
class InWorld : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
InWorld(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const);
|
InWorld(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const);
|
||||||
~InWorld();
|
~InWorld();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -92,6 +92,7 @@ protected:
|
|||||||
ConfigUtility& config;
|
ConfigUtility& config;
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
|
|||||||
@@ -30,10 +30,11 @@
|
|||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex):
|
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex):
|
||||||
config(*argConfig),
|
config(*argConfig),
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex)
|
characterIndex(*argCharacterIndex)
|
||||||
{
|
{
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
@@ -221,6 +222,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;
|
||||||
|
accountIndex = packet.clientInfo.accountIndex;
|
||||||
characterIndex = packet.clientInfo.characterIndex;
|
characterIndex = packet.clientInfo.characterIndex;
|
||||||
network.Bind(&packet.meta.srcAddress, Channels::SERVER);
|
network.Bind(&packet.meta.srcAddress, Channels::SERVER);
|
||||||
SetNextScene(SceneList::INWORLD);
|
SetNextScene(SceneList::INWORLD);
|
||||||
@@ -228,7 +230,7 @@ void LobbyMenu::HandlePacket(SerialPacket packet) {
|
|||||||
|
|
||||||
//handle errors
|
//handle errors
|
||||||
default:
|
default:
|
||||||
throw(std::runtime_error("Unknown SerialPacket::Type encountered"));
|
throw(std::runtime_error(std::string() + "Unknown SerialPacket::Type encountered in LobbyMenu: " + to_string_custom(int(packet.meta.type))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
class LobbyMenu : public BaseScene {
|
class LobbyMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const);
|
LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const);
|
||||||
~LobbyMenu();
|
~LobbyMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -65,6 +65,7 @@ protected:
|
|||||||
ConfigUtility& config;
|
ConfigUtility& config;
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
|
|
||||||
//members
|
//members
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ 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.accountIndex, sizeof(int));
|
||||||
SERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int));
|
SERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int));
|
||||||
|
|
||||||
//texts
|
//texts
|
||||||
@@ -95,6 +96,7 @@ void serializeCharacter(SerialPacket* packet, char* buffer) {
|
|||||||
|
|
||||||
//indexes
|
//indexes
|
||||||
SERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int));
|
SERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &packet->characterInfo.accountIndex, sizeof(int));
|
||||||
SERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int));
|
SERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int));
|
||||||
|
|
||||||
//texts
|
//texts
|
||||||
@@ -130,6 +132,7 @@ 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.accountIndex, sizeof(int));
|
||||||
DESERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int));
|
DESERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int));
|
||||||
|
|
||||||
//texts
|
//texts
|
||||||
@@ -178,6 +181,7 @@ void deserializeCharacter(SerialPacket* packet, char* buffer) {
|
|||||||
|
|
||||||
//indexes
|
//indexes
|
||||||
DESERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int));
|
DESERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &packet->characterInfo.accountIndex, sizeof(int));
|
||||||
DESERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int));
|
DESERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int));
|
||||||
|
|
||||||
//texts
|
//texts
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include "SDL/SDL_net.h"
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
#define NETWORK_VERSION 20140428
|
#define NETWORK_VERSION 20140506
|
||||||
#define PACKET_STRING_SIZE 100
|
#define PACKET_STRING_SIZE 100
|
||||||
|
|
||||||
#pragma pack(push, 0)
|
#pragma pack(push, 0)
|
||||||
@@ -88,8 +88,8 @@ union SerialPacket {
|
|||||||
//information about the client
|
//information about the client
|
||||||
struct ClientInformation {
|
struct ClientInformation {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
//TODO: change clientIndex to accountIndex for player ID
|
|
||||||
int clientIndex;
|
int clientIndex;
|
||||||
|
int accountIndex;
|
||||||
int characterIndex;
|
int characterIndex;
|
||||||
char username[PACKET_STRING_SIZE];
|
char username[PACKET_STRING_SIZE];
|
||||||
char handle[PACKET_STRING_SIZE];
|
char handle[PACKET_STRING_SIZE];
|
||||||
@@ -108,6 +108,7 @@ union SerialPacket {
|
|||||||
struct CharacterInformation {
|
struct CharacterInformation {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
int clientIndex;
|
int clientIndex;
|
||||||
|
int accountIndex;
|
||||||
int characterIndex;
|
int characterIndex;
|
||||||
char handle[PACKET_STRING_SIZE];
|
char handle[PACKET_STRING_SIZE];
|
||||||
char avatar[PACKET_STRING_SIZE];
|
char avatar[PACKET_STRING_SIZE];
|
||||||
|
|||||||
@@ -26,11 +26,12 @@
|
|||||||
|
|
||||||
struct AccountData {
|
struct AccountData {
|
||||||
std::string username;
|
std::string username;
|
||||||
//password
|
//TODO: password
|
||||||
bool blackListed = false;
|
bool blackListed = false;
|
||||||
bool whiteListed = true;
|
bool whiteListed = true;
|
||||||
|
|
||||||
int clientIndex;
|
int clientIndex;
|
||||||
|
int characterIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
struct CharacterData {
|
struct CharacterData {
|
||||||
//metadata
|
//metadata
|
||||||
int clientIndex;
|
|
||||||
std::string handle;
|
std::string handle;
|
||||||
std::string avatar;
|
std::string avatar;
|
||||||
|
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ private:
|
|||||||
void PumpPacket(SerialPacket);
|
void PumpPacket(SerialPacket);
|
||||||
|
|
||||||
//Account management
|
//Account management
|
||||||
int CreateUserAccount(std::string username, int clientIndex);
|
int CreateUserAccount(std::string username, int clientIndex, int characterIndex);
|
||||||
int LoadUserAccount(std::string username, int clientIndex);
|
int LoadUserAccount(std::string username, int clientIndex, int characterIndex);
|
||||||
int SaveUserAccount(int uid);
|
int SaveUserAccount(int uid);
|
||||||
void UnloadUserAccount(int uid);
|
void UnloadUserAccount(int uid);
|
||||||
void DeleteUserAccount(int uid);
|
void DeleteUserAccount(int uid);
|
||||||
|
|||||||
@@ -42,27 +42,28 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
||||||
|
//load the user account
|
||||||
|
int accountIndex = LoadUserAccount(packet.clientInfo.username, ClientData::uidCounter, CharacterData::uidCounter);
|
||||||
|
if (accountIndex < 0) {
|
||||||
|
//TODO: send rejection packet
|
||||||
|
std::cerr << "Error: Account already loaded: " << accountIndex << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//create the new client
|
//create the new client
|
||||||
ClientData newClient;
|
ClientData newClient;
|
||||||
newClient.address = packet.meta.srcAddress;
|
newClient.address = packet.meta.srcAddress;
|
||||||
|
|
||||||
//load the user account
|
|
||||||
int uid = LoadUserAccount(packet.clientInfo.username, ClientData::uidCounter);
|
|
||||||
if (uid < 0) {
|
|
||||||
std::cerr << "Error: Account already loaded: " << uid << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: move this into the character management code
|
//TODO: move this into the character management code
|
||||||
//create the new character
|
//create the new character
|
||||||
CharacterData newCharacter;
|
CharacterData newCharacter;
|
||||||
newCharacter.clientIndex = ClientData::uidCounter;
|
|
||||||
newCharacter.handle = packet.clientInfo.handle;
|
newCharacter.handle = packet.clientInfo.handle;
|
||||||
newCharacter.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 = ClientData::uidCounter;
|
packet.clientInfo.clientIndex = ClientData::uidCounter;
|
||||||
|
packet.clientInfo.accountIndex = accountIndex;
|
||||||
packet.clientInfo.characterIndex = CharacterData::uidCounter;
|
packet.clientInfo.characterIndex = CharacterData::uidCounter;
|
||||||
|
|
||||||
//bounce this packet
|
//bounce this packet
|
||||||
@@ -79,11 +80,10 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
|||||||
packet.characterInfo.motion = newCharacter.motion;
|
packet.characterInfo.motion = newCharacter.motion;
|
||||||
PumpPacket(packet);
|
PumpPacket(packet);
|
||||||
|
|
||||||
|
//TODO: don't send anything to a certain client until they send the OK (the sync packet? or ignore client side?)
|
||||||
//finished this routine
|
//finished this routine
|
||||||
clientMap[ClientData::uidCounter] = newClient;
|
clientMap[ClientData::uidCounter++] = newClient;
|
||||||
characterMap[CharacterData::uidCounter] = newCharacter;
|
characterMap[CharacterData::uidCounter++] = newCharacter;
|
||||||
ClientData::uidCounter++;
|
|
||||||
CharacterData::uidCounter++;
|
|
||||||
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,43 +113,24 @@ 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 character
|
//TODO: define the difference between unloading and deletng a character
|
||||||
|
|
||||||
//disconnect the specified client
|
//forward to the specified client
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
char buffer[PACKET_BUFFER_SIZE];
|
||||||
serialize(&packet, buffer);
|
serialize(&packet, buffer);
|
||||||
network.Send(&clientMap[packet.clientInfo.clientIndex].address, buffer, PACKET_BUFFER_SIZE);
|
network.Send(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, buffer, PACKET_BUFFER_SIZE);
|
||||||
clientMap.erase(packet.clientInfo.clientIndex);
|
|
||||||
|
|
||||||
//unload the client's account
|
//delete the client side character
|
||||||
//TODO: change clientIndex to accountIndex for player ID
|
|
||||||
for (auto it : accountMap) {
|
|
||||||
if (it.second.clientIndex == packet.clientInfo.clientIndex) {
|
|
||||||
UnloadUserAccount(it.first);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//prep the delete packet
|
|
||||||
SerialPacket delPacket;
|
SerialPacket delPacket;
|
||||||
delPacket.meta.type = SerialPacket::Type::CHARACTER_DELETE;
|
delPacket.meta.type = SerialPacket::Type::CHARACTER_DELETE;
|
||||||
|
delPacket.characterInfo.characterIndex = accountMap[packet.clientInfo.accountIndex].characterIndex;
|
||||||
|
PumpPacket(delPacket);
|
||||||
|
|
||||||
//delete server and client side characters
|
//erase the in-memory stuff
|
||||||
erase_if(characterMap, [&](std::pair<int, CharacterData> it) -> bool {
|
clientMap.erase(accountMap[packet.clientInfo.accountIndex].clientIndex);
|
||||||
//find the internal characters to delete
|
characterMap.erase(accountMap[packet.clientInfo.accountIndex].characterIndex);
|
||||||
if (it.second.clientIndex == packet.clientInfo.clientIndex) {
|
UnloadUserAccount(packet.clientInfo.accountIndex);
|
||||||
//send the delete characters command to all clients
|
|
||||||
delPacket.characterInfo.characterIndex = it.first;
|
|
||||||
PumpPacket(delPacket);
|
|
||||||
|
|
||||||
//delete this characters object
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//don't delete this characters object
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
std::cout << "Disconnect, total: " << clientMap.size() << std::endl;
|
std::cout << "Disconnect, total: " << accountMap.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleShutdown(SerialPacket packet) {
|
void ServerApplication::HandleShutdown(SerialPacket packet) {
|
||||||
@@ -160,7 +141,6 @@ void ServerApplication::HandleShutdown(SerialPacket packet) {
|
|||||||
|
|
||||||
//disconnect all clients
|
//disconnect all clients
|
||||||
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
||||||
packet.clientInfo.clientIndex = -1;
|
|
||||||
PumpPacket(packet);
|
PumpPacket(packet);
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?
|
|||||||
//Define the methods
|
//Define the methods
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
int ServerApplication::CreateUserAccount(std::string username, int clientIndex) {
|
int ServerApplication::CreateUserAccount(std::string username, int clientIndex, int characterIndex) {
|
||||||
//create this user account, failing if it exists, leave this account in memory
|
//create this user account, failing if it exists, leave this account in memory
|
||||||
sqlite3_stmt* statement = nullptr;
|
sqlite3_stmt* statement = nullptr;
|
||||||
|
|
||||||
@@ -62,10 +62,10 @@ int ServerApplication::CreateUserAccount(std::string username, int clientIndex)
|
|||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
|
|
||||||
//load this account into memory
|
//load this account into memory
|
||||||
return LoadUserAccount(username, clientIndex);
|
return LoadUserAccount(username, clientIndex, characterIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerApplication::LoadUserAccount(std::string username, int clientIndex) {
|
int ServerApplication::LoadUserAccount(std::string username, int clientIndex, int characterIndex) {
|
||||||
//load this user account, failing if it is in memory, creating it if it doesn't exist
|
//load this user account, failing if it is in memory, creating it if it doesn't exist
|
||||||
sqlite3_stmt* statement = nullptr;
|
sqlite3_stmt* statement = nullptr;
|
||||||
|
|
||||||
@@ -99,6 +99,7 @@ int ServerApplication::LoadUserAccount(std::string username, int clientIndex) {
|
|||||||
newAccount.blackListed = sqlite3_column_int(statement, 2);
|
newAccount.blackListed = sqlite3_column_int(statement, 2);
|
||||||
newAccount.whiteListed = sqlite3_column_int(statement, 3);
|
newAccount.whiteListed = sqlite3_column_int(statement, 3);
|
||||||
newAccount.clientIndex = clientIndex;
|
newAccount.clientIndex = clientIndex;
|
||||||
|
newAccount.characterIndex = characterIndex;
|
||||||
|
|
||||||
//finish the routine
|
//finish the routine
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
@@ -109,7 +110,7 @@ int ServerApplication::LoadUserAccount(std::string username, int clientIndex) {
|
|||||||
|
|
||||||
if (ret == SQLITE_DONE) {
|
if (ret == SQLITE_DONE) {
|
||||||
//create the non-existant account instead
|
//create the non-existant account instead
|
||||||
return CreateUserAccount(username, clientIndex);
|
return CreateUserAccount(username, clientIndex, characterIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw(std::runtime_error(std::string() + "Unknown SQL error in LoadUserAccount: " + sqlite3_errmsg(database) ));
|
throw(std::runtime_error(std::string() + "Unknown SQL error in LoadUserAccount: " + sqlite3_errmsg(database) ));
|
||||||
|
|||||||
Reference in New Issue
Block a user