Working on connection systems

This commit is contained in:
Kayne Ruse
2013-06-17 19:04:05 +10:00
parent 27ed91688a
commit 69f03cd250
2 changed files with 31 additions and 5 deletions
+27 -3
View File
@@ -168,13 +168,37 @@ void ServerApplication::Broadcast(BroadcastRequest& bcast) {
} }
void ServerApplication::HandleConnection(JoinRequest& request) { void ServerApplication::HandleConnection(JoinRequest& request) {
if (clients.size() >= SDLNET_MAX_UDPCHANNELS) {
//ignore the new connection if there's too many clients connected
return;
}
//create the containers //create the containers
ClientData client = { clientTicker++ }; ClientData client = { uniqueIndex };
PlayerData player = { playerTicker++ }; PlayerData player = { uniqueIndex };
uniqueIndex++;
//link the containers //link the containers
client.playerIndex = player.index; client.playerIndex = player.index;
player.clientIndex = client.index; player.clientIndex = client.index;
//??? oh fuck //fill the containers
player.handle = request.playerHandle;
player.avatar = request.playerAvatar;
//bind the address
client.channel = netUtil->Bind(&request.meta.address);
//push this information
clients[client.index] = client;
players[player.index] = player;
//send the player their information
Packet p;
p.meta.type = PacketType::JOIN_RESPONSE;
p.joinResponse.playerIndex = player.index;
netUtil->Send(client.channel, &p, sizeof(Packet));
//send it out to new players
//TODO
} }
+4 -2
View File
@@ -14,6 +14,7 @@
#include <map> #include <map>
#include <chrono> #include <chrono>
#include <string>
struct ClientData { struct ClientData {
int index; int index;
@@ -24,6 +25,8 @@ struct ClientData {
struct PlayerData { struct PlayerData {
int index; int index;
int clientIndex; int clientIndex;
std::string handle;
std::string avatar;
Vector2 position; Vector2 position;
Vector2 motion; Vector2 motion;
@@ -62,8 +65,7 @@ private:
bool running = false; bool running = false;
int clientTicker = 0; int uniqueIndex = 0;
int playerTicker = 0;
}; };
#endif #endif