ID:264292
 
Savefile Server Code:
Here is the savefile code
var/list/Allowed = list("Max Omega","Hellscraper","Equinox Productions","Yata The Prophet","Suou Tamaki","Norokido-kun","Tatsuyax","Seanleonartes")

world/Topic(T,Addr)
var/list/params = params2list(T)
switch(params["action"])
if("saveplayer")
var/mob/players = locate(params["player"])
var/X = world.Import()
if(X)
var/savefile/F = new(X)
if(F && istype(F))
if(!name)
world<<"<font color=red>\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] Error: [players.key]'s name could not be used as a savefile name</font>"
return -1
fcopy(X,"savefiles/[players.ckey].sav")
world << "\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [players.key]'s savefile has been successfully saved"
return 1
else
world<<"<font color=red>\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] Error: [players.key]'s savefile is not a valid savefile</font>"
return -2
else
world<<"<font color=red>\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] Error: [players.key]'s savefile is unable to be transfered</font>"
return -3

if("loadplayer")
var/mob/player = locate(params["player"])
var/X = world.Import()
if(X)
var/savefile/F = new(X)
var/address
var/port
F["Address"] >> address
F["Port"] >> port
if(player)
player.Load(player,address,port)



mob/proc
Load(mob/player,addr,port)
if(fexists("savefiles/[ckey].sav"))
var/savefile/F = new("savefiles/[ckey].sav")
world.Export("[addr]:[port]?action=loadplayer;player=\ref[src]",F)
world<<"\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [key]'s savefile has been successfully been loaded ([addr]:[port])"

world
New()
OpenPort(3319)
..()

mob
Login()
if(!(src.key in Allowed))
src<<"You are not authorized to be here!"
del(src)

for(var/mob/M in world)
if(M == src) continue
M << "\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [src.key] Has logged into The World R:2 Data Server"
src<<"<center><font size = 4><font color = red><b>Welcome to The World R:2 Data Server!</b></font></font></center>"
if(world.port)
src<<"<center>Server hosted at [world.address]:[world.port]</center>"
else
src<<"<center>Server hosted is currently not hosting</center>"

mob
verb
Host_Data_Server()
if(!world.port)
var/portnumber = input("Host Data server on what port?") as num|null
world.OpenPort(portnumber)
src<<"Data server now hosting on [world.port]</font>"
else
src<<"<font color = red>Data server is already hosting on port [world.port]!</font>"

Stop_Hosting_Data_Server()
if(world.port)
world.OpenPort("none")
src<<"Data server has stopped hosting"
else
src<<"<font color = red>Data server is already not hosting!</font>"

Delete_Savefile()
var/filelist = flist("savefiles/")
if(length(filelist) == 0)
src<<"<font color = red>There are no savefiles on the data server!</font>"
var/delete = input("Whose savefile do you wish to delete?") in filelist + list("Cancel")
if(delete == "Cancel") return
else
world<<"\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [delete] has been removed from the Data server"
fdel("savefiles/[delete]")

Change_Port()
if(world.port)
var/changeport = input("What do you want to change the port to?") as num
world.OpenPort(changeport)
src<<"The port has been changed to [world.port]"

mob
Stat()
..()
statpanel("Server")
var/counter = 0
var/filelist = flist("savefiles/")
var/i = 1
for(i , i <= length(filelist), i++)
counter++
stat("Savefiles count",counter)
stat("Data Server Address","[world.address]:[world.port]")

Test Game Server Code:
var
Server_Addr = "127.0.0.1"
Server_Port = "3319"


mob/verb
test_save()
Save(src)
test_load()
src.Request_Load()
mob
proc
Save()
if(world.port)
var/savefile/F = new()
Write(F)
switch(world.Export("[Server_Addr]:[Server_Port]?action=saveplayer;player=\ref[src]",F))
if(1)
src<<"Your game has been saved successfully"
if(-1)
src<<"Your savefile is corrupted. You cannot save at this time."
if(-2)
src<<"Your savefile is not a valid savefile."
if(-3)
src<<"Your savefile was not able to be sent over to the data server."
else
src<<"Cannot connect to data server. You cannot save at this time."
else
src<<"You cannot save. The game is not being hosted"

Request_Load()
if(world.port)
var/savefile/F = new()
F["Address"] << world.address
F["Port"] << world.port
world.Export("[Server_Addr]:[Server_Port]?player=\ref[src];action=loadplayer",F)
else
src<<"You cannot save. The game is not being hosted"

Load(mob/player,var/savefile/file)
player.Read(file)
player<<"Your savefile has been successfully loaded"



world/Topic(T,Addr)
var/list/params = params2list(T)
switch(params["action"])
if("loadplayer")
var/mob/player = locate(params["player"])
if(player)
var/savefile/F = new(world.Import())
player.Load(player,F)


mob/Stat()
statpanel("Status")
stat("Name",src.key)

Problem description:
I keep having this problem. Whenever I switch keys to test the saving procedure for the savefile server. The savefile server says that it just saved the person who was just on previously.

First I load up the savefile server.
Loaded up the test game server.
Tested Save.
Checked savefile server to see if it saved properly.
Close out of the test game server.
Log into a different key and open up the test game server
Save to see if it passes.

Now heres the problem. When I saved with the 2nd key. It says that the previous key had been saved. Even tho im on the other key. Please help. This might be a bug also im not sure.


                    if(!name)
world<<"<font color=red>\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] Error: [players.key]'s name could not be used as a savefile name</font>"
return -1


That makes no sense. You're checking if the world has a name, and then you're outputting that you couldn't use the player's name as a file name.
In response to Jeff8500
Nevermind I fixed my problem.

If you want to see it its right here

var/list/Allowed = list("Max Omega","Hellscraper","Equinox Productions","Yata The Prophet","Suou Tamaki","Norokido-kun","Tatsuyax","Seanleonartes")

world/Topic(T,Addr)
var/list/params = params2list(T)
switch(params["action"])
if("saveplayer")
var/X = world.Import()
var/savefile/F = new(X)
var/savefilename = F["key"]
if(X)
if(F && istype(F))
if(!savefilename)
world<<"<font color=red>\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] Error: [savefilename]'s name could not be used as a savefile name</font>"
return -1
fcopy(X,"savefiles/[savefilename].sav")
world << "\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [savefilename]'s savefile has been successfully saved"
return 1
else
world<<"<font color=red>\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] Error: [savefilename]'s savefile is not a valid savefile</font>"
return -2
else
world<<"<font color=red>\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] Error: [savefilename]'s savefile is unable to be transfered</font>"
return -3

if("loadplayer")
var/X = world.Import()
if(X)
var/savefile/F = new(X)
var/address
var/port
var/keys
F["key"] >> keys
F["Address"] >> address
F["Port"] >> port
Load(keys,address,port)



proc
Load(key,addr,port)
if(fexists("savefiles/[key].sav"))
var/savefile/F = new("savefiles/[key].sav")
F["KEY"] << key
world.Export("[addr]:[port]?action=loadplayer",F)
world<<"\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [key]'s savefile has been successfully been loaded ([addr]:[port])"

world
New()
OpenPort(3319)
..()

mob
Login()
if(!(src.key in Allowed))
src<<"You are not authorized to be here!"
del(src)

for(var/mob/M in world)
if(M == src) continue
M << "\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [src.key] Has logged into The World R:2 Data Server"
src<<"<center><font size = 4><font color = red><b>Welcome to The World R:2 Data Server!</b></font></font></center>"
if(world.port)
src<<"<center>Server hosted at [world.address]:[world.port]</center>"
else
src<<"<center>Server hosted is currently not hosting</center>"

mob
verb
Host_Data_Server()
if(!world.port)
var/portnumber = input("Host Data server on what port?") as num|null
world.OpenPort(portnumber)
src<<"Data server now hosting on [world.port]</font>"
else
src<<"<font color = red>Data server is already hosting on port [world.port]!</font>"

Stop_Hosting_Data_Server()
if(world.port)
world.OpenPort("none")
src<<"Data server has stopped hosting"
else
src<<"<font color = red>Data server is already not hosting!</font>"

Delete_Savefile()
var/filelist = flist("savefiles/")
if(length(filelist) == 0)
src<<"<font color = red>There are no savefiles on the data server!</font>"
var/delete = input("Whose savefile do you wish to delete?") in filelist + list("Cancel")
if(delete == "Cancel") return
else
world<<"\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] [delete] has been removed from the Data server"

fdel("savefiles/[delete]")

Change_Port()
if(world.port)
var/changeport = input("What do you want to change the port to?") as num
world.OpenPort(changeport)
src<<"The port has been changed to [world.port]"

List_Savefiles()
var/html = {"
<html>
<style type="text/css">
body
{
background-color: #000000;
color: #ffffff;
}
</style>"}

var/filelist = flist("savefiles/")
if(length(filelist) != 0)
html+="<font size = 6><center>Save Files</center></font><br>"
html += "<center>"
for(var/m in filelist)
html+= m
html+="<br>"
html += "</center>"
else
html+="<center>No savefiles in data server!</center>"
src<<browse(html,"window=savefilelist;can_close=1;can_minimize=0;can_resize=0")

Back_Up_Savefiles()
var/filelist = flist("savefiles/")
if(length(filelist) != 0)
for(var/m in filelist)
if(fexists("savefiles/[m]"))
var/savefile/M = new("savefiles/[m]")
fcopy(M,"savefiles_backup/[m]")
world<<"\[[time2text(,"Month DD, YYYY hh:mm:ss")]\] All savefiles have been backed up!"


mob
Stat()
..()
statpanel("Server")
var/counter = 0
var/filelist = flist("savefiles/")
var/i = 1
for(i , i <= length(filelist), i++)
counter++
stat("Savefiles count",counter)
stat("Data Server Address","[world.address]:[world.port]")


To test

var
Server_Addr = "127.0.0.1"
Server_Port = "3319"


mob/verb
test_save()
Save(src)
test_load()
src.Request_Load()
mob
proc
Save()
if(world.port)
var/savefile/F = new()
Write(F)
switch(world.Export("[Server_Addr]:[Server_Port]?action=saveplayer",F))
if(1)
src<<"Your game has been saved successfully"
if(-1)
src<<"Your savefile is corrupted. You cannot save at this time."
if(-2)
src<<"Your savefile is not a valid savefile."
if(-3)
src<<"Your savefile was not able to be sent over to the data server."
else
src<<"Cannot connect to data server. You cannot save at this time."
else
src<<"You cannot save. The game is not being hosted"

Request_Load()
if(world.port)
var/savefile/F = new()
F["ckey"] << src.ckey
F["key"] << src.key
F["Address"] << world.address
F["Port"] << world.port
world.Export("[Server_Addr]:[Server_Port]?action=loadplayer",F)
else
src<<"You cannot save. The game is not being hosted"

Load(mob/player,var/savefile/file)
player.Read(file)
player<<"Your savefile has been successfully loaded"



world/Topic(T,Addr)
var/list/params = params2list(T)
switch(params["action"])
if("loadplayer")
var/F = world.Import()
var/savefile/S = new(F)
var/savefilekey = S["KEY"]
for(var/mob/M in world)
if(M.key == savefilekey)
M.Load(M,S)


mob/Stat()
statpanel("Status")
stat("Name",src.key)

mob/Login()
..()