public override int ProcessCLogin(CLogin protocol) { Session session = Session.Get(protocol); SLogin result = new SLogin(); result.Argument.RoleId = protocol.Argument.RoleId; BAccount account = _taccount.Get(session.Account); if (null == account) { result.ResultCode = 1; session.SendResponse(result); return(Zeze.Transaction.Procedure.LogicError); } account.LastLoginRoleId = protocol.Argument.RoleId; BRoleData role = _trole.Get(protocol.Argument.RoleId); if (null == role) { result.ResultCode = 2; session.SendResponse(result); return(Zeze.Transaction.Procedure.LogicError); } BOnline online = _tonline.GetOrAdd(protocol.Argument.RoleId); online.RoleId = protocol.Argument.RoleId; // 对于同一个 session,允许重复登录 role,直接覆盖 online.SessionId = session.SessionId; session.LoginRoleId = protocol.Argument.RoleId; session.SendResponse(result); return(Zeze.Transaction.Procedure.Success); }
/// <summary> /// 发送在线可靠协议,如果不在线等,仍然不会发送哦。 /// </summary> /// <param name="roleId"></param> /// <param name="listenerName"></param> /// <param name="fullEncodedProtocol">协议必须先编码,因为会跨事务。</param> public void SendReliableNotify(long roleId, string listenerName, int typeId, Binary fullEncodedProtocol) { Game.App.Instance.Zeze.TaskOneByOneByKey.Execute( listenerName, Game.App.Instance.Zeze.NewProcedure(() => { BOnline online = table.Get(roleId); if (null == online || online.State == BOnline.StateOffline) { return Procedure.Success; } if (false == online.ReliableNotifyMark.Contains(listenerName)) { return Procedure.Success; // 相关数据装载的时候要同步设置这个。 } // 先保存在再发送,然后客户端还会确认。 // see Game.Login.Module: CLogin CReLogin CReliableNotifyConfirm 的实现。 online.ReliableNotifyQueue.Add(fullEncodedProtocol); if (online.State == BOnline.StateOnline) { var notify = new SReliableNotify(); // 不直接发送协议,是因为客户端需要识别ReliableNotify并进行处理(计数)。 notify.Argument.ReliableNotifyTotalCountStart = online.ReliableNotifyTotalCount; notify.Argument.Notifies.Add(fullEncodedProtocol); SendInProcedure(new List<long>() { roleId }, notify.TypeId, new Zeze.Net.Binary(notify.Encode())); } online.ReliableNotifyTotalCount += 1; // 后加,start 是 Queue.Add 之前的。 return Procedure.Success; }, "SendReliableNotify." + listenerName )); }
public override int ProcessReliableNotifyConfirmRequest(ReliableNotifyConfirm rpc) { Session session = Session.Get(rpc); BOnline online = _tonline.Get(session.RoleId.Value); if (null == online || online.State == BOnline.StateOffline) { return(ReturnCode(ResultCodeOnlineDataNotFound)); } session.SendResponseWhileCommit(rpc); // 同步前提交。 var syncResultCode = ReliableNotifySync( session, rpc.Argument.ReliableNotifyConfirmCount, online, false); if (ResultCodeSuccess != syncResultCode) { return(ReturnCode((ushort)syncResultCode)); } return(Procedure.Success); }
public override int ProcessReLoginRequest(ReLogin rpc) { Session session = Session.Get(rpc); BAccount account = _taccount.Get(session.Account); if (null == account) { return(ReturnCode(ResultCodeAccountNotExist)); } if (account.LastLoginRoleId != rpc.Argument.RoleId) { return(ReturnCode(ResultCodeNotLastLoginRoleId)); } BRoleData role = _trole.Get(rpc.Argument.RoleId); if (null == role) { return(ReturnCode(ResultCodeRoleNotExist)); } BOnline online = _tonline.Get(rpc.Argument.RoleId); if (null == online) { return(ReturnCode(ResultCodeOnlineDataNotFound)); } online.LinkName = session.LinkName; online.LinkSid = session.SessionId; online.State = BOnline.StateOnline; // 先发结果,再发送同步数据(ReliableNotifySync)。 // 都使用 WhileCommit,如果成功,按提交的顺序发送,失败全部不会发送。 session.SendResponseWhileCommit(rpc); Transaction.Current.RunWhileCommit(() => { var setUserState = new gnet.Provider.SetUserState(); setUserState.Argument.LinkSid = session.SessionId; setUserState.Argument.States.Add(rpc.Argument.RoleId); rpc.Sender.Send(setUserState); // 直接使用link连接。 }); var syncResultCode = ReliableNotifySync( session, rpc.Argument.ReliableNotifyConfirmCount, online); if (syncResultCode != ResultCodeSuccess) { return(ReturnCode((ushort)syncResultCode)); } App.Load.LoginCount.IncrementAndGet(); return(Procedure.Success); }
public override int ProcessLoginRequest(Login rpc) { Session session = Session.Get(rpc); BAccount account = _taccount.Get(session.Account); if (null == account) { return(ReturnCode(ResultCodeAccountNotExist)); } account.LastLoginRoleId = rpc.Argument.RoleId; BRoleData role = _trole.Get(rpc.Argument.RoleId); if (null == role) { return(ReturnCode(ResultCodeRoleNotExist)); } BOnline online = _tonline.GetOrAdd(rpc.Argument.RoleId); online.LinkName = session.LinkName; online.LinkSid = session.SessionId; online.State = BOnline.StateOnline; online.ReliableNotifyConfirmCount = 0; online.ReliableNotifyTotalCount = 0; online.ReliableNotifyMark.Clear(); online.ReliableNotifyQueue.Clear(); var linkSession = session.Link.UserState as Game.Server.LinkSession; online.ProviderId = App.Zeze.Config.AutoKeyLocalId; online.ProviderSessionId = linkSession.ProviderSessionId; // 先提交结果再设置状态。 // see linkd::gnet.Provider.ModuleProvider。ProcessBroadcast session.SendResponseWhileCommit(rpc); Transaction.Current.RunWhileCommit(() => { var setUserState = new gnet.Provider.SetUserState(); setUserState.Argument.LinkSid = session.SessionId; setUserState.Argument.States.Add(rpc.Argument.RoleId); rpc.Sender.Send(setUserState); // 直接使用link连接。 }); App.Load.LoginCount.IncrementAndGet(); return(Procedure.Success); }
public void Send(long roleId, Protocol p) { BOnline online = table.Get(roleId); if (null == online) { return; } AsyncSocket socket = Game.App.Instance.Server.GetSocket(online.SessionId); if (null == socket) { return; } p.Send(socket); }
private int ReliableNotifySync(Session session, long ReliableNotifyConfirmCount, BOnline online, bool sync = true) { if (ReliableNotifyConfirmCount < online.ReliableNotifyConfirmCount || ReliableNotifyConfirmCount > online.ReliableNotifyTotalCount || ReliableNotifyConfirmCount - online.ReliableNotifyConfirmCount > online.ReliableNotifyQueue.Count) { return(ResultCodeReliableNotifyConfirmCountOutOfRange); } int confirmCount = (int)(ReliableNotifyConfirmCount - online.ReliableNotifyConfirmCount); if (sync) { var notify = new SReliableNotify(); notify.Argument.ReliableNotifyTotalCountStart = ReliableNotifyConfirmCount; for (int i = confirmCount; i < online.ReliableNotifyQueue.Count; ++i) { notify.Argument.Notifies.Add(online.ReliableNotifyQueue[i]); } session.SendResponseWhileCommit(notify); } online.ReliableNotifyQueue.RemoveRange(0, confirmCount); online.ReliableNotifyConfirmCount = ReliableNotifyConfirmCount; return(ResultCodeSuccess); }