The client is receiving the list of servers

This commit is contained in:
Kayne Ruse
2013-11-22 23:19:29 +11:00
parent cb9aef95ec
commit e3605e4dc5
6 changed files with 55 additions and 77 deletions
+8 -17
View File
@@ -40,6 +40,9 @@ using namespace std;
//Define the network thread
//-------------------------
/* This thread sucks in the packets sent to the server, and pushes them onto the queue.
* This function is declared as a friend of ServerApplication, because I'm lazy
*/
int networkQueueThread(void* ptr) {
ServerApplication* app = reinterpret_cast<ServerApplication*>(ptr);
NetworkPacket packet;
@@ -152,24 +155,15 @@ void ServerApplication::Quit() {
void ServerApplication::HandlePacket(NetworkPacket packet) {
switch(packet.meta.type) {
// case NetworkPacket::Type::PING:
// //NOT USED
// break;
// case NetworkPacket::Type::PONG:
// //NOT USED
// break;
case NetworkPacket::Type::BROADCAST_REQUEST:
cout << "Recieved a request" << endl;
//send back the server's name
packet.meta.type = NetworkPacket::Type::BROADCAST_RESPONSE;
snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str());
networkUtil.Send(&packet.meta.srcAddress, &packet, sizeof(NetworkPacket));
break;
// case NetworkPacket::Type::BROADCAST_RESPONSE:
// //
// break;
case NetworkPacket::Type::JOIN_REQUEST:
//
break;
// case NetworkPacket::Type::JOIN_RESPONSE:
// //
// break;
case NetworkPacket::Type::DISCONNECT:
//
break;
@@ -178,11 +172,8 @@ void ServerApplication::HandlePacket(NetworkPacket packet) {
break;
//handle errors
case NetworkPacket::Type::NONE:
throw(runtime_error("NetworkPacket::Type::NONE encountered"));
break;
default:
throw(runtime_error("Unknown NetworkPacket::Type encountered"));
break;
}
}
}
+11 -6
View File
@@ -22,16 +22,20 @@
#ifndef SERVERAPPLICATION_HPP_
#define SERVERAPPLICATION_HPP_
#include "config_utility.hpp"
//networking
#include "network_packet.hpp"
#include "thread_safe_queue.hpp"
#include "udp_network_utility.hpp"
#include "world_room.hpp"
//APIs
#include "sqlite3/sqlite3.h"
#include "SDL/SDL.h"
#include "SDL/SDL_thread.h"
//misc
#include "config_utility.hpp"
#include "world_room.hpp"
//The main application class
class ServerApplication {
public:
@@ -47,10 +51,6 @@ public:
private:
void HandlePacket(NetworkPacket);
//members
bool running = true;
ConfigUtility config;
//networking
UDPNetworkUtility networkUtil;
ThreadSafeQueue<NetworkPacket> networkQueue;
@@ -58,6 +58,11 @@ private:
//database
sqlite3* database = nullptr;
//misc
bool running = true;
ConfigUtility config;
WorldRoom worldRoom;
};
#endif
+10 -25
View File
@@ -26,6 +26,10 @@
using namespace std;
//-------------------------
//Define the WorldRoom's thread
//-------------------------
int worldRoomThread(void* ptr) {
WorldRoom* room = reinterpret_cast<WorldRoom*>(ptr);
try {
@@ -40,6 +44,10 @@ int worldRoomThread(void* ptr) {
return 0;
}
//-------------------------
//Define the WorldRoom's methods
//-------------------------
WorldRoom::WorldRoom() {
//
}
@@ -62,37 +70,14 @@ void WorldRoom::Quit() {
void WorldRoom::HandlePacket(NetworkPacket packet) {
switch(packet.meta.type) {
case NetworkPacket::Type::PING:
//NOT USED
break;
case NetworkPacket::Type::PONG:
//NOT USED
break;
// case NetworkPacket::Type::BROADCAST_REQUEST:
// //
// break;
// case NetworkPacket::Type::BROADCAST_RESPONSE:
// //
// break;
// case NetworkPacket::Type::JOIN_REQUEST:
// //
// break;
// case NetworkPacket::Type::JOIN_RESPONSE:
// //
// break;
// case NetworkPacket::Type::DISCONNECT:
// //
// break;
// case NetworkPacket::Type::SYNCHRONIZE:
// //
// break;
//handle errors
case NetworkPacket::Type::NONE:
throw(runtime_error("NetworkPacket::Type::NONE encountered"));
break;
default:
throw(runtime_error("Unknown NetworkPacket::Type encountered"));
break;
}
}
}