-
Notifications
You must be signed in to change notification settings - Fork 577
ScutGame edited this page Dec 17, 2015
·
17 revisions
此章节介绍旧版本升级到新版本API更新或变动说明
此版本会增加新功能与bug修改,与之前6.7.9.x版本不兼容,开发者使用的旧版本不能直接升级,会影响旧的项目。
开发者的项目使用旧版本升级需要如下修改:
- 实体
GameUser
需要的地方如下:(使用到UserId属性的地放,需要修改为long类型)
[ProtoContract]
[EntityTable(CacheType.Dictionary, DbCofingKeys.DataKey)]
public class GameUser : BaseUser
{
[ProtoMember(1)]
[EntityField(true)]
public long UserId { get; set; }
protected override long GetIdentityId()
{
return UserId;
}
public override long GetUserId()
{
return UserId;
}
}
- 登录协议接口
LoginAction
需要修改如下:
DoSuccess方法的参数accountId 改为long类型。
public class Action1004 : LoginAction
{
protected override bool DoSuccess(long accountId, out IUser user)
{
}
public override void BuildPacket()
{
//若此下发的参数有userId参数,需要是long类型,
//客户端接收时,也需要相应调整
PushIntoStack(Current.SessionId);
PushIntoStack(Current.UserId); //UserId为long类型
}
}
- 其它协议接口需要上传UserId参数,如好友:
需要使用httpGet.GetLong
方法接收请求参数
public class ActionXXX : BaseAction
{
/// <summary>
/// 好友ID
/// </summary>
private long _friendUserId;
public override bool GetUrlElement()
{
if (httpGet.GetLong("FriendUserId", ref _friendUserId))
{
return true;
}
return false;
}
}
6.7.9.x 是最终版本,可与这前版本兼容,开发者使用的旧版本可以直接升级,不再增加新功能;新的功能将会放到alpha分支。
需要在config增加启用开关和输入日志目录,如下配置:
<add key="Profile.EnableCollect" value="True"/>
<add key="Profile.LogPath" value="d:\ProfileLog"/>
需要跟踪Redis修改日志,可开启如下配置:
<add key="Profile.OpenWriteLog" value="True"/>
针对实体存在多个主键时,优化查证效率,需要在Config配置中修改使用的Redis版本号为7,如:
<add key="Redis.ClientVersion" value="7" />
与之前的数据不兼容,新的项目可以直接使用;
旧的项目不需要加这段配置,使用原先的存储结构(版本号为5)即可,若要强制升级需要清空Redis数据。
[EntityTable(CacheType.Entity, DbConfig.Data, IsStoreInDb = false, IsExpired = false)]
public class UserNickName : ShareEntity
{
}
修改为:
[EntityTable(CacheType.Entity, DbConfig.Data, StorageType = StorageType.ReadWriteRedis, IsExpired = false)]
public class UserNickName : ShareEntity
{
}
Action1004类的DoSuccess方法
protected override bool DoSuccess(int userId, out IUser user)
{
if (gameUser == null ||
string.IsNullOrEmpty(gameUser.SessionID) ||
gameUser.IsOnlining)
{
gameUser = cacheSet.FindKey(Uid);
}
//...
GameUser gameUser = cacheSet.FindKey(Uid);
user = gameUser;
}
修改为:
protected override bool DoSuccess(int userId, out IUser user)
{
if (gameUser == null ||
string.IsNullOrEmpty(gameUser.SessionID) ||
(Current.User != null && !Current.User.IsOnlining))
{
gameUser = cacheSet.FindKey(Uid);
}
//...
GameUser gameUser = cacheSet.FindKey(Uid);
user = new SessionUser(gameUser);
}
GameUser.cs 修改
public class GameUser : BaseUser
{
#region extend method
protected override int GetIdentityId()
{
return UserId;
}
public override int GetUserId()
{
return UserId;
}
public override string GetPassportId()
{
return Pid;
}
public override string GetRetailId()
{
return RetailId;
}
public override bool IsLock
{
get { return Status == UserStatus.Locked; }
}
public override string GetNickName()
{
return NickName;
}
#endregion
}
Action中获取GameUser对象
var user = PersonalCacheStruct.Get<GameUser>(UserId.ToString());
UserLoginLog userLoginLog = new UserLoginLog();
DataSyncManager.GetDataSender().Send(userLoginLog);
修改为:
UserLoginLog userLoginLog = new UserLoginLog();
DataSyncManager.GetDataSender().Send(userLoginLog);
//或多条
var logList = new List<UserLoginLog>();
for(int i=0; i< 10; i++)
{
UserLoginLog userLoginLog = new UserLoginLog();
logList.Add(userLoginLog);
}
DataSyncManager.GetDataSender().Send(logList.ToArray());
private static void DoNotifyAction(int actionId, List<GameUser> userList, Parameters parameters, Action<int> callback)
{
ActionFactory.SendAsyncAction(userList, actionId, parameters, result => { });
if (callback != null)
{
callback(actionId);
}
}
或早期的API代码:
public static void SendAsyncAction<T>(List<T> userList, int actionId, Parameters parameters, Action<HttpGet> successHandle)
修改为:
private static void DoNotifyAction(int actionId, List<GameUser> userList, Parameters parameters, Action<int> callback)
{
List<SessionUser> sessionUsers = userList.ConvertAll(user => new SessionUser(user));
ActionFactory.SendAsyncAction(sessionUsers, actionId, parameters, result => { });
if (callback != null)
{
callback(actionId);
}
}
//Action1002
string[] userList = SnsManager.GetRegPassport(_data.DeviceID);
_result = new PassportResult()
{
PassportID = userList[0],
Password = CryptoHelper.DES_Decrypt(userList[1], GameEnvironment.Setting.ProductDesEnKey)
};
修改为:
string[] userList = SnsManager.GetRegPassport(_data.DeviceID);
_result = new PassportResult()
{
PassportID = userList[0],
Password = userList[1]
};
public override bool TakeAction()
{
_password = DecodePassword(_password);
if (SnsManager.ChangePass(Uid, _password) <= 0)
{
Tips(Language.Instance.ChangedPasswordError);
return false;
}
return true;
}
修改为:
public override bool TakeAction()
{
_password = DecodePassword(_password);
if (SnsManager.ChangePass(UserId.ToString(), _password) <= 0)
{
Tips(Language.Instance.ChangedPasswordError);
return false;
}
return true;
}