This sends the map to the client */
| 548 | |
| 549 | /** This sends the map to the client */ |
| 550 | NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap() |
| 551 | { |
| 552 | if (this->status < STATUS_AUTHORIZED) { |
| 553 | /* Illegal call, return error and ignore the packet */ |
| 554 | return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED); |
| 555 | } |
| 556 | |
| 557 | if (this->status == STATUS_AUTHORIZED) { |
| 558 | Debug(net, 9, "client[{}] SendMap(): first_packet", this->client_id); |
| 559 | |
| 560 | WaitTillSaved(); |
| 561 | this->savegame = std::make_shared<PacketWriter>(this); |
| 562 | |
| 563 | /* Now send the _frame_counter and how many packets are coming */ |
| 564 | auto p = std::make_unique<Packet>(this, PACKET_SERVER_MAP_BEGIN); |
| 565 | p->Send_uint32(_frame_counter); |
| 566 | this->SendPacket(std::move(p)); |
| 567 | |
| 568 | NetworkSyncCommandQueue(this); |
| 569 | Debug(net, 9, "client[{}] status = MAP", this->client_id); |
| 570 | this->status = STATUS_MAP; |
| 571 | /* Mark the start of download */ |
| 572 | this->last_frame = _frame_counter; |
| 573 | this->last_frame_server = _frame_counter; |
| 574 | |
| 575 | /* Make a dump of the current game */ |
| 576 | if (SaveWithFilter(this->savegame, true) != SL_OK) UserError("network savedump failed"); |
| 577 | } |
| 578 | |
| 579 | if (this->status == STATUS_MAP) { |
| 580 | bool last_packet = this->savegame->TransferToNetworkQueue(); |
| 581 | if (last_packet) { |
| 582 | Debug(net, 9, "client[{}] SendMap(): last_packet", this->client_id); |
| 583 | |
| 584 | /* Done reading, make sure saving is done as well */ |
| 585 | this->savegame->Destroy(); |
| 586 | this->savegame = nullptr; |
| 587 | |
| 588 | /* Set the status to DONE_MAP, no we will wait for the client |
| 589 | * to send it is ready (maybe that happens like never ;)) */ |
| 590 | Debug(net, 9, "client[{}] status = DONE_MAP", this->client_id); |
| 591 | this->status = STATUS_DONE_MAP; |
| 592 | |
| 593 | this->CheckNextClientToSendMap(); |
| 594 | } |
| 595 | } |
| 596 | return NETWORK_RECV_STATUS_OKAY; |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Tell that a client joined. |
no test coverage detected