Minor tweaks

This commit is contained in:
Kayne Ruse
2014-07-01 01:03:03 +10:00
parent deba324449
commit 8c9d071c7a
4 changed files with 40 additions and 17 deletions
-2
View File
@@ -75,14 +75,12 @@ protected:
//Network handlers //Network handlers
void HandlePacket(SerialPacket* const); void HandlePacket(SerialPacket* const);
void HandleDisconnect(SerialPacket* const); void HandleDisconnect(SerialPacket* const);
//TODO: more network handlers
//Server control //Server control
void RequestSynchronize(); void RequestSynchronize();
void SendPlayerUpdate(); void SendPlayerUpdate();
void RequestDisconnect(); void RequestDisconnect();
void RequestShutdown(); void RequestShutdown();
//TODO: more
//shared parameters //shared parameters
ConfigUtility& config; ConfigUtility& config;
+16 -4
View File
@@ -24,9 +24,10 @@
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp" #include "utility.hpp"
#include <stdexcept>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <stdexcept> #include <iostream>
//------------------------- //-------------------------
//Public access members //Public access members
@@ -106,6 +107,8 @@ void InWorld::Update(double delta) {
it.second.Update(delta); it.second.Update(delta);
} }
//TODO: Check collisions here
//update the camera //update the camera
if(localCharacter) { if(localCharacter) {
camera.x = localCharacter->origin.x - camera.marginX; camera.x = localCharacter->origin.x - camera.marginX;
@@ -288,15 +291,20 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
//create the character object //create the character object
CharacterData& character = characterMap[argPacket->characterIndex]; CharacterData& character = characterMap[argPacket->characterIndex];
//set the members //fill out the character's members
character.handle = argPacket->handle; character.handle = argPacket->handle;
character.avatar = argPacket->avatar; character.avatar = argPacket->avatar;
character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4); character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4);
character.bounds = {CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT};
character.roomIndex = argPacket->roomIndex; character.roomIndex = argPacket->roomIndex;
character.origin = argPacket->origin; character.origin = argPacket->origin;
character.motion = argPacket->motion; character.motion = argPacket->motion;
character.stats = argPacket->stats; character.stats = argPacket->stats;
//bookkeeping code
character.CorrectSprite(); character.CorrectSprite();
//catch this client's player object //catch this client's player object
@@ -316,6 +324,7 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//TODO: authenticate when own character is being deleted (linked to a TODO in the server) //TODO: authenticate when own character is being deleted (linked to a TODO in the server)
//catch this client's player object //catch this client's player object
if (argPacket->characterIndex == characterIndex) { if (argPacket->characterIndex == characterIndex) {
characterIndex = -1; characterIndex = -1;
@@ -327,6 +336,7 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) { void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) { if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
std::cout << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl;
HandleCharacterNew(argPacket); HandleCharacterNew(argPacket);
return; return;
} }
@@ -364,6 +374,8 @@ void InWorld::RequestSynchronize() {
newPacket.clientIndex = clientIndex; newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex; newPacket.accountIndex = accountIndex;
//TODO: location, range for sync request
network.SendTo(Channels::SERVER, &newPacket); network.SendTo(Channels::SERVER, &newPacket);
} }
@@ -374,7 +386,7 @@ void InWorld::SendPlayerUpdate() {
newPacket.type = SerialPacketType::CHARACTER_UPDATE; newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex; newPacket.characterIndex = characterIndex;
//handle, avatar //NOTE: omitting the handle and avatar here
newPacket.accountIndex = accountIndex; newPacket.accountIndex = accountIndex;
newPacket.roomIndex = localCharacter->roomIndex; newPacket.roomIndex = localCharacter->roomIndex;
newPacket.origin = localCharacter->origin; newPacket.origin = localCharacter->origin;
@@ -435,7 +447,7 @@ void InWorld::UpdateMap() {
//prune distant regions //prune distant regions
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) { 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) { if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
//clunky, but the alternative was time consuming //clunky, but the alternative was time consuming
+5 -1
View File
@@ -38,6 +38,10 @@
constexpr double CHARACTER_WALKING_SPEED = 140.0; constexpr double CHARACTER_WALKING_SPEED = 140.0;
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.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 { struct CharacterData {
//metadata //metadata
int owner; int owner;
@@ -48,7 +52,6 @@ struct CharacterData {
int roomIndex = 0; int roomIndex = 0;
Vector2 origin = {0.0,0.0}; Vector2 origin = {0.0,0.0};
Vector2 motion = {0.0,0.0}; Vector2 motion = {0.0,0.0};
Vector2 bounds = {0.0,0.0};
//base statistics //base statistics
Statistics stats; Statistics stats;
@@ -65,6 +68,7 @@ struct CharacterData {
//active gameplay members //active gameplay members
//NOTE: these are lost when unloaded //NOTE: these are lost when unloaded
#ifdef GRAPHICS #ifdef GRAPHICS
Vector2 bounds = {0.0,0.0};
SpriteSheet sprite; SpriteSheet sprite;
#endif #endif
bool inCombat = false; bool inCombat = false;
+19 -10
View File
@@ -141,7 +141,8 @@ void ServerApplication::Proc() {
HandlePacket(packetBuffer); HandlePacket(packetBuffer);
} }
//update the internals //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 //give the computer a break
SDL_Delay(10); SDL_Delay(10);
} }
@@ -269,6 +270,16 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
//TODO: authenticate who is disconnecting/kicking //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 //forward to the specified client
network.SendTo( network.SendTo(
@@ -296,6 +307,12 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
void ServerApplication::HandleShutdown(SerialPacket* const argPacket) { void ServerApplication::HandleShutdown(SerialPacket* const argPacket) {
//TODO: authenticate who is shutting the server down //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 //end the server
running = false; running = false;
@@ -399,15 +416,7 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
return; return;
} }
/* TODO: rewrite this design flaw, read more //accept client-side logic
* 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.
*/
character->roomIndex = argPacket->roomIndex; character->roomIndex = argPacket->roomIndex;
character->origin = argPacket->origin; character->origin = argPacket->origin;
character->motion = argPacket->motion; character->motion = argPacket->motion;