packet is being sent and received, bare-bones ping-pong is working

This commit is contained in:
Kayne Ruse
2013-05-20 01:02:15 +10:00
parent b587759203
commit 7866f46ed5
18 changed files with 342 additions and 63 deletions
+29 -5
View File
@@ -9,8 +9,8 @@ void Server::Init() {
if (SDLNet_Init()) {
throw(runtime_error("Failed to initialize SDL_net"));
}
config.Load("config.cfg");
netUtil.Open(config.Integer("port"), 512);
configUtil.Load("config.cfg");
netUtil.Open(configUtil.Integer("port"), sizeof(Packet));
running = true;
}
@@ -31,18 +31,42 @@ void Server::Quit() {
}
void Server::HandleInput() {
while(netUtil.Receive()) {
cout << reinterpret_cast<char*>(netUtil.GetInData()) << endl;
}
//accept new connections
//accept updates from the clients
//read the updates from the clients into internal containers
Packet packet;
while(netUtil.Receive()) {
memcpy(reinterpret_cast<void*>(&packet), netUtil.GetInData(), sizeof(Packet));
switch(packet.type) {
case PacketList::PING:
//respond to pings with the server name
cout << "responding to ping..." << endl;
packet.type = PacketList::PONG;
sprintf(packet.pong.buffer, "%s",configUtil.CString("servername"));
netUtil.Send(&netUtil.GetInPacket()->address, reinterpret_cast<void*>(&packet), sizeof(Packet));
break;
case PacketList::JOINREQUEST:
//
break;
case PacketList::NEWPLAYER:
//
break;
case PacketList::DELETEPLAYER:
//
break;
case PacketList::MOTIONUPDATE:
//
break;
}
}
}
void Server::UpdateWorld() {
//update internals ie.
// ai
// loot drops
delta.Calculate();
playerMgr.UpdateAll(delta.GetDelta());
}
void Server::HandleOutput() {