The character is visible, fixed a database issue
This commit is contained in:
@@ -301,7 +301,6 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
localCharacter = &character;
|
||||
|
||||
//setup the camera
|
||||
//TODO: can't change the screen size?
|
||||
camera.width = GetScreen()->w;
|
||||
camera.height = GetScreen()->h;
|
||||
|
||||
|
||||
@@ -238,5 +238,11 @@ void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
||||
network.Bind(&argPacket->srcAddress, Channels::SERVER);
|
||||
SetNextScene(SceneList::INWORLD);
|
||||
|
||||
//TODO: send this player's character info
|
||||
//send this player's character info
|
||||
CharacterPacket newPacket;
|
||||
newPacket.type = SerialPacketType::CHARACTER_NEW;
|
||||
strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
||||
newPacket.accountIndex = accountIndex;
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
@@ -21,6 +21,11 @@
|
||||
*/
|
||||
#include "main_menu.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
@@ -53,6 +58,11 @@ MainMenu::MainMenu(ConfigUtility* const argConfig):
|
||||
startButton.SetText("Start");
|
||||
optionsButton.SetText("Options");
|
||||
quitButton.SetText("Quit");
|
||||
|
||||
//debug
|
||||
cout << config["client.username"] << endl;
|
||||
cout << config["client.handle"] << endl;
|
||||
cout << config["client.avatar"] << endl;
|
||||
}
|
||||
|
||||
MainMenu::~MainMenu() {
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
#include "SDL/SDL_net.h"
|
||||
|
||||
#define NETWORK_VERSION 20140607
|
||||
#define PACKET_STRING_SIZE 100
|
||||
constexpr int NETWORK_VERSION = 20140607;
|
||||
constexpr int PACKET_STRING_SIZE = 100;
|
||||
|
||||
struct SerialPacketBase {
|
||||
//members
|
||||
|
||||
@@ -28,8 +28,8 @@ void serializeClient(ClientPacket* packet, void* buffer) {
|
||||
|
||||
SERIALIZE(buffer, &packet->clientIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->username, sizeof(PACKET_STRING_SIZE));
|
||||
// SERIALIZE(buffer, &packet->password, sizeof(PACKET_STRING_SIZE));
|
||||
SERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
|
||||
// SERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
|
||||
}
|
||||
|
||||
void deserializeClient(ClientPacket* packet, void* buffer) {
|
||||
@@ -37,6 +37,6 @@ void deserializeClient(ClientPacket* packet, void* buffer) {
|
||||
|
||||
DESERIALIZE(buffer, &packet->clientIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->username, sizeof(PACKET_STRING_SIZE));
|
||||
// DESERIALIZE(buffer, &packet->password, sizeof(PACKET_STRING_SIZE));
|
||||
DESERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
|
||||
// DESERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
//-------------------------
|
||||
//public methods
|
||||
//-------------------------
|
||||
@@ -233,7 +236,7 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket* const argPacket) {
|
||||
ServerPacket newPacket;
|
||||
|
||||
newPacket.type = SerialPacketType::BROADCAST_RESPONSE;
|
||||
snprintf(newPacket.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str());
|
||||
strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE);
|
||||
newPacket.playerCount = characterMgr.GetContainer()->size();
|
||||
newPacket.version = NETWORK_VERSION;
|
||||
|
||||
@@ -241,6 +244,8 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket* const argPacket) {
|
||||
}
|
||||
|
||||
void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
||||
cout << "Attempting connection: " << argPacket->username << endl;
|
||||
|
||||
//create the new client
|
||||
ClientData newClient;
|
||||
newClient.address = argPacket->srcAddress;
|
||||
@@ -268,6 +273,7 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
||||
}
|
||||
|
||||
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
||||
cout << "Trying to disconnect account " << argPacket->accountIndex << endl;
|
||||
//TODO: authenticate who is disconnecting/kicking
|
||||
|
||||
//forward to the specified client
|
||||
@@ -281,8 +287,10 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
||||
characterMgr.UnloadCharacterIf([&](std::map<int, CharacterData>::iterator it) -> bool {
|
||||
if (argPacket->accountIndex == it->second.owner) {
|
||||
PumpCharacterUnload(it->first);
|
||||
cout << "Deleting character " << it->first << endl;
|
||||
return true;
|
||||
}
|
||||
cout << "Not deleting character " << it->first << endl;
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -338,7 +346,8 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
||||
//-------------------------
|
||||
|
||||
void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
int characterIndex = characterMgr.CreateCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
|
||||
//NOTE: misnomer, try to load the character first
|
||||
int characterIndex = characterMgr.LoadCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
|
||||
|
||||
if (characterIndex == -1) {
|
||||
//TODO: rejection packet
|
||||
@@ -478,8 +487,8 @@ void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int
|
||||
|
||||
//TODO: keep this up to date when the character changes
|
||||
packet->characterIndex = characterIndex;
|
||||
snprintf(packet->handle, PACKET_STRING_SIZE, "%s", character->handle.c_str());
|
||||
snprintf(packet->avatar, PACKET_STRING_SIZE, "%s", character->avatar.c_str());
|
||||
strncpy(packet->handle, character->handle.c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(packet->avatar, character->avatar.c_str(), PACKET_STRING_SIZE);
|
||||
packet->accountIndex = character->owner;
|
||||
packet->roomIndex = character->roomIndex;
|
||||
packet->origin = character->origin;
|
||||
|
||||
Reference in New Issue
Block a user