This will not build; working on refactoring
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "client.hpp"
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
//This is explicitly a POD
|
||||||
|
static_assert(std::is_pod<Client>::value, "Client is not a POD");
|
||||||
|
|
||||||
|
unsigned int Client::uidCounter;
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef CLIENT_HPP_
|
||||||
|
#define CLIENT_HPP_
|
||||||
|
|
||||||
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
|
struct Client {
|
||||||
|
IPaddress address;
|
||||||
|
unsigned int uid;
|
||||||
|
static unsigned int uidCounter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -22,8 +22,25 @@
|
|||||||
#ifndef PLAYERENTITY_HPP_
|
#ifndef PLAYERENTITY_HPP_
|
||||||
#define PLAYERENTITY_HPP_
|
#define PLAYERENTITY_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
struct PlayerEntity {
|
struct PlayerEntity {
|
||||||
//TODO: stuff
|
int clientIndex;
|
||||||
|
std::string handle;
|
||||||
|
std::string avatar;
|
||||||
|
int level;
|
||||||
|
int exp;
|
||||||
|
int maxHP;
|
||||||
|
int health;
|
||||||
|
int maxMP;
|
||||||
|
int mana;
|
||||||
|
int attack;
|
||||||
|
int defence;
|
||||||
|
int intelligence;
|
||||||
|
int resistance;
|
||||||
|
float accuracy;
|
||||||
|
float evasion;
|
||||||
|
float luck;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
//initial setup
|
//initial setup
|
||||||
|
Client::uidCounter = 0;
|
||||||
Entity::uidCounter = 0;
|
Entity::uidCounter = 0;
|
||||||
config.Load("rsc\\config.cfg");
|
config.Load("rsc\\config.cfg");
|
||||||
|
|
||||||
@@ -103,6 +104,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
mapPager.SetRegionDepth(REGION_DEPTH);
|
mapPager.SetRegionDepth(REGION_DEPTH);
|
||||||
mapPager.GetGenerator()->SetLuaState(luaState);
|
mapPager.GetGenerator()->SetLuaState(luaState);
|
||||||
mapPager.GetFormat()->SetLuaState(luaState);
|
mapPager.GetFormat()->SetLuaState(luaState);
|
||||||
|
//TODO: config parameter
|
||||||
mapPager.GetFormat()->SetSaveDir("save/mapname/");
|
mapPager.GetFormat()->SetSaveDir("save/mapname/");
|
||||||
//TODO: pass args to the generator & format as needed
|
//TODO: pass args to the generator & format as needed
|
||||||
//NOTE: I might need to rearrange the init process so that lua & SQL can interact
|
//NOTE: I might need to rearrange the init process so that lua & SQL can interact
|
||||||
@@ -208,21 +210,21 @@ void ServerApplication::HandleBroadcastRequest(NetworkPacket packet) {
|
|||||||
|
|
||||||
void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
|
void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
|
||||||
//register the new client
|
//register the new client
|
||||||
ClientEntry c;
|
Client c;
|
||||||
c.address = packet.meta.srcAddress;
|
c.address = packet.meta.srcAddress;
|
||||||
clientMap[clientCounter] = c;
|
clientMap[Client::uidCounter] = c;
|
||||||
|
|
||||||
//send the client their info
|
//send the client their info
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
char buffer[PACKET_BUFFER_SIZE];
|
||||||
|
|
||||||
packet.meta.type = NetworkPacket::Type::JOIN_RESPONSE;
|
packet.meta.type = NetworkPacket::Type::JOIN_RESPONSE;
|
||||||
packet.clientInfo.index = clientCounter;
|
packet.clientInfo.index = Client::uidCounter;
|
||||||
serialize(&packet, buffer);
|
serialize(&packet, buffer);
|
||||||
|
|
||||||
network.Send(&clientMap[clientCounter].address, buffer, PACKET_BUFFER_SIZE);
|
network.Send(&clientMap[Client::uidCounter].address, buffer, PACKET_BUFFER_SIZE);
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine+
|
||||||
clientCounter++;
|
Client::uidCounter++;
|
||||||
cout << "Connect, total: " << clientMap.size() << endl;
|
cout << "Connect, total: " << clientMap.size() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#define SERVERAPPLICATION_HPP_
|
#define SERVERAPPLICATION_HPP_
|
||||||
|
|
||||||
//server specific stuff
|
//server specific stuff
|
||||||
|
#include "client.hpp"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
#include "player_entity.hpp"
|
#include "player_entity.hpp"
|
||||||
|
|
||||||
@@ -49,19 +50,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct ClientEntry {
|
|
||||||
IPaddress address;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PlayerEntry {
|
|
||||||
int clientIndex;
|
|
||||||
int mapIndex;
|
|
||||||
std::string handle;
|
|
||||||
std::string avatar;
|
|
||||||
Vector2 position;
|
|
||||||
Vector2 motion;
|
|
||||||
};
|
|
||||||
|
|
||||||
//The main application class
|
//The main application class
|
||||||
class ServerApplication {
|
class ServerApplication {
|
||||||
public:
|
public:
|
||||||
@@ -89,6 +77,9 @@ private:
|
|||||||
|
|
||||||
void PumpPacket(NetworkPacket);
|
void PumpPacket(NetworkPacket);
|
||||||
|
|
||||||
|
//APIs
|
||||||
|
std::map<int, Client> clientMap;
|
||||||
|
|
||||||
//maps
|
//maps
|
||||||
RegionPager<LuaGenerator, LuaFormat> mapPager;
|
RegionPager<LuaGenerator, LuaFormat> mapPager;
|
||||||
|
|
||||||
@@ -104,12 +95,6 @@ private:
|
|||||||
//misc
|
//misc
|
||||||
bool running = true;
|
bool running = true;
|
||||||
ConfigUtility config;
|
ConfigUtility config;
|
||||||
|
|
||||||
std::map<int, ClientEntry> clientMap;
|
|
||||||
std::map<int, PlayerEntry> playerMap;
|
|
||||||
|
|
||||||
int clientCounter = 0;
|
|
||||||
int playerCounter = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user