Save in Server
Eae pessoal. Como meu outro SiS estava com problemas, decidi fazer um decente e postar. Esse SiS era pra ser pro só meu Netplay(no qual pretendo fazer um projeto com um amigo). Mas não faz mal postar para vcs.
Com esse script vc pode enviar e receber qualquer arquivo, imagens, videos.. Mas fiz configurado para o SiS, não recomendo enviar arquivos pesados.
Características:
**Ele salva o arquivo do save.rxdata direto no server. O arquivo foi "resumido" e compactado, menos de 5kb, pode variar.
**Scene de espera, enquanto baixa os arquivos(bem rápido msm)
**Salva tudo, itens, equipamentos, magias, switches, locais tbm, variaveis, etc...
Como Funciona: Quem quiser entender, eu gero o arquivo de save, compacto com o Zlib para ficar menor, codifico com base64, para enviar como string para salvar no server. Dps é só receber, e refazer, decodificar, descompactar e criar o arquivo de novo.
obs: Foi necessário modificar o script do server.
Colocando no Jogo
Primeiro adicione esse script acima do Main:
- Código:
#=:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:
#Autor: RD12 Save in Server 2.0
#=:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:=:=:==:
class SiS
def file_encode(file)
File.open("Jogadores/"+file, 'rb') do|rdfile|
@data = rdfile.read#].pack("m0")
end
@data = [Zlib::Deflate.deflate(@data, 9)].pack('m0').gsub("\n", '')
return @data
end
def file_decode(str)
data = Zlib::Inflate.inflate(str.unpack('m0')[0])
return data
end
def send(id)
name = Network::Main.name
fdata = file_encode("#{name}-#{id}.rxdata")
Network::Main.socket.send("<char_id>#{id}</char_id>\n")
ptsize = 3048
for p in 1 .. (fdata.length/ptsize)+1
packet = fdata[(p - 1)*ptsize ... p*ptsize]
unless packet.nil? or packet.empty?
Network::Main.socket.send("<save_data>#{packet}</save_data>\n")
end
end
Network::Main.socket.send("<save_end></save_end>\n")
end
def receive(id)
Network::Main.socket.send("<rec_save>#{id}</rec_save>\n")
end
def delete(id)
Network::Main.socket.send("<del_save>#{id}</del_save>\n")
end
end
$SiS = SiS.new
class Game_Actor < Game_Battler
attr_accessor :map_id
end
class Scene_LoadSave
def main
@sprite = Sprite.new
#Modifique a title de loading entre ( )
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
$char_file = []
@tcount = 0
Graphics.transition
loop do
Network::Base.update
Network::Main.update
Graphics.update
update
if $scene != self
break
end
end
Graphics.freeze
@sprite.dispose
end
def update
if $char_file.size == 3
for i in 0..2
if $char_file[i].size > 10
file_dec = $SiS.file_decode($char_file[i])
file = File.open("Jogadores/#{Network::Main.name}-#{i+1}.rxdata", 'wb')
file.write(file_dec)
file.close
end
end
$scene = Scene_Title.new
else
@tcount += 1
if @tcount == 10
@tcount = 0
Network::Main.socket.send("<rec_save>#{$char_file.size+1}</rec_save>\n")
end
end
end
end
class Scene_Map
alias rd_update update
alias rd_main main
def main
@siscount = 0
rd_main
end
def update
rd_update
@siscount += 1
if @siscount == 140
@siscount = 0
autosave
end
$game_party.actors[0].map_id = $game_map.map_id
end
end
class Scene_Title
def carregar2
$ABS = MrMo_ABS.new
name = Network::Main.name
file = File.open("Jogadores/#{name}-#{@id_c}.rxdata", "rb")
characters = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)
#$game_system = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
#$game_screen = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_party = Marshal.load(file)
#$game_troop = Marshal.load(file)
#$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
#$ABS = Marshal.load(file)
$distribuir_pontos = Marshal.load(file)
$guild_name = Marshal.load(file)
$guild_position = Marshal.load(file)
$flag = Marshal.load(file)
$guild_points = Marshal.load(file)
$guild_lider_name = Marshal.load(file)
$hotkey = Marshal.load(file)
$game_map = Game_Map.new
$game_map.setup($game_party.actors[0].map_id)
$game_player.center($game_player.x, $game_player.y)
$game_map.update
$ABS.update
$game_party.refresh
$game_map.autoplay
Graphics.freeze
$char_id = @id_c
$divide_exp = false
if Network::Main.group == 'admin'
$game_party.actors[0].grupo = "Admin"
else
$game_party.actors[0].grupo = "Standard"
end
#Sair da Guild que foi deletada
if $guild_name != ""
if Network::Main.user_exist?($guild_name.to_s+"-Guild-DEL") == true
$guild_name = ""
$game_party.actors[0].guild = ""
$game_player.refresh
$guild_position = LANGUAGE::GUILDRANK
$guild_lider_name = ""
$guild_points = 0
return
end
end
if $guild_name == ""
$flag = 1
end
$game_player.refresh
$chat_ativo_agr = true
$scene = Scene_Map.new
$fechando_ativar = true
Network::Main.send_start
file.close
end
def sim
@delete.visible = false
@delete.active = false
if $Icon[4].visible == true
@deletechar[1] = true
name = Network::Main.name
File.delete("Jogadores/#{name}-1.rxdata")
Network::Main.socket.send("<delete_char>1</delete_char>\n")
@op_[1] = false
elsif $Icon[5].visible == true
@deletechar[2] = true
name = Network::Main.name
File.delete("Jogadores/#{name}-2.rxdata")
Network::Main.socket.send("<delete_char>2</delete_char>\n")
@op_[2] = false
elsif $Icon[6].visible == true
@deletechar[3] = true
name = Network::Main.name
File.delete("Jogadores/#{name}-3.rxdata")
Network::Main.socket.send("<delete_char>3</delete_char>\n")
@op_[3] = false
end
$scene = Scene_Title.new
end
end
Substitua o script [ACT] Auto Save por este:
- Código:
#==============================================================================
# ** Auto Save
#------------------------------------------------------------------------------
# By Valentine
# RD12
#==============================================================================
def autosave
name = Network::Main.name
char_id = $char_id
file = File.open("Jogadores/#{name}-#{char_id}.rxdata", "wb")
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
Marshal.dump(characters, file)
Marshal.dump(Graphics.frame_count, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_player, file)
#Marshal.dump($ABS, file)
Marshal.dump($distribuir_pontos, file)
Marshal.dump($guild_name, file)
Marshal.dump($guild_position, file)
Marshal.dump($flag, file)
Marshal.dump($guild_points, file)
Marshal.dump($guild_lider_name, file)
Marshal.dump($hotkey, file)
file.close
$SiS.send(char_id)
end
def resetwindows
$equip_w.visible = false
$equip_w.active = false
$member_list.visible = false
$member_list.active = false
$item_w.visible = false
$item_w.active = false
$janela_gold_w.visible = false
$help_w.visible = false
$help_w.active = false
$help_w_2.visible = false
$help_w_2.active = false
$help_w.visible = false
$help_w.active = false
$painel_adm.visible = false
$painel_adm.active = false
$convite.visible = false
$convite.active = false
$teleport.visible = false
$teleport.active = false
$skill.visible = false
$skill.active = false
$flag1.visible = false
$guild_w.visible = false
$guild_w.active = false
$msg.visible = false
$msg.active = false
$flag2.visible = false
$guild_created.visible = false
$guild_created.active = false
$memorizando_skill = false
$memorizando = false
$status.visible = false
$status.active = false
$quest_list.visible = false
$quest_list.active = false
$quest_w.visible = false
$quest_w.active = false
end
Agora script [WIN] Load_Character Apague as linhas 22 e 26:
@game_system = Marshal.load(file)
@game_screen = Marshal.load(file)
Agora no [NET] Network, linha 702 em baixo de return if @socket == nil
Adicione
- Código:
loop = 0
autosave if $scene.is_a?(Scene_Map)
loop do
loop += 1
self.update
break if @auth
break if loop == 300
end
Agora no [NET] Network linha 977 em baixo de case line
Adicione
- Código:
#get save data
when /<rec_save>(.*)<\/rec_save>/
$char_file = [] if $char_file.nil?
$char_file << $1.to_s
Mais em baixo procure por $scene = Scene_Title.new
substitua por: $scene = Scene_LoadSave.new
Vá na pasta do server, Scripts.lua, abra com um editor e em cima do peúltimo end(linha 443) adicione:
- Código:
elseif cmd == "<char_id>" then
do
data = string.gsub(data, "<char_id>", "")
data = string.gsub(data, "</char_id>", "")
save_file = io.open("Jogadores/"..user.name.."-"..data..".rxdata", "wb");
end
elseif cmd == "<save_data>" then
do
data = string.gsub(data, "<save_data>", "")
data = string.gsub(data, "</save_data>", "")
save_file:write(data)
end
elseif cmd == "<save_end>" then
do
save_file:close()
end
elseif cmd == "<rec_save>" then
do
data = string.gsub(data, "<rec_save>", "")
data = string.gsub(data, "</rec_save>", "")
local char_file = io.open("Jogadores/"..user.name.."-"..data..".rxdata", "rb")
if char_file ~= nil then
local save_contents = char_file:read("*all")
NP():SendToUser(user.id, "<rec_save>"..save_contents.."</rec_save>\n")
else
NP():SendToUser(user.id, "<rec_save>nil</rec_save>\n")
end
char_file:close()
io.close(char_file)
end
elseif cmd == "<delete_char>" then
do
data = string.gsub(data, "<delete_char>", "")
data = string.gsub(data, "</delete_char>", "")
os.remove("Jogadores/"..user.name.."-"..data..".rxdata")
end
Crie uma pasta com o nome Jogadores, dentro da pasta do server.
A pasta jogadores ainda é necessária no jogo.
DEMO: http://www.mediafire.com/?2g9w5u0q1y7l3td
Credítos RD12