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