/// <summary> /// 获取玩家列表回调 /// </summary> public void OnGetPlayersInfo(BaseProtocol baseProtocol) { BytesProtocol p = baseProtocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); int Playernum = p.GetInt(startIndex, ref startIndex); UnityEngine.Object playerprefab = Resources.Load("NetPlayerPrefab"); GameObject tmp_player = null; for (int i = 0; i < Playernum; i++) { string playerName = p.GetString(startIndex, ref startIndex); //自己不需要更新 if (playerName != NetworkManager.PlayerName) { tmp_player = Instantiate(playerprefab) as GameObject; tmp_player.name = playerName; tmp_player.transform.SetParent(transform); NetworkPlayer nPlayer = tmp_player.GetComponent <NetworkPlayer>(); nPlayer.SetPlayerName(playerName); ScenePlayers.Add(playerName, nPlayer); nPlayer.LastUpdateTime = NetworkManager.GetTimeStamp(); } } }
public bool Accept(SocketAsyncEventArgs socketAsyncEvent) { if (!_enabled) { Logger.WARN("Acceptor is not enabled."); _droppedCount++; return(true); } Logger.INFO("Client connected:{0}:{1} -> {2}:{3}", (socketAsyncEvent.AcceptSocket.RemoteEndPoint as IPEndPoint).Address.ToString(), (socketAsyncEvent.AcceptSocket.RemoteEndPoint as IPEndPoint).Port, _ipAddress, _port); BaseProtocol pProtocol = ProtocolFactoryManager.CreateProtocolChain(_protocolChain, Parameters); if (pProtocol == null) { Logger.FATAL("Unable to create protocol chain"); socketAsyncEvent.AcceptSocket.Close(); return(false); } var pTcpCarrier = new TCPCarrier(socketAsyncEvent.AcceptSocket) { Protocol = pProtocol.FarEndpoint, ReadEnabled = true }; pProtocol.FarEndpoint.IOHandler = pTcpCarrier; //6. Register the protocol stack with an application if (Application != null) { pProtocol = pProtocol.NearEndpoint; pProtocol.Application = Application; } //if (pProtocol.NearEndpoint.OutputBuffer != null) // pProtocol.NearEndpoint.EnqueueForOutbound(); if (AcceptEnabled) { socketAsyncEvent.AcceptSocket = null; try { if (!Socket.AcceptAsync(socketAsyncEvent)) { OnEvent(socketAsyncEvent); } } catch (Exception ex) { Logger.FATAL(ex.Message); return(false); } } else { socketAsyncEvent.ReturnPool(); } _acceptedCount++; return(true); }
public OpcHelper(BaseProtocol protocol, StationModel stnmodel, ushort serverindex) { MyBaseProtocol = protocol; MyStationModel = stnmodel; ServerIndex = serverindex; MyServer = stnmodel.StationOPCServer; }
private void OnConnectCallback(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; string MethodName = p.GetString(startIndex, ref startIndex); int returnCode = p.GetInt(startIndex, ref startIndex); if (returnCode == 0) { Debug.Log("连接成功"); UIManager.Instance.ShowUI(UIid.MainUI); MessageCenter.Send(EMessageType.PlayerName, inputField.text); UIManager.Instance.HideTheUI(this.uiId, () => { }); } else { Debug.Log("连接失败"); UIManager.Instance.ShowUI(UIid.TipsUI); object[] param = new object[2]; param[0] = "连接失败\n可能原因:昵称已被使用、服务器问题 或 网络故障"; param[1] = "知道了"; MessageCenter.Send_Multparam(EMessageType.TipsUI, param); } }
/// <summary> /// 发送心跳 /// </summary> /// <param name="heartbit"></param> public static bool SendHeartBit(bool heartbit, StationModel station, BaseProtocol protocol) { try { if (station.StationOPCServer == null || !station.StationOPCServer.Session.Connected) { return(false); } NodeIdCollection nodesToWriteHeart = new NodeIdCollection(); string comDB = station.DataWriteDB; //握手信号交互DB块 nodesToWriteHeart.Add(new NodeId(comDB + protocol.MES_PLC_Heart, station.ServerIndex)); //心跳 DataValueCollection values = new DataValueCollection(); values.Add(new DataValue(heartbit)); StatusCodeCollection codes; station.StationOPCServer.WriteValues(nodesToWriteHeart, values, out codes); foreach (StatusCode item in codes) { if (StatusCode.IsBad(item.Code)) { return(false); } } return(true); } catch (Exception ex) { LogHelper.Write("发送心跳异常:" + ex.Message, "system"); return(false); } }
public override void UnRegisterProtocol(BaseProtocol pProtocol) { var userList = SOManager["userList"]; var room = SOManager["room"]; lock (room) { base.UnRegisterProtocol(pProtocol); if (OnlineClient.ContainsValue(pProtocol)) { var clientId = OnlineClient.Single(x => x.Value == pProtocol).Key; if (room["publisher1"] != null && room["publisher1"]["id"] == clientId) { room.UnSet("publisher1"); } if (room["publisher2"] != null && room["publisher2"]["id"] == clientId) { room.UnSet("publisher2"); } if (room["adminId"] != null && room["adminId"]["id"] == clientId) { room.UnSet("adminId"); room.UnSet("ppt"); room.UnSet("pptPageNum"); } room.Track(); OnlineClient.Remove(clientId); userList.UnSet(clientId); userList.Track(); } } }
public Tosa25G(BaseProtocol protocolControl, BaseOvenControl ovenControl, Dictionary <string, string> param, ILog logger) { Log = new DriverLog(logger, "TOSA25G", param["Name"]); InitParam(param); CtrlCom = protocolControl; OvenControl = ovenControl; }
public void Login(string Name, int ProtocolVersion, bool IsForge) { BaseProtocol baseProtocol = new BaseProtocol(); Handshake handshake = new Handshake(); handshake.ProtocolVersion = ProtocolVersion; if (IsForge) { handshake.ServerAddress = Program.QueryConfig.ServerAddress + "\0FML\0"; } else { handshake.ServerAddress = Program.QueryConfig.ServerAddress; } handshake.ServerPort = Program.NatConfig.Port; handshake.NextState = NextState.login; byte[] buffer = baseProtocol.Pack(handshake); client.Send(buffer, 0, buffer.Length); Login login = new Login(); login.Name = Name; buffer = baseProtocol.Pack(login); client.Send(buffer, 0, buffer.Length); client.Flag = false; // Console.WriteLine($"Login完毕"); }
public void UnRegisterProtocol(BaseProtocol protocol) { foreach (var so in _sos.Values.Where(so => so.UnRegisterProtocol(protocol) && so.SubscribersCount == 0 && !so.IsPersistent).ToList()) { _sos.Remove(so.Name); } }
private void AcceptClient_ClientDisconnected(OnConnection clientConnection) { BaseProtocol ci = (BaseProtocol)clientConnection; ci.ClientClosed -= AcceptClient_ClientDisconnected; Clients.Remove(ci); }
/// <summary> /// sends a message to server /// </summary> /// <param name="message"></param> public void QueueMessage(BaseProtocol message) { if (Connected) { outboundQueue.Enqueue(message); } }
/// <summary> /// 更新网络玩家数据 /// </summary> /// <param name="protocol"></param> public void UpdatePlayerInfo(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); string playerName = p.GetString(startIndex, ref startIndex); float HP = p.GetFloat(startIndex, ref startIndex); float posX = p.GetFloat(startIndex, ref startIndex); float posY = p.GetFloat(startIndex, ref startIndex); float posZ = p.GetFloat(startIndex, ref startIndex); float rotX = p.GetFloat(startIndex, ref startIndex); float rotY = p.GetFloat(startIndex, ref startIndex); float rotZ = p.GetFloat(startIndex, ref startIndex); string CurrentAction = p.GetString(startIndex, ref startIndex); //自己的消息 if (playerName == NetworkManager.PlayerName) { BagManager.Instance.characterStatus.HP = HP; } if (ScenePlayers.ContainsKey(playerName)) { ScenePlayers[playerName].SetPlayerInfo(HP, CurrentAction); ScenePlayers[playerName].SetPlayerTransform(posX, posY, posZ, rotX, rotY, rotZ); } }
private void PacketProcess() { if (buffCount < sizeof(Int32)) { return; } Array.Copy(buff, lengthBytes, sizeof(Int32)); msgLength = BitConverter.ToInt32(lengthBytes, 0); if (buffCount < msgLength + sizeof(Int32)) { return; } BaseProtocol p = protocol.Decode(buff, sizeof(Int32), msgLength); //Debug.Log("收到消息:" + p.GetDescription()); //多线程-处理需为msgList加锁 lock (msgDistribution) { msgDistribution.msgList.Add(p); } //删除已处理的消息 int count = buffCount - msgLength - sizeof(Int32); //缓冲区长度-当前消息体长度-消息头长度 Array.Copy(buff, sizeof(Int32) + msgLength, buff, 0, count); //缓冲区字节数组删除已处理的消息 buffCount = count; if (buffCount > 0) { PacketProcess(); } }
/// <summary> /// 玩家死亡处理 /// </summary> /// <param name="protocol"></param> private void OnPlayerKilled(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); //杀手名 string KillerName = p.GetString(startIndex, ref startIndex); //被杀玩家名 string KilledPlayerName = p.GetString(startIndex, ref startIndex); //玩家死亡处理 if (KilledPlayerName == NetworkManager.PlayerName) { UIManager.Instance.ShowUI(UIid.FinishUI); object[] param = new object[3]; param[0] = "无畏之争——无谓之争"; param[1] = "你被 " + KillerName + " 击杀"; param[2] = " "; MessageCenter.Send_Multparam(EMessageType.FinishUI, param); CameraBase.Instance.isFollowing = false; return; } DelPlayer(KilledPlayerName); }
/// <summary> /// 获取地图道具随机数种子 /// </summary> private void OnGetMapItemDataBack(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); Seed = p.GetInt(startIndex, ref startIndex); object[] param = new object[2]; param[0] = "正在接收道具数据..."; param[1] = 0; MessageCenter.Send_Multparam(EMessageType.LoadingUI, param); if (Seed != 0) { //220个物品生成点的随机数 RandomList = InitTotalProbabilityValue(ProbabilityValue); param[0] = "道具数据接收完毕"; param[1] = 0; MessageCenter.Send_Multparam(EMessageType.LoadingUI, param); GenerateItem(); } else { Debug.LogError("Seed异常 " + Seed.ToString() + " 无法加载"); } }
public override void Broadcast(uint appId, BaseProtocol pFrom, Variant invokeInfo) { foreach (var inboundClusterProtocol in InboundClusters.Where(inboundClusterProtocol => pFrom != inboundClusterProtocol)) { inboundClusterProtocol.Broadcast(appId, pFrom, invokeInfo); } }
public void UnSet(string key, BaseProtocol pFrom = null) { if (!_versionIncremented) { Version++; _versionIncremented = true; } Payload[key] = null; var deleteDirtyInfo = new DirtyInfo { PropertyName = key, Type = Defines.SOT_SC_DELETE_DATA }; Synchronization?.Invoke(deleteDirtyInfo); #if PARALLEL _dirtyPropsByProtocol.AsParallel().ForAll(x => x.Value.Add(new DirtyInfo { PropertyName = key, Type = Defines.SOT_SC_DELETE_DATA })); #else if (pFrom is BaseClusterProtocol) { foreach (var registeredProtocol in _dirtyPropsByProtocol.Where(x => x.Key != pFrom)) { registeredProtocol.Value.Add(deleteDirtyInfo); } } else { foreach (var registeredProtocol in _dirtyPropsByProtocol) { registeredProtocol.Value.Add(deleteDirtyInfo); } } #endif }
public IOutFileStream CreateOutFileStream(BaseProtocol protocol, IInStream instream, bool append) { var pOutFileStream = CreateOutFileStream(protocol, instream.Name, null, append); pOutFileStream?.Link(instream); return(pOutFileStream); }
public void RegisterProtocol(BaseProtocol protocol) { _dirtyPropsByProtocol[protocol] = new List <DirtyInfo>(); //不向主服务器发送初始化SO信息 if (protocol is OutboundClusterProtocol) { return; } DirtyInfo di; //1. Clear di.PropertyName = "SOT_SC_CLEAR_DAT" + protocol.Id; di.Type = Defines.SOT_SC_CLEAR_DATA; _dirtyPropsByProtocol[protocol].Add(di); //2. Initial di.PropertyName = "SOT_SC_INITIAL_DAT" + protocol.Id; di.Type = Defines.SOT_SC_INITIAL_DATA; _dirtyPropsByProtocol[protocol].Add(di); //3. Mark all properties as updated if (Payload.Count > 0) { _dirtyPropsByProtocol[protocol].AddRange(Payload.Children.Select(x => new DirtyInfo { PropertyName = x.Key, Type = Defines.SOT_SC_UPDATE_DATA })); } //foreach (var key in Payload.Children.Keys) //{ // di.PropertyName = key; // di.Type = Defines.SOT_SC_UPDATE_DATA; // _dirtyPropsByProtocol[protocolId].Add(di); //} }
public override void Broadcast(uint appId, BaseProtocol pFrom, Variant invokeInfo) { if (pFrom != OutboundCluster) { OutboundCluster.Broadcast(appId, pFrom, invokeInfo); } }
public override void Broadcast(BaseProtocol from,Variant invokeInfo) { foreach (var session in Sessions) { } }
public Variant Test(BaseProtocol pFrom, Variant invoke) { var result = new Variant(); result["catagory"] = new Variant(PerformanceCounterCategory.GetCategories().Select(x => new Variant(x.CategoryName)).ToList()); return(result); }
public void Process(BaseProtocol pFrom, string name, bool isPersistent, Variant primitives) { var so = this[name, isPersistent]; for (var i = 0; i < primitives.Count; i++) { var primitive = primitives[i]; switch ((byte)primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_TYPE]) { case Defines.SOT_SC_UPDATE_DATA: var key = primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD].Children.Keys.First(); so.Set(key, primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD][key], pFrom); break; case Defines.SOT_SC_DELETE_DATA: so.UnSet(primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD][0], pFrom); break; case Defines.SOT_SC_INITIAL_DATA: case Defines.SOT_SC_CLEAR_DATA: so.Clear(pFrom); break; } } if (_sos.TryGetValue(name, out so)) { so.Track(); } }
private void Button_Click(object sender, RoutedEventArgs e) { BaseProtocol client = sModule.Clients.FirstOrDefault(); if (client == null) { return; } System.Diagnostics.Debug.WriteLine("TotalBytesReceived : " + client.TotalBytesReceived); System.Diagnostics.Debug.WriteLine("TotalBytesTransmitted : " + client.TotalBytesTransmitted); client.DisconnectByClient(); //client.Disconnect(); return; /* * OpenFileDialog openFileDialog = new OpenFileDialog(); * openFileDialog.Filter = "exe files (*.exe)|*.exe|All files (*.*)|*.*"; * openFileDialog.RestoreDirectory = true; * * if (openFileDialog.ShowDialog() != true) return; * * Stream myStream = openFileDialog.OpenFile(); * byte[] data = new byte[myStream.Length]; * myStream.Read(data, 0, data.Length); */ //client.SendFile(data); }
private void ReceiveMessage(BaseProtocol protocol) { MessageProtocol message = protocol as MessageProtocol; PrintToConsole(string.Format("{0}: {1}", message.from_client, message.message)); Debug.LogFormat("Recived message: {0} from {2} Len: {1}", message.message, message.message.Length, message.from_client); }
public CobbleConnection(ConnectionContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); _reader = context.CreateReader(); _writer = context.CreateWriter(); _protocol = new HandshakingProtocol(); }
public static void Buffer_BaseProtocol(BaseProtocol baseProtocol) { p_AllMsg.BaseProtocol.seq = baseProtocol.get_seq(); p_AllMsg.BaseProtocol.cmd = baseProtocol.get_cmd(); p_AllMsg.BaseProtocol.uid = baseProtocol.get_uid(); p_AllMsg.BaseProtocol.ack = baseProtocol.get_ack(); p_AllMsg.BaseProtocol.flag = baseProtocol.get_flag(); }
virtual public bool StreamNameAvailable(string streamName, BaseProtocol pProtocol) { if (AllowDuplicateInboundNetworkStreams) { return(true); } return(StreamsManager.StreamNameAvailable(streamName)); }
private void SetAvailableGames(BaseProtocol protocol) { currentLobbyData = protocol as CurrentLobbyProtocol; print("Display match..." + currentLobbyData.GetJson(out int _));; BuildMatchSelect( ); }
public override void UnRegisterProtocol(BaseProtocol protocol) { Logger.INFO("Outgoing Cluster!"); InboundClusters.Remove(protocol as InboundClusterProtocol); foreach (var so in (protocol as InboundClusterProtocol).SOs) { so.UnRegisterProtocol(protocol as InboundClusterProtocol); } }
public override void GetTargetOvenTemperature() { Dictionary <string, string> param = CreateParam(_boardName, _floorNum, _boardNum, _ovenPort, _ctlPort); BaseProtocol protocol = MockBaseProtocol(); BaseOvenControl ovenCtrol = MockBaseOvenControl(); IBoard test = new TOSA25G(protocol, ovenCtrol, param, this._logger); Assert.AreEqual(test.GetTargetOvenTemperature(), 70.0); }
public SocketClient(string ip, Int32 port, Int32 bufferSize, string localIp) { protocol = new BaseProtocol(); _client = new TCPAsyncClient(ip, port, bufferSize, protocol, localIp, 0); _client.Connected += client_Connected; _client.Closed += client_Closed; _client.Error += client_Error; protocol.Receive += protocol_ReceiveData; }
public override void RegisterProtocol(BaseProtocol protocol) { Logger.INFO("Incoming Cluster!"); InboundClusters.Add(protocol as InboundClusterProtocol); foreach (var room in ClientApplicationManager.ApplicationByName.Values) { room.SOManager.RegisterProtocol(protocol as InboundClusterProtocol); } }
public override void UnRegisterProtocol(BaseProtocol protocol) { Logger.INFO("DisconnectOutboundCluster"); ReconnectTimer.Start(); foreach (var so in OutboundCluster.SOs) { so.UnRegisterProtocol(OutboundCluster); } OutboundCluster = null; }
public override void RegisterProtocol(BaseProtocol protocol) { OutboundCluster = protocol as OutboundClusterProtocol; foreach (var room in ClientApplicationManager.ApplicationByName.Values) { room.SOManager.RegisterProtocol(OutboundCluster); } while (_offlineTasks!=null) { _offlineTasks(OutboundCluster); _offlineTasks = null; } }
public static bool SignalProtocolCreated(BaseProtocol protocol, Variant customParameters) { var application = ClientApplicationManager.FindAppByName(customParameters[Defines.CONF_APPLICATION_NAME]); if (application == null) { Logger.FATAL("Application {0} not found", customParameters[Defines.CONF_APPLICATION_NAME]); return false; } if (protocol == null) { Logger.WARN("OutboundCluster Connection failed:{0}", customParameters.ToString()); application.GetProtocolHandler<SlaveClusterAppProtocolHandler>().ReconnectTimer.Start(); return false; } protocol.CustomParameters = customParameters; protocol.Application = application; return true; }
public void Process(BaseProtocol pFrom,string name,bool isPersistent,Variant primitives) { var so = this[name, isPersistent]; for (var i = 0; i < primitives.Count; i++) { var primitive = primitives[i]; switch ((byte)primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_TYPE]) { case Defines.SOT_SC_UPDATE_DATA: var key = primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD].Children.Keys.First(); so.Set(key, primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD][key],pFrom); break; case Defines.SOT_SC_DELETE_DATA: so.UnSet(primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD][0], pFrom); break; case Defines.SOT_SC_INITIAL_DATA: case Defines.SOT_SC_CLEAR_DATA: so.Clear(pFrom); break; } } if (_sos.TryGetValue(name, out so)) so.Track(); }
public abstract void Broadcast(uint appId, BaseProtocol to, Variant invokeInfo);
public override void UnRegisterProtocol(BaseProtocol protocol) { //throw new NotImplementedException(); }
public override void RegisterProtocol(BaseProtocol protocol) { //1. Is this a client RTSP protocol? if (protocol.Type != ProtocolTypes.PT_RTSP) return; if (protocol.CustomParameters["isClient"] == null || !protocol.CustomParameters["isClient"])return; if (protocol.CustomParameters["forceTcp"] != null) { if (protocol.CustomParameters["forceTcp"] != VariantType.Boolean) { FATAL("Invalid forceTcp flag detected"); protocol.EnqueueForDelete(); return; } } else { protocol.CustomParameters["forceTcp"] = false; } //可能用不到了 //var rtsp = protocol as RtspProtocol; //if ((parameters.HasKeyChain(V_MAP, true, 2, "customParameters", "externalStreamConfig")) //|| (parameters.HasKeyChain(V_MAP, true, 2, "customParameters", "localStreamConfig"))) //{ // //5. Start play // if (!TriggerPlayOrAnnounce(pRTSPProtocol)) // { // FATAL("Unable to initiate play on uri %s", // (parameters["uri"])); // pRTSPProtocol.EnqueueForDelete(); // return; // } //} //else //{ // WARN("Bogus connection. Terminate it"); // pProtocol.EnqueueForDelete(); //} }
public void UnSet(string key, BaseProtocol pFrom = null) { if (!_versionIncremented) { Version++; _versionIncremented = true; } Payload[key] = null; var deleteDirtyInfo = new DirtyInfo {PropertyName = key, Type = Defines.SOT_SC_DELETE_DATA}; Synchronization?.Invoke(deleteDirtyInfo); #if PARALLEL _dirtyPropsByProtocol.AsParallel().ForAll(x => x.Value.Add(new DirtyInfo { PropertyName = key, Type = Defines.SOT_SC_DELETE_DATA })); #else if (pFrom is BaseClusterProtocol) { foreach (var registeredProtocol in _dirtyPropsByProtocol.Where(x => x.Key != pFrom)) { registeredProtocol.Value.Add(deleteDirtyInfo); } }else foreach (var registeredProtocol in _dirtyPropsByProtocol) { registeredProtocol.Value.Add(deleteDirtyInfo); } #endif }
public override void CallClient(BaseProtocol pTo, string functionName, Variant param) { var message = GenericMessageFactory.GetInvoke(3, 0, 0, false, 0, functionName, param.Clone()); SendRTMPMessage(pTo as BaseRTMPProtocol, message); }
public void Broadcast(uint appId, BaseProtocol pFrom, Variant invokeInfo) { Logger.INFO("SendBroadcast to {1}:{0}",invokeInfo,appId); Send(ClusterMessageType.BroadCast, o => { o.Write7BitValue(appId); o.Write(invokeInfo.ToBytes()); }); }
public override void Broadcast(BaseProtocol @from, Variant invokeInfo) { throw new NotImplementedException(); }
public override void RegisterProtocol(BaseProtocol protocol) { if (protocol is Session) Sessions.Add(protocol as Session); else CurrentProtocol = protocol as InboundRTMFPProtocol; }
public override void UnRegisterProtocol(BaseProtocol protocol) { if (protocol is Session) Sessions.Remove(protocol as Session); else CurrentProtocol = null; }
public void RegisterProtocol(BaseProtocol protocol) { _dirtyPropsByProtocol[protocol] = new List<DirtyInfo>(); //不向主服务器发送初始化SO信息 if (protocol is OutboundClusterProtocol) return; DirtyInfo di; //1. Clear di.PropertyName = "SOT_SC_CLEAR_DAT" + protocol.Id; di.Type = Defines.SOT_SC_CLEAR_DATA; _dirtyPropsByProtocol[protocol].Add(di); //2. Initial di.PropertyName = "SOT_SC_INITIAL_DAT" + protocol.Id; di.Type = Defines.SOT_SC_INITIAL_DATA; _dirtyPropsByProtocol[protocol].Add(di); //3. Mark all properties as updated if(Payload.Count>0) _dirtyPropsByProtocol[protocol].AddRange(Payload.Children.Select(x => new DirtyInfo { PropertyName = x.Key, Type = Defines.SOT_SC_UPDATE_DATA })); //foreach (var key in Payload.Children.Keys) //{ // di.PropertyName = key; // di.Type = Defines.SOT_SC_UPDATE_DATA; // _dirtyPropsByProtocol[protocolId].Add(di); //} }
public bool UnRegisterProtocol(BaseProtocol protocol) { List<DirtyInfo> dirtyInfo; return _dirtyPropsByProtocol.TryRemove(protocol, out dirtyInfo); }
public Variant Set(string key, Variant value, BaseProtocol pFrom = null) { if (value == null || value == VariantType.Null) { UnSet(key); return value; } if (!_versionIncremented) { Version++; _versionIncremented = true; } Payload[key] = value; var updateDirtyInfo = new DirtyInfo {PropertyName = key, Type = Defines.SOT_SC_UPDATE_DATA}; Synchronization?.Invoke(updateDirtyInfo); #if PARALLEL _dirtyPropsByProtocol.AsParallel().ForAll(x => x.Value.Add(new DirtyInfo { PropertyName = key, Type =x.Key == protocolId ? Defines.SOT_SC_UPDATE_DATACK : Defines.SOT_SC_UPDATE_DATA} )); #else foreach (var registeredProtocol in _dirtyPropsByProtocol) { if (registeredProtocol.Key == pFrom) { if (pFrom is BaseClusterProtocol)continue; registeredProtocol.Value.Add(new DirtyInfo { PropertyName = key, Type = Defines.SOT_SC_UPDATE_DATA_ACK }); } else { registeredProtocol.Value.Add(updateDirtyInfo); } } #endif return Payload[key]; }
public override void SharedObjectTrack(BaseProtocol to, string name, uint version, bool isPersistent, Variant primitives) { throw new NotImplementedException(); }
public override void CallClient(BaseProtocol to, string functionName, Variant invoke) { throw new NotImplementedException(); }
private void parseICMP(String[] lines) { String[] seps = lines [2].Split (new[]{ " " }, StringSplitOptions.None); protocolBody = new ICMP (seps); protocolBody.raw = lines [2]; }
public override void SharedObjectTrack(BaseProtocol to, string name, uint version, bool isPersistent, Variant primitives) { var message = SOMessageFactory.GetSharedObject(3, 0, 0, false, name, version, isPersistent); message.Body[Defines.RM_SHAREDOBJECT, Defines.RM_SHAREDOBJECT_PRIMITIVES] = primitives; if (!(to as BaseRTMPProtocol).SendMessage(message, true)) { to.EnqueueForDelete(); } }
public override void CallClient(BaseProtocol to, string functionName, Variant param) { //throw new System.NotImplementedException(); }
public override void Broadcast(BaseProtocol from,Variant invokeInfo) { var param = invokeInfo[Defines.RM_INVOKE_PARAMS].Clone(); param.Insert(0, Variant.Get()); var message = GenericMessageFactory.GetInvoke(3, 0, 0, false, 0, invokeInfo[Defines.RM_INVOKE_FUNCTION], Variant.Get(param)); Logger.INFO("send to {0} clients:{1}", _connections.Count,message.Body.ToString()); foreach (var baseRtmpProtocol in _connections.Values) { SendRTMPMessage(baseRtmpProtocol, message, false, false); } //message.Body.Recycle(); }
public override void UnRegisterProtocol(BaseProtocol protocol) { }
public void Send(Variant primitive,BaseProtocol from) { foreach (var listener in _dirtyPropsByProtocol.Keys) { if(from == listener)continue; var primitives = Variant.Get(); primitives[0] = primitive.Clone(); if (listener is BaseClusterProtocol) (listener as BaseClusterProtocol).SharedObjectTrack(Application, Name, Version, IsPersistent, primitives); else listener.Application.SharedObjectTrack(listener, Name, Version, IsPersistent, primitives); } }
public void Clear(BaseProtocol pFrom = null) { Payload.SetValue(); var clearDirtyInfo = new DirtyInfo {PropertyName = null, Type = Defines.SOT_SC_CLEAR_DATA}; Synchronization?.Invoke(clearDirtyInfo); foreach (var registeredProtocol in _dirtyPropsByProtocol.Where(x => x.Key != pFrom)) { registeredProtocol.Value.Add(clearDirtyInfo); } }