diff options
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index b69e0c0..6c4012e 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -149,7 +149,8 @@ void MainWidget::tick() | |||
| 149 | 149 | ||
| 150 | //qDebug() << "read str " << dataStr.length(); | 150 | //qDebug() << "read str " << dataStr.length(); |
| 151 | ProtoBuf::MapUpdate packet; | 151 | ProtoBuf::MapUpdate packet; |
| 152 | packet.ParseFromString(dataStr); | 152 | bool worked = packet.ParseFromString(dataStr); |
| 153 | Q_ASSERT(worked); | ||
| 153 | Transmission::map_t map = Util::createUninitialisedMap(); | 154 | Transmission::map_t map = Util::createUninitialisedMap(); |
| 154 | Q_ASSERT(packet.field_size() == (int) (Constants::map_size.width * Constants::map_size.height)); | 155 | Q_ASSERT(packet.field_size() == (int) (Constants::map_size.width * Constants::map_size.height)); |
| 155 | int i = 0; | 156 | int i = 0; |
| @@ -229,8 +230,14 @@ void MainWidget::playerScoreClicked() | |||
| 229 | 230 | ||
| 230 | Color::Color MainWidget::connectToServer() | 231 | Color::Color MainWidget::connectToServer() |
| 231 | { | 232 | { |
| 233 | // check command line arguments for server port | ||
| 234 | const QStringList &args = QCoreApplication::arguments(); | ||
| 235 | QString srv = args.value(1, "127.0.0.1"); | ||
| 236 | qDebug() << "srv: " << srv; | ||
| 237 | |||
| 238 | // connect to server | ||
| 232 | m_socket = new QTcpSocket(this); | 239 | m_socket = new QTcpSocket(this); |
| 233 | m_socket->connectToHost("127.0.0.1", Constants::port); | 240 | m_socket->connectToHost(srv, Constants::port); |
| 234 | bool worked = m_socket->waitForConnected(Constants::connection_timeout); | 241 | bool worked = m_socket->waitForConnected(Constants::connection_timeout); |
| 235 | if (worked) | 242 | if (worked) |
| 236 | { | 243 | { |
| @@ -239,10 +246,12 @@ Color::Color MainWidget::connectToServer() | |||
| 239 | worked = m_socket->waitForReadyRead(); | 246 | worked = m_socket->waitForReadyRead(); |
| 240 | if (worked) | 247 | if (worked) |
| 241 | { | 248 | { |
| 249 | // receive color | ||
| 242 | std::string data; | 250 | std::string data; |
| 243 | Util::QByteArrayToStdString(m_socket->readAll(), data); | 251 | Util::QByteArrayToStdString(m_socket->readAll(), data); |
| 244 | ProtoBuf::WhoAmI packet; | 252 | ProtoBuf::WhoAmI packet; |
| 245 | packet.ParseFromString(data); | 253 | Q_ASSERT(worked); |
| 254 | bool worked = packet.ParseFromString(data); | ||
| 246 | return static_cast<Color::Color>(packet.color() & Transmission::color_mask); | 255 | return static_cast<Color::Color>(packet.color() & Transmission::color_mask); |
| 247 | } | 256 | } |
| 248 | } | 257 | } |
