//--------------------------------------------------------------------- public PhotonServerPeerC(IRpcProtocol protocol, IPhotonPeer unmanaged_peer, EntityMgr entity_mgr, byte remote_node_type, RpcSessionListener listener) : base(protocol, unmanaged_peer) { mEntityMgr = entity_mgr; mRpcSession = new RpcSession(mEntityMgr, this); mListener = listener; mRemoteNodeType = remote_node_type; Dictionary <byte, object> map_param = new Dictionary <byte, object>(); map_param[0] = mEntityMgr.NodeType; map_param[1] = 0;// local_node_id OperationRequest operation_request = new OperationRequest((byte)_eRpcCmd.SyncPeerInfo, map_param); SendResult r = SendOperationRequest(operation_request, new SendParameters { ChannelId = 0 }); if (r != SendResult.Ok) { EbLog.Error("PhotonServerPeerC SyncPeerInfo Result=" + r); } if (mListener != null) { mListener.onSessionConnect(mEntityMgr.NodeType, mRemoteNodeType, mRpcSession); } }
//--------------------------------------------------------------------- public PhotonServerPeerS(IRpcProtocol rpc_protocol, IPhotonPeer native_peer, EntityMgr entity_mgr, RpcSessionListener listener) : base(rpc_protocol, native_peer) { mEntityMgr = entity_mgr; mRpcSession = new RpcSession(mEntityMgr, this); mListener = listener; }
//--------------------------------------------------------------------- public void connectBase(string base_ip, int base_port) { RpcSession.close(); RpcSession.OnSocketConnected = _onSocketConnected; RpcSession.OnSocketClosed = _onSocketClosed; RpcSession.OnSocketError = _onSocketError; RpcSession.connect(base_ip, base_port); }
//--------------------------------------------------------------------- public void Connect(string ip, int port) { RpcSession.Close(); RpcSession.OnSocketConnected = _onSocketConnected; RpcSession.OnSocketClosed = _onSocketClosed; RpcSession.OnSocketError = _onSocketError; RpcSession.Connect(ip, port); }
protected virtual RpcSession CreateSession() { var session_ = rpcPeer.CreateSession(CreateContext()); session_.InitializeRemotingObject(session_); this.session = session_; return(session_); }
//--------------------------------------------------------------------- // Interface: RpcSessionListener.onSessionConnect public void onSessionConnect(byte node_type_local, byte node_type_remote, RpcSession session) { SessionEvent se; se.connect = true; se.node_type_local = node_type_local; se.node_type_remote = node_type_remote; se.session = session; mQueSessionEvent.Enqueue(se); }
//------------------------------------------------------------------------- public override void init() { EbLog.Note("ClientUCenterSession.init()"); defRpcMethod((byte)_eUCenterNodeType.UCenter, (ushort)_eUCenterMethodType.login2ClientOnLogin, login2ClientOnLogin); // 设置session RpcSession session = (RpcSession)Entity.getCacheData("RemoteSession"); Entity.setSession((byte)_eUCenterNodeType.UCenter, session); }
internal SessionOpenedEventArgs(RpcSession session, IRpcConnection connection) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (connection == null) { throw new ArgumentNullException(nameof(connection)); } this.Session = session; this.Connection = connection; }
//------------------------------------------------------------------------- // 响应登陆请求 public void client2LoginLogin(RpcSession s, Dictionary <byte, object> map_param) { EbLog.Note("LoginUCenterSession.client2LoginLogin()"); string account = (string)map_param[0]; string password = (string)map_param[1]; string serverGroup = (string)map_param[2]; string channel = (string)map_param[3]; LoginApp <ComponentDef> login = EntityMgr.findFirstEntity("EtApp").getComponent <LoginApp <ComponentDef> >(); login.addLoginPlayer(serverGroup, account, password, channel, this); }
//------------------------------------------------------------------------- public override void init() { EbLog.Note("LoginUCenterSession.init()"); defRpcMethod((byte)_eUCenterNodeType.Client, (ushort)_eUCenterMethodType.client2LoginLogin, client2LoginLogin); // 设置session RpcSession session = (RpcSession)Entity.getCacheData("RemoteSession"); Entity.setSession((byte)_eUCenterNodeType.Client, session); // Create Client Remote rpcOneCreateRemote((byte)_eUCenterNodeType.Client, false); }
//--------------------------------------------------------------------- public PhotonClientPeer(EntityMgr entity_mgr, byte remote_node_type, RpcSessionListener listener) : base(ConnectionProtocol.Tcp) { Listener = this; mEntityMgr = entity_mgr; mRpcSession = new RpcSession(mEntityMgr, this); mListener = listener; mRemoteNodeType = remote_node_type; DebugOut = DebugLevel.ERROR; //WarningSize = 500; //CommandBufferSize = 500; //TrafficStatsEnabled = true; //this.IsSimulationEnabled = true; //NetworkSimulationSet NetworkSimulationSettings }
//------------------------------------------------------------------------- // 响应登陆请求 public void login2ClientOnLogin(RpcSession s, Dictionary <byte, object> map_param) { EbLog.Note("ClientUCenterSession.login2ClientOnLogin()"); string result = (string)map_param[0]; string token = (string)map_param[1]; byte count = (byte)map_param[2]; Dictionary <byte, object> param = new Dictionary <byte, object>(); for (byte idx = 0; idx < count; idx++) { param[idx] = map_param[(byte)(3 + idx)]; } mCoUCenter._onLogin(result, token, param); }
void OnSessionStarted(SessionOpenedEventArgs args) { this.Session = args.Session; try { OnSessionOpened(args); } catch (Exception e) { logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnSessionOpened)}: {e}"); } try { OnSessionOpenedEvent?.Invoke(args); } catch (Exception e) { logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnSessionOpenedEvent)}: {e}"); } }
void IRpcPeer.OnSessionClosed(SessionClosedEventArgs args) { this.Session = null; try { OnSessionClosed(args); } catch (Exception e) { logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnSessionClosed)}: {e}"); } try { OnSessionClosedEvent?.Invoke(args); } catch (Exception e) { logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnSessionClosedEvent)}: {e}"); } }
public override void OnDefRpcMethod() { RpcSession.defRpcMethod <int, string>(2, _onRpcMethod1); }
//------------------------------------------------------------------------- public void onSessionDisconnect(byte node_type_local, byte node_type_remote, RpcSession session) { EbLog.Note("ClientUCenter.onSessionDisconnect()"); }
//------------------------------------------------------------------------- public override void onRpcPropSync(RpcSession session, byte from_node, ushort reason) { }
//--------------------------------------------------------------------- public void update(float tm) { RpcSession.update(tm); }
//--------------------------------------------------------------------- //[EntityRpcMethod(_eEtNode.Anonymous)],定义NodeType,与Rpc委托比较校验函数参数 public void es2ecOnLogin(RpcSession s, Dictionary <byte, object> map_param) { EbLog.Note("EsApp.es2ecOnLogin()"); }
//--------------------------------------------------------------------- // Interface: RpcSessionListener.onSessionDisconnect public void onSessionDisconnect(byte node_type_local, byte node_type_remote, RpcSession session) { EbLog.Note("EcApp.onSessionDisconnect() node_type_local=" + node_type_local + " node_type_remote=" + node_type_remote); }
//--------------------------------------------------------------------- public void disconnect() { RpcSession.close(); }
//--------------------------------------------------------------------- public void Send(ushort method_id, byte[] data) { RpcSession.Send(method_id, data); }
//--------------------------------------------------------------------- public void Disconnect() { RpcSession.Close(); }
//------------------------------------------------------------------------- public void onRpcNodeMethod(RpcSession session, byte from_node, ushort method_id, Dictionary <byte, object> map_param) { }
//--------------------------------------------------------------------- public void Update(float tm) { RpcSession.Update(tm); }
//--------------------------------------------------------------------- public void nodeEc2EsLogin(RpcSession s, Dictionary <byte, object> map_param) { EbLog.Note("EsApp.nodeEc2EsLogin()"); }
//------------------------------------------------------------------------- public Entity onRpcEntityCreateRemote(RpcSession session, EntityData entity_data, bool from_db) { return(null); }