public void AfterCall(IRpcSession session) { if (Roles != null) { Session.Get <Player>().Roles = Roles.Select(r => r.Id).ToList(); } }
public override void OnExecute(object session) { IRpcSession rpcSession = (IRpcSession)session; lock (this.Request) { #if COREFX if (!Request.Tcs.Task.IsCompleted) { Request.Error = RpcError.Success; rpcSession.RemoveRpcRequest(Request.Id); Request.Tcs.SetResult(ReplyCommand); } #else if (Request.OnDone != null) { Request.Error = RpcError.Success; rpcSession.RemoveRpcRequest(Request.Id); try { Request.OnDone(ReplyCommand); } catch (Exception e) { var rpcClient = (RpcClient)session; rpcClient.Log.Error(e); } } #endif } }
//------------------------------------------------------------------------- async void _onSuperSocketSessionDestroy(IRpcSession s, SessionCloseReason reason) { ClientInfo client_info = getClientInfoThenRemove(s); if (client_info == null) { return; } EbLog.Note("玩家连接断开,EtPlayerGuid=" + client_info.et_player_guid); try { if (client_info.player_watcher_weak != null && !string.IsNullOrEmpty(client_info.et_player_guid)) { var grain_player = GrainClient.GrainFactory.GetGrain <ICellPlayer>(new Guid(client_info.et_player_guid)); await grain_player.unsubPlayer(client_info.player_watcher_weak); client_info.remote_endpoint = null; client_info.player_watcher = null; client_info.player_watcher_weak = null; } } catch (Exception ex) { EbLog.Error(ex.ToString()); } }
//--------------------------------------------------------------------- public void rpcBySession <T1, T2, T3, T4>(IRpcSession session, ushort method_id, T1 obj1, T2 obj2, T3 obj3, T4 obj4) { byte[] data = null; using (MemoryStream s = new MemoryStream()) { try { ProtoBuf.Serializer.SerializeWithLengthPrefix <T1>(s, obj1, ProtoBuf.PrefixStyle.Fixed32); ProtoBuf.Serializer.SerializeWithLengthPrefix <T2>(s, obj2, ProtoBuf.PrefixStyle.Fixed32); ProtoBuf.Serializer.SerializeWithLengthPrefix <T3>(s, obj3, ProtoBuf.PrefixStyle.Fixed32); ProtoBuf.Serializer.SerializeWithLengthPrefix <T4>(s, obj4, ProtoBuf.PrefixStyle.Fixed32); data = s.ToArray(); } catch (Exception ex) { EbLog.Error("Component.rpcBySession<T1,T2,T3,T4>() Serializer Error! MethodId=" + method_id + " Exception:" + ex.ToString()); EbLog.Error("Type1=" + typeof(T1).Name + " Type2=" + typeof(T2).Name + " Type3=" + typeof(T3).Name + " Type4=" + typeof(T4).Name); return; } } if (session != null) { session.send(method_id, data); } }
//--------------------------------------------------------------------- public void rpcBySession(IRpcSession session, ushort method_id) { if (session != null) { session.send(method_id, null); } }
//--------------------------------------------------------------------- public void rpcBySession <T1>(IRpcSession session, ushort method_id, T1 obj1) { byte[] data = null; using (MemoryStream s = new MemoryStream()) { try { ProtoBuf.Serializer.Serialize <T1>(s, obj1); data = s.ToArray(); } catch (Exception ex) { EbLog.Note("Component.rpcBySession<T1>() Serializer Error! MethodId=" + method_id + " Exception:" + ex.ToString()); EbLog.Note("Type1=" + typeof(T1).Name); return; } } if (session != null) { session.send(method_id, data); } }
private void SendNextQueuedItem() { Log.Trace("Send next queued item."); ITicket ticket = null; IRpcSession sessionCopy = null; lock (_sync) { if (_sendingInProgress) { Log.Debug("Already sending."); return; } if (_pendingRequests.Count == 0) { Log.Debug("Not pending requests to send."); return; } sessionCopy = _session; _sendingInProgress = true; ticket = _pendingRequests.First.Value; _pendingRequests.RemoveFirst(); ticket.Xid = _nextXid++; } sessionCopy.AsyncSend(ticket); }
/// <summary> /// Befores the call. /// </summary> /// <param name="session">The session.</param> public void BeforeCall(IRpcSession session) { // TODO: Use INotifyChangeCollection to set up Role = session.Get <Entity>(); MoveState = Role.GetMovable(); Position = Role.GetPos(); Unit = Role.Get <UnitComponent>(); }
private IRpcSession NewSession() { IRpcSession prevSession = _session; _session = _sessionCreater(); _session.OnExcepted += OnSessionExcepted; _session.OnSended += OnSessionMessageSended; return(prevSession); }
//--------------------------------------------------------------------- public void onRecvRpcData(IRpcSession session, ushort method_id, byte[] data) { if (SignDestroy) { return; } mRpcCallee._onRpcMethod(session, method_id, data); }
public RpcSessionAssigner(IRpcSession session, T service) { Session = session; Service = service; if (service is ISessionRequred requred) { requred.Session.Value = session; } }
private static CheckResult CheckFilter(IRpcSession session, MethodInfo method) { var filterAttributes = method.DeclaringType.GetCustomAttributes <SessionFilterAttribute>() .Concat( method.GetCustomAttributes <SessionFilterAttribute>()); return(filterAttributes .Select(f => f.CheckPermission(session)) .FirstOrDefault(r => !r.Allowed) ?? CheckResult.Allow); }
//------------------------------------------------------------------------- public ClientInfo getClientInfo(IRpcSession s) { ClientInfo client_info = null; lock (MapClientInfoLock) { MapClientInfo.TryGetValue(s, out client_info); } return(client_info); }
public async Task <IPEndPoint> CheckAsync() { Assert.NotNull(Session.Value); IRpcSession session = Session.Value; await Task.Delay(500); Assert.NotNull(session); return(session.RemoteEndPoint); }
public override void OnReceive(object session, Stream stream) { IRpcSession rpcSession = (IRpcSession)session; string id = ProtocolParser.ReadString(stream); this.Request = rpcSession.GetRpcRequest(id); ICommandHandler handler = (ICommandHandler)session; ReplyCommand = handler.Handle.OnReceiveCommand(session, stream); ReplyCommand.OnExecute(session); }
//------------------------------------------------------------------------- async void c2sPlayerRequest(PlayerRequest player_request) { IRpcSession s = EntityMgr.LastRpcSession; ClientInfo client_info = CoApp.getClientInfo(s); if (client_info == null) { return; } Task <MethodData> task = await Task.Factory.StartNew <Task <MethodData> >(async() => { MethodData method_data = new MethodData(); method_data.method_id = MethodType.c2sPlayerRequest; method_data.param1 = EbTool.protobufSerialize <PlayerRequest>(player_request); MethodData r = null; try { var grain_playerproxy = GrainClient.GrainFactory.GetGrain <ICellPlayer>(new Guid(client_info.et_player_guid)); r = await grain_playerproxy.c2sRequest(method_data); } catch (Exception ex) { EbLog.Error(ex.ToString()); } return(r); }); if (task.Status == TaskStatus.Faulted || task.Result == null) { if (task.Exception != null) { EbLog.Error(task.Exception.ToString()); } return; } MethodData result = task.Result; if (result.method_id == MethodType.None) { return; } lock (CoApp.RpcLock) { var player_response = EbTool.protobufDeserialize <PlayerResponse>(result.param1); CoApp.rpcBySession(s, (ushort)MethodType.s2cPlayerResponse, player_response); } }
public RoleManager( IRpcSession session, IEntityManager entityManager, IEntityRepository entityRepository, IPrefabRepository prefabRepository) { Session = session; EntityManager = entityManager; EntityRepository = entityRepository; PrefabRepository = prefabRepository; Session.Exiting += Session_Exiting; }
//------------------------------------------------------------------------- public ClientInfo getClientInfoThenRemove(IRpcSession s) { ClientInfo client_info = null; lock (MapClientInfoLock) { if (MapClientInfo.TryGetValue(s, out client_info)) { MapClientInfo.Remove(s); } } return(client_info); }
private void OnSessionMessageSended(IRpcSession session) { lock (_sync) { if (session != _session) { return; } _sendingInProgress = false; } SendNextQueuedItem(); }
//--------------------------------------------------------------------- internal void _onRpcMethod(IRpcSession session, ushort method_id, byte[] data) { RpcSlotBase rpc_slot = null; mMapRpcSlot.TryGetValue(method_id, out rpc_slot); if (rpc_slot == null) { EbLog.Error("RpcCallee._onRpcMethod() not found method_id. method_id = " + method_id); return; } rpc_slot.onRpcMethod(data); }
public void BeforeCall(IRpcSession session) { if (Roles != null) { return; } var player = Session.Get <Player>(); if (player.Roles is null) { player.Roles = new List <Guid>(); } Roles = player.Roles.Select(id => EntityRepository.LoadEntity(id)).ToList(); }
//------------------------------------------------------------------------- void _onSuperSocketSessionCreate(IRpcSession s, IPEndPoint remote_endpoint) { if (remote_endpoint != null) { EbLog.Note("玩家连接成功,RemoteEndPoint=" + remote_endpoint.ToString()); } ClientInfo client_info = new ClientInfo(); client_info.remote_endpoint = remote_endpoint; client_info.acc = ""; client_info.et_player_guid = ""; client_info.player_watcher = null; client_info.player_watcher_weak = null; lock (MapClientInfoLock) { MapClientInfo[s] = client_info; } }
//------------------------------------------------------------------------- public CellPlayerObserver(IComponent co_app, IRpcSession s) { CoApp = (BaseApp <DefApp>)co_app; Session = s; MapFunc = new Dictionary <MethodType, Action <MethodData> >(); MapFunc[MethodType.s2cAccountNotify] = s2cAccountNotify; MapFunc[MethodType.s2cPlayerNotify] = s2cPlayerNotify; MapFunc[MethodType.s2cBagNotify] = s2cBagNotify; MapFunc[MethodType.s2cEquipNotify] = s2cEquipNotify; MapFunc[MethodType.s2cStatusNotify] = s2cStatusNotify; MapFunc[MethodType.s2cPlayerChatNotify] = s2cPlayerChatNotify; MapFunc[MethodType.s2cPlayerFriendNotify] = s2cPlayerFriendNotify; MapFunc[MethodType.s2cPlayerMailBoxNotify] = s2cPlayerMailBoxNotify; MapFunc[MethodType.s2cPlayerTaskNotify] = s2cPlayerTaskNotify; MapFunc[MethodType.s2cPlayerTradeNotify] = s2cPlayerTradeNotify; MapFunc[MethodType.s2cPlayerDesktopNotify] = s2cPlayerDesktopNotify; MapFunc[MethodType.s2cPlayerLobbyNotify] = s2cPlayerLobbyNotify; MapFunc[MethodType.s2cPlayerRankingNotify] = s2cPlayerRankingNotify; }
private void OnSessionExcepted(IRpcSession session, Exception ex) { IRpcSession prevSession; lock (_sync) { if (session != _session) { return; } _sendingInProgress = false; prevSession = NewSession(); } Log.Debug("Session excepted: {0}", ex); SendNextQueuedItem(); prevSession.Close(ex); }
/// <summary> /// Get value of session's context which is type T and convert the object value to T. /// </summary> /// <typeparam name="T">The type</typeparam> /// <param name="session">The session</param> /// <returns>Converted session value</returns> public static T Get <T>(this IRpcSession session) { return((T)session[typeof(T).FullName ?? throw new InvalidOperationException()]);
public static T Get <T>(this IRpcSession session, string key) { return((T)session[key]); }
/// <summary>Initializes a new instance of the <see cref="T:System.Object"></see> class.</summary> public PlayerController(IRpcSession session) { Session = session; }
/// <summary> /// Checks the permission. /// </summary> /// <param name="session">The session.</param> /// <returns></returns> public override CheckResult CheckPermission(IRpcSession session) { return(CheckResult.If(session.IsSet <Entity>(), "Please select a role first.")); }
public abstract CheckResult CheckPermission(IRpcSession session);
public TestServiceA(IRpcSession session) { Session = session; }