Mmh I made an "internet" plugin for a test game (an online chess game...). The plugin is not yet finished, but 5 functions are operational:
void InitPostContent();
void AddPostContent(string variable, string content);
string SendWebPostMethod(string url, string action);
string ReadWebContent(string url, string action);
string SaveWebImage(string url, string action, string destFile);
The first three functions work the way an html form works, with the POST method:
- InitPostContent will initialize variables and values.
- AddPostContent will add a variable containing a value.
Example:
AddPostContent("test", "a value"); would work the same way as a form object in a web page :
<input type="hidden" name="test" value="a value">
- SendWebPostMethod simply submit variables and values to an url, the same way a form works, and then returns the page content as a string.
Example:
SendWebPostMethod("http://www.test.com/score.php", "?action=newscore"); would work the same way as if you submited a form with these parameters:
<form action="http://www.test.com/score.php?action=newscore" method="POST">
- ReadWebContent returns the content of a web page.
Example:
String buffer;
StrCopy(buffer, ReadWebContent("http://www.test.com/ags/agssave.001", "") );
File *output = File.Open("agssave.001", eFileWrite);
output.WriteRawLine(buffer);
output.Close();
This will copy the agssave from a website into the game folder.
Note: You could do the same thing with SendWebPostMethod as it also returns the url content.
- SaveWebImage will copy an image from an url into your game folder :
Example:
DynamicSprite * avatar;
SaveWebImage("http://www.test.com/images/avatar.bmp", "", "data/avatars/avatar.bmp");
avatar = DynamicSprite.CreateFromFile("data/avatars/avatar.bmp");
if (avatar != null) {
RawDrawImage(150, 100, avatar.Graphic);
avatar.Delete();
}
You'll find more info in the zip file.
void InitPostContent();
void AddPostContent(string variable, string content);
string SendWebPostMethod(string url, string action);
string ReadWebContent(string url, string action);
string SaveWebImage(string url, string action, string destFile);
The first three functions work the way an html form works, with the POST method:
- InitPostContent will initialize variables and values.
- AddPostContent will add a variable containing a value.
Example:
AddPostContent("test", "a value"); would work the same way as a form object in a web page :
<input type="hidden" name="test" value="a value">
- SendWebPostMethod simply submit variables and values to an url, the same way a form works, and then returns the page content as a string.
Example:
SendWebPostMethod("http://www.test.com/score.php", "?action=newscore"); would work the same way as if you submited a form with these parameters:
<form action="http://www.test.com/score.php?action=newscore" method="POST">
- ReadWebContent returns the content of a web page.
Example:
String buffer;
StrCopy(buffer, ReadWebContent("http://www.test.com/ags/agssave.001", "") );
File *output = File.Open("agssave.001", eFileWrite);
output.WriteRawLine(buffer);
output.Close();
This will copy the agssave from a website into the game folder.
Note: You could do the same thing with SendWebPostMethod as it also returns the url content.
- SaveWebImage will copy an image from an url into your game folder :
Example:
DynamicSprite * avatar;
SaveWebImage("http://www.test.com/images/avatar.bmp", "", "data/avatars/avatar.bmp");
avatar = DynamicSprite.CreateFromFile("data/avatars/avatar.bmp");
if (avatar != null) {
RawDrawImage(150, 100, avatar.Graphic);
avatar.Delete();
}
You'll find more info in the zip file.
ags_filenet.zip, 145ko
Download
Download