The server list is being populated from the network
This commit is contained in:
+58
-2
@@ -44,7 +44,7 @@ void Lobby::FrameStart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::Update(double delta) {
|
void Lobby::Update(double delta) {
|
||||||
//
|
Receive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::FrameEnd() {
|
void Lobby::FrameEnd() {
|
||||||
@@ -126,6 +126,62 @@ void Lobby::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
//Utilities
|
//Utilities
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void Lobby::BroadcastNetwork() {
|
void Lobby::Receive() {
|
||||||
|
Packet p;
|
||||||
|
while(netUtil->Receive()) {
|
||||||
|
memcpy(&p, netUtil->GetInData(), sizeof(Packet));
|
||||||
|
switch(p.type) {
|
||||||
|
case PacketType::PING:
|
||||||
|
//quick pong
|
||||||
|
p.type = PacketType::PONG;
|
||||||
|
netUtil->Send(&netUtil->GetInPacket()->address, &p, sizeof(Packet));
|
||||||
|
break;
|
||||||
|
case PacketType::PONG:
|
||||||
//
|
//
|
||||||
|
break;
|
||||||
|
// case PacketType::BROADCAST_REQUEST:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
case PacketType::BROADCAST_RESPONSE:
|
||||||
|
PushServer(p.broadcastResponse);
|
||||||
|
break;
|
||||||
|
// case PacketType::JOIN_REQUEST:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
// case PacketType::JOIN_RESPONSE:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
// case PacketType::DISCONNECT:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
// case PacketType::SYNCHRONIZE:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
// case PacketType::PLAYER_NEW:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
// case PacketType::PLAYER_DELETE:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
// case PacketType::PLAYER_MOVE:
|
||||||
|
// //
|
||||||
|
// break;
|
||||||
|
default:
|
||||||
|
throw(runtime_error("Failed to recognize the packet type"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::BroadcastNetwork() {
|
||||||
|
Packet p;
|
||||||
|
p.type = PacketType::BROADCAST_REQUEST;
|
||||||
|
netUtil->Send("255.255.255.255", configUtil->Int("server.port"), &p, sizeof(Packet));
|
||||||
|
serverList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::PushServer(BroadcastResponse& bcast) {
|
||||||
|
ServerEntry entry;
|
||||||
|
entry.name = bcast.name;
|
||||||
|
entry.address = netUtil->GetInPacket()->address;
|
||||||
|
serverList.push_back(entry);
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "service_locator.hpp"
|
||||||
|
#include "packet_type.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
@@ -39,7 +40,9 @@ protected:
|
|||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//utilities
|
//utilities
|
||||||
|
void Receive();
|
||||||
void BroadcastNetwork();
|
void BroadcastNetwork();
|
||||||
|
void PushServer(BroadcastResponse&);
|
||||||
|
|
||||||
//services
|
//services
|
||||||
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void ServerApplication::Init() {
|
|||||||
netUtil.Open(configUtil.Int("server.port"), sizeof(Packet));
|
netUtil.Open(configUtil.Int("server.port"), sizeof(Packet));
|
||||||
|
|
||||||
//disabled for debugging
|
//disabled for debugging
|
||||||
// running = true;
|
running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::Proc() {
|
void ServerApplication::Proc() {
|
||||||
@@ -60,12 +60,10 @@ void ServerApplication::HandleNetwork() {
|
|||||||
while(netUtil.Receive()) {
|
while(netUtil.Receive()) {
|
||||||
memcpy(&p, netUtil.GetInData(), sizeof(Packet));
|
memcpy(&p, netUtil.GetInData(), sizeof(Packet));
|
||||||
switch(p.type) {
|
switch(p.type) {
|
||||||
case PacketType::PING: {
|
case PacketType::PING:
|
||||||
//quick pong
|
//quick pong
|
||||||
Packet p;
|
|
||||||
p.type = PacketType::PONG;
|
p.type = PacketType::PONG;
|
||||||
netUtil.Send(&netUtil.GetInPacket()->address, &p, sizeof(Packet));
|
netUtil.Send(&netUtil.GetInPacket()->address, &p, sizeof(Packet));
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PacketType::PONG:
|
case PacketType::PONG:
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user