From ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 11 May 2011 17:38:29 +0200 Subject: - fix audio plugin and make that a real interface - that fixes a duplicate statis audiomanager (1x pacman, 1x audio plugin) on windows - display won/lost dialog upon gameend --- pacman-c++/server/server.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'pacman-c++/server/server.cpp') diff --git a/pacman-c++/server/server.cpp b/pacman-c++/server/server.cpp index 877c4a6..316b719 100644 --- a/pacman-c++/server/server.cpp +++ b/pacman-c++/server/server.cpp @@ -84,8 +84,8 @@ void Server::tick() return; } - /* fetch key updates */ - keyPressUpdate(); + /* fetch client updates */ + readClientUpdates(); /* let the bots move */ foreach (Color::Color color, m_bots) @@ -402,7 +402,7 @@ bool Server::waitForClientConnections() } char buf[1024]; - enet_address_get_host_ip(&m_host->address, buf, 1024); + enet_address_get_host_ip(&m_host->address, buf, sizeof(buf)); std::cout << "[Server] Listening on: " << qPrintable(QString("%1:%2").arg(buf).arg(m_host->address.port)) << std::endl; @@ -431,14 +431,18 @@ bool Server::waitForClientConnections() m_clientConnections[event.peer] = color; packet.set_color(color); Util::sendPacket(packet, event.peer, m_host); - std::cout << "[Connect] New Player: color=" << qPrintable(Util::colorToString(color)) << std::endl; + + char buf[1024]; + enet_address_get_host_ip(&event.peer->address, buf, sizeof(buf)); + std::cout << "[Connect] New Player: color=" << qPrintable(Util::colorToString(color)) + << ", address=" << buf << ':' << event.peer->address.port << std::endl; } break; case ENET_EVENT_TYPE_RECEIVE: - keyPressUpdate(&event); + processClientUpdate(&event); break; case ENET_EVENT_TYPE_DISCONNECT: - keyPressUpdate(&event); + processClientUpdate(&event); break; default: break; @@ -626,28 +630,29 @@ void Server::botCalculate(Actor *actor) m_actorMovements[actor->color()] = list.at(rand); } -void Server::keyPressUpdate() +void Server::readClientUpdates() { - ProtoBuf::KeyPressUpdate packet; ENetEvent event; while (enet_host_service(m_host, &event, 1) > 0) - keyPressUpdate(&event); + processClientUpdate(&event); } -void Server::keyPressUpdate(ENetEvent *event) +void Server::processClientUpdate(ENetEvent *event) { - ProtoBuf::KeyPressUpdate packet; switch(event->type) { case ENET_EVENT_TYPE_RECEIVE: { QSharedPointer data = Util::receivePacket(event->packet); enet_packet_destroy(event->packet); - bool worked = packet.ParseFromArray(data->data(), data->size()); - Q_ASSERT(worked); - Q_UNUSED(worked); - Transmission::field_t direction = packet.newkey(); + ProtoBuf::ClientUpdate packet; Color::Color color = m_clientConnections[event->peer]; + if (!packet.ParseFromArray(data->data(), data->size())) + { + qWarning() << "Invalid packet from client color=" << color; + return; + } + Transmission::field_t direction = packet.new_direction(); qDebug() << "[KeyPress] actor=" << color << "direction=" << direction; m_actorMovements[color] = Util::transmissionMovementToActor(direction); } @@ -760,7 +765,7 @@ void Server::initRoundMap() disconnect(AudioManager::self()->audioPlayer(), NULL, this, NULL); connect(AudioManager::self()->audioPlayer(), SIGNAL(finished()), this, SLOT(startGame())); - AudioManager::self()->audioPlayer()->play(Sound::Intro); + AudioManager::self()->play(Sound::Intro); m_tickTimer->start(); } @@ -782,7 +787,7 @@ void Server::stopGame(bool delay) { disconnect(AudioManager::self()->audioPlayer(), NULL, this, NULL); connect(AudioManager::self()->audioPlayer(), SIGNAL(finished()), this, SLOT(stopGame())); - AudioManager::self()->audioPlayer()->play(Sound::Die); + AudioManager::self()->play(Sound::Die); return; } -- cgit v1.2.3