JOIN_REJECTION works, ready for the rest
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
@@ -192,6 +193,9 @@ void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
case SerialPacketType::JOIN_RESPONSE:
|
case SerialPacketType::JOIN_RESPONSE:
|
||||||
HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
|
HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
|
case SerialPacketType::JOIN_REJECTION:
|
||||||
|
HandleJoinRejection(static_cast<TextPacket*>(argPacket));
|
||||||
|
break;
|
||||||
//handle errors
|
//handle errors
|
||||||
default:
|
default:
|
||||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
||||||
@@ -229,6 +233,11 @@ void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
|||||||
network.SendTo(Channels::SERVER, &newPacket);
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
|
||||||
|
//TODO: Better output
|
||||||
|
std::cerr << "Error: " << argPacket->text << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//server control
|
//server control
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ protected:
|
|||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
void HandleBroadcastResponse(ServerPacket* const);
|
void HandleBroadcastResponse(ServerPacket* const);
|
||||||
void HandleJoinResponse(ClientPacket* const);
|
void HandleJoinResponse(ClientPacket* const);
|
||||||
|
void HandleJoinRejection(TextPacket* const);
|
||||||
|
|
||||||
//server control
|
//server control
|
||||||
void SendBroadcastRequest();
|
void SendBroadcastRequest();
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
case SerialPacketType::JOIN_REJECTION:
|
case SerialPacketType::JOIN_REJECTION:
|
||||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
case SerialPacketType::SHUTDOWN_REJECTION:
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
case SerialPacketType::CHARACTER_REJECTION:
|
||||||
serializeText(buffer, static_cast<TextPacket*>(packet));
|
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,9 +67,14 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
|||||||
//load the user account
|
//load the user account
|
||||||
//TODO: handle passwords
|
//TODO: handle passwords
|
||||||
int accountIndex = accountMgr.LoadAccount(argPacket->username, clientIndex);
|
int accountIndex = accountMgr.LoadAccount(argPacket->username, clientIndex);
|
||||||
|
|
||||||
|
//Error checking
|
||||||
if (accountIndex < 0) {
|
if (accountIndex < 0) {
|
||||||
//TODO: send rejection packet
|
TextPacket newPacket;
|
||||||
std::cerr << "Error: Account already loaded: " << accountIndex << std::endl;
|
newPacket.type = SerialPacketType::JOIN_REJECTION;
|
||||||
|
std::string msg = std::string() + "Account already loaded: " + argPacket->username;
|
||||||
|
strncpy(newPacket.text, msg.c_str(), PACKET_STRING_SIZE); //BUG: If the name is too long this would truncate it
|
||||||
|
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,8 +228,6 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
|||||||
|
|
||||||
//make a new character if this one doesn't exist
|
//make a new character if this one doesn't exist
|
||||||
if (!character) {
|
if (!character) {
|
||||||
//this isn't normal
|
|
||||||
std::cerr << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl;
|
|
||||||
HandleCharacterNew(argPacket);
|
HandleCharacterNew(argPacket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user