summaryrefslogtreecommitdiff
path: root/src/network/network_content.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-17 16:53:32 +0000
committerrubidium <rubidium@openttd.org>2009-01-17 16:53:32 +0000
commit3a13b75e37b5642de3c1e89cf6ab3bf860b76375 (patch)
tree76215ba6e27bc0b1f49919c01ff2608f276b8e3d /src/network/network_content.h
parent2850bf9e006ebdd40b5562cca5117bca027cfab5 (diff)
downloadopenttd-3a13b75e37b5642de3c1e89cf6ab3bf860b76375.tar.xz
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
Diffstat (limited to 'src/network/network_content.h')
-rw-r--r--src/network/network_content.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/network/network_content.h b/src/network/network_content.h
new file mode 100644
index 000000000..bcbb05f8f
--- /dev/null
+++ b/src/network/network_content.h
@@ -0,0 +1,79 @@
+/* $Id$ */
+
+/** @file network_content.h Part of the network protocol handling content distribution. */
+
+#ifndef NETWORK_CONTENT_H
+#define NETWORK_CONTENT_H
+
+#if defined(ENABLE_NETWORK)
+
+#include "core/tcp_content.h"
+#include "../core/smallvec_type.hpp"
+
+/** Vector with content info */
+typedef SmallVector<ContentInfo *, 16> ContentVector;
+/** Iterator for the content vector */
+typedef ContentInfo **ContentIterator;
+
+/** Callbacks for notifying others about incoming data */
+struct ContentCallback {
+ /**
+ * We received a content info.
+ * @param ci the content info
+ */
+ virtual void OnReceiveContentInfo(ContentInfo *ci) {}
+
+ /**
+ * We have progress in the download of a file
+ * @param ci the content info of the file
+ * @param bytes the number of bytes downloaded since the previous call
+ */
+ virtual void OnDownloadProgress(ContentInfo *ci, uint bytes) {}
+
+ /**
+ * We have finished downloading a file
+ * @param cid the ContentID of the downloaded file
+ */
+ virtual void OnDownloadComplete(ContentID cid) {}
+
+ /** Silentium */
+ virtual ~ContentCallback() {}
+};
+
+/**
+ * Socket handler for the content server connection
+ */
+class ClientNetworkContentSocketHandler : public NetworkContentSocketHandler {
+protected:
+ SmallVector<ContentCallback *, 2> callbacks; ///< Callbacks to notify "the world"
+
+ FILE *curFile; ///< Currently downloaded file
+ ContentInfo *curInfo; ///< Information about the currently downloaded file
+
+ friend ClientNetworkContentSocketHandler *NetworkContent_Connect(ContentCallback *cb);
+ friend void NetworkContent_Disconnect(ContentCallback *cb);
+
+ DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO);
+ DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
+
+ ClientNetworkContentSocketHandler(SOCKET s, const struct sockaddr_in *sin);
+ ~ClientNetworkContentSocketHandler();
+public:
+ void RequestContentList(ContentType type);
+ void RequestContentList(uint count, const ContentID *content_ids);
+ void RequestContentList(ContentVector *cv, bool send_md5sum = true);
+
+ void RequestContent(uint count, const uint32 *content_ids);
+};
+
+ClientNetworkContentSocketHandler *NetworkContent_Connect(ContentCallback *cb);
+void NetworkContent_Disconnect(ContentCallback *cb);
+void NetworkContentLoop();
+
+void ShowNetworkContentListWindow(ContentVector *cv = NULL, ContentType type = CONTENT_TYPE_END);
+
+#else
+static inline void ShowNetworkContentListWindow() {}
+#endif /* ENABLE_NETWORK */
+
+#endif /* NETWORK_CONTENT_H */