forked from sin365/AxibugEmuOnline
133 lines
5.1 KiB
C#
133 lines
5.1 KiB
C#
using AxibugEmuOnline.Client.ClientCore;
|
||
using AxibugEmuOnline.Client.Common;
|
||
using AxibugEmuOnline.Client.Event;
|
||
using AxibugEmuOnline.Client.Network;
|
||
using AxibugProtobuf;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace AxibugEmuOnline.Client.Manager
|
||
{
|
||
public class AppGameSavMgr
|
||
{
|
||
Dictionary<int, Protobuf_Mine_GameSavInfo[]> dictRomId2SavInfo = new Dictionary<int, Protobuf_Mine_GameSavInfo[]>();
|
||
public AppGameSavMgr()
|
||
{
|
||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdGamesavGetGameSavList, RecvGetGameSavList);
|
||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdGamesavDelGameSav, RecvDelGameSavList);
|
||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdGamesavUploadGameSav, RecvUpLoadGameSav);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从数据层取存档列表数据(一般是OnNetGameSavListUpdate事件来了之后来取数据)
|
||
/// </summary>
|
||
/// <param name="RomID"></param>
|
||
/// <returns></returns>
|
||
public Protobuf_Mine_GameSavInfo[] GetRomSaveIDList(int RomID)
|
||
{
|
||
if (!dictRomId2SavInfo.ContainsKey(RomID))
|
||
{
|
||
dictRomId2SavInfo[RomID] = null;
|
||
}
|
||
return dictRomId2SavInfo[RomID];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 发送请求即时存档列表
|
||
/// </summary>
|
||
/// <param name="RomID"></param>
|
||
public void SendGetGameSavList(int RomID)
|
||
{
|
||
Protobuf_Mine_GetGameSavList req = new Protobuf_Mine_GetGameSavList()
|
||
{
|
||
RomID = RomID,
|
||
};
|
||
App.log.Info($"SendGetGameSavList");
|
||
App.network.SendToServer((int)CommandID.CmdGamesavGetGameSavList, ProtoBufHelper.Serizlize(req));
|
||
}
|
||
|
||
void RecvGetGameSavList(byte[] reqData)
|
||
{
|
||
Protobuf_Mine_GetGameSavList_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_Mine_GetGameSavList_RESP>(reqData);
|
||
|
||
Protobuf_Mine_GameSavInfo[] savArr = GetRomSaveIDList(msg.RomID);
|
||
for (int i = 0; i < savArr.Length; i++)
|
||
{
|
||
Protobuf_Mine_GameSavInfo info = msg.SavDataList.FirstOrDefault(w => w.SavDataIdx == i);
|
||
savArr[i] = info;
|
||
}
|
||
Eventer.Instance.PostEvent(EEvent.OnNetGameSavListUpdate, msg.RomID);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 发送删除即时存档
|
||
/// </summary>
|
||
/// <param name="RomID"></param>
|
||
/// <param name="SavDataIdx"></param>
|
||
public void SendDelGameSavList(int RomID,int SavDataIdx)
|
||
{
|
||
Protobuf_Mine_DelGameSav req = new Protobuf_Mine_DelGameSav()
|
||
{
|
||
RomID = RomID,
|
||
SavDataIdx = SavDataIdx
|
||
};
|
||
App.log.Info($"SendDelGameSavList");
|
||
App.network.SendToServer((int)CommandID.CmdGamesavGetGameSavList, ProtoBufHelper.Serizlize(req));
|
||
}
|
||
|
||
void RecvDelGameSavList(byte[] reqData)
|
||
{
|
||
Protobuf_Mine_DelGameSav_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_Mine_DelGameSav_RESP>(reqData);
|
||
|
||
Protobuf_Mine_GameSavInfo[] savArr = GetRomSaveIDList(msg.RomID);
|
||
savArr[msg.SavDataIdx] = null;
|
||
Eventer.Instance.PostEvent(EEvent.OnNetGameSavListUpdate, msg.RomID);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上传即时存档
|
||
/// </summary>
|
||
/// <param name="RomID"></param>
|
||
/// <param name="SavDataIdx"></param>
|
||
public void SendUpLoadGameSav(int RomID,int SavDataIdx, byte[] RawData, byte[] SavImgData)
|
||
{
|
||
//压缩
|
||
byte[] compressRawData = Helper.CompressByteArray(RawData);
|
||
|
||
//压缩
|
||
byte[] compressImgData = Helper.CompressByteArray(SavImgData);
|
||
|
||
Protobuf_Mine_UpLoadGameSav req = new Protobuf_Mine_UpLoadGameSav()
|
||
{
|
||
RomID = RomID,
|
||
SavDataIdx = SavDataIdx,
|
||
StateRaw = Google.Protobuf.ByteString.CopyFrom(compressRawData),
|
||
SavImg = Google.Protobuf.ByteString.CopyFrom(compressImgData),
|
||
};
|
||
|
||
App.log.Info($"SendDelGameSavList");
|
||
App.log.Info($"上传即时存档数据 原数据大小:{RawData.Length},压缩后;{compressRawData.Length}");
|
||
App.log.Info($"上传截图 原数据大小:{SavImgData.Length},压缩后;{compressImgData.Length}");
|
||
|
||
App.network.SendToServer((int)CommandID.CmdGamesavGetGameSavList, ProtoBufHelper.Serizlize(req));
|
||
}
|
||
|
||
void RecvUpLoadGameSav(byte[] reqData)
|
||
{
|
||
Protobuf_Mine_UpLoadGameSav_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_Mine_UpLoadGameSav_RESP>(reqData);
|
||
|
||
Protobuf_Mine_GameSavInfo[] savArr = GetRomSaveIDList(msg.RomID);
|
||
savArr[msg.UploadSevInfo.SavDataIdx] = msg.UploadSevInfo;
|
||
Eventer.Instance.PostEvent(EEvent.OnNetGameSavListUpdate, msg.RomID);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 即时存档或网络截图下载完成之后,需要先解压再使用
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public byte[] UnGzipData(byte[] data)
|
||
{
|
||
return Helper.DecompressByteArray(data);
|
||
}
|
||
}
|
||
} |