Minor tweaks
This commit is contained in:
@@ -75,14 +75,12 @@ protected:
|
||||
//Network handlers
|
||||
void HandlePacket(SerialPacket* const);
|
||||
void HandleDisconnect(SerialPacket* const);
|
||||
//TODO: more network handlers
|
||||
|
||||
//Server control
|
||||
void RequestSynchronize();
|
||||
void SendPlayerUpdate();
|
||||
void RequestDisconnect();
|
||||
void RequestShutdown();
|
||||
//TODO: more
|
||||
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
|
||||
+16
-4
@@ -24,9 +24,10 @@
|
||||
#include "channels.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
@@ -106,6 +107,8 @@ void InWorld::Update(double delta) {
|
||||
it.second.Update(delta);
|
||||
}
|
||||
|
||||
//TODO: Check collisions here
|
||||
|
||||
//update the camera
|
||||
if(localCharacter) {
|
||||
camera.x = localCharacter->origin.x - camera.marginX;
|
||||
@@ -288,15 +291,20 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
//create the character object
|
||||
CharacterData& character = characterMap[argPacket->characterIndex];
|
||||
|
||||
//set the members
|
||||
//fill out the character's members
|
||||
character.handle = argPacket->handle;
|
||||
character.avatar = argPacket->avatar;
|
||||
|
||||
character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4);
|
||||
character.bounds = {CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT};
|
||||
|
||||
character.roomIndex = argPacket->roomIndex;
|
||||
character.origin = argPacket->origin;
|
||||
character.motion = argPacket->motion;
|
||||
|
||||
character.stats = argPacket->stats;
|
||||
|
||||
//bookkeeping code
|
||||
character.CorrectSprite();
|
||||
|
||||
//catch this client's player object
|
||||
@@ -316,6 +324,7 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
|
||||
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
||||
|
||||
//catch this client's player object
|
||||
if (argPacket->characterIndex == characterIndex) {
|
||||
characterIndex = -1;
|
||||
@@ -327,6 +336,7 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||
|
||||
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
||||
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
|
||||
std::cout << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl;
|
||||
HandleCharacterNew(argPacket);
|
||||
return;
|
||||
}
|
||||
@@ -364,6 +374,8 @@ void InWorld::RequestSynchronize() {
|
||||
newPacket.clientIndex = clientIndex;
|
||||
newPacket.accountIndex = accountIndex;
|
||||
|
||||
//TODO: location, range for sync request
|
||||
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
@@ -374,7 +386,7 @@ void InWorld::SendPlayerUpdate() {
|
||||
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
||||
|
||||
newPacket.characterIndex = characterIndex;
|
||||
//handle, avatar
|
||||
//NOTE: omitting the handle and avatar here
|
||||
newPacket.accountIndex = accountIndex;
|
||||
newPacket.roomIndex = localCharacter->roomIndex;
|
||||
newPacket.origin = localCharacter->origin;
|
||||
@@ -435,7 +447,7 @@ void InWorld::UpdateMap() {
|
||||
|
||||
//prune distant regions
|
||||
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
|
||||
//check if the region is outside off this area
|
||||
//check if the region is outside of this area
|
||||
if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
|
||||
|
||||
//clunky, but the alternative was time consuming
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
constexpr double CHARACTER_WALKING_SPEED = 140.0;
|
||||
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
|
||||
|
||||
//the bounding boxes for the characters
|
||||
constexpr double CHARACTER_BOUNDS_WIDTH = 32.0;
|
||||
constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0;
|
||||
|
||||
struct CharacterData {
|
||||
//metadata
|
||||
int owner;
|
||||
@@ -48,7 +52,6 @@ struct CharacterData {
|
||||
int roomIndex = 0;
|
||||
Vector2 origin = {0.0,0.0};
|
||||
Vector2 motion = {0.0,0.0};
|
||||
Vector2 bounds = {0.0,0.0};
|
||||
|
||||
//base statistics
|
||||
Statistics stats;
|
||||
@@ -65,6 +68,7 @@ struct CharacterData {
|
||||
//active gameplay members
|
||||
//NOTE: these are lost when unloaded
|
||||
#ifdef GRAPHICS
|
||||
Vector2 bounds = {0.0,0.0};
|
||||
SpriteSheet sprite;
|
||||
#endif
|
||||
bool inCombat = false;
|
||||
|
||||
@@ -141,7 +141,8 @@ void ServerApplication::Proc() {
|
||||
HandlePacket(packetBuffer);
|
||||
}
|
||||
//update the internals
|
||||
//TODO: update the internals i.e. player positions
|
||||
//BUG: #30 Update the internals i.e. player positions
|
||||
|
||||
//give the computer a break
|
||||
SDL_Delay(10);
|
||||
}
|
||||
@@ -269,6 +270,16 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
||||
|
||||
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
||||
//TODO: authenticate who is disconnecting/kicking
|
||||
/*Pseudocode:
|
||||
if sender's account index -> client index -> address == sender's address then
|
||||
continue
|
||||
end
|
||||
if sender's account index -> admin == true OR sender's account index -> mod == true then
|
||||
continue
|
||||
end
|
||||
if neither of the above is true, then output a warning to the console, and return
|
||||
*/
|
||||
|
||||
|
||||
//forward to the specified client
|
||||
network.SendTo(
|
||||
@@ -296,6 +307,12 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
||||
|
||||
void ServerApplication::HandleShutdown(SerialPacket* const argPacket) {
|
||||
//TODO: authenticate who is shutting the server down
|
||||
/*Pseudocode:
|
||||
if sender's account -> admin is not true then
|
||||
print a warning
|
||||
return
|
||||
end
|
||||
*/
|
||||
|
||||
//end the server
|
||||
running = false;
|
||||
@@ -399,15 +416,7 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO: rewrite this design flaw, read more
|
||||
* Slaving the client to the server here is a terrible idea, instead there
|
||||
* needs to be a utility function to update and send the server-side character
|
||||
* to the clients.
|
||||
*
|
||||
* Other things to consider include functionality to reequip the character,
|
||||
* apply status effects and to change the stats as well. These should all be
|
||||
* handled server-side.
|
||||
*/
|
||||
//accept client-side logic
|
||||
character->roomIndex = argPacket->roomIndex;
|
||||
character->origin = argPacket->origin;
|
||||
character->motion = argPacket->motion;
|
||||
|
||||
Reference in New Issue
Block a user