diff options
| author | manuel <manuel@mausz.at> | 2011-05-11 17:38:29 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-11 17:38:29 +0200 |
| commit | ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5 (patch) | |
| tree | fb48f74ffcddcd8b260ebf78062623427aeda862 /pacman-c++/server | |
| parent | 535c342a2f28e0a1e90010b2f0ff4018eeeb200a (diff) | |
| download | foop-ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5.tar.gz foop-ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5.tar.bz2 foop-ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5.zip | |
- 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
Diffstat (limited to 'pacman-c++/server')
| -rw-r--r-- | pacman-c++/server/server.cpp | 39 | ||||
| -rw-r--r-- | pacman-c++/server/server.h | 6 |
2 files changed, 24 insertions, 21 deletions
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() | |||
| 84 | return; | 84 | return; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | /* fetch key updates */ | 87 | /* fetch client updates */ |
| 88 | keyPressUpdate(); | 88 | readClientUpdates(); |
| 89 | 89 | ||
| 90 | /* let the bots move */ | 90 | /* let the bots move */ |
| 91 | foreach (Color::Color color, m_bots) | 91 | foreach (Color::Color color, m_bots) |
| @@ -402,7 +402,7 @@ bool Server::waitForClientConnections() | |||
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | char buf[1024]; | 404 | char buf[1024]; |
| 405 | enet_address_get_host_ip(&m_host->address, buf, 1024); | 405 | enet_address_get_host_ip(&m_host->address, buf, sizeof(buf)); |
| 406 | std::cout << "[Server] Listening on: " | 406 | std::cout << "[Server] Listening on: " |
| 407 | << qPrintable(QString("%1:%2").arg(buf).arg(m_host->address.port)) << std::endl; | 407 | << qPrintable(QString("%1:%2").arg(buf).arg(m_host->address.port)) << std::endl; |
| 408 | 408 | ||
| @@ -431,14 +431,18 @@ bool Server::waitForClientConnections() | |||
| 431 | m_clientConnections[event.peer] = color; | 431 | m_clientConnections[event.peer] = color; |
| 432 | packet.set_color(color); | 432 | packet.set_color(color); |
| 433 | Util::sendPacket(packet, event.peer, m_host); | 433 | Util::sendPacket(packet, event.peer, m_host); |
| 434 | std::cout << "[Connect] New Player: color=" << qPrintable(Util::colorToString(color)) << std::endl; | 434 | |
| 435 | char buf[1024]; | ||
| 436 | enet_address_get_host_ip(&event.peer->address, buf, sizeof(buf)); | ||
| 437 | std::cout << "[Connect] New Player: color=" << qPrintable(Util::colorToString(color)) | ||
| 438 | << ", address=" << buf << ':' << event.peer->address.port << std::endl; | ||
| 435 | } | 439 | } |
| 436 | break; | 440 | break; |
| 437 | case ENET_EVENT_TYPE_RECEIVE: | 441 | case ENET_EVENT_TYPE_RECEIVE: |
| 438 | keyPressUpdate(&event); | 442 | processClientUpdate(&event); |
| 439 | break; | 443 | break; |
| 440 | case ENET_EVENT_TYPE_DISCONNECT: | 444 | case ENET_EVENT_TYPE_DISCONNECT: |
| 441 | keyPressUpdate(&event); | 445 | processClientUpdate(&event); |
| 442 | break; | 446 | break; |
| 443 | default: | 447 | default: |
| 444 | break; | 448 | break; |
| @@ -626,28 +630,29 @@ void Server::botCalculate(Actor *actor) | |||
| 626 | m_actorMovements[actor->color()] = list.at(rand); | 630 | m_actorMovements[actor->color()] = list.at(rand); |
| 627 | } | 631 | } |
| 628 | 632 | ||
| 629 | void Server::keyPressUpdate() | 633 | void Server::readClientUpdates() |
| 630 | { | 634 | { |
| 631 | ProtoBuf::KeyPressUpdate packet; | ||
| 632 | ENetEvent event; | 635 | ENetEvent event; |
| 633 | while (enet_host_service(m_host, &event, 1) > 0) | 636 | while (enet_host_service(m_host, &event, 1) > 0) |
| 634 | keyPressUpdate(&event); | 637 | processClientUpdate(&event); |
| 635 | } | 638 | } |
| 636 | 639 | ||
| 637 | void Server::keyPressUpdate(ENetEvent *event) | 640 | void Server::processClientUpdate(ENetEvent *event) |
| 638 | { | 641 | { |
| 639 | ProtoBuf::KeyPressUpdate packet; | ||
| 640 | switch(event->type) | 642 | switch(event->type) |
| 641 | { | 643 | { |
| 642 | case ENET_EVENT_TYPE_RECEIVE: | 644 | case ENET_EVENT_TYPE_RECEIVE: |
| 643 | { | 645 | { |
| 644 | QSharedPointer<QByteArray> data = Util::receivePacket(event->packet); | 646 | QSharedPointer<QByteArray> data = Util::receivePacket(event->packet); |
| 645 | enet_packet_destroy(event->packet); | 647 | enet_packet_destroy(event->packet); |
| 646 | bool worked = packet.ParseFromArray(data->data(), data->size()); | 648 | ProtoBuf::ClientUpdate packet; |
| 647 | Q_ASSERT(worked); | ||
| 648 | Q_UNUSED(worked); | ||
| 649 | Transmission::field_t direction = packet.newkey(); | ||
| 650 | Color::Color color = m_clientConnections[event->peer]; | 649 | Color::Color color = m_clientConnections[event->peer]; |
| 650 | if (!packet.ParseFromArray(data->data(), data->size())) | ||
| 651 | { | ||
| 652 | qWarning() << "Invalid packet from client color=" << color; | ||
| 653 | return; | ||
| 654 | } | ||
| 655 | Transmission::field_t direction = packet.new_direction(); | ||
| 651 | qDebug() << "[KeyPress] actor=" << color << "direction=" << direction; | 656 | qDebug() << "[KeyPress] actor=" << color << "direction=" << direction; |
| 652 | m_actorMovements[color] = Util::transmissionMovementToActor(direction); | 657 | m_actorMovements[color] = Util::transmissionMovementToActor(direction); |
| 653 | } | 658 | } |
| @@ -760,7 +765,7 @@ void Server::initRoundMap() | |||
| 760 | 765 | ||
| 761 | disconnect(AudioManager::self()->audioPlayer(), NULL, this, NULL); | 766 | disconnect(AudioManager::self()->audioPlayer(), NULL, this, NULL); |
| 762 | connect(AudioManager::self()->audioPlayer(), SIGNAL(finished()), this, SLOT(startGame())); | 767 | connect(AudioManager::self()->audioPlayer(), SIGNAL(finished()), this, SLOT(startGame())); |
| 763 | AudioManager::self()->audioPlayer()->play(Sound::Intro); | 768 | AudioManager::self()->play(Sound::Intro); |
| 764 | m_tickTimer->start(); | 769 | m_tickTimer->start(); |
| 765 | } | 770 | } |
| 766 | 771 | ||
| @@ -782,7 +787,7 @@ void Server::stopGame(bool delay) | |||
| 782 | { | 787 | { |
| 783 | disconnect(AudioManager::self()->audioPlayer(), NULL, this, NULL); | 788 | disconnect(AudioManager::self()->audioPlayer(), NULL, this, NULL); |
| 784 | connect(AudioManager::self()->audioPlayer(), SIGNAL(finished()), this, SLOT(stopGame())); | 789 | connect(AudioManager::self()->audioPlayer(), SIGNAL(finished()), this, SLOT(stopGame())); |
| 785 | AudioManager::self()->audioPlayer()->play(Sound::Die); | 790 | AudioManager::self()->play(Sound::Die); |
| 786 | return; | 791 | return; |
| 787 | } | 792 | } |
| 788 | 793 | ||
diff --git a/pacman-c++/server/server.h b/pacman-c++/server/server.h index 857f23d..26c1af2 100644 --- a/pacman-c++/server/server.h +++ b/pacman-c++/server/server.h | |||
| @@ -11,8 +11,6 @@ extern "C" { | |||
| 11 | #include "enet/enet.h" | 11 | #include "enet/enet.h" |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | class QTcpSocket; | ||
| 15 | |||
| 16 | class Server | 14 | class Server |
| 17 | : public SceneHolder | 15 | : public SceneHolder |
| 18 | { | 16 | { |
| @@ -27,8 +25,8 @@ protected slots: | |||
| 27 | void tick(); | 25 | void tick(); |
| 28 | 26 | ||
| 29 | /* receive updates of client */ | 27 | /* receive updates of client */ |
| 30 | void keyPressUpdate(); | 28 | void readClientUpdates(); |
| 31 | void keyPressUpdate(ENetEvent *event); | 29 | void processClientUpdate(ENetEvent *event); |
| 32 | 30 | ||
| 33 | protected: | 31 | protected: |
| 34 | /* block until we have connections from all clients */ | 32 | /* block until we have connections from all clients */ |
