ID:161889
 
I wanted to send a savefile to another world/server. I tried this piece of code:

mob/verb
SAVE()
var/savefile/F = new()
F << src
if(!world.Export("Samehada24.Game:2001#player",F)) // world address is Samehada24.Game on port 2001
usr << "World not online."
return

world/Topic(T) // world / Topic of the remote server
if(T == "player")
var/savefile/F = new(Import())
return 1


I tried this one and it worked it exported the file (tested it). But I didn't saw the .sav file on the remote server and I read that the file will be saved on the resource cache of the remote server...

- Is this the right way to transfer a savefile to another server or does it lack something?

- How can I read files from other servers?


Please help if you can...
if(!world.Export("Samehada24.Game:2001#player",F))

I haven't messed with world.Export(), however, that # should be a ? See: http://www.byond.com/docs/ref/info.html#/world/proc/Export
In response to Garthor
I got the code from DM Guide PDF... it still works using '#'

... but thanks anyway Garthor...


and...Is it possible to transfer the savefile to another server's computer or to a site??
In response to Samehada24
Technically, it is possible, yes. Feasible? I don't really know.
Although, I don't really entirely get what you mean by saying

transfer to another server's computer

So you should elaborate and be more specific.
Your problem may be that Samehada24.Game is not a valid destination! You can't post files on your hub entry.

You will need to host a central server and contact it by either IP address or via a domain name. I recommend a domain name (you can get one for free from providers like no-ip.com) so that if the IP ever changes you can modify it without having to redistribute the host files of your game.

The following may work, but is untested:
//this code needs to be in your game
mob/verb
Save()
var/savefile/F = new()
Write(F)
switch(world.Export("byond://myserver.com:1000?player",F))
if(1)
usr << "Your character has been saved."
if(-1)
usr << "The remote server is refusing connections. Your character could not be saved at this time."
if(-2)
usr << "The remote server reports that it cannot read the savefile. Your character could not be saved at this time."
if(-3)
usr << "The remote server reports that it has received no file or not a valid savefile. Your character could not be saved at this time."
else
usr << "The remote server is unavailable. Your character could not be saved at this time."
//TODO: write a system that stores the savefile in a buffer, so if the server is available again it will attempt to re-send it.

//the below code needs to be in your central server
world/Topic(T, Addr, Master, Key)
if(T == "player")
if(Addr == "123.456.789.00") //the IP of your server will need to be here, or you will need to write an authentication system
var/X = world.Import()
if(X)
var/savefile/F = new(X)
if(F && istype(F))
var/name = F["ckey"]
if(!name) return -2
fcopy(X,"savefiles/[name].sav")
return 1
return -3
else return -1
return ..() //perform the default functions for the "ping", "Del", and "Reboot" commands


You'll need to verify that a proper savefile is being sent from your game. Otherwise, anybody could send savefiles to your central server which could potentially lead to cheating.

In the case above I have locked it so only a specific IP address may send a savefile. This is bad in practise since you'll want to distribute the host files. In that case, you may want to include a code of some sort that only you know of, so others will have a much more difficult time to bypass your system. Hashing the savefile itself will also help.

You may be interested to know that it's possible to use client-side savefiles -- you can store the savefile on the players' computer so it can be used in any server. This requires you to have a hub entry, but works flawlessly if you use hashing to prevent cheating.

Hope I helped,
-- Data
In response to Android Data
thx data... and which would be better using client-side savefiles and hashing it or exporting it to other server? When hashing the savefiles is there any chance others can edit it?


Thanks for the help guys... it helped me alot!