How to make a web browser Game

No other external tools or programs are required except Game Maker and a dll.
Firstly to connect to the internet and use the HTTP protocol in Game Maker. You can either use the readily made mplay_ functions avaliable, but there a bit slow. I recommend using 39dll (GMC topic) to handle all your winsock calls.
So basically download the dll and scripts for 39dll.
Once you have them heres the code to execute a HTTP protocol:
01 // HTTP(host, GET/POST,POST variables)
02 if !bufferexists(global.HTTP_buffer)
03 global.HTTP_buffer=createbuffer();
04 //if !tcpconnected(global.HTTP_sock)
05 {
06 global.HTTP_sock = tcpconnect(argument0, 80, 0);
07 if(!global.HTTP_sock)
08 {
09 show_message("Unable to connect to "+argument0);
10 return -1;
11 exit;
12 }
13 }
14 setformat(global.HTTP_sock, 1, chr(13) + chr(10));
15 newLine = chr(13) + chr(10);
16 clearbuffer(global.HTTP_buffer);
17 writechars(argument1+" HTTP/1.0" + newLine,global.HTTP_buffer);
18 writechars("Host: "+argument0 + newLine,global.HTTP_buffer);
19 writechars("User-Agent: Shadow Zone/1.0" + newLine,global.HTTP_buffer);
20 if is_string(argument2)
21 {
22 writechars("Content-Type: application/x-www-form-urlencoded"+newLine,global.HTTP_buffer);
23 writechars("Content-Length: "+string(string_length(argument2))+newLine,global.HTTP_buffer);
24 writechars(newLine+argument2,global.HTTP_buffer);
25 }
26 //show_message(argument1+" HTTP/1.0" + newLine+"Host: "+argument0 + newLine+newLine+argument2);
27 sendmessage(global.HTTP_sock,"",0,global.HTTP_buffer);
28 processHeader = true;
29 while(processHeader)
30 {
31 receivemessage(global.HTTP_sock,0,global.HTTP_buffer);
32 firstWord = readsep(newLine,global.HTTP_buffer);
33 switch(firstWord)
34 {
35 case "": //blank line
36 processHeader = false;
37 break;
38
39 //read important stuff from header...
40 }
41 }
42 clearbuffer(global.HTTP_buffer);
43 setformat(global.HTTP_sock, 2);
44 retVal = "";
45 while(1)
46 {
47 size = receivemessage(global.HTTP_sock, 6000,global.HTTP_buffer);
48 if(size > 0)
49 retVal += readchars(size,global.HTTP_buffer);
50 else break;
51 }
52 return retVal;
This is how you would use the above code once 39dll and the scripts are implemented into your game.
To open www.nilbd.tk/index.php:
1 dllinit(0,1,1);
2 HTTP("www.nilbd.tk","GET /index.php");
This function will return the HTML code of the webpage. I’m not sure how you would parse the HTML code to display it as a webpage but that is how you access a webpage.
~Ad
PS: If you meant to play your games in a web browser refer to csmanoj’s post, but if you wanted to turn your game into a web browser use this post and reply if more help is required.

0 comments: