Jump to content


Photo

Http Dll 2


  • Please log in to reply
156 replies to this topic

#1 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 715 posts
  • Version:GM8.1

Posted 02 June 2011 - 12:28 AM

A long time ago I created Http Dll, but that dll was rather difficult to use. So I've created a completely new version which is easier to use and has a lot more features. Since I was already using sockets internally, I decided to add functions to access them. Of course you also need buffers to manipulate the binary data, so I added those as well.

Features:
  • Http requests
    • Allows you to download web pages or files without blocking the game.
    • Allows you to set request headers and post parameters.
    • Allows you to read the status code, response headers and of course the message body.
    • Supports file uploads.
  • Sockets
    • Supports listening sockets (server) and normal sockets (client).
    • Supports IPv4 and IPv6.
    • Supports TCP and UDP.
  • Buffers: very similar to 39dll, but with a few extra data types.
  • MD5 and SHA-1
  • ZLib compression
  • RC4 encryption
  • Hexadecimal and base64 encoding/decoding
The DLL also fixes an annoying bug/feature in 39dll that can cause data to be lost. With 39dll, the maximum amount of data that can be recieved as a whole is limited by the operating system. Windows will only buffer a fixed amount of data, e.g. 64KB. This might not be enough if you're trying to send large files. If too much data is buffered by the receiver, the sender has to wait to send more data. Since 39dll's sendmessage function doesn't wait, part of the data is lost if too much data is sent at once. This DLL does additional buffering to avoid this problem, so no data is ever lost. You can buffer as much data as you want on both the sending side and the receiving side.

Unlike Http Dll, Http Dll 2 doesn't use a separate thread. I've changed this because it was confusing, and the advantage wasn't that big.

Latest version:
Download Http Dll 2.3 release 4 (with source code)

Older versions:
Download Http Dll 2.2 (with source code)
Download Http Dll 2.1 (with source code)
Download Http Dll 2.0 (with source code)

Documentation:
http://www.maartenba...lls/http-dll-2/

License
lgpl-v3.png
Http Dll 2 is distributed under the terms of the GNU Lesser General Public License.

Edited by Maarten Baert, 08 May 2013 - 09:54 AM.

  • 14

#2 Knuked

Knuked

    GMC Member

  • New Member
  • 242 posts
  • Version:GM:HTML5

Posted 02 June 2011 - 01:05 AM

Windows will only buffer a fixed amount of data, e.g. 64KB. This might not be enough if you're trying to send large files. If too much data is buffered by the receiver, the sender has to wait to send more data. Since 39dll's sendmessage function doesn't wait, part of the data is lost if too much data is sent at once. This DLL does additional buffering to avoid this problem, so no data is ever lost.


One of the absolute worst things about the 39dll in my opinion, not that my opinion matters much ;)

Anyhow Maarten, I hope this is a bit easier, the last one was rather difficult to use and I appreciate you noticing that and attempting to rectify. You bring a lot to this community with all your dlls' and hard work and for that I thank you friend. Plus one to you! I will most certainly give this thing another try :)

Edited by Knuked, 02 June 2011 - 01:06 AM.

  • 0

#3 Mayhem Games

Mayhem Games

    Proud Kiwi

  • GMC Member
  • 955 posts
  • Version:GM:Studio

Posted 02 June 2011 - 03:50 AM

Looks much better than the original :) I haven't tried this out properly yet but do have plans for it in an upcoming project. This update may just make it one of my favorite Game Maker dll's :lol:
  • 0

#4 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 2863 posts
  • Version:GM:Studio

Posted 02 June 2011 - 01:38 PM

A must-have on my DLLs folder and a must-use on most of my games, this post has been tagged :)
  • 0

#5 sinny

sinny

    GMC Member

  • New Member
  • 17 posts

Posted 02 June 2011 - 05:46 PM

I'm looking to either fix or dump my usage of 39dll, as I've just started testing a small project using it and I'm noticing what appears to be lag when only transferring a couple of numbers between client and server (for movement). I know this can't be right, so I assume I'm either using it incorrectly, or otherwise, but for now I'll have a play with this and see what it's like.

There aren't any installation instructions that I can find; I know this is easy for old hands but I'm only a month into GM. Any simple procedure?
  • 0

#6 Medo42

Medo42

    GMC Member

  • GMC Member
  • 220 posts

Posted 02 June 2011 - 06:52 PM

I'm looking to either fix or dump my usage of 39dll, as I've just started testing a small project using it and I'm noticing what appears to be lag when only transferring a couple of numbers between client and server (for movement). I know this can't be right, so I assume I'm either using it incorrectly, or otherwise, but for now I'll have a play with this and see what it's like.

Did you try to disable Nagle's algorighm? IIRC the command for that is setnagle(1), paradoxically.

Generally I have to say, this dll does look very good. I didn't look at everything yet, but this is the only dll/extension I know besides Faucet Networking that handles reading from and writing to sockets in a sane manner.
  • 0

#7 sinny

sinny

    GMC Member

  • New Member
  • 17 posts

Posted 03 June 2011 - 11:04 AM


I'm looking to either fix or dump my usage of 39dll, as I've just started testing a small project using it and I'm noticing what appears to be lag when only transferring a couple of numbers between client and server (for movement). I know this can't be right, so I assume I'm either using it incorrectly, or otherwise, but for now I'll have a play with this and see what it's like.

Did you try to disable Nagle's algorighm? IIRC the command for that is setnagle(1), paradoxically.


Oh good god that is insane. Totally fixed it. Uh, thanks.
  • 0

#8 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 10 June 2011 - 08:00 AM

What can be the reason this code not to work?
http_dll_2_1_init();
rq=httprequest_create();
httprequest_connect(rq,"http://randomsite.com/randompage.php?argument1=blah",0);
var st;
while(1) 
   {
    httprequest_update(rq);
    st = httprequest_get_state(rq);
    if st==4 || st==5 break;
    sleep(10);
   }
if st!=5 show_message(httprequest_get_message_body(rq));else {show_message(":C    :<    :(");show_message(httprequest_get_message_body(rq));}
httprequest_destroy(rq);
It always shows those emoticons >.>
  • 0

#9 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 715 posts
  • Version:GM8.1

Posted 11 June 2011 - 10:49 AM

It works for me ...

Make sure the server is online, and make sure your firewall isn't blocking your game.
  • 1

#10 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 11 June 2011 - 03:32 PM

Yeah, it turned out my website got deleted.
Anyway, I got another question: How do I make the dll ignore the html tags such as <!-- --> and <script> </script>? My webhost is putting them automatically and this only wastes bandwidth and time to send. >.>
  • 0

#11 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 715 posts
  • Version:GM8.1

Posted 13 June 2011 - 10:21 AM

You should filter them out manually with string functions. The easiest way to do this is to add a special 'marker' to your own data, so you can see where your data starts and ends. Like this:
echo "<----begin---->";
// (now echo your data)
echo "<----end---->";
Then you can use this script to remove the garbage:
// remove_garbage(str)
var marker_begin, marker_end, p1, p2;
marker_begin = "<----begin---->";
marker_end = "<----end---->";
p1 = string_pos(marker_begin, argument0);
p2 = string_pos(marker_end, argument0);
if p1=0 or p2<p1+string_length(marker_begin) {
    return "";
} else {
    return string_copy(argument0, p1+string_length(marker_begin), p2-p1-string_length(marker_begin));
}

Edited by Maarten Baert, 13 June 2011 - 10:23 AM.

  • 0

#12 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 13 June 2011 - 12:48 PM

I haven't tested this yet, but I liked v1 of the DLL, so I can't imagine I would dislike this ;) .

However, before I test it, I did have a question. This DLL has an MD5 hash algorithm built-in. Would it be possible to also include HMAC-SHA1? This is used for many OAuth systems (the security system of choice for most big online services nowadays), so including it would make integration with well-known services much easier.

I found a SHA1 DLL here: http://gmc.yoyogames...dpost&p=1080503 , so making an HMAC using that shouldn't be too hard, but I'd rather not use 2 separate DLLs for one function, especially since MD5 is already included.

-IMP ;) :)

*EDIT* You know that whole part about "shouldn't be too hard to make the HMAC script"? I was wrong. My attempt ended up with the same unresolved issue found here: http://gmc.yoyogames...howtopic=484442 . So please, please, please, add in HMAC-SHA1 hashing, please.

Edited by IceMetalPunk, 13 June 2011 - 01:04 PM.

  • 0

#13 Jub Jub

Jub Jub

    GMC Member

  • GMC Member
  • 15 posts

Posted 15 June 2011 - 02:29 AM

Excellent, this DLL looks exactly like what I was looking for. :) Thanks!
  • 0

#14 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 15 June 2011 - 04:41 PM

I got another problem - when I open my website with the browser, the php's echoes text is displayed, but when I try to get the result of the same addres ingame with httprequest_get_message_body, it returns an empty string "". The scripts were working correctly, but then the website was took down for a while to be approved - when it got back online, it simply stopped replying to the game. Why is this? I think the problem lies in the scripts, could it be somewhere else?
  • 0

#15 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 15 June 2011 - 10:49 PM

Link is dead :(
  • 0

#16 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 715 posts
  • Version:GM8.1

Posted 16 June 2011 - 03:30 PM

@locohost: The link works for me ...

I got another problem - when I open my website with the browser, the php's echoes text is displayed, but when I try to get the result of the same addres ingame with httprequest_get_message_body, it returns an empty string "". The scripts were working correctly, but then the website was took down for a while to be approved - when it got back online, it simply stopped replying to the game. Why is this? I think the problem lies in the scripts, could it be somewhere else?

Try setting the User-Agent header to the User-Agent of an existing browser (e.g. "Mozilla/5.0"). Maybe the website doesn't respond to requests without a 'real' user agent (I've seen this a few times).

@IceMetalPunk:
Adding SHA-1 shouldn't be that hard, I will try it.

If I understand correctly, it works like this:
HMAC-MD5(message, key) = MD5(opad(key)+MD5(ipad(key)+message))
But I think MD5 is supposed to return a 16-byte binary string instead of a 32-byte hexadecimal string. You can do that with buffer_write_hex. I wrote a script for HMAC-MD5 and it gives the same results as PHP, so I think it works :).
// hmac_md5_string(message, key);
var b, i, c, h;

b = buffer_create();
c = min(string_length(argument1), 64);

// ipad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$36);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $36);
}

// first hash
md5_begin();
md5_read_buffer(b);
md5_read_string(argument0);
md5_end();
h = md5_result();
buffer_clear(b);

// opad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$5c);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $5c);
}
buffer_write_hex(b, h);

// second hash
md5_begin();
md5_read_buffer(b);
md5_end();
h = md5_result();

buffer_destroy(b);

return h;
Alternatively, if you want to calculate the HMAC of a buffer:
// hmac_md5_buffer(messagebuffer, key);
var b, i, c, h;

b = buffer_create();
c = min(string_length(argument1), 64);

// ipad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$36);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $36);
}

// first hash
md5_begin();
md5_read_buffer(b);
md5_read_buffer(argument0);
md5_end();
h = md5_result();
buffer_clear(b);

// opad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$5c);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $5c);
}
buffer_write_hex(b, h);

// second hash
md5_begin();
md5_read_buffer(b);
md5_end();
h = md5_result();

buffer_destroy(b);

return h;

Edited by Maarten Baert, 16 June 2011 - 03:32 PM.

  • 2

#17 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 16 June 2011 - 03:47 PM

Wow thanks Maarten for that really useful reply!

Here is what I see when I click the link...

Download Link Broken
  • 0

#18 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 16 June 2011 - 04:45 PM


I got another problem - when I open my website with the browser, the php's echoes text is displayed, but when I try to get the result of the same addres ingame with httprequest_get_message_body, it returns an empty string "". The scripts were working correctly, but then the website was took down for a while to be approved - when it got back online, it simply stopped replying to the game. Why is this? I think the problem lies in the scripts, could it be somewhere else?

Try setting the User-Agent header to the User-Agent of an existing browser (e.g. "Mozilla/5.0"). Maybe the website doesn't respond to requests without a 'real' user agent (I've seen this a few times).

Thanks, although it still doesnt work for me. I tried both with "Mozilla/5.0" and "Opera/9.60 (Windows NT 5.1; U; de) Presto/2.1.1"(got from this site) as User-Agent header, but the website seems not to care too much about this.
Here is the script I use everytime when I create a new http request:
var rq;
rq=httprequest_create();
//httprequest_set_request_header(rq, "User-Agent", "Mozilla/5.0", true);
httprequest_set_request_header(rq, "User-Agent", "Opera/9.60 (Windows NT 5.1; U; de) Presto/2.1.1", true);  
httprequest_connect(rq,argument0,0);
return rq;
Can something else be revealing that the game is not a browser?
  • 0

#19 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 715 posts
  • Version:GM8.1

Posted 16 June 2011 - 06:21 PM

I've added SHA-1, and I've also added an example for the HMAC scripts.

@locohost: Okay, try this one:
http://www.mediafire...adwi5lxch97dum9
I have no idea why the first one doesn't work though.

@regular: There are a lot of possibilities, including:
- 'Referer' header (url of the previous page that was visited)
- 'Cookie' header
- 'Accept-Encoding' header
And many more. You could try a Firefox plugin like HttpFox to find out what headers Firefox is sending, and copy those headers to your program (except the Connection and Keep-Alive headers, those can't be used with this DLL).

If that doesn't work, can you tell me the URL of the website?
  • 1

#20 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 16 June 2011 - 06:35 PM

@Maarten: I went to your website and got it from there. Not sure what's up with the link though. Thanks :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users