summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-12-05 14:34:19 +0000
committerrubidium <rubidium@openttd.org>2010-12-05 14:34:19 +0000
commit97434f0e06d2191b332a876e3171c5f3d1166d79 (patch)
tree8cbd35f8b6a5c9bb190d51b465dc22d9aa8dfd9c
parentc8e8b0e0a01e097320220ec05f2d0e27f82d3dc7 (diff)
downloadopenttd-97434f0e06d2191b332a876e3171c5f3d1166d79.tar.xz
(svn r21392) -Change: prepare the network protocol for getting the file size later in the download process
-rw-r--r--src/network/core/tcp_game.cpp2
-rw-r--r--src/network/core/tcp_game.h8
-rw-r--r--src/network/network_client.cpp22
-rw-r--r--src/network/network_client.h1
-rw-r--r--src/network/network_server.cpp3
5 files changed, 25 insertions, 11 deletions
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp
index 6c68217fc..73fece057 100644
--- a/src/network/core/tcp_game.cpp
+++ b/src/network/core/tcp_game.cpp
@@ -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)
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index 24adf6acd..40ffdb1d4 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -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,11 +273,16 @@ 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).
*/
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 7d1e7f669..40e8d5668 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -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;
diff --git a/src/network/network_client.h b/src/network/network_client.h
index cccec668d..0f73a6e1c 100644
--- a/src/network/network_client.h
+++ b/src/network/network_client.h
@@ -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);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 5437cd006..40c5c2f26 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -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);