Compare commits

..

12 Commits

Author SHA1 Message Date
Kayne Ruse fa4ccb6596 Merge branch 'develop' 2015-02-14 23:54:35 +11:00
Kayne Ruse 87af4f1a1e Comment tweaks, updated network version 2015-02-14 23:54:18 +11:00
Kayne Ruse 18b144fa46 Updated client, read more
It seems like the project as a whole is fairly stable now. I'm prepping to
merge this into master, despite the lack of monsters ATM. Hopefully this
break hasn't affected the stability too much.
2015-02-14 23:39:56 +11:00
Kayne Ruse e71d0b3a09 Finished these server tweaks 2015-02-13 23:34:34 +11:00
Kayne Ruse 9710acad6f Lost focus 2015-02-13 02:57:36 +11:00
Kayne Ruse ca2d4c9217 Expanded network protocol, read more
Not really doing much, just busywork with the server's handlers.

I've tweaked the TODO tags as well.
2015-02-13 02:05:10 +11:00
Kayne Ruse bad6cc2fab Moved ip_operators.*pp to common/utilities 2015-02-05 23:06:22 +11:00
Kayne Ruse 95e3ce9a69 Re-added the network version 2015-02-05 22:24:04 +11:00
Kayne Ruse 5583ba4323 Updated TODO comments 2015-02-04 16:52:22 +11:00
Kayne Ruse a18577665a Updated TODO tags 2015-01-23 03:34:53 +11:00
Kayne Ruse 0bdafe7e15 minor file shuffling 2015-01-21 05:21:14 +11:00
Kayne Ruse 38f6ced633 Filled out some client side monster code 2015-01-21 05:09:55 +11:00
49 changed files with 1233 additions and 879 deletions
+1 -1
View File
@@ -127,7 +127,7 @@ void BaseScene::HandleEvents() {
break;
#ifdef USE_EVENT_JOYSTICK
//TODO: joystick/gamepad support
//EMPTY
#endif
#ifdef USE_EVENT_UNKNOWN
+1 -1
View File
@@ -59,7 +59,7 @@ protected:
virtual void KeyUp(SDL_KeyboardEvent const&) {}
#ifdef USE_EVENT_JOYSTICK
//TODO: joystick/gamepad support
//EMPTY
#endif
#ifdef USE_EVENT_UNKNOWN
+3 -4
View File
@@ -37,7 +37,7 @@
#include "main_menu.hpp"
#include "options_menu.hpp"
#include "lobby_menu.hpp"
#include "in_world.hpp"
#include "world.hpp"
#include "disconnected_screen.hpp"
//-------------------------
@@ -83,7 +83,6 @@ void ClientApplication::Init(int argc, char* argv[]) {
//debug output
//-------------------------
//TODO: enable/disable these with a switch
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
std::cout << "Internal sizes:" << std::endl;
@@ -186,8 +185,8 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&clientIndex, &accountIndex);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&clientIndex, &accountIndex);
case SceneList::WORLD:
activeScene = new World(&clientIndex, &accountIndex);
break;
case SceneList::DISCONNECTEDSCREEN:
activeScene = new DisconnectedScreen();
+23
View File
@@ -21,3 +21,26 @@
*/
#include "base_monster.hpp"
#include "config_utility.hpp"
void BaseMonster::CorrectSprite() {
//TODO: (9) empty
}
std::string BaseMonster::SetHandle(std::string s) {
return handle = s;
}
std::string BaseMonster::GetHandle() const {
return handle;
}
std::string BaseMonster::SetAvatar(std::string s) {
avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1);
return avatar;
}
std::string BaseMonster::GetAvatar() const {
return avatar;
}
+10 -1
View File
@@ -29,8 +29,17 @@ public:
BaseMonster() = default;
virtual ~BaseMonster() = default;
void CorrectSprite();
std::string SetHandle(std::string s);
std::string GetHandle() const;
std::string SetAvatar(std::string s);
std::string GetAvatar() const;
protected:
//
//metadata
std::string handle;
std::string avatar;
};
#endif
+6 -47
View File
@@ -23,54 +23,13 @@
#include <iostream>
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList, Uint8* keyState) {
//skip this if there's no movement
if (motion == 0) {
return false;
}
//determine the simple movement based on input
Vector2 newMotion = {0, 0};
if (keyState[SDLK_w]) {
newMotion.y -= CHARACTER_WALKING_SPEED;
}
if (keyState[SDLK_a]) {
newMotion.x -= CHARACTER_WALKING_SPEED;
}
if (keyState[SDLK_s]) {
newMotion.y += CHARACTER_WALKING_SPEED;
}
if (keyState[SDLK_d]) {
newMotion.x += CHARACTER_WALKING_SPEED;
}
bool ret = false;
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
for(auto& box : boxList) {
if (box.CheckCollision(origin + bounds)) {
//push the character to the closest non-contact position
Vector2 shift = box.CalcShift(origin + bounds);
origin += shift;
//set any motion in that direction to zero
if (shift.x != 0) {
newMotion.x = 0;
}
if (shift.y != 0) {
newMotion.y = 0;
}
ret = true;
if (box.CheckOverlap(origin + bounds)) {
origin -= motion;
motion = {0, 0};
return true;
}
}
//handle diagonals
if (newMotion.x != 0 && newMotion.y != 0) {
newMotion *= CHARACTER_WALKING_MOD;
}
//set the new motion
motion = newMotion;
//signal for updates
return ret;
return false;
}
+1 -1
View File
@@ -33,7 +33,7 @@ public:
LocalCharacter() = default;
virtual ~LocalCharacter() = default;
bool ProcessCollisionGrid(std::list<BoundingBox>, Uint8* keyState);
bool ProcessCollisionGrid(std::list<BoundingBox>);
private:
//NOTE: NO MEMBERS
@@ -1,264 +0,0 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "in_world.hpp"
#include "channels.hpp"
#include "ip_operators.hpp"
#include "terminal_error.hpp"
#include <chrono>
#include <sstream>
#include <stdexcept>
//-------------------------
//Basic connections
//-------------------------
void InWorld::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
//heartbeat system
case SerialPacketType::PING:
HandlePing(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::PONG:
HandlePong(static_cast<ServerPacket*>(argPacket));
break;
//game server connections
case SerialPacketType::LOGOUT_RESPONSE:
HandleLogoutResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT_RESPONSE:
HandleDisconnectResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT_FORCED:
HandleDisconnectForced(static_cast<ClientPacket*>(argPacket));
break;
//map management
case SerialPacketType::REGION_CONTENT:
HandleRegionContent(static_cast<RegionPacket*>(argPacket));
break;
//character management
case SerialPacketType::CHARACTER_CREATE:
HandleCharacterCreate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DELETE:
HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_EXISTS:
HandleCharacterQueryExists(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_MOVEMENT:
HandleCharacterMovement(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_ATTACK:
HandleCharacterAttack(static_cast<CharacterPacket*>(argPacket));
break;
//monster management
case SerialPacketType::MONSTER_CREATE:
HandleMonsterCreate(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_DELETE:
HandleMonsterDelete(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_EXISTS:
HandleMonsterQueryExists(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_MOVEMENT:
HandleMonsterMovement(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_ATTACK:
HandleMonsterAttack(static_cast<MonsterPacket*>(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;
msg << "Unknown SerialPacketType encountered in InWorld: " << static_cast<int>(argPacket->type);
throw(std::runtime_error(msg.str()));
}
break;
}
}
void InWorld::HandlePing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void InWorld::HandlePong(ServerPacket* const argPacket) {
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
throw(std::runtime_error("Heartbeat message received from an unknown source"));
}
attemptedBeats = 0;
lastBeat = Clock::now();
}
//-------------------------
//Connection control
//-------------------------
void InWorld::SendLogoutRequest() {
ClientPacket newPacket;
//send a logout request
newPacket.type = SerialPacketType::LOGOUT_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::SendDisconnectRequest() {
ClientPacket newPacket;
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
newPacket.clientIndex = clientIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::SendShutdownRequest() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::SHUTDOWN_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
if (localCharacter) {
characterMap.erase(characterIndex);
localCharacter = nullptr;
}
accountIndex = -1;
characterIndex = -1;
//reset the camera
camera.marginX = camera.marginY = 0;
//because, why not? I guess...
SendDisconnectRequest();
}
void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
HandleLogoutResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
}
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
HandleDisconnectResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
}
void InWorld::CheckHeartBeat() {
//check the connection (heartbeat)
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
//escape to the disconnect screen
SendDisconnectRequest();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
else {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
}
}
//-------------------------
//map management
//-------------------------
void InWorld::SendRegionRequest(int roomIndex, int x, int y) {
RegionPacket packet;
//pack the region's data
packet.type = SerialPacketType::REGION_REQUEST;
packet.roomIndex = roomIndex;
packet.x = x;
packet.y = y;
network.SendTo(Channels::SERVER, &packet);
}
void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
//replace existing regions
regionPager.UnloadIf([&](Region const& region) -> bool {
return region.GetX() == argPacket->x && region.GetY() == argPacket->y;
});
regionPager.PushRegion(argPacket->region);
//clean up after the serial code
delete argPacket->region;
argPacket->region = nullptr;
}
void InWorld::UpdateMap() {
if (roomIndex == -1) {
return;
}
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1)
int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT;
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
//prune distant regions
regionPager.GetContainer()->remove_if([&](Region const& region) -> bool {
return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd;
});
//request empty regions within this zone
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
if (!regionPager.FindRegion(i, j)) {
SendRegionRequest(roomIndex, i, j);
}
}
}
}
-253
View File
@@ -1,253 +0,0 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "in_world.hpp"
#include "channels.hpp"
#include "terminal_error.hpp"
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
//-------------------------
//Public access members
//-------------------------
InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
keyState(SDL_GetKeyState(nullptr))
{
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
disconnectButton.SetImage(&buttonImage);
disconnectButton.SetFont(&font);
shutDownButton.SetImage(&buttonImage);
shutDownButton.SetFont(&font);
//set the button positions
disconnectButton.SetX(50);
disconnectButton.SetY(50 + buttonImage.GetClipH() * 0);
shutDownButton.SetX(50);
shutDownButton.SetY(50 + buttonImage.GetClipH() * 1);
//set the button texts
disconnectButton.SetText("Disconnect");
shutDownButton.SetText("Shut Down");
//load the tilesheet
//TODO: add the tilesheet to the map system
//TODO: Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
//Send the character data
//TODO: login scene, prompt, etc.
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_LOAD;
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);
//query the world state
memset(&newPacket, 0, MAX_PACKET_SIZE);
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
//set the camera's values
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//debug
//
}
InWorld::~InWorld() {
//unload the local data
characterMap.clear();
monsterMap.clear();
}
//-------------------------
//Frame loop
//-------------------------
void InWorld::FrameStart() {
//
}
void InWorld::Update() {
//create and zero the buffer
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
memset(packetBuffer, 0, MAX_PACKET_SIZE);
try {
//suck in and process all waiting packets
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
}
catch(terminal_error& e) {
throw(e);
}
catch(std::exception& e) {
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
}
//free the buffer
delete reinterpret_cast<char*>(packetBuffer);
//heartbeat system
CheckHeartBeat();
//update all entities
for (auto& it : characterMap) {
it.second.Update();
}
for (auto& it : monsterMap) {
it.second.Update();
}
//update the map
UpdateMap();
//skip the rest without a local character
if (!localCharacter) {
return;
}
//get the collidable boxes
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
//process the collisions
if (localCharacter->ProcessCollisionGrid(boxList, keyState)) {
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
//update the camera
camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY;
}
void InWorld::FrameEnd() {
//
}
void InWorld::RenderFrame() {
SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void InWorld::Render(SDL_Surface* const screen) {
//draw the map
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
}
//draw the entities
for (auto& it : characterMap) {
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y);
}
for (auto& it : monsterMap) {
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y);
}
//draw UI
disconnectButton.DrawTo(screen);
shutDownButton.DrawTo(screen);
std::ostringstream msg;
msg << fps.GetFrameRate();
font.DrawStringTo(msg.str(), screen, 0, 0);
}
//-------------------------
//Event handlers
//-------------------------
void InWorld::QuitEvent() {
//two-step logout
SendDisconnectRequest();
SetNextScene(SceneList::QUIT);
}
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
disconnectButton.MouseMotion(motion);
shutDownButton.MouseMotion(motion);
}
void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) {
disconnectButton.MouseButtonDown(button);
shutDownButton.MouseButtonDown(button);
}
void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendLogoutRequest();
}
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendShutdownRequest();
}
}
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
//hotkeys & player input
switch(key.keysym.sym) {
case SDLK_ESCAPE:
//TODO: the escape key should actually control menus and stuff
SendLogoutRequest();
return;
case SDLK_w:
case SDLK_a:
case SDLK_s:
case SDLK_d:
ProcessLocalCharacterMovement();
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
}
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_w:
case SDLK_a:
case SDLK_s:
case SDLK_d:
ProcessLocalCharacterMovement();
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
}
@@ -49,11 +49,11 @@
#include <chrono>
class InWorld : public BaseScene {
class World: public BaseScene {
public:
//Public access members
InWorld(int* const argClientIndex, int* const argAccountIndex);
~InWorld();
World(int* const argClientIndex, int* const argAccountIndex);
~World();
protected:
//Frame loop
@@ -71,43 +71,56 @@ protected:
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//Basic connections
//handle incoming traffic
void HandlePacket(SerialPacket* const);
void HandlePing(ServerPacket* const);
void HandlePong(ServerPacket* const);
//Connection control
void SendLogoutRequest();
void SendDisconnectRequest();
void SendShutdownRequest();
void HandleLogoutResponse(ClientPacket* const);
void HandleDisconnectResponse(ClientPacket* const);
void HandleDisconnectForced(ClientPacket* const);
//heartbeat system
void hPing(ServerPacket* const);
void hPong(ServerPacket* const);
void CheckHeartBeat();
//basic connections
void SendLogoutRequest();
void SendDisconnectRequest();
void SendAdminDisconnectForced();
void SendAdminShutdownRequest();
void hLogoutResponse(ClientPacket* const);
void hDisconnectResponse(ClientPacket* const);
void hAdminDisconnectForced(ClientPacket* const);
//map management
void SendRegionRequest(int roomIndex, int x, int y);
void HandleRegionContent(RegionPacket* const);
void hRegionContent(RegionPacket* const);
void UpdateMap();
//character management
void HandleCharacterCreate(CharacterPacket* const);
void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterQueryExists(CharacterPacket* const);
void HandleCharacterMovement(CharacterPacket* const);
void HandleCharacterAttack(CharacterPacket* const);
void hCharacterCreate(CharacterPacket* const);
void hCharacterDelete(CharacterPacket* const);
void hQueryCharacterExists(CharacterPacket* const);
void hQueryCharacterStats(CharacterPacket* const);
void hQueryCharacterLocation(CharacterPacket* const);
void hCharacterMovement(CharacterPacket* const);
void hCharacterAttack(CharacterPacket* const);
void hCharacterDamage(CharacterPacket* const);
//monster management
void HandleMonsterCreate(MonsterPacket* const);
void HandleMonsterDelete(MonsterPacket* const);
void HandleMonsterQueryExists(MonsterPacket* const);
void HandleMonsterMovement(MonsterPacket* const);
void HandleMonsterAttack(MonsterPacket* const);
void hMonsterCreate(MonsterPacket* const);
void hMonsterDelete(MonsterPacket* const);
void hQueryMonsterExists(MonsterPacket* const);
void hQueryMonsterStats(MonsterPacket* const);
void hQueryMonsterLocation(MonsterPacket* const);
void hMonsterMovement(MonsterPacket* const);
void hMonsterAttack(MonsterPacket* const);
void hMonsterDamage(MonsterPacket* const);
//player movement
void ProcessLocalCharacterMovement();
//chat
void hTextBroadcast(TextPacket* const);
void hTextSpeech(TextPacket* const);
void hTextWhisper(TextPacket* const);
//general gameplay
void SendLocalCharacterMovement();
std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight);
@@ -143,7 +156,7 @@ protected:
LocalCharacter* localCharacter = nullptr;
//heartbeat
//TODO: Heartbeat needs it's own utility
//TODO: (2) Heartbeat needs it's own utility
typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now();
int attemptedBeats = 0;
@@ -151,7 +164,6 @@ protected:
//ugly references; I hate this
ConfigUtility& config = ConfigUtility::GetSingleton();
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
Uint8* keyState = nullptr;
};
#endif
@@ -19,7 +19,7 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "in_world.hpp"
#include "world.hpp"
#include "channels.hpp"
@@ -35,7 +35,7 @@
//DOCS: new characters will result in create messages
//DOCS: this client's character will exist in both (skipped)
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
void World::hCharacterCreate(CharacterPacket* const argPacket) {
//prevent double message
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
std::ostringstream msg;
@@ -51,7 +51,7 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
//fill the character's info
character->SetOrigin(argPacket->origin);
character->SetMotion(argPacket->motion);
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); //TODO: (1) send the bounds from the server
character->SetHandle(argPacket->handle);
character->SetAvatar(argPacket->avatar);
character->SetOwner(argPacket->accountIndex);
@@ -71,10 +71,10 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
}
//debug
std::cout << "Create, total: " << characterMap.size() << std::endl;
std::cout << "Character Create, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
void World::hCharacterDelete(CharacterPacket* const argPacket) {
//ignore if this character doesn't exist
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt == characterMap.end()) {
@@ -97,10 +97,10 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
characterMap.erase(characterIt);
//debug
std::cout << "Delete, total: " << characterMap.size() << std::endl;
std::cout << "Character Delete, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
void World::hQueryCharacterExists(CharacterPacket* const argPacket) {
//prevent a double message about this player's character
if (argPacket->accountIndex == accountIndex) {
return;
@@ -124,11 +124,19 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
character->CorrectSprite();
//debug
std::cout << "Query, total: " << characterMap.size() << std::endl;
std::cout << "Character Query, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterMovement(CharacterPacket* const argPacket) {
//TODO: Authentication
void World::hQueryCharacterStats(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
void World::hQueryCharacterLocation(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
void World::hCharacterMovement(CharacterPacket* const argPacket) {
//TODO: (1) Authentication
if (argPacket->characterIndex == characterIndex) {
return;
}
@@ -143,72 +151,19 @@ void InWorld::HandleCharacterMovement(CharacterPacket* const argPacket) {
}
}
void InWorld::HandleCharacterAttack(CharacterPacket* const argPacket) {
//TODO: attack animation
void World::hCharacterAttack(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
void World::hCharacterDamage(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
//-------------------------
//monster management
//player movement & collision
//-------------------------
void InWorld::HandleMonsterCreate(MonsterPacket* const argPacket) {
//TODO
}
void InWorld::HandleMonsterDelete(MonsterPacket* const argPacket) {
//TODO
}
void InWorld::HandleMonsterQueryExists(MonsterPacket* const argPacket) {
//TODO
}
void InWorld::HandleMonsterMovement(MonsterPacket* const argPacket) {
//TODO
}
void InWorld::HandleMonsterAttack(MonsterPacket* const argPacket) {
//TODO
}
//-------------------------
//player movement
//-------------------------
void InWorld::ProcessLocalCharacterMovement() {
//character movement
if (!localCharacter) {
return;
}
Vector2 newMotion = {0, 0};
if (keyState[SDLK_w]) {
newMotion.y -= CHARACTER_WALKING_SPEED;
}
if (keyState[SDLK_a]) {
newMotion.x -= CHARACTER_WALKING_SPEED;
}
if (keyState[SDLK_s]) {
newMotion.y += CHARACTER_WALKING_SPEED;
}
if (keyState[SDLK_d]) {
newMotion.x += CHARACTER_WALKING_SPEED;
}
//handle diagonals
if (newMotion.x != 0 && newMotion.y != 0) {
newMotion *= CHARACTER_WALKING_MOD;
}
//set the info
if (localCharacter->GetMotion() != newMotion) {
localCharacter->SetMotion(newMotion);
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
}
void InWorld::SendLocalCharacterMovement() {
void World::SendLocalCharacterMovement() {
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
@@ -221,7 +176,7 @@ void InWorld::SendLocalCharacterMovement() {
network.SendTo(Channels::SERVER, &newPacket);
}
std::list<BoundingBox> InWorld::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) {
std::list<BoundingBox> World::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) {
//prepare for collisions
BoundingBox wallBounds = {0, 0, tileWidth, tileHeight};
std::list<BoundingBox> boxList;
+39
View File
@@ -0,0 +1,39 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
//-------------------------
//chat
//-------------------------
void World::hTextBroadcast(TextPacket* const argPacket) {
//TODO: (9) empty
}
void World::hTextSpeech(TextPacket* const argPacket) {
//TODO: (9) empty
}
void World::hTextWhisper(TextPacket* const argPacket) {
//TODO: (9) empty
}
@@ -0,0 +1,135 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
#include "ip_operators.hpp"
#include <chrono>
#include <sstream>
#include <stdexcept>
//-------------------------
//heartbeat system
//-------------------------
void World::hPing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void World::hPong(ServerPacket* const argPacket) {
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
throw(std::runtime_error("Heartbeat message received from an unknown source"));
}
attemptedBeats = 0;
lastBeat = Clock::now();
}
void World::CheckHeartBeat() {
//check the connection (heartbeat)
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
//escape to the disconnect screen
SendDisconnectRequest();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
else {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
}
}
//-------------------------
//Connection control
//-------------------------
void World::SendLogoutRequest() {
ClientPacket newPacket;
//send a logout request
newPacket.type = SerialPacketType::LOGOUT_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void World::SendDisconnectRequest() {
ClientPacket newPacket;
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
newPacket.clientIndex = clientIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void World::SendAdminDisconnectForced() {
//TODO: (9) empty
}
void World::SendAdminShutdownRequest() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::ADMIN_SHUTDOWN_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void World::hLogoutResponse(ClientPacket* const argPacket) {
if (localCharacter) {
characterMap.erase(characterIndex);
localCharacter = nullptr;
}
accountIndex = -1;
characterIndex = -1;
//reset the camera
camera.marginX = camera.marginY = 0;
//because, why not? I guess...
SendDisconnectRequest();
}
void World::hDisconnectResponse(ClientPacket* const argPacket) {
hLogoutResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
}
void World::hAdminDisconnectForced(ClientPacket* const argPacket) {
hDisconnectResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
}
+418
View File
@@ -0,0 +1,418 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
#include "terminal_error.hpp"
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
//-------------------------
//Public access members
//-------------------------
World::World(int* const argClientIndex, int* const argAccountIndex):
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
{
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
disconnectButton.SetImage(&buttonImage);
disconnectButton.SetFont(&font);
shutDownButton.SetImage(&buttonImage);
shutDownButton.SetFont(&font);
//set the button positions
disconnectButton.SetX(50);
disconnectButton.SetY(50 + buttonImage.GetClipH() * 0);
shutDownButton.SetX(50);
shutDownButton.SetY(50 + buttonImage.GetClipH() * 1);
//set the button texts
disconnectButton.SetText("Disconnect");
shutDownButton.SetText("Shut Down");
//load the tilesheet
//TODO: (1) Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
//Send the character data
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_LOAD;
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);
//query the world state
memset(&newPacket, 0, MAX_PACKET_SIZE);
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
newPacket.type = SerialPacketType::QUERY_MONSTER_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
//set the camera's values
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//debug
//
}
World::~World() {
//unload the local data
characterMap.clear();
monsterMap.clear();
}
//-------------------------
//Frame loop
//-------------------------
void World::FrameStart() {
//
}
void World::Update() {
//create and zero the buffer
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
memset(packetBuffer, 0, MAX_PACKET_SIZE);
try {
//suck in and process all waiting packets
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
}
catch(terminal_error& e) {
throw(e);
}
catch(std::exception& e) {
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
}
//free the buffer
delete reinterpret_cast<char*>(packetBuffer);
//heartbeat system
CheckHeartBeat();
//update all entities
for (auto& it : characterMap) {
it.second.Update();
}
for (auto& it : monsterMap) {
it.second.Update();
}
//update the map
UpdateMap();
//skip the rest without a local character
if (!localCharacter) {
return;
}
//get the collidable boxes
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
//process the collisions
if (localCharacter->ProcessCollisionGrid(boxList)) {
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
//update the camera
camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY;
}
void World::FrameEnd() {
//
}
void World::RenderFrame() {
// SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void World::Render(SDL_Surface* const screen) {
//draw the map
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
}
//draw the entities
for (auto& it : characterMap) {
//TODO: (1) depth ordering
it.second.DrawTo(screen, camera.x, camera.y);
}
for (auto& it : monsterMap) {
it.second.DrawTo(screen, camera.x, camera.y);
}
//draw UI
disconnectButton.DrawTo(screen);
shutDownButton.DrawTo(screen);
std::ostringstream msg;
msg << fps.GetFrameRate();
font.DrawStringTo(msg.str(), screen, 0, 0);
}
//-------------------------
//Event handlers
//-------------------------
void World::QuitEvent() {
//two-step logout
SendDisconnectRequest();
SetNextScene(SceneList::QUIT);
}
void World::MouseMotion(SDL_MouseMotionEvent const& motion) {
disconnectButton.MouseMotion(motion);
shutDownButton.MouseMotion(motion);
}
void World::MouseButtonDown(SDL_MouseButtonEvent const& button) {
disconnectButton.MouseButtonDown(button);
shutDownButton.MouseButtonDown(button);
}
void World::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendLogoutRequest();
}
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendAdminShutdownRequest();
}
}
void World::KeyDown(SDL_KeyboardEvent const& key) {
//hotkeys
switch(key.keysym.sym) {
case SDLK_ESCAPE:
//TODO: (1) the escape key should actually control menus and stuff
SendLogoutRequest();
return;
}
//character movement
if (!localCharacter) {
return;
}
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
case SDLK_w:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_a:
motion.x -= CHARACTER_WALKING_SPEED;
break;
case SDLK_s:
motion.y += CHARACTER_WALKING_SPEED;
break;
case SDLK_d:
motion.x += CHARACTER_WALKING_SPEED;
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
void World::KeyUp(SDL_KeyboardEvent const& key) {
//character movement
if (!localCharacter) {
return;
}
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
case SDLK_w:
motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED);
break;
case SDLK_a:
motion.x = std::min(0.0, motion.x += CHARACTER_WALKING_SPEED);
break;
case SDLK_s:
motion.y = std::max(0.0, motion.y -= CHARACTER_WALKING_SPEED);
break;
case SDLK_d:
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED);
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
//BUGFIX: reset cardinal direction speed on key release
if (motion.x > 0) {
motion.x = CHARACTER_WALKING_SPEED;
}
else if (motion.x < 0) {
motion.x = -CHARACTER_WALKING_SPEED;
}
if (motion.y > 0) {
motion.y = CHARACTER_WALKING_SPEED;
}
else if (motion.y < 0) {
motion.y = -CHARACTER_WALKING_SPEED;
}
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
//-------------------------
//Direct incoming traffic
//-------------------------
void World::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
//heartbeat system
case SerialPacketType::PING:
hPing(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::PONG:
hPong(static_cast<ServerPacket*>(argPacket));
break;
//game server connections
case SerialPacketType::LOGOUT_RESPONSE:
hLogoutResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT_RESPONSE:
hDisconnectResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
hAdminDisconnectForced(static_cast<ClientPacket*>(argPacket));
break;
//map management
case SerialPacketType::REGION_CONTENT:
hRegionContent(static_cast<RegionPacket*>(argPacket));
break;
//character management
case SerialPacketType::CHARACTER_CREATE:
hCharacterCreate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DELETE:
hCharacterDelete(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_EXISTS:
hQueryCharacterExists(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_STATS:
hQueryCharacterStats(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_LOCATION:
hQueryCharacterLocation(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_MOVEMENT:
hCharacterMovement(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_ATTACK:
hCharacterAttack(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DAMAGE:
hCharacterDamage(static_cast<CharacterPacket*>(argPacket));
break;
//monster management
case SerialPacketType::MONSTER_CREATE:
hMonsterCreate(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_DELETE:
hMonsterDelete(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_EXISTS:
hQueryMonsterExists(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_STATS:
hQueryMonsterStats(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_LOCATION:
hQueryMonsterLocation(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_MOVEMENT:
hMonsterMovement(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_ATTACK:
hMonsterAttack(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_DAMAGE:
hMonsterDamage(static_cast<MonsterPacket*>(argPacket));
break;
//chat
case SerialPacketType::TEXT_BROADCAST:
hTextBroadcast(static_cast<TextPacket*>(argPacket));
break;
case SerialPacketType::TEXT_SPEECH:
hTextSpeech(static_cast<TextPacket*>(argPacket));
break;
case SerialPacketType::TEXT_WHISPER:
hTextWhisper(static_cast<TextPacket*>(argPacket));
break;
//general rejection messages
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::QUERY_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;
msg << "Unknown SerialPacketType encountered in World: " << static_cast<int>(argPacket->type);
throw(std::runtime_error(msg.str()));
}
break;
}
}
+79
View File
@@ -0,0 +1,79 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
//-------------------------
//map management
//-------------------------
void World::SendRegionRequest(int roomIndex, int x, int y) {
RegionPacket packet;
//pack the region's data
packet.type = SerialPacketType::REGION_REQUEST;
packet.roomIndex = roomIndex;
packet.x = x;
packet.y = y;
network.SendTo(Channels::SERVER, &packet);
}
void World::hRegionContent(RegionPacket* const argPacket) {
//replace existing regions
regionPager.UnloadIf([&](Region const& region) -> bool {
return region.GetX() == argPacket->x && region.GetY() == argPacket->y;
});
regionPager.PushRegion(argPacket->region);
//clean up after the serial code
delete argPacket->region;
argPacket->region = nullptr;
}
void World::UpdateMap() {
if (roomIndex == -1) {
return;
}
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1)
int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT;
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
//prune distant regions
regionPager.GetContainer()->remove_if([&](Region const& region) -> bool {
return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd;
});
//request empty regions within this zone
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
if (!regionPager.FindRegion(i, j)) {
SendRegionRequest(roomIndex, i, j);
}
}
}
}
+126
View File
@@ -0,0 +1,126 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
#include <iostream>
#include <sstream>
#include <stdexcept>
//-------------------------
//monster management
//-------------------------
void World::hMonsterCreate(MonsterPacket* const argPacket) {
//check for logic errors
if (monsterMap.find(argPacket->monsterIndex) != monsterMap.end()) {
std::ostringstream msg;
msg << "Double monster creation event; ";
msg << "Index: " << argPacket->monsterIndex << "; ";
msg << "Handle: " << argPacket->handle;
throw(std::runtime_error(msg.str()));
}
//ignore monsters from other rooms
if (roomIndex != argPacket->roomIndex) {
//temporary error checking
std::ostringstream msg;
msg << "Monster from the wrong room received: ";
msg << "monsterIndex: " << argPacket->monsterIndex << ", roomIndex: " << argPacket->roomIndex;
throw(std::runtime_error(msg.str()));
}
//implicitly create the element
BaseMonster* monster = &monsterMap[argPacket->monsterIndex];
//fill the monster's info
monster->SetHandle(argPacket->handle);
monster->SetAvatar(argPacket->avatar);
monster->SetBounds(argPacket->bounds);
monster->SetOrigin(argPacket->origin);
monster->SetMotion(argPacket->motion);
//debug
std::cout << "Monster Create, total: " << monsterMap.size() << std::endl;
}
void World::hMonsterDelete(MonsterPacket* const argPacket) {
//ignore if this monster doesn't exist
std::map<int, BaseMonster>::iterator monsterIt = monsterMap.find(argPacket->monsterIndex);
if (monsterIt == monsterMap.end()) {
return;
}
//remove this monster
monsterMap.erase(monsterIt);
//debug
std::cout << "Monster Delete, total: " << monsterMap.size() << std::endl;
}
void World::hQueryMonsterExists(MonsterPacket* const argPacket) {
//ignore monsters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
return;
}
//implicitly create the element
BaseMonster* monster = &monsterMap[argPacket->monsterIndex];
//fill the monster's info
monster->SetHandle(argPacket->handle);
monster->SetAvatar(argPacket->avatar);
monster->SetBounds(argPacket->bounds);
monster->SetOrigin(argPacket->origin);
monster->SetMotion(argPacket->motion);
//debug
std::cout << "Monster Query, total: " << monsterMap.size() << std::endl;
}
void World::hQueryMonsterStats(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
void World::hQueryMonsterLocation(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
void World::hMonsterMovement(MonsterPacket* const argPacket) {
//ignore if this monster doesn't exist
std::map<int, BaseMonster>::iterator monsterIt = monsterMap.find(argPacket->monsterIndex);
if (monsterIt == monsterMap.end()) {
return;
}
monsterIt->second.SetOrigin(argPacket->origin);
monsterIt->second.SetOrigin(argPacket->motion);
}
void World::hMonsterAttack(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
void World::hMonsterDamage(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
+6 -8
View File
@@ -100,14 +100,14 @@ void LobbyMenu::FrameEnd() {
}
void LobbyMenu::Render(SDL_Surface* const screen) {
//TODO: I need a proper UI system for the entire client and the editor
//TODO: (2) I need a proper UI system for the entire client and the editor
//UI
search.DrawTo(screen);
join.DrawTo(screen);
back.DrawTo(screen);
//TODO: draw headers for the server list
//TODO: (1) draw headers for the server list
for (int i = 0; i < serverInfo.size(); i++) {
//draw the selected server's highlight
if (selection == &serverInfo[i]) {
@@ -131,8 +131,6 @@ void LobbyMenu::Render(SDL_Surface* const screen) {
if (!serverInfo[i].compatible) {
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
}
//TODO: ping/delay?
}
}
@@ -166,7 +164,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//has the user selected a server on the list?
BoundingBox tmpBox = listBox;
tmpBox.h *= serverInfo.size();
if (tmpBox.CheckCollision({button.x, button.y, 0, 0})) {
if (tmpBox.CheckOverlap({button.x, button.y})) {
selection = &serverInfo[(button.y - listBox.y)/listBox.h];
}
else {
@@ -250,15 +248,15 @@ void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) {
throw(std::runtime_error("Client index invalid during login"));
}
accountIndex = argPacket->accountIndex;
SetNextScene(SceneList::INWORLD);
SetNextScene(SceneList::WORLD);
}
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
//TODO: Better output for join rejection
//TODO: (9) empty
}
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
//TODO: Better output for login rejection
//TODO: (9) empty
}
//-------------------------
+7 -4
View File
@@ -88,8 +88,7 @@ void MainMenu::Render(SDL_Surface* const screen) {
//text
font.DrawStringTo("Thanks for playing!", screen, 50, screen->h - 50 - image.GetClipH() * 2);
font.DrawStringTo("You can get the latest version at: ", screen, 50, screen->h - 50 - image.GetClipH() * 1);
font.DrawStringTo("https://github.com/Ratstail91/Tortuga", screen, 50, screen->h - 50 - image.GetClipH() * 0);
//TODO: replace this with a website address
font.DrawStringTo("krgamestudios.com", screen, 50, screen->h - 50 - image.GetClipH() * 0);
}
//-------------------------
@@ -109,7 +108,7 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
}
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//TODO: Buttons should only register as "selected" when the left button is used
//TODO: (2) Buttons should only register as "selected" when the left button is used
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::LOBBYMENU);
}
@@ -126,5 +125,9 @@ void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
}
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
//
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
}
+1 -1
View File
@@ -28,7 +28,7 @@
#include "raster_font.hpp"
#include "button.hpp"
//TODO: The options screen needs to be USED
//NOTE: The options screen needs to be USED
class OptionsMenu : public BaseScene {
public:
//Public access members
+1 -1
View File
@@ -33,7 +33,7 @@ enum class SceneList {
MAINMENU,
OPTIONSMENU,
LOBBYMENU,
INWORLD,
WORLD,
DISCONNECTEDSCREEN,
};
@@ -34,14 +34,11 @@ struct CharacterPacket : SerialPacketBase {
//the owner
int accountIndex;
//TODO: Authentication token?
//location
int roomIndex;
Vector2 origin;
Vector2 motion;
//gameplay components: equipment, items, buffs, debuffs...
};
void serializeCharacter(void* buffer, CharacterPacket* packet);
@@ -28,6 +28,7 @@ struct ClientPacket : SerialPacketBase {
int clientIndex;
int accountIndex;
char username[PACKET_STRING_SIZE];
//TODO: (9) password, auth token
};
void serializeClient(void* buffer, ClientPacket* packet);
@@ -44,9 +44,6 @@ void serializeMonster(void* buffer, MonsterPacket* packet) {
serialCopy(&buffer, &packet->origin.y, sizeof(double));
serialCopy(&buffer, &packet->motion.x, sizeof(double));
serialCopy(&buffer, &packet->motion.y, sizeof(double));
//attack data
//TODO
}
void deserializeMonster(void* buffer, MonsterPacket* packet) {
@@ -70,7 +67,4 @@ void deserializeMonster(void* buffer, MonsterPacket* packet) {
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
//attack data
//TODO
}
@@ -38,8 +38,6 @@ struct MonsterPacket : SerialPacketBase {
int roomIndex;
Vector2 origin;
Vector2 motion;
//TODO: attack data
};
void serializeMonster(void* buffer, MonsterPacket* packet);
@@ -29,6 +29,12 @@ void serializeText(void* buffer, TextPacket* packet) {
//content
serialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
serialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
//location
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
serialCopy(&buffer, &packet->origin.x, sizeof(double));
serialCopy(&buffer, &packet->origin.y, sizeof(double));
serialCopy(&buffer, &packet->range, sizeof(int));
}
void deserializeText(void* buffer, TextPacket* packet) {
@@ -37,4 +43,10 @@ void deserializeText(void* buffer, TextPacket* packet) {
//content
deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
deserialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
//location
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
deserialCopy(&buffer, &packet->range, sizeof(int));
}
@@ -24,9 +24,14 @@
#include "serial_packet_base.hpp"
#include "vector2.hpp"
struct TextPacket : SerialPacketBase {
char name[PACKET_STRING_SIZE];
char text[PACKET_STRING_SIZE];
int roomIndex;
Vector2 origin;
int range;
};
void serializeText(void* buffer, TextPacket* packet);
+1 -1
View File
@@ -34,7 +34,7 @@
typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = -1;
constexpr int NETWORK_VERSION = 20150214;
union MaxPacket {
CharacterPacket a;
+15 -12
View File
@@ -27,7 +27,6 @@
* valid data, but it will still be carried in that packet's format.
*/
//TODO: This needs to be smoothed out
enum class SerialPacketType {
//default: there is something wrong
NONE,
@@ -57,7 +56,7 @@ enum class SerialPacketType {
//disconnect from the server
DISCONNECT_REQUEST,
DISCONNECT_RESPONSE,
DISCONNECT_FORCED,
ADMIN_DISCONNECT_FORCED,
//load the account
LOGIN_REQUEST,
@@ -68,7 +67,7 @@ enum class SerialPacketType {
LOGOUT_RESPONSE,
//shut down the server
SHUTDOWN_REQUEST,
ADMIN_SHUTDOWN_REQUEST,
//-------------------------
//RegionPacket
@@ -76,7 +75,7 @@ enum class SerialPacketType {
//-------------------------
//map data
REGION_REQUEST, //NOTE: technically a query
REGION_REQUEST,
REGION_CONTENT,
//-------------------------
@@ -84,8 +83,7 @@ enum class SerialPacketType {
// character index,
// handle, avatar,
// account index (owner),
// room index, origin, motion,
// statistics
// room index, origin, motion
//-------------------------
//character management
@@ -102,6 +100,7 @@ enum class SerialPacketType {
//set the info in the server
CHARACTER_MOVEMENT,
CHARACTER_ATTACK,
CHARACTER_DAMAGE,
//admin control
// ADMIN_SET_CHARACTER_ORIGIN,
@@ -109,20 +108,21 @@ enum class SerialPacketType {
//-------------------------
//MonsterPacket
// monster index,
// handle, avatar, hitbox
// handle, avatar
// bounds
// room index, origin, motion
// TODO: attack data
//-------------------------
MONSTER_CREATE,
MONSTER_DELETE,
QUERY_MONSTER_EXISTS, //a list of monsters in a room
QUERY_MONSTER_STATS, //statistics of a specific monster type or instance
QUERY_MONSTER_LOCATION, //umm...
QUERY_MONSTER_EXISTS,
QUERY_MONSTER_STATS,
QUERY_MONSTER_LOCATION,
MONSTER_MOVEMENT, //monster movement
MONSTER_MOVEMENT,
MONSTER_ATTACK,
MONSTER_DAMAGE,
//-------------------------
//TextPacket
@@ -131,6 +131,8 @@ enum class SerialPacketType {
//general speech
TEXT_BROADCAST,
TEXT_SPEECH,
TEXT_WHISPER,
//rejection/error messages
JOIN_REJECTION,
@@ -139,6 +141,7 @@ enum class SerialPacketType {
CHARACTER_REJECTION,
MONSTER_REJECTION,
SHUTDOWN_REJECTION,
QUERY_REJECTION,
//-------------------------
//not used
+14 -4
View File
@@ -57,12 +57,12 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::DISCONNECT_REQUEST:
case SerialPacketType::DISCONNECT_RESPONSE:
case SerialPacketType::DISCONNECT_FORCED:
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
case SerialPacketType::LOGIN_REQUEST:
case SerialPacketType::LOGIN_RESPONSE:
case SerialPacketType::LOGOUT_REQUEST:
case SerialPacketType::LOGOUT_RESPONSE:
case SerialPacketType::SHUTDOWN_REQUEST:
case SerialPacketType::ADMIN_SHUTDOWN_REQUEST:
serializeClient(buffer, static_cast<ClientPacket*>(packet));
break;
case SerialPacketType::REGION_REQUEST:
@@ -78,6 +78,7 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::QUERY_CHARACTER_LOCATION:
case SerialPacketType::CHARACTER_MOVEMENT:
case SerialPacketType::CHARACTER_ATTACK:
case SerialPacketType::CHARACTER_DAMAGE:
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break;
case SerialPacketType::MONSTER_CREATE:
@@ -87,15 +88,19 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::QUERY_MONSTER_LOCATION:
case SerialPacketType::MONSTER_MOVEMENT:
case SerialPacketType::MONSTER_ATTACK:
case SerialPacketType::MONSTER_DAMAGE:
serializeMonster(buffer, static_cast<MonsterPacket*>(packet));
break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::TEXT_SPEECH:
case SerialPacketType::TEXT_WHISPER:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::MONSTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::QUERY_REJECTION:
serializeText(buffer, static_cast<TextPacket*>(packet));
break;
}
@@ -117,12 +122,12 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::DISCONNECT_REQUEST:
case SerialPacketType::DISCONNECT_RESPONSE:
case SerialPacketType::DISCONNECT_FORCED:
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
case SerialPacketType::LOGIN_REQUEST:
case SerialPacketType::LOGIN_RESPONSE:
case SerialPacketType::LOGOUT_REQUEST:
case SerialPacketType::LOGOUT_RESPONSE:
case SerialPacketType::SHUTDOWN_REQUEST:
case SerialPacketType::ADMIN_SHUTDOWN_REQUEST:
deserializeClient(buffer, static_cast<ClientPacket*>(packet));
break;
case SerialPacketType::REGION_REQUEST:
@@ -138,6 +143,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::QUERY_CHARACTER_LOCATION:
case SerialPacketType::CHARACTER_MOVEMENT:
case SerialPacketType::CHARACTER_ATTACK:
case SerialPacketType::CHARACTER_DAMAGE:
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break;
case SerialPacketType::MONSTER_CREATE:
@@ -147,15 +153,19 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::QUERY_MONSTER_LOCATION:
case SerialPacketType::MONSTER_MOVEMENT:
case SerialPacketType::MONSTER_ATTACK:
case SerialPacketType::MONSTER_DAMAGE:
deserializeMonster(buffer, static_cast<MonsterPacket*>(packet));
break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::TEXT_SPEECH:
case SerialPacketType::TEXT_WHISPER:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::MONSTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::QUERY_REJECTION:
deserializeText(buffer, static_cast<TextPacket*>(packet));
break;
}
-1
View File
@@ -140,7 +140,6 @@ int UDPNetworkUtility::SendToAllChannels(void* data, int len) {
return sent;
}
//TODO: put a void* and int* parameter list here
int UDPNetworkUtility::Receive() {
memset(packet->data, 0, packet->maxlen);
int ret = SDLNet_UDP_Recv(socket, packet);
+14 -16
View File
@@ -22,8 +22,6 @@
#ifndef BOUNDINGBOX_HPP_
#define BOUNDINGBOX_HPP_
#include "vector2.hpp"
#include <type_traits>
#include <algorithm>
@@ -34,15 +32,16 @@ public:
int w, h;
BoundingBox() = default;
BoundingBox(int i, int j): x(i), y(j), w(0), h(0) {};
BoundingBox(int i, int j, int k, int l): x(i), y(j), w(k), h(l) {};
~BoundingBox() = default;
BoundingBox& operator=(BoundingBox const&) = default;
int Size() {
return (w-x) * (h-y);
return std::max(w*h,0);
}
bool CheckCollision(BoundingBox rhs) {
bool CheckOverlap(BoundingBox rhs) {
return !(
x >= rhs.x + rhs.w ||
y >= rhs.y + rhs.h ||
@@ -50,25 +49,24 @@ public:
rhs.y >= y + h);
}
Vector2 CalcShift(BoundingBox rhs) {
if (!CheckCollision(rhs)) {
return {0, 0};
BoundingBox CalcOverlap(BoundingBox rhs) {
if (!CheckOverlap(rhs)) {
return {0, 0, 0, 0};
}
//DOCS: Given two BoundingBox objects, how does the other have to move so that they are no longer colliding?
Vector2 horizontal = {0, 0};
Vector2 vertical = {0, 0};
horizontal.x = std::abs(x + w - rhs.x) < std::abs(rhs.x + rhs.w - x) ? x + w - rhs.x -1 : -(rhs.x + rhs.w - x -1);
vertical.y = std::abs(y + h - rhs.x) < std::abs(rhs.y + rhs.h - y) ? y + h - rhs.y -1 : -(rhs.y + rhs.h - y -1);
return std::abs(vertical.y) < std::abs(horizontal.x) ? vertical : horizontal;
BoundingBox ret;
ret.x = std::max(x, rhs.x);
ret.y = std::max(y, rhs.y);
ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x;
ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y;
return ret;
}
};
//This is explicitly a POD
static_assert(std::is_pod<BoundingBox>::value, "BoundingBox is not a POD");
#include "vector2.hpp"
//operators
inline BoundingBox operator+(BoundingBox b, Vector2 v) {
return {b.x + (int)v.x, b.y + (int)v.y, b.w, b.h};
+1 -1
View File
@@ -11,5 +11,5 @@ function mapSaver.Save(r)
io.write("map_saver:Save(", Region.GetX(r), ", ", Region.GetY(r), ")\n")
end
--TODO: create a flexible saving & loading system
--TODO: (9) create a flexible saving & loading system
return mapSaver
+4 -4
View File
@@ -1,10 +1,10 @@
--TODO: An archive table of all dead characters
--TODO: (9) An archive table of all dead characters
CREATE TABLE IF NOT EXISTS Accounts (
uid INTEGER PRIMARY KEY AUTOINCREMENT,
username varchar(100) UNIQUE,
username varchar(100) UNIQUE, --TODO: (9) Swap username for email address
--TODO: server-client security
--server-client security
-- passhash varchar(100),
-- passsalt varchar(100),
@@ -101,5 +101,5 @@ CREATE TABLE IF NOT EXISTS WornEquipment (
--unique information
durability INTEGER DEFAULT 0,
stats INTEGER REFERENCES StatisticSets(uid)
--TODO: attached script?
--attached script?
);
+1 -1
View File
@@ -47,7 +47,7 @@ private:
int clientIndex;
std::string username;
//TODO: password
//password/auth token
//bit fields?
bool blackListed = false;
+11 -11
View File
@@ -30,45 +30,45 @@ MonsterManager::~MonsterManager() {
}
int MonsterManager::Create(std::string) {
//TODO
//Create
}
void MonsterManager::Unload(int uid) {
//TODO
//Unload
}
void MonsterManager::UnloadAll() {
//TODO
//UnloadAll
}
void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn) {
//TODO
//UnloadIf
}
MonsterData* MonsterManager::Get(int uid) {
//TODO
//Get
}
int MonsterManager::GetLoadedCount() {
//TODO
//GetLoadedCount
}
std::map<int, MonsterData>* MonsterManager::GetContainer() {
//TODO
//GetContainer
}
lua_State* MonsterManager::SetLuaState(lua_State* L) {
//TODO
//SetLuaState
}
lua_State* MonsterManager::GetLuaState() {
//TODO
//GetLuaState
}
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
//TODO
//SetDatabase
}
sqlite3* MonsterManager::GetDatabase() {
//TODO
//GetDatabase
}
-1
View File
@@ -66,7 +66,6 @@ static int getWaypointMgr(lua_State* L) {
}
static int initialize(lua_State* L) {
//TODO: This could fit into the room system's globals
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
//set the refs of these parameters (backwards, since it pops from the top of the stack)
+1 -1
View File
@@ -71,7 +71,7 @@ int unloadRoom(lua_State* L) {
}
int getRoom(lua_State* L) {
//TODO: integer vs name for getRoom()
//integer vs name for getRoom()
RoomManager& roomMgr = RoomManager::GetSingleton();
RoomData* room = nullptr;
+37 -27
View File
@@ -34,6 +34,7 @@
#include "udp_network_utility.hpp"
//common utilities
#include "ip_operators.hpp"
#include "serial_packet.hpp"
#include "singleton.hpp"
@@ -47,10 +48,6 @@
#include <map>
#include <string>
//global utility functions
bool operator==(IPaddress lhs, IPaddress rhs);
bool operator!=(IPaddress lhs, IPaddress rhs);
//The main application class
class ServerApplication: public Singleton<ServerApplication> {
public:
@@ -68,46 +65,59 @@ private:
//handle incoming traffic
void HandlePacket(SerialPacket* const);
//heartbeat sustem
void HandlePing(ServerPacket* const);
void HandlePong(ServerPacket* const);
//heartbeat system
void hPing(ServerPacket* const);
void hPong(ServerPacket* const);
//basic connections
void HandleBroadcastRequest(ServerPacket* const);
void HandleJoinRequest(ClientPacket* const);
void HandleLoginRequest(ClientPacket* const);
void hBroadcastRequest(ServerPacket* const);
void hJoinRequest(ClientPacket* const);
void hLoginRequest(ClientPacket* const);
//client disconnections
void HandleLogoutRequest(ClientPacket* const);
void HandleDisconnectRequest(ClientPacket* const);
void hLogoutRequest(ClientPacket* const);
void hDisconnectRequest(ClientPacket* const);
//server commands
void HandleDisconnectForced(ClientPacket* const);
void HandleShutdownRequest(ClientPacket* const);
void hAdminDisconnectForced(ClientPacket* const);
void hAdminShutdownRequest(ClientPacket* const);
//data management
void HandleRegionRequest(RegionPacket* const);
void HandleCharacterExists(CharacterPacket* const);
void SaveServerState();
void FullClientUnload(int index);
void FullAccountUnload(int index);
void FullCharacterUnload(int index);
void hRegionRequest(RegionPacket* const);
void hQueryCharacterExists(CharacterPacket* const);
void hQueryCharacterStats(CharacterPacket* const);
void hQueryCharacterLocation(CharacterPacket* const);
void hQueryMonsterExists(MonsterPacket* const);
void hQueryMonsterStats(MonsterPacket* const);
void hQueryMonsterLocation(MonsterPacket* const);
//character management
void HandleCharacterCreate(CharacterPacket* const);
void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterLoad(CharacterPacket* const);
void HandleCharacterUnload(CharacterPacket* const);
void hCharacterCreate(CharacterPacket* const);
void hCharacterDelete(CharacterPacket* const);
void hCharacterLoad(CharacterPacket* const);
void hCharacterUnload(CharacterPacket* const);
//character movement
void HandleCharacterMovement(CharacterPacket* const);
void HandleCharacterAttack(CharacterPacket* const);
void hCharacterMovement(CharacterPacket* const);
void hCharacterAttack(CharacterPacket* const);
void hCharacterDamage(CharacterPacket* const);
//character management
void hMonsterDamage(MonsterPacket* const);
//chat
void hTextBroadcast(TextPacket* const);
void hTextSpeech(TextPacket* const);
void hTextWhisper(TextPacket* const);
//utility methods
void PumpPacket(SerialPacket* const);
void PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance);
void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
void SaveServerState();
void FullClientUnload(int index);
void FullAccountUnload(int index);
void FullCharacterUnload(int index);
//APIs and utilities
sqlite3* database = nullptr;
+15 -11
View File
@@ -28,7 +28,7 @@
//Character Management
//-------------------------
void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterCreate(CharacterPacket* const argPacket) {
int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
if (characterIndex < 0) {
@@ -55,7 +55,7 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket)
PumpPacket(&newPacket);
}
void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterDelete(CharacterPacket* const argPacket) {
//get the user's data
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
if (!accountData) {
@@ -102,7 +102,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
PumpPacket(static_cast<SerialPacket*>(&newPacket));
}
void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterLoad(CharacterPacket* const argPacket) {
int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
if (characterIndex < 0) {
@@ -135,7 +135,7 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
PumpPacket(&newPacket);
}
void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterUnload(CharacterPacket* const argPacket) {
//get the entries
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex);
if (!characterData) {
@@ -144,12 +144,12 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
AccountData* accountData = accountMgr.Get(characterData->GetOwner());
if (!accountData) {
return; //TODO: logic_error
return;
}
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex());
if (!clientData) {
return; //TODO: logic_error
return;
}
//check for fraud
@@ -175,9 +175,9 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
//character movement
//-------------------------
//TODO: Could replace this verbosity with a "verify" method, taking a client, account and character ptr as arguments
//TODO: (2) Could replace this verbosity with a "verify" method, taking a client, account and character ptr as arguments
void ServerApplication::HandleCharacterMovement(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) {
//get the specified objects
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex);
@@ -197,7 +197,7 @@ void ServerApplication::HandleCharacterMovement(CharacterPacket* const argPacket
//check if allowed
if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) {
//TODO: send to the client?
//TODO: (2) send to the client?
std::cerr << "Failed to set character motion due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl;
return;
}
@@ -234,6 +234,10 @@ void ServerApplication::HandleCharacterMovement(CharacterPacket* const argPacket
}
}
void ServerApplication::HandleCharacterAttack(CharacterPacket* const) {
//TODO: bounce graphical attack data
void ServerApplication::hCharacterAttack(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hCharacterDamage(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
+34
View File
@@ -0,0 +1,34 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "server_application.hpp"
void ServerApplication::hTextBroadcast(TextPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hTextSpeech(TextPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hTextWhisper(TextPacket* const argPacket) {
//TODO: (9) empty
}
+7 -11
View File
@@ -28,13 +28,13 @@
//heartbeat system
//-------------------------
void ServerApplication::HandlePing(ServerPacket* const argPacket) {
void ServerApplication::hPing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void ServerApplication::HandlePong(ServerPacket* const argPacket) {
void ServerApplication::hPong(ServerPacket* const argPacket) {
clientMgr.HandlePong(argPacket);
}
@@ -42,7 +42,7 @@ void ServerApplication::HandlePong(ServerPacket* const argPacket) {
//basic connections
//-------------------------
void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) {
void ServerApplication::hBroadcastRequest(ServerPacket* const argPacket) {
//send the server's data
ServerPacket newPacket;
@@ -54,7 +54,7 @@ void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) {
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
}
void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
void ServerApplication::hJoinRequest(ClientPacket* const argPacket) {
//register the client
int clientIndex = clientMgr.Create(argPacket->srcAddress);
@@ -69,7 +69,7 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
std::cout << "New join, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
}
void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) {
void ServerApplication::hLoginRequest(ClientPacket* const argPacket) {
//get the client data
ClientData* clientData = clientMgr.Get(argPacket->clientIndex);
@@ -110,7 +110,7 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) {
std::cout << "New login, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
}
void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) {
void ServerApplication::hLogoutRequest(ClientPacket* const argPacket) {
//get the account and client data
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
if (!accountData) {
@@ -144,7 +144,7 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) {
std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
}
void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) {
void ServerApplication::hDisconnectRequest(ClientPacket* const argPacket) {
//get the client data
ClientData* clientData = clientMgr.Get(argPacket->clientIndex);
if (!clientData) {
@@ -170,7 +170,3 @@ void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) {
//finished this routine
std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
}
void ServerApplication::HandleDisconnectForced(ClientPacket* const argPacket) {
//TODO: HandleDisconnectForced
}
@@ -25,20 +25,10 @@
#include <sstream>
//-------------------------
//General data management
//Queries
//-------------------------
//TODO: Queries
void ServerApplication::SaveServerState() {
//TODO: SaveServerState
}
//-------------------------
//Map management
//-------------------------
void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
void ServerApplication::hRegionRequest(RegionPacket* const argPacket) {
//get the region object, send a rejection on error
RoomData* room = roomMgr.Get(argPacket->roomIndex);
if (!room) {
@@ -71,7 +61,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
}
void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) {
void ServerApplication::hQueryCharacterExists(CharacterPacket* const argPacket) {
//respond with all character data
CharacterPacket newPacket;
@@ -84,3 +74,23 @@ void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket)
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
}
}
void ServerApplication::hQueryCharacterStats(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hQueryCharacterLocation(CharacterPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hQueryMonsterExists(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hQueryMonsterStats(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hQueryMonsterLocation(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
+58 -38
View File
@@ -128,7 +128,6 @@ void ServerApplication::Init(int argc, char* argv[]) {
//debug output
//-------------------------
//TODO: enable/disable these with a switch
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
std::cout << "Internal sizes:" << std::endl;
@@ -195,7 +194,8 @@ void ServerApplication::Proc() {
void ServerApplication::Quit() {
std::cout << "Shutting down" << std::endl;
//TODO: save the server state
//save the server state
SaveServerState();
//close the managers
accountMgr.UnloadAll();
@@ -214,91 +214,111 @@ void ServerApplication::Quit() {
}
//-------------------------
//direct incoming traffic
//handle incoming traffic
//-------------------------
void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
//heartbeat system
case SerialPacketType::PING:
HandlePing(static_cast<ServerPacket*>(argPacket));
hPing(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::PONG:
HandlePong(static_cast<ServerPacket*>(argPacket));
hPong(static_cast<ServerPacket*>(argPacket));
break;
//client connections
case SerialPacketType::BROADCAST_REQUEST:
HandleBroadcastRequest(static_cast<ServerPacket*>(argPacket));
hBroadcastRequest(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::JOIN_REQUEST:
HandleJoinRequest(static_cast<ClientPacket*>(argPacket));
hJoinRequest(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::LOGIN_REQUEST:
HandleLoginRequest(static_cast<ClientPacket*>(argPacket));
hLoginRequest(static_cast<ClientPacket*>(argPacket));
break;
//client disconnections
case SerialPacketType::LOGOUT_REQUEST:
HandleLogoutRequest(static_cast<ClientPacket*>(argPacket));
hLogoutRequest(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT_REQUEST:
HandleDisconnectRequest(static_cast<ClientPacket*>(argPacket));
hDisconnectRequest(static_cast<ClientPacket*>(argPacket));
break;
//server commands
// case SerialPacketType::DISCONNECT_FORCED:
// HandleDisconnectForced(static_cast<ClientPacket*>(argPacket));
// break;
case SerialPacketType::SHUTDOWN_REQUEST:
HandleShutdownRequest(static_cast<ClientPacket*>(argPacket));
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
hAdminDisconnectForced(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::ADMIN_SHUTDOWN_REQUEST:
hAdminShutdownRequest(static_cast<ClientPacket*>(argPacket));
break;
//data management & queries
case SerialPacketType::REGION_REQUEST:
HandleRegionRequest(static_cast<RegionPacket*>(argPacket));
hRegionRequest(static_cast<RegionPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_EXISTS:
HandleCharacterExists(static_cast<CharacterPacket*>(argPacket));
hQueryCharacterExists(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_STATS:
hQueryCharacterStats(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_LOCATION:
hQueryCharacterLocation(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_EXISTS:
hQueryMonsterExists(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_STATS:
hQueryMonsterStats(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_LOCATION:
hQueryMonsterLocation(static_cast<MonsterPacket*>(argPacket));
break;
//character management
case SerialPacketType::CHARACTER_CREATE:
HandleCharacterCreate(static_cast<CharacterPacket*>(argPacket));
hCharacterCreate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DELETE:
HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
hCharacterDelete(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_LOAD:
HandleCharacterLoad(static_cast<CharacterPacket*>(argPacket));
hCharacterLoad(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_UNLOAD:
HandleCharacterUnload(static_cast<CharacterPacket*>(argPacket));
hCharacterUnload(static_cast<CharacterPacket*>(argPacket));
break;
/* case SerialPacketType::QUERY_CHARACTER_EXISTS:
//
break;
case SerialPacketType::QUERY_CHARACTER_STATS:
//
break;
case SerialPacketType::QUERY_CHARACTER_LOCATION:
//
break;
*/
//character movement
case SerialPacketType::CHARACTER_MOVEMENT:
HandleCharacterMovement(static_cast<CharacterPacket*>(argPacket));
hCharacterMovement(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_ATTACK:
HandleCharacterAttack(static_cast<CharacterPacket*>(argPacket));
hCharacterAttack(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DAMAGE:
hCharacterDamage(static_cast<CharacterPacket*>(argPacket));
break;
//monster management
case SerialPacketType::MONSTER_DAMAGE:
hMonsterDamage(static_cast<MonsterPacket*>(argPacket));
break;
//chat
case SerialPacketType::TEXT_BROADCAST:
hTextBroadcast(static_cast<TextPacket*>(argPacket));
break;
case SerialPacketType::TEXT_SPEECH:
hTextSpeech(static_cast<TextPacket*>(argPacket));
break;
case SerialPacketType::TEXT_WHISPER:
hTextWhisper(static_cast<TextPacket*>(argPacket));
break;
/*
//enemy management
//TODO: enemy management
//TODO: text
*/
//handle errors
default: {
std::ostringstream msg;
+10 -14
View File
@@ -25,23 +25,15 @@
#include <iostream>
#include <sstream>
//-------------------------
//these should've come standard
//-------------------------
bool operator==(IPaddress lhs, IPaddress rhs) {
return lhs.host == rhs.host && lhs.port == rhs.port;
}
bool operator!=(IPaddress lhs, IPaddress rhs) {
return !(lhs == rhs);
}
//-------------------------
//server commands
//-------------------------
void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) {
void ServerApplication::hAdminDisconnectForced(ClientPacket* const argPacket) {
//TODO: (9) empty
}
void ServerApplication::hAdminShutdownRequest(ClientPacket* const argPacket) {
//get the account and client data
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
if (!accountData) {
@@ -84,7 +76,7 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) {
//disconnect all clients
TextPacket newPacket;
newPacket.type = SerialPacketType::DISCONNECT_FORCED;
newPacket.type = SerialPacketType::ADMIN_DISCONNECT_FORCED;
strncpy(newPacket.text, "Server shutdown", PACKET_STRING_SIZE);
PumpPacket(&newPacket);
@@ -92,6 +84,10 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) {
std::cout << "Shutdown signal accepted" << std::endl;
}
void ServerApplication::SaveServerState() {
//TODO: (9) empty
}
//-------------------------
//full unload methods
//-------------------------
+26
View File
@@ -0,0 +1,26 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "server_application.hpp"
void ServerApplication::hMonsterDamage(MonsterPacket* const argPacket) {
//TODO: (9) empty
}
@@ -27,12 +27,10 @@
static int create(lua_State* L) {
WaypointManager* mgr = static_cast<WaypointManager*>(lua_touserdata(L, 1));
//TODO
}
static int unload(lua_State* L) {
WaypointManager* mgr = static_cast<WaypointManager*>(lua_touserdata(L, 1));
//TODO
}
static int getWaypoint(lua_State* L) {
+18 -12
View File
@@ -7,15 +7,21 @@ TODO: Account passwords (list)
* ...
* salts & hashes
TODO: Split config.cfg in two, one for the server and the client
TODO: Add the "home" parameter to the server's config file
TODO: Waypoints, with positions and trigger zones (collision areas) for doors, monster spawns, etc.
TODO: Fix shoddy movement
TODO: Periodic mass server saves
TODO: Remove the big "Shut Down" button (currently broken...)
TODO: Make a way for the server owner to control the server directly
TODO: The TileSheet class should implement the surface itself
TODO: Time delay for requesting region packets
TODO: A proper logging system
TODO: Fix the const-ness of accessors
TODO: Add a screenshot of the game to README.md
TODO: Features
* Make sure login errors are sent to the client
* Split config.cfg in two, one for the server and the client
* Add the "home" parameter to the server's config file
* Waypoints, with positions and trigger zones (collision areas) for doors, monster spawns, etc.
* Fix shoddy movement
* Periodic mass server saves
* Remove the big "Shut Down" button (currently broken...)
* Make a way for the server owner to control the server directly
* The TileSheet class should implement the surface itself
* Time delay for requesting region packets
* A proper logging system
* Fix the const-ness of accessors
* Add a screenshot of the game to README.md
* joystick/gamepad support
* add the tilesheet to the map system
* ping/delay displayed in the lobby
* login screen prompting for username & password