Added support for cleaning up after rejection messages
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#config
|
||||
INCLUDES+=.
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,client.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -0,0 +1,23 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "terminal_error.hpp"
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef TERMINALERROR_HPP_
|
||||
#define TERMINALERROR_HPP_
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
class terminal_error: public std::runtime_error {
|
||||
public:
|
||||
explicit terminal_error(const std::string& str): runtime_error(str) {}
|
||||
explicit terminal_error(const char* cstr): runtime_error(cstr) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
#include directories
|
||||
INCLUDES+=. entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
|
||||
INCLUDES+=. client_utilities entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
|
||||
|
||||
#libraries
|
||||
#the order of the $(LIBS) is important, at least for MinGW
|
||||
@@ -25,6 +25,7 @@ OUT=$(addprefix $(OUTDIR)/,client)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
$(MAKE) -C client_utilities
|
||||
$(MAKE) -C entities
|
||||
$(MAKE) -C scenes
|
||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "channels.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include "terminal_error.hpp"
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -103,6 +104,9 @@ void InWorld::Update() {
|
||||
HandlePacket(packetBuffer);
|
||||
}
|
||||
}
|
||||
catch(terminal_error& e) {
|
||||
throw(e);
|
||||
}
|
||||
catch(std::exception& e) {
|
||||
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
|
||||
}
|
||||
@@ -230,6 +234,15 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
||||
HandleRegionContent(static_cast<RegionPacket*>(argPacket));
|
||||
break;
|
||||
|
||||
//rejection messages
|
||||
case SerialPacketType::REGION_REJECTION:
|
||||
case SerialPacketType::CHARACTER_REJECTION:
|
||||
throw(terminal_error(static_cast<TextPacket*>(argPacket)->text));
|
||||
break;
|
||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
||||
throw(std::runtime_error(static_cast<TextPacket*>(argPacket)->text));
|
||||
break;
|
||||
|
||||
//errors
|
||||
default: {
|
||||
std::ostringstream msg;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. .. ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
||||
INCLUDES+=. .. ../client_utilities ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ dumpTable(roomSystem)
|
||||
dumpTable(roomSystem.RoomManager)
|
||||
dumpTable(roomSystem.Room)
|
||||
|
||||
local overworld = roomSystem.RoomManager.CreateRoom("overworld")
|
||||
--NOTE: room 0 is the first that the client asks for, therefore it must exist
|
||||
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld")
|
||||
roomSystem.Room.Initialize(overworld, "overworld.bmp", mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save)
|
||||
|
||||
print("Finished the lua script")
|
||||
|
||||
@@ -107,7 +107,7 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) {
|
||||
network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket));
|
||||
|
||||
//log the error
|
||||
std::cerr << "Error message sent: " << msg << std::endl;
|
||||
std::cerr << "Error message sent: " << newPacket.text << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -233,11 +233,30 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) {
|
||||
}
|
||||
|
||||
//check for fraud
|
||||
if (clientData->GetAddress() != argPacket->srcAddress || accountData->GetAdministrator() != true) {
|
||||
if (clientData->GetAddress() != argPacket->srcAddress) {
|
||||
std::cerr << "Falsified server shutdown detected from: " << accountData->GetUsername() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//reject non-admin requests
|
||||
if (accountData->GetAdministrator() != true) {
|
||||
std::cerr << "Rejected server shutdown command from: " << accountData->GetUsername() << std::endl;
|
||||
|
||||
//build the message
|
||||
std::ostringstream msg;
|
||||
msg << "Invalid admin status";
|
||||
|
||||
//build the packet
|
||||
TextPacket newPacket;
|
||||
newPacket.type = SerialPacketType::SHUTDOWN_REJECTION;
|
||||
strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE);
|
||||
|
||||
//send the rejection message
|
||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//end the server
|
||||
running = false;
|
||||
|
||||
@@ -270,7 +289,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||
|
||||
//log the error
|
||||
std::cerr << "Error message sent: " << msg << std::endl;
|
||||
std::cerr << "Error message sent: " << newPacket.text << std::endl;
|
||||
return;
|
||||
}
|
||||
Region* region = room->GetPager()->GetRegion(argPacket->x, argPacket->y);
|
||||
|
||||
Reference in New Issue
Block a user