Sending a BMP or a TGA file

Posted By: Germanunkol

Sending a BMP or a TGA file - 03/10/07 09:50

Hi!
I would like all the players to have the option creating their own logo, and use this logo in a multiplayer game.

If you've played X˛ - the Thread, you might remember the logo that is attached to the ship. You can create your own logo and save it into a folder, and then choose this logo to be displayed on your ship.
We'll worry about putting the ship logo on the ship later on, maybe by manipulating the skins or just using a sprite.

For now, we're trying to figure out how to send the image - automatically - over the net, so that when I make my own logo on my computer, it can be displayed on all other computers as well.
Also, is there a way to make things safer? I certainly don't want any viruses to be send over the net...

I don't know too much about sending files/network outside 3dgs...

Thanks,
Micha

P.S. we're using populace. Shouldn't really matter... but just in case you need to know.
I also have the GSHTTP.dll, which should be able to download the file...?
Posted By: khanoftruth

Re: Sending a BMP or a TGA file - 03/10/07 18:12

This would only work if you have users and stuff (I think). My method applies to using PHP and MySQL.

Think about how when a user creates their username, it send that data to the MySQL database on the server. The same process (I don't really know it off the top of my head) would apply here.
Posted By: fastlane69

Re: Sending a BMP or a TGA file - 03/10/07 19:39

Custom user content is a logistical nightmare if it's not built as part of the network architecture (which it isn't in 3DGS).

You could enact a solution that uploaded the custom logo to a web server and then asked each player to download it when needed in the game but I think it would be a nightmare to script out, manage, and implement properly.

Furthermore everytime the logo changed or a new player came on board you would have to re-upload and re-download and that could eat up your bandwidth right quick if you don't manage it properly.

My opinion: Can be done but I daresay it would be the only thing one person would be working on for a long time to get it done.
Posted By: HPW

Re: Sending a BMP or a TGA file - 03/11/07 12:33

You could try to open the images with file_open_read and read the content into a String, then send the string to a 3DGS Server application and save it as a file with str_open_write. If clients connects to the server than you could send the image in the same way to the clients.
Viruses are really a problem, but without a implementet virus search engine in 3DGS you can't really be sure to avoid them.
Posted By: Leonardo

Re: Sending a BMP or a TGA file - 03/11/07 13:15

I'm not sure how to send a 200x200 image or larger, but I've played MU Online and there you can create your own custom guild logo, that is 9x9 pixels I believe or something like that. If that would suit me, I would create a large grid where one square represents one pixel and then let the user create his logo pixel by pixel and send that information to the server and then draw the pixels on the skin of a ship, human etc. But if you need large bitmaps, this option would not be very useful.
Posted By: HPW

Re: Sending a BMP or a TGA file - 03/11/07 13:20

If you can import an bitmap into the "pixel-editor" like Leonardo wrote, than you can also be more sure to avoid viruses. You only send then 3 or 4 arrays to the server and the clients, like array_red[512], array_green[512], array_blue[512], array_alpha[512].
Posted By: TWO

Re: Sending a BMP or a TGA file - 03/11/07 13:23

Reading and sending the file in C-Script should not work, because C-Script uses formatet reading afaik. But it's possible in C++ via the ios::binary flag, search in good for fstream.

If it's not like a said and C-Script gets the bits unchanged, this should easly be possible. Just do like HPW told you, open the file, read it into a string and send the string. At the other clients, create a black bitmap and write the data to it.
Posted By: HPW

Re: Sending a BMP or a TGA file - 03/11/07 13:32

It is also possible with sending the arrays (red, green, blue and alpha) and use the draw or bitmap methods of 3DGS. You could use draw_line with only 1 pixel length of the line for each pixel or use pixel_to_bmap for this.
Posted By: Nagashi

Re: Sending a BMP or a TGA file - 03/12/07 02:27

The basics of this are quite simple with gshttp.dll I’ve constructed a small demo here… http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/719567/an/0/page/0#Post719567 it’s basically the meat and potatoes of what your looking for, note that this demo only covers the downloading and loading in-game during play, not the uploading…

Cheers
Posted By: Germanunkol

Re: Sending a BMP or a TGA file - 03/12/07 12:33

you guys rule. Thanks for every single answer

I'll fiddle around with this, and maybe host the code afterwards, if I get something working.
Thanks!!

Micha
Posted By: Germanunkol

Re: Sending a BMP or a TGA file - 03/13/07 19:04

Hmm... there's multiple ways to do this you mentioned.
Sending the file in a string... how do I read a file in binary into an ascii string?... does that even work?

I don't know much about file types, help?

I wanted to use the pixel_for_bmap method, but the manual is against that somehow... they say not to overuse the function, and that it can crash your program easily...


thx,
Micha
Posted By: HPW

Re: Sending a BMP or a TGA file - 03/14/07 22:44

If you want to use pixel_to_bmap then you should use pixel_for_bitmap on the other side of your client/server to read the information of the pixels into 3 or 4 arrays.

something like this...
Code:

var v_alpha[512];
var v_red[512];
var v_green[512];
var v_blue[512];

function read_bmap(b_bmap)
{
var v_x = 0;
var v_y = 0;
var v_index = 0;
var v_pixel;
var v_format;

v_format = bmap_lock(b_bmap, 0);
if (v_format != 0) // valid bmap?
{
while (v_y < bmap_height(b_bmap))
{
while (v_x < bmap_width(b_bmap))
{
v_index = (v_y*bmap_width(b_bmap))+v_x;
v_pixel = pixel_for_bmap(b_bmap, v_x, v_y);
pixel_to_vec(temp, v_alpha[v_index], v_format, v_pixel);
v_red[v_index] = temp.red;
v_green[v_index] = temp.green;
v_blue[v_index] = temp.blue;
v_x += 1;
}
v_y += 1;
}
}
bmap_unlock(b_bmap);
}

function write_bmap(b_bmap)
{
var v_x = 0;
var v_y = 0;
var v_index = 0;
var v_pixel;
var v_format;

v_format = bmap_lock(b_bmap, 0);
if (v_format != 0) // valid bmap?
{
while (v_y < bmap_height(b_bmap))
{
while (v_x < bmap_width(b_bmap))
{
v_index = (v_y*bmap_width(b_bmap))+v_x;
temp.red = v_red[v_index];
temp.green = v_green[v_index];
temp.blue = v_blue[v_index];
v_pixel = pixel_for_vec(temp, v_alpha[v_index], v_format);
pixel_to_bmap(b_bmap, v_x, v_y, v_pixel);
v_x += 1;
}
v_y += 1;
}
}
bmap_unlock(b_bmap);
}



I don't tested this functions but it should work.
Now you need a function that sends the 4 arrays (v_red, v_green, v_blue and y_alpha) to server or clients.
Posted By: HPW

Re: Sending a BMP or a TGA file - 03/14/07 22:51

I think they means with overuse something like using it every frame?!? But I don't know.
Posted By: Germanunkol

Re: Sending a BMP or a TGA file - 03/17/07 15:55

Thanks a lot!
the manual said:
"For speed reasons this function is not safeguarded. Exceeding the bmap size (for instance by redefining d3d_texlimit) will lead to an engine crash."
that's what I meant, sorry.
But I don't think that'll be a problem for me, because I'll know the pixel size.
and your code goes around that problem with the pic size as well, cause you check the bmap's size...:)

I'll try this method and let you know what I come up with!


© 2024 lite-C Forums