(svn r21392) -Change: prepare the network protocol for getting the file size later in the download process

This commit is contained in:
rubidium 2010-12-05 14:34:19 +00:00
parent c8e8b0e0a0
commit 97434f0e06
5 changed files with 25 additions and 11 deletions

View File

@ -89,6 +89,7 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
GAME_COMMAND(PACKET_CLIENT_GETMAP)
GAME_COMMAND(PACKET_SERVER_WAIT)
GAME_COMMAND(PACKET_SERVER_MAP_BEGIN)
GAME_COMMAND(PACKET_SERVER_MAP_SIZE)
GAME_COMMAND(PACKET_SERVER_MAP_DATA)
GAME_COMMAND(PACKET_SERVER_MAP_DONE)
GAME_COMMAND(PACKET_CLIENT_MAP_OK)
@ -177,6 +178,7 @@ DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WELCOME)
DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP)
DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT)
DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_BEGIN)
DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_SIZE)
DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DATA)
DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DONE)
DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)

View File

@ -73,6 +73,7 @@ enum PacketGameType {
PACKET_CLIENT_GETMAP, ///< Client requests the actual map.
PACKET_SERVER_WAIT, ///< Server tells the client there are some people waiting for the map as well.
PACKET_SERVER_MAP_BEGIN, ///< Server tells the client that it is beginning to send the map.
PACKET_SERVER_MAP_SIZE, ///< Server tells the client what the (compressed) size of the map is.
PACKET_SERVER_MAP_DATA, ///< Server sends bits of the map to the client.
PACKET_SERVER_MAP_DONE, ///< Server tells it has just sent the last bits of the map to the client.
PACKET_CLIENT_MAP_OK, ///< Client tells the server that it received the whole map.
@ -272,10 +273,15 @@ protected:
/**
* Sends that the server will begin with sending the map to the client:
* uint32 Current frame.
* uint32 Size of the map (in bytes).
*/
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_BEGIN);
/**
* Sends the size of the map to the client.
* uint32 Size of the (compressed) map (in bytes).
*/
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_SIZE);
/**
* Sends the data of the map to the client:
* Contains a part of the map (until max size of packet).

View File

@ -691,7 +691,6 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_BEGIN)
if (this->status < STATUS_AUTHORIZED || this->status >= STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
this->status = STATUS_MAP;
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
if (this->download_file != NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
char filename[MAX_PATH];
@ -708,15 +707,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_BEGIN)
_frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32();
_network_join_bytes = 0;
_network_join_bytes_total = p->Recv_uint32();
/* If the network connection has been closed due to loss of connection
* or when _network_join_kbytes_total is 0, the join status window will
* do a division by zero. When the connection is lost, we just return
* that. If kbytes_total is 0, the packet must be malformed as a
* savegame less than 1 kilobyte is practically impossible. */
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
if (_network_join_bytes_total == 0) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
_network_join_bytes_total = 0;
_network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING;
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0);
@ -724,6 +715,17 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_BEGIN)
return NETWORK_RECV_STATUS_OKAY;
}
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_SIZE)
{
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
if (this->download_file == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
_network_join_bytes_total = p->Recv_uint32();
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0);
return NETWORK_RECV_STATUS_OKAY;
}
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_DATA)
{
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;

View File

@ -55,6 +55,7 @@ protected:
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WELCOME);
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT);
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_BEGIN);
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_SIZE);
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DATA);
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DONE);
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_JOIN);

View File

@ -404,6 +404,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
/* Now send the _frame_counter and how many packets are coming */
Packet *p = new Packet(PACKET_SERVER_MAP_BEGIN);
p->Send_uint32(_frame_counter);
this->SendPacket(p);
p = new Packet(PACKET_SERVER_MAP_SIZE);
p->Send_uint32(ftell(file_pointer));
this->SendPacket(p);