Game Development Community

Libcurl implementation

by Fyodor "bank" Osokin · in Torque Game Engine · 11/17/2007 (7:44 pm) · 63 replies

this is my own libcurl implementation into TGE 1.5.2 "as is". Feel free to use it for your own games.
---------------------------
What implemented:
download works for http and ftp (without login/password - tested)
download works for http and ftp (with login/password - not tested)
you can set to resume previously interrupted download/upload (tested)
you can cancel download (tested)
upload works, but not tested heavily
---------------------------
See the available script functions.
If you need upload, don't forget to call .setUploadFlag(true); :)

---------------------------
Instructions:

Download "full" curl package (I've used 1.17.1).
Unpack it into /lib/ folder (so you have the /lib/curl-7.17.1/* )

For "Torque Demo" (or your own project):
Add ../lib/curl-7.17.1/include to the project's "Addition Include Directories".
Add ;CURL_STATICLIB to project's "Preprocessor Definitions".
Add ;"../lib/curl-7.17.1/lib/Release" to project's "Additional Library Directories".
Add curllib.lib to project's "Addition Dependencies".
Add libcmt.lib to project's "Ignore Specific Library" (without this it won't link the EXE).

Add lib/curl-7-17-1/lib/curllib.vcproj project file into your solution.

In curllib project's properties:
Add ";../../zlib" to the project's "Addition Include Directories".
Add ";HAVE_ZLIB_H;HAVE_ZLIB;HAVE_LIBZ;CURL_STATICLIB;CURL_DISABLE_LDAP" to the "Preprocessor Definitions".

engine changes:
game/main.cc:
at the top where all other includes are, add:
#include "sim/simCurl.h"
change the beginning of initLibraries function:
static bool initLibraries()
{
   [b]if (!SimCurl::initialize())
   {
      Platform::AlertOK("libcurl Error", "Unable to initialize the libcurl... aborting.");
      return false;
   }
[/b]
   if(!Net::init())
   ...
change the end of shutdownLibraries function:
Net::shutdown();
   [b]SimCurl::deinitialize();[/b]
}

Rebuild the "curllib" project.
Rebuild your project (Torque Demo).

If it don't compile and giving errors like "templates can't be used when "C" linkage.." for wspiapi.h (see this page for explanation), you need to change the curl/curl.h file in includes folder (changes in BOLD):
#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H))
/* The check above prevents the winsock2 inclusion if winsock.h already was
   included, since they can't co-exist without problems */
  [b]#ifdef __cplusplus
    }
  #endif[/b]
#include <winsock2.h>
#include <ws2tcpip.h>
  [b]#ifdef __cplusplus
    extern "C" {
  #endif[/b]
#endif

See next post for code :)
Page«First 1 2 3 4 Next»
#61
09/01/2010 (6:48 pm)
Thanks Tony for your comment on the threading part.

I managed to fix a important issue (no more than 2 download in the queue) by looking at your resource on Mysql.
#62
03/15/2011 (5:47 am)
Can you tell me how I can read from the buffer when I do not use the file write part? I am trying to make a GBitmap of it but it doesn't seem to work as far as what I am doing... This is what i have:

U32 SimCurl::loadBitmap()
{
	bitmap = new GBitmap;

	if(isRunning()) { Con::errorf("Still running!:");
	return 0;
	}
	
	FileStream* fileStream = FileStream::createAndOpen("starter.fps/test.png", Torque::FS::File::AccessMode::Write);

	fileStream->copyFrom(stream);

	//fileStream->write((U8 *)storagedesc.mem.ptr);

	fileStream->close();

	bitmap->read(*stream);

	return stream->getStreamSize();
}

DefineEngineMethod( SimCurl, loadBitmap, S32, (),,
				   "@brief Called to check if an object resides on the clientside.\n\n"
				   "@return True if the object resides on the client, false otherwise.")
{
	//GBitmap* bitmap = object->loadBitmap();
	return object->loadBitmap();
}

Ignore the file writes, I am trying some different things to see how the buffer part works... The function of course in normal methods would return some form of reference to the bitmap, but right now I just want it to make the actual bitmap...
#63
03/26/2011 (6:53 pm)
Ok, I'm sorry for being a bit of an idiot, but where can I get this "Full" libcurl?
Page«First 1 2 3 4 Next»